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 itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
K = int(input())

ans = []
for i, c in enumerate(S[:-1]):
    num = ord('z') - ord(c) + 1
    if K >= num:
        K -= num
        ans.append('a')
    else:
        ans.append(c)
# if K > 0:
ans.append(chr((ord(S[-1]) - ord('a') + K) % 26 + ord('a')))
print("".join(ans))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
K = int(input())

ans = []
for i, c in enumerate(S):
    num = ord('z') - ord(c) + 1
    if K >= num:
        K -= num
        ans.append('a')
    else:
        ans.append(c)
if K > 0:
    ans[-1] = chr((ord(ans[-1]) - ord('a') + K % 26) % 26 + ord('a'))
print("".join(ans))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
K = int(input())

ans = []
for i, c in enumerate(S):
    num = ord('z') - ord(c) + 1
    if K >= num:
        K -= num
        ans.append('a')
    else:
        ans.append(c)
if K > 0:
    ans[-1] = chr((ord(S[-1]) - ord('a') + K % 26) % 26 + ord('a'))
print("".join(ans))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
K = int(input())

ans = []
for i, c in enumerate(S):
    num = ord('z') - ord(c) + 1
    if K >= num:
        K -= num
        ans.append('a')
    else:
        ans.append(c)
if K > 0:
    ans[-1] = chr((ord(S[-1]) - ord('a') + K) % 26 + ord('a'))
print("".join(ans))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
v = list(s)
n = len(s)
a = [0 for i in range(n)]

for i in range(n):
  a[i] = 123 - ord(s[i])
  if k == 0:
    break
  if k >= a[i]:
    v[i] = 'a'
    k -= a[i]

if k > 0:
  k %= 26
  v[n-1] = chr(ord(v[n-1])+k)
print (''.join(v))

Submission status: Wrong Answer

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

a = [0 for i in range(len(s))]
t = ''

for i in range(len(s)):
  a[i] = 123 - ord(s[i])
  if k >= a[i]:
    v[i] = 'a'
    k -= a[i]

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

Submission status: Wrong Answer

Solution code:
import sys, math
from itertools import accumulate
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    s, K = input(), ii()
    l = list(map(lambda c: (ord('z')-ord(c)+1)%26, s))

    acc = 0
    t = ''
    for i in range(len(s)-1):
        if acc + l[i] <= K:
            acc += l[i]
            t += 'a'
        else:
            t += s[i]

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

    print(t)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, math
from itertools import accumulate
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    s, K = input(), ii()
    l = list(map(lambda c: (ord('z')-ord(c)+1)%26, s))

    acc = 0
    t = ''
    for i in range(len(s)):
        if acc + l[i] <= K:
            acc += l[i]
            t += 'a'
        else:
            if i == len(s)-1 and K-acc > 0:
                t += chr(ord(s[i])+K-acc)
            else:
                t += s[i]

    print(t)
        




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, math
from itertools import accumulate
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    s, K = input(), ii()
    l = list(map(lambda c: ord('z')-ord(c)+1, s))

    acc = 0
    t = ''
    for i in range(len(s)):
        if acc + l[i] <= K:
            acc += l[i]
            t += 'a'
        else:
            if i == len(s)-1 and K-acc > 0:
                t += chr(ord(s[i])+K-acc)
            else:
                t += s[i]

    print(t)
        




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

for i in range(len(s)):
    a = 26-(ord(s[i])-97)
    # print(ord(s[i]))
    # print(a)
    if k >= a and a != 26:
        k -= a
        s[i] = "a"
# print(k)
s[-1] = chr(97+((ord(s[-1])+k) % 97) % 27)
# print(ord(s[-1]))
print("".join(s))

Submission status: Wrong Answer

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

for i in range(len(s)):
    a = 26-(ord(s[i])-97)
    # print(ord(s[i]))
    # print(a)
    if k >= a and a != 26:
        k -= a
        s[i] = "a"
print(k)
s[-1] = chr(97+((ord(s[-1])+k) % 97) % 27)
# print(ord(s[-1]))
print("".join(s))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = ""
for si in s:
  num = ord("z") - ord(si) + 1
  if num <= k:
    ans += "a"
    k -= num
  else:
    ans += si

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

Submission status: Wrong Answer

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

ans = ""
for si in s:
  num = ord("z") - ord(si) + 1
  if num <= k:
    ans += "a"
    k -= num
  else:
    ans += si

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

Submission status: Wrong Answer

Solution code:

def resolve():
    S = input()
    K = int(input())

    ans = []
    for s in S:
        if K > 0:
            diff = ord(s) - ord("a")
            shift = (26 - diff) % 26
            if K - shift >= 0:
                ans.append("a")
                K -= shift
            else:
                ans.append(s)

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

    print("".join(ans))


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

oz = ord("z")

ans = ""

for s in S[:-1]:
    if K==0:
        break
    if oz+1-ord(s) <= K:
        K -= oz+1-ord(s)
        ans += "a"
    else:
        ans += s

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

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
for i in range(len(s)):
  if(ord("a") + 26 - ord(s[i]) <= K):
    K -= ord("a") + 26 - ord(s[i])
    s = s[:i] + "a" + s[i+1:]
  if(i == len(s) - 1):
    s = s[:-1] + chr(ord("a") + ((ord(s[-1]) + K % 26) - ord("a")) % 26)
print(s)

Submission status: Wrong Answer

Solution code:
def main():
    S = list(input())
    K = int(input())
    L = len(S)
    for i in range(L):
        tmp = ord(S[i]) - ord('a')
        if i == len(S) - 1:
            S[i] = chr((tmp + K) % 26 + ord('a'))
        if 26 - tmp <= K:
            K -= 26 - tmp
            S[i] = 'a'

    print(''.join(S))




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = list(input())
    K = int(input())
    L = len(S)
    for i in range(L):
        if ord('z') - ord(S[i]) + 1 <= K:
            K -= ord('z') - ord(S[i]) + 1
            S[i] = 'a'

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

    print(''.join(S))




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
#print(ord("z"))
for i in range(len(s)):
  if 123 - ord(s[i]) <= k:
    k -= (123 - ord(s[i]))
    s[i] = "a"
    #print(k)
#print(s, k)
k %= 26
if ord(s[-1]) + k > 122:
  s[-1] = chr(ord(s[-1]) + k - 26)
else:
  s[-1] = chr(ord(s[-1]) + k)
ans = ""
for i in s:
  ans += i
print(ans)

Submission status: Wrong Answer

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

def dist(char):
  return 123-ord(char)

distance = list(map(dist,s))
flag=0
for i in range(len(s)):
  if s[i] != 'a' and distance[i]<=K:
    s[i] = 'a'
    K -= distance[i]
  else:
    flag=1
    continue
      
if K == 0:
  flag=0
    
if flag:
  for i in range(len(s)):
    if s[-i-1] != 'a':
      tmp = min(distance[-i-1],K)
      s[-i-1] = chr(ord(s[-i-1])+tmp)
      K -= tmp
    if K == 0:break
      
if K != 0:
  for i in range(len(s)):
    q,r = divmod(K,26)
    if q > 0 and r != 0:
      s[-i-1] = 'z'
      K -= q*26
    elif r==0:
      break
    else:
      s[-i-1] = chr(ord(s[-i-1])+r)
      K = 0
      break
      
print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
#print(ord("z"))
for i in range(len(s)):
  if 123 - ord(s[i]) <= k:
    k -= (123 - ord(s[i]))
    s[i] = 'a'
    #print(k)
#print(s, k)
k %= 26
if ord(s[-1]) + k > 122:
  s[-1] = chr(ord(s[-1]) + k - 26)
else:
  s[-1] = chr(ord(s[-1]) + k)
ans = ""
for i in s:
  ans += i
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
#print(ord("z"))
for i in range(len(s)):
  if 123 - ord(s[i]) <= k:
    k -= (123 - ord(s[i]))
    s[i] = 'a'
    #print(k)
#print(s, k)
k %= 26
for i in range(1, len(s) + 1):
  if k == 0:
    break
  else:
    if 122 - ord(s[-i]) < k:
      k -= 122 - ord(s[-i])
      s[-i] = 'z'
    else:
      s[-i] = chr(ord(s[-i]) + k)
      k = 0
ans = ""
for i in s:
  ans += i
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
#print(ord("z"))
for i in range(len(s)):
  if 123 - ord(s[i]) <= k:
    k -= (123 - ord(s[i]))
    s[i] = 'a'
    #print(k)
#print(s, k)
for i in range(1, len(s) + 1):
  if k == 0:
    break
  else:
    if 122 - ord(s[-i]) < k:
      k -= 122 - ord(s[-i])
      s[-i] = 'z'
    else:
      s[-i] = chr(ord(s[-i]) + k)
      k = 0
ans = ""
for i in s:
  ans += i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = list(input())
    k = input_int()

    # 方針: 左の文字から貪欲に a を作る
    #       余ったk は一番右の文字の操作につかう
    for i in range(len(S)):
        c = ord(S[i])
        if c == ord("a"):
            continue
        dif = ord("z") - c + 1
        if dif <= k:
            S[i] = "a"
            k -= dif

    # 余ったkを一番右の文字の操作に使う
    S[-1] = chr(ord("a") + ((ord(S[-1]) + k) % ord("a")))
    print("".join(S))
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    ans = ['' for _ in range(len(S))]
    for i in range(len(S)):
        d = ord(S[i]) - ord('a')
        shift = (26 - d) % 26
        if K - shift >= 0:
            ans[i] = 'a'
            K -= shift
        else:
            ans[i] = S[i]
    if K > 0:
        K %= 26
        d = (K + ord(S[i]) - ord('a')) % 26
        ans[-1] = chr(d + ord('a'))
    print(''.join(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
b = "abcdefghijklmnopqrstuvwxyz"
n = len(s)
for i in range(n):
  dp = b.find(s[i])
  if k >= 26-dp:
    k-=26-dp
    s[i] = "a"
    if k == 0:
      break
else:
  s[-1] = b[(b.find(s[-1])+k)%26]
print("".join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
num = len(s)
for i in range(num):
    a = 122-ord(s[i])+1
    if a <= k:
        k -= a
        s[i] = 'a'
if k > 0:
    s[-1] = chr(ord(s[-1])+k%26)
print(*s, sep='')

Submission status: Wrong Answer

Solution code:
alpha=[chr(ord('a') + i) for i in range(26)]
a=list(input())
N=int(input())
for i in range(len(a)):
   s=26-alpha.index(a[i])
   if s<=N:
      a[i]="a"
      N-=s
   else:
      pass
s=alpha.index(a[-1])
s=(s+N)%26
a[-1]=alpha[s]
print(*a,sep="")

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
for i in range(n):
    if k <= 0 or s[i] == 'a':
        continue
    if 123 - ord(s[i]) <= k:
        k -= 123 - ord(s[i])
        s[i] = 'a'
# print(k)
# print(s)
k %= 26
print(ord(s[-1])+k)
if ord(s[-1])+k > 122:
    s[-1] = chr(97+(122-ord(s[-1])+k))
else:
    s[-1] = chr(ord(s[-1])+k)
# print(k)
print(*s, sep='')

Submission status: Wrong Answer

Solution code:
s = list(input())
K = int(input())
ans = []
for c in s:
    cnt = ord('z') - ord(c) + 1
    if K >= cnt:
        K -= cnt
        ans.append('a')
    else:
        ans.append(c)
K %= 26
if 122 < ord(ans[-1]) + K:
    ans[-1] = chr(ord(ans[-1]) + K - 26)
else:
    ans[-1] = chr(ord(ans[-1]) + K)
print(*ans,sep='')

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase
alp = ascii_lowercase
num = {char: i for i, char in enumerate(alp)}

s = input()
k = int(input())
ns = [num[char] for char in s]

for i in range(len(ns)):
    v = ns[i]
    if 26 - v <= k:
        ns[i] = 0
        k -= 26 - v

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

print(''.join(alp[n] for n in ns))

Submission status: Wrong Answer

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

ans = []
rem = k
for si in s[:-1]:
    if si == 'a':
        to_a = 0
    else:
        to_a = ord('z') - ord(si) + 1

    if to_a <= rem:
        rem -= to_a
        ans.append('a')
    else:
        ans.append(si)
        # next_s = chr(ord(si) + rem)
        # ans.append(next_s)
        # rem = 0


last_s_ord = (ord(s[-1]) + rem - ord('a'))%ord('a')
last_s = chr(ord('a') + last_s_ord)
ans.append(last_s)
ans = ''.join(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import string
abc = string.ascii_lowercase
s = list(input())
K = int(input())
index = 0
while K > 0:
    if index == len(s) - 1:
        s[index] = abc[(abc.index(s[index]) + K) % 26]
        break
    tmp = 26 - abc.index(s[index])
    if tmp == 0: continue
    if K >= tmp:
        s[index] = 'a'
        index += 1
        K -= tmp
    else:
        index += 1

for i in s:
    print(i, end='')

Submission status: Wrong Answer

Solution code:
import string
abc = string.ascii_lowercase
s = list(input())
K = int(input())
index = 0
while K > 0:
    if index == len(s) - 1:
        s[index] = abc[(abc.index(s[index]) + K) % 26]
        break
    tmp = 26 - abc.index(s[index])
    if K >= tmp:
        s[index] = 'a'
        index += 1
        K -= tmp
    else:
        index += 1

for i in s:
    print(i, end='')

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
    s = input()
    k = int(input())
    s2 = []
    s2a = s2.append
    for se in s:
        if ord(se) - 97:
            s2a(123 - ord(se))
        else:
            s2a(0)
    s2_ac = tuple(accumulate(s2))
    if s2_ac[-1] < k:
        k -= s2_ac[-1]
        k = k % 26
        r = s[:-1] + chr(97 + k)
        print(r)
    elif s2_ac[-1] == k:
        lens = len(s)
        r = 'a' * lens
        print(r)
    else:
        pos = bisect(s2_ac, k)
        if pos == 0:
            r = chr(k + ord(s[0])) + s[1:]
            print(r)
        elif s2_ac[pos-1] == k:
            r = 'a' * pos + s[pos:]
            print(r)
        else:
            r = 'a' * pos
            k -= s2_ac[pos-1]
            for i1 in range(pos, len(s)):
                if s2[i1] <= k:
                    r += 'a'
                    k -= s2[i1]
                else:
                    r += s[i1]
            if k:
                lastc = chr(ord(r[-1]) + k)
                r = r[:-1] + lastc
            print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = list(input())
n = len(s)
k = int(input())
alphabet = [chr(i) for i in range(97, 97+26)]
al_d = {}
for i in range(26):
    al_d[alphabet[i]] = i
for i in range(n):
    tobe_a = 26 - al_d[s[i]]
    if tobe_a <= k:
        k -= tobe_a
        s[i] = 'a'
remain = k % 26
s[-1] = alphabet[al_d[s[-1]]+remain]
print(''.join(s))

Submission status: Wrong Answer

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

L = []
for i in range(len(s)):
    L.append((ord("z")-ord(s[i])+1))

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

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

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

#############
# Main Code #
#############

S = input()
K = getN()
alpha = 'abcdefghijklmnopqrstuvwxyz'
dict = {}
for i in range(26):
    dict[alpha[i]] = 26 - i

ans = []
# ループさせてaにできるならする
# できないなら持ち越し
for i in range(len(S) - 1):
    roop = 0
    index = alpha.index(S[i])
    if K >= dict[S[i]]:
        K -= dict[S[i]]
        roop = dict[S[i]]
    ans.append(alpha[(index + roop) % 26])

# 最後の一文字について
index = alpha.index(S[-1])
ans.append(alpha[(index + K) % 26])
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n=len(s)
ans=""
for i in range(n):
    if i<n-1:
        if s[i]=="a":
            ans+="a"
        else:
            t=123-ord(s[i])
            if k>=t:
                ans+="a"
                k-=t
            else:
                ans+=s[i]
    if i==n-1:
        tt=k%26
        ans+=chr(ord(s[i])+tt)
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(map(str,input()))
k = int(input())
ans = [0]*len(s)



b = 123
for i in range(len(ans)):
    tmp = ord(s[i])
    if i != len(ans)-1:
        if b - tmp <= k:
            k = k-(b - tmp)
            ans[i] = "a"
        else:
            ans[i] = s[i]
    
    else:
        tmp1 = k % 26
        ans[i] = 96+tmp1
        ans[i] = chr(ans[i])            
       
print("".join(ans))

Submission status: Wrong Answer

Solution code:
s = list(map(str,input()))
k = int(input())
ans = [0]*len(s)



b = 123
for i in range(len(ans)):
    tmp = ord(s[i])
    if i != len(ans)-1:
        if b - tmp <= k:
            k = k-(b - tmp)
            ans[i] = "a"
        else:
            ans[i] = s[i]
    
    else:
        if tmp + k >= 123:
            tmp1 = k % 26
            ans[i] = 96+tmp1
            ans[i] = chr(ans[i])            
        else:
            ans[i] = k+tmp
            ans[i] = chr(ans[i])
       
print("".join(ans))

Submission status: Wrong Answer

Solution code:
s = list(map(str,input()))
k = int(input())
ans = [0]*len(s)



b = 123
for i in range(len(ans)):
    tmp = ord(s[i])
    if i != len(ans)-1:
        if b - tmp <= k:
            k = k-(b - tmp)
            ans[i] = "a"
        else:
            ans[i] = s[i]
    
    else:
        if tmp + k >= 123:
            tmp1 = k % 26
            ans[i] = 96+tmp1
            ans[i] = chr(ans[i])            
        else:
            ans[i] = k+tmp
            ans[i] = chr(ans[i])
print(k)            
print("".join(ans))

Submission status: Wrong Answer

Solution code:
s = list(map(str,input()))
k = int(input())
ans = [0]*len(s)



b = 123
for i in range(len(ans)):
    tmp = ord(s[i])
    if i != len(ans)-1:
        if b - tmp <= k:
            k = k-(b - tmp)
            ans[i] = "a"
        else:
            ans[i] = s[i]
    
    else:
        if tmp + k >= 123:
            tmp1 = k % 25
            ans[i] = 96+tmp1
            ans[i] = chr(ans[i])            
        else:
            ans[i] = k+tmp
            ans[i] = chr(ans[i])
            
print("".join(ans))

Submission status: Wrong Answer

Solution code:
s = list(map(str,input()))
k = int(input())
ans = [0]*len(s)



b = 123
for i in range(len(ans)):
    tmp = ord(s[i])
    if i != len(ans)-1:
        if b - tmp <= k:
            k = k-(b - tmp)
            ans[i] = "a"
        else:
            ans[i] = s[i]
    
    else:
        if tmp + k >= 123:
            tmp1 = (tmp+k) % 26
            ans[i] = 96+tmp1
            ans[i] = chr(ans[i])            
        else:
            ans[i] = k+tmp
            ans[i] = chr(ans[i])
            
print("".join(ans))

Submission status: Wrong Answer

Solution code:
s = list(map(str,input()))
k = int(input())
ans = [0]*len(s)



b = 123
for i in range(len(ans)):
    tmp = ord(s[i])
    if i != len(ans)-1:
        if b - tmp <= k:
            k = k-(b - tmp)
            ans[i] = "a"
        else:
            ans[i] = s[i]
    
    else:
        if tmp + k >= 123:
            tmp1 = (tmp+k) % 25
            ans[i] = 96+tmp1
            ans[i] = chr(ans[i])            
        else:
            ans[i] = k+tmp
            ans[i] = chr(ans[i])
            
print("".join(ans))

Submission status: Wrong Answer

Solution code:
s = list(map(str,input()))
k = int(input())
ans = [0]*len(s)



b = 123
for i in range(len(ans)):
    tmp = ord(s[i])
    if i != len(ans)-1:
        if b - tmp <= k:
            k = k-(b - tmp)
            ans[i] = "a"
        else:
            ans[i] = s[i]
    
    else:
        if tmp + k >= 123:
            tmp1 = (tmp+k) % 122
            ans[i] = 96+tmp1
            ans[i] = chr(ans[i])            
        else:
            ans[i] = k+tmp
            ans[i] = chr(ans[i])
            
print("".join(ans))

Submission status: Wrong Answer

Solution code:
s = list(map(str,input()))
k = int(input())
ans = [0]*len(s)

for i in range(len(s)):
    tmp = ord(s[i])
    ans[i] = tmp

b = 123
for i in range(len(ans)):
    tmp = ord(s[i])
    if i != len(ans)-1:
        if b - tmp <= k:
            k = k-(b - tmp)
            ans[i] = "a"
        else:
            ans[i] = s[i]
    
    else:
        if tmp + k >= 122:
            tmp1 = (tmp+k) % 122
            ans[i] = 96+tmp1
            ans[i] = chr(ans[i])            
        else:
            ans[i] += k
            ans[i] = chr(ans[i])

print("".join(ans))

Submission status: Wrong Answer

Solution code:
s = list(map(str,input()))
k = int(input())
ans = [0]*len(s)

for i in range(len(s)):
    tmp = ord(s[i])
    ans[i] = tmp

b = 123
for i in range(len(ans)):
    tmp = ord(s[i])
    if i != len(ans)-1:
        if b - tmp <= k:
            k = k-(b - tmp)
            ans[i] = "a"
        else:
            ans[i] = s[i]
    
    else:
        if tmp + k >= 123:
            tmp1 = (tmp+k) % 122
            ans[i] = 96+tmp1
            ans[i] = chr(ans[i])            
        else:
            ans[i] += k
            ans[i] = chr(ans[i])

print("".join(ans))

Submission status: Wrong Answer

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

rest = K
oz = ord('z')
oa = ord('a')
ans = list(S)

for ci in range(len(S)):
    check = oz - ord(S[ci]) + 1
    if rest >= check:
        ans[ci] = 'a'
        rest -= check

if rest >= 0:
    for i in range(rest%26):
        if oz == ord(ans[-1]):
            ans[-1] = 'a'
        else:
            ans[-1] = chr(ord(ans[-1])+1)
    
print("".join(ans))

Submission status: Wrong Answer

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

rest = K
oz = ord('z')
oa = ord('a')
ans = list(S)

for ci in range(len(S)):
    check = oz - ord(S[ci]) + 1
    if rest >= check:
        ans[ci] = 'a'
        rest -= check

if rest >= 0:
    for i in range(rest):
        if oz == ord(ans[-1]):
            ans[-1] = 'a'
        else:
            ans[-1] = chr(ord(ans[-1])+1)
    
print("".join(ans))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n=len(s)
i=0
ans=""
while i<n:
    if i!=n-1:
        if k>=123-ord(s[i]):
            ans+="a"
            k-=(123-ord(s[i]))
        else:
            ans+=s[i]
    else:
        if k>=123-ord(s[i]):
            k-=(123-ord(s[i]))#一旦aにする
            k=k%26
            ans+=chr(97+k)
        else:
            ans+=chr(ord(s[i])+k)
    i+=1
print(ans)

Submission status: Wrong Answer

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

ans = []
for ch in s:
    v = ord("a") + 26 - ord(ch)
    if v <= K:
        K -= v
        ans.append("a")
    else:
        ans.append(ch)

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

Submission status: Wrong Answer

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

ans = []
for ch in s:
    v = ord("a") + 26 - ord(ch)
    if v <= K:
        K -= v
        ans.append("a")
    else:
        ans.append(ch)

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

Submission status: Wrong Answer

Solution code:
s=input()
K = int(input())
si = ''
for i in range(len(s)-1):
    tmp = 123-ord(s[i])
    if tmp <= K:
        K -= tmp
        si += 'a'
    else:
        si += s[i]
si+=chr(97+(ord(s[-1])+K-97)%26)
print(si)

Submission status: Wrong Answer

Solution code:
from bisect import *
S = list(str(input()))
K = int(input())

alp = list("abcdefghijklmnopqrstuvwxyz")

for i in range(len(S)):
  b = bisect_left(alp,S[i])

  if i == len(S)-1:
    S[i] = alp[(b+K)%26]
  if b == 0:
    continue
  elif 26 - b <= K:
    K -= (26 - b)
    S[i] = "a"
  if K == 0:
    break
  
print("".join(S))

Submission status: Wrong Answer

Solution code:
from bisect import *
S = list(str(input()))
K = int(input())

alp = list("abcdefghijklmnopqrstuvwxyz")

for i in range(len(S)):
  b = bisect_left(alp,S[i])
  if i == len(S)-1:
    S[i] = alp[(b+K)%26]
  elif 26 - b <= K:
    K -= (26 - b)
    S[i] = "a"
  if K == 0:
    break

print("".join(S))

Submission status: Wrong Answer

Solution code:
s,k,t=input(),int(input()),""
for q in s:k=max(k-(123-ord(q))%26,0);t+=[q,"a"][k>=0]
print(t[:-1]+chr((ord(t[-1])-97+k)%26+97))

Submission status: Wrong Answer

Solution code:
s,k,t=input(),int(input()),""
for q in s:
 if(p:=(122-ord(q))%26)<k:t+="a";k-=p
 else:t+=q
print(t[:-1]+chr((ord(t[-1])-97+k)%26+97))

Submission status: Wrong Answer

Solution code:
s, k, t = input(), int(input()), ""
for q in s:
    if (p := 123 - ord(q)) <= k:
        k -= p
        t += "a"
    else:
        t += q
print(t[:-1] + chr((ord(t[-1]) - 97 + k) % 26 + 97))

Submission status: Wrong Answer

Solution code:
s, k, t = input(), int(input()), ""
for s in s:
    if (p := 123 - ord(s)) <= k:
        k -= p
        t += "a"
    else:
        t += s
print(t[:-1] + chr((ord(t[-1]) - 97 + k) % 26 + 97))

Submission status: Wrong Answer

Solution code:
s, k, t, i = input(), int(input()), "", 0
for s in s:
    if (p := 123 - ord(s)) <= k:
        k -= p
        t += "a"
    else:
        t += s
print(t[:-1] + chr((ord(t[-1]) - 97 + k) % 26 + 97))

Submission status: Wrong Answer

Solution code:
s, k, t, i = input(), int(input()), "", 0
for s in s:
    if (p := 123 - ord(s)) <= k:
        k -= p
        t += "a"
    else:
        t += s
print(t[:-1] + chr((ord(t[-1]) + k % 26) % 96 + 96))