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.
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:
```
maxk=2005
def xcost(s,d):
price=0
for i in range(7):
if s[i]=='1' and d[i]=='0':
price=maxk #cant convert
break
elif s[i]=='0' and d[i]=='1':
price+=1
return price
s=['1110111','0010010','1011101','1011011','0111010','1101011','1101111','1010010','1111111','1111011']
p=[bin(i)[2:].zfill(7) for i in range(128)]
cost=[[xcost(p[i],s[j]) for j in range(10)] for i in range(128)]
n,k=map(int,input().split(" "))
scoreboard=[int(input(),2) for i in range(n)]
dp=[[False for i in range(k+1)] for j in range(n)]
bit_int=scoreboard[n-1]
for j in cost[bit_int]:
if j<=k:
dp[n-1][j]=True
for i in range(n-2,-1,-1):
bit_int=scoreboard[i]
for j in range(k+1):
for x in cost[bit_int]:
if j>=x and dp[i+1][j-x]:
dp[i][j]=True
break
if dp[0][k]:
ans=[]
for pos,i in enumerate(scoreboard):
for j in range(9,-1,-1):
v=cost[i][j]
if pos==n-1 and k==v:
ans.append(str(j))
break
elif pos<n-1 and k>=v and dp[pos+1][k-v]:
ans.append(str(j))
k-=v
break
print("".join(ans))
else:
print(-1)
``` | instruction | 0 | 30,239 | 20 | 60,478 |
Yes | output | 1 | 30,239 | 20 | 60,479 |
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:
```
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
digs = ["1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"]
def chg(pat,c):
dig = digs[c]
cnt = 0
for i in range(7):
if pat[i]=='0' and dig[i]=='1':
cnt += 1
if pat[i]=='1' and dig[i]=='0':
return 9
return cnt
n,k = inm()
pats = []
chgh = {}
for i in range(n):
p =ins()
a = []
for m in range(10):
a.append(chg(p,m))
chgh[p] = a
pats.append(p)
d = [[0]*(k+1) for i in range(n+1)]
d[n][0] = 1
for i in range(n-1,-1,-1):
p =pats[i]
for j in range(k+1):
if d[i+1][j]==0:
continue
for m in range(10):
v = chgh[p][m] # chg(p,m)
if v<9 and j+v<=k:
d[i][j+v] = 1
if d[0][k]==0:
print(-1)
exit()
ans = []
x = k
for i in range(n):
p = pats[i]
for m in range(9,-1,-1):
v = chgh[p][m] # chg(p,m)
if v<9 and x-v>=0 and d[i+1][x-v]==1:
ans.append(str(m))
x -= v
break
print(''.join(ans))
``` | instruction | 0 | 30,240 | 20 | 60,480 |
Yes | output | 1 | 30,240 | 20 | 60,481 |
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,os,io
# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
input = sys.stdin.readline
def cout(a):
for i in a:
print(i,end="")
print()
n,m = [int(i) for i in input().split()]
a = []
b = [[1,1,1,0,1,1,1],[0,0,1,0,0,1,0],[1,0,1,1,1,0,1],[1,0,1,1,0,1,1],[0,1,1,1,0,1,0],[1,1,0,1,0,1,1],[1,1,0,1,1,1,1],[1,0,1,0,0,1,0],[1,1,1,1,1,1,1],[1,1,1,1,0,1,1]]
for i in range (n):
a.append([int(i) for i in input().strip()])
cnt = [0]*n
for i in range (n):
mini = 7
for j in range (9,-1,-1):
cs = 0
for k in range (7):
if a[i][k]==1 and b[j][k]==0:
cs = 10
break
if a[i][k]==0 and b[j][k]==1:
cs+=1
mini = min(cs, mini)
cnt[i] = mini
cnt1 = [0]*(n+1)
for i in range (n):
cnt1[i] = 7-sum(a[i])
for i in range (n-2, -1, -1):
cnt[i]+=cnt[i+1]
cnt1[i]+=cnt1[i+1]
cnt.append(0)
if cnt[0]>m or m>cnt1[0]:
print(-1)
exit()
extra = m
final = []
if n==1:
for i in range (n):
for j in range (9, -1, -1):
cs = 0
for k in range (7):
if a[i][k]==1 and b[j][k]==0:
cs = -1
break
if a[i][k]==0 and b[j][k]==1:
cs += 1
if cs==-1:
continue
if (extra - cs)>= cnt[i+1] and (extra - cs)<=cnt1[i+1]:
final.append(j)
extra -= cs
break
for i in final:
print(i,end="")
print()
exit()
lastcs = 0
for i in range (n-2):
for j in range (9, -1, -1):
cs = 0
for k in range (7):
if a[i][k]==1 and b[j][k]==0:
cs = -1
break
if a[i][k]==0 and b[j][k]==1:
cs += 1
if cs==-1:
continue
if (extra - cs)>= cnt[i+1] and (extra - cs)<=cnt1[i+1]:
final.append(j)
extra -= cs
lastcs = cs
break
if n>=3:
extra += lastcs
available1 = set()
available2 = set()
for i in range (1,3):
for j in range (9, -1, -1):
cs = 0
for k in range (7):
if a[-i][k]==1 and b[j][k]==0:
cs = -1
break
if a[-i][k]==0 and b[j][k]==1:
cs += 1
if cs==-1:
continue
if i==1:
available1.add(cs)
else:
available2.add(cs)
if n==2:
available = list(available1)
for i in range (n-2, n):
for j in range (9, -1, -1):
cs = 0
for k in range (7):
if a[i][k]==1 and b[j][k]==0:
cs = -1
break
if a[i][k]==0 and b[j][k]==1:
cs += 1
if cs==-1:
continue
if (extra - cs)>= cnt[i+1] and (extra - cs)<=cnt1[i+1] and (extra - cs)in available:
final.append(j)
available = [0]
extra -= cs
break
else:
if len(final):
final.pop()
available = []
for i in available1:
for j in available2:
available.append(i+j)
i = n-3
for j in range (9, -1, -1):
cs = 0
for k in range (7):
if a[n-3][k]==1 and b[j][k]==0:
cs = -1
break
if a[n-3][k]==0 and b[j][k]==1:
cs += 1
if cs==-1:
continue
if (extra - cs)>= cnt[i+1] and (extra - cs)<=cnt1[i+1] and (extra - cs)in available:
final.append(j)
extra -= cs
break
available = list(available1)
for i in range (n-2, n):
for j in range (9, -1, -1):
cs = 0
for k in range (7):
if a[i][k]==1 and b[j][k]==0:
cs = -1
break
if a[i][k]==0 and b[j][k]==1:
cs += 1
if cs==-1:
continue
if (extra - cs)>= cnt[i+1] and (extra - cs)<=cnt1[i+1] and (extra - cs)in available:
final.append(j)
available = [0]
extra -= cs
break
for i in final:
print(i,end="")
print()
``` | instruction | 0 | 30,241 | 20 | 60,482 |
No | output | 1 | 30,241 | 20 | 60,483 |
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
lines = sys.stdin.readlines()
# nums = lists(map(int, lines[0].strip().split(" ")))
``` | instruction | 0 | 30,242 | 20 | 60,484 |
No | output | 1 | 30,242 | 20 | 60,485 |
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:
```
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 not(ans[j]==nine):
i-=1
j-=1
continue
ans[j]=eight
bank-=1
j-=1
lamp=lamps[n-1]
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)
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))
``` | instruction | 0 | 30,243 | 20 | 60,486 |
No | output | 1 | 30,243 | 20 | 60,487 |
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
lines = sys.stdin.readlines()
# nums = list(map(int, lines[0].strip().split(" ")))
(n, k) = map(int, lines[0].strip().split(" "))
strings = []
for i in range(1, n+1):
strings.append(lines[i].strip())
encoding = ["1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"]
cnt = []
for i in range(10):
cnt.append(encoding[i].count("1"))
relation = {}
def possible(s):
if s in relation: return relation[s]
res = []
num = int(s, 2)
ones = s.count("1")
seen = set()
m, M = 7, 0
for i in range(9, -1, -1):
xor = bin(int(encoding[i], 2) ^ num)[2:].count("1")
if xor in seen: continue
else: seen.add(xor)
if ones + xor == cnt[i]:
res.append((str(i), xor))
m = min(m, xor)
M = max(M, xor)
relation[s] = [res, m, M]
return [res, m, M]
combi = []
mini, maxi = [], []
for s in strings:
tmp = possible(s)
combi.append(tmp[0])
mini.append(tmp[1])
maxi.append(tmp[2])
for i in range(n-2, -1, -1):
mini[i] += mini[i+1]
maxi[i] += maxi[i+1]
def solve(pt, k):
if k < mini[pt] or k > maxi[pt]: return -1
L = len(combi[pt])
if pt == n-1:
for i in range(L):
if k == combi[pt][i][1]: return combi[pt][i][0]
return -1
for i in range(L):
res = solve(pt+1, k-combi[pt][i][1])
if res != -1: return combi[pt][i][0] + res
return -1
res = solve(0, k)
print(res)
``` | instruction | 0 | 30,244 | 20 | 60,488 |
No | output | 1 | 30,244 | 20 | 60,489 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234 | instruction | 0 | 30,446 | 20 | 60,892 |
Tags: greedy
Correct Solution:
```
def main():
a, k = input().split()
k = int(k)
a = list(a)
n = len(a)
for i in range(n):
idx_max = max(range(i, min(i + k + 1, n)), key=a.__getitem__)
a.insert(i, a.pop(idx_max))
k -= idx_max - i
print(''.join(a))
if __name__ == "__main__":
main()
``` | output | 1 | 30,446 | 20 | 60,893 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234 | instruction | 0 | 30,447 | 20 | 60,894 |
Tags: greedy
Correct Solution:
```
s, k = map(str,input().split())
k = int(k)
z = len(s)
for i in range(z):
val = s[i]
ind = i
for j in range(i+1,i+k+1):
if j < len(s) and s[j] > val:
val = s[j]
ind = j
s = s[:i] + s[ind] + s[i:ind] + s[ind + 1:]
k -= ind - i
print(s)
``` | output | 1 | 30,447 | 20 | 60,895 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234 | instruction | 0 | 30,448 | 20 | 60,896 |
Tags: greedy
Correct Solution:
```
arr=list(input().split())
s = list(arr[0])
k = int(arr[1])
ans = []
while s:
x = s.index(max(s[:k+1]))
ans.append(s[x])
s.pop(x)
k-=x
print(''.join(ans))
``` | output | 1 | 30,448 | 20 | 60,897 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234 | instruction | 0 | 30,449 | 20 | 60,898 |
Tags: greedy
Correct Solution:
```
a, k = input().split()
a, k = list(a), int(k)
for i, x in enumerate(a):
if k == 0:
break
vi, v = -1, x
for j, y in enumerate(a[i + 1:min(len(a), i + k + 1)]):
if y > v:
vi, v = j, y
if vi > -1:
del a[i + vi + 1]
a.insert(i, v)
k -= vi + 1
print(''.join(a))
``` | output | 1 | 30,449 | 20 | 60,899 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234 | instruction | 0 | 30,450 | 20 | 60,900 |
Tags: greedy
Correct Solution:
```
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque
def r():
return int(input())
def rm():
return map(int,input().split())
def rl():
return list(map(int,input().split()))
s, k = map(str,input().split())
k = int(k)
s = [int(s[i]) for i in range(len(s))]
n = len(s)
pnt=0
while k!=0 and pnt<n-1:
maxi = max(s[pnt+1:min(k+pnt+1,len(s))])
if maxi<=s[pnt]:
pnt+=1
else:
found=False
for i in range(pnt+1,min(k+pnt+1,n)):
if s[i]==maxi:
found=True
break
if found:
k-=(i-pnt)
s = s[:pnt] + [s[i]] + s[pnt:i] + s[i+1:]
pnt+=1
print(*s,sep='')
``` | output | 1 | 30,450 | 20 | 60,901 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234 | instruction | 0 | 30,451 | 20 | 60,902 |
Tags: greedy
Correct Solution:
```
num,k=map(int,input().split())
num=list(str(num))
ans=[]
while k>0 and len(num)>0 :
c=max(num[0:k+1]) # ζε€§θ¦ηθε΄
ans.append(c)
k-=num.index(c)
num.remove(c)
ans.extend(num)
print(''.join(ans))
``` | output | 1 | 30,451 | 20 | 60,903 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234 | instruction | 0 | 30,452 | 20 | 60,904 |
Tags: greedy
Correct Solution:
```
# Author : nitish420 --------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
mod=10**9+7
# sys.setrecursionlimit(10**6)
def main():
a,k=map(int,input().split())
a=list(map(int,list(str(a))))
j=0
while k:
try:
z=j
mx=a[j]
i=j+1
while i<=min(k+j,len(a)-1):
if a[i]>mx:
mx=a[i]
z=i
i+=1
for l in range(z,j,-1):
a[l]=a[l-1]
a[j]=mx
k-=(z-j)
j+=1
except:
break
print(*a,sep="")
# print(k)
#----------------------------------------------------------------------------------------
def nouse0():
# This is to save my code from plag due to use of FAST IO template in it.
a=420
b=420
print(f'i am nitish{(a+b)//2}')
def nouse1():
# This is to save my code from plag due to use of FAST IO template in it.
a=420
b=420
print(f'i am nitish{(a+b)//2}')
def nouse2():
# This is to save my code from plag due to use of FAST IO template in it.
a=420
b=420
print(f'i am nitish{(a+b)//2}')
# region fastio
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')
def nouse3():
# This is to save my code from plag due to use of FAST IO template in it.
a=420
b=420
print(f'i am nitish{(a+b)//2}')
def nouse4():
# This is to save my code from plag due to use of FAST IO template in it.
a=420
b=420
print(f'i am nitish{(a+b)//2}')
def nouse5():
# This is to save my code from plag due to use of FAST IO template in it.
a=420
b=420
print(f'i am nitish{(a+b)//2}')
# endregion
if __name__ == '__main__':
main()
``` | output | 1 | 30,452 | 20 | 60,905 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234 | instruction | 0 | 30,453 | 20 | 60,906 |
Tags: greedy
Correct Solution:
```
inp, k = map(int, input().split())
inp = list(repr(inp))
ans = []
while len(inp) != 0:
tmp = max(inp[:k + 1])
pos = inp.index(tmp)
k -= pos
ans.append(tmp)
inp.pop(pos)
print(''.join(ans))
``` | output | 1 | 30,453 | 20 | 60,907 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234
Submitted Solution:
```
a,k=map(int,input().split())
a=list(str(a))
b=""
while(len(a)>0):
m=a.index(max(a[:k+1]))
k-=m
b+=a[m]
a.pop(m)
print(b)
# Made By Mostafa_Khaled
``` | instruction | 0 | 30,454 | 20 | 60,908 |
Yes | output | 1 | 30,454 | 20 | 60,909 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234
Submitted Solution:
```
a,k=map(int,input().split())
a=list(str(a))
b=""
while(len(a)>0):
e=max(a[:k+1])
ind=a.index(e)
b+=e
k-=ind
a.pop(ind)
print(b)
``` | instruction | 0 | 30,455 | 20 | 60,910 |
Yes | output | 1 | 30,455 | 20 | 60,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234
Submitted Solution:
```
a,k=input().split()
l=list(a)
k=int(k)
n=len(l)
for i in range(n):
t=l[i]
i1=0
for j in range(i+1,min(i+k+1,n)):
if l[j]>t:
t=l[j]
i1=j
while i1>i:
k-=1
l[i1],l[i1-1]=l[i1-1],l[i1]
i1-=1
print(''.join(l))
``` | instruction | 0 | 30,456 | 20 | 60,912 |
Yes | output | 1 | 30,456 | 20 | 60,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234
Submitted Solution:
```
a,k=map(int,input().split())
a=list(str(a))
b=""
while(len(a)>0):
m=a.index(max(a[:k+1]))
k-=m
b+=a[m]
a.pop(m)
print(b)
``` | instruction | 0 | 30,457 | 20 | 60,914 |
Yes | output | 1 | 30,457 | 20 | 60,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
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")
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
#vsInput()
n,k=value()
a=list(str(n))
for i in range(k):
for j in range(len(a)-1):
if(a[j+1]>a[j]):
a[j],a[j+1]=a[j+1],a[j]
break
print(*a,sep="")
``` | instruction | 0 | 30,458 | 20 | 60,916 |
No | output | 1 | 30,458 | 20 | 60,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234
Submitted Solution:
```
import collections
import math
# 011011
#
def sort(key):
return key[1]
def pack(key):
return key[0]
def gcd(a,b):
if b ==0 :
return a
else:
return gcd(b,a%b)
def solve(a,b):
b = int(b) % int(a)
ah=0
ans=[]
for i in range(len(a)):
for x in range(len(a)-1,i,-1):
if int(a[i]) < int(a[x]) and x-i <= int(b) and int(b)>0:
ans.append((x,i))
b= str(int(b) - (x-i))
q=ans.copy()
a=[ i for i in a]
for i in q:
temp=i[1]
m=a[i[1]:i[0]]
a[i[1]] = a[i[0]]
a.pop(i[0])
a[temp+1:i[0]]=m
return ''.join(a)
a,b=map(str,input().split())
print(solve(a,b))
# c=-1
# for i in range(len(ar)-1):
# if ar[i][1]==ar[i+1][1]:
# c=i
# else:
# m = ar[c:i+1]
# m=sorted(m,key=pack)
# ar[c:i+1]=m
``` | instruction | 0 | 30,459 | 20 | 60,918 |
No | output | 1 | 30,459 | 20 | 60,919 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234
Submitted Solution:
```
s = input().split()
k = int(s[1])
v, t = [], []
for x in s[0]:
v.append(int(x))
t.append(int(x))
t.sort(reverse=True)
for i in range(len(t)):
index = -1
for j in range(i, len(v)):
if v[j] == t[i]:
index = j
break
if k >= index - i:
k -= (index - i)
for j in range(index, i, -1):
v[j], v[j - 1] = v[j - 1], v[j]
else:
m, index = 0, -1
for j in range(i, i + k + 1):
if v[j] > m:
m = v[j]
index = j
for j in range(index, i, -1):
v[j], v[j - 1] = v[j - 1], v[j]
k = 0
break
ans = 0
for x in v:
ans = ans * 10 + x
print(ans)
``` | instruction | 0 | 30,460 | 20 | 60,920 |
No | output | 1 | 30,460 | 20 | 60,921 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 β€ a β€ 1018; 0 β€ k β€ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234
Submitted Solution:
```
n, k = input().split()
n = [*n]
k = int(k)
i = 1
while k > 0 and i < len(n):
for j in range(i, 0, -1):
if n[j] <= n[j - 1] or k == 0:
break
n[j], n[j - 1] = n[j - 1], n[j]
k -= 1
i += 1
print(*n, sep = '')
``` | instruction | 0 | 30,461 | 20 | 60,922 |
No | output | 1 | 30,461 | 20 | 60,923 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | instruction | 0 | 30,529 | 20 | 61,058 |
Tags: implementation
Correct Solution:
```
# You lost the game.
n = int(input())
r = "123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370"
print(r[n-1])
``` | output | 1 | 30,529 | 20 | 61,059 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | instruction | 0 | 30,530 | 20 | 61,060 |
Tags: implementation
Correct Solution:
```
#import pandas
def answer(n):
res = ""
for i in range(1, 371):
res = res + str(i)
return res[n -1]
print(answer(int(input())))
``` | output | 1 | 30,530 | 20 | 61,061 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | instruction | 0 | 30,531 | 20 | 61,062 |
Tags: implementation
Correct Solution:
```
s = ''
for i in range(1,371):
s += str(i)
n = int(input())
print(s[n-1])
``` | output | 1 | 30,531 | 20 | 61,063 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | instruction | 0 | 30,532 | 20 | 61,064 |
Tags: implementation
Correct Solution:
```
n = int(input())
t = 1
s = ''
while (len(s) < 1000):
s += str(t)
t += 1
print(s[n - 1])
``` | output | 1 | 30,532 | 20 | 61,065 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | instruction | 0 | 30,533 | 20 | 61,066 |
Tags: implementation
Correct Solution:
```
n = int(input())
s = str.join('', map(str, range(n + 1)))
print(s[n])
``` | output | 1 | 30,533 | 20 | 61,067 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | instruction | 0 | 30,534 | 20 | 61,068 |
Tags: implementation
Correct Solution:
```
n=int(input())
s=""
i=1
while len(s)<=n:
s+=str(i)
i+=1
print(s[n-1])
``` | output | 1 | 30,534 | 20 | 61,069 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | instruction | 0 | 30,535 | 20 | 61,070 |
Tags: implementation
Correct Solution:
```
n = int(input())
nums = ''
for i in range(1, n + 1):
nums += str(i)
print(nums[n - 1])
``` | output | 1 | 30,535 | 20 | 61,071 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | instruction | 0 | 30,536 | 20 | 61,072 |
Tags: implementation
Correct Solution:
```
p = int(input()) - 1
print (''.join(str(x) for x in range(1,1000))[p])
``` | output | 1 | 30,536 | 20 | 61,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
Submitted Solution:
```
n = int(input())
s = ""
n2 = 0
for i in range(1,1000):
i = str(i)
n2 += len(i)
s += i
if n2 > n:
print(s[n-1])
break
``` | instruction | 0 | 30,537 | 20 | 61,074 |
Yes | output | 1 | 30,537 | 20 | 61,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
Submitted Solution:
```
s=''.join(str(x) for x in range(1, 500))
print(s[int(input())-1])
``` | instruction | 0 | 30,538 | 20 | 61,076 |
Yes | output | 1 | 30,538 | 20 | 61,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
Submitted Solution:
```
s = ''
for i in range(388):
s += str(i)
n=int(input())
print(s[n])
``` | instruction | 0 | 30,539 | 20 | 61,078 |
Yes | output | 1 | 30,539 | 20 | 61,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
Submitted Solution:
```
def main():
n = int(input())
s=''.join(str(i) for i in range(1,n+1))
print(s[n-1])
if __name__ == '__main__':
main()
``` | instruction | 0 | 30,540 | 20 | 61,080 |
Yes | output | 1 | 30,540 | 20 | 61,081 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
Submitted Solution:
```
n = int(input())
if n < 10:
print(n)
elif n < 189:
n -= 9
if(n % 2 == 0):
print(int(n % 20/2-1))
else:
print(int(n/20)+1)
else:
n -= 189
if(n % 3 == 0):
print(int(n % 30/3-1))
elif((n+1) % 3 == 0):
print(int(n / 30)+1)
else:
print(int(n/300)+1)
``` | instruction | 0 | 30,541 | 20 | 61,082 |
No | output | 1 | 30,541 | 20 | 61,083 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
Submitted Solution:
```
t=int(input())
chk="123456789101112131415"
if t<=21:
print(chk[t-1])
else:
print(chk[(t%29)-1])
``` | instruction | 0 | 30,542 | 20 | 61,084 |
No | output | 1 | 30,542 | 20 | 61,085 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
Submitted Solution:
```
n = int(input())
string = ''
for i in range(1,n+1):
string += str(i)
if len(string) == n:
print(string[len(string)-1])
break
``` | instruction | 0 | 30,543 | 20 | 61,086 |
No | output | 1 | 30,543 | 20 | 61,087 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
Input
The only line of the input contains a single integer n (1 β€ n β€ 1000) β the position of the digit you need to print.
Output
Print the n-th digit of the line.
Examples
Input
3
Output
3
Input
11
Output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
Submitted Solution:
```
def bubble_sort(l):
for i in range(len(l) - 1):
for j in range(len(l) - i - 1):
if l[j] > l[j + 1]:
l[j], l[j + 1] = l[j + 1], l[j]
return l
def main_function():
n = int(input())
output_str = ""
output_list = []
for i in range(1, n):
for j in str(i):
output_list.append(j)
return int(output_list[-1])
print(main_function())
``` | instruction | 0 | 30,544 | 20 | 61,088 |
No | output | 1 | 30,544 | 20 | 61,089 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 β€ n β€ 200 000, 1 β€ t β€ 109) β the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all. | instruction | 0 | 30,561 | 20 | 61,122 |
Tags: dp, implementation, math
Correct Solution:
```
n, t = map(int, input().split())
x = input()
i = x.find('.')
for j in range(i + 1, n):
if x[j] > '4':
for k in range(t):
j -= 1
if x[j] != '4': break
if j == i:
j -= 1
while j and x[j] == '9': j -= 1
x = x[:j] + str(int(x[j]) + 1) + '0' * (i - j - 1)
else:
x = x[:j] + str(int(x[j]) + 1)
break
print(x)
# Made By Mostafa_Khaled
``` | output | 1 | 30,561 | 20 | 61,123 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 β€ n β€ 200 000, 1 β€ t β€ 109) β the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all. | instruction | 0 | 30,562 | 20 | 61,124 |
Tags: dp, implementation, math
Correct Solution:
```
def main():
n,t = map(int,input().split())
b = list(input())
p = b.index('.')
if int(b[p+1]) > 4:
del b[p:n]
b = list(b)
for x in range(len(b)-1,-1,-1):
if b[x] == '9':
b[x] = '0'
else:
b[x] = chr(ord(b[x])+1)
break
else:
b.insert(0,'1')
print(''.join(b))
return
else:
if p + 1 < n - 1:
for x in range(p+1,n):
if int(b[x+1]) > 4:
b[x] = chr(ord(b[x])+1)
del b[x+1:n]
t-=1
break
else:
print(''.join(b))
return
for y in range(x,p,-1):
if int(b[y]) < 5 or t == 0:
break
elif b[y-1] != '.':
b[y-1] = str(int(b[y-1])+1)
del b[y:n]
t-=1
elif b[y-1] == '.':
del b[y-1:n]
b = list(b)
for x in range(len(b)-1,-1,-1):
if b[x] == '9':
b[x] = '0'
else:
b[x] = chr(ord(b[x])+1)
break
else:
b.insert(0,'1')
b = ''.join(b)
print(b)
main()
``` | output | 1 | 30,562 | 20 | 61,125 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 β€ n β€ 200 000, 1 β€ t β€ 109) β the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all. | instruction | 0 | 30,563 | 20 | 61,126 |
Tags: dp, implementation, math
Correct Solution:
```
n, t = map(int, input().split())
xs = list(input())
dot = xs.index('.')
pos = -1
for i in range(dot+1, n):
if xs[i] > '4':
pos = i
break
if pos < 0:
print("".join(xs))
else:
for j in range(t):
if xs[pos-1-j] != '4':
break
pos = pos - 1 - j
while pos >= 0 and (xs[pos] == '9' or pos == dot):
pos -= 1
if pos < 0:
print("1", end="")
print("0"*dot)
elif pos < dot:
print("".join(xs[:pos]), end="")
print(chr(ord(xs[pos])+1), end="")
print("0"*(dot-pos-1))
else:
print("".join(xs[:pos]), end="")
print(chr(ord(xs[pos])+1))
``` | output | 1 | 30,563 | 20 | 61,127 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 β€ n β€ 200 000, 1 β€ t β€ 109) β the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all. | instruction | 0 | 30,564 | 20 | 61,128 |
Tags: dp, implementation, math
Correct Solution:
```
n, k = map(int, input().split())
s = list(input())
dot = s.index(".")
pos =-1
for i in range(dot+1, n):
if s[i] > "4":
pos = i
break
if pos < 0:
print("".join(s))
else:
for j in range(k):
if s[pos-1-j] != "4":
break
pos = pos-1-j
while pos >= 0 and (s[pos] == "9" or pos == dot):
pos -= 1
if pos < 0:
print("1", end = "")
print("0"*dot)
elif pos < dot:
print("".join(s[:pos]), end = "")
print(chr(ord(s[pos])+1), end = "")
print("0"*(dot-pos-1))
else:
print("".join(s[:pos]), end = "")
print(chr(ord(s[pos])+1))
``` | output | 1 | 30,564 | 20 | 61,129 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 β€ n β€ 200 000, 1 β€ t β€ 109) β the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all. | instruction | 0 | 30,565 | 20 | 61,130 |
Tags: dp, implementation, math
Correct Solution:
```
def main():
n,t = map(int,input().split())
b = input()
p = b.find('.')
for i in range(p+1,n):
if b[i]>'4':
break
else:
print(b)
return
while t:
i-=1
t-=1
if b[i]<'4':
break
if i>p:
print(b[:i], chr(ord(b[i])+1), sep = '')
else:
k = list(b[:i])
for x in range(len(k)-1,-1,-1):
if k[x] == '9':
k[x] = '0'
else:
k[x] = chr(ord(k[x])+1)
break
else:
k.insert(0,'1')
print(''.join(k))
if __name__ == '__main__':
main()
``` | output | 1 | 30,565 | 20 | 61,131 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 β€ n β€ 200 000, 1 β€ t β€ 109) β the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all. | instruction | 0 | 30,566 | 20 | 61,132 |
Tags: dp, implementation, math
Correct Solution:
```
n, t = map(int,input().split())
s = "0"+input()
f = s.find('.')
if f == -1:
print(s[1:])
exit(0)
r = list(s[:f]+s[f+1:])
for i in range(f,len(r)):
if r[i] >= "5" and r[i] <= "9":
while r[i] >= "5" and r[i] <= "9":
if i < f or t <= 0:
break
i -= 1
z = ord(r[i])+1
while z == ord("9")+1:
i -= 1
z = ord(r[i])+1
#print(r[i])
while len(r) != i+1:
r.pop()
r[-1] = chr(z)
t -= 1
break
if r[0] == '0':
r = r[1:]
f -= 1
r += ['0']*max(f-len(r),0)
if len(r) == f:
print(*r,sep='')
else:
print(*r[:f],'.',*r[f:],sep='')
``` | output | 1 | 30,566 | 20 | 61,133 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 β€ n β€ 200 000, 1 β€ t β€ 109) β the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all. | instruction | 0 | 30,567 | 20 | 61,134 |
Tags: dp, implementation, math
Correct Solution:
```
n, t = map(int, input().split())
tmp = input()
s = []
for i in range(n):
s.append(tmp[i])
ind = n
perenos = 0
for i in range(n):
if (s[i] == '.'):
nach = i + 1
for i in range(nach, n):
if (int(s[i]) > 4):
ind = i
break
if (ind == n):
print(*s, sep="")
exit()
while (t > 0 and s[ind] != '.'):
if (int(s[ind]) > 3):
ind -= 1
perenos = 1
t -= 1
if (s[ind] == '9'):
t += 1
else:
s[ind] = str(int(s[ind]) + 1)
perenos = 0
break
if s[ind] == '.':
ind -= 1
while (s[ind] == '9'):
s[ind] = '0'
ind -= 1
if (ind < 0 and perenos != 0):
print(1, end="")
viv = 0
while (s[viv] != '.'):
print(s[viv], end="")
viv += 1
else:
s[ind] = str(int(s[ind]) + perenos)
viv = 0
while (s[viv] != '.'):
print(s[viv], end="")
viv += 1
else:
while (s[ind] == '9' or s[ind] == '.'):
if (s[ind] == '.'):
ind -= 1
continue
s[ind] = '0'
ind -= 1
s[ind] = str(int(s[ind]) + perenos)
for i in range(ind + 1):
print(s[i], end="")
``` | output | 1 | 30,567 | 20 | 61,135 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 β€ n β€ 200 000, 1 β€ t β€ 109) β the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all. | instruction | 0 | 30,568 | 20 | 61,136 |
Tags: dp, implementation, math
Correct Solution:
```
#!/usr/bin/env python
#-*-coding:utf-8 -*-
import sys
from decimal import*
n,t=map(int,input().split())
x=input()
i=x.find('.')
if 0>i:
print(x)
sys.exit()
if 1>i:
i=1
n+=1
x='0'+x
for j in range(1+i,n):
if'4'<x[j]:break
else:
print(x)
sys.exit()
while 0<t:
j-=1
if'4'!=x[j]:break
t-=1
getcontext().prec=1+j
x=pow(Decimal(10),i-j)+Decimal(x[:1+j])
print(x if x!=x.to_integral_value()else x.quantize(Decimal(1)))
``` | output | 1 | 30,568 | 20 | 61,137 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 β€ n β€ 200 000, 1 β€ t β€ 109) β the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all.
Submitted Solution:
```
(n, t) = [int(x) for x in input().split()]
(a, s) = input().split('.')
s = list(s)
pos = len(s) - 1
for i in range(len(s)):
if ord(s[i]) > ord('4'):
pos = i
break
while t > 0 and pos > 0:
if ord(s[pos]) > ord('4'):
pos -= 1
s[pos] = chr(ord(s[pos]) + 1)
t -= 1
else:
break
if t > 0 and pos == 0 and s[0] > '4':
it = len(a) - 1
A = [ord(ch) - ord('0') for ch in a]
A[it] += 1
while it > 0:
if A[it] == 10:
A[it] = 0
A[it - 1] += 1
it -= 1
else:
break
res = "".join([str(x) for x in A])
print(res)
else:
res = a + '.' + "".join(s[:pos + 1])
print(res)
``` | instruction | 0 | 30,569 | 20 | 61,138 |
Yes | output | 1 | 30,569 | 20 | 61,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 β€ n β€ 200 000, 1 β€ t β€ 109) β the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all.
Submitted Solution:
```
n, t = map(int, input().split())
s = input()
ind = s.find(".")
for i in range(ind+1, n):
if s[i] > "4":
break
else:
print(s)
quit()
while t:
t -= 1
i -= 1
if s[i] < "4":
break
if i > ind:
print(s[:i], chr(ord(s[i])+1), sep = "")
else:
t = list(s[:i])
for i in range(len(t)-1, -1, -1):
if t[i] == "9":
t[i] = "0"
else:
t[i] = chr(ord(t[i])+1)
break
else:
t.insert(0, "1")
print("".join(t))
``` | instruction | 0 | 30,570 | 20 | 61,140 |
Yes | output | 1 | 30,570 | 20 | 61,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 β€ n β€ 200 000, 1 β€ t β€ 109) β the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all.
Submitted Solution:
```
n, t = map(int, input().split())
mark = input().split('.')
shift = False
fraction = []
for digit in map(int, mark[1]):
if digit > 4:
t -= 1
if fraction:
fraction[-1] += 1
while t and fraction and fraction[-1] > 4:
t -= 1
fraction.pop()
if fraction:
fraction[-1] += 1
else:
shift = True
else:
shift = True
break
fraction.append(digit)
if shift:
last_digits = [int(mark[0][-1]) + 1]
i = -1
while last_digits[-1] > 9:
last_digits[-1] -= 10
i -= 1
if -i <= len(mark[0]):
last_digits.append(int(mark[0][i]) + 1)
else:
last_digits.append(1)
print(mark[0][:i], *last_digits[::-1], sep='', end='')
else:
print(mark[0], end='')
if fraction:
print('.', *fraction, sep='')
``` | instruction | 0 | 30,571 | 20 | 61,142 |
Yes | output | 1 | 30,571 | 20 | 61,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 β€ n β€ 200 000, 1 β€ t β€ 109) β the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all.
Submitted Solution:
```
n, t = map(int, input().split())
x = input()
i = x.find('.')
for j in range(i + 1, n):
if x[j] > '4':
for k in range(t):
j -= 1
if x[j] != '4': break
if j == i:
j -= 1
while j and x[j] == '9': j -= 1
x = x[:j] + str(int(x[j]) + 1) + '0' * (i - j - 1)
else:
x = x[:j] + str(int(x[j]) + 1)
break
print(x)
``` | instruction | 0 | 30,572 | 20 | 61,144 |
Yes | output | 1 | 30,572 | 20 | 61,145 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.