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: Wrong Answer

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a="abcdefghijklmnopqrstuvwxyz"
s=input()
ans=""
k=int(input())
for i in range(len(s)-1):
    if s[i]!="a":
        if a.index(s[i])+k>=26:
            ans=ans+"a"
            k-=26-a.index(s[i])
        else:
            ans=ans+s[i]
ans=ans+a[(a.index(s[-1])+k)%26]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a="abcdefghijklmnopqrstuvwxyz"
s=input()
ans=""
k=int(input())
for i in range(len(s)-1):
    if a.index(s[i])+k>=26:
        ans=ans+"a"
        k-=26-a.index(s[i])
    else:
        ans=ans+s[i]
ans=ans+a[(a.index(s[-1])+k)%26]
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

asc = [0] * len(s)
for i in range(len(s)):
    asc[i] = ord(s[i]) - ord("a")
i = 0
for i in range(len(s)):
    if 26 - asc[i] <= k or i == len(s) - 1:
        x = 26 - asc[i]
        asc[i] = (asc[i] + min(k, x)) % 26
        k -= x

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

Submission status: Wrong Answer

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

    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
    D = dict(zip(ascii_lowercase,list(range(0,len(ascii_lowercase)))))

    n = len(ascii_lowercase)

    for i in range(0,len(s)):
        j = D[s[i]]
        if j != 0 and 26 -j <= k:
            k -= (26-j)
            s[i] ='a'
    print(''.join(s))

main()

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = list(SS())
    K = I()

    # 左からaにしていって、余ったKを一番右に突っ込む
    for i in range(len(s) - 1):
        diff = ord('z') + 1 - ord(s[i])
        if K >= diff:
            K -= diff
            s[i] = 'a'

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

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

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

a = ord(s[-1])+k%26
if(a > ord("z")):
    a -= 26
ans += chr(a)
    
print(ans)

Submission status: Wrong Answer

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

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

a = ord(s[-1])+k%26
if(a > ord("z")):
    a -= 26
ans += chr(a)
    
print(ans)

Submission status: Wrong Answer

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

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

if(k):  
    a = ord(s[-1])+k%26
    if(a > ord("z")):
        a -= 26
    ans += chr(a)
    
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(len(s)):
  f=-ord(s[i])+ord("z")+1
  if f<=k:
    l[i]="a"
    k-=f
k=k%26
l[-1]=chr(ord(l[-1])+k)
print("".join(l))

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
n = int(input())
ans = ["A"]*l
for i in range(l-1):
  temp = ord("z")-ord(s[i])+1
  if temp <= n:
    n-=temp
    ans[i]="a"
  else:
    ans[i]=s[i]


last = ord(s[l-1])+n
#print(last)
while last>ord("z"):
  last-=26
ans[l-1]=chr(last)
print("".join(ans))

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = list(input())
k = INT()

i = 0
while k > 0:
    tmp = ord(s[i]) - ord('a')
    if i < len(s) - 1:
        if 26 - tmp <= k:
            k -= 26 - tmp
            s[i] = 'a'
        i += 1
    else:
        s[i] = chr((tmp+k)%26 + ord('a'))
        k = 0

print(''.join(s))

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = list(input())
k = INT()

i = 0
while k > 0:
    tmp = ord(s[i]) - ord('a')
    if i < len(s) - 1:
        if 26 - tmp <= k:
            k -= 26 - tmp
            s[i] = 'a'
        i += 1
    else:
        s[i] = chr((tmp+k)%26 + ord('a'))
        k = 0

print(*s, sep='')

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    k = int(input())
    ans = []
    for s in S:
        if (r := 123 - ord(s)) <= k:
            ans.append('a')
            k -= r
        else:
            ans.append(s)
    if k > 0:
        k %= 26
        ans[-1] = chr(a if (a := ord(ans[-1]) + k) <= 122 else a - 26)
    print(''.join(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    n = len(S)
    k = int(input())
    i = 0
    ans = []
    while k > 0:
        if i == n - 1:
            k %= 26
            if (r := 123 - ord(S[i])) <= k:
                ans.append(chr(97 + k - r))
            else:
                ans.append(chr(ord(S[i]) + k))
            k = 0
        else:
            if (r := 123 - ord(S[i])) <= k and S[i] != 'a':
                ans.append('a')
                k -= r
                i += 1
            else:
                ans.append(S[i])
                i += 1
    print(''.join(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    n = len(S)
    k = int(input())
    i = 0
    ans = []
    while k > 0:
        if i == n - 1:
            k %= 26
            if (r := 123 - ord(S[i])) <= k:
                ans.append(chr(97 + k - r))
            else:
                ans.append(chr(ord(S[i]) + k))
            k = 0
        else:
            if (r := 123 - ord(S[i])) <= k:
                ans.append('a')
                k -= r
                i += 1
            else:
                ans.append(S[i])
                i += 1
    print(''.join(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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
if K > 0:
    S[-1] = chr((ord(S[-1]) - ord('a') + K) % 26 + ord('a'))

print("".join(S))

Submission status: Wrong Answer

Solution code:
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
if K > 0:
    S[-1] = chr((ord(S[-1]) - ord('a') + K % 26) % 26 + ord('a'))

print("".join(S))

Submission status: Wrong Answer

Solution code:
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
else:
    if K > 0:
        S[-1] = chr((ord(S[-1]) - ord('a') + K % 26) + ord('a'))

print("".join(S))

Submission status: Wrong Answer

Solution code:
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
else:
    if K > 0:
        S[-1] = chr((ord(S[-1]) + K % 26) % 26)

print("".join(S))

Submission status: Wrong Answer

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

l = 0
for i, s in enumerate(S):
    if ord('z') - ord(s) + 1 <= K:
        S[i] = 'a'
        K -= ord('z') - ord(s) + 1
    else:
        l = i
else:
    if K > 0:
        S[-1] = chr(ord(S[-1]) + K % 26)

print("".join(S))

Submission status: Wrong Answer

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

l = 0
for i, s in enumerate(S):
    if ord('z') - ord(s) + 1 <= K:
        S[i] = 'a'
        K -= ord('z') - ord(s) + 1
    else:
        l = i
else:
    if K > 0:
        S[l] = chr(ord(S[l]) + K % 26)

print("".join(S))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = ""
for i, s in enumerate(S):
    if i == len(S) - 1:
        if ord(s) + K <= ord("z"):
            ans += chr(ord(s) + K)
        else:
            ans += chr(ord("a") + (ord(s) + K - ord("z") - 1) % 26)
    elif ord("z") + 1 - ord(s) <= K:
        ans += "a"
        K -= (ord("z") + 1 - ord(s))
    else:
        ans += s

print(ans)

Submission status: Wrong Answer

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

ans = ""
for i, s in enumerate(S):
    if i == len(S) - 1:
        if ord(s) + K <= ord("z"):
            ans += chr(ord(s) + K)
        else:
            ans += chr(ord("a") + (ord(s) + K - ord("z") - 1) % 26)
        break
    if ord("z") + 1 - ord(s) <= K:
        ans += "a"
        K -= (ord("z") + 1 - ord(s))
    else:
        ans += s

print(ans)

Submission status: Wrong Answer

Solution code:
A = {i-97:chr(i) for i in range(97,123)}
B = {v:k for k,v in A.items()}
s = list(input().strip())
K = int(input())
for i in range(len(s)-1):
    if K>=26-B[s[i]]:
        K -= (26-B[s[i]])
        s[i]="a"
k = K%26
ind = (B[s[-1]]+k)%26
s[-1] = A[ind]
print("".join(s))

Submission status: Wrong Answer

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

s = list(input())
k = inp()
n = len(s)
nxa = ord('z') + 1

for i,x in enumerate(s):
    rem = nxa - ord(x)
    if rem <= k:
        s[i] = 'a'
        k -= rem
if k > 0:
    s[i] = chr(ord('a') + (ord(s[i])-ord('a')+k)%26)
print(''.join(s))

Submission status: Wrong Answer

Solution code:
li_s = list(input())
k = int(input())
z = ord('z')
ans = ''
for i in range(len(li_s)):
    if i < len(li_s)-1 and k-(z-ord(li_s[i])+1) >= 0:
        k -= z-ord(li_s[i])+1
        ans = ans + 'a'
    elif i < len(li_s)-1:
        ans = ans + li_s[i]
    elif i == len(li_s) - 1:
        p = ord(li_s[i])  + k
        p %= 26
        p += 78
        if 97 <= p:
            ans = ans + chr(p)
        else:
            ans = ans + chr(p+26)
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
n = len(s)
k = int(input())
t = [ord(s[i]) - 97 for i in range(n)]
for i in range(n):
    if k == 0:
        break
    x = 26 - t[i]
    if 0 < x % 26 <= k:
        k -= x
        s[i] = "a"
if k > 0:
    s[-1] = chr((k + t[-1]) % 26 + 97)
print("".join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
t = list(map(lambda x:ord(x)-ord("a"),s)) #a-zを0-25に正規化

for i in range(len(t)):
  diff = 26-t[i] #aになるまでの差
  if diff <= k:
    t[i]+=diff
    k-=diff
  else:
    continue
t[-1]+=k #k余りを一番最後に足す

#print("s:",s)
#print("t:",t)
u = "".join(list(map(lambda x:chr((x%26+ord("a"))),t)))
print(u)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
t = list(map(lambda x:ord(x)-ord("a"),s)) #a-zを0-25に正規化

for i in range(len(t)):
  diff = 26-t[i] #aになるまでの差
  if diff <= k:
    t[i]+=diff
    k-=diff
    print(t[i],diff,k)
  else:
    continue
t[-1]+=k #k余りを一番最後に足す

#print("s:",s)
#print("t:",t)
u = "".join(list(map(lambda x:chr((x%26+ord("a"))),t)))
print(u)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
t = list(map(lambda x:ord(x)-ord("a"),s)) #a-zを0-25に正規化

for i in range(len(t)):
  diff = 26-t[i] #aになるまでの差
  if diff <= k:
    t[i]+=diff
    k-=diff
    print(t[i],diff,k)
  else:
    continue
t[-1]+=k #k余りを一番最後に足す

#print("s:",s)
#print("t:",t)
u = "".join(list(map(lambda x:chr((x%26+ord("a"))),t)))
print("u:",u)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
t = list(map(lambda x:ord(x)-ord("a"),s)) #a-zを0-25に正規化

for i in range(len(t)):
  diff = 26-t[i] #aになるまでの差
  if diff <= k:
    t[i]+=diff
    k-=diff
    print(t[i],diff,k)
  else:
    continue
t[-1]+=k #k余りを一番最後に足す

#print("s:",s)
#print("t:",t)
u = "".join(list(map(lambda x:chr((x%26+ord("a"))),t)))
#print("u:",u)

Submission status: Wrong Answer

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

for i,c in enumerate(s):
	x = ord('z')-ord(c)+1
	if x <= K:
		s = s[:i]+'a'+s[i+1:]
		K -= x

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

Submission status: Wrong Answer

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

for i,c in enumerate(s):
	x = ord('z')-ord(c)+1
	if x <= K:
		s = s[:i]+'a'+s[i+1:]
		K -= x

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
s = input()
k = int(input())
n = len(s)
ans = []
# kを減らしていく。もし、aまで戻せるならaまで進めてk をその分減らす。
for i in range(n):
    if s[i] == "a":
        ans.append("a")
    elif 123 - ord(s[i]) <= k:
        ans.append("a")
        k -= 123 - ord(s[i])
    else:
        ans.append(s[i])
# print(k)
k %= 26  # 26で割ったあまりに落とす
for i in range(n - 1, -1, -1):  # 後ろから見ていく
    if k == 0:
        break
    if 122 - ord(s[i]) >= k:  # この場所でk==0にできる
        ans[i] = chr((ord(ans[i]) + k))
        break
    else:
        ans[i] = "z"
        k -= 122 - ord(s[i])
print("".join(ans))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
s = input()
k = int(input())
n = len(s)
ans = []
# kを減らしていく。もし、aまで戻せるならaまで進めてk をその分減らす。
for i in range(n):
    if s[i] == "a":
        ans.append("a")
    elif 123 - ord(s[i]) <= k:
        ans.append("a")
        k -= 123 - ord(s[i])
    else:
        ans.append(s[i])
# print(k)
k %= 26  # 26で割ったあまりに落とす
for i in range(n - 1, -1, -1):  # 後ろから見ていく
    if k == 0:
        break
    if 122 - ord(s[i]) >= k:
        ans[i] = chr((ord(s[i]) + k))
        break
    else:
        ans[i] = "z"
        k -= 122 - ord(s[i])
print("".join(ans))

Submission status: Wrong Answer

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

ans = ""
for s in S:
    if 123-ord(s) <= K:
        ans += "a"
        K -= 123-ord(s)
    else:
        ans += s
if K > 0:
    ans = ans[:-1] + chr((ord(ans[-1])-97+K)%26+97)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union
# import time
# import math, cmath
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import _heapify_max, _heappop_max, _siftdown_max
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import Fraction               # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10)



def main():
    Num = Union[int, float]
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79e+308
    # inf = 2 ** 63 - 1             # (for fast JIT compile in PyPy) 9.22e+18
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    # def _heappush_max(h, item): h.append(item); _siftdown_max(h, 0, len(h)-1)


    def calc_rotate_min(L, start, rotate):
        n = len(L)
        for i in range(start, n):
            # print(i, L, rotate)
            if rotate == 0:
                return
            if i == n - 1:
                # この文字をグルグルするしかない
                L[i] = (L[i] + rotate % 26) % 26
                return
            if 26 - L[i] <= rotate:
                rotate -= (26 - L[i])
                L[i] = 0    # 'a' にする                
            else:
                # この文字を最小にはできない
                return calc_rotate_min(L, i+1, rotate)


    
    s = input()
    k = ii()
    L = list(map(lambda x: ord(x)-ord('a'), s))
    calc_rotate_min(L, 0, rotate=k)
    
    for num in L:
        print(chr(num+ord('a')), end='')
    print('')



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = list(input())
    K = int(input())
    N = len(S)
    k = K
    for i,c in enumerate(S):
        distance = ord('z') + 1 - ord(c)
        if distance <= k:
            k -= distance
            S[i] = 'a'
    
    S[-1] = chr((ord(S[-1]) - ord('a') + k) % 26 + ord('a'))
    print(''.join(S))

main()

Submission status: Wrong Answer

Solution code:
def main():
    S = list(input())
    K = int(input())
    N = len(S)
    k = K
    for i,c in enumerate(S):
        distance = ord('z') + 1 - ord(c)
        if distance <= k:
            k -= distance
            S[i] = 'a'
    
    S[-1] = chr((ord(S[i]) - ord('a') + k) % 26 + ord('a'))
    print(''.join(S))

main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')

#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

s=list(ss())
k=ii()
ans=""
for i in range(len(s)):
    p=ord(s[i])
    
    if i==len(s)-1:
        k%=122-97+1
        #print(k)
        p+=k
        if p>=123:
            p-=122-97+1
        ans=ans+chr(p)
        #print(p)
    elif k>=123-p:
        k-=123-p
        ans=ans+"a"
    else:
        ans=ans+s[i]

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
c = ord("z") + 1
for i in range(n):
    tmp = c - ord(s[i])
    if k >= tmp:
        s[i] = "a"
        k -= tmp
if k > 0:
    s[n-1] = chr((ord(s[n-1])+k%26)%123)
print("".join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
c = ord("z") + 1
for i in range(n):
    tmp = c - ord(s[i])
    if k >= tmp:
        s[i] = "a"
        k -= tmp
if k > 0:
    s[n-1] = chr(ord(s[n-1])+k%26)
print("".join(s))

Submission status: Wrong Answer

Solution code:
s=list(input())
K=int(input())
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"]

for i in range(len(s)):
    n=alp.index(s[i])
    if n+K>=26:
        s[i]="a"
        K-=26-n
    if K==0:
        break
    if i==len(s)-1 and K>0:
        n=alp.index(s[i])
        s[i]=alp[(n+K)%26]

for j in s:
    print(j,end="")
print()

Submission status: Wrong Answer

Solution code:
s=list(input())
K=int(input())
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"]

for i in range(len(s)):
    n=alp.index(s[i])
    if n+K>=26:
        s[i]="a"
        K-=26-n
    if K==0:
        break
    if i==len(s)-1 and K>0:
        s[i]=alp[(n+K)%26]

for j in s:
    print(j,end="")
print()

Submission status: Wrong Answer

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

ord_a = ord('a')
ord_z = ord('z')

k = K
Ans = list(S)
for i, s in enumerate(S[:-1]):
    ord_s = ord(s)
    dif = ord_z - ord_s + 1
#    print(i, k, dif)
    if s == 'a':
        continue
    elif dif <= k:
        Ans[i] = 'a'
        k -= dif
    else:
        Ans[-1] = chr(ord_a + (ord(Ans[-1]) + k - ord_a)%26)
        k -= k
        break
else:
    Ans[-1] = chr(ord_a + (ord(Ans[-1]) + k - ord_a)%26)
print(''.join(Ans))

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

S = list(readline().rstrip())
K = int(readline())
N = len(S)
for i in range(N):
    t = ord(S[i])-97
    if 26 - t <= K:
        S[i] = 'a'
        K -= 26-t
S[-1] = chr((ord(S[-1])-97 + K%26)%26 + 97)
print(''.join(S))

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

S = list(readline().rstrip())
K = int(readline())
N = len(S)
for i,s in enumerate(S):
    t = ord(s)-97
    if 26 - t <= K:
        S[i] = 'a'
        K -= 26-t
S[-1] = chr((ord(S[-1])-97 + K%26)%26 + 97)
print(''.join(S))

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

S = list(readline().rstrip())
K = int(readline())
N = len(S)
for i,s in enumerate(S):
    t = ord(s)-97
    if 26 - t <= K:
        S[i] = 'a'
        K -= 26-t
S[-1] = chr((ord(S[i]) + K%26)%97+97)
print(''.join(S))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=''
for i in range(len(s)-1):
  if not s[i]=='a':
    if k>=123-ord(s[i]):
      k-=(123-ord(s[i]))
      ans+='a'
    else:
      ans+=s[i]
ans+=chr((ord(s[-1])-97+k)%26+97)
print(ans)

Submission status: Wrong Answer

Solution code:
G={chr(a+ord("a")):a for a in range(26)}
H={G[b]:b for b in G}

T=input()
S=[]
for s in T:
    S.append(G[s])
K=int(input())

I=0
N=len(S)
for i in range(N):
    if (i!=N-1) and (26-S[i]<=K):
        K-=26-S[i]
        S[i]=0
    elif i==N-1:
        S[i]=(S[i]+K)%26

U=""
for s in S:
    U+=H[s]

print(U)

Submission status: Wrong Answer

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

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

print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
for i in range(n-1):
    d = ord('z')-ord(s[i])+1
    if d<=k:
        s[i] = 'a'
        k -= d

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


print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
for i in range(n-1):
    d = ord('z')-ord(s[i])+1
    if d<=k:
        s[i] = 'a'
        k -= d

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

print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
for i in range(n):
    d = ord('z')-ord(s[i])+1
    if d<=k:
        s[i] = 'a'
        k -= d

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

print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
for i in range(n):
    d = ord('z')-ord(s[i])+1
    if d<=k:
        s[i] = 'a'
        k -= d

if k>0:
    x = ord(s[-1])+k%26
    d = x-ord('z')
    if d>0:
        x = chr('a')+d
    s[-1] = chr(x)


print(''.join(s))