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()
s = list(S)

K = int(input())

alp = "abcdefghijklmnopqrstuvwxyz"
dic = {}

for i in range(26):
    dic[alp[i]] = (26 - i) % 26

ind = {}
for i in range(26):
    ind[alp[i]] = i

for i in range(len(s)):


    if K >= dic[s[i]]:
        K -= dic[s[i]]
        s[i] = "a"

    if i == len(s)-1:
        s[i] = alp[ (K + ind[s[i]]) % 26 ]

    

print ("".join(s))

Solution (Python):
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush

sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): 
    return int(input())
def inpm(): 
    return map(int,input().split())
def inpl(): 
    return list(map(int, input().split()))
def inpls(): 
    return list(input().split())
def inplm(n): 
    return list(int(input()) for _ in range(n))
def inpll(n): 
    return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    s=list(input())
    k=inp()
    n=len(s)
    for i in range(n):
        s[i]=ord(s[i])
    for i in range(n):
        if i==n-1:
            s[i]+=k
            if s[i]>=123:
                s[i]=(s[i]-97)%26+97
        elif s[i]==97:
            s[i]='a'
            continue
        elif 123-s[i]<=k:
            k-=123-s[i]
            s[i]=97
        s[i]=chr(s[i])
    print(''.join(s))

if __name__ == "__main__":
    main()

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

def calcCostToGetA(char):
  if char=='a':
    return 0
  return (ord("z")+1)-ord(char)

for i in range(len(s)):
  cost=calcCostToGetA(s[i])
  if cost<=K:
    s[i]='a'
    K-=cost
    if K==0:
      break

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

Solution (Python):

import sys
from string import ascii_lowercase as alph
ind_alph = dict((char, ind) for ind, char in enumerate(alph))

def main():
    s, k = sys.stdin.read().split()
    s = list(s)
    k = int(k)
    n = len(s)

    i = 0
    while k:
        diff = (26 - ind_alph[s[i]]) % 26
        if diff <= k:
            s[i] = 'a'
            k -= diff
        if i == n - 1 and k:
                s[i] = alph[(ind_alph[s[i]] + k) % 26]
                k = 0
        i += 1

    print(''.join(s))

if __name__ == '__main__':
    main()

Solution (Python):

import sys
from string import ascii_lowercase as alph
ind_alph = dict((char, ind) for ind, char in enumerate(alph))

def main():
    s, k = sys.stdin.read().split()
    s = list(s)
    k = int(k)
    n = len(s)

    i = 0
    while k:
        j = ind_alph[s[i]]
        diff = (26 - j) % 26
        if diff <= k:
            s[i] = 'a'
            k -= diff
        if i == n - 1 and k:
                s[i] = alph[(ind_alph[s[i]] + k) % 26]
                k = 0
        i += 1

    print(''.join(s))

if __name__ == '__main__':
    main()

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

komoji = list('abcdefghijklmnopqrstuvwxyz')
komoji2 = komoji + komoji
index = {}

num = 1
for k in komoji:
    index[k] = num
    num += 1

cost = []
for s in S:
    c = 27 - index[s]
    if c == 26:
        c = 0
    cost.append(c)

ans = []

for num, c in enumerate(cost):
    if c <= K:
        K -= c
        ans.append('a')
    else:
        ans.append(S[num])
        continue
if K != 0:
    K %= 26
    last = ans[-1]
    last = komoji2[komoji.index(last) + K]
    ans[-1] = last
print(''.join(ans))

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

Solution (Python):
s=input()
k=int(input())
ss=[]
for i in range(len(s)):
	ss.append(ord(s[i])-ord("a"))
i=0
while k>0:
	if i==len(s)-1:
		ss[i]=(k+ss[i])%26
		break
	elif k>=26-ss[i] and ss[i]!=0:
		k-=(26-ss[i])
		ss[i]=0
	i+=1
ans=""
for i in range(len(s)):
	ans+=chr(ord("a")+ss[i])
print(ans)

Solution (Python):
s = list(input())
k = int(input())
a = "azyxwvutsrqponmlkjihgfedcb"
for i in range(len(s)-1):
  t = a.index(s[i])
  if k < t:
    continue
  else:
    s[i] = "a"
    k -= t
s[len(s)-1] = a[(a.index(s[len(s)-1])-k)%26]
print(*s, sep="")

Solution (Python):
s = list(input())
K = int(input())
character = '0abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
limit = len(s) - 1

here = 0
while K:
    tmp = character.find(s[here])
    if tmp == 1 and here != limit:
        here += 1
        continue

    if tmp + K > 26 and here != limit:
        K -= 26 - tmp + 1
        s[here] = 'a'
        here += 1
    elif here == limit:
        K %= 26
        s[-1] = character[tmp + K]
        break
    else:
        here += 1
print(''.join(s))

Solution (Python):
from string import ascii_lowercase

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

b = ord('a')

ret = ''
for c in s[:-1]:
    if c == 'a':
        ret += 'a'
        continue
    need = 26 - (ord(c) - b)
    if k >= need:
        k -= need
        ret += 'a'
    else:
        ret += c

k %= 26

c = s[-1]
ret += chr((ord(c) - b + k) % 26 + b)

print(ret)

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

for i in range(len(s)):
    if s[i] == 0: continue
    r = 26 - s[i]
    if r <= k:
        k -= r
        s[i] = 0

s[-1] = (s[-1] + k) % 26
print("".join([chr(x + ord("a")) for x in s]))

Solution (Python):
alpha2num = lambda c: ord(c) - ord('a') + 1
num2alpha = lambda c: chr(c+ord('a')-1)
S = list(map(alpha2num, input()))
K = int(input())

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

if K >= 1:
    S[-1] = (S[-1] + K) % 26
    if S[-1] == 0:
        S[-1] = 26
S = list(map(num2alpha, S))
print(*S, sep='')

Solution (Python):
s=input()
n=int(input())
to_a=[(ord("z")+1-ord(c))%26 for c in s]
is_a=[False for c in s]
for i in range(len(s)):
  if n>=to_a[i]:
    n-=to_a[i]
    is_a[i]=True
    to_a[i]=0
n%=26
for i in range(len(s)-1,-1,-1):
    if not is_a[i]:
        s=s[:i]+chr(ord(s[i])+n)+s[i+1:]
        n=0
        break
if n>0:
    s=s[:-1]+chr(ord("a")+n)
    is_a[-1]=False
for i in range(len(s)):
  if is_a[i]:
    print("a",end="")
  else:
    print(s[i],end="")

Solution (Python):
s=input()
n=int(input())
to_a=[(ord("z")+1-ord(c))%26 for c in s]
is_a=[False for c in s]
for i in range(len(s)):
  if n>=to_a[i]:
    n-=to_a[i]
    is_a[i]=True
    to_a[i]=0
n%=26
for i in range(len(s)-1,-1,-1):
    if not is_a[i]:
        s=s[:i]+chr(ord(s[i])+n)+s[i+1:]
        n=0
        break
if n>0:
    s=s[:-1]+chr(ord("a")+n)
    is_a[-1]=False
for i in range(len(s)):
  if is_a[i]:
    print("a",end="")
  else:
    print(s[i],end="")

Solution (Python):
s_ = input()
n = len(s_)
k = int(input())
s = [ord(s_[i])-97 for i in range(n)]

for i in range(n-1):
    if s[i]:
        if 26-s[i]<=k:
            k -= (26-s[i])
            s[i] = 0


s[n-1] += k
s[n-1] %= 26


ans = [chr(s[i]+97) for i in range(n)]

print(''.join(ans))

Solution (Python):
s=list(str(input()))
k=int(input())
n=len(s)
alpha2num=lambda c: ord(c)-ord('a')+1
for i in range(n):
    s[i]=alpha2num(s[i])

c=k
for i in range(n):
    if c-(27-s[i])>=0:
        if s[i]+c>26 and s[i]!=1:
            c=c-(27-s[i])
            s[i]=1

s[-1]+=c%26
num2alpha=lambda c: chr(c+96)
for i in range(n):
    s[i]=num2alpha(s[i])

print("".join(map(str,s)))

Solution (Python):
def main():
    S = input()
    K = int(input())
    ans = ""
    for i, s in enumerate(S):
        tmp = ord(s) - ord('a')
        if i == len(S) - 1:
            ans += chr((tmp + K) % 26 + ord('a'))
        elif s == 'a':
            ans += s
        elif 26 - tmp <= K:
            ans += 'a'
            K -= 26 - tmp
        else:
            ans += s

    print(ans)
            


if __name__ == "__main__":
    main()

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

S = [ord(c)-97 for c in S]
k = K
for i, s in enumerate(S[:]):
    if s==0:
        continue
    elif 26-s <= k:
        S[i] = 0
        k -= 26-s
S[-1] = (S[-1]+k) % 26
print("".join(map(lambda c: chr(c+97), S)))

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

a = [0] * len(s)
for i in range(len(s) - 1):
  a[i] =  ((ord('z') - ord(s[i])) + 1)%26
  if a[i] == 0:
    pass
  elif K - a[i] >= 0:
    K -= a[i]
    a[i] = 0

for i in range(len(s)-1):
  print(chr((26-a[i])%26+ord('a')), end = '')

if K != 0:
  b = ord('a') + (ord(s[-1])-ord('a') + K)%26
  print( chr( b ) ) 
else:
  print(s[-1])

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

new = ""
for i in range(len(s) - 1):
  diff = (123 - ord(s[i])) % 26
  if diff <= K:
    K -= diff
    new += "a"
  else:
    new += s[i]

if K > 0:
  new_char = ord(s[-1]) + (K % 26)
  if new_char > 122:
    new_char = 96 + (new_char - 122)
  new += chr(new_char)
else:
  new += s[-1]

print(new)

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

num = [26 - i for i in range(26)]
num[0] = 10 ** 9 + 10

a_ = ord('a')

ans = ''
for c in s:
    x = ord(c) - a_
    if num[x] <= k:
        ans += 'a'
        k -= num[x]
    else:
        ans += c
k %= 26
if k > 0:
    c = ans[-1]
    ans = ans[:-1] + chr(a_ + ((ord(c) - a_ + k) % 26))
print(ans)

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

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

print("".join(s))

Solution (Python):
s=input()
k=int(input())
string="abcdefghijklmnopqrstuvwxyz"
lists=[0 for i in range(len(s))]
for i in range(len(s)):
    lists[i]=s[i]

dic={}
for i in range(26):
    dic[string[i]]=(26-i)%26

ans=0
for i in range(len(s)):
    ans=ans+dic[lists[i]]
    if ans<=k:
        lists[i]="a"
    elif ans>=k:
        ans=ans-dic[lists[i]]
    if i==len(s)-1:

        left=(k-ans)%26
        index=dic[lists[len(s)-1]]
        index-=left
        strings="a"
        for some in dic.keys():
            if dic[some]==index%26:
                strings=some
        lists[i]=strings                   
an=""
for j in lists:
    an+=j
print(an)

Solution (Python):
w=input()
nw=len(w)
lw=list(w)
n=int(input())
alpha="qwertyuiopasdfghjklzxcvbnm"
l=sorted(list(alpha))
d={}
for i in range(26):
  d[l[i]]=i
num=n
count=0
while num>0 and count<nw:
  if lw[count]=="a":
    count+=1
  else:
    letter=lw[count]
    if 27-d[letter]-1<=num:
      num-=27-d[letter]-1
      lw[count]="a"
      count+=1
    else:
      count+=1
if num>0:
  a=lw[-1]
  num1=d[a]
  lw[-1]=l[(num1+num)%26]
print("".join(lw))

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

ans = ""
cnt = 0
for i in range(len(S)):
    
    if i == len(S) - 1:
        if ord(S[i]) + (K-cnt)%26 > ord("z"):
            tmp = ord(S[i]) + (K-cnt)%26 - ord("z")
            ans += chr(96+tmp)
        
        else:
            ans += chr(ord(S[i]) + (K-cnt)%26)
    else:
        
        if cnt >= K:
            ans += S[i]
        else:
            if S[i] == "a":
                ans += "a"
            else:
                if cnt + (123 - ord(S[i])) <= K:
                    ans += "a"
                    cnt += (123 - ord(S[i]))
                else:
                    ans += S[i]

print(ans)

Solution (Python):
abc=list(reversed("bcdefghijklmnopqrstuvwxyza"))
s=list(input())
K=int(input())
S=[]
for i in s:
  S.append(abc.index(i))

for i in range(len(S)):
  if S[i]<=K:
    K-=S[i]
    S[i]=0
    
if K>0:
  S[-1]-=K%26
  
if S[-1]<0:
  S[-1]=26+S[-1]
  
ans=[]
for i in S:
  ans.append(abc[i])
  
print("".join(ans))

Solution (Python):
def solve(s, k):
    mapping = {(chr(ord("a") + i)): (26-i)%26 for i in range(26)}
    t = list(s)
    n = len(s)
    for i in range(n):
        if k >= mapping[s[i]]:
            t[i] = "a"
            k -= mapping[s[i]]
    if k > 0:
        k %= 26
        j = ord(t[i]) + k
        if j > ord("z"):
            j -= 26
        t[n-1] = chr(j)
    return "".join(t)

s = input()
k = int(input())
print(solve(s, k))

Solution (Python):
alpha2num = lambda c: ord(c) - ord('a') + 1
num2alpha = lambda c: chr(c+96)

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

N = len(s)
apos = [alpha2num(i) for i in s]

a = []
for i in apos[:-1]:
  diff = 27 - i
  if K >= diff and i != 1:
    K -= diff
    a.append(num2alpha(1))
  else:
    a.append(num2alpha(i))


lastw = (K + apos[-1] - 1) % 26 + 1
a.append(num2alpha(lastw))
print("".join(a))

Solution (Python):
s=input()
k=int(input())
t="abcdefghijklmnopqrstuvwxyz"
a=[t.index(i)for i in s]
i=0
while k:
  if i==len(s)-1:a[i]+=k;a[i]%=26;k=0
  if a[i]==0 or 26-a[i]>k:i+=1
  else:a[i]+=1;a[i]%=26;k-=1
print("".join([t[i]for i in a]))

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

S = list(S)
i = 0
while(K>0):
  if i == len(S)-1:
    S[i] = chr(((ord(S[i])-97)+K)%26+97)
    K = 0
  else:
    a = 26-(ord(S[i])-97)
    if a != 26 and K >= a:
      S[i] = 'a'
      K -= a
  i += 1
print(''.join(S))

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

S = list(S)
i = 0
while(K>0):
  if i == len(S)-1:
    S[i] = chr(((ord(S[i])-97)+K)%26+97)
    K = 0
  else:
    a = 26-(ord(S[i])-97)
    if a != 26 and K >= a:
      S[i] = 'a'
      K -= a
  i += 1
print(''.join(S))

Solution (Python):
alphabet_small = {chr(i):i-97 for i in range(97, 97+26)}
s = input()
k = int(input())
ans =""
for character in s:
    i = alphabet_small[character]
    
    if i != 0 and k >= 26 - i:
        k -= 26 - i
        ans += "a"
    else:
        ans += character


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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

S = input()[:-1]
K = int(input())
ans = ""


def dist_to_a(c):
    return 26-(26+ord(c)-ord('a')) % 26


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

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

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

alp = [chr(i) for i in range(97, 97+26)]

ans = ''
for s in S:
    loc = alp.index(s)
    if s == 'a' or loc + K < 26:
        ans += s
    else:
        K -= 26 - loc
        ans += 'a'

if K > 0:
    K %= 26
    ans = ans[:-1] + alp[(alp.index(ans[-1])+K)%26]
print(ans)

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

Solution (Python):

alpha2num = lambda c: ord(c) - ord('a') + 1
num2alpha = lambda c: chr(c+64)

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

l = [0] * len(s)
for i in range(len(s)):
    tmp = alpha2num(s[i])
    tmp2 = 27 - tmp
    if tmp2 == 26:
        tmp2 = 0
    l[i] = tmp2



for i in range(len(s)):
    if l[i] <= k:
        k -= l[i]
        l[i] = 0

l[-1] -= k%26
while True:
    if l[i] <= -1:
        l[i] += 26
    elif 26 <= l[i]:
        l[i] -= 26
    else:
        break



ans = ''
for i in range(len(s)):
    if l[i] == 0:
        l[i] = 1
    else:
        l[i] = 27 -l[i]
    
    ans += num2alpha(l[i])

print(ans.lower())

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

lista=[]
for i in range(26):
	lista.append(chr(ord('a') + i))
	


s_list=list(s)
len_s=len(list(s))
temp1=k
temp2=0
for i in range(len_s):
	if (123-ord(s_list[i])<=temp1)and (s_list[i] != 'a'):
		temp1=temp1-(123-ord(s_list[i]))
		s_list[i]="a"
if temp1!=0:

	temp2=temp1%26+ord(s_list[-1])
	if temp2>122:
		temp2=temp2-122+96
	s_list[-1]=chr(temp2)



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

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

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

Solution (Python):
s = input()
K = int(input())
base_count = ord("z") + 1
ans = ""
for c in s:
    t = (base_count - ord(c)) % 26
    if t <= K:
        ans += "a"
        K -= t
    else:
        ans += c
if K > 0:
    K = K % 26
    ans = ans[:-1] + chr((ord(ans[-1]) + K))
print(ans)

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

al=list('bcdefghijklmnopqrstuvwxyza')

ans=''
for i in range(len(s)):
    d=25-al.index(s[i])
    if d<=k or s[i]=='a':
        ans+='a'
        k-=d
    else:
        ans+=s[i]
k=k%26
f=al.index(ans[-1])
kai=list(ans)
kai.pop(-1)
ans=''.join(kai)
ans+=al[min(f+k,f+k-26)]
print(ans)

Solution (Python):
import string

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

alp = string.ascii_lowercase
ans = ''

for i in range(len(s)-1):
    num = (len(alp) - alp.index(s[i])) % 26
    if num <= K:
        K -= num
        ans += 'a'
    else:
        ans += s[i]

if K > 0:
    num = (alp.index(s[-1]) + K) % 26
    ans += alp[num]
else:
    ans += s[-1]

print(ans)

Solution (Python):
import string

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

alpha = string.ascii_lowercase
s = len(S)

for i in range(s):
    num = (26 - alpha.index(S[i])) % 26
    if num <= K:
        K -= num
        S[i] = 'a'
    else:
        pass

if K > 0:
    num = (alpha.index(S[-1]) + K) % 26
    S[-1] = alpha[num]
else:
    pass

print(*S, sep='')

Solution (Python):
import string
S = list(input())
K = int(input())
dic = {}
letters=string.ascii_lowercase[::-1]
for id,i in enumerate(letters):
  dic[i] = id + 1
while K > 0:
  SS = S
  for i in range(len(S)):
    if S[i] == "a":
      pass
    else:
      if K >= dic[S[i]]:
        K -= dic[S[i]]
        S[i] = "a"
      else:
        pass
  if SS == S:
    break
if K > 0:
  K %= 26
  V = 0
  if dic[S[-1]] > K:
    V = dic[S[-1]] - K
  else:
    V = (dic[S[-1]] + K) % 26 + 2
  for k,v in dic.items():
    if v == V:
      S[-1] = k
print(*S,sep="")

Solution (Python):
s = input()
k =int(input())
sn = []
sa = []
num2alpha = lambda c: chr(c+64)
alpha2num = lambda c: ord(c) - ord('A') + 1

for c in s:
    sn.append(alpha2num(c))

for i in range(0,len(sn)-1):
    if sn[i] != 33 and 59 - sn[i] <= k:
        k -= 59 - sn[i]
        sn[i] = 33
    else:
        continue

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

for c in sn:
    sa.append(num2alpha(c))

print("".join(sa))

Solution (Python):
S = input()
K = int(input())
N = len(S)
alp = "abcdefghijklmnopqrstuvwxyz"
ans = ""
for i in range(N):
    s = S[i]
    index = alp.find(s)
    if i == N-1:
        ans += alp[(index+K)%26]
    else:
        if s=="a":
            ans += "a"
        elif 26-index <= K:
            ans += "a"
            K -= (26-index)
        else:
            ans += s
print(ans)

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

abc="bcdefghijklmnopqrstuvwxyza"

cnt=K
for i in range(len(s)):
    temp=25-abc.index(s[i])
    if cnt>=temp:
        s[i]="a"
        cnt-=temp

if cnt!=0:
    s[-1]=abc[(abc.index(s[-1])+cnt)%26]

print("".join(s))

Solution (Python):
S=list(map(lambda x: (27-((ord(x)-96)))%26, list(input())))
K=int(input())


for i,s in enumerate(S):
  if K-s>=0:
    K-=s
    S[i]=0
if K>0:
  S[-1]-=K%26
  S[-1]%=26


S=list(map(lambda x: 1 if x==0 else 27-x, S))
S=list(map(lambda x: chr(x+96), S))
print("".join(S))

Solution (Python):
import sys

def I(): return(int(sys.stdin.readline()))
def S(): return(list(sys.stdin.readline())[:-1])

def main():
    s = S()
    K = I()
    N = len(s)

    for i in range(N):
        if K==0:
            break
        if s[i] != "a" and ord("z")-ord(s[i])<K:
            K -= ord("z")-ord(s[i])+1
            s[i] = "a"
    
    if K>0:
        K %= 26

    s[N-1] = chr(ord(s[N-1])+K)
    return("".join(s))

if __name__ == "__main__":
    print(main())

Solution (Python):
s = input()
ans = ""
k = int(input())
x = "abcdefghijklmnopqrstuvwxyz"

for i in range(len(s)-1):
    if (26-(ord(s[i])-ord("a")))%26 <= k:
        ans += "a"
        k -= (26-(ord(s[i])-ord("a")))%26 
    else:
        ans += s[i]

last = x[(ord(s[-1])-ord("a")+k)%26]
ans += last

print(ans)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
k = I()
n = len(s)
alpha = 'abcdefghijklmnopqrstuvwxyz'
ans = ''
for i in range(n-1):
    a = 26 - alpha.index(s[i])
    if s[i] == 'a':
        ans += s[i]
        continue
    if a <= k:
        k -= a
        ans += 'a'
    else:
        ans += s[i]
if k > 0:
    tmp = alpha.index(s[-1])
    ans += alpha[(tmp + k % 26) % 26]
else:
    ans += s[-1]
print(ans)

Solution (Python):


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

cnta=0
min_l=10000

for i in range(n):
    cnt=123-ord(s[i])
    if cnt>k:continue
    if s[i]=='a':
        cnta+=1
        continue
    s[i]='a'
    k-=cnt
    if k==0:break
else:
    last=s[-1]
    while cnta>=0:
        tmp=ord(last)-97
        kk=(k-cnta*26)%26
        
        min_l=min(min_l,(tmp+kk)%26)
        cnta-=1
    else:
        s[-1]=chr(min_l+97)
        
print(''.join(s))

Solution (Python):
import sys
from collections import defaultdict
sys.setrecursionlimit(200000)
input = sys.stdin.readline


S = [ord(v) - ord("a") for v in input().strip()]
N, = map(int, input().split())

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

S[-1] += N % 26

print("".join([chr(ord("a") + v) for v in S]))

Solution (Python):



def main():
    s = [c for c in input()]
    k = int(input())
    l = len(s)

    
    
    for i in range(l):
        t = (ord('z') - ord(s[i]) + 1) % 26

        if t <= k:
            k -= t
            s[i] = 'a'

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

    print(''.join(s))


if __name__ == '__main__':
    main()

Solution (Python):
def main():

    s = input()
    K = int(input())
    n = len(s)
    t = ""
    for i in range(n):
        if s[i] == "a":
            t += s[i]
        elif ord("z") - ord(s[i]) + 1 <= K:
            K -= ord("z") - ord(s[i]) + 1
            t += "a"
        else:
            t += s[i]

    if K > 0:
        u = chr(97 + (ord(t[-1])-97 + K % 26) % 26)
        t = t[:-1] + u
    return t

if __name__ == '__main__':
    print(main())

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

ans = []
for i in range(len(s)):
    if K >= ord('z')-ord(s[i])+1 and s[i] != 'a':
        K -= ord('z')-ord(s[i])+1
        ans.append('a')
    else:
        ans.append(s[i])

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

print(''.join(ans))

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)

from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    s = list(input())
    num = int(input())

    for i in range(len(s)):
        now_ind = ord(s[i])
        if now_ind == 97:
            continue
        if now_ind + num > 122:
            num -= 123 - now_ind
            s[i] = 'a'

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

    print(''.join(s))



if __name__ == '__main__':
    main()

Solution (Python):
s = input()
K = int(input())
N = len(s)
l = list(s)
abc = "abcdefghijklmnopqrstuvwxyz"
M = {}
for i in range(len(abc)):
  M[abc[i]] = i
for i in range(N):
  c = l[i]
  n = (26-M[c])%26
  if K >= n:
    l[i] = "a"
    K -= n
K = K%26
l[-1] = abc[(M[l[-1]]+K)%26]
print("".join(l))

Solution (Python):
s = [ord(i) - 97 for i in input()]
k = int(input())

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

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

ans = "".join(chr(i+97) for i in s)
print(ans)

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

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

for i,c in enumerate(S):
    needed = (97  - ord(c)) % 26
    if needed <= N:
        N -= needed
        S[i] = "a"

N %= 26

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

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

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

while k>0:
    for i in range(len(s)):
        ss=ord(s[i])
        check=122-ss+1
        if check <= k and s[i]!='a':
            k-=check
            s[i]='a'
        else:
            continue
    if s.count('a')==len(s) and k>0:
        k=k%26
        s[-1]=chr(ord(s[-1])+k)
        ans=''.join(s)
        break
    else:
        s[-1]=chr(ord(s[-1])+k)
        ans=''.join(s)
        break
print(ans)

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

a_num = 97
z_num = 122

for i in range(len(s)):
    if K == 0:
        break
    else:
        if i == len(s) - 1:
          if ord(s[i])+ (K%26) <= z_num:
            s[i] = chr(ord(s[i]) + (K%26))
          else:
            s[i] = chr(ord(s[i]) + (K%26) - 26)

        elif ord(s[i]) == a_num:
            continue
        elif K >= z_num - ord(s[i]) + 1:
            K -= z_num - ord(s[i]) + 1
            s[i]="a"
        
print("".join(s))

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

t = []
for i in range(len(s)):
    d = 0 if s[i] == 'a' else ord('z') - ord(s[i]) + 1 
    if d <= k:
        t.append('a')
        k -= d
    else:
        t.append(s[i])

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

print(''.join(t))

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

apple=lambda c:ord(c)-ord("a")+1

l=[]
for i in range(len(s)):
    s[i]=apple(s[i])
    dif=27-s[i]
    if s[i]==1:
        pass
    elif dif<=N:
        N-=dif
        s[i]=1

s[-1]-=1
s[-1]=(s[-1]+N)%26
s[-1]+=1

kiss = lambda c: chr(c+96)
for i in range(len(s)):
    s[i]=kiss(s[i])

print("".join(s))

Solution (Python):
S = input()
K = int(input())
length = len(S)
alpha, n = 'abcdefghijklmnopqrstuvwxyz', 26
i = 0
ans = ''
while i < length:
    diff = (n - (ord(S[i]) - ord('a'))) % 26
    
    if 0 <= diff <= K:
        ans += 'a'
        K -= diff
    else:
        ans += S[i]
    i += 1
if K: ans = ans[:-1] + chr(ord('a') + (ord(ans[-1]) - ord('a') + K) % 26)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = input().rstrip()
K = int(input())

S_rank = [ord(x)-ord('a') for x in S]

after = []

rest = K
for i,x in enumerate(S_rank[:-1]):
    n = (-x)%26
    if n > rest:
        n = 0
    x += n
    x %= 26
    rest -= n
    after.append(chr(x+ord('a')))
after.append(chr(ord('a')+(S_rank[-1]+rest)%26))

answer = ''.join(after)
print(answer)

Solution (Python):
S = list(input())
K = int(input())
characters = ['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']
L = []
for s in S:
  L.append(characters.index(s))

for i in range(len(L)):
  if L[i] == 0:
    pass
  elif 26-L[i] <= K:
    K -= (26-L[i])
    L[i] = 0
  elif K == 0:
    pass
  else:
    pass

L[len(L)-1] = (L[len(L)-1] + K)%26


P = ""

for l in L:
  P += characters[l]
print(P)

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

A = []
for s in S:
    t = (ord('z') - ord(s) + 1) % 26
    if t <= K:
        K -= t
        A.append('a')
    else:
        A.append(s)

A[-1] = chr((ord(A[-1]) + K - ord('a')) % 26 + ord('a'))
print("".join(A))

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

A = []
for s in S:
    if s == 'a':
        A.append('a')
        continue
    t = ord('z') - ord(s) + 1
    if t <= K:
        K -= t
        A.append('a')
    else:
        A.append(s)

A[-1] = chr((ord(A[-1]) + K - ord('a')) % 26 + ord('a'))
print("".join(A))

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

alph = "abcdefghijklmnopqrstuvwxyz"
memo = {}
for i, char in enumerate(alph):
    memo[char] = 26 - i
memo["a"] = 0

ans = []
for char in s:
    if memo[char] <= k:
        ans.append("a")
        k -= memo[char]
    else:
        ans.append(char)
ans[-1] = alph[(26 - memo[ans[-1]] + k) % 26]
print("".join(map(str, ans)))

Solution (Python):

def main():
    S = input().rstrip()
    K = int(input())
    abc = "abcdefghijklmnopqrstuvwxyz"
    
    dist = {c: 26 - i for i, c in enumerate(abc)}
    dist["a"] = 0
    A = [dist[i] for i in S]
    ans = ""
    for i, s in zip(A[:-1], S[:-1]):
        if 0 < i <= K:  
            ans += "a"
            K -= i
        else:
            ans += s
    
    ans += chr((ord(S[-1]) + K - ord("a")) % 26 + ord("a"))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from string import ascii_lowercase as abc


def main():
    S = input().rstrip()
    K = int(input())
    
    dist = {c: 26 - i for i, c in enumerate(abc)}
    dist["a"] = 0
    A = [dist[i] for i in S]
    ans = ""
    for i, s in zip(A[:-1], S[:-1]):
        if 0 < i <= K:  
            ans += "a"
            K -= i
        else:
            ans += s
    
    ans += chr((ord(S[-1]) + K - ord("a")) % 26 + ord("a"))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from string import ascii_lowercase as abc


def main():
    S = input().rstrip()
    K = int(input())
    N, MOD = len(S), 26
    
    dist = {c: 26 - i for i, c in enumerate(abc)}
    dist["a"] = 0
    A = [dist[i] for i in S]
    for i in range(N):
        if A[i] and A[i] <= K:  
            A[i], K = 0, K - A[i]
    A[-1] = (A[-1] - K) % MOD  
    rest = {v: k for k, v in dist.items()}
    ans = [rest[i] for i in A]  
    print(*ans, sep="")


if __name__ == "__main__":
    main()