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):
def main():
    S = input()
    N = len(S)
    K = int(input())
    from string import ascii_lowercase
    dic = {a: i for i, a in enumerate(ascii_lowercase)}
    rdic = {i: a for i, a in enumerate(ascii_lowercase)}
    li = [(26 - dic[s]) % 26 for s in S]
    ans = []
    
    for i, cnt in enumerate(li):
        if i == N - 1:
            ans.append(rdic[(dic[S[i]] + K) % 26])
            continue
        if cnt <= K:
            K -= cnt
            ans.append("a")
        else:
            ans.append(S[i])
    print("".join(ans))


if __name__ == '__main__':
    main()

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

ans = ''
for s in S:
    to_a_cost = (26 - (ord(s) - 97)) % 26
    if to_a_cost <= K:
        ans += 'a'
        K -= to_a_cost
    else:
        ans += s


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

print(ans)

Solution (Python):
import sys

class alphabet(): 
    def __init__(self, capitalize):
        self.num = dict() 
        self.index = dict() 
        self.abc = ["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"]
        if capitalize: 
            for i in range(26): self.abc[i] = self.abc[i].upper()
        for i, a in enumerate(self.abc):
            self.num[a] = i
            self.index[i] = a

def solve():
    S = list(input())
    length = len(S)
    K = int(input())
    changed = 0
    AB = alphabet(False)
    for i, s in enumerate(S):
        aId = AB.num[s]
        if aId == 0: continue
        else:
            toA = 26 - aId
            if K - changed >= toA: 
                S[i] = "a"
                changed += toA
    if K - changed > 0:
        aId = AB.num[S[length - 1]]
        S[length - 1] = AB.index[(aId + K - changed) % 26]
    print("".join(map(str, S)))
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):

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

for i in range(len(S)):
    if S[i] == 'a':
        continue

    d = ord('z') - ord(S[i]) + 1
    if K >= d:
        S[i] = 'a'
        K -= d
    

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

print(''.join(S))

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


D = {c:i for i,c in enumerate('abcdefghijklmnopqrstuvwxyz')}
a = 'abcdefghijklmnopqrstuvwxyz'
s = S()
k = I()
ans = []
cnt = 0
for i in s:
    if 26 - D[i] <= k and i != 'a':
        k -= 26 - D[i]
        ans += ['a']
    else:
        ans += [i]

if k:
    ans[-1] = a[D[ans[-1]] + k % 26]


print(''.join(ans))

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

Solution (Python):
def main():
    s = input().rstrip()
    k = int(input())
    for i in range(len(s)):
        x = ord("z") - ord(s[i]) + 1
        if k >= x and x != 26:
            k -= x
            s = s[:i] + "a" + s[i+1:]
        if i == len(s)-1:
            s = s[:i] + (chr(ord(s[i]) + (k%26)))
    print(s)

if __name__ == "__main__":
    main()

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

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

print("".join(s))

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

s = input()
n = len(s)
r = [ord('z') - ord(t) + 1 if t != 'a' else 0 for t in s]
res = [None] * n
k = inp()
for i,x in enumerate(r):
    if x <= k:
        res[i] = 'a'
        k -= x
if k > 0:
    tmp = 'a' if res[-1] != None else s[-1]
    res[-1] = chr((ord(tmp) - ord('a') + k)%26 + ord('a'))
for i,t in enumerate(res):
    if t == None:
        res[i] = s[i]
print(''.join(res))

Solution (Python):
s = list(input())
K = int(input())
def plus(c,i):
    return chr((ord(c)-ord('a')+i)%26+ord('a'))

for i,ss in enumerate(s):
    want = (ord('z') + 1 - ord(ss))%26
    if K >= want:
        s[i] = plus(s[i],want)
        K = K - want
    
K = K % 26
if K >= 1:
    s[-1] = plus(s[-1],K)
print("".join(s))

Solution (Python):

s = list(input())
K = int(input())
N = len(s)
alp = [chr(i) for i in range(97, 97+26)]

for i in range(N):
    idx = alp.index(s[i])
    
    if K + idx >= 26 and idx != 0:
        K = K - ( 26 - idx )
        s[i] = 'a'
    if K == 0:
        break
    
if K > 0:
    id = alp.index(s[N-1])

    id_ = ( id + K ) % 26

    s[N-1] = alp[id_]

print(''.join(s))

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

Solution (Python):
alp = "abcdefghijklmnopqrstuvwxyz"
s = input()
K = int(input())
N = len(s)
T = ""
for i in range(N):
    n = alp.index(s[i])
    if i==N-1:
        T+=alp[(n+K)%26]
    else:
        if n!=0 and K>=26-n:
            T+="a"
            K-=(26-n)
        else:T+=alp[n]
print(T)

Solution (Python):
s=list(input())
K=int(input())
A=[chr(ord('a') + i) for i in range(26)]+[chr(ord('a') + i) for i in range(26)]
for i in range(len(s)):
  a=A.index(s[i])
  if i==len(s)-1:
    K%=26
    s[i]=A[a+K]
    break
  if s[i]=='a':
    continue
  if K>=26-a:
    K-=(26-a)
    s[i]='a'
  else:
    continue
print(*s,sep='')

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    k = int(input().strip())
    ans = []
    for i, c in enumerate(s):
        if i == len(s)-1:
            ans.append(chr(ord('a') + (ord(c) + k % 26 - ord('a')) % 26))
            break
        d = (ord('z') - ord(c) + 1) % 26
        if d <= k:
            k -= d
            ans.append('a')
        else:
            ans.append(c)
    print(''.join(ans))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    ans = list(s[:])
    k = int(input().strip())
    for i in range(len(s)):
        d = (ord('z') - ord(s[i]) + 1) % 26
        if k - d >= 0:
            ans[i] = 'a'
            k -= d
        if i == len(s) - 1:
            
            ans[i] = chr(ord('a') + (ord(ans[i]) - ord('a') + k%26) % 26)
    print(''.join(ans))

if __name__ == '__main__':
    main()

Solution (Python):
s = input()
x = int(input())
tank = []
for c in list(s):
    if c=='a':
        tank.append(0)
    else:
        tank.append(ord('z') + 1 - ord(c))
res = ''
for i in range(len(tank)):
    if tank[i] == 0:
        res += s[i]
    elif tank[i] <= x:
        x -= tank[i]
        tank[i] = 0
        res += 'a'
    else:
        res += s[i]

c = res[-1]
x %= 26
if ord(c)+x <= ord('z'):
    res = res[:-1] + chr(ord(c)+x)
else:
    res = res[:-1] + chr(ord(c)+x-ord('z')+ord('a')-1)
print(res)

Solution (Python):
s=input()
k=int(input())
ls=[]
lord=[]
for i in range(len(s)):
    ls.append(s[i])
    lord.append(ord(s[i]))
i=0
while k>0 and i<len(s):
    if lord[i]!=97 and k>=123-lord[i]:    
        k=k-(123-lord[i])
        lord[i]=97
        ls[i]='a'
    i+=1

if k>0:
    lord[-1]=lord[-1]+k%26
    ls[-1]=chr(lord[-1])
for x in ls:
    print(x,end="")

Solution (Python):
S = input()
K = int(input())
V = []
for e in S:
    V.append(ord(e)-97)
for i in range(len(S)):
    if S[i] == 'a':
        continue
    if K < 26-V[i]:
        pass
    else:
        K -= 26-V[i]
        V[i] = 0
V[-1] += K
V[-1] %= 26
V = [chr(e+97) for e in V]
print("".join(V))

Solution (Python):
import string

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

str=string.ascii_lowercase
abc=str+str

s_len=len(s)
for i in range(s_len):
  si_inx=abc.index(s[i])

  if i==s_len-1:
    k%=26
    s[i]=abc[si_inx+k]
    break

  if s[i]=='a':
    continue

  if k>=26-si_inx:
    k-=26-si_inx
    s[i]='a'
  else:
    continue

print(''.join(s))

Solution (Python):
import string

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

str=string.ascii_lowercase
abc=str+str

s_len=len(s)
for i in range(s_len):
  si_inx=abc.index(s[i])

  if i==s_len-1:
    k%=26
    s[i]=abc[si_inx+k]
    break

  if s[i]=='a':
    continue

  if k>=26-si_inx:
    k-=26-si_inx
    s[i]='a'
  else:
    continue

  if k<=0:
    break

print(''.join(s))

Solution (Python):
s=input()
slist=[i for i in s]
K=int(input())
cost = []
for i in s:
    if i=="a":
        cost.append(0)
    else:
        cost.append(ord("z")-ord(i)+1)

for i,c in enumerate(cost):
    if c<=K:
        K = K-c
        slist[i]="a"

lastord = (ord(slist[-1])-ord("a")+K)%26+ord("a")
slist[-1]=chr(lastord)

print("".join(slist))

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

alpha=list('abcdefghijklmnopqrstuvwxyz')

ans=[]
for i in range(len(s)):
    ki= 26-alpha.index(s[i]) if s[i]!='a' else 0

    if(i==len(s)-1):
        kn=k+alpha.index(s[i])
        kn=kn%26
        ans.append(alpha[kn])
    elif(ki<=k):
        ans.append('a')
        k-=ki
    else:
        ans.append(s[i])
print(''.join(ans))

Solution (Python):
S=input()
K=int(input())
c2i=lambda c: ord(c)-ord("a")
i2c=lambda i: chr(i+ord("a"))
A=list(map(c2i, S))
for i in range(len(A)):
    if A[i] and 26-A[i]<=K:
        K-=26-A[i]
        A[i]=0
A[-1]+=K
A[-1]%=26
print("".join(map(i2c,A)))

Solution (Python):
import sys


def main():
    s = list(input())
    K = int(input())
    
    l = len(s)
    for i in range(l-1):
        moji = s[i]
        if moji == "a":
            continue
        else:
            a = ord("z")-ord(moji)+1
            if a <= K:
                s[i] = "a"
                K -= a

    K %= 26
    use = ord(s[-1])+K
    if use >= 123:
        use -= 26
    s[-1] = chr(use)
    print("".join(map(str,s)))
    
if __name__ == "__main__":
    main()

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

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

Solution (Python):
s = input()
ints = [ord(i) - ord('a') for i in s]
K = int(input())
n = len(s)
i = 0
while i < n:
    if ints[i] != 0 and 25 - ints[i] + 1 <= K:
        K -= 25 - ints[i] + 1
        ints[i] = 0
    i += 1

K %= 26
ints[-1] = (ints[-1] + K) % 26
s_ = ''
for i in ints:
    s_ += chr(i + ord('a'))

print(s_)

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

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

if k > 0:
    k = k%26
    x = z - ord(s[-1]) +1
    if k >= x:
        k -= z - ord(s[-1]) + 1
        s[-1] = chr(a + k)
    else:
        s[-1] = chr(ord(s[-1])+k)
    
print("".join(s))

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

cnt = K
ans = ''

for s in S:
    if s == 'a':
        ans += 'a'
    elif cnt >= 123 - ord(s):
        cnt -= 123 - ord(s)
        ans += 'a'
    else:
        ans += s

last = ans[-1]
last = chr((ord(last) - 97 + cnt) % 26 + 97)
print(ans[:-1] + last)

Solution (Python):
N = 26
ord_a = ord('a')
S = [ord(s) - ord_a for s in input()]
K = int(input())


for i in range(len(S)):
    r = (N - S[i]) % N
    if K >= r:
        K -= r
        S[i] = 0


S[-1] += K % N
S[-1] %= N

answer = ''.join(chr(s + ord_a) for s in S)
print(answer)

Solution (Python):
s = input()
k = int(input())
l = [(26 - (ord(c) - ord('a'))) % 26 for c in s]
for i in range(len(s) - 1):
    if k >= l[i]:
        k -= l[i]
        s = s[:i] + 'a' + s[i + 1 :]

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

Solution (Python):
alp1 = list('abcdefghijklmnopqrstuvwxyz'[::-1])
num = [i for i in range(1,26)]
alp = {}
for a,n in zip(alp1,num):
    alp[a] = n
s = input()
K = int(input())
ans =''
now = 0
while True:
    if s[now] == 'a':
        ans += 'a'
    elif K >= alp[s[now]]:
        K -= alp[s[now]]
        ans += 'a'
    else:
        ans += s[now]
    now += 1
    if now == len(s):
        break
if K:
    alp1 = alp1[::-1]
    last = ans[-1]
    ans = ans[:-1]
    ind = alp1.index(last)
    ind = (ind+K)%26
    ans += alp1[ind]
    print(ans)
else:
    print(ans)

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

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

    if i==len(s)-1:
        res.append(chr((num+k)%26+97))
    elif s[i] == "a":
        res.append("a")
    elif 26 - num <= k:
        res.append("a")
        k-=26-num
    else:
        res.append(s[i])

print("".join(res))

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

Solution (Python):
s = input()
k = int(input())
alp = 'bcdefghijklmnopqrstuvwxyza'
t = alp.find(s[0])
if len(s) == 1:
    s = alp[(k+t)%26]
else: 
    if k >= 25-t:
        s = 'a' + s[1:]
        k -= 25-t
    for i in range(1, len(s)-1):
        t = alp.find(s[i])
        if k >= 25-t:
            s = s[:i] + 'a' + s[i+1:]
            k -= 25-t
    s = s[:len(s)-1] + alp[(k+alp.find(s[-1]))%26]
print(s)

Solution (Python):
from sys import stdin
import string

alpha = string.ascii_lowercase
nokori = [26-i for i in range(26)];nokori[0] = 0
s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())
sin = ""
for i in s:
    if nokori[alpha.index(i)] <= k:
        k -= nokori[alpha.index(i)]
        sin += "a"
    else:
        sin += i
q = alpha.index(sin[-1])
q += k
print(sin[:-1]+alpha[q%26])

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

for i in range(len(s)):
    if K == 0:
        continue
    n = ord(s[i]) - ord("a")
    if n == 0:
        continue
    m = 26 - n
    if K >= m:
        s[i] = "a"
        K -= m

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

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

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

N = len(S)
T = list(S)
for i in range(N - 1):
    if T[i] == 'a':
        continue
    if K >= ord('z') - ord(T[i]) + 1:
        K -= ord('z') - ord(T[i]) + 1
        T[i] = 'a'

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

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

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

for i in range(len(S)):
  n = ord(S[i])
  if S[i] == 'a':
    continue
  if ord('z') - n + 1 <= K:
    K -= ord('z') - n + 1
    S[i] = 'a'
assert K >= 0
if K != 0:
  n = ord(S[-1])
  n -= ord('a')
  n += K
  n %= 26
  n += ord('a')
  S[-1] = chr(n)
print(''.join(S))

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

A = [" " for _ in range(len(S))]

zan = K
for i in range(len(S)):
  n = (ord('z') - ord(S[i]) + 1) % 26 
  if zan >= n:
    zan -= n
    A[i] = 'a'
  else:
    A[i] = S[i]

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

Solution (Python):
S = [s for s in input()]
K = int(input())
N = len(S)



ord_a = ord('a')

T = [0]*N
for i in range(N):
    s = S[i]
    a = ord(s)
    r = (ord_a + 26 - a) % 26
    if r <= K:
        K -= r
        s = 'a'
    T[i] = s
if K > 0:
    t = T[N - 1]
    a = ord(t)
    a = ord_a + (a - ord_a + K) % 26
    T[N - 1] = chr(a)
print(''.join(T))

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

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

ans = ''
for i, c in enumerate(s):
    dif = ord('z') - ord(c) + 1
    dif %= 26
    if i == len(s) - 1:
        K %= 26
        if ord(c) + K > ord('z'):
            K -= 26
        ans += chr(ord(c) + K)
    elif dif <= K:
        ans += 'a'
        K -= dif
    else:
        ans += c
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    ans = list(s[:])
    k = int(input().strip())
    for i in range(len(s)):
        d = (ord('z') - ord(s[i]) + 1) % 26
        if k - d >= 0:
            ans[i] = 'a'
            k -= d
        if i == len(s) - 1:
            
            ans[i] = chr(ord('a') + (ord(ans[i]) - ord('a') + k%26) % 26)
    print(''.join(ans))

if __name__ == '__main__':
    main()

Solution (Python):
s = str(input())
n = int(input())
k = ord("z")
a = [0]*len(s)
for i in range(len(s)):
    a[i] = ord(s[i])
for i in range(len(s)):
    if a[i] == ord("a"):
        continue
    if n>=k+1-a[i]:
        n = n-k-1+a[i]
        a[i] = ord("a")
    
    if n<=0:
        break
if n>0:
    a[-1] += n%26
ans = ""
for i in range(len(s)):
    ans += chr(a[i])
print(ans)

Solution (Python):
alf = {c:i for i,c in enumerate('abcdefghijklmnopqrstuvwxyz')}
a = 'abcdefghijklmnopqrstuvwxyz'
s = input()
k = int(input())
diff = [26-alf[c] if c != 'a' else 0 for c in s]
ans = []
for i in range(len(s)):
    if k >= diff[i]:
        ans.append('a')
        k -= diff[i]
    else:
        ans.append(s[i])
    
if k > 0:
    ans[-1] = a[(alf[ans[-1]] + k % 26)]
print(''.join(ans))

Solution (Python):
a=input()
n=len(a)
m=int(input())
ans=""
for i in range(n-1):
  if a[i]=="a":
    ans += "a"
    continue
  x=ord(a[i])-97
  if m>=26-x:
    ans += "a"
    m -= 26-x
  else:
    ans += a[i]
ans += chr((ord(a[n-1])-97+m)%26+97)
print(ans)

Solution (Python):
from string import ascii_lowercase

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

d = {c: (26 - i) % 26 for i, c in enumerate(ascii_lowercase)}

ret = ''
for c in s[:-1]:
    if d[c] <= k:
        k -= d[c]
        ret += 'a'
    else:
        ret += c

k %= 26
idx = (ascii_lowercase.index(s[-1]) + k) % 26
c = ascii_lowercase[idx]
ret += c

print(ret)

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

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

Solution (Python):
from collections import defaultdict
def main():
    s = list(input())
    K = int(input())
    lowercase = [chr(i) for i in range(97, 97+26)]
    en = []
    for i in range(26):
        en.append(26-i)
    dic = defaultdict(int)

    for i,j in zip(lowercase,en):
        dic[i] = j

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

if __name__ == '__main__':
    main()

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

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

Solution (Python):
s = input()
K = int(input())
alp = 'abcdefghijklmnopqrstuvwxyz'

ans = ''
for i,w in enumerate(s):
    if i != len(s)-1 and (26-(ord(w)-ord('a')))%26 <= K:
        ans += 'a'
        K -= (26-(ord(w)-ord('a')))%26
    elif i != len(s)-1:
        ans += w
    if i == len(s)-1:
        
        lastlidx = (ord(w)-ord('a') + K%26)%26
        ans += alp[lastlidx]
print(ans)

Solution (Python):
S = input()
K = int(input())
alp = '0bcdefghijklmnopqrstuvwxyza'
alp_dict = {s:i for i,s in enumerate(alp)}


cnt = 0
ans = ''
for i,s in enumerate(S):
  if cnt + (26-alp_dict[s]) <= K:
    cnt += (26-alp_dict[s])
    ans += 'a'
  else:
    ans += s

if (K-cnt)%26==0:
  print(ans)
else:
  rest = (K-cnt)%26
  print(ans[:-1]+alp[(alp_dict[ans[-1]]+rest)%26])

Solution (Python):




def ord_until_a(char):
    if char == 'a':
        return 0
    return ord('a') + 26 - ord(char)
    


S = input()
K = int(input())
ans = []
for s in S:
    diff = ord_until_a(s)
    if K >= diff:
        ans.append('a')
        K -= diff
    else:
        ans.append(s)

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

print(''.join(ans))

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

Solution (Python):
s=input()
k=int(input())
sl=[]
n=len(s)
for i in range(n):
  if s[i]!='a':
    if 26-(ord(s[i])-97)<=k:
      sl.append('a')
      k-=26-(ord(s[i])-97)
    else:
      sl.append(s[i])
  else:
    sl.append(s[i])
if k>0:
  if k%26!=0:
    sl[n-1]=chr(ord(sl[n-1])+k%26)
print(''.join(sl))

Solution (Python):
S = input()
N = len(S)
K = int(input())
T = []
for i in range(N):
    s = ord(S[i]) - 97
    a = (26-s) % 26
    if a <= K:
        K -= a
        T.append("a")
    else:
        T.append(S[i])
T[-1] = chr((ord(T[-1]) - 97 + K) % 26 + 97)
print("".join(T))

Solution (Python):
S = [(ord("z") + 1 - ord(s)) % 26 for s in input()]
K = int(input())

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

S[-1] = (S[-1] - K) % 26
print(*[chr(ord("z") - (s-1) % 26) for s in S], sep="")

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

c = [ord(s1)-ord('a') for s1 in s]
sl = list(s)

for i in range(len(s)):
    if c[i] and 26-c[i] <= K:
        sl[i] = 'a'
        K -= 26-c[i]
sl[len(s)-1] = chr((ord(sl[len(s)-1]) - ord('a') + K) % 26 + ord('a'))

print(''.join(sl))

Solution (Python):
s = input().strip()
K = int(input())
if K>len(s)*26:
    d = (K-len(s)*26)//26
    K = K-26*d
x = ""
for i in range(len(s)):
    if i<len(s)-1 and (26-(ord(s[i])-ord("a")))%26 <= K:
        x += "a"
        K -= (26-(ord(s[i])-ord("a")))%26
    elif i<len(s)-1:
        x += s[i]
    elif i==len(s)-1:
        k = ord(s[i])+K%26
        if k<=122:
            x += chr(k)
        else:
            x += chr(k-26)
print(x)

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

print(ans)

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

for i in range(N - 1):
    d = (ord("a") - ord(S[i])) % 26
    if d <= K:
        S[i] = "a"
        K -= d

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

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

S = [0 for _ in range(N)]

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

tmp = K
ans = ''

for i in range(N):
    if S[i]==0:
        ans += 'a'
    elif 26-S[i] <= tmp:
        ans += 'a'
        tmp -= 26-S[i]
    else:
        ans += s[i]
        
if tmp:
    ans = ans[:-1]+chr((ord(ans[-1])-97+tmp)%26+97)
    
print(ans)

Solution (Python):
s = input()
K = int(input())
alpha = "bcdefghijklmnopqrstuvwxyza"
dic = {j : 25 - i for i, j in enumerate(alpha)}
inv_dic = {j : i for i, j in dic.items()}
s_ls = [dic[_s] for _s in s]
remain = K
ind = 0
len_s = len(s)
while ind < len_s and remain > 0:
    _s = s_ls[ind]
    if _s <= remain:
        remain -= _s
        s_ls[ind] = 0
    ind += 1
if remain > 0:
    s_ls[ind - 1] = (s_ls[ind - 1] - remain) % 26
print("".join([inv_dic[_s] for _s in s_ls]))

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


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
import string
s = (stdin.readline().rstrip())
K = int(stdin.readline().rstrip())

alp = string.ascii_lowercase*3
ans = ""
for i in s:
    ind = alp.index(i)
    cnt = 0
    if i == "a":
        ans += "a"
        continue
    for j in alp[ind+1:]:
        cnt += 1
        if K - cnt < 0:
            ans += i
            cnt = 0
            break
        if j == "a":
            ans += "a"
            K = K - cnt
            cnt = 0
            break
if K != 0:
    ind = (K % 26) + alp.index(ans[-1])
    ans = ans[:-1]+alp[ind]
print(ans)

Solution (Python):
s = [ord(i) for i in input()]
K = int(input())

ret = []
for c in s[:-1] :
    if c == 97 :
        ret.append('a')
        continue
        
    if c + K > 122 :
        ret.append('a')
        K -= 123 - c
    else :
        ret.append(chr(c))
        
K %= 26
ret.append(chr((s[-1] + K - 97) % 26 + 97))
        
print(''.join(ret))

Solution (Python):

alpha = "bcdefghijklmnopqrstuvwxyza"
last_process = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
need_char_point = {}
need_point_char = {}
pointa = 0
for i in reversed(range(len(alpha))):
    need_char_point[alpha[pointa]] = i
    need_point_char[i] = alpha[pointa]
    pointa += 1


s = str(input())
k = int(input())
ans = ""
for i in range(len(s)):
    if k >= need_char_point[s[i]]:
        k -= need_char_point[s[i]]
        ans += "a"
    else:
        ans += s[i]
if k > 0:
    k %= 26
    for i in range(len(last_process)):
        if ans[-1] == last_process[i]:
            tmp = i
            break
    hoge = list(ans)
    hoge[-1] = last_process[tmp+k]
    ans = "".join(hoge)

print(ans)

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

    s = list(map(lambda x: ord(x), s))
    B = [0 for _ in range(len(s))]
    for i in range(len(s)):
        b = 26 - (s[i] - ord("a"))
        if b == 26:
            B[i] = 0
        elif b <= K:
            K -= b
            B[i] = 0
        else:
            B[i] = b

    if K != 0:
        B[-1] -= K
        B[-1] %= 26

    ans = list(map(lambda c: chr(ord("a") + (26 - c) % 26), B))
    print("".join(ans))


main()

Solution (Python):
from collections import deque
s=input()
money=int(input())
ans=deque()

d = dict(zip([chr(i) for i in range(97, 97+26)], range(0,26)))
d_r = dict(zip(range(0,26),[chr(i) for i in range(97, 97+26)]))

s_hash = deque([d[i] for i in s])

while len(s_hash)>0:
    
    n = s_hash.popleft()
    if (money >= 26 - n) & (n != 0):
        ans.append(0)
        money -= 26 - n
    else:
        ans.append(n)

money = money % 26
while money>0:
    n = ans.pop()
    ans.append((n+money) % 26)
    money = 0

print("".join([d_r[i] for i in ans]))

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

alp = "abcdefghijklmnopqrstuvwxyza"
to_a = {alp[i]: 26 - i for i in range(1, len(alp))}

for i, s in enumerate(S):
    if to_a[s] > k:
        continue
    else:
        S[i] = "a"
        k -= to_a[s]
    if k == 0:
        break

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

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

Solution (Python):
s=input()
K=int(input())
ns=len(s)
ls=list(s)
for i in range(ns):
    if K==0:
        break
    if ls[i]=="a":
        continue
    toa=ord("z")+1-ord(ls[i])
    
    if toa<=K:
        ls[i]="a"
        
        K-=toa
        
ls[-1]=chr(ord(ls[-1])+K%26)

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

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


def main():
    s = input().strip()
    K = int(input())
    ans = ""
    for c in s:
        if c == "a":
            ans += c
        else:
            cost = 26 - (ord(c) - ord("a"))
            if cost <= K:
                K -= cost
                ans += "a"
            else:
                ans += c
    finalletter = ans[-1]
    ans = ans[:-1] + chr(ord("a") + (ord(finalletter) - ord("a") + K) % 26)
    print(ans)

if __name__ == '__main__':
    main()

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

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

K %= 26 
tmp = ord(s[n - 1]) + K
if tmp >= 123:
    tmp -= 26
s[n - 1] = chr(tmp)

print (*s, sep = '')