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 ** 7)
rl = sys.stdin.readline


def solve():
    s = rl().rstrip()
    K = int(rl())
    
    ans = []
    for si in s:
        if si == 'a':
            ans.append('a')
            continue
        cnt = ord('z') - ord(si) + 1
        if cnt <= K:
            ans.append('a')
            K -= cnt
        else:
            ans.append(si)
    
    ans[-1] = chr(ord('a') + (ord(ans[-1]) - ord('a') + K % 26) % 26)
    print(''.join(ans))


if __name__ == '__main__':
    solve()

Solution (Python):
s = str(input())
k = int(input())
S = []
for i in range(len(s)):
    S.append(ord(s[i]) - 97)
i = 0
while k > 0:
    if S[i] > 0 and 26 - S[i] <= k:
        k -= 26 - S[i]
        S[i] = 0
        i += 1
    else:
        i += 1
    if i >= len(s):
        S[-1] += k
        break
ans = ''
for x in S:
    ans += chr((x % 26) + 97)
print(ans)

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

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

if __name__ == '__main__':
    solve()

Solution (Python):
s = list(map(str, input().rstrip()))
k = int(input())

diff = [(ord("a") + 26 - ord(x)) % 26 for x in s]

for i in range(len(s) - 1):
    if diff[i] <= k:
        s[i] = "a"
        k -= diff[i]
    else:
        continue

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

s[-1] = chr(tmp)

print("".join(s))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    s = rl().rstrip()
    K = int(rl())
    
    ans = []
    for si in s:
        if si == 'a':
            ans.append('a')
            continue
        cnt = ord('z') - ord(si) + 1
        if cnt <= K:
            ans.append('a')
            K -= cnt
        else:
            ans.append(si)
    
    ans[-1] = chr(ord('a') + (ord(ans[-1]) - ord('a') + K % 26) % 26)
    print(''.join(ans))


if __name__ == '__main__':
    solve()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

s = list(input())
K = INT()

def ctoi(c):
	return ord(c)-ord("a")

for i in range(len(s)):
	x = ctoi(s[i])
	if x == 0 or 26-x > K:
		continue
	K -= 26 - x
	s[i] = "a"

if K:
	s[-1] = ascii_lowercase[(ctoi(s[-1])+K)%26]

print("".join(s))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

s = list(input())
K = INT()

for i in range(len(s)):
	tmp = 26 - ascii_lowercase.index(s[i])
	if tmp <= K and tmp < 26:
		K -= tmp
		s[i] = "a"

idx = ascii_lowercase.index(s[-1])
s[-1] = ascii_lowercase[(idx+K)%26]

print(*s, sep="")

Solution (Python):
import sys
from io import StringIO
import unittest
import os



def resolve():
    s = list(input())
    k = int(input())

    
    need_cnt_list = [26 - (ord(i) % 97) for i in s]
    
    
    

    ans = []

    zan_cnt = k

    for num, i in enumerate(need_cnt_list):
        
        if s[num] == "a":
            ans.append("a")
        
        elif zan_cnt >= i:
            zan_cnt -= i
            
            ans.append("a")
        
        else:
            ans.append(s[num])

    
    
    now_last = ord(ans[-1]) - 97
    last = zan_cnt % 26 + now_last

    
    ans[-1] = chr(last + 97)
    print("".join(ans))
    return



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

    def test_input_1(self):
        test_input = """xyz
4"""
        output = """aya"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """a
25"""
        output = """z"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """codefestival
100"""
        output = """aaaafeaaivap"""
        self.assertIO(test_input, output)

    
    def test_1original_1(self):
        test_input = """bbb
100000000"""
        output = """aaz"""
        self.assertIO(test_input, output)

    
    def test_1original_2(self):
        test_input = """bbb
75"""
        output = """aaa"""
        self.assertIO(test_input, output)

    
    def test_1original_2(self):
        test_input = """bbc
74"""
        output = """aaa"""
        self.assertIO(test_input, output)

    
    def test_1original_3(self):
            test_input = """bba
74"""
            output = """aay"""
            self.assertIO(test_input, output)



if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        
        resolve()

    else:
        
        unittest.main()

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

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

ans = []
for c in s[:-1]:
    to_a = (ord('z')-ord(c)+1) % 26
    if k < to_a:
        ans.append(c)
    else:
        k -= to_a
        ans.append('a')
else:
    c = s[-1]
    x = ord(c)-ord('a')
    y = (k+x) % 26
    ans.append(chr(ord('a')+y))


print(''.join(ans))

Solution (Python):
s=list(input())
K=int(input())
for i in range(len(s)):
    if i==len(s)-1:
        K=K%26
        x=ord(s[i])
        for j in range(K):
            x+=1
            if x==123:
                x=97
        s[i]=chr(x)
    else:
        if K<=0 or s[i]=='a':
            continue
        dif=123-ord(s[i])
        if dif<=K:
            s[i]='a'
            K-=dif
print(''.join(s))

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

'''
ordの位置


左の文字からNで'a'に出来るかを確認
aに出来るならaにして使った分をNから引く
繰り返して行き一番最後にあまりをすべて使う
'''
  
for i, s in enumerate(S):
  if ord(s) - 97 > 0  and 122 - ord(s) < N:
    S[i] = "a"
    N -= 123 - ord(s)
else:
  S[i] = chr(N % 26 + ord(S[i])) 
       
print("".join(S))

Solution (Python):
from collections import deque
s = input()
k = int(input())
a = ord("a")
l = deque(list())
l1 = []
for i in range(len(s)):
  s1 = s[i]
  l.append(((a+26)-ord(s1))%26)

while k!=0:
    if len(l)!=0:
        t = l.popleft()
        if k>=t:
            l1.append("a")
            k -= t
        else:
          if t=="a":
            l1.append(t)
          else:
            l1.append(chr((ord('a')-t+26)))
    else:
      k %= 26
      l1[-1] = chr(int(ord(l1[-1])+k))
      k = 0
l2 = []
if len(l)>=1:
  for t in l:
    t %= 26
    if t==0:
      l2.append("a")
    else:
      l2.append(chr((ord('a')-t+26)))
  l1 += l2
print("".join(l1))

Solution (Python):
alpha = "abcdefghijklmnopqrstuvwxyz"
A = ["a"]+[i for i in alpha[::-1]]
s = list(input())
k = int(input())
n = len(s)
for i in range(n):
    if s[i] == "a":
        continue
    j = A.index(s[i])
    if j <= k:
        s[i] = "a"
        k -= j
    if k == 0:
        print("".join(s))
        exit()
else:
    k %= 26
    l = alpha.index(s[-1])
    if l + k <= 25:
        s[-1] = alpha[k+l]
    else:
        s[-1] = alpha[k+l-26]
    print("".join(s))

Solution (Python):
alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = input()
K = int(input())
ans = ''
for i in range(len(s) - 1):
    s_i = alphabet.index(s[i])
    if s[i] == 'a':
        ans += 'a'
        continue
    if (26 - s_i <= K):
        K -= 26 - s_i
        ans += 'a'
    else:
        ans += s[i]
ans += alphabet[(K + alphabet.index(s[-1])) % 26]
print(ans)

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

ans = []

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

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


print(*ans, sep = "")

Solution (Python):





import math
import sys
import bisect
import heapq  
from collections import deque
inf = 10**18
mod = 10**9+7

s = input()
k = int(input())
n = len(s)
ans = []
for c in s[:n-1]:
    if c == 'a':
        ans.append('a')
        continue
    if ord('z')-ord(c)+1 <= k:
        k-=(ord('z')-ord(c)+1)
        ans.append('a')
    else:
        ans.append(c)
ans.append(chr(ord('a')+(ord(s[n-1])-ord('a')+k)%26))
print(*ans, sep='')

Solution (Python):
S=list(input())
k=int(input())
for i in range(len(S)):
    s=S[i]
    if s=="a":continue
    x=123-ord(s)
    
    if k>=x:
        k-=x
        S[i]="a"

    else:continue
k%=26
for i in range(len(S)):
    if S[-1-i]!="a":
        S[-1-i]=chr((ord(S[-1-i])-97+k%26)+97)
        print("".join(S));break
else:
    S[-1]=chr((ord(S[-1])-97+k%26)+97)
    print("".join(S))

Solution (Python):
s = input()
k = int(input())
d = {}
dd = {}
for i, ss in enumerate('abcdefghijklmnopqrstuvwxyz'):
    d[ss] = i
    dd[i] = ss
ans = ''

for ss in s[:-1]:
    if k >= 26 - d[ss] and ss != 'a':
        k -= 26 - d[ss]
        ans += 'a'
    else:
        ans += ss
k = (d[s[-1]] + k) % 26
ans += dd[k]
print(*ans, sep='')

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

Solution (Python):
s=list(map(ord,list(input())))
k=int(input())

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

c=0
while k>0:
    if c==len(s)-1:
        s[c]=(s[c]+k)%26
        k=0
    elif s[c]==0:
        c+=1
    elif s[c]+k>=26:
        k-=26-s[c]
        s[c]=0
        c+=1
    else:
        c+=1

seq=""
for i in range(len(s)):
    seq+=chr(s[i]+97)

print(seq)

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue
import numpy as np

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

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





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

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

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

    print(*s, sep="")


if __name__ == '__main__':
    main()

Solution (Python):
al=[chr(ord('a') + i) for i in range(26)]
s=input()
N=len(s)
K=int(input())

for i in range(N):
  if i<N-1:
    a=26-al.index(s[i])
    if K>=a and s[i]!="a":
      K -= a
      s=s[0:i]+al[(al.index(s[i])+a)%26]+s[i+1:]
  else:
    K %= 26
    p= (K+al.index(s[i]))% 26
    s=s[0:N-1]+al[p]
    K=0
    
print(s)

Solution (Python):

s = list(ord(i) for i in input())
k = int(input())

for i in range(len(s)-1):
  if s[i] == ord("a"): continue
  t = ord("z")+1-s[i]
  if k >= t:
    s[i] = 97
    k -= t
if k > 0:
  k %= 26
  s[-1] += k
  if s[-1] > ord("z"):
    s[-1] -= 26
print("".join(list(map(chr, s))))

Solution (Python):
dic = {"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}
ls = ["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"]

s = input()
k = int(input())
s_l = []
for i in range(len(s)):
    s_l.append(s[i])

for i in range(len(s_l)):
    if dic[s_l[i]] <= k:
        k -= dic[s_l[i]]
        s_l[i] = "a"

if k > 0:
    s_l[-1] = ls[((26 - dic[s_l[-1]]) + k)%26]

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

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

ns = []
for c in s[:-1]:
    if c == 'a':
        ns.append(c)
        continue

    ofstoa = ord('z')+1-ord(c)
    if k >= ofstoa:
        ns.append(chr(ord(c) + ofstoa - 26))
        k -= ofstoa
    else:
        ns.append(c)

last = ord(s[-1])
k = k%26
if last + k > ord('z'):
    ns.append(chr(last + k - 26))
else:
    ns.append(chr(last + k))
print(''.join(ns))

Solution (Python):


import sys
readline = sys.stdin.readline

S = list(readline().rstrip())
K = int(readline())

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

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

print("".join(S))

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
k = inn()
n = len(s)
t = [ord(c)-ord('a') for c in s]
for i in range(n):
    if t[i]>0 and k>=26-t[i]:
        k -= 26-t[i]
        t[i] = 0
if k>0:
    t[n-1] = (t[n-1]+k)%26
print(''.join([chr(t[i]+ord('a')) for i in range(n)]))

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

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

print(ans[:-1]+last)

Solution (Python):
S = input()
K = int(input())
Ans = []
for s in S[:-1]:
    if s == 'a':
        Ans.append('a')
        continue
    if (123 - ord(s)) <= K:
        Ans.append('a')
        K -= 123 - ord(s)
    else:
        Ans.append(s)

K %= 26
if ord(S[-1]) + K >= 123:
    Ans.append(chr(ord(S[-1]) + K - 26))
else:
    Ans.append(chr(ord(S[-1]) + K))


print(''.join(Ans))

Solution (Python):
s = input()
k = int(input())
f = lambda x: (ord('a') - ord(x))%26
ans = ''
for c in s:
    if k>=f(c):
        ans += 'a'
        k -= f(c)
    else:
        ans += c
ans = ans[:-1] + chr(ord('a') + (ord(ans[-1])-ord('a')+k)%26)
print(ans)

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

for i in range(n):
    x = ord(s[i]) - ord('a')
    if x == 0 or 26 -x > k: continue
    k -= 26 - x
    s[i] = 'a'

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

print(''.join(s))

Solution (Python):
s = list(input())
k = int(input())
n = len(s)
al=[chr(ord('a') + i) for i in range(26)]

for i in range(n):
    now = ord(s[i]) - ord('a')
    if now != 0:
        if k >= 26 - now:
            s[i] = "a"
            k -= 26 - now
        
s[n-1] = al[(ord(s[n-1])-ord("a") + k) % 26]

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

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

for i in range(n-1):
    t=s[i]
    order=ord(t)-97
    if order==0:
        continue
    elif k>=26-order:
        s[i]='a'
        k-=26-order
    else:
        continue
s[n-1]=chr(97+(ord(s[n-1])-97+k)%26)

print(''.join(s))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = list(input())
K = INT()

def ctoi(c):
	return ord(c) - ord('a')

for i in range(len(s)):
	x = ctoi(s[i])
	if x == 0 or 26-x > K:  continue
	K -= 26-x
	s[i] = "a"
if K:
	s[-1] = ascii_lowercase[(ctoi(s[-1])+K)%26]
print("".join(s))

Solution (Python):

S=list(input())
K=int(input())
N=len(S)

L=[]

for i in range(N):
    L.append((26-(ord(S[i])-ord("a")))%26)

for i in range(N):
    if K>=L[i]:
        S[i]="a"
        K-=L[i]

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

print("".join(S))

Solution (Python):
def codefes16qa_c():
    s = str(input())
    k = int(input())
    n = len(s)
    ans = ''
    for i in range(n):
        if s[i] == 'a':
            ans += s[i]
            continue
        step2a = 1 + ord('z') - ord(s[i])
        if step2a <= k:
            ans += 'a'
            k -= step2a
        else:
            ans += s[i]
    if k > 0:
        last = ord(ans[-1]) + (k % 26)
        ans = ans[:n-1] + chr(last)
    print(ans)

codefes16qa_c()

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

s = list(ns())
n = len(s)
k = ni()

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

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

print(*s, sep="")

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

    for i in range(len(s)-1):
        if s[i] == 'a':
            continue
        else:
            mod = 26-(ord(s[i])-97)%26
            if k >= mod:
                k -= mod
                s[i] = 'a'
            if k == 0:
                break
    
    if k > 0:
        mod = ((ord(s[-1])-97)+k)%26
        s[-1] = chr(mod+97)
    print(''.join(s))

if __name__ == '__main__':
    main()

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

now = 0

while k>0 and now<len(s):
    if s[now]=='a':
        now+=1
        continue
    tmp = ord('z')-ord(s[now])+1
    if tmp<=k:
        s[now] = 'a'
        k -= tmp
        now+=1
    else:
        now+=1

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

print(*s,sep='')

Solution (Python):
def main():
    s=list(input())
    k=int(input())
    i=0
    while k>=0 and i<len(s)-1:
        if s[i]!='a' and k>=123-ord(s[i]):
            k-=123-ord(s[i])
            s[i]="a"
        i+=1
    if i==len(s)-1:
        s[-1]=chr(97+(k-(123-ord(s[i])))%26)
    print("".join(s))
if __name__=="__main__":
    main()

Solution (Python):
alphabet = list("abcdefghijklmnopqrstuvwxyz")
s = list(input())
S = [alphabet.index(x) for x in s]
K = int(input())
tmp = K
i = 0
while i < len(S) and tmp > 0:
  if S[i] != 0 and 26-S[i] <= tmp:
    tmp -= 26-S[i]
    S[i] = 0
  i += 1
if tmp > 0:
  S[-1] = (S[-1]+tmp)%26
print("".join([alphabet[x] for x in S]))

Solution (Python):
X='abcdefghijklmnopqrstuvwxyz'*2
S=input()
k=int(input())
N=[]
for s in S:
    if s=='a':
        N.append(0)
    else:
        N.append(26-X.index(s))
ans=''
for i in range(len(S)):
    if N[i]<=k :
        k-=N[i]
        ans+='a'
    else:
        ans+=S[i]
ans=ans[:-1]+X[X.index(ans[-1])+k%26]

print(ans)

Solution (Python):


s = input()
k = int(input())
n = len(s)
ans = []
for i in range(n):
    t = (ord('z') - ord(s[i]) + 1) % 26
    if k - t >= 0:
        ans.append('a')
        k -= t
    else:
        ans.append(s[i])
if k > 0:
    k %= 26
    ans[-1] = chr(ord(ans[-1]) + k)
print(''.join(ans))

Solution (Python):
S=list(input())
k=int(input())
Ans=[0]*len(S)
c=0
for i in range(len(S)):
  if (26-(ord(S[i])-97))%26<=k:
    Ans[i]="a"
    k=k-(26-(ord(S[i])-97))%26
    c=c+(26-(ord(S[i])-97))%26
  else:
    Ans[i]=S[i]
  if i==len(S)-1:
    c=ord(Ans[i])+k%26
    if ord(Ans[i])+k%26>=123:
      c=c-26
    Ans[i]=chr(c)
print("".join(Ans))

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

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

i=0
l=''
while i<len(S)-1:
    if S[i]=='a':
        l+='a'
    elif 123-ord(S[i])<=K:
        l+='a'
        K-=123-ord(S[i])
    else:
        l+=S[i]
    i+=1

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


print(l)

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

Solution (Python):
import sys

s = list(sys.stdin.readline().strip())
K = int(sys.stdin.readline().strip())

i = 0
while i < len(s):
    if K == 0:
        break

    
    if i == len(s) - 1:
        n = (ord(s[i]) - ord("a") + K) % 26
        
        s[i] = chr(ord("a") + n)
        break

    if s[i] == "a":
        i += 1
        continue

    
    
    n = 26 - (ord(s[i]) - ord("a"))
    
    if n <= K:
        s[i] = "a"
        K -= n

    i += 1

print("".join(s))

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

alp = list('abcdefghijklmnopqrstuvwxyz')
moji_li = []
count_li = []
for ss in s_li:
    ind = alp.index(ss)
    moji_li.append(alp.index(ss))
    count_li.append(26 - alp.index(ss))
for i,c in enumerate(count_li):
    
    if i == len(count_li)-1:
        moji_li[i]+= k
        break
    else:
        if c == 26:
            continue
        if c<=k:
            k-=c
            moji_li[i]=0
ans = ''


for m in moji_li:
    ans += alp[m%26]
print(ans)

Solution (Python):
s=input()
n=int(input())
l=""
for i in range(len(s)):
    f=(26+ord("a")-ord(s[i]))%26
    if n>=f:n-=f;l+="a"
    else:l+=s[i]
    if n==0:print(l+s[i+1:]);exit()
print(l[:-1]+chr(ord(l[-1])+n%26))

Solution (Python):
s=list(input())
k=int(input())
for e,i in enumerate(s):
    c=(123-ord(i))%26
    if k>=c:
        s[e]="a"
        k-=c
    else:s[e]=i
l = chr((ord(s[-1])-97+k)%26+97)
print("".join(s[:-1])+l)

Solution (Python):
s = list(input())
k = int(input())
abc = "abcdefghijklmnopqrstuvwxyz"
c = 0
for e,i in enumerate(s):
    
    if k-26+abc.index(i)>=0 and i!='a':
        s[e] = 'a'
        k-=26-abc.index(i)
    
k+=abc.index(s[-1])
k%=26
s[-1] = abc[k]

print("".join(s))

Solution (Python):
a = list(input())
k = int(input())
abc = "abcdefghijklmnopqrstuvwxyz"
c = 0
for e,i in enumerate(a[:-1]):
    
    if k-26+abc.index(i)>=0 and i!='a':
        a[e] = 'a'
        k-=26-abc.index(i)
    
k+=abc.index(a[-1])
k%=26
a[-1] = abc[k]

print("".join(a))

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    k=int(input())
    len_s=len(s)
    new_s=""
    for i,ss in enumerate(s[:-1]):
        t=ord('z')-ord(ss)+1
        if t<=k and ss!='a':
            k-=t
            new_s+='a'
        else:
            new_s+=ss
    if ord(s[-1])+k%26<=ord('z'):
        new_s+=chr(ord(s[-1])+k%26)
    else:
        new_s+=chr(ord(s[-1])+k%26-26) 
    print(new_s)

if __name__=='__main__':
    main()

Solution (Python):
s=input()
k=int(input())
n=len(s)
s=[s[i] for i in range(n)]
l={"a":26,"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}
for i in range(n):
    c=s[i]
    if c=="a":
        continue
    if l[c]>k:
        continue
    k-=l[c]
    s[i]="a"
if k>0:
    k=k%26
    c=s[-1]
    for i in l:
        if l[i]==l[c]-k:
            s[-1]=i
s=''.join(s)
print(s)

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

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

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

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

Solution (Python):
s=input()
ls = len(s)
k= int(input())
for i in range(ls-1):
    tn = ord('z')-ord(s[i])+1
    if k>=tn and s[i]!='a':
        k-=tn
        print('a',end='')
    else:
        print(s[i],end='')
ik = (k + ord(s[-1])-ord('a')) % 26
print(chr(ord('a')+ik))

Solution (Python):
import sys
from string import ascii_lowercase as AL

input = sys.stdin.readline


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

    N = len(S)
    T = [s for s in S]
    for i in range(N):
        if T[i] == "a":
            continue
        idx = AL.index(T[i])
        if 26 - idx <= K:
            K -= (26 - idx)
            T[i] = "a"

    _, r = divmod(K, 26)
    T[-1] = AL[AL.index(T[-1]) + r]

    ans = "".join(T)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import itertools

s = input()
K = int(input())

alp = list('abcdefghijklmnopqrstuvwxyz')

index_list = [alp.index(s[i]) for i in range(len(s))]

cnt_list = []
for j in index_list:
    if j > 0:
        cnt_list.append(26-j)
    else:
        cnt_list.append(0)

s_list = list(s)

if sum(cnt_list) <= K:
    num = (K - sum(cnt_list)) % 26
    l = "a" * (len(s)-1) + alp[num]
    print(l)
else:
    i = 0
    for i in range(len(s)):
        if i == len(s)-1:
            if K >= cnt_list[i]:
                num = (K - cnt_list[i]) % 26
                s_list[i] = alp[num]
            else:
                s_list[i] = alp[K-cnt_list[i]]
        elif K >= cnt_list[i]:
            K -= cnt_list[i]
            s_list[i] = 'a'
        else:
            pass
    ans = ''.join(s_list)
    print(ans)

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

    print(''.join(s))

if __name__ == '__main__':
     main()

Solution (Python):
S = input()
K = int(input())
N = len(S)
A = [0]*N

ans = ""
for i in range(N):
  A[i] = (ord("z") - ord(S[i]) + 1) % 26
  if i != N-1:
    if K >= A[i]:
      K -= A[i]
      ans += "a"
    else:
      ans += S[i]
  else:
    K = K % 26
    s = ord(S[i]) + K
    if s > ord("z"):
      s -= 26
    ans += chr(s)
    
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = list(input())
    k = int(input())
    alphabet = [chr(i) for i in range(97, 97 + 26)]

    for i in range(len(s)):
        if s[i] == "a":
            continue

        idx = alphabet.index(s[i])
        if 26 - idx <= k:
            s[i] = "a"
            k -= 26 - idx

    if k:
        idx = alphabet.index(s[i]) + k % 26
        s[-1] = alphabet[idx]

    print("".join(s))



if __name__ == '__main__':
    resolve()

Solution (Python):
def main():
    s = input()
    K = int(input())
    new_s = ""

    l = ['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']
    d = {
        "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,
    }

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

    new_s += l[(l.index(s[-1]) + K) % 26]

    print(new_s)

if __name__ == '__main__':
    main()

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

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

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

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