Problem:
 Score : 400 points    Problem Statement Mr. Takahashi has a string s consisting of lowercase English letters.
He repeats the following operation on s exactly K times.   Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of z is a .   For example, if you perform an operation for the second letter on aaz , aaz becomes abz .
If you then perform an operation for the third letter on abz , abz becomes aba .  Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s .
Find the such string.      Constraints  1≤|s|≤10^5  All letters in s are lowercase English letters.  1≤K≤10^9         Input The input is given from Standard Input in the following format:  s  K       Output Print the lexicographically smallest string after performing exactly K operations on s .        Sample Input 1 xyz
4      Sample Output 1 aya  For example, you can perform the following operations: xyz , yyz , zyz , ayz , aya .       Sample Input 2 a
25      Sample Output 2 z  You have to perform exactly K operations.       Sample Input 3 codefestival
100      Sample Output 3 aaaafeaaivap

Solution (Python):
import sys
import itertools

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


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))

Solution (Python):
s = list(input())
k = int(input())
ls = list("abcdefghijklmnopqrstuvwxyz")
ls.sort(reverse=True)
ls = ["a"] + ls[:-1]
for i in range(len(s)):
    if i != len(s)-1:
        if k >= ls.index(s[i]):
            k -= ls.index(s[i])
            s[i] = "a"
        else:
            continue
    else:
        k %= 26
        s[-1] = ls[(ls.index(s[-1])-k)%26]
print("".join(s))

Solution (Python):
s=input()
k=int(input())
num=[(123-ord(s[i]))%26 for i in range(len(s))]
ans=""
for i in range(len(s)-1):
    if num[i]<=k:
        ans+="a"
        k-=num[i]
    else:
        ans+=s[i]
k%=26
if num[-1]<=k:
    ans+=chr(97+k-num[-1])
else:
    ans+=chr(ord(s[-1])+k)
print(ans)

Solution (Python):
s = input()
k = int(input())
v = list(s)
n = len(s)
a = [0 for i in range(n)]

for i in range(n):
  a[i] = (123 - ord(s[i]))%26
  if k == 0:
    break
  if k >= a[i]:
    v[i] = 'a'
    k -= a[i]

if k > 0:
  k %= 26
  v[n-1] = chr(ord(v[n-1])+k)
print (''.join(v))

Solution (Python):
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()

Solution (Python):
import sys
input = sys.stdin.readline


def read():
    s = input().strip()
    K = int(input().strip())
    return s, K


def solve(s, K):
    ans = []
    for a in s:
        c = (ord("z") - ord(a) + 1) % 26
        if c <= K:
            K -= c
            ans.append("a")
        else:
            ans.append(a)
    if K > 0:
        c = (ord(ans[-1]) - ord("a") + K) % 26
        ans[-1] = chr(c + ord("a"))
    return "".join(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Solution (Python):
S=input()
K=int(input())
lenS=len(S)
for i in range(lenS-1):
    ordS_i=ord(S[i])
    if (ord("a")-ordS_i)%26<=K:
        K-=(ord("a")-ordS_i)%26
        S=S[:i]+"a"+S[i+1:]
ordS_i=ord(S[lenS-1])
moda=(ordS_i-ord("a")+K)%26
S=S[:lenS-1]+chr(ord("a")+moda)
print(S)

Solution (Python):
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))

Solution (Python):
s = input()
k = int(input())

for i in range(len(s)):
    if s[i] != "a":
        req = ord("z") - ord(s[i]) + 1

        if req <= k:
            k -= req
            s = s[:i] + "a" + s[i+1:]

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

print(s)

Solution (Python):
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)

Solution (Python):

def resolve():
    def decode(x):
        return ord(x) - 97

    def encode(x):
        return chr(x + 97)

    S = list(map(decode, input()))
    K = int(input())

    for i in range(len(S) - 1):
        if S[i] == 0:
            continue
        if 26 - S[i] <= K:
            K -= 26 - S[i]
            S[i] = 0

    S[-1] = (S[-1] + K) % 26
    ans = map(encode, S)
    print("".join(ans))


if __name__ == "__main__":
    resolve()

Solution (Python):

def resolve():
    S = input()
    K = int(input())

    ans = []
    for s in S:
        diff = ord(s) - ord("a")
        if diff == 0:
            ans.append("a")
            continue
        elif 26 - diff <= K:
            ans.append("a")
            K -= 26 - diff
        else:
            ans.append(s)

    K %= 26
    d = (K + ord(ans[-1]) - ord('a')) % 26
    ans[-1] = chr(d + ord('a'))

    print("".join(ans))


if __name__ == "__main__":
    resolve()

Solution (Python):
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

s=input()
N=len(s)
K=intput()
ans=[]
for i in range(N-1):
    if (26-ston(s[i]))%26<=K:
        ans.append('a')
        K-=(26-ston(s[i]))%26
    else:
        ans.append(s[i])
ans.append(ntos((ston(s[N-1])+K)%26))
lprint(ans,'')

Solution (Python):
S = input()
K = int(input())

oz = ord("z")

ans = ""

for s in S[:-1]:
    if s != "a" and oz+1-ord(s) <= K:
        K -= oz+1-ord(s)
        ans += "a"
    else:
        ans += s

ans += chr(((ord(S[-1])-ord("a")+K)%26)+ord("a"))

print(ans)

Solution (Python):
s = list(input())
k = int(input())

for i, c in enumerate(s):
    t = (ord("z") - ord(c) + 1) % 26
    if k >= t:
        s[i] = "a"
        k -= t

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

print("".join(s))

Solution (Python):
S = input()
S = list(S)

def func(c) -> int:
    t = 26 - (ord(c) - ord('a'))
    t %= 26
    return t

L = [func(c) for c in S]

K = int(input())
for i in range(len(L)):
    if(L[i] <= K):
        K -= L[i]
        L[i] = 0
    else:
        continue

if(K > 0):
    
    K %= 26
    L[-1] -= K
    if(L[-1] < 0):
        L[-1] += 26

def gunc(c):
    t = 26 - c
    t %= 26
    return chr(t+97)
ans = [gunc(c) for c in L]
st = ''
for c in ans:
    st += c
print(st)

Solution (Python):
def main():
    S = list(input())
    K = int(input())
    L = len(S)
    for i in range(L):
        if S[i] == 'a':
            continue
        if ord('z') - ord(S[i]) + 1 <= K:
            K -= ord('z') - ord(S[i]) + 1
            S[i] = 'a'

    if K > 0:
        S[-1] = chr(ord(S[-1]) + K % 26)

    print(''.join(S))




if __name__ == "__main__":
    main()

Solution (Python):
s = list(input())
k = int(input())

for i in range(len(s)):
  if s[i] != 'a' and 123 - ord(s[i]) <= k:
    k -= (123 - ord(s[i]))
    s[i] = "a"
    

k %= 26
if ord(s[-1]) + k > 122:
  s[-1] = chr(ord(s[-1]) + k - 26)
else:
  s[-1] = chr(ord(s[-1]) + k)
ans = ""
for i in s:
  ans += i
print(ans)

Solution (Python):
import sys



def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = list(input())
    k = input_int()

    
    
    for i in range(len(S)):
        c = ord(S[i])
        if c == ord("a"):
            continue
        dif = ord("z") - c + 1
        if dif <= k:
            S[i] = "a"
            k -= dif
    
    S[-1] = chr(ord("a") + ((ord(S[-1]) - ord("a")) + (k % 26)))
    print("".join(S))
    return


if __name__ == "__main__":
    main()

Solution (Python):
s = list(input())
K = int(input())
zp1 = 1+ord('z')
for i in range(len(s)):
    si = s[i]
    cost = (zp1-ord(si))%26
    if cost <= K:
        K -= cost
        s[i] = 'a'
s[-1] = chr(ord('a') + (K + ord(s[-1]) - ord('a')) % 26)
print(''.join(s))

Solution (Python):
def main():
    S = input()
    K = int(input())
    ans = ['' for _ in range(len(S))]
    for i in range(len(S)):
        d = ord(S[i]) - ord('a')
        shift = (26 - d) % 26
        if K - shift >= 0:
            ans[i] = 'a'
            K -= shift
        else:
            ans[i] = S[i]
    if K > 0:
        K %= 26
        d = (K + ord(ans[-1]) - ord('a')) % 26
        ans[-1] = chr(d + ord('a'))
    print(''.join(ans))


if __name__ == '__main__':
    main()

Solution (Python):
class common_function():
    """
        1. よく使いそうで予め用意しておいた変数をまとめた
        2. よく使いそうな関数群をまとめた
    """
    def __init__(self):
        """
            1. 英字の一覧をリストに格納しておいた変数
        """
        self.sletter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
        self.bletter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']


def main():
    common = common_function()
    s = list(input())
    K = int(input())
    t = [0]
    for i in range(len(common.sletter)-1, 0, -1):
        t.append(i)

    u = []
    for i in range(len(s)):
        u.append(t[common.sletter.index(s[i])])
    
    ans = ''
    for i in range(len(s)-1):
        if u[i] <= K:
            ans += 'a'
            K -= u[i]
        else:
            ans += s[i]
    K = K%26
    if u[len(s)-1] <= K:
        K -= u[len(s)-1]
        ans += common.sletter[K]
    else:
        ans += common.sletter[common.sletter.index(s[len(s)-1])+K]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
s = list(input())
n = len(s)
k = int(input())

for i in range(n):
    if k > 0 and i == n-1:
        x = ord(s[i])-ord("a")
        s[i] = chr((k+x)%26+ord("a"))
        break
    if s[i] == "a":
        continue
    x = ord(s[i])-ord("a")

    if k >= 26-x:
        s[i] = "a"
        k -= 26-x
print(*s,sep="")

Solution (Python):
s = list(input())
k = int(input())
for i in range(len(s)):
  dp = 26-ord(s[i])+97
  if k >= dp and s[i] != "a":
    k-=dp
    s[i] = "a"
    if k == 0:
      break
else:
  s[-1] = chr((ord(s[-1])-97+k)%26+97)
print(*s,sep="")

Solution (Python):
s = list(input())
k = int(input())
num = len(s)

for i in range(num):
    a = 122-ord(s[i])+1
    if a <= k and s[i] != 'a':
        k -= a
        s[i] = 'a'
if k > 0:
    s[-1] = chr(ord(s[-1])+k%26)
print(*s, sep='')

Solution (Python):
alpha=[chr(ord('a') + i) for i in range(26)]
a=list(input())
N=int(input())
for i in range(len(a)):
   s=26-alpha.index(a[i])
   if s<=N and s!=26:
      a[i]="a"
      N-=s
s=alpha.index(a[-1])
s=(s+N)%26
a[-1]=alpha[s]
print(*a,sep="")

Solution (Python):
s = list(input())
K = int(input())
l = len(s)
for i in range(l-1):
    x = (ord('a')-ord(s[i])) % 26
    if x <= K:
        K -= x
        s[i] = 'a'
s[l-1] = chr(ord('a') + (ord(s[-1])-ord('a')+K) % 26)
print(''.join(s))

Solution (Python):
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'


k %= 26

if ord(s[-1])+k > 122:
    s[-1] = chr(97+(122-ord(s[-1])+k))
else:
    s[-1] = chr(ord(s[-1])+k)

print(*s, sep='')

Solution (Python):
s = list(input())
K = int(input())
ans = []
for c in s:
    cnt = ord('z') - ord(c) + 1
    if c == 'a':
        ans.append('a')
    elif K >= cnt:
        K -= cnt
        ans.append('a')
    else:
        ans.append(c)
K %= 26
if 122 < ord(ans[-1]) + K:
    ans[-1] = chr(ord(ans[-1]) + K - 26)
else:
    ans[-1] = chr(ord(ans[-1]) + K)
print(*ans,sep='')

Solution (Python):
s = list(input())
K = int(input())
ans = []
for c in s:
    cnt = ord('z') - ord(c) + 1
    if c == 'a':
        ans.append('a')
    elif K >= cnt:
        K -= cnt
        ans.append('a')
    else:
        ans.append(c)
K %= 26
if 122 < ord(ans[-1]) + K:
    ans[-1] = chr(ord(ans[-1]) + K - 26)
else:
    ans[-1] = chr(ord(ans[-1]) + K)
print(*ans,sep='')

Solution (Python):
from string import ascii_lowercase
s = input()
k = int(input())

def main(s, k):
    alp = ascii_lowercase
    num = {char: i for i, char in enumerate(alp)}

    ns = [num[char] for char in s]

    for i in range(len(ns)):
        v = ns[i]
        if v != 0 and 26 - v <= k:
            ns[i] = 0
            k -= 26 - v

    ns[-1] = (ns[-1] + k) % 26

    return ''.join(alp[n] for n in ns)
print(main(s, k))

Solution (Python):

list = {'a':0,'b':25,'c':24,'d':23,'e':22,'f':21,'g':20,'h':19,
         'i': 18,'j':17,'k':16,'l':15,'m':14,'n':13,'o':12,'p':11,
         'q': 10,"r":9,'s':8,'t':7,'u':6,'v':5,'w':4,'x':3,'y':2,'z':1}
list2 = {0:'a',1:'b',2:'c',3:'d',4:'e',5:'f',6:'g',7:'h',
         8:'i',9:'j',10:'k',11:'l',12:'m',13:'n',14:'o',15:'p',
         16:'q',17:"r",18:'s',19:'t',20:'u',21:'v',22:'w',23:'x',24:'y',25:'z'}
list3 = {'a':0,'b':1,'c':2,'d':3,'e':4,'f':5,'g':6,'h':7,
         'i': 8,'j':9,'k':10,'l':11,'m':12,'n':13,'o':14,'p':15,
         'q': 16,"r":17,'s':18,'t':19,'u':20,'v':21,'w':22,'x':23,'y':24,'z':25}
s = input()

K = int(input())

for i in range(len(s)):
    num = list[s[i]]
    if num <=K:
        s = s[:i] + 'a' + s[i+1:]
        K -= num

if K >0:
    print(s[:-1]+list2[(list3[s[-1]]+K)%26])
else:
    print(s)

Solution (Python):
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)
        
        
        


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)

Solution (Python):
import string
abc = string.ascii_lowercase
s = list(input())
K = int(input())
index = 0
while K > 0:
    if index == len(s) - 1:
        s[index] = abc[(abc.index(s[index]) + K) % 26]
        break
    tmp = 26 - abc.index(s[index])
    if tmp == 26:
        index += 1
        continue
    if K >= tmp:
        s[index] = 'a'
        index += 1
        K -= tmp
    else:
        index += 1

for i in s:
    print(i, end='')

Solution (Python):
import string
abc = string.ascii_lowercase
s = list(input())
K = int(input())
index = 0
while K > 0:
    if index == len(s) - 1:
        s[index] = abc[(abc.index(s[index]) + K) % 26]
        break
    tmp = 26 - abc.index(s[index])
    if tmp == 26:
        index += 1
        continue
    if K >= tmp:
        s[index] = 'a'
        index += 1
        K -= tmp
    else:
        index += 1

for i in s:
    print(i, end='')

Solution (Python):
s = list(input())
k = int(input())

for i, c in enumerate(s):
    t = (ord("z") - ord(c) + 1) % 26
    if k >= t:
        s[i] = "a"
        k -= t

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

print("".join(s))

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = input()
    k = int(input())
    r = ""
    for se in s:
        if se == 'a':
            r += 'a'
        else:
            if 123 - ord(se) <= k:
                r += 'a'
                k -= (123 - ord(se))
            else:
                r += se
    if k:
        k = k % 26
        lastc = chr(k + ord(r[-1]))
        r = r[:-1] + lastc
    print(r)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
    s = input()
    k = int(input())
    s2 = []
    s2a = s2.append
    for se in s:
        if ord(se) - 97:
            s2a(123 - ord(se))
        else:
            s2a(0)
    s2_ac = tuple(accumulate(s2))
    lens = len(s)
    if s2_ac[-1] < k:
        k -= s2_ac[-1]
        k = k % 26
        r = 'a' * (lens - 1) + chr(97 + k)
        print(r)
    elif s2_ac[-1] == k:
        r = 'a' * lens
        print(r)
    else:
        pos = bisect(s2_ac, k)
        if pos == 0:
            r = chr(k + ord(s[0])) + s[1:]
            print(r)
        elif s2_ac[pos-1] == k:
            r = 'a' * pos + s[pos:]
            print(r)
        else:
            r = 'a' * pos
            k -= s2_ac[pos-1]
            for i1 in range(pos, len(s)):
                if s2[i1] <= k:
                    r += 'a'
                    k -= s2[i1]
                else:
                    r += s[i1]
            if k:
                lastc = chr(ord(r[-1]) + k)
                r = r[:-1] + lastc
            print(r)

if __name__ == '__main__':
    main()

Solution (Python):
s=input()
k=int(input())
n=len(s)
num=[0]*n
for i in range(n):
    if s[i]!="a":
        num[i]=123-ord(s[i])
if sum(num)>=k:
    ans=""
    for i in range(n-1):
        if k>=num[i]:
            k-=num[i]
            ans+="a"
        else:
            ans+=s[i]
    if k>=num[-1]:
        ans+="a"
    else:
        ans+=chr(97+((ord(s[-1])-97+k)%26))
else:
    k-=sum(num)
    ans="a"*(n-1)
    ans+=chr(97+(k%26))
print(ans)

Solution (Python):
s = list(input())
n = len(s)
k = int(input())
alphabet = [chr(i) for i in range(97, 97+26)]
al_d = {}
for i in range(26):
    al_d[alphabet[i]] = i
for i in range(n):
    tobe_a = 26 - al_d[s[i]]
    if tobe_a <= k:
        tobe_a %= 26
        k -= tobe_a
        s[i] = 'a'
remain = k % 26
s[-1] = alphabet[al_d[s[-1]]+remain]
print(''.join(s))

Solution (Python):
s = input()
k = int(input())

L = []
for i in range(len(s)):
    L.append((ord("z")-ord(s[i])+1))

ans = ""
i = 0
while i < len(s):
    if s[i] == "a":
        ans +="a"
        i +=1
    elif k-L[i] >= 0:
        ans +="a"
        k -=L[i]
        i +=1
    else:
        ans +=s[i]
        i +=1
k = k%26
ans = ans[:-1] + chr(ord(ans[-1]) + k)
print(ans)

Solution (Python):
s=[s for s in input()]
k=int(input())
for i,j in enumerate(s):
  if j=='a':continue
  if ord('z')-ord(j)+1<=k:
    s[i]='a'
    k-=ord('z')-ord(j)+1
  if k==0:break
if k>0:s[-1]=chr(k%26+ord(s[-1]))
print(''.join(s))

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    K = int(input())
    ans = ''
    for s in S:
        if s=='a':
            ans += s
        else:
            if 123 - ord(s) <= K:
                ans += 'a'
                K -= 123 - ord(s)
            else:
                ans += s
    if K > 0:
        ans = ans[:-1] + (chr(ord(ans[-1]) + K%26))
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

s = input()
k = int(input())
ans = ""
n = len(s)
for p, i in enumerate(s):
    if p == n - 1:
        ans += chr((ord(i) - 97 + k) % 26 + 97)
        break
    if (cost := (123 - ord(i)) % 26) <= k:
        ans += "a"
        k -= cost
    else:
        ans += i
print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7





S = input()
K = getN()
alpha = 'abcdefghijklmnopqrstuvwxyz'
ans = ''


for i in range(len(S) - 1):
    roop = (26 - alpha.index(S[i])) % 26
    if K >= roop:
        K -= roop
        ans += 'a'
    else:
        ans += S[i]


ans += alpha[(alpha.index(S[-1]) + K) % 26]
print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = list(input())
    k = int(readline())
    l = len(s)
    rem = k

    for i in range(l):
        char = s[i]
        diff = (ord("z") - ord(s[i]) + 1) % 26
        if rem >= diff:
            rem -= diff
            s[i] = "a"

    rem = rem % 26
    s[l - 1] = chr(ord(s[l - 1]) + rem)
    print("".join(s))


if __name__ == '__main__':
    main()

Solution (Python):
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)

Solution (Python):
s = input()
k = int(input())
l = "abcdefghijklmnopqrstuvwxyz"
ans = ""
for i in range(len(s) - 1):
    num = (26 - l.index(s[i])) % 26
    if k >= num:
        ans += "a"
        k -= num
    else:
        ans += s[i]
ans += l[(l.index(s[-1]) + k) % 26]
print(ans)

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

s = input()
l = len(s)
k = ni()
def aind(w):
    if w=="a":
        ret = 0
    else:
        ret = 26 - (ord(w) - ord("a"))
    return ret
ans = []
for i in range(l-1):
    if aind(s[i]) <=k:
        ans.append("a")
        k-=aind(s[i])
    else:
        ans.append(s[i])

idx =(ord(s[-1]) - ord("a") +k%26)%26 +ord("a")
ans.append( chr(idx) )
print("".join(ans))

Solution (Python):
string = input()
k = int(input())
ans = list(string)

alpha = "abcdefghijklmnopqrstuvwxyz"
alpha_to_num = {}
for i in range(26):
    alpha_to_num[alpha[i]] = i
    
for i, s in enumerate(ans):
    if s == "a":
        continue
    pos = alpha_to_num[s]
    kk = 26 - pos
    if kk > k:
        continue
    k -= kk
    ans[i] = "a"
    
pos = alpha_to_num[ans[-1]]
new_pos = (k + pos) % 26
ans[-1] = alpha[new_pos]
print("".join(ans))

Solution (Python):
s = input()
K = int(input())
alpha = "abcdefghijklmnopqrstuvwxyz"
inv_alpha = "azyxwvutsrqponmlkjihgfedcb"
D = {inv_alpha[i]: i for i in range(26)}
n = len(s)
for i in range(n):
  if i == n - 1:
    x = K % 26
    print(alpha[(26-D[s[i]]+x)%26], end = '')
  else:
    if K >= D[s[i]]:
      K -= D[s[i]]
      print('a', end = '')
    else:
      print(s[i], end = '')
print()

Solution (Python):
S = input()
K = int(input())

rest = K
oz = ord('z')
oa = ord('a')
ans = list(S)

for ci in range(len(S)):
    if S[ci] == 'a':
        continue
    
    check = oz - ord(S[ci]) + 1
    if rest >= check:
        ans[ci] = 'a'
        rest -= check

if rest >= 0:
    for i in range(rest%26):
        if oz == ord(ans[-1]):
            ans[-1] = 'a'
        else:
            ans[-1] = chr(ord(ans[-1])+1)
    
print("".join(ans))

Solution (Python):
s=input()
k=int(input())
n=len(s)
i=0
ans=""
while i<n:
    if i!=n-1:
        if s[i]=="a":
            ans+="a"
            
        elif k>=123-ord(s[i]):
            ans+="a"
            k-=(123-ord(s[i]))
            
        else:
            ans+=s[i]
            
    else:
        if k>=123-ord(s[i]):
            k-=(123-ord(s[i]))
            k=k%26
            ans+=chr(97+k)
        else:
            ans+=chr(ord(s[i])+k)
        
    i+=1
print(ans)

Solution (Python):
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))

Solution (Python):
s=input()
K = int(input())
c = []
for i in range(len(s)):
    if s[i]=='a':
        c.append(0)
    else:
        c.append(123-ord(s[i]))
for i in range(len(s)):
    if c[i] <= K:
        K -= c[i]
        c[i]=0
    else:
        continue
if K >0 and c[-1]==0:
    c[i]+= K%26
else:
    c[i] = (-c[i] +K)%26
si = ''
for i in range(len(c)-1):
    if c[i]==0:
        si += 'a'
    else:
        si += s[i]
si += chr(97+c[-1])
print(si)

Solution (Python):
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))

Solution (Python):
def main():
    import sys
    from collections import defaultdict

    def input(): return sys.stdin.readline().rstrip()

    s = input()
    n = len(s)
    k = int(input())
    for i in range(n):
        tmp = (ord('a')-ord(s[i]))%26
        if tmp > k:
            continue
        k -= tmp
        s = s[:i]+'a'+s[i+1:]
    s = s[:-1]+chr((ord(s[-1])+k%26-ord('a'))%26+ord('a'))
    print(s)

    
if __name__ == '__main__':
    main()

Solution (Python):
s,k=open(0)
k=int(k)
*s,t=s
for q in s:
 if(p:=(123-ord(q))%26)<=k:t+="a";k-=p
 else:t+=q
print(t[1:-1]+chr((ord(t[-1])-97+k)%26+97))

Solution (Python):
s,k,t=input(),int(input()),""
for q in s:
 if(p:=(123-ord(q))%26)<=k:t+="a";k-=p
 else:t+=q
print(t[:-1]+chr((ord(t[-1])-97+k)%26+97))

Solution (Python):
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))

Solution (Python):
s=list(input())

k=int(input())

ans = []

for alf in s:
    if alf == 'a':
        ans.append('a')
    else:
        if 123 - ord(alf) <= k:
            k -= 123 - ord(alf)
            ans.append('a')
        else:
            ans.append(alf)
if 0 < k:
    amari = (ord(ans[-1])-97+k)%26
    ans[-1] = chr(amari+97)
    
print(''.join(map(str,ans)))

Solution (Python):
s = input()
k = int(input())

asc = [0] * len(s)
for i in range(len(s)):
    asc[i] = ord(s[i]) - ord("a")
i = 0
for i in range(len(s)):
    if 26 - asc[i] <= k and asc[i] != 0:
        x = 26 - asc[i]
        asc[i] = 0
        k -= x
if k > 0:
    asc[-1] += k % 26
for i in range(len(s)):
    asc[i] += ord("a")
    asc[i] = chr(asc[i])
print("".join(asc))

Solution (Python):
def main():
    s = list(input())
    k = int(input())

    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
    D = dict(zip(ascii_lowercase,list(range(0,len(ascii_lowercase)))))

    n = len(ascii_lowercase)

    for i in range(0,len(s)):
        j = D[s[i]]
        if j != 0 and 26 -j <= k:
            k -= (26-j)
            s[i] ='a'

    if k >0:
        j = (D[s[-1]] + k%26)%26
        s[-1] = ascii_lowercase[j]
    print(''.join(s))

main()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = list(SS())
    K = I()

    
    for i in range(len(s) - 1):
        diff = (ord('a') - ord(s[i])) % 26
        if K >= diff:
            K -= diff
            s[i] = 'a'

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

if __name__ == '__main__':
    resolve()

Solution (Python):
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)