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, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
S = list(input())
K = int(input())

for i in range(len(S)-1):
    if S[i] == 'a':
        continue

    d = ord('z') - ord(S[i]) + 1
    if K >= d:
        S[i] = 'a'
        K -= d
    # print(K, d)

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

print(''.join(S))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


D = {c:i for i,c in enumerate('abcdefghijklmnopqrstuvwxyz')}
a = 'abcdefghijklmnopqrstuvwxyz'
s = S()
k = I()
ans = []
cnt = 0
for i in s:
    if 26 - D[i] <= k:
        k -= 26 - D[i]
        ans += ['a']
    else:
        ans += [i]

if k:
    ans[-1] = a[(D[ans[-1]] + k) % 26]


print(''.join(ans))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


s = S()
k = I()
ans = ''
for i in s:
    if 123 - ord(i) <= k:
        k -= 123 - ord(i)
        ans += 'a'
    else:
        ans += i


print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
K = int(input())
n = len(s)
for i in range(n-1):
    m = ord('z') - ord(s[i]) + 1
    if m <= K:
        s[i] = 'a'
        K -= m
s[n-1] = chr((ord(s[n-1])+K-97)%26+97)
print(''.join(s))

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,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()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
r = [ord('z') - ord(t) + 1 for t in s]
res = [None] * n
k = inp()
for i,x in enumerate(r):
    if x <= k:
        res[i] = 'a'
        k -= x
if k > 0:
    tmp = 'a' if res[-1] != None else s[-1]
    res[-1] = chr((ord(tmp) - ord('a') + k)%26 + ord('a'))
for i,t in enumerate(res):
    if t == None:
        res[i] = s[i]
print(''.join(res))

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,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()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
r = [[ord('z') - ord(t) + 1, i] for i,t in enumerate(s)]
# print(r)
res = [None] * n
k = inp()
nx = n
for i,x in enumerate(r):
    if x[0] <= k:
        res[i] = 'a'
        k -= x[0]
if k > 0:
    tmp = res[-1] if res[-1] != None else s[-1]
    res[-1] = chr((ord(tmp) - ord('a') + k)%26 + ord('a'))
# print(res)
for i,t in enumerate(res):
    if t == None:
        res[i] = chr(-r[i][0]+ord('z')+1)
print(''.join(res))

Submission status: Wrong Answer

Solution code:
s = list(input())
K = int(input())
def plus(c,i):
    return chr((ord(c)-ord('a')+i)%26+ord('a'))
# 上から順に回るなら回す
for i,ss in enumerate(s):
    want = (ord('z') + 1 - ord(ss))%26
    if K >= want:
        print(i,K,want)
        s[i] = plus(s[i],want)
        K = K - want
    
K = K % 26
if K >= 1:
    s[-1] = plus(s[-1],K)
print("".join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
K = int(input())
def plus(c,i):
    return chr((ord(c)-ord('a')+i)%26+ord('a'))
# 上から順に回るなら回す
for i,ss in enumerate(s):
    want = ord('z') + 1 - ord(ss)
    if K >= want:
        s[i] = plus(ss,want)
        K = K - want
K = K % 26
if K >= 1:
    s[-1] = plus(s[-1],K)
print("".join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
K = int(input())
def plus(c,i):
    return chr((ord(c)-ord('a')+i)%26+ord('a'))

# 上から順に回るなら回す
for i,ss in enumerate(s):
    want = ord('z') + 1 - ord(ss)
    if K >= want:
        s[i] = plus(ss,want)
        K = K - want
if K >= 1:
    s[-1] = plus(s[-1],K)
print("".join(s))

Submission status: Wrong Answer

Solution code:
#codinf utf-8
s = list(input())
K = int(input())
N = len(s)
alp = [chr(i) for i in range(97, 97+26)]

for i in range(N):
    idx = alp.index(s[i])
    if K + idx >= 26:
        K = K - ( 26 - idx )
        s[i] = 'a'
    if K == 0:
        break
    
if K > 0:
    id = alp.index(s[N-1])

    id_ = ( id + K ) % 26

    s[N-1] = alp[id_]

print(''.join(s))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    k = int(input().strip())
    ans = []
    for i, c in enumerate(s):
        if i == len(s)-1:
            ans.append(chr(ord('a') + (ord(c) + k % 26 - ord('a')) % 26))
            break
        d = ord('z') - ord(c) + 1
        if d <= k:
            k -= d
            ans.append('a')
        else:
            ans.append(c)
    print(''.join(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    k = int(input().strip())
    ans = []
    for i, c in enumerate(s):
        if i == len(s)-1:
            ans.append(chr(ord('a') + (ord(c) + k % 26 - ord('a')) % 26))
            break
        d = ord('z') - ord(c) + 1
        if d < k:
            k -= d
            ans.append('a')
        else:
            ans.append(c)
    print(''.join(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# print("a:{} z:{}".format(ord("a"), ord("z")))
a_code = 97
z_code = 122
ans = ""
for i,si in enumerate(s):
    code = ord(si)
    # 末尾なら残り操作を全て適用
    if i == (length-1):
        code += K%26
        ans += chr(code if code <= z_code else code-26)
        break
    count = z_code - code + 1
    if count > K:
        ans += si
        continue
    K -= count
    ans += "a"

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
V = []
for e in S:
    V.append(ord(e)-97)
for i in range(len(S)):
    if K < 26-V[i]:
        pass
    else:
        K -= 26-V[i]
        V[i] = 0
V[-1] += K
V[-1] %= 26
V = [chr(e+97) for e in V]
print("".join(V))

Submission status: Wrong Answer

Solution code:
import string

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

str=string.ascii_lowercase
abc=str+str

s_len=len(s)
for i in range(s_len):
  si_inx=abc.index(s[i])

  if i==s_len-1:
    k%=26
    s[i]=abc[si_inx+k]
    break

  if k>=26-si_inx:
    k-=26-si_inx
    s[i]='a'
  else:
    continue

  if k<=0:
    break

print(''.join(s))

Submission status: Wrong Answer

Solution code:
import sys
#input = sys.stdin.buffer.readline

def main():
    s = list(input())
    K = int(input())
    
    l = len(s)
    for i in range(l-1):
        moji = s[i]
        a = ord("z")-ord(moji)+1
        if a <= K:
            s[i] = "a"
            K -= a

    rest = ((ord(s[-1])+K)%97)%26
    s[-1] = chr(rest+97)
    print("".join(map(str,s)))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
ints = [ord(i) - ord('a') for i in s]
K = int(input())
n = len(s)
i = 0
while i < n:
    if ints[i] != 0 and 25 - ints[i] + 1 <= K:
        K -= 25 - ints[i] + 1
        ints[i] = 0
    i += 1

K %= 26
ints[-1] = (ints[-1] + K) % 26
s_ = ''
for i in ints:
    s_ += chr(i + ord('a'))

print(s_, K)

Submission status: Wrong Answer

Solution code:
s = input()
ints = [ord(i) - ord('a') for i in s]
K = int(input())
n = len(s)
i = 0
while i < n:
    if 25 - ints[i] + 1<= K:
        K -= 25 - ints[i] + 1
        ints[i] = 0
    i += 1

K %= 26
ints[-1] = (ints[-1] + K) % 26
s_ = ''
for i in ints:
    s_ += chr(i + ord('a'))

print(s_)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
m=len(s)
box=[chr(i) for i in range(97,97+26)]

word={j:26-i for i,j in enumerate(box)}
word_num={26-i:j for i,j in enumerate(box)}
number={i:j for i,j in enumerate(box)}
ans=""

for i,j in enumerate(s):
    if i==m-1 and k>0:
        k %=26
        if k>=word[j]:ans +=number[k-word[j]]
        else:ans +=word_num[word[j]-k]
    elif word[j]<=k:
        k -=word[j]
        ans +="a"
    else:ans +=j

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
m=len(s)
box=[chr(i) for i in range(97,97+26)]

word={j:26-i for i,j in enumerate(box)}
word_num={26-i:j for i,j in enumerate(box)}
number={i:j for i,j in enumerate(box)}
ans=""

for i,j in enumerate(s):
    if i==m-1:
        k %=26
        if k>=word[j]:ans +=number[k-word[j]]
        else:ans +=word_num[word[j]-k]
    elif word[j]<=k:
        k -=word[j]
        ans +="a"
    else:ans +=j

print(ans)

Submission status: Wrong Answer

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

word={j:26-i for i,j in enumerate([chr(_) for _ in range(97,97+26)])}
number={i:j for i,j in enumerate(chr(_) for _ in range(97,97+26))}
number[26]="a"
ans=""

for i,j in enumerate(s):
    if i==m-1 and k>0:
        k %=26
        if k>word[j]:ans +=number[k-word[j]]
        else:ans +=number[26-word[j]+k]
    elif word[j]<=k:
        k -=word[j]
        ans +="a"
    else:ans +=j

print(ans)

Submission status: Wrong Answer

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

word={j:26-i for i,j in enumerate([chr(_) for _ in range(97,97+26)])}
number={i:j for i,j in enumerate(chr(_) for _ in range(97,97+26))}
ans=""

for i,j in enumerate(s):
    if word[j]<=k:
        k -=word[j]
        ans +="a"
    elif i==m-1 and k>0:
        k %=26
        if k>word[j]:ans +=number[k-word[j]]
        else:ans +=number[26-word[j]+k]
    else:ans +=j

print(ans)

Submission status: Wrong Answer

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

word={j:26-i for i,j in enumerate([chr(_) for _ in range(97,97+26)])}
number={i:j for i,j in enumerate(chr(_) for _ in range(97,97+26))}
ans=""

for i,j in enumerate(s):
    if word[j]<=k:
        k -=word[j]
        ans +="a"
    elif i==m-1 and k>0:
        k %=26
        if word[j]>k:ans +=number[26-word[j]+k]
        else:ans +=number[k-word[j]]
    else:ans +=j

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
l = [26 - (ord(c) - ord('a')) % 26 for c in s]
for i in range(len(s) - 1):
    if k >= l[i]:
        k -= l[i]
        s = s[:i] + 'a' + s[i + 1 :]

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

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
l = [26 - (ord(c) - ord('a')) for c in s]
for i in range(len(s) - 1):
    if k >= l[i]:
        k -= l[i]
        s = s[:i] + 'a' + s[i + 1 :]

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

Submission status: Wrong Answer

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

res=[]
for i in range(len(s)):
    num = ord(s[i])-97

    if i==len(s)-1:
        res.append(chr((num+k)%26+97))
    elif 26 - num <= k:
        res.append("a")
        k-=26-num
    else:
        res.append(s[i])

print("".join(res))

Submission status: Wrong Answer

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

res=[]
for i in range(len(s)):
    num = ord(s[i])-97

    if i==len(s)-1:
        res.append(chr((num+k)%26+97))
    elif 26 - num < k:
        res.append("a")
        k-=26-num
    else:
        res.append(s[i])

print("".join(res))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
alp = 'bcdefghijklmnopqrstuvwxyza'
for i in range(len(s)):
    t = alp.index(s[i])
    if k >= 25-t:
        s = s[:i] + 'a' + s[i+1:]
        k -= 25-t
    elif i == len(s)-1:
        s = s[:i] + alp[k+t%26]
print(s)

Submission status: Wrong Answer

Solution code:
s = input()
l = ''
n = int(input())
alp = [chr(ord('a')+i) for i in range(26)]
for i in range(len(s)):
  if i != len(s)-1:
    if 97+26-ord(s[i]) <= n:
      n -= (123-ord(s[i]))
      l += 'a'
    else:
      l += s[i]
  else:
    t = ord(s[i])
    if t+n <= 122:
      l += chr(t+n)
    else:
      n = n%26
      if t+n <= 122:
        l += chr(t+n)
      else:
        l += chr(t+n-26)
print(l)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

if K != 0:
  n = ord(S[-1])
  n -= ord('a')
  n += K
  n %= ord('z') - ord('a') + 1
  n += ord('a')
  S[-1] = chr(n)
print(''.join(S))

Submission status: Wrong Answer

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

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

if K != 0:
  n = ord(S[-1])
  n -= ord('a')
  n += K
  n %= ord('z') - ord('a')
  n += ord('a')
  S[-1] = chr(n)
print(''.join(S))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
ans = ""
l = 26
for i in range(len(s)-1):
    if l - ord(s[i]) + 97 <= k:
        k -= l - ord(s[i]) + 97
        ans += "a"
    else:
        ans += s[i]
ans += (chr(((ord(s[-1]) - 97) + k + l**100) % l + 97))
print(ans)

Submission status: Wrong Answer

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

ans = ''
for i, c in enumerate(s):
    dif = ord('z') - ord(c) + 1
    if i == len(s) - 1:
        K %= 26
        if ord(c) + K > ord('z'):
            K -= 26
        ans += chr(ord(c) + K)
    elif dif <= K:
        ans += 'a'
        K -= dif
    else:
        ans += c
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    ans = list(s[:])
    k = int(input().strip())
    for i in range(len(s)):
        d = ord('z') - ord(s[i]) + 1
        if k - d >= 0:
            ans[i] = 'a'
            k -= d
        if i == len(s) - 1:
            # print((ord(ans[i]) + k%26) % 26)
            ans[i] = chr(ord('a') + (ord(ans[i]) - ord('a') + k%26) % 26)
    print(''.join(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    ans = list(s[:])
    k = int(input().strip())
    for i in range(len(s)):
        d = ord('z') - ord(s[i]) + 1
        if k - d >= 0:
            ans[i] = 'a'
            k -= d
        if i == len(s) - 1:
            # print((ord(ans[i]) + k%26) % 26)
            ans[i] = chr(ord('a') + (ord(ans[i]) + k%26) % 26)
    print(''.join(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    ans = list(s[:])
    k = int(input().strip())
    for i in range(len(s)):
        d = ord('z') - ord(s[i]) + 1
        if k - d >= 0:
            ans[i] = 'a'
            k -= d
        if i == len(s) - 1:
            ans[i] = chr(ord(ans[i]) + k%26)
    print(''.join(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = str(input())
n = int(input())
k = ord("z")
a = [0]*len(s)
for i in range(len(s)):
    a[i] = ord(s[i])
for i in range(len(s)):
    if n>=k+1-a[i]:
        n = n-k-1+a[i]
        a[i] = ord("a")
    
    if n<=0:
        break
if n>0:
    a[-1] += n%26
ans = ""
for i in range(len(s)):
    ans += chr(a[i])
print(ans)

Submission status: Wrong Answer

Solution code:
alf = {c:i for i,c in enumerate('abcdefghijklmnopqrstuvwxyz')}
a = 'abcdefghijklmnopqrstuvwxyz'
s = input()
k = int(input())
diff = [26-alf[c] if c != a else 0 for c in s]
ans = []
for i in range(len(s)):
    if k >= diff[i]:
        ans.append('a')
        k -= diff[i]
    else:
        ans.append(s[i])
    # print(ans,k)
if k > 0:
    ans[-1] = a[(alf[ans[-1]] + k % 26)]
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
alf = {c:i for i,c in enumerate('abcdefghijklmnopqrstuvwxyz')}
a = 'abcdefghijklmnopqrstuvwxyz'
s = input()
k = int(input())
diff = [26-alf[c] for c in s]
diff[0] = 0
ans = []
for i in range(len(s)):
    if k >= diff[i]:
        ans.append('a')
        k -= diff[i]
    else:
        ans.append(s[i])
    # print(ans,k)
if k > 0:
    ans[-1] = a[(alf[ans[-1]] + k % 26)]
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
alf = {c:i for i,c in enumerate('abcdefghijklmnopqrstuvwxyz')}
a = 'abcdefghijklmnopqrstuvwxyz'
s = input()
k = int(input())
diff = [26-alf[c] for c in s]
ans = []
for i in range(len(s)):
    if k >= diff[i]:
        ans.append('a')
        k -= diff[i]
    else:
        ans.append(s[i])
if k > 0:
    ans[-1] = a[(alf[ans[-1]] + k % 26)]
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
alf = {c:i for i,c in enumerate('abcdefghijklmnopqrstuvwxyz')}
a = 'abcdefghijklmnopqrstuvwxyz'
s = input()
k = int(input())
t = [26-alf[c] for c in s]
ans = []
for i in range(len(s)):
    if k >= t[i]:
        ans.append('a')
        k -= t[i]
        t[i] = 26
    else:
        ans.append(s[i])
if k > 0:
    ans[-1] = a[(alf[ans[-1]] + k) % 26]
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
a=input()
n=len(a)
m=int(input())
ans=""
for i in range(n-1):
  x=ord(a[i])-97
  if m>=26-x:
    ans += "a"
    m -= 26-x
  else:
    ans += a[i]
ans += chr((ord(a[n-1])-97+m)%26+97)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
alp = 'abcdefghijklmnopqrstuvwxyz'

ans = ''
for i,w in enumerate(s):
    if (26-(ord(w)-ord('a')))%26 <= K:
        ans += 'a'
        K -= (26-(ord(w)-ord('a')))%26
    elif i != len(s)-1:
        ans += w
    elif i == len(s)-1:
        #ans = ans[:-1]
        lastlidx = (ord(w)-ord('a') + K%26)%26
        ans += alp[lastlidx]
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_c
# 前の方からgreedyに`a`に変えていって、残った回数は最後の一文字で無限に回す?


def ord_until_a(char):
    return ord('a') + 26 - ord(char)


S = input()
K = int(input())
ans = []
for s in S:
    diff = ord_until_a(s)
    if K >= diff:
        ans.append('a')
        K -= diff
    else:
        ans.append(s)

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

print(''.join(ans))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_c
# 前の方からgreedyに`a`に変えていって、残った回数は最後の一文字で無限に回す


def ord_until_a(char):
    return ord('a') + 26 - ord(char)


S = input()
K = int(input())
ans = []
for s in S:
    diff = ord_until_a(s)
    if K >= diff:
        ans.append('a')
        K -= diff
    else:
        ans.append(s)

if K > 0:
    K %= 26
    last = ord(s) + K
    if last > ord('z'):
        last -= 26
    ans[-1] = chr(last)

print(''.join(ans))

Submission status: Wrong Answer

Solution code:
import bisect
alp = 'abcdefghijklmnopqrstuvwxyz'
alp_dict = {s:i for i, s in enumerate('abcdefghijklmnopqrstuvwxyz')}
N = len(alp)
S = input()
K = int(input())

if K>=len(S)*(N-1):
  K = K%N
  print('a'*(len(S)-1) + alp[(alp_dict[S[-1]]+K)%N])
  exit()
  
ans = ''
for s in S:
  i = alp_dict[s]
  if K>=N-i:
    ans += 'a'
    K -= N-i
  else:
    ans += s
if K == 0:
  print(ans)
else:
  K = K%N
  last_s = alp[(alp_dict[ans[-1]]+K)%N]
  print(ans[:-1] + last_s)

Submission status: Wrong Answer

Solution code:
import bisect
alp = 'abcdefghijklmnopqrstuvwxyz'
alp_dict = {s:i for i, s in enumerate('abcdefghijklmnopqrstuvwxyz')}
N = len(alp)
S = input()
K = int(input())

if K>=len(S)*(N-1):
  K = K%N
  print('a'*len(S) + alp[(alp_dict[S[-1]]+K)%N])
  exit()
  
ans = ''
for s in S:
  i = alp_dict[s]
  if K>=N-i:
    ans += 'a'
    K -= N-i
  else:
    ans += s
if K == 0:
  print(ans)
else:
  K = K%N
  last_s = alp[(alp_dict[ans[-1]]+K)%N]
  print(ans[:-1] + last_s)

Submission status: Wrong Answer

Solution code:
import bisect
alp = 'abcdefghijklmnopqrstuvwxyz'
alp_dict = {s:i for i, s in enumerate('abcdefghijklmnopqrstuvwxyz')}
N = len(alp)
S = input()
K = int(input())

if K>=len(S)*N:
  print('a'*len(S))
  exit()

ans = ''
for s in S:
  i = alp_dict[s]
  if K>=N-i:
    ans += 'a'
    K -= N-i
  else:
    ans += s
if K == 0:
  print(ans)
else:
  K = K%N
  last_s = alp[(alp_dict[ans[-1]]+K)%N]
  print(ans[:-1] + last_s)

Submission status: Wrong Answer

Solution code:
import bisect
alp = 'abcdefghijklmnopqrstuvwxyz'
alp_dict = {s:i for i, s in enumerate('abcdefghijklmnopqrstuvwxyz')}
N = len(alp)
S = input()
K = int(input())

if K>=len(S)*N:
  print('a'*N)
  exit()

ans = ''
for s in S:
  i = alp_dict[s]
  if K>=N-i:
    ans += 'a'
    K -= N-i
  else:
    ans += s
if K == 0:
  print(ans)
else:
  K = K%N
  last_s = alp[(alp_dict[ans[-1]]+K)%N]
  print(ans[:-1] + last_s)

Submission status: Wrong Answer

Solution code:
alp = 'abcdefghijklmnopqrstuvwxyz'
N = len(alp)
S = input()
K = int(input())
ans = ''
for s in S:
  i = alp.find(s)
  if K>=N-i:
    ans += 'a'
    K -= N-i
  else:
    ans += s
if K == 0:
  print(ans)
else:
  K = K%N
  last_s = alp[(S.find(ans[-1])+K)%N]
  print(ans[:-1] + last_s)

Submission status: Wrong Answer

Solution code:
s = input().strip()
K = int(input())
cnt = 0
x = ""
for i in range(len(s)):
    if (26-(ord(s[i])-ord("a")))%26 <= K-cnt:
        x += "a"
        cnt += (26-(ord(s[i])-ord("a")))%26
    else:
        x += s[i]
print(x)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import string
s = (stdin.readline().rstrip())
K = int(stdin.readline().rstrip())
alp = string.ascii_lowercase*2
ans = ""
cnt = 0
for i in s:
    ind = alp.index(i)
    for j in alp[ind+1:]:
        cnt += 1
        if K - cnt < 0:
            ans += i
            cnt = 0
            break
        if j == "a":
            ans += "a"
            K = K - cnt
            cnt = 0
            break
if K != 0:
    ind = (K % 26) + alp.index(ans[-1])
    ans = ans[:-1]+alp[ind]
print(ans)

Submission status: Wrong Answer

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

    s = list(map(lambda x: ord(x), s))
    B = [0 for _ in range(len(s))]
    for i in range(len(s)):
        b = 26 - (s[i] - ord("a"))
        if b == 26:
            B[i] = 0
        elif b < K:
            K -= b
            B[i] = 0
        else:
            B[i] = b

    if K != 0:
        B[-1] -= K
        B[-1] %= 26

    ans = list(map(lambda c: chr(ord("a") + (26 - c) % 26), B))
    print("".join(ans))


main()

Submission status: Wrong Answer

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

    s = list(map(lambda x: ord(x), s))
    B = [0 for _ in range(len(s))]
    for i in range(len(s)):
        b = 26 - (s[i] - ord("a"))
        if b < K:
            K -= b
            B[i] = 0
        else:
            B[i] = b

    if K != 0:
        B[-1] -= K
        B[-1] %= 26

    ans = list(map(lambda c: chr(ord("a") + (26 - c) % 26), B))
    print("".join(ans))


main()

Submission status: Wrong Answer

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

    s = list(map(lambda x: ord(x), s))
    B = [0 for _ in range(len(s))]
    for i in range(len(s)):
        b = 26 - (s[i] - ord("a"))
        if b <= K:
            K -= b
            B[i] = 0
        else:
            B[i] = b

    if K != 0:
        B[-1] -= K
        B[-1] %= 26

    ans = list(map(lambda c: chr(ord("a") + (26 - c) % 26), B))
    print("".join(ans))


main()

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.buffer.readline


def main():
    s = list(readline())
    s = s[:-1]
    K = int(readline())

    B = [0 for _ in range(len(s))]
    for i in range(len(s)):
        b = 26 - (s[i] - ord("a"))
        if b <= K:
            K -= b
            B[i] = 0
        else:
            B[i] = b

    if K != 0:
        B[-1] -= K
        B[-1] %= 26

    ans = list(map(lambda c: chr(ord("a") + (26 - c) % 26), B))
    print("".join(ans))


main()

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.buffer.readline


def main():
    s = list(readline())
    s = s[:-1]
    K = int(readline())

    B = [0 for _ in range(len(s))]
    for i in range(len(s)):
        b = 26 - (s[i] - ord("a"))
        if b <= K:
            K -= b
            B[i] = 0
        else:
            B[i] = b

    if K != 0:
        B[-1] = (B[-1] - K) % 26

    ans = list(map(lambda c: chr(ord("a") + (26 - c) % 26), B))
    print("".join(ans))


main()

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.buffer.readline


def main():
    s = list(readline())
    s = s[:-1]
    K = int(readline())

    B = [0 for _ in range(len(s))]
    for i in range(len(s)):
        b = 26 - (s[i] - ord("a"))
        if b <= K:
            K -= b
            B[i] = 0
        else:
            B[i] = b

    if K != 0:
        B[-1] -= K

    ans = list(map(lambda c: chr(ord("a") + (26 - c) % 26), B))
    print("".join(ans))


main()