qyliang/CodeNanoFix huggingface dataset:
Buggy code:
s=input()
sc=0
tc=0
for i in s:
  if i=="S":
    sc+=1
  elif sc!=0:
    sc-=1
  else tc+=1
print(tc+sc)

Fixed code:
s=input()
sc=0
tc=0
for i in s:
  if i=='S':
    sc+=1
  elif sc!=0:
    sc-=1
  else :tc+=1
print(tc+sc)
Buggy code:
s,t = 0,0
for x in input():
  if x == 'S':
    s += 1
  else:
    if s > 1:
      s -= 1
    else:
      t += 1

print(s+t)

Fixed code:
X = input()

s, t = 0, 0
for x in X:
    if x == "S":
        s += 1
    else:
        if s == 0:
            t += 1
        else:
            s -= 1

print(s+t)
Buggy code:
# -*- coding: utf-8 -*-

text = list(input())
txt_stuck = []

for i in text:
    if i == 'S':
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck == []:
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck[-1] == 'T':
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck[-1] == 'S':
        txt_stuck.pop()

print(''.join(txt_stuck))

Fixed code:
# -*- coding: utf-8 -*-

text = list(input())
txt_stuck = []

for i in text:
    if i == 'S':
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck == []:
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck[-1] == 'T':
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck[-1] == 'S':
        txt_stuck.pop()

print(len(txt_stuck))
Buggy code:
# coding: utf-8
n_S, n_T = 0, 0

if c in input():
    if c == "S":
        n_S += 1
    else:
        if n_S:
            n_S -= 1
        else:
            T += 1
print(n_S + n_T)


Fixed code:
# coding: utf-8
n_S, n_T = 0, 0

for c in input():
    if c == "S":
        n_S += 1
    else:
        if n_S:
            n_S -= 1
        else:
            n_T += 1
print(n_S + n_T)
Buggy code:
s=input()
ans=0
count=0
for i in s:
    if i=='S':count=max(1,count+1)
    else:count-=1
    if count<0:ans+=1
print(ans*2,count)

Fixed code:
s=input()
ans=0
count=0
for i in s:
    if i=='S':count=max(1,count+1)
    else:count-=1
    if count<0:ans+=1
print(ans*2)
Buggy code:
s = list(input())
l = []
for i in range(len(s)):
    if s[i] == 'S':
        l.append('S')
    elif l[-1] == 'T' or not l:
        l.append('T')
    else:
        l.pop()
print(len(l))



Fixed code:
s = list(input())
l = []
for i in range(len(s)):
    if s[i] == 'S':
        l.append('S')
    elif not l:
        l.append('T')
    elif l[-1] == 'T':
        l.append('T')
    else:
        l.pop()
print(len(l))
Buggy code:
x = input()
c = 0
for i in x:
  if x == "S":
    c += 1
  elif c>0:
    c -= 1
print(2*c)
  

Fixed code:
x = list(input())
c = 0
for i in x:
  if i == "S":
    c += 1
  elif c>0:
    c -= 1
print(2*c)
Buggy code:
s = input()
stack = [s[0]]
for i in range(1,len(s)):
    cur_str = stack[-1]
    new_str = s[i]
    if cur_str+new_str=="ST":
        stack.pop()
    else:
        stack.append(new_str)
print(len(stack))


Fixed code:
s = input()
stack = [s[0]]
for i in range(1,len(s)):
    if len(stack)==0:
        stack.append(s[i])
        continue
    else:
        cur_str = stack[-1]
        new_str = s[i]
        if cur_str+new_str=="ST":
            stack.pop()
        else:
            stack.append(new_str)
print(len(stack))
Buggy code:
from collections import deque
S=input()
table=deque()
table.append(1)
ans=0
for s in S:
    if s=='S':
        table.append(1)
        #print(table,ans)
    else:
        if len(table)==1:
            table[0]==1
           #print(table,ans)
        else:
            table.pop()
            ans+=table[-1]
            #table[-1]+=1
            #print(table,ans)
print(ans)

Fixed code:
from collections import deque
S=input()
table=deque()
table.append(1)
ans=0
for s in S:
    if s=='S':
        table.append(1)
        #print(table,ans)
    else:
        if len(table)==1:
            table[0]==1
           #print(table,ans)
        else:
            table.pop()
            ans+=table[-1]
            #table[-1]+=1
            #print(table,ans)
print(len(S)-2*ans)
Buggy code:
s=input()
ls=len(s)
c=0
for i in range(ls):
    if s[i]=='S':
        c+=1
    elif c>0:
        ans+=2
        c-=1
print(ls-ans)

Fixed code:
s = input()
ans = len(s)
c = 0
for i in range(len(s)):
    if s[i] == 'S':
        c += 1
    elif c > 0:
        ans -= 2
        c -= 1
print(ans)
Buggy code:
a=input()
x=0
b=0
for i in a:
  if i=="T" and x<-1:
    x+=1
  elif i=="S":
    x-=1
    
  if x==0:
    b+=1
print(b*2)

Fixed code:
a=input()
x=0
b=0
for i in a:
  if i=="T" and x<=-1:
    x+=1
  elif i=="S":
    x-=1
  elif x==0:
    b+=1
print(b*2)
Buggy code:
string = input()
stack = ""

for i in string:
    if i == "S":
        stack += i
    elif i == "T" and (stack == "" or stack[-1] == "T"):
        stack += i
    else:
        stack = stack[0:-1]
    print(stack)

print(len(stack))


Fixed code:
string = input()
stack = ""

for i in string:
    if i == "S":
        stack += i
    elif i == "T" and (stack == "" or stack[-1] == "T"):
        stack += i
    else:
        stack = stack[0:-1]

print(len(stack))
Buggy code:
s = input()
cnt = 0
while cnt < 100000:
    print(1)
    n = len(s)
    s = ''.join(s.split('ST'))
    if len(s) != n:
        cnt += (len(s) - n) // 2
    else:
        break
    i = s.find('ST')
    
    stlen = 0
    if i > 0:
        for j in range(min(i, len(s)-2-i)):
            if s[i-j-1] == 'S' and s[i+j+2] == 'T':
                stlen += 1
            else:
                break
        s = s[:i-stlen] + s[i+stlen+2:]
        cnt += 1 + stlen
print(len(s))

Fixed code:
s = input()
cnt = 0
while cnt < 100000:
    n = len(s)
    s = ''.join(s.split('ST'))
    if len(s) != n:
        cnt += (len(s) - n) // 2
    else:
        break
    i = s.find('ST')
    
    stlen = 0
    if i > 0:
        for j in range(min(i, len(s)-2-i)):
            if s[i-j-1] == 'S' and s[i+j+2] == 'T':
                stlen += 1
            else:
                break
        s = s[:i-stlen] + s[i+stlen+2:]
        cnt += 1 + stlen
print(len(s))
Buggy code:
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
K = int(input())

ans = []
for i, c in enumerate(S):
    num = ord('z') - ord(c) + 1
    if K >= num:
        K -= num
        ans.append('a')
    else:
        ans.append(c)
if K > 0:
    ans[-1] = chr((ord(S[-1]) - ord('a') + K) % 26 + ord('a'))
print("".join(an))
    


Fixed code:
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
K = int(input())

ans = []
for i, c in enumerate(S):
    if c == 'a':
        ans.append(c)
        continue
    num = ord('z') - ord(c) + 1
    if K >= num:
        K -= num
        ans.append('a')
    else:
        ans.append(c)
if K > 0:
    ans[-1] = chr((ord(ans[-1]) - ord('a') + K % 26) % 26 + ord('a'))
print("".join(ans))
Buggy code:
import sys, math
from itertools import accumulate
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    s, K = input(), ii()
    l = list(map(lambda c: (ord('z')-ord(c)+1)%26, s))

    acc = 0
    t = ''
    for i in range(len(s)):
        if acc + l[i] <= K:
            acc += l[i]
            t += 'a'
        else:
            if i == len(s)-1 and K-acc > 0:
                t += chr(ord(s[i])+K-acc)
            else:
                t += s[i]

    print(t)
        




if __name__ == "__main__":
    main()

Fixed code:
import sys, math
from itertools import accumulate
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    s, K = input(), ii()
    l = list(map(lambda c: (ord('z')-ord(c)+1)%26, s))

    acc = 0
    t = ['']*len(s)
    for i in range(len(s)):
        if acc + l[i] <= K:
            acc += l[i]
            t[i] = 'a'
        else:
            t[i] = s[i]

    if i == len(s)-1 and K-acc > 0:
        t[i] = chr((ord(t[i])-ord('a')+K-acc)%26+ord('a'))

    print(''.join(t))

if __name__ == "__main__":
    main()
Buggy code:
s = list(input())
k = int(input())

for i in range(len(s)):
    a = 26-(ord(s[i])-97)
    # print(ord(s[i]))
    # print(a)
    if k >= a or a != 26:
        k -= a
        s[i] = "a"
# print(k)
s[-1] = chr(97+((ord(s[-1])+k) % 97) % 26)
# print(ord(s[-1]))
print("".join(s))


Fixed code:
s = list(input())
k = int(input())

for i in range(len(s)):
    a = 26-(ord(s[i])-97)
    # print(ord(s[i]))
    # print(a)
    if k >= a and a != 26:
        k -= a
        s[i] = "a"
# print(k)
s[-1] = chr(ord(s[-1]) + k % 26)
# print(ord(s[-1]))
print("".join(s))
Buggy code:
s = input()
k = int(input())

ans = ""
for si in s:
  num = ord("z") - ord(si) + 1
  if num <= k:
    ans += "a"
    k -= num
  else:
    ans += si

if k > 0:
  num = k % 26
  num -= ord("z") - ord(ans[-1])
  if num == 0:
    new_c = "z"
  else:
    new_c = chr(ord("a") - 1 + num)
  print(ans[:-1] + new_c)
else:
  print(ans)




Fixed code:
s = input()
k = int(input())

ans = ""
for si in s:
  if si == "a":
    ans += "a"
    continue
  num = ord("z") - ord(si) + 1
  if num <= k:
    ans += "a"
    k -= num
  else:
    ans += si

if k > 0:
  num = k % 26
  if ord(ans[-1]) + num <= ord("z"):
    new_c = chr(ord(ans[-1]) + num)
  else:
    num -= ord("z") - ord(ans[-1])
    new_c = chr(ord("a") - 1 + num)
  print(ans[:-1] + new_c)
else:
  print(ans)
Buggy code:
s = list(input())
k = int(input())
n = len(s)
for i in range(n):
    if k <= 0 or s[i] == 'a':
        continue
    if 123 - ord(s[i]) <= k:
        k -= 123 - ord(s[i])
        s[i] = 'a'
# print(k)
# print(s)
k %= 26
print(ord(s[-1])+k)
if ord(s[-1])+k > 122:
    s[-1] = chr(97+(122-ord(s[-1])+k))
else:
    s[-1] = chr(ord(s[-1])+k)
# print(k)
print(*s, sep='')


Fixed code:
s = list(input())
k = int(input())
n = len(s)
for i in range(n):
    if k <= 0 or s[i] == 'a':
        continue
    if 123 - ord(s[i]) <= k:
        k -= 123 - ord(s[i])
        s[i] = 'a'
# print(k)
# print(s)
k %= 26
# print(ord(s[-1])+k)
if ord(s[-1])+k > 122:
    s[-1] = chr(97+(122-ord(s[-1])+k))
else:
    s[-1] = chr(ord(s[-1])+k)
# print(k)
print(*s, sep='')
Buggy code:
s=input()
k=int(input())

ans = []
rem = k
for si in s[:-1]:
    if si == 'a':
        to_a = 0
    else:
        to_a = ord('z') - ord(si) + 1

    if to_a <= rem:
        rem -= to_a
        ans.append('a')
    else:
        ans.append(si)
        # next_s = chr(ord(si) + rem)
        # ans.append(next_s)
        # rem = 0


last_s_ord = (ord(s[-1]) + rem - ord('a'))%ord('a')
last_s = chr(ord('a') + last_s_ord)
ans.append(last_s)
ans = ''.join(ans)
print(ans)

Fixed code:
s=input()
k=int(input())

ans = []
rem = k
for si in s[:-1]:
    if si == 'a':
        to_a = 0
    else:
        to_a = ord('z') - ord(si) + 1

    if to_a <= rem:
        rem -= to_a
        ans.append('a')
    else:
        ans.append(si)
        # next_s = chr(ord(si) + rem)
        # ans.append(next_s)
        # rem = 0


last_s_ord = (ord(s[-1]) + rem - ord('a'))%26
last_s = chr(ord('a') + last_s_ord)
ans.append(last_s)
ans = ''.join(ans)
print(ans)
Buggy code:
s=input()
k=int(input())
n=len(s)
ans=""
for i in range(n):
    if i<n-1:
        if s[i]=="a":
            ans+="a"
        else:
            t=123-ord(s[i])
            if k>=t:
                ans+="a"
                k-=t
            else:
                ans+=s[i]
    if i==n-1:
        tt=k%26
        ans+=chr(ord(s[i])+tt)
print(ans)                

Fixed code:
s=input()
k=int(input())
n=len(s)
ans=""
for i in range(n):
    if i<n-1:
        if s[i]=="a":
            ans+="a"
        else:
            t=123-ord(s[i])
            if k>=t:
                ans+="a"
                k-=t
            else:
                ans+=s[i]
    if i==n-1:
        tt=(ord(s[i])-97+k)%26
        ans+=chr(tt+97)
print(ans)
Buggy code:
from bisect import *
S = list(str(input()))
K = int(input())

alp = list("abcdefghijklmnopqrstuvwxyz")

for i in range(len(S)):
  b = bisect_left(alp,S[i])
  print(b,K,S)
  if i == len(S)-1:
    S[i] = alp[(b+K)%26]
  elif 26 - b <= K:
    K -= (26 - b)
    S[i] = "a"
  if K == 0:
    break
  
print("".join(S))

Fixed code:
from bisect import *
S = list(str(input()))
K = int(input())

alp = list("abcdefghijklmnopqrstuvwxyz")

for i in range(len(S)):
  b = bisect_left(alp,S[i])

  if i == len(S)-1:
    S[i] = alp[(b+K)%26]
  elif b == 0:
    continue
  elif 26 - b <= K:
    K -= (26 - b)
    S[i] = "a"
  if K == 0:
    break
  
print("".join(S))
Buggy code:
s,k,t=input(),int(input()),""
for q in s:
 if(p:=(122-ord(q))%26)<k:t+="a";k-=p
 else:t+=q
print(t[:-1]+chr((ord(t[-1])-97+k)%26+97))

Fixed code:
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))
Buggy code:
s = input()
K = int(input())
k = K

ans = ""
for i in range(len(s)-1):
    if(s[i] == "a"):
        continue
    if(ord(s[i])+k >= ord("z")+1):
        ans += "a"
        k -= ord("z")+1-ord(s[i])
    else:
        ans += s[i]

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

Fixed code:
s = input()
K = int(input())
k = K

ans = ""
for i in range(len(s)-1):
    if(s[i] == "a"):
        ans += s[i]
        continue
    if(ord(s[i])+k >= ord("z")+1):
        ans += "a"
        k -= ord("z")+1-ord(s[i])
    else:
        ans += s[i]

a = ord(s[-1])+k%26
if(a > ord("z")):
    a -= 26
ans += chr(a)
    
print(ans)
Buggy code:
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
l[-1]=chr(ord(s[-1])+k)
print("".join(l))

Fixed code:
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))
Buggy code:
S = input()
K = int(input())

ord_a = ord('a')
ord_z = ord('z')

k = K
Ans = list(S)
for i, s in enumerate(S[:-1]):
    ord_s = ord(s)
    dif = ord_z - ord_s + 1
#    print(i, k, dif)
    if s == 'a':
        continue
    elif dif <= k:
        Ans[i] = 'a'
        k -= dif
    else:
        Ans[-1] = chr(ord_a + (ord(Ans[-1]) + k - ord_a)%26)
        k -= k
        break
else:
    Ans[-1] = chr(ord_a + (ord(Ans[-1]) + k - ord_a)%26)
print(''.join(Ans))

Fixed code:
S = input()
K = int(input())

ord_a = ord('a')
ord_z = ord('z')

k = K
Ans = list(S)
for i, s in enumerate(S[:-1]):
    ord_s = ord(s)
    dif = ord_z - ord_s + 1
#    print(i, k, dif)
    if s == 'a':
        Ans[i] = 'a'
    elif dif <= k:
        Ans[i] = 'a'
        k -= dif
    else:
        pass
Ans[-1] = chr(ord_a + (ord(Ans[-1]) + k - ord_a)%26)
print(''.join(Ans))
Buggy code:
s=input()
k=int(input())
ans=''
for i in range(len(s)-1):
  if not s[i]=='a':
    if k>=123-ord(s[i]):
      k-=(123-ord(s[i]))
      ans+='a'
    else:
      ans+=s[i]
ans+=chr((ord(s[-1])-97+k)%26+97)
print(ans)

Fixed code:
s=input()
k=int(input())
ans=''
for i in range(len(s)-1):
  if s[i]=='a':
    ans+='a'
  else:
    if k>=123-ord(s[i]):
      k-=(123-ord(s[i]))
      ans+='a'
    else:
      ans+=s[i]
ans+=chr((ord(s[-1])-97+k)%26+97)
print(ans)
Buggy code:
s = list(input())
k = int(input())
n = len(s)
for i in range(n):
    if s[i]=='a':continue
    d = ord('z')-ord(s[i])+1
    if d<=k:
        s[i] = 'a'
        k -= d

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

print(''.join(s))


Fixed code:
s = list(input())
K = int(input())

for i in range(len(s)):
    if s[i] == "a":
        continue
    d = ord("z")-ord(s[i]) + 1
    if d <= K:
        s[i] = "a"
        K -= d

x = (ord(s[-1])-ord("a")+K)%26
s[-1] = chr(ord("a")+x)
print("".join(s))
Buggy code:
makeA = lambda c: (ord('z')-ord(c)+1) % 26
s = list(map(makeA,list(input())))
print(s)
K = int(input())
len_s = len(s)
print(len_s)
for i in range(len_s-1):
    if s[i] <= K:
        K -= s[i]
        s[i] = 0
        print(s)
if K > 0:
    s[-1] = (s[-1] + 26 - (K % 26)) % 26
print(s)
makeS = lambda n: chr((26-n)%26+ord('a'))
print(''.join(list(map(makeS,s))))

Fixed code:
makeA = lambda c: (ord('z')-ord(c)+1) % 26
s = list(map(makeA,list(input())))
#print(s)
K = int(input())
len_s = len(s)
#print(len_s)
for i in range(len_s-1):
    if s[i] <= K:
        K -= s[i]
        s[i] = 0
        #print(s)
if K > 0:
    s[-1] = (s[-1] + 26 - (K % 26)) % 26
#print(s)
makeS = lambda n: chr((26-n)%26+ord('a'))
print(''.join(list(map(makeS,s))))
Buggy code:
S = input()
K = int(input())
z = ord('z') + 1

res = ""
flg = False
for i,c in enumerate(S):
    if z - ord(c) <= K:
        res += 'a'
        K -= z-ord(c)
    else:
        res += chr(ord(c))

res = res[:-1] + chr((ord(res[-1]) + K)%26)
print(res)


Fixed code:
S = input()
K = int(input())
z = ord('z') + 1

res = ""
flg = False
for i,c in enumerate(S):
    if c == 'a':
        res += 'a'
        continue
    elif z - ord(c) <= K:
        res += 'a'
        K -= z-ord(c)
    else:
        res += chr(ord(c))

res = res[:-1] + chr((ord(res[-1])-ord('a') + K) % 26 + ord('a'))
print(res)
Buggy code:
from collections import deque
s = input()
k = int(input())
a = ord("a")codefestival
100
l = deque(list())
l1 = []
for i in range(len(s)):
    s1 = s[i]
    l.append(((a+26)-ord(s1))%26)
while k!=0:
    if len(l)!=0:
        t = l.popleft()
        if k>=t:
            l1.append("a")
            k -= t
        else:
            l1.append(chr(ord('a')-t+26))
    else:
        l1[-1] = chr(int(ord(l1[-1])+k))
        k = 0
print(''.join(l1))

Fixed code:
from collections import deque
s = input()
k = int(input())
a = ord("a")
l = deque(list())
l1 = []
for i in range(len(s)):
  s1 = s[i]
  l.append(((a+26)-ord(s1))%26)
#print(l)
while k!=0:
    if len(l)!=0:
        t = l.popleft()
        if k>=t:
            l1.append("a")
            k -= t
        else:
          if t=="a":
            l1.append(t)
          else:
            l1.append(chr((ord('a')-t+26)))
    else:
      k %= 26
      l1[-1] = chr(int(ord(l1[-1])+k))
      k = 0
l2 = []
if len(l)>=1:
  for t in l:
    t %= 26
    if t==0:
      l2.append("a")
    else:
      l2.append(chr((ord('a')-t+26)))
  l1 += l2
print("".join(l1))
Buggy code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    for i in range(len(s)):
        if si == "a":
            continue
        si = ord(s[i]) - 97
        if k >= 26 - si:
            s[i] = "a"
            k -= 97 + 26 - si
            if k == 0:
                break

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

    print(*s, sep="")


if __name__ == '__main__':
    main()


Fixed code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    for i in range(len(s)):
        if s[i] == "a":
            continue
        si = ord(s[i]) - 97
        if k >= 26 - si:
            s[i] = "a"
            k -= 26 - si
            if k == 0:
                break

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

    print(*s, sep="")


if __name__ == '__main__':
    main()
Buggy code:
s=list(input())
print(s)
K=int(input())
i=0
while i<len(s):
    if i==len(s)-1:
        s[i]=chr(97+(ord(s[i])-97+K)%26)
        break
    if K<abs(123-ord(s[i]))%26:
        i+=1
    elif K>=abs(123-ord(s[i]))%26:
        sub=abs(123-ord(s[i]))%26
        s[i]="a"
        K-=sub
        i+=1
print("".join(s))

Fixed code:
s=list(input())
K=int(input())
i=0
while i<len(s):
    if i==len(s)-1:
        s[i]=chr(97+(ord(s[i])-97+K)%26)
        break
    if K<abs(123-ord(s[i]))%26:
        i+=1
    elif K>=abs(123-ord(s[i]))%26:
        sub=abs(123-ord(s[i]))%26
        s[i]="a"
        K-=sub
        i+=1
print("".join(s))
Buggy code:
ss=input()
s=list(ss)
k=int(input())
l=len(s)
z=ord('z')
a=ord('a')
for i in range(l):
    if z-ord(s[i])+1<=k:
        k-=z-ord(s[i])+1
        s[i]='a'

if k>0:
    last=(ord(s[-1])+k-a)%(z-a)+a
    s[-1]=chr(last)

ans=''.join(s)
print(ans)

Fixed code:
z=ord('z')
a=ord('a')
ss=input()
s=list(ss)
k=int(input())
l=len(s)

for i in range(l):
    if (z-ord(s[i])+1<=k)and(s[i]!='a'):
        k-=z-ord(s[i])+1
        s[i]='a'

if k>0:
    last=(ord(s[-1])+k-a)%26+a
    s[-1]=chr(last)

ans=''.join(s)
print(ans)
Buggy code:
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    s = list(input())
    k = int(input())
    for i in range(len(s)):
        if s[i] == 'a':
            continue
        if k >= ord('z') - ord(s[i]) + 1:
            k -= ord('z') - ord(s[i]) + 1
            s[i] = 'a'
            if k == 0:
                break
    
    if k > 0:
        s[-1] = chr((ord(s[-1]) + k - 91)%26 + 91)
    
    print(''.join(s))
if __name__ == '__main__':
    main()


Fixed code:
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    s = list(input())
    k = int(input())
    for i in range(len(s)):
        if s[i] == 'a':
            continue
        if k >= ord('z') - ord(s[i]) + 1:
            k -= ord('z') - ord(s[i]) + 1
            s[i] = 'a'
            if k == 0:
                break
    
    if k > 0:
        s[-1] = chr((ord(s[-1]) + k - 97)%26 + 97)
    
    print(''.join(s))
if __name__ == '__main__':
    main()