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



Sample input:
xyz
4


Sample output:
aya

Submission status: Accepted

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

c=k
for i in range(n):
    if c-(27-s[i])>=0:
        if s[i]+c>26 and s[i]!=1:
            c=c-(27-s[i])
            s[i]=1
#print(s[-1],c)
s[-1]+=c%26
num2alpha=lambda c: chr(c+96)
for i in range(n):
    s[i]=num2alpha(s[i])

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

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

print(new)

Submission status: Accepted

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

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

a_ = ord('a')

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
k=int(input())
for i in range(len(s)):
    if s[i]=="a":
        continue
    if k>=ord("z")-ord(s[i])+1:
        k-=(ord("z")-ord(s[i])+1)
        s[i]="a"

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

print("".join(s))

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = ""
cnt = 0
for i in range(len(S)):
    #最後の文字で操作回数が余ってるなら使い切る
    if i == len(S) - 1:
        if ord(S[i]) + (K-cnt)%26 > ord("z"):
            tmp = ord(S[i]) + (K-cnt)%26 - ord("z")
            ans += chr(96+tmp)
        #print(K,cnt,(K-cnt)%26)
        else:
            ans += chr(ord(S[i]) + (K-cnt)%26)
    else:
        #先頭からなるべくaにしていく。回数が足りないならその文字は飛ばす
        if cnt >= K:
            ans += S[i]
        else:
            if S[i] == "a":
                ans += "a"
            else:
                if cnt + (123 - ord(S[i])) <= K:
                    ans += "a"
                    cnt += (123 - ord(S[i]))
                else:
                    ans += S[i]

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

# 残りのKを消化
lastw = (K + apos[-1] - 1) % 26 + 1
a.append(num2alpha(lastw))
print("".join(a))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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


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


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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

#print(l)

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

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

#print(l)

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

print(ans.lower())


#%%

Submission status: Accepted

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

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

s_list=list(s)
len_s=len(list(s))
temp1=k
temp2=0
for i in range(len_s):
	if (123-ord(s_list[i])<=temp1)and (s_list[i] != 'a'):
		temp1=temp1-(123-ord(s_list[i]))
		s_list[i]="a"
if temp1!=0:
#	print(temp1)
	temp2=temp1%26+ord(s_list[-1])
	if temp2>122:
		temp2=temp2-122+96
	s_list[-1]=chr(temp2)
#print(temp2)
#print(str(s_list))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

al=list('bcdefghijklmnopqrstuvwxyza')

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

Submission status: Accepted

Solution code:
import string

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

alp = string.ascii_lowercase
ans = ''

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

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

print(ans)

Submission status: Accepted

Solution code:
import string

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

alpha = string.ascii_lowercase
s = len(S)

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

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

print(*S, sep='')

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

print("".join(sa))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

abc="bcdefghijklmnopqrstuvwxyza"

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

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

print("".join(s))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

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

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

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

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

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#CODEFESTIVAL2016 qual A C

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

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

Submission status: Accepted

Solution code:
# 2019/09/17

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

cnta=0
min_l=10000

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

Submission status: Accepted

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

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

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

S[-1] += N % 26

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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

    # See:
    # https://atcoder.jp/contests/code-festival-2016-quala/submissions/1033174
    for i in range(l):
        t = (ord('z') - ord(s[i]) + 1) % 26

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

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

    print(''.join(s))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():

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

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

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

Submission status: Accepted

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

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

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

print(''.join(ans))

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




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

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

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

    print(''.join(s))



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

N %= 26

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a_num = 97
z_num = 122

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

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

Submission status: Accepted

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

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

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

print(''.join(t))

Submission status: Accepted

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

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

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

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

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

print("".join(s))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

after = []

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

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

Submission status: Accepted

Solution code:
S = list(input())
K = int(input())
characters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n',
              'o','p','q','r','s','t','u','v','w','x','y','z']
L = []
for s in S:
  L.append(characters.index(s))

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

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


P = ""

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# code-festival-2016-qualaC - 次のアルファベット / Next Letter
def main():
    S = input().rstrip()
    K = int(input())
    abc = "abcdefghijklmnopqrstuvwxyz"
    # dist[c] := distance to "a" through "z"
    dist = {c: 26 - i for i, c in enumerate(abc)}
    dist["a"] = 0
    A = [dist[i] for i in S]
    ans = ""
    for i, s in zip(A[:-1], S[:-1]):
        if 0 < i <= K:  # change s to "a" if possible
            ans += "a"
            K -= i
        else:
            ans += s
    # use the remaining K on A[-1] and combine with ans
    ans += chr((ord(S[-1]) + K - ord("a")) % 26 + ord("a"))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# code-festival-2016-qualaC - 次のアルファベット / Next Letter
from string import ascii_lowercase as abc


def main():
    S = input().rstrip()
    K = int(input())
    # dist[c] := distance to "a" through "z"
    dist = {c: 26 - i for i, c in enumerate(abc)}
    dist["a"] = 0
    A = [dist[i] for i in S]
    ans = ""
    for i, s in zip(A[:-1], S[:-1]):
        if 0 < i <= K:  # change s to "a" if possible
            ans += "a"
            K -= i
        else:
            ans += s
    # use the remaining K on A[-1] and combine with ans
    ans += chr((ord(S[-1]) + K - ord("a")) % 26 + ord("a"))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# code-festival-2016-qualaC - 次のアルファベット / Next Letter
from string import ascii_lowercase as abc


def main():
    S = input().rstrip()
    K = int(input())
    N, MOD = len(S), 26
    # dist[c] := distance to "a" through "z"
    dist = {c: 26 - i for i, c in enumerate(abc)}
    dist["a"] = 0
    A = [dist[i] for i in S]
    for i in range(N):
        if A[i] and A[i] <= K:  # A[i] -> "a" if possible
            A[i], K = 0, K - A[i]
    A[-1] = (A[-1] - K) % MOD  # use the remaining K on A[-1]
    rest = {v: k for k, v in dist.items()}
    ans = [rest[i] for i in A]  # restore dist to chr
    print(*ans, sep="")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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="")

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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