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()
    k = int(input())

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

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

    print("".join(ans))


if __name__ == '__main__':
    main()

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

for i, s in enumerate(S):
    if ord('z') - ord(s) + 1 <= k:
        S[i] = 'a'
        k -= (ord('z') - ord(s) + 1) % 26

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

print(str().join(S))

Solution (Python):
S = input()
K = int(input())
cost = [(ord("z") - ord(s) + 1) % 26 for s in S]
A = [chr(ord("a") + i) for i in range(26)]

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

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

Solution (Python):

aord = ord("a")
s = list(raw_input())
k = int(input())
i = 0

while k > 0 and i < len(s):
	if k >= ord('z') - ord(s[i]) + 1:
		if s[i] != "a":
			k -= ord('z') - ord(s[i]) + 1
			s[i] = "a"

	i += 1
k = k%26
s[len(s)-1] = chr(ord(s[len(s)-1]) + k)
print ''.join(s)

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

sArr = list(s)
endpoint = len(sArr) - 1
result = ""

for i in range(len(sArr)):
    if K == 0:
        break
    else:
        if (123 - ord(sArr[i])) <= K:
            K -= (123 - ord(sArr[i])) % 26
            sArr[i] = "a"

if K > 0:
    K %= 26
    sArr[endpoint] = chr(ord(sArr[endpoint]) + K)

for j in range(len(sArr)):
    result += sArr[j]

print(result)

Solution (Python):

import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


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


def code(s):
    return ord(s)-97

def char(c):
    c = c % 26
    return chr(c+97)



ans_list = []
for p in range(n):
    c = code(s[p])
    if c == 0:
        
        ans_list.append("a")
        continue
    if 26-c > K:
        
        ans_list.append(s[p])
        continue
    
    ans_list.append("a")
    K -= 26-c
ans = "".join(ans_list)
ans = ans[:-1] + char(code(ans[-1])+K)

print(ans)

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

Solution (Python):
s = input()
k = int(input())
num,ans = 0,[]
while num!=len(s):
	if s[num]=="a": ans.append("a")
	elif 123-ord(s[num])<=k:
		k -= 123-ord(s[num])
		ans.append("a")
	else: ans.append(s[num])
	num += 1
ans[-1] = chr(ord(ans[-1])+k%26)
print("".join(ans))

Solution (Python):

s=list(map(lambda c:ord(c)-ord('a'),input()))
k=int(input())
for i in range(len(s)):
    if 26-s[i]<=k and s[i]!=0:
        k-=(26-s[i])
        s[i]=0
s[-1]=(s[-1]+k)%26
for n in s:
    print(chr(ord('a')+n),end='')
print()

Solution (Python):
def main():
    s = input()
    n = int(input())
    
    t = []
    a = []
    for i in s:
        ord_i = ord(i)
        t.append(((123 - ord_i)%26, ord_i))
    
    for i in t:
        if n >= i[0]:
            a.append('a')
            n -= i[0]
        else:
            a.append(chr(i[1]))
            
    a[-1] = chr(ord(a[-1]) + n%26)
    print(''.join(a))
    
if __name__ == '__main__':
    main()

Solution (Python):
s = list(input())
n = int(input())
ret = ""
for i, ss in enumerate(s):
    a = 123 - ord(ss)
    if a == 26:
        a = 0
    if i == len(s) - 1:
        c = ord(ss) + (n % 26)
        if c > 122:
            c -= 26
        ret += chr(c)
        break
    if n < a:
        ret += ss
    else:
        n -= a
        ret += 'a'

print(ret)

Solution (Python):

s = list(input())
k = int(input())
for tmp in range(len(s)):
    if k == 0:
        break
    a = 26-(ord(s[tmp]) - ord('a'))
    if s[tmp] != 'a' and k >= a: 
        k -= a
        s[tmp] = 'a'
    else:
        pass
if k > 0:
    s[len(s)-1] = chr((ord(s[len(s)-1])+k%26))
print(''.join(s))

Solution (Python):
S = input()
K = int(input())
ans = ""
for i in range(len(S)):
    if(S[i] != 'a' and K >= (ord('a') - ord(S[i]))%26):
        ans += 'a'
        K -= (ord('a') - ord(S[i]))%26
    else:
        ans += S[i]

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

Solution (Python):
def up(c, i):
    i %= 26
    b = ord('z')-ord(c)+1
    if i >= b:
        i -= b
        c = 'a'
    c = chr(ord(c)+i)
    return c



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

a = ord('a')
ans = ''

for i in range(len(s)):
    b = ord('z')-ord(s[i])+1
    if i == len(s)-1:
        ans += up(s[i], K)
    elif b == 26:
        ans += 'a'
    elif K >= b:
        K -= b
        ans += 'a'
    else:
        ans += s[i]

print(ans)

Solution (Python):
s = list(raw_input())
K = int(raw_input())
for i in xrange(len(s)):
  if s[i] == 'a': continue
  d = ord('z') - ord(s[i]) + 1
  if K >= d:
    s[i] = 'a'
    K -= d
    
K %= 26
s[-1] = chr((ord(s[-1]) - ord('a') + K)%26 + ord('a'))
  
print "".join(s)

Solution (Python):
dict_alp = dict([(chr(i), i - 97) for i in range(97, 97+26)])
alp = [chr(i) for i in range(97, 97+26)]

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

i = 0
while k > 0:
    if i == l - 1:
        k %= 26
        s[i] = alp[(dict_alp[s[i]] + k) % 26]
        break

    if s[i] == alp[0]:
        i += 1
        continue

    if k < 26 - dict_alp[s[i]]:
        i += 1
        continue

    k -= (26 - dict_alp[s[i]])
    s[i] = alp[0]

    i += 1

print("".join(s))

Solution (Python):
S = input()
k = int(input())
goal = ord('z') + 1
ans = []
for c in S:
    if c == 'a':
        ans.append('a')
        continue
    d = goal - ord(c)
    if k >= d:
        k -= d
        ans.append('a')
    else:
        ans.append(c)
last = (k + ord(ans[-1]) - ord('a')) % 26
ans[-1] = chr(ord('a') + last)
print(''.join(ans))

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

for i, c in enumerate(s):
	if K <= 0:
		break
	diff = (123 - ord(c)) % 26
	if diff <= K:
		s[i] = 'a'
		K -= diff
s[-1] = chr(97 + (ord(s[-1]) - 97 + K) % 26)
print(''.join(s))

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

alphabet = "abcdefghijklmnopqrstuvwxyz"

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

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

alphabet = "abcdefghijklmnopqrstuvwxyz"

for i in range(len(s)):
    if (26 - alphabet.index(s[i])) <= K and (s[i] != "a"):
        K -= (26 - alphabet.index(s[i]))
        s[i] = "a"
        
    if K <= 0:
        break
        
if K > 0:
    K = K % 26
  
    idx = alphabet.index(s[-1])+K
    s[-1] = alphabet[idx%26]
    
print("".join(s))

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

alphabet = ['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']

for i in range(len(s)):
    if K <=0 :
        break
    if (26 - alphabet.index(s[i])) <= K and s[i] != "a":
        
        K -= (26 - alphabet.index(s[i]))
        s[i] = "a"


if K > 0:
    if K%26 + alphabet.index(s[-1]) > 25:
        s[-1] = alphabet[(K%26 - alphabet.index(s[-1]))]
    else:
        s[-1] = alphabet[(K%26+alphabet.index(s[-1]))]
print("".join(s))

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

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

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

Solution (Python):
w="bcdefghijklmnopqrstuvwxyza"
d={}
for i in xrange(len(w)):
    d[w[i]]=25-i
ss=raw_input()
s=[]
for i in xrange(len(ss)):
    s.append(ss[i])
K=int(raw_input())
for i in xrange(len(s)):
    if d[s[i]]<=K:
        K -= d[s[i]]
        s[i]="a"
K%=26
s[len(s)-1]=w[(25-d[s[len(s)-1]]+K)%26]
print "".join(s)

Solution (Python):
import string

s = list(input())
k = int(input())
d = {c:(26-i)%26 for i, c in enumerate(string.ascii_lowercase)}
d_inv = {(26-i)%26:c for i, c in enumerate(string.ascii_lowercase)}

for i in range(len(s)):
    if k > 0:
        if d[s[i]] <= k:
            k -= d[s[i]]
            s[i] = "a"
    else:
        break
s[-1] = d_inv[(d[s[-1]]-k)%26]

print("".join(s))

Solution (Python):



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

num_s=[]

for moji in s:
    num_s.append(ord(moji)-ord('a'))


ans=''
for idx in range(0,len(num_s)-1,1):
    if num_s[idx]==0:
        ans=ans+'a'
    elif K >= (26 - num_s[idx]):
        K=K-(26 - num_s[idx])
        ans=ans+'a'
    else:
        
        ans=ans+s[idx]


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

print(ans)

Solution (Python):
s=raw_input()
K=int(raw_input())
ozp1=123



ls=list(s)
for i in range(len(ls)):
    nowwork=ozp1-ord(ls[i])
    if i==len(ls)-1:
        K%=26
        
        ls[i]=chr(ord(ls[i])+K)
        if ord(ls[i])>ord("z"):
            zu=ord(ls[i])-ord("z")-1
            
            ls[i]=chr(ord("a")+zu)
    if K==0:
        break

    if ls[i]=="a":
        continue
    if nowwork<=K and (len(ls)-1!=i):
        K-=nowwork
        ls[i]="a"

print "".join(ls)

Solution (Python):
s=raw_input()
K=int(raw_input())
ozp1=123



ls=list(s)
for i in range(len(ls)):
    nowwork=ozp1-ord(ls[i])
    if i==len(ls)-1:
        K%=26
        
        ls[i]=chr(ord(ls[i])+K)
        if ord(ls[i])>ord("z"):
            zu=ord(ls[i])-ord("z")-1
            
            ls[i]=chr(ord("a")+zu)
    if K==0:
        break

    if ls[i]=="a":
        continue
    if nowwork<=K and (len(ls)-1!=i):
        K-=nowwork
        ls[i]="a"

print "".join(ls)

Solution (Python):
jisho = ["z","y","x","w","v","u","t","s","r","q","p","o","n","m","l","k","j","i","h","g","f","e","d","c","b","a"]

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

for elem in s:
    if elem == "a":
        res += "a"
    elif jisho.index(elem)+1 <= k:
        res += "a"
        k -= jisho.index(elem)+1
    else:
        res += elem

res = res[0:n-1] + jisho[jisho.index(res[n-1])-k%26]
print(res)

Solution (Python):
s = bytearray(raw_input())
N = int(raw_input())
dis = [ord('z')-c for c in s]

for idx, d in enumerate(dis[:-1]):
    if d!=25 and d+1 <= N:
        s[idx] = 'a'
        N -= (d+1)

if N > 0:
    N %= 26
    t = (dis[-1]-N) % 26
    s[-1] = chr(ord('z') - t)
print s

Solution (Python):




"""









"""
import sys

def input_single_line():
    """Receive Inputs."""
    return input()

def input_two_line():
    """Receive Two Lined Inputs.
    Like this.

    N
    1 2 3 4 5
    """
    n = sys.stdin.readline()
    n = n.rstrip("\n")
    target = sys.stdin.readline()
    target = target.rstrip("\n")
    

    return n, target


def check_a_becombility(one_str: str) -> int:
    """Check how can this str become "a"
    >>> check_a_becombility("a")
    0
    >>> check_a_becombility("z")
    1
    >>> check_a_becombility("b")
    25
    """
    if ord(one_str) == 97:
        return 0  

    return 123 - ord(one_str)


def make_suzuki_process(target_str :str, chance: int) -> str:
    """Suzuki Process.
    >>> make_suzuki_process("xyz", 4)
    'aya'
    >>> make_suzuki_process("a", 25)
    'z'
    >>> make_suzuki_process("codefestival", 100)
    'aaaafeaaivap'
    >>> make_suzuki_process("aaaa", 1000)
    'aaam'
    >>> make_suzuki_process("a", 26)
    'a'
    """
    target_str = list(target_str)
    costs = [check_a_becombility(i) for i in target_str]

    for pos, each_cost in enumerate(costs):
        if chance - each_cost >= 0:
            chance = chance - each_cost
            target_str[pos] = "a"

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

    return "".join(target_str)

if __name__ == "__main__":
    import doctest
    doctest.testmod()

    inputted = input_two_line()

    print(make_suzuki_process(inputted[0], int(inputted[1])))

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

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

asca = 97
ascz = 122
start = 0
lens = len(s)

loop = lambda x: asca if x == ascz else x+1

for k in range(K):
    if start == lens - 1:
        for i in range((K-k) % (ascz - asca + 1)):
            s[start] = loop(s[start])
        break
    for i in range(start, lens):
        c = s[i]
        if i == lens - 1:
            s[i] = loop(c)
            break
        if c == asca:
            start += 1
            continue
        v = c + (K-k)
        if v > ascz:
            s[i] = loop(c)
            break
        else:
            continue
print(''.join(map(chr, s)))

Solution (Python):
import string
import sys
s = input()
k = int(input())
a = [ord(_) for _ in s]
for i in range(len(s)-1):
    if a[i] != ord('a'):
        df = ord('z') - a[i] + 1
        if k >= df:
            a[i] = ord('a')
            k -= df
    if k == 0: break
if k != 0:
    k = k % 26
    a[len(a)-1] += k - 26 if ord('z') < k + a[len(a)-1] else k
[print(chr(_), end="") for _ in a]
print("")

Solution (Python):
s = map(lambda i: (ord('z') - ord(i) + 1) % 26, raw_input())
n = len(s)
k = int(raw_input())

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

s[-1] -= k

s = map(lambda i: (26 - i) % 26 + ord('a'), s)
s = ''.join(map(chr, s))

print s

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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


def f():
    s = input()
    k = int(input())
    a = [ord(_) - ord('a') for _ in s]
    l = len(s)
    for i in range(l):
        if k < 1:
            break
        c = a[i]
        if c == 0:
            continue
        d = 26 - c
        if k >= d:
            a[i] = 0
            k -= d
    a[-1] = (a[-1] + k) % 26
    return ''.join([chr(_ + ord('a')) for _ in a])

print(f())

Solution (Python):
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')


def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())


def join(s):
    return ''.join(s)


def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)


def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m


def index(a, x):
    
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1


def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

nh=zip([1,0,-1,0],[0,1,0,-1])



st=slist()
k=i()

for j in range(len(st)):
    o=ord(st[j])
    if k >= 123-o and st[j]!='a':
        k -= (123-o)
        st[j]='a'
        
n=97+(ord(st[len(st)-1])-97+k)%26

st[len(st)-1] = chr(n)
print join(st)

Solution (Python):
s=input()
k=int(input())
d = dict()
alphabet = "abcdefghijklmnopqrstuvwxyz"
for i in range(len(alphabet)):
    d[alphabet[i]]=i
    
def f(s,k):
    s = [s[i] for i in range(len(s))]
    res = s
    L = 0
    for i in range(len(s)):
        l = max((26 - d[s[i]]) % 26, 0)
        if i==len(s)-1:
            res[i] = alphabet[(d[s[i]] + (k-L)) % 26]
        else:
            if L + l <= k:
                res[i] = "a"
                L += l
            else:
                continue
    return(''.join(res))
print(f(s,k))

Solution (Python):
y=list(raw_input())
k=int(raw_input())
for i in range(len(y)):
	if y[i]=='a':
		continue
	else:
		if 123-ord(y[i])<=k:
			k-=(123-ord(y[i]))
			y[i]='a'
y[len(y)-1]=chr(ord(y[len(y)-1])+k%26)
print ''.join(y)

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


s_l = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

def s_i(st):
    for i in range(26):
        if st == s_l[i]:
            return i + 1
            break

j = 0
while k > 0 and j <= len(s)-1:
    a = s_i(s[j])
    if s[j] == 'a' and j < len(s)-1:
        pass
    elif 27 - a <= k and j < len(s)-1:
        k = k - (27 - a)
        s = s[:j] + 'a' + s[j+1:]
    elif j == len(s) - 1:
        t = (a+k)%26 - 1
        if t >= 0:
            s = s[:j] + s_l[t]
        else:
            s = s[:j] + s_l[t + 26]
        break
    else:
        pass
    j += 1

print s

Solution (Python):
import sys
S = str(input())
K = int(input())

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

    if ord('z') - arr[i] + 1 <= count and arr[i] != ord('a'):
        arr[i] = ord('a')
        count -= ord('z') - ord(S[i]) + 1

    if count == 0:
        break

for c in arr:
    sys.stdout.write(chr(c))

print('')

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

a = "abcdefghijklmnopqrstuvwxyz"

zi = a.index("z") 
si = [zi - a.index(c) + 1 if c != "a" else 0  for c in s]

for i, (c, ci) in enumerate(zip(s, si)):
    if K == 0:
        break
    if c == "a":
        continue
    if ci <= K:
        s[i] = 'a'
        K = K - ci

K = K % len(a)
if K > 0:
    s[-1] = a[a.index(s[-1]) + K]

print("".join(s))

Solution (Python):

def main():                                                                                                               
  
  s = raw_input()
  K = int(raw_input())
  ch = [123-ord(c) for c in s]
  for i in range(len(s)):
    if ch[i] == 26 and i != len(s)-1:
      continue
    elif ch[i] < K:
      K = K - ch[i]
      ch[i] = 26
    elif ch[i] == K:
      K = K - ch[i]
      ch[i] = 26
      break
    elif ch[i] > K and i != len(s)-1:
      continue
    else:
      tmp = ch[i]
      ch[i] = ch[i] - K
      K = K - tmp
      if ch[i] <= 0:
        ch[i] == 26
  if K > 0:
    ch[len(s)-1] = ch[len(s)-1] - K%26
  
  ch = [str(unichr((27-c)+96)) for c in ch]
  print ''.join(ch)
main()

Solution (Python):

str = input()
K = int(input())
tempK = K
result = ""
for i in range(len(str)-1):
	changeNum = 122-ord(str[i])+1
	if (changeNum <= tempK and str[i] != "a"):
		result += "a"
		tempK -= changeNum
	else:
		result += str[i]
tempK %= 26
if (tempK > 0):
	changeNum = ord(str[-1]) + tempK
	if (changeNum > 122):
		changeNum = changeNum -122 + 97 -1
	else:
		changeNum = changeNum
	result += chr(changeNum)
else:
	result += str[-1]
print(result)

Solution (Python):
import sys 

s = sys.stdin.readline().strip()
K = int(sys.stdin.readline())
c = []
for i in s:
        c.append(ord(i)-ord('a'))

i =0
while i< len(c):
        path2a = (26-c[i] ) % 26
        if path2a <= K:                                                                                                                                                                                                               
                K -= path2a
                c[i] = 0 
        i+=1
c[-1] = (c[-1]+ K) %26 

res = ""
for i in c:
        res += chr(i+ord('a'))

sys.stdout.write( res)

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

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

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

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

    diff = ord("z") - ord(s[i]) + 1

    if diff <= k:
        k -= diff
        s[i] = "a"

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

print("".join(s))

Solution (Python):








s = input()
K = int(input())
l = len(s)
ans = ['a']*l

ORDa = 97

for i in range(l):
	now = ord(s[i]) - ORDa
	tmp = 26 - now
	
	if K == 0:
		ans[i] = s[i]
	elif tmp == 26:
		ans[i] = s[i]
	elif tmp <= K:
		ans[i] = 'a'
		K -= tmp
	else:
		ans[i] = s[i]

if K > 0:
	K = K % 26
	tmp = ord(ans[-1])
	if tmp + K > ord('z'):
		aa = tmp + K - (ord('z') + 1)
		ans[-1] = chr(aa + ORDa)
	else:
		ans[-1] = chr(tmp + K)
		
print("".join(ans))

Solution (Python):

s = map((lambda x: ord(x) - 96), raw_input())
k = int(raw_input())


for i in range(len(s)):
  sv = s[i]
  if sv == 1 or (27 - sv) > k:
    continue
  s[i] = 1
  k = k - (27 - sv)

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

print "".join(map((lambda x: chr(x + 96)), s))

Solution (Python):
def r_shift(c, i):
    return chr(ord('a') + int(((ord(c) + i) - ord('a'))) % 26)
s = input()
K = int(input())
r = ''
for c in s[:-1]:
    dis = 26 - (ord(c) - ord('a'))
    if dis <= K and c != 'a':
        K -= dis
        r += 'a'
    else:
        r += c
if K > 0:
    r += r_shift(s[-1], K)
else:
    r += s[-1]
print(r)

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

new_s = ""
















for i in range(len(s)):
    c = s[i]
    cost = 123 - ord(c)
    if i == len(s) - 1:
        if cost <= K:
            new_s += chr(97 + (K - cost) % 26)
        else:
            new_s += chr(ord(c) + K)
    elif c == 'a':
        new_s += 'a'
    elif cost <= K:
        new_s += "a"
        K -= cost
    else:
        new_s += c

print(new_s)

Solution (Python):
def f(s,K):
 if K==0:
  return s,"",0
 res=0
 str=""
 for i in range(len(s)-1):
  if s[i]=="a":
   str+="a"
   res+=1
   continue
  if K>=123-ord(s[i]):
   str+="a"
   res+=1
   K-=123-ord(s[i])
  else:
   break
 if res==0:
  skip=0
  for skip in range(len(s)):
   if K>=123-ord(s[skip]):
    break
  return s[:skip],s[skip:],K
 return str,s[res:],K

ss=input()
KK=int(input())
sol=""
while len(ss)>1:
 x,ss,KK=f(ss,KK)
 sol+=x
if len(ss)==1:
 KK%=26
 if ord(ss[0])+KK<123:
  sol+=chr(ord(ss[0])+KK)
 else:
  sol+=chr(ord(ss[0])+KK-26)
print(sol)

Solution (Python):
def num_to_char(s_num):
    ch = []
    for num in s_num:
        ch.append(alphabet[(num%26)-1])
    return ch

s = raw_input()
K = input()

alphabet = ['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']
ans = []

s_num = []
for char in s:
    s_num.append(alphabet.index(char) + 1)

for i in xrange(len(s_num)):
    if 27 - s_num[i] <= K and (s_num[i] != 1) and (i != len(s_num) - 1):
        K = K - (27 - s_num[i])
        s_num[i] = 27
    elif (i == len(s_num) - 1):
        s_num[i] = s_num[i] + K
    else:
        pass
print "".join(num_to_char(s_num))

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

for i in range(len(s)):
    if s[i] == "a":
        pass
    elif 123 - ord(s[i]) <= K:
        K -= (123 - ord(s[i]))
        s[i] = 'a'

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

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

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

i = 0
while K>=26 and i<len(s)-1:
	if alpha.index(s[i]) != 0:
		K = K - (26 - alpha.index(s[i]))
		s = s[:i] + 'a' + s[i+1:]
	i=i+1

for moji in range(i, len(s)):
	if alpha.index(s[moji]) != 0:
		if K >= 26-alpha.index(s[moji]):
			K = K - (26-alpha.index(s[moji]))
			s = s[:moji] + 'a' + s[moji+1:] 

if K>0:
	last_char = alpha[ alpha.index(s[-1]) + (K % 26) ]
	s = s[:-1] + last_char

print s

Solution (Python):
s = raw_input()
k = input()
i = 0
while True:
    if i == len(s)-1:
        
        t = ord(s[i])+k
        if t > ord("z"):
            t -= ord("a")
            t %= (ord("z")-ord("a") + 1)
            t += ord("a")
        s = s[:i] + chr(t)
        print s
        exit()
        
    elif s[i] != "a" and ord(s[i]) + k > ord("z"):
        
        k = k - ord("z") + ord(s[i]) -1
        s = s[:i] + "a" + s[i+1:]        
        
    i += 1

Solution (Python):
ring = raw_input()
num = input()

str = []
for i in range(len(ring)):
  str.append(ring[i])

for i in range(len(str)):
  if num-1 >= ord("z")-ord(str[i]) and str[i] != "a":
    num =  num - (ord("z")-ord(str[i])+1)
    str[i] = "a"

num = num % 26
while(num > 0):
  if str[-1] == "z":
    num -= 1
    str[-1] = "a"
    continue
  str[-1] = chr(ord(str[-1])+1)
  num -= 1

ans = ""
for i in str:
  ans += i
print ans

Solution (Python):
s = raw_input()
K = int(raw_input())
_s, _K = s[:], K
a = "abcdefghijklmnopqrstuvwxyz"
ai = a.index("a")
zi = a.index("z") 
si = [zi - a.index(c) + 1 if c != "a" else 0  for c in s]

for i, (c, ci) in enumerate(zip(s, si)):
    if K == 0:
        break
    if c == "a":
        continue
    if ci <= K:
        s = s[0:i] + "a" + s[i+1:]
        K = K - ci

K = K % len(a)
if K > 0:
    s = s[:-1] + a[a.index(s[-1]) + K]

print(s)

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

for i in xrange(len(s)):
    if s[i]=='a':
        continue
    if ord(s[i])+K < 123:
        continue
    else:
        K-=(123-ord(s[i]))
        s[i]='a'
if K>0:
    asc=ord(s[-1])+K%26
    s[-1]=chr(asc)
print "".join(s)

Solution (Python):
def num_to_char(s_num):
    ch = []
    for num in s_num:
        ch.append(alphabet[(num%26)-1])
    return ch

s = raw_input()
K = input()

alphabet = ['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']
ans = []

s_num = []
for char in s:
    s_num.append(alphabet.index(char) + 1)

for i in xrange(len(s_num)):
    if 27 - s_num[i] <= K and (s_num[i] != 1) and (i != len(s_num) - 1):
        K = K - (27 - s_num[i])
        s_num[i] = 27
    elif 27 - s_num[i] <= K and (s_num[i] == 1) and (i != len(s_num) - 1):
        pass
    elif 27 - s_num[i] > K and (s_num[i] != 1) and (i != len(s_num)-1):
        pass
    elif 27 - s_num[i] > K and (s_num[i] == 1) and (i != len(s_num) - 1):
        pass

    elif (i == len(s_num) - 1):
        s_num[i] = s_num[i] + K

print "".join(num_to_char(s_num))

Solution (Python):
s = list(raw_input())
K = input()
for i in xrange(len(s)):
    if 123-ord(s[i]) <= K and s[i] != 'a':
        K-=123-ord(s[i])
        s[i] = 'a'
if K > 0:
    s[-1] = chr((ord(s[-1])%97+K%26)%26+97)
print ''.join(s)

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

for i in range(len(s)):
    tmp = ord(s[i]) 
    
    if 1 <= 123 - tmp <= K and tmp != 97:
        
        s[i] = "a"
        K -= (123 - tmp)

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

def print_all(s):
    for t in s:
        print(t, end="")
    print()


print_all(s)

Solution (Python):
moji = {a: b for a, b in zip("abcdefghijklmnopqrstuvwxyz", range(26))}

s = list(raw_input())
k = int(raw_input())

for i, e in enumerate(s):
    if e != "a":
        if 26 - moji[e] <= k:
            s[i] = "a"
            k -= 26 - moji[e]

k = k % 26 if k >= 0 else 0
if k != 0:
    s[-1] = "abcdefghijklmnopqrstuvwxyz"[(moji[s[-1]] + k) if moji[s[-1]]+k < 26 else moji[s[-1]] + k - 25]

print "".join(s)

Solution (Python):
def f(s,i,m):
    m = m%26
    if ord(s[i])+m <= 122:
        s[i] = chr(ord(s[i])+m)
    else:
        t = ord(s[i])+m-122
        s[i] = chr(96+t)
    return s

def judge(c,n):
    if ord(c)+n > 122:
        return (123 - ord(c))%26
    else:
        return 0
        
s = list(input())
n = int(input())
l = len(s)

for i in range(0,l):
    if i == l-1:
        s = f(s,i,n)
    else:
        d = judge(s[i],n)
        s = f(s,i,d)
        n = n - d

print(''.join(s))

Solution (Python):
def f(s,i,m):
    m = m%26
    if ord(s[i])+m <= 122:
        s[i] = chr(ord(s[i])+m)
    else:
        t = ord(s[i])+m-122
        s[i] = chr(96+t)
    return s

def judge(c,n):
    if ord(c)+n > 122:
        return (123 - ord(c))%26
    else:
        return 0
        
s = list(input())
n = int(input())
l = len(s)

for i in range(0,l):
    if i == l-1:
        s = f(s,i,n)
    else:
        d = judge(s[i],n)
        s = f(s,i,d)
        n = n - d

print(''.join(s))

Solution (Python):
def cost_for_next_a(c):
    return 123 - ord(c)

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

new_s = ""


for i in range(len(s)):
    c = s[i]
    if i == len(s) - 1:
        if cost_for_next_a(c) <= K:
            new_s += chr(97 + (K - cost_for_next_a(c)) % 26)
        else:
            new_s += chr(ord(c) + K)
    elif c == 'a':
        new_s += 'a'
    elif cost_for_next_a(c) <= K:
        new_s += "a"
        K -= cost_for_next_a(c)
    else:
        new_s += c

print(new_s)

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

def toA(char):
    return (ord('z')-ord(char)+1)%26

def toC(char,k):
    if(ord('z')-ord(char)>=k%26):
        return chr(ord(char)+k%26)
    else:
        return chr(ord('a')+k-ord('z')-ord(char))
for i in range(len(s)):
    if(k==0):
        break
    if(k>=toA(s[i])):
        k-=toA(s[i])
        s[i]='a'
    if(i==len(s)-1) and k>0:
        s[i]= toC(s[i],k)
print("".join(s))

Solution (Python):
def cost_for_next_a(c):
    return 123 - ord(c)

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

new_s = ""











for i in range(len(s)):
    if i == len(s) - 1:
        if cost_for_next_a(s[i]) <= K:
            new_s += chr(97 + (K - cost_for_next_a(s[i])) % 26)
        else:
            new_s += chr(ord(s[i]) + K)
    elif s[i] == 'a':
        new_s += 'a'
    elif cost_for_next_a(s[i]) <= K:
        new_s += "a"
        K -= cost_for_next_a(s[i])
    else:
        new_s += s[i]

print(new_s)