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
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def diff(s):
    if s == 'a': return 0
    if s == 'b': return 25
    if s == 'c': return 24
    if s == 'd': return 23
    if s == 'e': return 22
    if s == 'f': return 21
    if s == 'g': return 20
    if s == 'h': return 19
    if s == 'i': return 18
    if s == 'j': return 17
    if s == 'k': return 16
    if s == 'l': return 15
    if s == 'm': return 14
    if s == 'n': return 13
    if s == 'o': return 12
    if s == 'p': return 11
    if s == 'q': return 10
    if s == 'r': return 9
    if s == 's': return 8
    if s == 't': return 7
    if s == 'u': return 6
    if s == 'v': return 5
    if s == 'w': return 4
    if s == 'x': return 3
    if s == 'y': return 2
    if s == 'z': return 1

def sol():
    S = list(input().strip())
    K = int(input())

    for i, s in enumerate(S):
        if s == 'a':
            continue
        else:
            if diff(s) <= K:
                S[i] = 'a'
                K -= diff(s)

    last = K % 26
    S[-1] = chr(ord(S[-1]) + last)
    print(*S, sep='')

sol()

Solution (Python):
s = list(input())
K = int(input())
for i in range(len(s)):
  K -= (97 - ord(s[i]))%26
  if K < 0:
    K += (97 - ord(s[i]))%26
  else:
    s[i] = 'a'
s[-1] = chr(((ord(s[-1])+K)-97)%26+97)
for i in s:
  print(i,end="")

Solution (Python):
s=list(input())
k=int(input())
l=[chr(i) for i in range(97, 97+26)]
for i in range(len(s)-1):
  if (26-l.index(s[i]))%26<=k:
    k-=(26-l.index(s[i]))%26
    s[i]='a'
s[len(s)-1]=l[(l.index(s[len(s)-1])+k)%26]
print(''.join(s))

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

a='abcdefghijklmnopqrstuvwxyz'
d=dict()
for i in range(26):
	d[a[i]]=i
	
for i in range(len(s)):
	if 26-d[s[i]]<=n:
		n-=(26-d[s[i]])%26
		s[i]='a'

s[len(s)-1]=a[(d[s[len(s)-1]]+n)%26]
print(''.join(s))

Solution (Python):
s=input()
K=int(input())
S=[c for c in s]
def diff(c):
    return ord('z')-ord(c)
for i in range(len(s)):
    d=diff(S[i])
    if d<min(25,K):
        K-=d+1
        S[i]='a'
k=K%26
S[-1]=chr(ord(S[-1])+k) if k<=diff(S[-1]) else chr(ord(S[-1])+k-26)
print(''.join(S))

Solution (Python):
S = [c for c in input()]
K = int(input())

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

K %= 26

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

ans = ''.join(S)

print(ans)

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

NEXA = 26
dic = {chr(97+i): i for i in range(NEXA)}

s = lc()
k = ni()

ans = []

for si in s:
    to_nexa = (NEXA - dic[si]) % NEXA
    if to_nexa <= k:
        k -= to_nexa
        ans.append('a')

    else:
        ans.append(si)

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

print("".join(ans))

Solution (Python):
S = list(input())
K = int(input())
a = ord("a")
for i,s in enumerate(S):
    t = (a-ord(s))%26
    if K>=t:
        K-=t
        S[i] = "a"
if K>0:
    S[-1] = chr(a + (ord(S[-1])-a+K)%26)
print("".join(S))

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

ans = ""
for i in range(len(S)):
    if ord("z") - ord(S[i]) + 1 <= K and i != len(S) - 1:
        ans += "a"
        if S[i] == "a":
            continue
        K -= ord("z") + 1 - ord(S[i])
    elif i == len(S) - 1:
       K %= 26
       if ord("z") - ord(S[i]) + 1 <= K:
            K -= ord("z") + 1 - ord(S[i]) 
            ans += chr(ord("a") + K)
       else:
            ans += chr( ord(S[i]) + K)
    else:
        ans += S[i]

print(ans)

Solution (Python):
s = input().rstrip()
k = int(input())
for i in range(len(s)):
    if s[i] == "a":
        continue
    cost = ord("z") - ord(s[i]) + 1
    if cost <= k:
        k -= cost
        s = s[:i] + "a" + s[i+1:]
s = s[:-1] + chr((ord(s[-1]) - ord("a") + k) % 26 + ord("a"))
print(s)

Solution (Python):
s=list(input())
l=len(s)
k=int(input())
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}
for i in range(l):
  if k-dic[s[i]]>=0:
    k=k-dic[s[i]]
    s[i]='a'
if k%26==0:
  ans=''
  for c in s:
    ans+=c
  print(ans)
else:
  s[-1]=chr(ord('a')+(ord(s[-1])-ord('a')+k)%26)
  ans=''
  for c in s:
    ans+=c
  print(ans)

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):
def main():
    s = list(input())
    n = int(input())

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

if __name__=="__main__": main()

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

t = []

for i in range(len(s)):
    c=ord(s[i])-97
    if i!=len(s)-1:
        if c!=0:
            if K>=26-c:
                K-=26-c
                t.append("a")
            else:
                t.append(chr(97+c))
        else:
            t.append("a")
    else:
        t.append(chr(97+(c+K)%26))

print("".join(t))

Solution (Python):
s = list(input())
K = int(input())
for i in range(len(s)-1):
    if K == 0:
        break
    else:
        if s[i] == "a":
            continue
        else:
            if 123-ord(s[i]) <= K:
                K -= 123-ord(s[i])
                s[i] = "a"
K = K %26
if K > 0:
    if ord(s[-1])+K <= 122:
        s[-1] = chr(ord(s[-1])+K)
    else:
        s[-1] = chr(96+((ord(s[-1])+K-122)))

print(*s,sep="")

Solution (Python):
s = str(input())
K = int(input())
L = [0 for k in range(len(s))]

for k in range(len(s)):
    L[k] = (123-ord(s[k]))%26

now = 0
while K > 0 and now < len(s):
    if K >= L[now]:
        K -= L[now]
        L[now] = 0
        now += 1
    else:
        now += 1

ans = ""
for k in range(len(s)):
    if L[k] == 0:
        ans += "a"
    else:
        ans += chr(123-L[k])
print(ans[:-1]+chr(ord(ans[-1])+K%26))

Solution (Python):
s = input()
K = int(input())
ans = ''
for ind,i in enumerate(s):
    if(i=='a' and ind!=len(s)-1):
        ans+='a'
        continue
    d = 123-ord(i)
    if(ind==len(s)-1):
        K%=26
        if(K>=d):
            ans += chr(97+K-d)
            continue
        ans+=chr(ord(i)+K)
    elif(K>=d):
        K-=d
        ans+='a'
    else:
        ans+=i
print(ans)

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

ans = ''

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

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

print(ans)

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

ans = ''

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

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

print(ans)

Solution (Python):
import string
alp=string.ascii_lowercase
s=input()
k=int(input())
ans=[]
i=0
while i<len(s)-1:
    t=s[i]
    d=(26-alp.index(t))%26
    if d<=k:
        k-=d
        ans.append('a')
    else:
        ans.append(t)
    i+=1
if k>0:
    ans.append(alp[(alp.index(s[-1])+k%26)%26])
else:
    ans.append(s[-1])
print(''.join(ans))

Solution (Python):
import string
alp=string.ascii_lowercase
s=input()
k=int(input())
ans=''
i=0
while i<len(s)-1:
    t=s[i]
    d=(26-alp.index(t))%26
    if d<=k:
        k-=d
        ans+='a'
    else:
        ans+=t
    i+=1
if k>0:
    ans+=alp[(alp.index(s[-1])+k%26)%26]
else:
    ans+=s[-1]
print(ans)

Solution (Python):


import string
alp=string.ascii_lowercase
di={}
for i in range(26):
    di[alp[i]]=i
s=input()
a=[]
for i in s:
    a.append(i)
l=a.pop()
if a:
    a=a[::-1]
k=int(input())
ans=''
i=0
while a:
    t=a.pop()
    d=(26-di[t])%26
    if d<=k:
        k-=d
        ans+='a'
    else:
        ans+=t
    i+=1
kk=k%26
ans+=alp[(alp.index(l)+kk)%26]
print(ans)

Solution (Python):
s=input()
k=int(input())
A={}
for i in range(26):
  A[chr(ord('a')+i)]=26-i
C=[]
for ss in s:
  C.append(A[ss])
ans=""
for i in range(len(s)):
  if i==len(s)-1:
    k%=26
    if ord(s[-1])+k>122:
      ans+=chr(ord(s[-1])+k-26)
    else:
      ans+=chr(ord(s[-1])+k)
  elif s[i]!="a" and k>=C[i]:
    ans+="a"
    k-=C[i]
  else:
    ans+=s[i]
print(ans)

Solution (Python):
def main():
    s = input()
    K = int(input())
    a = ord("a")
    code = [ord(c) - a for c in s]
    for i in range(len(s)):
        x = (26 - code[i]) % 26
        if x <= K:
            code[i] = 0
            K -= x
    code[-1] = code[-1] + K % 26
    ans = "".join([chr(a + x) for x in code])
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

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



t = list(s)
L = K
for i in range(len(s)):
    d = 123 - ord(s[i])
    if 1 <= d <= min(25, L):
        t[i] = 'a'
        L -= d
t[-1] = chr((ord(t[-1]) - 97 + L) % 26 + 97)
ans = ''.join(t)


print(ans)

Solution (Python):

"""
C - 次のアルファベット / Next Letter
https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_c

"""
import sys

from string import ascii_lowercase

def solve(s, K):
    ans = []
    lut = 'a' + ascii_lowercase[::-1]
    for ch in s:
        distance = lut.index(ch)
        if distance <= K:
            K -= distance
            ans.append('a')
        else:
            ans.append(ch)
    ans[-1] = ascii_lowercase[(ord(ans[-1]) - ord('a') + K) % 26]
    return ''.join(ans)


def main(args):
    s = input()
    K = int(input())
    ans = solve(s, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):

"""
C - 次のアルファベット / Next Letter
https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_c

"""
import sys

from string import ascii_lowercase

def solve(s, K):
    ans = []
    for ch in s:
        distance = ascii_lowercase[::-1].index(ch) + 1
        if distance <= K and ch != 'a':
            K -= distance
            ans.append('a')
        else:
            ans.append(ch)
    ans[-1] = ascii_lowercase[(ord(ans[-1]) - ord('a') + K) % 26]
    return ''.join(ans)


def main(args):
    s = input()
    K = int(input())
    ans = solve(s, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
d = {chr(122 - i):i + 1 for i in range(26)}
d['a'] = 0
s = list(input())
k = int(input())
l = []
for i in range(len(s)):
  l.append(d[s[i]])
for i in range(len(s)):
  if l[i] <= k:
    k -= l[i]
    s[i] = 'a'
s[-1] = chr((ord(s[-1]) - 97 + k) % 26 + 97)
print(''.join(s))

Solution (Python):
S = input()
T = ""
K = int(input())
for s in S:
    x = (123 - ord(s))%26
    if K >= x:
        s = "a"
        K -= x
    T += s

K = K%26
ans = ""
for t in T[::-1]:
    d = min(K, 122 - ord(s))
    K -= d
    ans += chr(ord(t)+d)

print(ans[::-1])

Solution (Python):
s=input()
l=[]
for i in s:l.append((123-ord(i))%26)
k=int(input())
for i,j in enumerate(l):
    if j<=k:l[i],k=26,k-j
l[-1]=(l[-1]-k%26)+[0,26][l[-1]-k%26<1]
for i,j in enumerate(l):l[i]=chr(123-j)
print(''.join(map(str,l)))

Solution (Python):
a ='abcdefghijklmnopqrstuvwxyz'
s = input()
k = int(input())
sl =len(s)
nl =[(123-ord(l)) % 26 for l in s]

i = 0
while k > 0 and i < sl:
    if nl[i] !=0 and k >=nl[i]:
        k -= nl[i]
        nl[i] = 0
        i += 1
    else:
        i += 1
if k > 0:
    nl[-1] += 26- k
print(''.join([a[(26-i) % 26] for i in nl]))

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

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

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

for i in range(N):
    toA=(ord('z')+1-ord(S[i]))%26
    if K>=toA:
        S[i]='a'
        K-=toA

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

Solution (Python):
a = list(map(str, input()))
b = int(input())

for i in range(len(a)):
    if a[i] == 'a':
        continue
    else:
        s = ord(a[i]) - 96
        if 27 - s <= b:
            a[i] = 'a'
            b -= 27 - s

if b != 0:
    a[-1] = chr(((ord(a[-1]) - 97 + b) % 26) + 97)

print(''.join(a))

Solution (Python):
s,k=open(0)
k=int(k)
*l,=map(ord,s[:-1])
for i,t in enumerate(l):
  j=(19-t)%26
  if j<=k:k-=j;l[i]=97
l[-1]+=k%26
print(*map(chr,l),sep='')

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

ans = ''
for _s in s[:-1]:
  if _s == 'a':
    ans += 'a'
  elif 26 - ord(_s) + ord('a') <= k:
    ans += 'a'
    k -= 26 - ord(_s) + ord('a')
  else:
    ans += _s

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

print(ans)

Solution (Python):

alpha='abcdefghijklmnopqrstuvwxyz'
S=input()
K=int(input())
ans=''
for s in S:
    idx=alpha.index(s)
    if idx==0 or 26-idx>K:
        ans+=s
        continue
    else:
        K-=26-idx
        ans+='a'
if K>0:
    tar=ans[-1]
    idx=alpha.index(tar)
    ans=ans[:-1]+alpha[(idx+K)%26]
print(ans)

Solution (Python):
s=input();x=[i-96for i in map(ord,s)];n=int(input())
for k,v in enumerate(x):
    y=(27-v)%26
    if y<=n:n-=y;x[k]=1
x[-1]+=n%26;print("".join(map(chr,[i+96for i in x])))

Solution (Python):
s=input()
x=[i-96for i in map(ord,s)]
n=int(input())
for i in range(len(s)):
    y=(26-x[i]+1)%26
    if y<=n:
        n-=y
        x[i]=1
x[-1]+=n%26
print("".join(map(chr,[i+96 for i in x])))

Solution (Python):
s = input()
x = []
for i in s:
    x.append(ord(i) - ord('a'))
K = int(input())
for i in range(len(x)):
    if x[i] == 0:
        continue
    d = 26 - x[i]
    if K >= d:
        x[i] = 0
        K -= d
x[-1] = (x[-1] + K) % 26
for i in x:
    print(chr(i + ord('a')), end = "")
print()

Solution (Python):
s = input()
x = []
for i in s:
    x.append(ord(i) - ord('a'))
K = int(input())
for i in range(len(x)):
    if x[i] == 0:
        continue
    d = 26 - x[i]
    if K >= d:
        x[i] = 0
        K -= d
x[-1] = (x[-1] + K) % 26
for i in x:
    print(chr(i + ord('a')), end = "")
print()

Solution (Python):
import sys

if __name__ == '__main__':
    ord_a = ord('a')
    s = [ord(c) - ord_a for c in input()]
    k = int(input())
    for x in s[:-1]:
        if 25 - x < k:
            sys.stdout.write('a')
            k -= (26 - x) % 26
        else:
            sys.stdout.write(chr(ord_a + x))
    print(chr((s[-1] + k) % 26 + ord_a))

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

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    S = input_raw[0]
    input_raw = read_func().strip().split()
    K = int(input_raw[0])
    newS =""
    for s in S:
        new_s = s
        if ord(s) - ord('a') > 0 and (K - ((ord('a') - ord(s)) % 26)) >= 0:
            new_s = "a"
            K -= ((ord('a') - ord(s)) % 26)
        newS += new_s
    new_end_char = newS[len(S) - 1]
    if K > 0:
        t = ord(newS[len(S) - 1]) + (K % 26)
        if t > ord('z'):
            t = t - ord('z') + ord('a')
        new_end_char = chr(t)
    print newS[:len(S) - 1] + new_end_char


if __name__ == '__main__':
    main()

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

for i in range(N - 1):
	if s[i] != "a":
		if K >= 123 - ord(s[i]):
			K -= 123 - ord(s[i])
			s[i] = "a"
			
s[-1] = chr((ord(s[-1]) - 97 + K) % 26 + 97)

print("".join(s))

Solution (Python):
s=input()
K=int(input())
ans=[]

for c in s:
  if c=="a":
    ans.append(c)
    continue
  if ord("z")+1- ord(c)<=K:
    K-=ord("z")+1-ord(c)
    ans.append("a")
    continue
    
  ans.append(c)
    
if K:
  ans[-1]=chr( (ord(ans[-1])+K%26 -ord("a"))%26+ord("a") )
print("".join(ans))

Solution (Python):
s=input()
k=int(input())
a=[]
for t in s[:-1]:
  c=123-ord(t)
  if k<c or t=='a':
    a.append(t)
  else:
    k-=c
    a.append('a')
a.append(chr((ord(s[-1])-97+k)%26+97))
print(''.join(a))

Solution (Python):
s=input()
k=int(input())
a=[]
for t in s[:-1]:
  c=123-ord(t)
  if k<c or t=='a':
    a.append(t)
  else:
    k-=c
    a.append('a')
a.append(chr((ord(s[-1])-97+k)%26+97))
print(''.join(a))

Solution (Python):

from string import ascii_lowercase

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

d = {}
d2 = {}
for i in range(len(ascii_lowercase)):
    c = ascii_lowercase[i]
    d[c] = (len(ascii_lowercase)-i)%len(ascii_lowercase)
    d2[c] = i

for i in range(n):
    if s[i]!="a" and d[s[i]]<=k:
        k -= d[s[i]]
        s[i] = "a"

if k>0:
    k %= len(ascii_lowercase)
    s[-1] = ascii_lowercase[(d2[s[-1]]+k)%len(ascii_lowercase)]

print("".join(s))

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

Solution (Python):
ord_a = ord('a')

ss = input()
K = int(input())

As = [ord(s) - ord_a for s in ss]

anss = []
for A in As[:-1]:
    num = 26 - A
    if A == 0 or K < num:
        anss.append(A)
    else:
        anss.append(0)
        K -= num

anss.append((As[-1] + K) % 26)

print(''.join([chr(ans + ord_a) for ans in anss]))

Solution (Python):
s = input()
k = int(input())
n = len(s)
mod = 26
alpha = "abcdefghijklmnopqrstuvwxyz"
aldic = {}
ansstr = ""
for i, al in enumerate(alpha, 1):
    aldic[al] = i

for i in range(n - 1):
    if k >= mod - aldic[s[i]] + 1 and s[i] != "a":
        ansstr += "a"
        k -= mod - aldic[s[i]] + 1
    else:
        ansstr += s[i]
ansstr += alpha[(aldic[s[n - 1]] + k - 1) % mod]
print(ansstr)

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


Costs = {chr(98 + i): (25 - i) for i in range(25)}
Costs['a'] = 0
alphabets = [chr(97 + i) for i in range(26)]


ans = ""
for i in range(len(S)):
    s = S[i]
    if K >= Costs[s]:
        K -= Costs[s]
        ans += 'a'
    else:
        ans += s


ans = ans[:-1] + alphabets[(alphabets.index(ans[-1]) + K) % 26]
print(ans)

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


Costs = {chr(98 + i): (25 - i) for i in range(25)}
Costs['a'] = 0
alphabets = [chr(97 + i) for i in range(26)]


ans = ""
for i in range(len(S) - 1):
    s = S[i]
    if K >= Costs[s]:
        K -= Costs[s]
        ans += 'a'
    else:
        ans += s


ans += alphabets[(alphabets.index(S[-1]) + K) % 26]
print(ans)

Solution (Python):
d1={'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}
d2=['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','a']
s=list(input())
k=int(input())
lens=len(s)
ans=''
ind=1
for i in s:
  if ind==lens:
    ans+=d2[(d2.index(i)+k)%26]
  elif k>=d1[i]:
    k-=d1[i]
    ans+='a'
  else:
    ans+=i
  ind+=1
print(ans)

Solution (Python):
s = input()
k = int(input())
ans = []
for i in range(len(s)):
  toa =(ord('z')-ord(s[i]))+1
  if s[i] =='a':ans += s[i]
  else:
   if toa <= k:
     k -= toa 
     ans += 'a'
   else: ans += s[i]

if k == 0:print("".join(ans))
else: 
  rest = k%26
  tmp = ord(ans[-1])+rest
  if tmp >122:
    tmp -= 26
  ans[-1] = chr(tmp)
  print("".join(ans))

Solution (Python):
a=ord('a')
alpha=['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())
a=ord('a')
N=len(s)
L=[0]*N
t=K
for i in range(N):
    L[i]=ord(s[i])-a
i=0
while i<N:
    
    if L[i]==0:
        i+=1
        continue
    if t>=26-L[i]:
        t=t-(26-L[i])
        L[i]=0
    i+=1
L[-1]=(L[-1]+t)%26
x=''
for i in range(N):
    x+=alpha[L[i]]
print(x)

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

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

abc = 'bcdefghijklmnopqrstuvwxyza'
abc_to_index = {abc[_]: _ for _ in range(26)}

ans = ''
for i in range(N):
    if 25 - abc_to_index[s[i]] > K or i == N - 1:
        ans += s[i]
    else:
        ans += 'a'
        K -= 25 - abc_to_index[s[i]]
ans = ans[:-1] + abc[(abc_to_index[ans[-1]] + K) % 26]
print(ans)

Solution (Python):
S=[ord(i)-97 for i in list(input())]
K=int(input())
N=len(S)
T=[chr(S[i]+97) for i in range(N)]
for i in range(N):
    if K>=(26-S[i]):
        K-=(26-S[i])%26
        T[i]='a'
        S[i]=0
    else:
        continue
S[-1]=(S[-1]+K)%26
T[-1]=chr(S[-1]+97)
ans=""
for i in range(N):
    ans=ans+T[i]
print(ans)

Solution (Python):
A=["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"]
Num=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]

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

S=[]
for i in range(len(s)):
    for j in range(26):
        if s[i]==A[j]:
            S.append(Num[j])

for a in range(len(S)-1):
    if (26-S[a])%26<=K:
        K-=(26-S[a])%26
        S[a]=(S[a]+(26-S[a]))%26

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


for x in range(len(S)):
    for y in range(26):
        if S[x]==Num[y]:
            S[x]=A[y]
print("".join(S))

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

Solution (Python):
s=input()
N=len(s)
K=int(input())
a="abcdefghijklmnopqrstuvwxyz"
S=[]
A=list(a)
for i in range(N-1):
  if s[i]!="a":
    k=A.index(s[i])
    if K>=26-k:
      S.append("a")
      K-=26-k
    else:
      S.append(s[i])
  else:
    S.append("a")
if K>=0:
  k=A.index(s[N-1])
  S.append(A[(k+K)%26])
print("".join(S))

Solution (Python):
s = list(input())
K = int(input())
AB = ["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 = len(s)
Ans = ""
for i in range(L-1):
    if s[i] == "a": Ans += "a"
    else:
        move = 26 - AB.index(s[i])
        if move <= K:
            Ans += "a"
            K -= move
        else: Ans += s[i]

if s[L-1] == "a": Ans += AB[K%26]
else:
    move = 26 - AB.index(s[L-1])
    if move <= K:
        K -= move
        Ans += AB[K%26]
    else:
        Ans += AB[AB.index(s[L-1]) + K]
print(Ans)

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

for i in range(len(s)):
    if i!=len(s)-1:
        if S[i]!=97 and 123-S[i]<=K:
            K-=123-S[i]
            S[i]=97
    if i==len(s)-1:
        S[i]+=K%26
        if S[i]>=123:
            S[i]=S[i]-123+97
T=""
for i in range(len(s)):
    T+=chr(S[i])
print(T)

Solution (Python):
s = input()
K = int(input())
ans = ''
alphas = {'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}
a = 'abcdefghijklmnopqrstuvwxyz'
dict1 = {}
dict2 = {}
i = 1
while i <= 26:
  dict1[i%26] = a[i-1]
  dict2[a[i-1]] = i
  i += 1
for chara in s:
  if alphas[chara] <= K:
    ans = ans + 'a'
    K = K - alphas[chara]
  else:
    ans = ans + chara
K = K%26
if len(ans)>=2:
  ans = ans[:-1]+dict1[(dict2[ans[-1]]+K)%26]
else:
  ans = dict1[(dict2[ans]+K)%26]
print(ans)

Solution (Python):
s=list(input())
k=int(input())
al=list('abcdefghijklmnopqrstuvwxyz')
n=0
while k>0:
    if n==len(s)-1:k=k%26
    if 26-al.index(s[n])<=k and s[n]!='a':
        k-=26-al.index(s[n])
        s[n]='a'
        n=min(len(s)-1,n+1)
    else:
        if n<len(s)-1:n+=1
        else:
            s[n]=al[al.index(s[n])+k]
            k=0
print(''.join(s))

Solution (Python):
s=input()
k=int(input())
f=lambda x:(123-ord(x))%26 
g=lambda x:chr((ord(x)-97+k)%26+97)

b=[]
for i in s:
  cost=f(i)
  if cost<=k:
    b.append("a")
    k-=cost
  else:
    b.append(i)
if k:b[-1]=g(b[-1])
print("".join(b))

Solution (Python):
s=input()
k=int(input())
f=lambda x:(123-ord(x))%26 
g=lambda x:chr((ord(x)-97+k)%26+97)

b=[]
for i in s:
  cost=f(i)
  if cost<=k:
    b.append("a")
    k-=cost
  else:
    b.append(i)
if k:b[-1]=g(b[-1])
print("".join(b))

Solution (Python):
S=[ord(i)-97 for i in list(input())]
K=int(input())
N=len(S)
T=[chr(S[i]+97) for i in range(N)]
for i in range(N):
    if K>=(26-S[i]):
        K-=(26-S[i])%26
        T[i]='a'
        S[i]=0
    else:
        continue
S[-1]=(S[-1]+K)%26
T[-1]=chr(S[-1]+97)
ans=""
for i in range(N):
    ans=ans+T[i]
print(ans)

Solution (Python):

from sys import stdin

s_in = lambda: stdin.readline()[:-1] 
d_in = lambda: int(stdin.readline()) 
ds_in = lambda: list(map(int, stdin.readline().split())) 

alp = 26
s_list = list(s_in())
K = d_in()
alp0 = ord('a') - 1

for i in range(len(s_list)):
	num = ord(s_list[i]) - alp0
	if K >= (alp - num + 1) % alp:
		s_list[i] = 'a'
		K -= (alp - num + 1) % alp
		
s_list[-1] = chr(alp0 + 1 + (ord(s_list[-1]) - alp0 + K - 1) % alp)

print(''.join(s_list))

Solution (Python):
def c_next_letter(S, K):
    s = list(S)
    for t, elem in enumerate(s):
        if t == len(s) - 1 and K > 0:
            
            s[t] = chr(ord('a') + (ord(elem) - ord('a') + K) % 26)
        elif elem == 'a':
            continue  
        elif ord('z') - ord(elem) + 1 <= K:
            
            s[t] = 'a'
            K -= ord('z') - ord(elem) + 1
    ans = ''.join(s)
    return ans

S = input()
K = int(input())
print(c_next_letter(S, K))

Solution (Python):
alp = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
       "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
s = list(input())
k = int(input())
a = 0
while k > 0:
    for i in range(26):
        if alp[i] == s[a]:
            t = i
            break
    if a == len(s) - 1:
        s[a] = alp[(t + k) % 26]
        break
    elif s[a] == "a":
        a = a
    elif 26 - t <= k:
        s[a] = "a"
        k -= 26 - t
    a += 1
print("".join(s))

Solution (Python):
from string import ascii_lowercase as al
cost = dict(zip(al, [0] + list(range(25, 0, -1))))

s = input()
K = int(input())
ans = ''
for si in s:
    if K - cost[si] >= 0:
        K -= cost[si]
        ans += 'a'
    else:
        ans += si
print(ans[:-1] + (al * 2)[al.index(ans[-1]) + K % 26])

Solution (Python):
import string
alph = string.ascii_lowercase * 2
s = input()
k = int(input())

needed = 0
ind_list = []
for i in range(len(s)):
	ind_list.append(alph.index(s[i]))
	if ind_list[-1] != 0:
		needed += 26 - ind_list[-1]

if needed <= k:
	mod = (k - needed) % 26
	print("a" * (len(s) - 1) + alph[mod])
else:
	ans = []
	for i in range(len(s) - 1):
		if k == 0 or s[i] == "a":
			ans.append(s[i])
			continue
		if k >= 26 - ind_list[i]:
			ans.append("a")
			k -= 26 - ind_list[i]
		else:
			ans.append(s[i])

	if k == 0:
		ans.append(s[-1])
	else:
		ans.append(alph[(ind_list[-1] + k) % 26])

	print(*ans, sep="")

Solution (Python):

import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())


s = ns()
k = ni()

chl = list(s)
res = k

for i, c in enumerate(chl):
    if c == "a":
        continue
    
    elif res >= ord("z") - ord(c) + 1:
        chl[i] = "a"
        res -= (ord("z") - ord(c) + 1)

chl[-1] = chr(ord(chl[-1]) + res%26)

print("".join(chl))

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
K = int(input())
ans = ''

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

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

print(ans)

Solution (Python):
s = list(input())
k = int(input())
n = len(s)
do = 0
while do<=n-1:
    rest = (97-ord(s[do]))%26
    if rest<=k:
        k -= rest
        s[do] = 'a'
        do+=1
    else:
        do+=1


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

print(''.join(s))