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

Solution (Python):
s = input()
l = len(s)
n = int(input())
ans = ["A"]*l
for i in range(l-1):
  if s[i]=="a":
    ans[i]="a"
    continue
  temp = ord("z")-ord(s[i])+1
  if temp <= n:
    n-=temp
    ans[i]="a"
  else:
    ans[i]=s[i]

last = ord(s[l-1])+n

while last>ord("z"):
  last-=26
ans[l-1]=chr(last)
print("".join(ans))

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = list(input())
k = INT()

i = 0
while k > 0:
    tmp = ord(s[i]) - ord('a')
    if i < len(s) - 1:
        if tmp != 0 and 26 - tmp <= k:
            k -= 26 - tmp
            s[i] = 'a'
        i += 1
    else:
        s[i] = chr((tmp+k)%26 + ord('a'))
        k = 0

print(''.join(s))

Solution (Python):
from string import ascii_lowercase

def main():
    s = list(input())
    K = int(input())
    for i, c in enumerate(s):
        num = ord(c) - ord("a")

        if num > 0 and K - (26-num) >= 0:
            s[i] = "a"
            K -= (26-num)

    num = ord(s[-1]) - ord("a")
    last = (num + K)%26
    s[-1] = ascii_lowercase[last]
    print("".join(s))

        
if __name__ == "__main__":
    main()

Solution (Python):
s=list(input())
k=int(input())
for i in range(len(s)):
    if i==len(s)-1:
        s[-1]=chr((ord(s[i])-97+k)%26+97)
        break
    if s[i]=='a':
        continue
    if 123-ord(s[i])<=k:
        k-=123-ord(s[i])
        s[i]='a'
print(*s,sep='')

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

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

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

print("".join(S))

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

Solution (Python):
s = list(input())
k = int(input())
A = 'abcdefghijklmnopqrstuvwxyz'
Da = {a:i for i,a in enumerate(A)}

c = 0
for i in range(len(s)):
    if s[i]!='a' and 26-Da[s[i]]<=k:
        k -= 26-Da[s[i]]
        s[i] = 'a'
if k:
    s[i] = A[Da[s[i]]+k%26]
print("".join(s))

Solution (Python):
s = list(input())
k = int(input())
t = list(map(lambda x:ord(x)-ord("a"),s))
 
for i in range(len(t)):
  diff = 26-t[i]
  if diff != 26 and diff <= k: 
    t[i]+=diff
    k-=diff
t[-1]+=k
 
u = "".join(list(map(lambda x:chr((x%26+ord("a"))),t)))
print(u)

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

ans = ""
for i, s in enumerate(S):
    if i == len(S) - 1:
        if ord(s) + K <= ord("z"):
            ans += chr(ord(s) + K)
        else:
            ans += chr(ord("a") + (ord(s) + K - ord("z") - 1) % 26)
    elif s == "a":
        ans += "a"
        continue
    elif ord("z") + 1 - ord(s) <= K:
        ans += "a"
        K -= (ord("z") + 1 - ord(s))
    else:
        ans += s

print(ans)

Solution (Python):
A = {i-97:chr(i) for i in range(97,123)}
B = {v:k for k,v in A.items()}
s = list(input().strip())
K = int(input())
for i in range(len(s)-1):
    if s[i]!="a" and K>=26-B[s[i]]:
        K -= (26-B[s[i]])
        s[i]="a"
k = K%26
ind = (B[s[-1]]+k)%26
s[-1] = A[ind]
print("".join(s))

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = list(input())
k = inp()
n = len(s)
nxa = ord('z') + 1

for i,x in enumerate(s):
    if x == 'a':
        continue
    rem = nxa - ord(x)
    if rem <= k:
        s[i] = 'a'
        k -= rem
if k > 0:
    s[-1] = chr(ord('a') + (ord(s[-1])-ord('a')+k)%26)
print(''.join(s))

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

a=ord('a')
S=list(map(lambda x:ord(x)-a,input()))
K=int(input())
ans=[]
for x in S:
    if x==0:
        ans.append('a')
    elif 26-x<=K:
        ans.append('a')
        K-=26-x
    else:
        ans.append(chr(x+a))
if K>0:
    ans[-1]=chr((ord(ans[-1])-a+K)%26+a)
print(''.join(ans))

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

def ctoi(c):
    return ord(c) - ord('a')
def toa(c):
    i = ctoi(c)
    return (26-i)%26

ans = ''
for c in S:
    if len(ans)+1 == len(S):
        ans += chr((ctoi(c) + K)%26 + ord('a'))
    else:
        to = toa(c)
        if to <= K:
            ans += 'a'
            K -= to
        else:
            ans += c
print(ans)

Solution (Python):
import sys
from collections import defaultdict, deque, Counter
import math


from bisect import bisect_left, bisect_right
import heapq




input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    s = getS()
    k = getN()

    sn = [ord(i) - ord("a") for i in s]
    for i, c in enumerate(sn):
        if c != 0:
            if k >= 26 - c:
                k -= 26 - c
                sn[i] = 0

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

    

    print("".join([chr(i + ord("a")) for i in sn]))



def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    
    solve()

Solution (Python):
import sys
input = sys.stdin.readline
S = list(input())[: -1]
K = int(input())
a = ord("a")
N = len(S)
for i in range(N):
  x = ord(S[i])
  if K >= (a - x) % 26:
    K -= (a - x) % 26
    S[i] = "a"
S[-1] = chr((ord(S[i]) - a + K % 26) % 26 + a)
print("".join(S))

Solution (Python):
li_s = list(input())
k = int(input())
z = ord('z')
ans = ''
for i in range(len(li_s)):
    if i < len(li_s) - 1 and li_s[i] == 'a':
        ans += 'a'
    elif i < len(li_s)-1 and k-(z-ord(li_s[i])+1) >= 0:
        k -= z-ord(li_s[i])+1
        ans = ans + 'a'
    elif i < len(li_s)-1:
        ans = ans + li_s[i]
    elif i == len(li_s) - 1:
        p = ord(li_s[i])  + k
        p %= 26
        p += 78
        if 97 <= p:
            ans = ans + chr(p)
        else:
            ans = ans + chr(p+26)
print(ans)

Solution (Python):
s = list(input())
n = len(s)
k = int(input())
t = [ord(s[i]) - 97 for i in range(n)]
for i in range(n):
    if k == 0:
        break
    x = 26 - t[i]
    if 0 < x % 26 <= k:
        k -= x
        s[i] = "a"
t[-1] = ord(s[-1]) - 97
if k > 0:
    s[-1] = chr((k + t[-1]) % 26 + 97)
print("".join(s))

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

Solution (Python):
import string
S = input()
K = int(input())
LEN = len(S)
ans = ''
for pos, s in enumerate(S, 1):
    idx = string.ascii_lowercase.find(s)
    if pos < LEN:
        if idx > 0 and 26-idx <= K:
            ans += 'a'
            K -= (26 - idx)
        else:
            ans += s
    else:
        
        ans += string.ascii_lowercase[(idx + K)%26]

print(ans)

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    S = list(in_s())
    N = len(S)
    K = in_n()

    ac = ord('a') + 26
    zc = ord('z')

    for i in range(N):
        if S[i] != 'a':
            nc = ord(S[i])
            if ac - nc <= K:
                S[i] = 'a'
                K -= ac - nc

    if K != 0:
        tc = S[-1]
        S[-1] = chr(((ord(tc) - ord('a')) + K % 26) % 26 + ord('a'))

    print(''.join(S))


if __name__ == '__main__':
    main()

Solution (Python):
s,K = open(0).read().split()
K = int(K)
dista = [(123 - ord(x)) % 26 for x in s]
sa = sum(dista)
if K >= sa:
    print('a'*(len(s)-1)+chr(97+(K-sa)%26))
else:
    ans = []
    count = K
    for i in range(len(s)):
        if count >= dista[i]:
            ans.append('a')
            count -= dista[i]
        else:
            ans.append(s[i])
    if ans[-1] == 'a':
        ans[-1] = chr(97+(count%26))
    else:
        ans[-1] = chr(ord(ans[-1])+count)
    print(''.join(ans))

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

rlt = ''

for i in range(len(s)-1):
  c = (26-ord(s[i])+ord('a'))%26
  if K >= c:
    rlt += 'a'
    K -= c
  else:
    rlt += s[i]
    
rlt += chr((K + ord(s[-1]) - ord('a'))%26 + ord('a'))
print(rlt)

Solution (Python):
s = list(input())
k = int(input())
t = list(map(lambda x:ord(x)-ord("a"),s))

for i in range(len(t)):
  diff = 26-t[i]
  if diff != 26 and diff <= k: 
    t[i]+=diff
    k-=diff
t[-1]+=k

u = "".join(list(map(lambda x:chr((x%26+ord("a"))),t)))
print(u)

Solution (Python):
s = list(input())
k = int(input())
t = list(map(lambda x:ord(x)-ord("a"),s)) 

for i in range(len(t)):
  diff = 26-t[i] 
  if diff != 26 and diff <= k: 
    t[i]+=diff
    k-=diff
  else:
    continue

t[-1]+=k 

u = "".join(list(map(lambda x:chr((x%26+ord("a"))),t)))
print(u)

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

Solution (Python):
s=input()
k=int(input())
lens=len(s)
alp="azyxwvutsrqponmlkjihgfedcb"

ans=[]
for i in range(lens):
    d=alp.index(s[i])
    if k>=d:
        k-=d
        ans.append("a")
    else:
        ans.append(s[i])

las=ans.pop()
alp="abcdefghijklmnopqrstuvwxyz"
ans.append(alp[(alp.index(las)+k)%26])

print("".join(ans))

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

ans = []
a = ord('z') + 1
for i in s:
    if a - ord(i) <= k and i != 'a':
        k -= a - ord(i)
        ans.append(ord('a'))
    else:
        ans.append(ord(i))
ans[-1] += k % 26
if ans[-1] >= a:
    ans[-1] -= 26
print(*map(chr, ans), sep='')

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

ans = []
a = ord('z') + 1
for i in s:
    if k == 0:
        ans.append(ord(i))
    elif a - ord(i) <= k and i != 'a':
        k -= a - ord(i)
        ans.append(ord('a'))
    else:
        ans.append(ord(i))
ans[-1] += k % 26
if ans[-1] >= a:
    ans[-1] -= 26
print(*map(chr, ans), sep='')

Solution (Python):

s = input()
k = int(input())
n = len(s)
ans = []

for i in range(n):
    if s[i] == "a":
        ans.append("a")
    elif 123 - ord(s[i]) <= k:
        ans.append("a")
        k -= 123 - ord(s[i])
    else:
        ans.append(s[i])

k %= 26  
ans[-1] = chr((ord(ans[-1]) + k - 97) % 26 + 97)
print("".join(ans))

Solution (Python):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    s = list(input())
    N = len(s)
    K = int(input())
    i = 0
    while K > 0:
        if i == N-1:
            num = ord(s[i])+K%26
            if num > ord('z'):
                num -= 26
            s[i] = chr(num)
            break
        else:
            if s[i] != 'a':
                num = 26-ord(s[i])+ord('a')
                if  num <= K:
                    s[i] = 'a'
                    K -= num
            i += 1
    print(''.join(s))

if __name__ == "__main__":
    main()

Solution (Python):
s = list(input())
k = int(input())
n = len(s)
alph_map = {chr(ord('a') + i): (26 - i) % 26 for i in range(26)}
for i in range(n):
    if k >= alph_map[s[i]]:
        k -= alph_map[s[i]]
        s[i] = 'a'
if k > 0:
    s[n-1] = chr((ord(s[n-1]) + k % 26) % 123)
print(''.join(s))

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

ans = ""
for s in S:
    if s == "a":
        ans += s
    elif 123-ord(s) <= K:
        ans += "a"
        K -= 123-ord(s)
    else:
        ans += s
if K > 0:
    ans = ans[:-1] + chr((ord(ans[-1])-97+K)%26+97)
print(ans)

Solution (Python):


import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union































def main():
    Num = Union[int, float]
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    


    def calc_rotate_min(L, rotate):
        n = len(L)
        for i in range(n):
            
            if rotate == 0:
                return
            if i == n - 1:
                
                L[i] = (L[i] + rotate % 26) % 26
                return
            if L[i] != 0 and 26 - L[i] <= rotate:
                rotate -= (26 - L[i])
                L[i] = 0    


    
    s = input()
    k = ii()
    L = list(map(lambda x: ord(x)-ord('a'), s))
    calc_rotate_min(L, rotate=k)
    
    for num in L:
        print(chr(num+ord('a')), end='')
    print('')



if __name__ == "__main__":
    main()

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

N = len(S)

L = []

for i in range (0, N):
	L.append((97-ord(S[i]))%26)

W = []

for i in range (0, N-1):
	if L[i] <= K:
		W.append('a')
		K -= L[i]
	else:
		W.append(S[i])

V = (26-L[N-1]+K)%26
W.append(chr(97+V))
print(*W, sep="")

Solution (Python):
def main():
    S = list(input())
    K = int(input())
    k = K
    for i,c in enumerate(S):
        distance = (ord('z') + 1 - ord(c))%26
        if distance <= k:
            k -= distance
            S[i] = 'a'
    S[-1] = chr((ord(S[-1]) - ord('a') + k) % 26 + ord('a'))
    print(''.join(S))

main()

Solution (Python):
s = input()
k = int(input())
ans = ""
for i in range(len(s)-1):
    cost = ord("z")+1-ord(s[i])
    if s[i] == "a" or k < cost:
        ans += s[i]
    else:
        ans += "a"
        k -= cost
c = s[-1]
k %= 26
for _ in range(k):
    if c == "z": c = "a"
    else: c = chr(ord(c)+1)
ans += c
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')



 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





s=list(ss())
k=ii()
ans=""
for i in range(len(s)):
    p=ord(s[i])
    
    if i==len(s)-1:
        k%=122-97+1
        
        p+=k
        if p>=123:
            p-=122-97+1
        ans=ans+chr(p)
        
    elif s[i]=="a":
        ans=ans+"a"
    elif k>=123-p:
        k-=123-p
        ans=ans+"a"
    else:
        ans=ans+s[i]

print(ans)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


s = input()
k = int(input())

cnt = 0
n = len(s)
ans = [i for i in s]
for i in range(n):
    
    if cnt == k:
        break
    cost = ord("z") + 1 - ord(ans[i])
    if i == n - 1:
        cost2 = cost - 1
        
        if k - cnt <= cost2:
            ans[i] = chr(ord(ans[i]) + k - cnt)
        else:
            k2 = k - cnt - cost2
            if k2 % 26 == 0:
                ans[i] = "z"
            else:
                ans[i] = chr(ord("a") + k2 % 26 - 1)
        break
    if ans[i] == "a":
        continue  
    if k - cnt >= cost:
        cnt += cost
        ans[i] = "a"
print("".join(ans))

Solution (Python):
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
print("".join(map(encode, S)))

Solution (Python):
s = list(input())
k = int(input())
n = len(s)
map = {(chr(ord("a") + i)): (26-i)%26 for i in range(26)}
for i in range(n):
    if k >= map[s[i]]:
        k -= map[s[i]]
        s[i] = "a"
if k > 0:
    s[n-1] = chr((ord(s[n-1])+k%26)%123)
print("".join(s))

Solution (Python):
s=list(input())
K=int(input())
alp=["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"]

for i in range(len(s)):
    n=alp.index(s[i])
    if n!=0 and n+K>=26:
        s[i]="a"
        K-=26-n
    if i==len(s)-1 and K>0:
        n=alp.index(s[i])
        s[i]=alp[(n+K)%26]

for j in s:
    print(j,end="")
print()

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

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

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




S = S()
N = I()
L = [ord(s)-97 for s in S]

for i in range(len(L)):
  if i == len(L)-1:
    L[i] = (L[i] + N)%26
  elif L[i] == 0:
    continue
  elif 26-L[i]<=N:
    temp = 26-L[i]
    L[i] = 0
    N -= temp
  else:
    continue
    
print(*[chr(i+97) for i in L],sep="")

Solution (Python):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7
 
S = list(readline().rstrip())
K = int(readline())
N = len(S)
for i,s in enumerate(S):
    t = ord(s)-97
    if t == 0:
        continue
    if 26 - t <= K:
        S[i] = 'a'
        K -= 26-t
S[-1] = chr((ord(S[i]) + K%26)%97+97)
print(''.join(S))

Solution (Python):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

S = list(readline().rstrip())
K = int(readline())
N = len(S)
for i in range(N):
    t = ord(S[i])-97
    if t == 0:
        continue
    if 26 - t <= K:
        S[i] = 'a'
        K -= 26-t
S[-1] = chr((ord(S[-1])-97 + K%26)%26 + 97)
print(''.join(S))

Solution (Python):
def str_rotate(S,k): 
    if k >= 26:
        k = k%26
    if ord(S) + k > 123:
        S = chr(ord(S)+k-97)
    else:
        S = chr(ord(S)+k)
    return S

s = list(input())
k = int(input())
for i in range(len(s)):
    if k == 0:
        break
    if s[i] == "a":
        pass
    elif 123 - ord(s[i]) <= k:
        k -= 123 - ord(s[i])
        s[i] = "a"
    else:
        pass
s[-1] = str_rotate(s[-1],k)
print("".join(s))

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

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

Solution (Python):
s = input()
K = int(input())
alh = [chr(i) for i in range(97, 97 + 26)]
ans = ""
d = {}
for n,i in enumerate(alh):
    d[i] = (26-n)%26
for i in s[:-1]:
    if K >= d[i]:
        K -=d[i]
        ans += "a"
    else:
        ans += i
ans += chr(97+(ord(s[-1])+K-97)%26)
print(ans)

Solution (Python):
G={chr(a+ord("a")):a for a in range(26)}
H={G[b]:b for b in G}

T=input()
S=[]
for s in T:
    S.append(G[s])
K=int(input())

I=0
N=len(S)
for i in range(N):
    if (i<N-1) and (26-S[i]<=K) and S[i]!=0:
        K-=26-S[i]
        S[i]=0
    elif i==N-1:
        S[i]=(S[i]+(K%26))%26

U=""
for s in S:
    U+=H[s]

print(U)

Solution (Python):
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(s[-1])-ord('a')+k)%26
s[-1] = chr(ord('a')+x)

print(''.join(s))

Solution (Python):
s = list(input())
k = int(input())
n = len(s)
for i in range(n-1):
    d = (ord('z')-ord(s[i])+1)%26
    if d<=k:
        s[i] = 'a'
        k -= d

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


print(''.join(s))

Solution (Python):
makeA = lambda c: (ord('z')-ord(c)+1) % 26
s = list(map(makeA,list(input())))

K = int(input())
len_s = len(s)

for i in range(len_s-1):
    if s[i] <= K:
        K -= s[i]
        s[i] = 0
        
if K > 0:
    s[-1] = (s[-1] + 26 - (K % 26)) % 26

makeS = lambda n: chr((26-n)%26+ord('a'))
print(''.join(list(map(makeS,s))))

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

Solution (Python):
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        ans[-1] = chr((ord(ans[-1]) + k - 97) % 26 + 97)
    print(''.join(ans))

if __name__ == '__main__':
    main()