message stringlengths 2 59.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 37 108k | cluster float64 20 20 | __index_level_0__ int64 74 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99.
Submitted Solution:
```
N=input()
Dict={'0':2,'1':7,'2':2,'3':3,'4':3,'5':4,'6':2,'7':5,'8':1,'9':2}
print(Dict[N[0]]*Dict[N[1]])
``` | instruction | 0 | 29,517 | 20 | 59,034 |
Yes | output | 1 | 29,517 | 20 | 59,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99.
Submitted Solution:
```
s=input()
listed=[]
for s in s:
listed.append(s)
counter=1
for integer in listed:
if integer=='0':
counter=counter*2
elif integer=='1':
counter=counter*7
elif integer=='2':
counter=counter*2
elif integer=='3':
counter=counter*3
elif integer=='4':
counter=counter*3
elif integer=='5':
counter=counter*4
elif integer=='6':
counter=counter*2
elif integer=='7':
counter=counter*5
elif integer=='8':
counter=counter*1
elif integer=='9':
counter=counter*2
print(counter)
``` | instruction | 0 | 29,518 | 20 | 59,036 |
Yes | output | 1 | 29,518 | 20 | 59,037 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99.
Submitted Solution:
```
def main():
out = ""
fixes = {'0':2,'1':7,'2':2,'3':3,'4':3,'5':4,'6':2,'7':5,'8':1,'9':2}
n = input()
return fixes[n[0]]*fixes[n[1]]
if __name__ == '__main__':
print(main())
``` | instruction | 0 | 29,519 | 20 | 59,038 |
Yes | output | 1 | 29,519 | 20 | 59,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99.
Submitted Solution:
```
v=[2,7,2,3,3,4,2,5,1,2]
r=1
for x in input():r*=v[int(x)]
print(r)
``` | instruction | 0 | 29,520 | 20 | 59,040 |
Yes | output | 1 | 29,520 | 20 | 59,041 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99.
Submitted Solution:
```
n = int(input())
a1, a2 = n // 10, n % 10
t = { 0: 3,
1: 7,
2: 2,
3: 3,
4: 3,
5: 3,
6: 2,
7: 5,
8: 1,
9: 2}
print(t[a1] * t[a2])
``` | instruction | 0 | 29,521 | 20 | 59,042 |
No | output | 1 | 29,521 | 20 | 59,043 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99.
Submitted Solution:
```
n=list(map(int,input()))
a=[2,7,2,3,2,2,2,5,1,2]
print(a[n[0]]*a[n[1]])
``` | instruction | 0 | 29,522 | 20 | 59,044 |
No | output | 1 | 29,522 | 20 | 59,045 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99.
Submitted Solution:
```
p=input()
di={0:[0,8],1:[0,1,3,7,8,9],2:[2,8],3:[3,8,9],4:[4,8,9],5:[5,6,8,9],6:[6,8],7:[0,7,3,8,9],8:[8],9:[8,9]}
y=len(di[int(p[0])])*len(di[int(p[1])])
print(y)
``` | instruction | 0 | 29,523 | 20 | 59,046 |
No | output | 1 | 29,523 | 20 | 59,047 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99.
Submitted Solution:
```
__author__ = 'pxy'
c={}
c[0]=[0,8]
c[1]=[0,1,3,4,7,8,9]
c[2]=[2,8]
c[3]=[3,8,9]
c[4]=[4,8,9]
c[5]=[5,6,8,9]
c[6]=[6,8]
c[7]=[0,3,7,8,9]
c[8]=[8]
c[9]=[9]
str=input()
print(len(c[int(str[0])])*len(c[int(str[1])]))
``` | instruction | 0 | 29,524 | 20 | 59,048 |
No | output | 1 | 29,524 | 20 | 59,049 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940 | instruction | 0 | 29,695 | 20 | 59,390 |
Tags: dp, greedy
Correct Solution:
```
s=input()
s1=input()
l=[]
l1=[]
for x in s :
l.append(int(x))
for x in s1 :
l1.append(int(x))
d={}
for x in l :
d[x]=d.get(x,0)+1
f=False
if len(s1)>len(s) :
l=sorted(l)
l=l[::-1]
print("".join(map(str,l)))
exit()
ans=[0]*len(s)
ki=0
i=0
while(i<len(l1)) :
f=True
for j in range(max(l1[i],ki),-1,-1) :
if d.get(j,-1)>0 :
ans[i]=j
d[j]-=1
f=False
if j!=l1[i] :
ki=9
break
if f :
for i1 in range(i-1,-1,-1) :
f1=False
for j in range(max(l1[i1],ki)-1,-1,-1) :
if d.get(j,-1)>0 :
d[ans[i1]]+=1
ans[i1]=j
d[j]-=1
f1=True
i=i1
ki=9
break
if f1 :
break
else :
d[ans[i1]]+=1
ans[i1]=0
i+=1
print("".join(map(str,ans)))
``` | output | 1 | 29,695 | 20 | 59,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940 | instruction | 0 | 29,696 | 20 | 59,392 |
Tags: dp, greedy
Correct Solution:
```
a = input()
b = input()
if len(b) > len(a):
tmp = list(a)
tmp.sort(reverse = True)
for i in tmp:
print(i, end="")
exit(0)
sa = [0] * 10
for i in a:
sa[int(i)] += 1
def tolow():
tmp = ""
for i in range(0, 10):
tmp += str(i) * sa[i]
return tmp
def tobig():
tmp = ""
for i in range(9, -1, -1):
tmp += str(i) * sa[i]
return tmp
nakop = ""
for i in range(len(b)):
tmp = int(b[i])
if (sa[tmp] > 0):
sa[tmp] -= 1
cur = int(nakop + b[i] + tolow())
if cur <= int(b):
nakop += str(b[i])
continue
else:
sa[tmp] += 1
for j in range(tmp - 1, -1, -1):
if sa[j]:
sa[j] -= 1
print(nakop + str(j) + tobig())
exit(0)
else:
for j in range(tmp - 1, -1, -1):
if sa[j]:
sa[j] -= 1
print(nakop + str(j) + tobig())
exit(0)
print(nakop)
``` | output | 1 | 29,696 | 20 | 59,393 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940 | instruction | 0 | 29,697 | 20 | 59,394 |
Tags: dp, greedy
Correct Solution:
```
a=''.join(reversed(sorted(input())))
b=int(input())
r=''
while len(a)>0:
for i in range(len(a)):
n=r+a[i]+''.join(sorted(a[:i]+a[i+1:]))
if int(n)<=b:
r+=a[i]
a=a[:i]+a[i+1:]
break
print(r)
``` | output | 1 | 29,697 | 20 | 59,395 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940 | instruction | 0 | 29,698 | 20 | 59,396 |
Tags: dp, greedy
Correct Solution:
```
import bisect
def solve(l,d,s2,r):
ans=""
lol=0
i=0
lo=0
while i<(len(s2)):
if(lo==1):
#print("lol",i)
a=s2[i]
ind=bisect.bisect_left(l,a)
#print(ind,a)
for x in range(ind,-1,-1):
if(l[x]<l[ind]):
ind=x
#print("lol")
break
ans+=str(l[ind])
d[l.pop(ind)]-=1
lol=1
break
a=s2[i]
ind=bisect.bisect_left(l,a)
#print(l,ind,a)
if(ind==len(l)):
ind-=1
ans+=str(l[ind])
d[l[ind]]-=1
lol=1
break
elif(l[ind]>a):
if(ind==0):
while ind==0:
l.append(int(ans[-1]))
d[int(ans[-1])]+=1
l.sort()
ans=ans[:len(ans)-1]
lo=1
i-=1
a=s2[i]
ind=bisect.bisect_left(l,a)
#print(i)
#i+=1
continue
lol=1
ans+=str(l[ind-1])
#print(ans,i)
d[l[ind-1]]-=1
l.pop(ind-1)
break
else:
ans+=str(l[ind])
d[l[ind]]-=1
l.pop(ind)
i+=1
ll=[]
#print("lol",d)
if(lol):
for i in d:
if(d[i]!=0):
ll.append(i)
ll.sort(reverse=True)
co=0
#print(ll)
for i in ll:
for j in range(d[i]):
if(i==0):
co+=1
if(co>r):
break
ans+=str(i)
print(ans)
from math import gcd
import sys
from collections import defaultdict as dd
input=sys.stdin.readline
s1=list(map(int,input().strip()))
s2=list(map(int,input().strip()))
z=s1.count(0)
d=dd(int)
n=len(s1)
m=len(s2)
l=sorted(s1)
for i in s1:
d[i]+=1
if len(s1)<len(s2):
for i in range(len(s1)-1,-1,-1):
print(l[i],end="")
elif(len(s1)>len(s2)):
r=m-(n-z)
#print(l,m,n,z)
l=l[z-r:]
#print(l,r)
solve(l,d,s2,r)
else:
solve(l,d,s2,100)
``` | output | 1 | 29,698 | 20 | 59,397 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940 | instruction | 0 | 29,699 | 20 | 59,398 |
Tags: dp, greedy
Correct Solution:
```
a = list(input())
b = int(input())
a.sort()
a = a[::-1]
patasxan = ""
while(len(a) > 0):
for i in range(len(a)):
num = patasxan + a[i] + "".join(sorted(a[:i] + a[i + 1:]))
if (int(num) <= b):
patasxan += a[i]
a = a[:i] + a[i+1:]
break
print(patasxan)
``` | output | 1 | 29,699 | 20 | 59,399 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940 | instruction | 0 | 29,700 | 20 | 59,400 |
Tags: dp, greedy
Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 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 pf(s): return print(s, flush=True)
def main():
a = [c for c in S()]
b = [c for c in S()]
r = []
if len(a) < len(b):
r = sorted(a,reverse=True)
else:
a.sort()
la = len(a)
for i in range(la):
k = 0
for j in range(len(a)-1,-1,-1):
if a[j] > b[i]:
continue
if a[j] == b[i]:
t = a[:j] + a[j+1:]
if t <= b[i+1:]:
k = j
break
continue
k = j
break
r.append(a[k])
a = a[:k] + a[k+1:]
if r[-1] < b[i]:
r += sorted(a,reverse=True)
break
return ''.join(r)
print(main())
``` | output | 1 | 29,700 | 20 | 59,401 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940 | instruction | 0 | 29,701 | 20 | 59,402 |
Tags: dp, greedy
Correct Solution:
```
a=input().strip()
b=input().strip()
if len(b)>len(a):
print(''.join(sorted(a))[::-1])
else:
f=[0]*11
for ele in a:
f[int(ele)]+=1
ans=''
i=0
n=len(b)
while i<n:
num=int(b[i])
if f[num] :
ans+=str(num)
f[num]-=1
else:
break
i+=1
flag=0
while True and len(ans)!=len(a):
num=int(b[i])
num-=1
while num>=0:
if f[num]:
ans+=str(num)
f[num]-=1
for j in range(9,-1,-1):
ans+=(str(j)*f[j])
break
num-=1
if len(ans)==len(a):
break
f[int(ans[-1])]+=1
ans=ans[:-1]
i-=1
print(ans.strip())
``` | output | 1 | 29,701 | 20 | 59,403 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940 | instruction | 0 | 29,702 | 20 | 59,404 |
Tags: dp, greedy
Correct Solution:
```
n, N = input(), input()
N = [i for i in N]
n = sorted((i for i in n), reverse=True)
def has_hal(n, N):
return sorted(n) <= N
def solve(n, N):
if len(n) < len(N):
return ''.join(n)
if not n:
return ''
for pos, d in enumerate(n):
if d > N[0]:
continue
if d == N[0]:
n1 = n[:]
n1.remove(d)
if has_hal(n1, N[1:]):
return d + solve(n1, N[1:])
if d < N[0]:
n1 = n[:pos] + n[pos + 1:]
return d + ''.join(n1)
print(solve(n, N))
``` | output | 1 | 29,702 | 20 | 59,405 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940
Submitted Solution:
```
def find_f(la, max_f):
f = max_f
while (not la.count(f))and(f >= 0):
f -= 1
return f
def get_ans():
i = 0
la_ = la[:]
lb_ = lb[:]
ans.clear()
while i < len(a):
f = find_f(la_, lb_[i])
if f >= 0:
la_.remove(f)
ans.append(f)
if f < lb_[i]:
for j in range(i + 1, len(lb_)):
lb_[j] = 9
i += 1
else:
return i
return -1
a = input()
b = input()
ans = []
la = list(map(int, list(a)))
lb = list(map(int, list(b)))
if len(a) < len(b):
lb = [9] * len(b)
#for i in range(len(lb)):
# print(find_f(la, lb[i]))
res = get_ans()
#print(la, lb, res, ans)
while res != -1:
while lb[res - 1] == 0:
res -= 1
lb[res - 1] -= 1
for j in range(res, len(lb)):
lb[j] = 9
res = get_ans()
#print(la, lb, res, ans)
#print(ans)
print(''.join(map(str, ans)))
``` | instruction | 0 | 29,703 | 20 | 59,406 |
Yes | output | 1 | 29,703 | 20 | 59,407 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940
Submitted Solution:
```
def permute(a,b):
d={}
if len(a)==len(b) and len(a)==1:
if int(a)<=int(b):
return a
else:
return "-1"
for alpha in a:
try:
d[alpha]+=1
except KeyError:
d[alpha]=1
if len(a)<len(b):
strs=""
for i in range(0,10)[::-1]:
try:
strs+=d[str(i)]*str(i)
except:
pass
return strs
elif len(a)==len(b):
try:
i=d[b[0]]
s=permute(a.replace(b[0],"",1),b[1:])
if s!="-1":
return b[0]+s
else:
i=int(b[0])-1
while i>=0:
try:
d[str(i)]-=1
strs=str(i)
for i in range(0,10)[::-1]:
try:
strs+=d[str(i)]*str(i)
except:
pass
return strs
except:
i-=1
return "-1"
except KeyError:
i=int(b[0])-1
while i>=0:
try:
d[str(i)]-=1
strs=str(i)
for i in range(0,10)[::-1]:
try:
strs+=d[str(i)]*str(i)
except:
pass
return strs
except:
i-=1
return "-1"
a=(input())
b=(input())
d={}
print(permute(a,b))
``` | instruction | 0 | 29,704 | 20 | 59,408 |
Yes | output | 1 | 29,704 | 20 | 59,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940
Submitted Solution:
```
f=0
res=[]
def rec(c, b, pos):
global f
global res
if f==1:
return
if pos==len(b):
print (''.join(res))
f=1
return
if pos!=0:
for i in range(int(b[pos]), -1, -1):
if (c[i]!=0 and f==0):
if (i<int(b[pos])):
q=str(i)
c[i]-=1
for i in range(len(c)-1, -1, -1):
q+=str(i)*c[i]
print (''.join(res), q, sep='')
f=1
return
c[i]-=1
res.append(str(i))
rec(c, b, pos+1)
res=res[:-1]
c[i]+=1
else:
for i in range(int(b[pos]), 0, -1):
if (c[i]!=0 and f==0):
if (i<int(b[pos])):
q=str(i)
c[i]-=1
for i in range(len(c)-1, -1, -1):
q+=str(i)*c[i]
print (''.join(res), q, sep='')
f=1
return
c[i]-=1
res.append(str(i))
rec(c, b, pos+1)
res=res[:-1]
c[i]+=1
a=[x for x in input()]
b=[x for x in input()]
if (len(b)>len(a)):
print (''.join(sorted(a, key=lambda x:-int(x))))
else:
c=[0 for x in range(10)]
for i in a:
c[int(i)]+=1
rec (c, b, 0)
``` | instruction | 0 | 29,705 | 20 | 59,410 |
Yes | output | 1 | 29,705 | 20 | 59,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940
Submitted Solution:
```
a=list(input())
b=int(input())
pre=''
a.sort()
a=a[::-1]
#print(a)
while(len(a)>0):
for i in range(0,len(a)):
numb=pre+a[i]+"".join(sorted(a[:i]+a[i+1:]))
if(int(numb)<=b):
pre+=a[i]
a=a[:i]+a[i+1:]
break
print(pre)
``` | instruction | 0 | 29,706 | 20 | 59,412 |
Yes | output | 1 | 29,706 | 20 | 59,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940
Submitted Solution:
```
a = input()
b = input()
nua = int(a)
nub = int(b)
a = [i for i in a]
b = [i for i in b]
answer =0
a.sort(reverse = True)
if len(b) > len(a):
answer = int(''.join(a))
else:
for k in range(len(a)-1):
if int(a[k]) > int(b[k]):
l =1;
while int(a[k+l]) > int(b[k]):
l +=1
a[k],a[k+l] = a[k+l],a[k]
answer = int(''.join(a))
if answer < nub:
break;
else:
continue
elif int(a[k]) == int(b[k]):
answer = int(''.join(a))
if answer < nub:
break;
else:
continue
else :
answer = int(''.join(a))
break
print (answer)
``` | instruction | 0 | 29,707 | 20 | 59,414 |
No | output | 1 | 29,707 | 20 | 59,415 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940
Submitted Solution:
```
# @oj: codeforces
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-11-17 11:11
# @url:https://codeforc.es/contest/915/problem/C
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio
BUFSIZE = 8192
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")
# ------------------------------
## 注意嵌套括号!!!!!!
## 先有思路,再写代码,别着急!!!
## 先有朴素解法,不要有思维定式,试着换思路解决
## 精度 print("%.10f" % ans)
## sqrt:int(math.sqrt(n))+1
## 字符串拼接不要用+操作,会超时
## 二进制转换:bin(1)[2:].rjust(32,'0')
## array copy:cur=array[::]
## oeis:example 1, 3, _, 1260, _, _, _, _, _, 12164510040883200
def main():
a=int(input())
b=int(input())
if len(str(a))<len(str(b)):
ans=sorted(list(str(a)),reverse=True)
print ("".join(ans))
return
cnt=[0]*10
for i in range(len(str(a))):
cnt[int(str(a)[i])]+=1
ans=[]
f=True
for x in [int(i) for i in str(b)]:
mx=-1
for j in range(10):
if cnt[j]>0:
if j<=x:
mx=max(mx,j)
if mx==-1:
f=False
break
if mx<x:
cnt[mx]-=1
ans.append(mx)
break
if mx==x:
cnt[x]-=1
ans.append(x)
# print (cnt)
res=[]
for i in range(10):
if cnt[i]>0:
res+=[i]*cnt[i]
sr=sorted(res,reverse=True)
# print (ans,f,sr)
if f:
tmp=ans+sr
print ("".join([str(x) for x in tmp]))
else:
n=len(str(a))
for i in range(len(sr)):
if len(ans)>0 and sr[i]<ans[-1]:
ans[-1],sr[i]=sr[i],ans[-1]
print ("".join([str(x) for x in (ans+sr)]))
return
for i in range(len(ans)-1,-1,-1):
if len(ans)>0 and ans[i]>ans[-1]:
ans[i],ans[-1]=ans[-1],ans[i]
tmp=ans[:i+1]+sorted(ans[i+1:]+sr,reverse=True)
print ("".join([str(x) for x in tmp]))
return
print (a)
if __name__ == "__main__":
main()
``` | instruction | 0 | 29,708 | 20 | 59,416 |
No | output | 1 | 29,708 | 20 | 59,417 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940
Submitted Solution:
```
s=input(); q=input(); ans=""
m=sorted(list(map(str,s)),reverse=True)
if len(s)<len(q):
ans="".join(m)
else:
s1=list(map(str,s))
for i in q:
if i in s1:
ans+=i; s1.remove(i)
else:
break
boo=False
if len(ans)!=len(q):
s1+=[q[0]]
ind=sorted(s1).index(q[0])
ans+=s1[max(ind-1,0)]
s1.remove(q[0])
s1.remove(s[ind-1])
boo=True
dif=len(q)-len(ans);
remain="".join(sorted(s1,reverse=True))
ans+=remain[0:max(1,dif)]
print(ans)
``` | instruction | 0 | 29,709 | 20 | 59,418 |
No | output | 1 | 29,709 | 20 | 59,419 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940
Submitted Solution:
```
def x(a,b):
#print('dsahhf ',a,b)
l = len(a)
if len(a) < len(b):
return(''.join(sorted(a,reverse = True)))
elif l>len(b):
#print(a,a[:-1])
return '0' + x(a[1:],b)
else:
f = True
if l ==0:return ''
for i in range(l):
if a[i-l]>b[i]:
F = False
elif a[l-1] < b[i]:break
if not f:return -1
a = list(a)
a.sort(reverse = True)
o = ''
if b[0] in a:
f = a.index(b[0])
t = x(a[:f]+a[f+1:],b[1:])
#print(t,a[:f]+a[f+1:],b[1:])
f2 = -1
if t == -1:
m = '9'
f2 = 0
for i in range(l-1,-1,-1):
if a[i] > b[0]:
break
m = a[i]
f2 = i
#print(a,f2,m)
#print(a[:f2],a[f2+1:])
return m+''.join(a[:f2])+''.join(a[f2+1:])
else:return b[0]+t
else:
m = '9'
f2 = 0
for i in range(l-1,-1,-1):
if a[i] > b[0]:
break
m = a[i]
f2 = i
#print(a,f2,m)
#print(a[:f2],a[f2+1:])
return m+''.join(a[:f2])+''.join(a[f2+1:])
a = input()
b = input()
print(int(x(list(sorted(a)),b)))
``` | instruction | 0 | 29,710 | 20 | 59,420 |
No | output | 1 | 29,710 | 20 | 59,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits. | instruction | 0 | 30,077 | 20 | 60,154 |
Tags: math, sortings
Correct Solution:
```
import sys
n = int(input())
sizes = list(map(int, input().split()))
sizes.sort()
need = 0
for i in range(1, len(sizes)):
a, b = sizes[i-1], sizes[i]
if a == b:
continue
if a != 1:
a *= 2
if a > b:
print('YES')
sys.exit()
print('NO')
``` | output | 1 | 30,077 | 20 | 60,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits. | instruction | 0 | 30,078 | 20 | 60,156 |
Tags: math, sortings
Correct Solution:
```
I=input
R=range(int(I())-1)
a=sorted(map(int,I().split()))
s='NO'
for i in R:
if a[i]<a[i+1]and a[i]*2>a[i+1]:s='YES'
print(s)
``` | output | 1 | 30,078 | 20 | 60,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits. | instruction | 0 | 30,079 | 20 | 60,158 |
Tags: math, sortings
Correct Solution:
```
input()
b={int(x)for x in input().split()}
b=sorted(list(b))
for i in range(1,len(b)):
if 2*b[i-1]>b[i]:
print("YES")
break
else:print("NO")
``` | output | 1 | 30,079 | 20 | 60,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits. | instruction | 0 | 30,080 | 20 | 60,160 |
Tags: math, sortings
Correct Solution:
```
def datatypes(x,answer):
for i in range(1,n):
if x[i]<2*x[i-1] and x[i]!=x[i-1]:
answer="YES"
break
print(answer)
n=int(input())
x = list(map(int,input().split()))
x.sort()
answer="NO"
datatypes(x,answer)
``` | output | 1 | 30,080 | 20 | 60,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits. | instruction | 0 | 30,081 | 20 | 60,162 |
Tags: math, sortings
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
l.sort()
done=0
for i in range(n-1):
if l[i]<l[i+1] and 2*l[i]>l[i+1]:
done=1
break
if done==1:
print('YES')
else:
print('NO')
``` | output | 1 | 30,081 | 20 | 60,163 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits. | instruction | 0 | 30,082 | 20 | 60,164 |
Tags: math, sortings
Correct Solution:
```
n = (int)(input())
flag = True
a = list(map(int,input().split()))
a.sort()
for x in range(1,len(a)):
if a[x] < 2 *a[x-1] and a[x] != a[x-1]:
print('YES')
flag = False
break
if flag:
print('NO')
``` | output | 1 | 30,082 | 20 | 60,165 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits. | instruction | 0 | 30,083 | 20 | 60,166 |
Tags: math, sortings
Correct Solution:
```
n=int(input())-1
a=sorted(map(int,input().split()))
ans='NO'
for i in range(n):
if a[i]<a[i+1]and a[i]*2>a[i+1]:
ans='YES'
print(ans)
``` | output | 1 | 30,083 | 20 | 60,167 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits. | instruction | 0 | 30,084 | 20 | 60,168 |
Tags: math, sortings
Correct Solution:
```
#!/usr/bin/env python3
n = int(input())
a = sorted(list(map(int, input().split())))
ok = True
for i in range(1, len(a)):
if a[i] != a[i-1] and a[i-1] * 2 > a[i]:
ok = False
break
print("NO" if ok else "YES")
``` | output | 1 | 30,084 | 20 | 60,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
Submitted Solution:
```
n = int(input())
lis = sorted(map(int,input().split()))
c=0
#print(lis)
for i in range(n-1,0,-1):
if lis[i]<lis[i-1]*2 and lis[i]!=lis[i-1]:
c=1
break
if c:
print("YES")
else:
print("NO")
``` | instruction | 0 | 30,085 | 20 | 60,170 |
Yes | output | 1 | 30,085 | 20 | 60,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
Submitted Solution:
```
n, t = int(input()) - 1, sorted(list(map(int, input().split())))
print('YNEOS'[all(2 * t[i] <= t[i + 1] for i in range(n) if t[i] < t[i + 1]) :: 2])
# Made By Mostafa_Khaled
``` | instruction | 0 | 30,086 | 20 | 60,172 |
Yes | output | 1 | 30,086 | 20 | 60,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
Submitted Solution:
```
n = int(input())
A = sorted(list(set(map(int, input().split()))))
good = True
for i in range(1, len(A)):
if A[i - 1] * 2 > A[i]:
good = False
if not good:
print("YES")
else:
print("NO")
``` | instruction | 0 | 30,087 | 20 | 60,174 |
Yes | output | 1 | 30,087 | 20 | 60,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
Submitted Solution:
```
from sys import *
n=int(stdin.readline())
a=[int(z) for z in stdin.readline().split()]
a.sort()
na=[a[0]]
for i in a:
if i>na[-1]:
na.append(i)
for i in range(1,len(na)):
if na[i]<2*na[i-1]:
stdout.write("YES\n")
exit(0)
stdout.write("NO\n")
``` | instruction | 0 | 30,088 | 20 | 60,176 |
Yes | output | 1 | 30,088 | 20 | 60,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
Submitted 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
from itertools import permutations
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
n=int(input())
a=list(map(int,input().split()))
a.sort()
if a[-1]>2*a[-2]:
print("YES")
else:
print("NO")
``` | instruction | 0 | 30,089 | 20 | 60,178 |
No | output | 1 | 30,089 | 20 | 60,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
Submitted Solution:
```
n = int(input())
sp = sorted(list(map(int, input().split())))
fi = 2 ** (sp[n - 2]) - 1
se = 2 ** (sp[n - 1]) - 1
if fi ** 2 >= se:
print("YES")
else:
print("NO")
``` | instruction | 0 | 30,090 | 20 | 60,180 |
No | output | 1 | 30,090 | 20 | 60,181 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
l=set(l)
l=list(l)
l.sort()
done=0
for i in range(len(l)-1):
if l[i]>5:
if l[i+1]!=2*l[i] and l[i+1]!=(2*l[i]-1):
done=1
elif l[i]==3:
if l[i+1]==5 and l[i+1]==6:
done=1
elif l[i]==2:
if l[i+1]!=3:
done=1
elif l[i]==4:
if l[i+1]!=7 and l[i+1]!=8:
done=1
elif l[i]==5:
if l[i+1]!=8 and l[i+1]!=9 and l[i+1]!=9:
done=1
elif l[i]==1:
if l[i+1]!=1:
done=1
if done==1:
print('YES')
else:
print('NO')
``` | instruction | 0 | 30,091 | 20 | 60,182 |
No | output | 1 | 30,091 | 20 | 60,183 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
Submitted Solution:
```
input()
d_arr = list(set([int(z) for z in input().split(" ")]))
a = len(d_arr)
d_arr.sort()
#print(d_arr)
found = True
for i in range(0, a - 1):
#print(d_arr[i]*2)
#print("i am hgere")
#print(val)
if d_arr[i]*2 > d_arr[a - 1]:
found = False
break
if not found:
print("YES")
else:
print("NO")
``` | instruction | 0 | 30,092 | 20 | 60,184 |
No | output | 1 | 30,092 | 20 | 60,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 | 30,229 | 20 | 60,458 |
Tags: bitmasks, dp, graphs, greedy
Correct Solution:
```
N,K=map(int,input().split())
arr=[list(input()) for _ in range(N)]
dp=[[False]*(K+1) for _ in range(N+1)]
dp[0][0]=True
costs=[[] for _ in range(2**7)]
digits=["1110111","0010010","1011101","1011011","0111010","1101011","1101111","1010010","1111111","1111011"]
for i in range(2**7):
bits=format(i,'b')
if len(bits)!=7:
bits='0'*(7-len(bits))+bits
for digit in digits:
tmp=0
for j in range(7):
if bits[j]=='0' and digit[j]=='1':
tmp+=1
elif bits[j]=='1' and digit[j]=='0':
break
else:
costs[i].append(tmp)
for i in range(2**7):
costs[i]=list(set(costs[i]))
for i in range(N):
tmp=0
for k in range(7):
if arr[N-i-1][k]=='1':
tmp+=2**(6-k)
for j in range(K,-1,-1):
for c in costs[tmp]:
if j-c>=0 and dp[i][j-c]==True:
dp[i+1][j]=True
ans=''
for i in range(N):
for j in range(9,-1,-1):
cost=0
for k in range(7):
if arr[i][k]=='0' and digits[j][k]=='1':
cost+=1
elif arr[i][k]=='1' and digits[j][k]=='0':
break
else:
if K-cost>=0 and dp[N-i-1][K-cost]==True:
ans+=str(j)
K-=cost
break
else:
print(-1)
break
else:
print(ans)
``` | output | 1 | 30,229 | 20 | 60,459 |
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 | 30,230 | 20 | 60,460 |
Tags: bitmasks, dp, graphs, greedy
Correct Solution:
```
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
# sys.setrecursionlimit(200000)
# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def tinput():
return input().split()
def rinput():
return map(int, tinput())
def rlinput():
return list(rinput())
# mod = int(1e9)+7
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
# ----------------------------------------------------
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
digits = ["1110111", "0010010", "1011101", "1011011", "0111010",
"1101011", "1101111", "1010010", "1111111", "1111011"]
if __name__ == "__main__":
n, k = rinput()
s = [input() for _ in range(n)]
howmany = [[0 for i in range(10)]for i in range(n)]
for i in range(n):
for d in range(10):
cnt = 0
a, b = s[i], digits[d]
for j in range(7):
if a[j] is '1' and b[j] is '0':
cnt = -1
break
elif a[j] is '0' and b[j] is '1':
cnt += 1
howmany[i][d] = cnt
canmake = [[False for i in range(k+1)]for i in range(n+1)]
canmake[n][0]=True
for i in range(n, 0, -1):
for j in range(k+1):
if canmake[i][j]:
for d in range(10):
if howmany[i-1][d]!=-1 and j+howmany[i-1][d] <=k:
canmake[i-1][j+howmany[i-1][d]] = True
if not canmake[0][k]:
print(-1)
sys.exit()
ans = ''
for i in range(n):
for d in range(9,-1,-1):
if howmany[i][d]!=-1 and k>=howmany[i][d] and canmake[i+1][k-howmany[i][d]]:
ans+=str(d)
k-=howmany[i][d]
break
print(ans)
``` | output | 1 | 30,230 | 20 | 60,461 |
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 | 30,231 | 20 | 60,462 |
Tags: bitmasks, dp, graphs, greedy
Correct Solution:
```
n, k = map(int, input().split())
bins = [input() for _ in range(n)]
digits = [
'1110111',
"0010010",
"1011101",
"1011011",
"0111010",
"1101011",
"1101111",
"1010010",
"1111111",
"1111011"
]
memo = [[-1 for _ in range(k+1)] for _ in range(n+1)]
memo[n][0] = 0
def foo(u, p):
d = 0
for cu, cp in zip(u, p):
if cu > cp:
return -1
d += cu != cp
return d
for i in range(n-1, -1, -1):
for m, s in enumerate(digits):
d = foo(bins[i], s)
if d == -1:
continue
for j in range(k+1-d):
recu = memo[i+1][j]
if recu == -1:
continue
memo[i][j+d] = 10 * d + m
if memo[0][k] >= 0:
for i in range(n):
print(memo[i][k] % 10, end='')
k -= memo[i][k] // 10
print()
else:
print(-1)
``` | output | 1 | 30,231 | 20 | 60,463 |
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 | 30,232 | 20 | 60,464 |
Tags: bitmasks, dp, graphs, greedy
Correct Solution:
```
zero='1110111'
one='0010010'
two='1011101'
three='1011011'
four="0111010"
five="1101011"
six="1101111"
seven= "1010010"
eight="1111111"
nine="1111011"
numbers=[nine,eight,seven,six,five,four,three,two,one,zero]
n,k2=map(int,input().split())
bank=0
completefail=0
listofusage=[]
listofbestnums=[]
lamps=[]
def convert(s):
# initialization of string to ""
new = ""
# traverse in the string
for x in s:
new += x
# return string
return new
for i in range(n):
lamp=input()
lamps.append(lamp)
maxusage=100
bestnum=''
for j in numbers:
fail=0
usage=0
for k in range(7):
if j[k]=='0' and lamp[k]=='1':
fail=1
if j[k]=='1' and lamp[k]=='0':
usage+=1
if fail==1:
continue
if usage<maxusage:
bestnum=j
maxusage=usage
if maxusage==100:
completefail=1
break
listofusage.append(maxusage)
listofbestnums.append(bestnum)
if completefail==1 or sum(listofusage)>k2:
print(-1)
else:
ans=[]
bank=k2-sum(listofusage)
for i in range(n-1):
lamp=lamps[i]
change=0
for j in numbers:
fail=0
usage=0
for k in range(7):
if j[k]=='0' and lamp[k]=='1':
fail=1
if j[k]=='1' and lamp[k]=='0':
usage+=1
if fail==1:
continue
if usage-listofusage[i]<=bank:
change=1
bank-=usage-listofusage[i]
break
if change==0:
ans.append(listofbestnums[i])
else:
ans.append(j)
totalfail=0
if bank>7-listofusage[n-1]:
j=n-2
const=bank-7+listofusage[n-1]
for i in range(const):
if j==-1:
totalfail=1
break
if ans[j]==eight:
i-=1
j-=1
continue
ans[j]=eight
bank-=1
j-=1
lamp=lamps[n-1]
change=0
for j in numbers:
fail=0
usage=0
for k in range(7):
if j[k]=='0' and lamp[k]=='1':
fail=1
if j[k]=='1' and lamp[k]=='0':
usage+=1
if fail==1:
continue
if usage-listofusage[n-1]==bank:
change=1
bank-=usage-listofusage[n-1]
break
if change==0:
ans.append(listofbestnums[n-1])
else:
ans.append(j)
if totalfail==1 or not(bank==0):
print(-1)
else:
printans=[]
for i in range(n):
for j in range(10):
if ans[i]==numbers[j]:
printans.append(str(9-j))
break
print(convert(printans))
``` | output | 1 | 30,232 | 20 | 60,465 |
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 | 30,233 | 20 | 60,466 |
Tags: bitmasks, dp, graphs, greedy
Correct Solution:
```
from sys import stdin
from collections import Counter, deque
#input = stdin.buffer.readline
nm = ["1110111", "0010010", "1011101", "1011011", "0111010",
"1101011", "1101111", "1010010", "1111111", "1111011"]
n, k = map(int, input().split())
sg = []
for _ in range(n): sg.append(input())
def get_conv(fm, nm):
ls = []
for num, to in enumerate(nm):
cc = 0
for i in range(7):
if fm[i] == to[i]:
pass
elif fm[i] == '0' and to[i] == '1':
cc += 1
else:
break
else:
ls.append((num, cc))
return ls
dp = [ [0]*(k+1) for _ in range(n+1) ]
dp[n][k] = 1
for i in reversed(range(n)):
conv = get_conv(sg[i], nm)
for j in range(k+1):
if not dp[i+1][j]: continue
for num, cc in conv:
if j-cc >= 0: dp[i][j-cc] = 1
if not dp[0][0]: print(-1); exit()
res, p = [], 0
for i in range(n):
conv = get_conv(sg[i], nm)
for num, cc in reversed(conv):
if p+cc <= k and dp[i+1][p+cc]:
res.append(num)
p += cc
break
print(''.join(map(str, res)))
``` | output | 1 | 30,233 | 20 | 60,467 |
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 | 30,234 | 20 | 60,468 |
Tags: bitmasks, dp, graphs, greedy
Correct Solution:
```
import sys
import bisect
input=sys.stdin.readline
#t=int(input())
t=1
for _ in range(t):
#n=int(input())
n,k=map(int,input().split())
count=[[-1]*10 for j in range(n)]
l=["1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"]
d={}
for i in range(n):
d[i]=[]
for i in range(n):
d[i]=input()
for j in range(10):
cnt=0
for j1 in range(7):
if l[j][j1]=='0' and d[i][j1]=='1':
cnt=-1
break
else:
if l[j][j1]!=d[i][j1]:
cnt+=1
if cnt!=-1:
count[i][j]=cnt
ans=[[0]*(k+1) for j in range(n+1)]
ans[n][0]=1
#print(ans)
for i in range(n,0,-1):
for j in range(k+1):
if ans[i][j]==1:
for i1 in range(10):
if count[i-1][i1]!=-1 and j+count[i-1][i1]<=k:
ans[i-1][j+count[i-1][i1]]=1
if (ans[0][k]==0):
print(-1)
else:
for i in range(n):
for j in range(9,-1,-1):
#print(j,k-count[i][j],ans[i+1][k-count[i][j]])
if (count[i][j]!=-1 and count[i][j]<=k and ans[i+1][k-count[i][j]]==1):
maxi=j
k-=count[i][j]
break
print(maxi,end="")
``` | output | 1 | 30,234 | 20 | 60,469 |
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 | 30,235 | 20 | 60,470 |
Tags: bitmasks, dp, graphs, greedy
Correct Solution:
```
digits_b = ["1110111", "0010010", "1011101", "1011011", "0111010",
"1101011", "1101111", "1010010", "1111111", "1111011"]
counts = [s.count('1') for s in digits_b]
digits_num = [int(s, 2) for s in digits_b]
nn, kk = map(int, input().split())
poss = [[] for i in range(nn)]
for i in range(nn):
s = input()
count = s.count('1')
num = int(s, 2)
for d in range(9, -1, -1):
if num & digits_num[d] == num:
poss[i].append((d, counts[d] - count))
dp = [[0 for __ in range(kk+1)] for _ in range(nn+1)]
dp[0][0] = 1
for n in range(nn):
for k in range(kk+1):
if not dp[n][k]:
continue
for _, c in poss[nn-n-1]:
if c + k > kk:
continue
dp[n+1][k+c] = 1
out = []
if dp[nn][kk]:
for n in range(nn):
for nx, c in poss[n]:
if c > kk or not dp[nn-1-n][kk-c]:
continue
kk -= c
out.append(nx)
break
print(''.join(map(str, out)))
else:
print(-1)
``` | output | 1 | 30,235 | 20 | 60,471 |
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 | 30,236 | 20 | 60,472 |
Tags: bitmasks, dp, graphs, greedy
Correct Solution:
```
import sys
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
def li(): return [int(i) for i in input().split()]
def lli(rows): return [li() for _ in range(rows)]
def si(): return input()
def ii(): return int(input())
def ins(): return input().split()
val=[119, 18, 93, 91, 58, 107, 111, 82, 127, 123]
cnt=[6,2,5,5,4,5,6,3,7,6]
n,k=MI()
nums,count=[],[]
for i in range(n):
s=SI()
curr,c=0,0
for j in range(7):
if s[j]=='1':
curr+=(1<<(6-j))
c+=1
nums.append(curr)
count.append(c)
req=[[-1 for j in range(10)] for i in range(n)]
for i in range(n):
for j in range(10):
if(nums[i]|val[j]==val[j]):
req[i][j]=cnt[j]-count[i]
dp=[[-1 for j in range(k+1)] for i in range(n+1)]
dp[n][0]=0
for i in range(n-1,-1,-1):
for j in range(k+1):
for d in range(10):
if req[i][d]!=-1 and j>=req[i][d] and dp[i+1][j-req[i][d]]!=-1:
dp[i][j]=d
if dp[0][k]==-1:
print(-1)
else:
ans=[]
for i in range(n):
ans.append(str(dp[i][k]))
k-=req[i][dp[i][k]]
print(''.join(ans))
``` | output | 1 | 30,236 | 20 | 60,473 |
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:
```
numbers=["1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"]
n,m = list(map(int,input().split()))
changes = [[0]*(10) for i in range(n)]
for i in range(n) :
s = input()
for j in range(10) :
count = 0
for k in range(7) :
if numbers[j][k] == '1' and s[k] == '0' :
count +=1
elif numbers[j][k] == '0' and s[k] == '1' :
count = -1
break
changes[i][j] = count
dp = [[0]*(m+1) for i in range(n+1)]
dp[n][0] = 1
for i in range(n,0,-1) :
for j in range(m+1) :
if dp[i][j]:
for k in range(10) :
if changes[i-1][k] != -1 and changes[i-1][k] + j <= m :
dp[i-1][j + changes[i-1][k]] =1
if dp[0][m] ==0 :
print(-1)
else :
for i in range(n) :
num = 0
for j in range(9,-1,-1) :
if changes[i][j] != -1 and m >= changes[i][j] and dp[i+1][m - changes[i][j]]:
num = j
m -= changes[i][j]
break
print(num ,end = '')
``` | instruction | 0 | 30,237 | 20 | 60,474 |
Yes | output | 1 | 30,237 | 20 | 60,475 |
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
from typing import List
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s)]))
def invr():
return(map(int,input().split()))
def get_digit_masks():
digits = [ [1,2,5,7,6,3],
[3,6],
[1,3,4,5,7],
[1,3,4,6,7],
[2,4,3,6],
[1,2,4,6,7],
[1,2,4,5,6,7],
[1,3,6],
[1,2,3,4,5,6,7],
[1,2,3,4,6,7]]
digit_mask = []
for sticks in digits:
mask = 0
for i in sticks:
mask |= (1 << (i-1))
digit_mask.append(mask)
return digit_mask
def fill_transitions(digit_mask) -> List[List[int]]:
options = 2 ** 7
T = [[-1] * 10 for _ in range(options)]
for cur in range(options):
for d in range(10):
# how many sticks can we lighten to get digit d from cur?
if cur == 37 and d == 7:
gg = 0
dmask = digit_mask[d]
k = get_diff(cur, dmask)
if k == -1:
continue
T[cur][d] = k
return T
def find_max_digit(T, A: List[int], index, budget, dp) -> int:
# what is the max digit we can get at index i if we have budget?
if index == len(A):
if budget == 0:
return 0
return -1
if dp[index][budget] is not None:
return dp[index][budget]
cur = A[index]
for d in range(9, -1, -1):
r = T[cur][d]
if r == -1:
continue
if r <= budget:
rec = find_max_digit(T, A, index+1, budget-r, dp)
if rec != -1:
dp[index][budget] = d
return d
else:
# finished without a break
dp[index][budget] = -1
return -1
def from_file(f):
return f.readline
def get_diff(a, b):
"""
How many sticks to add to a to get b?
"""
# print("{0:7b}".format(a))
# print("{0:7b}".format(b))
intersection = a & b
if intersection != a:
return -1
b -= intersection
k = 0
while b != 0:
if b & 1 == 1:
k += 1
b >>= 1
return k
A = []
d_to_mask = get_digit_masks()
T = fill_transitions(d_to_mask)
# with open('4.txt') as f:
# input = from_file(f)
# n, K = invr()
# for _ in range(n):
# s = insr()
# d = 0
# for i,c in enumerate(s):
# if c == '1':
# d |= 1 << i
# # print("{0:7b}".format(d))
# A.append(d)
# # max digit at pos i for budget k
# dp = [[-1] * (K + 1) for _ in range(n + 1)]
# dp[n][0] = 0
#
# for index in range(n-1, -1, -1):
# for d in range(9, -1, -1):
# diff = get_diff(A[index], d_to_mask[d])
# if diff == -1:
# continue
# #dp[index+1][k] are filled for some k
# for k in range(diff, K+1):
# if dp[index+1][k-diff] >= 0:
# dp[index][k] = max(d, dp[index][k])
#
# if dp[0][K] == -1:
# print('-1')
# else:
# res = []
# for index in range(n):
# res.append(dp[index][K])
# K -= get_diff(A[index], d_to_mask[dp[index][K]])
# print("".join(map(str,res)))
n, K = invr()
for _ in range(n):
s = insr()
d = 0
for i,c in enumerate(s):
if c == '1':
d |= 1 << i
# print("{0:7b}".format(d))
A.append(d)
# max digit at pos i for budget k
dp = [[-1] * (K + 1) for _ in range(n + 1)]
dp[n][0] = 0
for index in range(n-1, -1, -1):
for d in range(9, -1, -1):
diff = get_diff(A[index], d_to_mask[d])
if diff == -1:
continue
#dp[index+1][k] are filled for some k
for k in range(diff, K+1):
if dp[index+1][k-diff] >= 0:
dp[index][k] = max(d, dp[index][k])
if dp[0][K] == -1:
print('-1')
else:
res = []
for index in range(n):
res.append(dp[index][K])
K -= get_diff(A[index], d_to_mask[dp[index][K]])
print("".join(map(str,res)))
``` | instruction | 0 | 30,238 | 20 | 60,476 |
Yes | output | 1 | 30,238 | 20 | 60,477 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.