ZhenlongDai/ACPR huggingface dataset:
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
import string

t = stdin.readline().rstrip()
alpha = string.ascii_lowercase
mi = 10**10

for target in alpha:
    s = t
    cnt = 0
    while True:
        cnt += 1
        sin = ""
        for i in range(len(s)-1):
            sin += s[i] if s[i] == target else s[i+1]
        s = sin
        if s.count(target) == len(s):
            break
    mi = min(mi,cnt)

print(mi)

Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
from sys import stdin
import string

t = stdin.readline().rstrip()
alpha = string.ascii_lowercase
mi = 10**10
if len(set(t)) == 1:
    print(0)
    exit() 
for target in alpha:
    s = t
    cnt = 0
    while True:
        cnt += 1
        sin = ""
        for i in range(len(s)-1):
            sin += s[i] if s[i] == target else s[i+1]
        s = sin
        if s.count(target) == len(s):
            break
    mi = min(mi,cnt)

print(mi)

Problem: p03687
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import collections
s=input()
slist=list(s)
c=collections.Counter(slist)
l=[]
dist=[]
ma=0
cnt=0
val=list(c.values())
key=list(c.keys())
for i in range(len(val)):
    l.append([key[i],val[i]])

for i in range(len(l)):
    ma=0
    cnt=0
    for j in range(len(s)):
        
        if s[j]!=l[i][0]:
            cnt=cnt+1
        else:
            if (ma<cnt):
                ma=cnt
                cnt=0
    if ma < cnt:
        ma = cnt
    dist.append(ma)
dist.sort()
print(dist[0])

Failing test case input:
whcrjpjyhtrywkrlxnbrbaobmx

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
import collections
s=input()
l=[]
dist=[]
ma=0
cnt=0
s2=""
s3=""
l=list(set(s))

for i in range(len(l)):
    ma=0
    cnt=0
    for j in range(len(s)):
        
        if s[j]!=l[i]:
            cnt=cnt+1
        else:
            if (ma<=cnt):
                ma=cnt
            cnt=0
    if ma <= cnt:
        ma = cnt
    
    dist.append(ma)
dist.sort()
print(dist[0])
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from copy import deepcopy

s = input()
ans = len(s)-1
for i in range(26):
    tc = chr(ord("a")+i)
    tv = 0
    ts = deepcopy(s)
    for j in range(len(s)):
        if ts.count(tc) == len(ts):
            ans = min(ans, tv)
            break
        nxt = ""
        for k in range(len(ts)-1):
            if ts[k] == tc or ts[k-1] == tc:
                nxt += tc
            else:
                nxt += ts[k]
        tv += 1
        ts = deepcopy(nxt)
print(ans)


Failing test case input:
advvtm

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
from copy import deepcopy

s = input()
ans = len(s)-1
for i in range(26):
    tc = chr(ord("a")+i)
    tv = 0
    ts = deepcopy(s)
    for j in range(len(s)):
        if ts.count(tc) == len(ts):
            ans = min(ans, tv)
            break
        nxt = ""
        for k in range(len(ts)-1):
            if ts[k] == tc or ts[k+1] == tc:
                nxt += tc
            else:
                nxt += ts[k]
        tv += 1
        ts = deepcopy(nxt)
print(ans)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

s = input()

s = list(s)

counter = Counter(s).most_common()
most = []

maxnum = counter[0][1]

for i in counter:
	if i[1] == maxnum:
		most.append(i[0])

res = float("inf")
for c in most:
	l = s[:]
	n = 0
	while 1:
		if len(set(l)) == 1:
			break
		else:
			n+=1
			for i in range(len(l)-1):
				if l[i]==c or l[i+1]==c:
					l[i] = c
			l.pop()
	res = min(res, n)

print(res)

Failing test case input:
smjoabjdoxmrjwypugydyqrchv

Expected output:
11


Actual output:
13


Fixed submission (verdict: Accepted):
from collections import Counter

s = input()

s = list(s)

res = float("inf")
for c in s:
	l = s[:]
	n = 0
	while 1:
		if len(set(l)) == 1:
			break
		else:
			n+=1
			for i in range(len(l)-1):
				if l[i]==c or l[i+1]==c:
					l[i] = c
			l.pop()
	res = min(res, n)

print(res)
Problem: p03687
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s = input()
l = len(s)

def le(s,x):
    cnt = 0
    L = []
    num = []
    for i in range(l):
        if s[i] != x:
            cnt +=1
            if i == l-1:
                L.append(cnt)
        elif s[i] == x:
            L.append(cnt)
            cnt = 0
    num = L[1:-1]   
    ans = 0
    if num:
        for i in num:
            if i%2 == 0:
                ans = i
            else:
                ans = i
    ANS = max(L[0],ans,L[-1])        
    
    return ANS
C = 10**10   
for i in range(l):
    
    C = min(C,(le(s,s[i])))
print(C)

Failing test case input:
vhcrjxbyhtpywkrlxncrbbojmr

Expected output:
10


Actual output:
5


Fixed submission (verdict: Accepted):
from copy import deepcopy
s = input()

ans = 10**10
for i in range(len(s)):
    a = s[i]
    t = deepcopy(s)
    cnt = 0
    
    while len(set(list(t))) !=1:
        
        cnt +=1
        while True:
            S = ""
            for j in range(len(t)-1):
                if (t[j] == a) or (t[j+1] == a):
                    S +=a
                    
                else:
                    S +=t[j]

            else:
                t = deepcopy(S)
                
                break
    ans = min(ans,cnt)
    
print(ans)

Problem: p03687
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from sys import stdin


s = stdin.readline().rstrip()



ans = len(s)
for c in range(ord('a'), ord('z')+1):
    cnt, cntMax = 0, 0
    for i in range(0, len(s)-1):
        if s[i] == chr(c):
            cntMax = max(cnt, cntMax)
            cnt = 0
            continue
        cnt += 1
    cntMax = max(cnt, cntMax)
    ans = min(ans, cntMax)
print(ans, '\n')



Failing test case input:
zzx

Expected output:
1


Actual output:
0 



Fixed submission (verdict: Accepted):
from sys import stdin


s = stdin.readline().rstrip()



ans = len(s)
for c in range(ord('a'), ord('z')+1):
    cnt, cntMax = 0, 0
    for i in range(0, len(s)):
        if s[i] == chr(c):
            cntMax = max(cnt, cntMax)
            cnt = 0
            continue
        cnt += 1
    cntMax = max(cnt, cntMax)
    ans = min(ans, cntMax)
print(ans, '\n')
Problem: p03687
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import Counter
S = input()
counter_S = Counter(S)
max_val = max(counter_S.values())
nums = []
for key,val in counter_S.items():
    if val == max_val:
        nums.append(key)
ans=pow(10,9)
for num in nums:
    s=S
    ans2=0
    while len(Counter(s)) > 1:
        list_s=list(s)
        new_s=[]
        for n in range(len(list_s)-1):
            if list_s[n] == num or list_s[n+1] == num:
                new_s.append(num)
            else:
                new_s.append(list_s[n])
        s = new_s
        ans2 += 1
    ans =  min(ans, ans2)
print(ans)


Failing test case input:
xpwzglbjquntrci{axpdikofyw

Expected output:
13


Actual output:
14


Fixed submission (verdict: Accepted):
from collections import Counter
S = input()
nums = list(set(S))
ans=pow(10,9)
for num in nums:
    s=S
    ans2=0
    while len(Counter(s)) > 1:
        list_s=list(s)
        new_s=[]
        for n in range(len(list_s)-1):
            if list_s[n] == num or list_s[n+1] == num:
                new_s.append(num)
            else:
                new_s.append(list_s[n])
        s = new_s
        ans2 += 1
    ans =  min(ans, ans2)
print(ans)

Problem: p03687
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=input()
import collections
tmp=list(collections.Counter(N).keys())
ans=float("Inf")
import copy
for i in tmp:
   c=0
   l=copy.deepcopy(tmp)
   while len(set(l))!=1:
      tmp2=[]
      for j in range(len(l)-1):
         if l[j] ==i or l[j+1]==i:
            tmp2.append(i)
         else:
            tmp2.append(l[j])
      c+=1
      l=copy.deepcopy(tmp2)
   ans=min(ans,c)
print(ans)

Failing test case input:
smjoabjdoxmrjwypugydyqrchv

Expected output:
11


Actual output:
9


Fixed submission (verdict: Accepted):
N=input()
import collections
tmp=list(collections.Counter(N).keys())
ans=float("Inf")
import copy
for i in tmp:
   c=0
   l=copy.deepcopy(N)
   while len(set(l))!=1:
      tmp2=[]
      for j in range(len(l)-1):
         if l[j] ==i or l[j+1]==i:
            tmp2.append(i)
         else:
            tmp2.append(l[j])
      c+=1
      l=copy.deepcopy(tmp2)
   ans=min(ans,c)
print(ans)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

s = input()

if s.count(s[0]) == len(s):
    print(0)
    sys.exit()

dic = {'a': []}
for i in range(len(s)):
    if s[i] not in dic:
        dic[s[i]] = []
    dic[s[i]].append(i)

m = 100
for v in dic.values():
    v.append(len(s)+1)
    dist = v[0]
    for i in range(len(v))[1:]:
        dist = max(dist, v[i] - v[i-1])
    m = min(m, dist)

print(m-1)


Failing test case input:
smjoabjdoxmrjwypugydyqrchv

Expected output:
11


Actual output:
10


Fixed submission (verdict: Accepted):
import sys

s = input()

if s.count(s[0]) == len(s):
    print(0)
    sys.exit()

dic = {'a': []}
for i in range(len(s)):
    if s[i] not in dic:
        dic[s[i]] = []
    dic[s[i]].append(i)

m = 100
for v in dic.values():
    v.append(len(s))
    dist = v[0]
    for i in range(len(v))[1:]:
        dist = max(dist, v[i] - v[i-1] - 1)
    m = min(m, dist)

print(m)
Problem: p03687
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import copy
char = list(map(chr, range(ord('a'), ord('z')+1)))
target = list(input())
ans = float("inf")
for c in char:
  s = copy.deepcopy(target)
  tmpans = 0
  while True:
    for i in range(len(s)-1):
      if s[i] == c or s[i+1] == c:
        s[i] = c
    s.pop()
    tmpans += 1
    flag = True
    for si in s:
      if si != s[0]:
        flag = False
    if flag==True:
      break
  if ans > tmpans:
    ans = tmpans
print(ans)
     



Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
import copy
char = list(map(chr, range(ord('a'), ord('z')+1)))
target = list(input())
ans = float("inf")
for c in char:
  s = copy.deepcopy(target)
  tmpans = 0
  while True:
    flag = True
    for si in s:
      if si != s[0]:
        flag = False
    if flag==True:
      break
    for i in range(len(s)-1):
      if s[i] == c or s[i+1] == c:
        s[i] = c
    s.pop()
    tmpans += 1
  if ans > tmpans:
    ans = tmpans
print(ans)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
s = input()
counter = Counter(s)
target = counter.most_common()[0][0]
j = 0
while(1):
    if len(set(s)) == 1:
        break
    new_s = ""
    for i in range(len(s)-1):
        if s[i] == target or s[i+1] == target:
            new_s +=target
        else:
            new_s += s[i]
    j+=1;
    s = new_s
print(j)

Failing test case input:
i`bknc

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
a = input()
min = 10000
for target in set(a):
    s = a
    j = 0
    while(1):
        
        if len(set(s)) == 1:
            break
        new_s = ""
        for i in range(len(s)-1):
            if s[i] == target or s[i+1] == target:
                new_s +=target
            else:
                new_s += s[i]
        j+=1;
        if j > min:
            break
        s = new_s
    if min > j:
        min = j

print(min)
Problem: p03687
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
l = list(set(s))

min_c = 10**8
for i in l:
    old_s = s
    new_s = ''
    idx = 1
    c = 0
    while True:
        for j in range(len(s)-idx):
            if old_s[j] == i or old_s[j+1] == i:
                new_s += i
            
            else:
                new_s += old_s[j]
        
        idx += 1
        c += 1
        
        if len(set(new_s)) == 1:
            break
        
        else:
           old_s = new_s
           new_s = ''
    
    min_c = min(min_c,c)

print(min_c)
    

Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
s = input()
l = list(set(s))

if len(set(s)) == 1:
    print(0)
    exit()

min_c = 10**8
for i in l:
    old_s = s
    new_s = ''
    idx = 1
    c = 0
    
    while True:
        for j in range(len(s)-idx):
            if old_s[j] == i or old_s[j+1] == i:
                new_s += i
            
            else:
                new_s += old_s[j]
        
        idx += 1
        c += 1
        
        if len(set(new_s)) == 1:
            break
        
        else:
           old_s = new_s
           new_s = ''
    
    min_c = min(min_c,c)

print(min_c)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

s = "zzz"
s = "whbrjpjyhsrywlqjxdbrbaomnw"
f = {}
g = {}

chars = [c for c in s]


for char in chars:
    f[char] = []
    f[char].append(-1)
    for i, c in enumerate(s):
        if(c==char):
            f[char].append(i)
    f[char].append(len(s))

max_len_all = len(s)
for char in chars:
    max_len = 0
    for i in range(len(f[char])-1):
        max_len = max(max_len, f[char][i+1]-f[char][i])
    g[char] = max_len
    if(g[char]<max_len_all):
        ans = char
        max_len_all = g[char]





print(max_len_all-1)


Failing test case input:
smjoabjdoxmrjwypugydyqrchv

Expected output:
11


Actual output:
8


Fixed submission (verdict: Accepted):
s = input()
f = {}
g = {}

chars = [c for c in s]


for char in chars:
    f[char] = []
    f[char].append(-1)
    for i, c in enumerate(s):
        if(c==char):
            f[char].append(i)
    f[char].append(len(s))

max_len_all = len(s)
for char in chars:
    max_len = 0
    for i in range(len(f[char])-1):
        max_len = max(max_len, f[char][i+1]-f[char][i])
    g[char] = max_len
    if(g[char]<max_len_all):
        ans = char
        max_len_all = g[char]





print(max_len_all-1)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
s = input()
x = Counter(s).most_common()
n = x[0][1]
count = 0
for t in x:
    if t[1] == n:
        count += 1
    else:
        break
ans = 100
for i in range(count):
    ch = x[i][0]
    t = list(s)
    num = 0
    while set(t) != set(ch):
        num += 1
        temp = tuple(t)
        k = len(t)
        for i in range(k-1):
            if temp[i+1] == ch:
                t[i] = ch
        t = t[:-1]
    ans = min(num, ans)
print(ans)


Failing test case input:
aajklc

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
from collections import Counter
s = input()
x = Counter(s).most_common()
ans = 100
for p in x:
    ch = p[0]
    t = list(s)
    num = 0
    while set(t) != set(ch):
        num += 1
        temp = tuple(t)
        k = len(t)
        for i in range(k-1):
            if temp[i+1] == ch:
                t[i] = ch
        t = t[:-1]
    ans = min(num, ans)
print(ans)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
l = set(list(s))
N = len(s)
n = len(s)
ans = 0

for ll in l:
    S = s
    while n > 0:
        tmp = ''
        for i in range(n - 1):
            if S[i] == ll or S[i + 1] == ll:
                tmp += ll
            else:
                tmp += S[i]
        if len(set(tmp)) == 1:
            ans = max(ans, len(tmp))
            break
        n -= 1
        S = tmp

print(N - ans)


Failing test case input:
xpwzglbjquntrci{axpdikofyw

Expected output:
13


Actual output:
21


Fixed submission (verdict: Accepted):
s = input()
l = list(s)
N = len(s)
n = len(s)
ans = 0

if len(set(s)) == 1:
    print(0)
    exit()

for ll in l:
    S = s
    n = N
    while n > 0:
        tmp = ''
        for i in range(n - 1):
            if S[i] == ll or S[i + 1] == ll:
                tmp += ll
            else:
                tmp += S[i]
        if len(set(tmp)) == 1:
            ans = max(ans, len(tmp))
            break
        n -= 1
        S = tmp

print(N - ans)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
l = list(s)
N = len(s)
n = len(s)
ans = 0

for ll in l:
    S = s
    n = N
    while n > 0:
        tmp = ''
        for i in range(n - 1):
            if S[i] == ll or S[i + 1] == ll:
                tmp += ll
            else:
                tmp += S[i]
        if len(set(tmp)) == 1:
            ans = max(ans, len(tmp))
            break
        n -= 1
        S = tmp

print(N - ans)


Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
s = input()
l = list(s)
N = len(s)
n = len(s)
ans = 0

if len(set(s)) == 1:
    print(0)
    exit()

for ll in l:
    S = s
    n = N
    while n > 0:
        tmp = ''
        for i in range(n - 1):
            if S[i] == ll or S[i + 1] == ll:
                tmp += ll
            else:
                tmp += S[i]
        if len(set(tmp)) == 1:
            ans = max(ans, len(tmp))
            break
        n -= 1
        S = tmp

print(N - ans)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()

ans = float('inf')
for goal in S:
    dist = [float('inf')] * len(S)
    right = float('inf')
    for i in range(len(S))[:: -1]:
        s = S[i]
        if s == goal:
            right = i
        dist[i] = min(dist[i], abs(i - right))

    cost = float('inf')
    for i in range(1, len(S) + 1):
        lMax = max(dist[:i])
        if lMax == float('inf'):
            continue
        cost = min(cost, max(lMax, max(dist[:len(S) - lMax])))
    ans = min(ans, cost)

print(ans)

Failing test case input:
zz{

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
S = input()

ans = float('inf')
for goal in S:
    dist = [float('inf')] * len(S)
    right = float('inf')
    for i in range(len(S))[:: -1]:
        if S[i] == goal:
            right = i
        dist[i] = min(dist[i], abs(i - right))

    cost = float('inf')
    for i in range(len(S)):
        cost = min(cost, max(i, max(dist[:len(S) - i])))
    ans = min(ans, cost)

print(ans)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=str(input())
ans=int(len(s)/2)

for i in range(97, 97+26):
  if chr(i) in s:
    ct= s.count(chr(i))
    place=[0]*ct
    for j in range(ct-1):
      place[0]=s.find(chr(i))+1
      place[j+1]=s[place[j]:].find(chr(i))+place[j]+1
    haba=max(len(s)-place[ct-1]-1,place[0]-1)
    for j in range(ct-1):
      haba=max(haba,place[j+1]-place[j]-1)
    ans=min(ans,haba)

print(ans)

Failing test case input:
zz{

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
s=str(input())
ans=int(len(s)/2)

for i in range(97, 97+26):
  if chr(i) in s:
    ct= s.count(chr(i))
    place=[0]*ct
    for j in range(ct-1):
      place[0]=s.find(chr(i))+1
      place[j+1]=s[place[j]:].find(chr(i))+place[j]+1
    haba=max(len(s)-place[ct-1],place[0]-1)
    for j in range(ct-1):
      haba=max(haba,place[j+1]-place[j]-1)
    ans=min(ans,haba)

print(ans)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def main() -> None:
    s = next_str()
    dic = [set() for _ in range(len(s))]

    flg = False

    for i in range(len(s)):
        dic[i].add(s[i])

    print(dic)

    while True:
        for c in range(ord('a'), ord('z') + 1):
            for i in range(len(dic)):
                if chr(c) not in dic[i]:
                    break
            else:
                flg = True

        for i in range(len(dic) - 1):
            dic[i] |= dic[i + 1]

        if flg: break
        dic = dic[:-1]

    print(len(s) - len(dic))


if __name__ == '__main__':
    main()

Failing test case input:
advvtm

Expected output:
2


Actual output:
[{'a'}, {'d'}, {'v'}, {'v'}, {'t'}, {'m'}]
2


Fixed submission (verdict: Accepted):
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def main() -> None:
    s = next_str()
    dic = [set() for _ in range(len(s))]

    flg = False

    for i in range(len(s)):
        dic[i].add(s[i])

    while True:
        for c in range(ord('a'), ord('z') + 1):
            for i in range(len(dic)):
                if chr(c) not in dic[i]:
                    break
            else:
                flg = True

        for i in range(len(dic) - 1):
            dic[i] |= dic[i + 1]

        if flg: break
        dic = dic[:-1]

    print(len(s) - len(dic))


if __name__ == '__main__':
    main()
Problem: p03994
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s=list(input())
K=int(input())
for i in range(len(s)-1):
    a= ord("z")+1 - ord(s[i])
    if K>=a:
        s[i]="a"
        K-=a
if K:
    s[-1]=chr((K+ord(s[-1])-ord("a"))%(ord("z") - ord("a")+1)+ord("a"))
print("".join(s))


Failing test case input:
lavitsffeodc
110

Expected output:
aaaaaaaaeadf


Actual output:
aaaaaaafeodm


Fixed submission (verdict: Accepted):
s=list(input())
K=int(input())
for i in range(len(s)-1):
    if s[i]!="a":
        a= ord("z")+1 - ord(s[i])
        if K>=a:
            s[i]="a"
            K-=a
if K:
    s[-1]=chr((K+ord(s[-1])-ord("a"))%(ord("z") - ord("a")+1)+ord("a"))
print("".join(s))

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
K = int(input())

ans = ''
for i, c in enumerate(s):
    dif = ord('z') - ord(c) + 1
    if i == len(s) - 1:
        ans += chr(((ord(c) + K - ord('a')) % 26) + ord('a'))
    elif dif <= K:
        ans += 'a'
        K -= dif
    else:
        ans += c
print(ans)


Failing test case input:
lawitsffeodc
100

Expected output:
aaaaaaaaeodi


Actual output:
aaaaaaafeodd


Fixed submission (verdict: Accepted):
s = input()
K = int(input())

ans = ''
for i, c in enumerate(s):
    dif = ord('z') - ord(c) + 1
    dif %= 26
    if i == len(s) - 1:
        K %= 26
        if ord(c) + K > ord('z'):
            K -= 26
        ans += chr(ord(c) + K)
    elif dif <= K:
        ans += 'a'
        K -= dif
    else:
        ans += c
print(ans)

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
x=[i-96for i in map(ord,s)]

n=int(input())
for i in range(len(s)):
    if 26-x[i]+1<=n:
        n-=26-x[i]+1
        x[i]=1

x[-1]+=n%26
print("".join(map(chr,[i+96 for i in x])))

Failing test case input:
caoeffstivdl
111

Expected output:
aaaaaaativdo


Actual output:
aaaaafstiadm


Fixed submission (verdict: Accepted):
s=input()
x=[i-96for i in map(ord,s)]
n=int(input())
for i in range(len(s)):
    y=(26-x[i]+1)%26
    if y<=n:
        n-=y
        x[i]=1
x[-1]+=n%26
print("".join(map(chr,[i+96 for i in x])))

Problem: p03994
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
k = int(input())

res=[]
for i in range(len(s)):
    num = ord(s[i])-97

    if i==len(s)-1:
        res.append(chr((num+k)%26+97))
    elif 26 - num <= k:
        res.append("a")
        k-=26-num
    else:
        res.append(s[i])

print("".join(res))

Failing test case input:
lwsiuafffodc
101

Expected output:
aaaaaaaafodk


Actual output:
aaaaaaaffodf


Fixed submission (verdict: Accepted):
s = input()
k = int(input())

res=[]
for i in range(len(s)):
    num = ord(s[i])-97

    if i==len(s)-1:
        res.append(chr((num+k)%26+97))
    elif s[i] == "a":
        res.append("a")
    elif 26 - num <= k:
        res.append("a")
        k-=26-num
    else:
        res.append(s[i])

print("".join(res))
Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    import sys
    input = sys.stdin.readline
    s = list(input().strip())
    K = int(input())
    for i, c in enumerate(s):
        z = 123 - ord(c)
        if K >= z:
            s[i] = 'a'
            K -= z
        if K == 0:
            break
    
    s[-1] = chr(((ord(s[-1])-97+K))%26+97)

    print(''.join(s))

if __name__ == '__main__':
     main()

Failing test case input:
lwsiuafffodc
101

Expected output:
aaaaaaaafodk


Actual output:
aaaaaaaffodf


Fixed submission (verdict: Accepted):
def main():
    import sys
    input = sys.stdin.readline
    s = list(input().strip())
    K = int(input())
    for i, c in enumerate(s):
        if c == 'a':
            continue
        z = 123 - ord(c)
        if K >= z:
            s[i] = 'a'
            K -= z
        if K == 0:
            break
    
    s[-1] = chr(((ord(s[-1])-97+K))%26+97)

    print(''.join(s))

if __name__ == '__main__':
     main()

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
k = int(input())
s = [i for i in s]
for i,v in enumerate(s):
    if v == 'a':
        break
    if k <= 0:
        break
    if ord('z') - ord(v) + 1 <= k:
        k -= ord('z') - ord(v) + 1
        s[i] = 'a'
k %= 26
s[-1] = chr(ord('a')+(ord(s[-1])-ord('a')+k)%26)
print(''.join(s))

Failing test case input:
caoffestivdl
110

Expected output:
aaaaaaativdn


Actual output:
aaoffestivdt


Fixed submission (verdict: Accepted):
s = input()
k = int(input())
ans = ''
for i,v in enumerate(s):
    if (ord('a') - ord(v))%26 <= k:
        k -= (ord('a') - ord(v))%26
        ans += 'a'
    else:
        ans += v
k %= 26
last = chr(ord('a')+(ord(ans[-1])-ord('a')+k)%26)

print(ans[:-1]+last)

Problem: p03994
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s=input()
k=int(input())
l=list(s)

for i in range(len(s)):
  f=-ord(s[i])+ord("z")+1
  if f<=k:
    l[i]="a"
    k-=f

k=k%26
a=ord(l[-1])+k 
if a> ord("z"):a-=26
l[-1]=chr(a)
print("".join(l))

Failing test case input:
caoffestiwdl
101

Expected output:
aaaaaastiwdm


Actual output:
aaaafeaaiwdo


Fixed submission (verdict: Accepted):
s=input()
k=int(input())
l=list(s)

for i in range(len(s)):
  f=(-ord(s[i])+ord("z")+1)%26
  if f<=k:
    l[i]="a"
    k-=f

k=k%26
a=ord(l[-1])+k 
if a> ord("z"):a-=26
l[-1]=chr(a)
print("".join(l))

Problem: p03994
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s=list(input())
k=int(input())
for i in range(len(s)):
    c = ord('z') - ord(s[i]) + 1
    if c > k:
        continue
    else:
        k -= c
        s[i] = 'a'
if k > 0:
    s[-1] = chr(ord('a') + ((ord(s[-1]) - ord('a') + k) % 26))
print(''.join(s))

Failing test case input:
caoffestiwdl
111

Expected output:
aaaaaaatiwdo


Actual output:
aaaaaesaiwdl


Fixed submission (verdict: Accepted):
s=list(input())
k=int(input())
for i in range(len(s)):
    c = (ord('z') - ord(s[i]) + 1)%26
    if c <= k:
        k -= c
        s[i] = 'a'
s[-1] = chr(ord('a') + ((ord(s[-1]) - ord('a') + k) % 26))
print(''.join(s))
Problem: p03994
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s = input()
K = int(input())

ans = []
for ch in s:
    v = ord("a") + 26 - ord(ch)
    if v <= K:
        K -= v
        ans.append("a")
    else:
        ans.append(ch)

if K > 0:
    ans[-1] = chr(ord(ans[-1]) + K % 26)
print("".join(ans))


Failing test case input:
lwsitafffodc
101

Expected output:
aaaaaaaafodj


Actual output:
aaaaaaaffode


Fixed submission (verdict: Accepted):
s = input()
K = int(input())

ans = []
for ch in s:
    v = ord("a") + 26 - ord(ch)
    if ch != "a" and v <= K:
        K -= v
        ans.append("a")
    else:
        ans.append(ch)

if K > 0:
    ans[-1] = chr(ord(ans[-1]) + K % 26)
print("".join(ans))

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = list(input())
K = int(input())

a_num = 97
z_num = 122

for i in range(len(s)):
    if K == 0:
        break
    else:
        if i == len(s) - 1:
          if ord(s[i])+ (K%26) <= z_num:
            s[i] = chr(ord(s[i]) + (K%26))
          else:
            s[i] = chr(ord(s[i]) + (K%26) - 26)

        elif ord(s[i]) == a_num:
            continue
        elif K > z_num - ord(s[i]) + 1:
            K -= z_num - ord(s[i]) + 1
            s[i]="a"
        
print("".join(s))


Failing test case input:
xyy
2

Expected output:
xay


Actual output:
xya


Fixed submission (verdict: Accepted):
s = list(input())
K = int(input())

a_num = 97
z_num = 122

for i in range(len(s)):
    if K == 0:
        break
    else:
        if i == len(s) - 1:
          if ord(s[i])+ (K%26) <= z_num:
            s[i] = chr(ord(s[i]) + (K%26))
          else:
            s[i] = chr(ord(s[i]) + (K%26) - 26)

        elif ord(s[i]) == a_num:
            continue
        elif K >= z_num - ord(s[i]) + 1:
            K -= z_num - ord(s[i]) + 1
            s[i]="a"
        
print("".join(s))

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
ord_a = ord('a')

ss = input()
K = int(input())

As = [ord(s) - ord_a for s in ss]

anss = []
for A in As[:-1]:
    num = 26 - A
    if K >= num:
        anss.append(0)
        K -= num
    else:
        anss.append(A)

anss.append((As[-1] + K) % 26)

print(''.join([chr(ans + ord_a) for ans in anss]))


Failing test case input:
caoeffstivdl
111

Expected output:
aaaaaaativdo


Actual output:
aaaaafstiadm


Fixed submission (verdict: Accepted):
ord_a = ord('a')

ss = input()
K = int(input())

As = [ord(s) - ord_a for s in ss]

anss = []
for A in As[:-1]:
    num = 26 - A
    if A == 0 or K < num:
        anss.append(A)
    else:
        anss.append(0)
        K -= num

anss.append((As[-1] + K) % 26)

print(''.join([chr(ans + ord_a) for ans in anss]))
Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
K = int(input())

ans = ""
for i in range(len(S)):
    if ord("z") - ord(S[i]) + 1 <= K:
        ans += "a"
        K -= ord("z") + 1 - ord(S[i])
    else:
        if i == len(S) - 1:
            if K > 0:
                ans += chr( ord(S[i]) + K)
            else:
              ans += S[i]
        else:
            ans += S[i]

print(ans)


Failing test case input:
xx{
2

Expected output:
xxc


Actual output:
xxa


Fixed submission (verdict: Accepted):
S = input()
K = int(input())

ans = ""
for i in range(len(S)):
    if ord("z") - ord(S[i]) + 1 <= K and i != len(S) - 1:
        ans += "a"
        if S[i] == "a":
            continue
        K -= ord("z") + 1 - ord(S[i])
    elif i == len(S) - 1:
       K %= 26
       if ord("z") - ord(S[i]) + 1 <= K:
            K -= ord("z") + 1 - ord(S[i]) 
            ans += chr(ord("a") + K)
       else:
            ans += chr( ord(S[i]) + K)
    else:
        ans += S[i]

print(ans)

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    s = input()
    n = int(input())
    
    t = []
    a = []
    for i in s:
        ord_i = ord(i)
        t.append(((123 - ord_i)%26, ord_i))
    print(t)
    
    for i in t:
        if n >= i[0]:
            a.append('a')
            n -= i[0]
        else:
            a.append(chr(i[1]))
            
    a[-1] = chr(ord(a[-1]) + n%26)
    print(''.join(a))
    
if __name__ == '__main__':
    main()

Failing test case input:
xzy
6

Expected output:
aaa


Actual output:
[(3, 120), (1, 122), (2, 121)]
aaa


Fixed submission (verdict: Accepted):
def main():
    s = input()
    n = int(input())
    
    t = []
    a = []
    for i in s:
        ord_i = ord(i)
        t.append(((123 - ord_i)%26, ord_i))
    
    for i in t:
        if n >= i[0]:
            a.append('a')
            n -= i[0]
        else:
            a.append(chr(i[1]))
            
    a[-1] = chr(ord(a[-1]) + n%26)
    print(''.join(a))
    
if __name__ == '__main__':
    main()

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve():
    S = input()
    l = len(S)
    K = int(input())
    i = 0
    ans = ''
    while i < l-1 and K>0:
        n = ord(S[i])-ord('a')
        if 25-n<K:
            ans += 'a'
            K -= 26-n
        else:
            ans += S[i]
        i += 1
    if K == 0:
        ans += S[i:]
    else:
        ans += chr((ord(S[-1])-ord('a')+K)%26+ord('a'))
    return ans
print(solve())

Failing test case input:
lavitshfeodc
101

Expected output:
aaaaaaaaeodk


Actual output:
aaaaaaafeodf


Fixed submission (verdict: Accepted):
def solve():
    S = input()
    l = len(S)
    K = int(input())
    i = 0
    ans = ''
    while i < l-1 and K>0:
        n = ord(S[i])-ord('a')
        if n==0:
            ans += 'a'
            i += 1
            continue
        if 25-n<K:
            ans += 'a'
            K -= 26-n
        else:
            ans += S[i]
        i += 1
    if K == 0:
        ans += S[i:]
    else:
        ans += chr((ord(S[-1])-ord('a')+K)%26+ord('a'))
    return ans
print(solve())
Problem: p03994
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
k = int(input())

res=[]
for i in range(len(s)):
    num = ord(s[i])-97

    if i==len(s)-1:
        res.append(chr((num+k)%26+97))
    elif 26 - num < k:
        res.append("a")
        k-=26-num
    else:
        res.append(s[i])

print("".join(res))

Failing test case input:
cdoeffstival
101

Expected output:
aaaaffaaiaal


Actual output:
aaaaffaaivaq


Fixed submission (verdict: Accepted):
s = input()
k = int(input())

res=[]
for i in range(len(s)):
    num = ord(s[i])-97

    if i==len(s)-1:
        res.append(chr((num+k)%26+97))
    elif s[i] == "a":
        res.append("a")
    elif 26 - num <= k:
        res.append("a")
        k-=26-num
    else:
        res.append(s[i])

print("".join(res))

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
k = int(input())
result = ""
i = 0

while i < len(s)-1:
    s_i = ord(s[i])
    if 123-s_i <= k:
        result = result+"a"
        k -= 123-s_i
    else:
        result = result+s[i]
    i += 1
if k>0:
    result = result + chr((ord(s[i])-97+k)%26+97)
else:
    result = result + s[i]

print(result)

Failing test case input:
lwshuafffodc
100

Expected output:
aaaaaaaafodi


Actual output:
aaaaaaaffodd


Fixed submission (verdict: Accepted):
s = input()
k = int(input())
result = ""
i = 0

while i < len(s)-1:
    s_i = ord(s[i])
    if s[i]=="a":
        result = result+"a"
    elif 123-s_i <= k:
        result = result+"a"
        k -= 123-s_i
    else:
        result = result+s[i]
    i += 1
if k>0:
    result = result + chr((ord(s[i])-97+k)%26+97)
else:
    result = result + s[i]

print(result)

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
K=int(input())
S=[c for c in s]
def diff(c):
    return ord('z')-ord(c)
for i in range(len(s)):
    d=diff(S[i])
    if d<K:
        K-=d+1
        S[i]='a'
k=K%26
S[-1]=chr(ord(S[-1])+k) if k<=diff(S[-1]) else chr(ord(S[-1])+k-26)
print(''.join(S))

Failing test case input:
caoeffstivdl
111

Expected output:
aaaaaaativdo


Actual output:
aaaaafstiadm


Fixed submission (verdict: Accepted):
s=input()
K=int(input())
S=[c for c in s]
def diff(c):
    return ord('z')-ord(c)
for i in range(len(s)):
    d=diff(S[i])
    if d<min(25,K):
        K-=d+1
        S[i]='a'
k=K%26
S[-1]=chr(ord(S[-1])+k) if k<=diff(S[-1]) else chr(ord(S[-1])+k-26)
print(''.join(S))

Problem: p03994
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s, k, t, i = input(), int(input()), "", 0
for s in s:
    if (p := 123 - ord(s)) <= k:
        k -= p
        t += "a"
    else:
        t += s
print(t[:-1] + chr((ord(t[-1]) - 97 + k) % 26 + 97))

Failing test case input:
lavitsffeodc
110

Expected output:
aaaaaaaaeadf


Actual output:
aaaaaaafeodm


Fixed submission (verdict: Accepted):
s, k, t = input(), int(input()), ""
for q in s:
    if (p := (123 - ord(q)) % 26) <= k:
        k -= p
        t += "a"
    else:
        t += q
print(t[:-1] + chr((ord(t[-1]) - 97 + k) % 26 + 97))
Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
K = int(input())

ans = ""
for i in range(len(S)):
    if ord("z") - ord(S[i]) + 1 <= K:
        ans += "a"
        K -= ord("z") + 1 - ord(S[i])
    else:
        if i == len(S) - 1:
            if K > 0:
                ans += chr( ord(S[i]) + K%26)
            else:
                ans += S[i]
        else:
            ans += S[i]
print(ans)


Failing test case input:
{yz
19

Expected output:
aaq


Actual output:
aaa


Fixed submission (verdict: Accepted):
S = input()
K = int(input())

ans = ""
for i in range(len(S)):
    if ord("z") - ord(S[i]) + 1 <= K and i != len(S) - 1:
        ans += "a"
        if S[i] == "a":
            continue
        K -= ord("z") + 1 - ord(S[i])
    elif i == len(S) - 1:
       K %= 26
       if ord("z") - ord(S[i]) + 1 <= K:
            K -= ord("z") + 1 - ord(S[i]) 
            ans += chr(ord("a") + K)
       else:
            ans += chr( ord(S[i]) + K)
    else:
        ans += S[i]

print(ans)

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = list(input())
k = int(input())

for i, s in enumerate(S):
    if ord('z') - ord(s) + 1 <= k:
        S[i] = 'a'
        k -= (ord('z') - ord(s) + 1)

S[-1] = chr((ord(S[-1]) + (k % 26)) % ord('a') + ord('a'))

print(str().join(S))

Failing test case input:
lavitsffeodc
110

Expected output:
aaaaaaaaeadf


Actual output:
aaaaaaafeodm


Fixed submission (verdict: Accepted):
S = list(input())
k = int(input())

for i, s in enumerate(S):
    if ord('z') - ord(s) + 1 <= k:
        S[i] = 'a'
        k -= (ord('z') - ord(s) + 1) % 26

S[-1] = chr((ord(S[-1]) + (k % 26)) % ord('a') % 26 + ord('a'))

print(str().join(S))

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
k = int(input())
l = [26 - (ord(c) - ord('a')) % 26 for c in s]
for i in range(len(s) - 1):
    if k >= l[i]:
        k -= l[i]
        s = s[:i] + 'a' + s[i + 1 :]

k %= 26
s = s[:-1] + chr(ord('a') + (ord(s[-1]) - ord('a') + k) % 26)
print(s)


Failing test case input:
daoffestiwdl
101

Expected output:
aaaaaastiwdn


Actual output:
aaaafeaaiadl


Fixed submission (verdict: Accepted):
s = input()
k = int(input())
l = [(26 - (ord(c) - ord('a'))) % 26 for c in s]
for i in range(len(s) - 1):
    if k >= l[i]:
        k -= l[i]
        s = s[:i] + 'a' + s[i + 1 :]

k %= 26
s = s[:-1] + chr(ord('a') + (ord(s[-1]) - ord('a') + k) % 26)
print(s)
Problem: p03994
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
K = int(input())

ans = []

for i in s:
    if i == "a":
        ans.append("a")
        continue
    
    elif ord(i) + K > ord("z") + 1:
        ans.append("a")
        K -= ord("z") + 1 - ord(i)
    
    else:
        ans.append(i)
        


last = (K + ord(ans[-1]) - ord('a')) % 26
ans[-1] = chr(ord("a") + last)
print(''.join(ans))

Failing test case input:
cdoeffstiwal
110

Expected output:
aaaaafatiwal


Actual output:
aaaaafsaiwam


Fixed submission (verdict: Accepted):
s = input()
K = int(input())

ans = []

for i in s:
    if i == "a":
        ans.append("a")
        continue
    
    if ord(i) + K >= ord("z") + 1:
        ans.append("a")
        K -= ord("z") + 1 - ord(i)
    
    else:
        ans.append(i)
        


last = (K + ord(ans[-1]) - ord('a')) % 26
ans[-1] = chr(ord("a") + last)
print(''.join(ans))

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
K = int(input())
ans = ''
for ind,i in enumerate(s):
    if(i=='a' and ind!=len(s)-1):
        ans+='a'
        continue
    d = 122-ord(i)
    if(ind==len(s)-1):
        if(K>26):
            K%=26
    if(K>d):
        K-=(d+1)
        ans+='a'
    elif(ind==len(s)-1):
        ans+=chr(ord(i)+K)
    else:
        ans+=i
print(ans)


Failing test case input:
xxz
8

Expected output:
aab


Actual output:
aaa


Fixed submission (verdict: Accepted):
s = input()
K = int(input())
ans = ''
for ind,i in enumerate(s):
    if(i=='a' and ind!=len(s)-1):
        ans+='a'
        continue
    d = 123-ord(i)
    if(ind==len(s)-1):
        K%=26
        if(K>=d):
            ans += chr(97+K-d)
            continue
        ans+=chr(ord(i)+K)
    elif(K>=d):
        K-=d
        ans+='a'
    else:
        ans+=i
print(ans)

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
k = int(input())

len_s = len(s)
moji = [0]*(len_s)

for i in range(len_s):
    num = 26-(ord(s[i])-ord('a'))
    if num <= k:
        moji[i] = 'a'
        k -= num
    else:
        moji[i] = s[i]

     
if k != 0:
    
    moji[len_s-1] = chr(ord(moji[len_s-1])+k%26)
        
print(*moji,sep='')

Failing test case input:
lavitsgfeodc
101

Expected output:
aaaaaaaaeodj


Actual output:
aaaaaaafeode


Fixed submission (verdict: Accepted):
s = input()
k = int(input())

len_s = len(s)
moji = [0]*(len_s)

for i in range(len_s):
    num = 26-(ord(s[i])-ord('a'))
    if num <= k and num != 26:
        moji[i] = 'a'
        k -= num
    else:
        moji[i] = s[i]

     
if k != 0:
    
    moji[len_s-1] = chr(ord(moji[len_s-1])+k%26)
        
print(*moji,sep='')
Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = str(input())
k = int(input())

n = len(s)

l = [0]*n
for i in range(n):
    l[i] = ord('z') -ord(s[i]) + 1


ans = list(s)
i = 0
while k > 0:
    if i > n-1:
        break
    if l[i] <= k:
        ans[i] = 'a'
        k -= l[i]
    i += 1
k %= 26
if k > 0:
    ans[-1] = chr((k + ord(ans[-1])-ord('a'))%26+97)

print(''.join(ans))


Failing test case input:
daoffestiwdl
101

Expected output:
aaaaaastiwdn


Actual output:
aaaafeaaiadl


Fixed submission (verdict: Accepted):
s = str(input())
k = int(input())

n = len(s)

l = [0]*n
for i in range(n):
    l[i] = ord('z') -ord(s[i]) + 1
    l[i] %= 26


ans = list(s)
i = 0
while k > 0:
    if i > n-1:
        break
    if l[i] <= k:
        ans[i] = 'a'
        k -= l[i]
    i += 1
k %= 26
if k > 0:
    ans[-1] = chr((k + ord(ans[-1])-ord('a'))%26+97)

print(''.join(ans))

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
k = int(input())
slen = len(s)
new_s = ""

for i in range(slen):
  val = ord("z") + 1 - ord(s[i])
  if k >= val:
    k -= val
    new_s += "a"
  else:
    new_s += s[i]
    
if k > 0:
  new_s = new_s[:-1] + chr(ord(s[slen-1]) + k % 26)

print(new_s)

Failing test case input:
lavitsffeodc
111

Expected output:
aaaaaaaaeadg


Actual output:
aaaaaaafeodn


Fixed submission (verdict: Accepted):
s = input()
k = int(input())
slen = len(s)
new_s = ""

for i in range(slen):
  val = (ord("z") + 1 - ord(s[i])) % 26
  if k >= val:
    k -= val
    new_s += "a"
  else:
    new_s += s[i]
    
if k > 0:
  tmp_val = ord(new_s[slen-1]) + k % 26
  if tmp_val > ord("z"):
    tmp_val -= 26
  new_s = new_s[:-1] + chr(tmp_val)

print(new_s)

Problem: p03994
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
s = input()
K = int(input())

for i,c in enumerate(s):
	x = ord('z')-ord(c)+1
	if x <= K:
		s = s[:i]+'a'+s[i+1:]
		K -= x

print(s[:-1]+chr((ord(s[-1])+K%26-ord('a'))%26+ord('a')))

Failing test case input:
lavitshfeodc
101

Expected output:
aaaaaaaaeodk


Actual output:
aaaaaaafeodf


Fixed submission (verdict: Accepted):
s = input()
K = int(input())

for i,c in enumerate(s):
	x = (ord('z')-ord(c)+1)%26
	if x <= K:
		s = s[:i]+'a'+s[i+1:]
		K -= x

print(s[:-1]+chr((ord(s[-1])-ord('a')+K)%26+ord('a')))

Problem: p03994
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
s = list(input())
k = int(input())

for i in range(len(s)):
    a = 26-(ord(s[i])-97)
    
    
    if k >= a or a != 26:
        k -= a
        s[i] = "a"

s[-1] = chr(97+((ord(s[-1])+k) % 97) % 26)

print("".join(s))


Failing test case input:
liwbtsffeodc
001

Expected output:
liwbtsffeodd


Actual output:
aaaaaaaaaaao


Fixed submission (verdict: Accepted):
s = list(input())
k = int(input())

for i in range(len(s)):
    a = 26-(ord(s[i])-97)
    
    
    if k >= a and a != 26:
        k -= a
        s[i] = "a"

s[-1] = chr(ord(s[-1]) + k % 26)

print("".join(s))
Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

str = input()
K = int(input())
tempK = K
result = ""
for i in range(len(str)):
	changeNum = 122-ord(str[i])+1
	if (changeNum <= tempK):
		result += "a"
		tempK -= changeNum
	else:
		result += str[i]
if (tempK != 0):
	tempK %= 26
	changeNum = ord(str[-1]) + tempK
	if (changeNum > 122):
		changeNum = changeNum -122 + 97 -1
	result = result[:-1] + chr(changeNum)
print(result)


Failing test case input:
zyw
10

Expected output:
aad


Actual output:
aaz


Fixed submission (verdict: Accepted):

str = input()
K = int(input())
tempK = K
result = ""
for i in range(len(str)-1):
	changeNum = 122-ord(str[i])+1
	if (changeNum <= tempK and str[i] != "a"):
		result += "a"
		tempK -= changeNum
	else:
		result += str[i]
tempK %= 26
if (tempK > 0):
	changeNum = ord(str[-1]) + tempK
	if (changeNum > 122):
		changeNum = changeNum -122 + 97 -1
	else:
		changeNum = changeNum
	result += chr(changeNum)
else:
	result += str[-1]
print(result)

Problem: p03994
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):




def ord_until_a(char):
    return ord('a') + 26 - ord(char)


S = input()
K = int(input())
ans = []
for s in S:
    diff = ord_until_a(s)
    if K >= diff:
        ans.append('a')
        K -= diff
    else:
        ans.append(s)

if K > 0:
    K %= 26
    last = ord(ans[-1]) + K
    if last > ord('z'):
        last -= 26
    ans[-1] = chr(last)

print(''.join(ans))


Failing test case input:
caoffestiwdl
111

Expected output:
aaaaaaatiwdo


Actual output:
aaaaaesaiwdl


Fixed submission (verdict: Accepted):




def ord_until_a(char):
    if char == 'a':
        return 0
    return ord('a') + 26 - ord(char)
    


S = input()
K = int(input())
ans = []
for s in S:
    diff = ord_until_a(s)
    if K >= diff:
        ans.append('a')
        K -= diff
    else:
        ans.append(s)

if K > 0:
    K %= 26
    last = ord(ans[-1]) + K
    if last > ord('z'):
        last -= 26
    ans[-1] = chr(last)

print(''.join(ans))

Problem: p03994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
k=int(input())
ss=[]
for i in range(len(s)):
	ss.append(ord(s[i])-ord("a"))
i=0
while k>0:
	if i==len(s)-1:
		ss[i]=(k+ss[i])%26
		break
	elif k>=26-ss[i] and ss[i]!="a":
		k-=(26-ss[i])
		ss[i]=0
	i+=1
ans=""
for i in range(len(s)):
	ans+=chr(ord("a")+ss[i])
print(ans)


Failing test case input:
lwsiuafffodc
101

Expected output:
aaaaaaaafodk


Actual output:
aaaaaaaffodf


Fixed submission (verdict: Accepted):
s=input()
k=int(input())
ss=[]
for i in range(len(s)):
	ss.append(ord(s[i])-ord("a"))
i=0
while k>0:
	if i==len(s)-1:
		ss[i]=(k+ss[i])%26
		break
	elif k>=26-ss[i] and ss[i]!=0:
		k-=(26-ss[i])
		ss[i]=0
	i+=1
ans=""
for i in range(len(s)):
	ans+=chr(ord("a")+ss[i])
print(ans)