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

sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    a = list(input())
    K = int(input())
    for i in range(len(a)):
        if a[i]=='a':
            val=0
        else:
            val = 123 - ord(a[i])

        if val <= K:
            a[i] = 'a'
            K -= val
        if i == len(a) - 1 and K > 0:
            a[-1] = chr(ord(a[-1]) + K % 26)
    print(''.join(a))


resolve()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    a = list(input())
    K = int(input())
    for i in range(len(a)):
        if a[i]=='a' and i!=len(a)-1:
            continue
        else:
            val = 123 - ord(a[i])
            if val <= K:
                a[i] = 'a'
                K -= val
            if i == len(a) - 1 and K > 0:
                a[-1] = chr(ord(a[-1]) + K % 26)
    print(''.join(a))


resolve()

Solution (Python):
s=input()
k=int(input())
a2n = lambda c: ord(c) - ord('a') + 1
n2a = lambda c: chr(c+64).lower()
ls=list(s)
i=0
while k>0 and i<len(ls):
  a=(1-a2n(ls[i]))%26
  if k>=a:
    ls[i]='a'
    k-=a
  i+=1
if k>0:
  ls[-1]=n2a(a2n(ls[-1])+k%26)
print(''.join(ls))

Solution (Python):

s = input()
k = int(input())
n = len(s)

a = []
for i in range(n):
    a.append(ord(s[i])-ord('a'))

for i in range(n):
    need = (26 - a[i])%26
    if(k>=need):
        a[i]=0
        k-=need


k %= 26

for ii in range(n):
    i = n-1-ii
    rem = 25 - a[i]
    if(rem<=k):
        a[i]+=rem
        k-=rem
    else:
        a[i]+=k
        k=0
        
        break
ans = [' ' for i in range(n)]
for i in range(n):        
    ans[i] = chr(a[i]+ord('a'))
print(''.join(map(str,ans)))

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

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

Solution (Python):
s=input()
n=len(s)
k=int(input())
ans=[]
for i in range(n):
    if i==n-1:
        ans.append(chr(((ord(s[i])-97+k)%26)+97))
    else:

        if s[i]=="a":
            ans.append("a")
        else:
            if 26-(ord(s[i])-97)<=k:
                ans.append("a")
                k-=(26-(ord(s[i])-97))
            else:
                ans.append(s[i])
print("".join(ans))

Solution (Python):
s=list(input())
N=len(s)
K=int(input())
num=123

for i in range(N):
    diff=(num-ord(s[i]))%26
    if K==0:
        break
    if diff<=K:
        s[i]="a"
        K=K-diff


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

print("".join(s))

Solution (Python):
original_s = list(input())
s = list(map(lambda x:ord(x)-97-26, original_s))
K = int(input())

ans = original_s
for i in range(len(s)):
    if abs(s[i]) <= K and s[i] != -26:
        ans[i] = "a"
        K += s[i]

ans[-1] = chr(((ord(ans[-1]) + K) - 97) % 26 + 97)

print("".join(ans))

Solution (Python):
def need(a):
    if a=="a":
        return 0
    else:
        return 123-ord(a)

s=list(input())
x=int(input())
i=0
while x>0:
    count=need(s[i])
    if x>=count:
        s[i]="a"
        x-=count
    
    if i==len(s)-1:
        s[i]=chr(ord(s[i])+(x%26))
        x=0
    i+=1
print("".join(s))

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

for i in range(len(sl)):
    ord_s = ord(sl[i])
    use = 123 - ord_s
    if k - use >= 0 and sl[i] != "a":
        sl[i] = "a"
        k -= use

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

print("".join(sl))

Solution (Python):





from bisect import bisect_left
from string import ascii_lowercase

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

ac = list(ascii_lowercase) + ['a']
dmap = {}
for i in range(len(ac) - 1):
    
    dmap[ac[i]] = len(ac) - i - 1
dmap['a'] = 0

ans = list(s)
output = []

for idc, c in enumerate(ans):
    if k >= dmap[c]:
        output.append('a')
        k -= dmap[c]
    else:
        output.append(c)

k %= 26

new_char = chr(ord(output[-1]) + k)
output[-1] = new_char
print("".join(output))

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

for i in range(len(s)-1):
    z2a = (ord('z') + 1 - ord(s[i])) % 26
    if z2a <= K:
        s = s[:i] + 'a' + s[i+1:]
        K -= z2a

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

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

i=0
while i<len(S)-1:
    if S[i]!='a' and 123-ord(S[i])<=N:
        N-=123-ord(S[i])
        S[i]='a'
    i+=1

N=N%26
while N:
    if S[-1]=='z':
        S[-1]='a'
    else:
        S[-1]=chr(ord(S[-1])+1)
    N-=1

print(''.join(S))

Solution (Python):

"""
もし一周回せるなら回してコストを払う
そうでないなら何もせずに次のアルファベットへ
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
kijun = ord("a")
alpha = [i for i in range(kijun,kijun+26)]
mod = 26

s = readline().rstrip().decode('utf-8')
k = int(readline())

ans = []
for i in s:
    if i == "a":
        ans.append(i)
    elif i == "z":
        if k >= 1:
            ans.append("a")
            k -= 1
        else:
            ans.append(i)
    else:
        if k >= kijun+26 - ord(i):
            ans.append("a")
            k -= kijun+26 - ord(i)
        else:
            ans.append(i)
if k:
    ans[-1] = chr(kijun+(ord(ans[-1])-kijun+k)%mod)
print("".join(ans))

Solution (Python):
import sys
import math  
import bisect  
import queue  


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


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

    S = [s for s in S]
    D = [ord('z') - ord(s) + 1 if s != 'a' else 0 for s in S]
    T = []
    for s, d in zip(S, D):
        if d <= K:
            T.append('a')
            K -= d
        else:
            T.append(s)

    c = ord(T[-1])
    K %= 26
    for _ in range(K):
        if c == ord('z'):
            c = ord('a')
        else:
            c += 1
    T[-1] = chr(c)

    print(''.join(T))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math  
import bisect  
import queue  


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


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

    S = [s for s in S]
    D = [ord('z') - ord(s) + 1 if s != 'a' else 0 for s in S]
    T = []
    for s, d in zip(S, D):
        if d <= K:
            T.append('a')
            K -= d
        else:
            T.append(s)

    c = ord(T[-1])
    for _ in range(K):
        if c == ord('z'):
            c = ord('a')
        else:
            c += 1
    T[-1] = chr(c)

    print(''.join(T))


if __name__ == '__main__':
    main()

Solution (Python):
s = input()
k = int(input())
n = len(s)
le = [""]*n
ne = []

for i in range(n):
    le[i] = s[i]
    if s[i] == "a":
        ne.append(0)
    else:
        ne.append(123-ord(s[i]))
        
rem = k
for i in range(n):
    if rem >= ne[i]:
        rem -= ne[i]
        le[i] = 'a'
        
saigo = ord(le[n-1]) - 97
ssm = (rem+saigo) % 26
le[n-1] = chr(97+ssm)

print(*le,sep = "")

Solution (Python):
s = input()
k = int(input())
n = len(s)
for i in range(n):
  num = ord(s[i])
  if num == 97 or 123-num > k:
    continue
  k -= (123-num)
  s = s[:i] + 'a' + s[i+1:]
if k > 0:
  t = k%26
  s = s[:n-1] + chr(ord(s[n-1])+t)
print(s)

Solution (Python):
s = input()
k = int(input())
n = len(s)
for i in range(n):
  num = ord(s[i])
  if num == 97 or 123-num > k:
    continue
  k -= (123-num)
  s = s[:i] + 'a' + s[i+1:]
if k > 0:
  t = k%26
  s = s[:n-1] + chr(ord(s[n-1])+t)
print(s)

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

result=""
for ss in s:
    if ss=="a":
        result+="a"
    else:
        if k>= 123 - ord(ss):
            k-=123-ord(ss)
            result+="a"
        else:
            result+=ss


if k>0:
    k=k%(123-97)
    temp=chr((((ord(result[-1])-97)+k)%(123-97))+97)
    print(result[:-1]+temp)
else:
    print(result)

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



for i in range(len(s)):
    if s[i] != 'a':
        dist = ord('z') - ord(s[i]) + 1
        if dist <= K:
            K -= dist
            s[i] = 'a'

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


print(''.join(s))

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

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

Solution (Python):
s = input()
K = int(input())
after = []
rem = K
for i in range(len(s)-1):
    if s[i] == 'a':
        after.append('a')
        continue
    c = ord('z') - ord(s[i]) + 1
    if c <= rem:
        rem -= c
        after.append('a')
    else:
        after.append(s[i])

last = ord(s[-1])
if rem > 0:
    last += rem%26
    if last > ord('z'):
        last -= 26
after.append(chr(last))

print(''.join(after))

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    ans = []
    k = I()
    for i,si in enumerate(s):
        if si == "a":
            ans.append(si)
            continue
        j = (ord("a")-ord(si))%26
        if j <= k:
            k -= j
            ans.append("a")
        else:
            ans.append(si)
    k %= 26
    ans[-1] = chr(ord(ans[-1])+k)
    print(*ans,sep="")
    return


if __name__ == "__main__":
    solve()

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

for i in range(N):
    if S[i]=="a":
        continue
    sa=ord("z")-ord(S[i])+1
    if sa<=K:
        K-=sa
        S[i]="a"

if K!=0:
    K%=26
    S[i]=chr(ord(S[i])+K)

print("".join(S))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    S = input()
    K = int(input())
    nums = []
    a = ord("a")
    for s in S:
        nums.append(ord(s) - a)

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

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

    ans = ""
    for n in nums:
        ans += chr(n + a)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def icc(c):
	ret=(ord('z') - ord(c) + 1)
	return ret
	
def nn(c,v):
	ret=chr(ord(c)+v)
	return ret

def main():
	s=input()
	n = int(input())
	
	
	ret = []
	for c in s:
		
		if c != 'a' and icc(c) <= n:
			ret.append('a')
			n-=icc(c)
		else:
			ret.append(c)
	
	n%=26
	if icc(ret[-1]) <= n:
		n-=icc(ret[-1])
		ret[-1]='a'
	ret[-1]=nn(ret[-1], n)
	
	return ''.join(ret)
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
s = input()
k = int(input())
loop = ord('z') + 1
remaining = k
ans = []
for c in s:
    if c == 'a':
        ans.append(c)
        continue
    r = loop - ord(c)
    if r <= remaining:
        ans.append('a')
        remaining -= r
    else:
        ans.append(c)
if remaining > 0:
    remaining %= 26
    ans[-1] = chr(ord(ans[-1]) + remaining)
print(''.join(ans))

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

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

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    S = list(Scanner.string())
    K = Scanner.int()
    i = 0
    while i < len(S):
        c = S[i]
        n = ord(c) - ord('a')
        if n > 0 and 26 - n <= K:
            c = 'a'
            K -= 26 - n
            S[i] = c
        i += 1
    if K > 0:
        c = S[-1]
        for _ in range(K % 26):
            c = chr(ord(c) + 1)
            if c == chr(ord('z') + 1):
                c = 'a'
        S[-1] = c
    print(''.join(S))


def main():
    
    solve()


if __name__ == "__main__":
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = list(input())
k = int(input())
for i in range(len(s)):
    num = (ord('z') - ord(s[i]) + 1) % 26
    if num <= k:
        k -= num
        s[i] = 'a'
s[-1] = chr((ord(s[-1]) - ord('a') + k) % 26 + ord('a'))
print(*s, sep='')

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

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

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 item in s[:len(s)-1]:
    cost=(123-ord(item))
    if item=="a":
        ans.append(item)
        continue
    if K>=cost:
        K-=cost
        ans.append("a")
    else:
        ans.append(item)

K%=26
last=ord(s[-1])
if last+K>122:
    ans.append(chr(last+K-26))
else:
    ans.append(chr(last+K))

print("".join(ans))

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

S = [ord(i)-97 for i in s]

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

if last > 0:
    S[-1] += last
    S[-1] %= 26

S = [chr(i+97) for i in S]
print(''.join(S))

Solution (Python):
s = [ord(x) - ord("a") for x in input()]
k = int(input())

for i, r in enumerate(s):
    if r == 0:
        pass
    elif 26 - r <= k:
        k -= 26-r
        s[i] = 0

if k > 0:
    k %= 26
    s[-1] += k

ans = ""
for r in s:
    ans += chr(ord("a") + r)

print(ans)

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

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

S = list(s)

import string
A = [chr(i) for i in range(ord("a"), ord("z")+1)]
B = {}
for i in range(26):
    B[A[i]] = i

for i in range(n):
    if S[i] != "a" and 26 - B[S[i]] <= k:
        k -= 26 - B[S[i]]
        S[i] = "a"
        

if k > 0:
    S[-1] = A[(B[S[-1]] + k) % 26]



print("".join(S))

Solution (Python):
s = [ord(alph)-97 for alph in input()]
K = int(input())
i = 0
while K > 0 and i < len(s)-1:
    if s[i] != 0 and 26-s[i] <= K:
        K -= 26-s[i]
        s[i] = 0
    else:
        i += 1
s[-1] = (s[-1]+K)%26 
print(*[chr(x+97) for x in s], sep = '')

Solution (Python):
s = input()
n = len(s)
c = [ord(s[i]) for i in range(n)]
k = int(input())
ind = 0
while k > 0:
    if ind == n:
        break
    if c[ind] == 97:
        ind += 1
        continue
    elif 123 - c[ind] <= k:
        k -= 123-c[ind]
        c[ind] = 97
        ind += 1
    elif 123 - c[ind] > k:
        ind += 1
        continue

if k > 0:
    k %= 26
    c[-1] += k
    if c[-1] >= 123:
        c[-1] = 97 + (123-c[-1])

print(''.join([chr(c[i]) for i in range(n)]))

Solution (Python):





def main():
    S = list(input())
    K = int(input())

    li = list("abcdefghijklmnopqrstuvwxyz")
    dic = {}
    for i,j in enumerate(li):
        dic[j] = 26-i
    dic["a"] = 0

    for i in range(len(S)):
        if dic[S[i]] <= K:
            K -= dic[S[i]]
            S[i] = "a"
    if K>0:
        num = (dic[S[-1]]-26)*(-1)
        S[-1] = li[(num+K)%26]

    for i in range(len(S)):
        print(S[i],end="")
    print()


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    word = list(input())
    operation = int(input())
    cost = {}
    for i in range(26):
        cost[chr(ord("a") + i)] = ord("z") - ord("a") - i + 1
    for i in range(len(word)):
        if cost[word[i]] <= operation and word[i] != "a":
            operation -= cost[word[i]]
            word[i] = "a"
        else:
            continue
    if 0 < operation:
        word[-1] = chr((ord(word[-1]) - ord("a") + operation % 26) % 26 + ord("a"))
    print("".join(word))


if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    s = S()
    k = II()
    ans = []
    for si in s[:-1]:
        x = (ord("a") - ord(si)) % 26
        if x <= k:
            k -= x
            ans.append("a")
        else:
            ans.append(si)
    ans.append(chr(ord("a") + (k - (ord("a") - ord(s[-1])) % 26) % 26))
    print("".join(ans))
    return



if __name__ == '__main__':
    solve()

Solution (Python):
def c2a(c):
    return (26 - ord(c) + ord("a")) % 26


s = input()
k = int(input())
l = len(s)
ans = ""
for i, e in enumerate(s, 1):
    if i == l:
        code = (ord(e) - ord("a") + k) % 26 + ord("a")
        c = chr(code)
    else:
        cnt = c2a(e)
        if cnt <= k:
            c = "a"
            k -= cnt
        else:
            c = e

    ans += c

print(ans)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

goal = ord("z") + 1 
s = input()
k = int(input())
n = len(s)
ans = [0] * n
for i,si in enumerate(s):
  if si == "a":ans[i] = "a"
  elif goal - ord(si) <= k:
    k -= goal - ord(si)
    ans[i] = "a"
  else:
    ans[i] = si
m = k % 26
ans[-1] = chr((ord(ans[-1]) - ord("a") + m)%26 + ord("a"))
print(*ans,sep="")

Solution (Python):
S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    
    if S[idx] == "a" and idx < L-1:
        idx += 1
        continue
        
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            
            idx += 1
        else:
            
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        K -= k
        S[idx] = "a"
        if idx < L-1:
            idx += 1

print("".join(S))

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

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

alp = list('abcdefghijklmnopqrstuvwxyz')
s2a = {alp[i]: 26-i for i in range(26)}
s2a['a'] = 0

for i in range(len(S)):
    s = S[i]
    if s2a[s] <= k:
        k -= s2a[s]
        S[i] = 'a'

k %= 26
idx = alp.index(S[-1])
S[-1] = alp[k+idx]

print(*S, sep='')

Solution (Python):
s = list(input())
k = int(input())
for i in range(len(s)):
  if ord("z")<ord(s[i])+k and s[i]!="a":
    k =k-(ord("z")-ord(s[i])+1)
    s[i]="a"
  if i==len(s)-1 and 0<k:
    k=k%26
    s[i]=chr(ord(s[i])+k)
print("".join(s))

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

alphabets = "abcdefghijklmnopqrstuvwxyz"
a = {c:i for i, c in enumerate(alphabets)}
s = list(input())
n = len(s)
k = int(input())

def f(k, i):
    if i == n - 1:
        k_ = k % 26
        c = s[i]
        shifted = (k_ + a[c]) % 26
        return alphabets[shifted]

    c = s[i]
    diff = 26 - a[c]
    if c != "a" and diff <= k:
        return "a" + f(k-diff, i+1)
    else:
        return c + f(k, i+1)
        

print(f(k, 0))

Solution (Python):
s=input()
l=len(s)
k=int(input())
z=''
for i in range(l):
  t=123-ord(s[i])
  if s[i]=='a':
    z+='a'
  elif t<=k:
    z+='a'
    k-=t
  else:
    z+=s[i]
v=ord(z[l-1])-97+k
z=z[:l-1]+chr(v%26+97)
print(z)

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    S = [x for x in sys.stdin.readline().split()][0]  
    K = [int(x) for x in sys.stdin.readline().split()][0]  
    
    

    
    
    
    

    logger.debug('{}'.format([]))

    a_ord = ord("a")
    z_index = ord("z") - a_ord

    s_ord = [ord(s) - a_ord for s in S]
    for i, s in enumerate(s_ord):
        if z_index + 1 - s > K or s == 0:
            continue
        else:
            s_ord[i] = 0
            K -= z_index - s + 1

    mod = ord("z") - a_ord + 1
    if K > 0:
        K = K % mod
        s_ord[-1] = (s_ord[-1] + K) % mod

    print("".join([chr(x + a_ord) for x in s_ord]))


if __name__ == "__main__":
    resolve()




import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """xyz
4"""
        output = """aya"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """a
25"""
        output = """z"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """codefestival
100"""
        output = """aaaafeaaivap"""
        self.assertIO(input, output)

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

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

Solution (Python):
if __name__ == "__main__":
    s = input()
    k = int(input())

    s_num = [0] * len(s)
    res = k
    for i in range(len(s)):
        tmp = ord(s[i]) - 97
        if tmp != 0 and 26 - tmp <= res:
            res -= (26 - tmp)
            s_num[i] = 0
        else:
            s_num[i] = tmp

    res %= 26

    s_num[-1] += res

    ans = ''
    for i in s_num:
        ans += chr(i + 97)

    print(ans)

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

for i in range(len(s)):
    if k==0:break

    num=ord(s[i])
    ch_num=123-num
    if i==len(s)-1:
        s[i]=chr(97+(num+k-97)%26) 
        
        k=0
        break
    elif s[i]=='a':continue
    elif ch_num<=k:
        s[i]='a'
        k-=ch_num
print(''.join(s))

Solution (Python):
t="abcdefghijklmnopqrstuvwxyz"
s=input()
k=int(input())
a=[t.index(i)for i in s]
ans=""
for i in a:
  j=i
  if i==0:
    ans+="a"
    continue
  if k>=26-i:
    k-=26-i
    j=0
  ans+=t[j]
j+=k
j%=26
ans=ans[:-1]+t[j]
print(ans)

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

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

Solution (Python):

abc = ''
for i in range(97 ,97+26):
    abc += chr(i)


S = input()
K = int(input())
ans = ''
for i,s in enumerate(S):
    if ord(s) > ord('a') and 26 - (ord(s) - ord('a')) <= K and i!=len(S)-1:
        ans += 'a'
        
        K -= 26 - (ord(s) - ord('a'))
        

    elif i != len(S)-1:
        ans += s
    else:
        
        ans += abc[(ord(s) + K%26-ord('a'))%26]
        

print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = list(STR())
l = len(s)
k = INT()
for i in range(l):
    tmp = (ord('z') - ord(s[i]) + 1) % 26
    if tmp <= k:
        s[i] = 'a'
        k -= tmp
    
s[l - 1] = chr((ord(s[l - 1]) - ord('a') + k) % 26 + ord('a'))
print(''.join(s))

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

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    s = input().rstrip()
    K = int(input())

    def c(x): return ord(x) - ord('a')
    def d(x): return chr(x + ord('a'))
    ans = []
    i = 0
    while i < (len(s) - 1):
        to_a = (26 - c(s[i])) % 26
        if to_a <= K:
            ans.append('a')
            K -= to_a
        else:
            ans.append(s[i])
        i += 1
    if K > 0:
        ans.append(d((c(s[-1]) + K) % 26))
    else:
        ans.append(s[i])
    print(''.join(ans))

if __name__ == '__main__':
    main()

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

"""
Kを使用する
-> aにすることができる

残りのKはs[-1]に使用
"""

from collections import defaultdict
alpha = defaultdict(int)
for i in range(97, 97 + 26):
    alpha[chr(i)] = i - 97

for i in range(len(s)):
    if s[i] == "a":
        continue
    if 26 - alpha[s[i]] <= K:
        K -= 26 - alpha[s[i]]
        s[i] = "a"

if K > 0:
    s[-1] = chr(97 + (alpha[s[-1]] + K) % 26)

print(*s, sep="")