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: Runtime Error

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

d = [0] * n
for i in range(n):
    if s[i] != 'a':
        d[i] = ord('z') - ord(s[i]) + 1

ans = list(s)
for i in range(n):
    if d[i] != 0 and d[i] <= k:
        k -= d[i]
        c = ord(s[i]) + d[i]
        ans[i] = chr(c - ord('z') + ord('a') - 1) if c > ord('z') else chr(c)
    if k == 0: break
    if i == n-1:
        ans[i] = chr(ord(s[i]) + k)

print(''.join(ans))

Submission status: Runtime Error

Solution code:
def codefes16qa_c():
    s = str(input())
    k = int(input())
    n = len(s)
    ans = ''
    for i in range(n):
        step2a = 1 + ord('z') - ord(s[i])
        if step2a <= k:
            ans += 'a'
            k -= step2a
        else:
            ans += s[i]
    if k > 0:
        last = ord(ans[-1]) + k
        ans = ans[:n-1] + chr(last)
    print(ans)

codefes16qa_c()

Submission status: Runtime Error

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

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = list(input()) #sys.stdin.readlineは最後が改行
k = int(input())

now = 0

while k>0 and now<len(s):
    tmp = ord('z')-ord(s[now])+1
    if tmp<=k:
        s[now] = 'a'
        k -= tmp
        now+=1
    else:
        now+=1

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

print(*s,sep='')

Submission status: Runtime Error

Solution code:
X='abcdefghijklmnopqrstuvwxyz'*2
S=input()
k=int(input())
N=[]
for s in S:
    if s=='a':
        N.append(0)
    else:
        N.append(26-X.index(s))
ans=''
for i in range(len(S)):
    if N[i]<=k :
        k-=N[i]
        ans+='a'
    else:
        ans+=S[i]
ans=ans[:-1]+X[X.index(ans[-1])+k]

print(ans)

Submission status: Runtime Error

Solution code:
X='abcdefghijklmnopqrstuvwxyz'*2
S=input()
k=int(input())
N=[]
for s in S:
    if s=='a':
        N.append(0)
    else:
        N.append(26-X.index(s))
ans=''
for i in range(len(S)):
    if N[i]<=k :
        k-=N[i]
        ans+='a'
    else:
        ans+=S[i]
ans=ans[:-1]+X[X.index(ans[i])+k]

print(ans)

Submission status: Runtime Error

Solution code:
from _collections import deque
X='abcdefghijklmnopqrstuvwxyz'*2
S=input()
k=int(input())
N=deque([])
for s in S:
    if s=='a':
        N.append(0)
    else:
        N.append(26-X.index(s))
important=0
for i in range(len(S)):
    if N[i]<=k :
        k-=N[i]
    else:
        important=i
        break
ans2=''
for i in range(important,len(S)-1):
    if N[i]<=k:
        ans2+='a'
        k-=N[i]
    else:
        ans2+=X[X.index(S[i])]

print('a'*important+ans2+X[X.index(S[-1])+k])

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_c

s = input()
k = int(input())
n = len(s)
ans = []
for i in range(n):
    t = (ord('z') - ord(s[i]) + 1) % 26
    if t <= k:
        ans.append('a')
        k -= t
    else:
        ans.append(s[i])
ans[-1] = chr(ord(ans[-1]) + k)
print(''.join(ans))

Submission status: Runtime Error

Solution code:
s=input()
n=int(input())
l=""
for i in range(len(s)):
    f=(26+ord("a")-ord(s[i]))%26
    if n>=f:n-=f;l+="a"
    else:l+=s[i]
    if n==0:print(l+s[i+1:]);exit()
print(l[:-1]+chr(ord(l[-1])+n))

Submission status: Runtime Error

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

len_s = len(s)
moji = [0]*(len_s)

for i in range(len_s):
    num = 26-(ord(s[i])-ord('a'))
    if num <= k:
        moji[i] = 'a'
        k -= num
    else:
        moji[i] = s[i]
        
if k != 0:
    #print(k)
    moji[len_s-1] = chr(ord(moji[len_s-1])+k)
        
print(*moji,sep='')

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    a=list(input())
    K=int(input())
    for i in range(len(a)):
        val=123-ord(a[i])
        if val<=K:
            a[i]='a'
            K-=val
        if i==len(a)-1 and K>0:
            a[-1]=chr(ord(a[-1])+K)
    print(''.join(a))



resolve()

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
a2n = lambda c: ord(c) - ord('a') + 1
n2a = lambda c: chr(c+64).lower()
ls=list(s)
i=0
while k>0 and i<len(ls):
  a=(1-a2n(ls[i]))%26
  if k>=a:
    ls[i]='a'
    k-=a
  i+=1
if k>0:
  ls[-1]=n2a(a2n(ls[-1])+k)
print(''.join(ls))

Submission status: Runtime Error

Solution code:
s=list(input())
N=len(s)
K=int(input())
num=123

for i in range(N):
    diff=(num-ord(s[i]))%26
    if K==0:
        break
    if diff<=K:
        s[i]="a"
        K=K-diff
#print(s)
if K>0:
    s[N-1]=chr(ord(s[N-1])+K)
#print(s)
print("".join(s))

Submission status: Runtime Error

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

for i in range(len(sl)):
    ord_s = ord(sl[i])
    use = 123 - ord_s
    if k - use >= 0:
        sl[i] = "a"
        k -= use

if k > 0:
    sl[-1] = chr(ord(sl[-1]) + k)

print("".join(sl))

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
ss = [0]*len(s)
for i in range(len(s)):
    if k >= 26:
        k = k + ord(s[i])-97-26
        ss[i] = "a"
    elif 97+26 - ord(s[i]) <= k:
        k = k + ord(s[i])-97-26
        ss[i] = "a"
    else:
        ss[i] = s[i]
if k != 0:
    ss[-1] = chr(ord(s[-1])+k)

for i in range(len(s)):
    print(ss[i],end='')
print()

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
ss = [0]*len(s)
for i in range(len(s)):
    if k >= 26:
        k = k + ord(s[i])-97-26
        ss[i] = 'a'
    elif 97+26 - ord(s[i]) <= k:
        k = k + ord(s[i])-97-26
        ss[i] = 'a'
    else:
        ss[i] = s[i]
ss[-1] = chr(ord(s[-1])+k)
#print((ss))

for i in range(len(s)):
    print(ss[i],end='')
print()

Submission status: Runtime Error

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

result=""
for ss in s:
    if ss=="a":
        result+="a"
    else:
        if k>= 123 - ord(ss):
            k-=123-ord(ss)
            result+="a"
        else:
            result+=ss


if k>0:
    k=k%(123-97)
    temp=chr((((ord(result[-1])-97)+k)%(123-97))+97)
    
print(result[:-1]+temp)

#print(ord("a")):97
#print(ord("b")):98
#print(ord("z")):122
#97ならそのまま
#aにするには123-ord()をすればいい

Submission status: Runtime Error

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

result=""
for ss in s:
    if ss=="a":
        result+="a"
    else:
        if k>= 123 - ord(ss):
            k-=123-ord(ss)
            result+="a"
        else:
            result+=ss



print(result[:-1]+chr(ord(result[-1])+k))

#print(ord("a")):97
#print(ord("b")):98
#print(ord("z")):122
#97ならそのまま
#aにするには123-ord()をすればいい

Submission status: Runtime Error

Solution code:
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    s = list(input())
    k = int(input())
    for i in range(len(s)):
        if s[i] == 'a':
            continue
        if k >= ord('z') - ord(s[i]) + 1:
            k -= ord('z') - ord(s[i]) + 1
            s[i] = 'a'
            if k == 0:
                break
    
    if k > 0:
        s[-1] = chr(ord(s[-1]) + k)
    
    print(''.join(s))
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    s = list(input())
    k = int(input())
    for i in range(len(s)):
        if s[i] == 'a':
            continue
        if k >= ord('z') - ord(s[i]) + 1:
            k -= ord('z') - ord(s[i]) + 1
            s[i] = 'a'
            if k == 0:
                break
        else:
            i += 1
    
    if k > 0:
        s[-1] = chr(ord(s[-1]) + k)
    
    print(''.join(s))
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

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

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    ans = ""
    k = I()
    for i,si in enumerate(s):
        if si == "a":
            ans += si
            continue
        j = (ord("a")-ord(si))%26
        if j <= k:
            k -= j
            ans += "a"
        else:
            ans += si
    k %= 26
    print(ans[:-1]+chr(ord(ans[-1])+k))
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
s=input()
K=int(input())
znum=ord("z")
count=0
ans=[]
for i in range(len(s)):
    num=ord(s[i])
    if s[i]=="a":
        ans.append("a")
        continue
    sa=znum-num+1
    if (count+sa)<=K:
        ans.append("a")
        count+=sa
    else:
        ans.append(s[i])

if count<K:
    num=ord(s[-1])
    num+=(K-count)
    itr=chr(num)
    S=""
    for i in range(len(ans)):
        if i==(len(ans)-1):
            S=S+itr
            continue
        S=S+ans[i]
else:
    S=""
    for i in range(len(ans)):
        S=S+ans[i]
        
print(S)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
k = int(input())
al = [chr(ord('a') + i) for i in range(26)]
ans = ''
for i in range(len(s)):
    num = al.index(s[i])
    if 26 - num <= k:
        k -= 26 - num
        if i != len(s) - 1:
            ans += 'a'
        else:
            ans += al[k]
    else:
        if i != len(s) - 1:
            ans += s[i]
        else:
            ans += al[num + k]
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
s=input()
K=int(input())

ans=[]
#122
for item in s[:len(s)-1]:
    cost=(123-ord(item))
    if K>=cost:
        K-=cost
        ans.append("a")
    else:
        ans.append(item)

last=ord(s[-1])
if last+K>122:
    ans.append(chr(last+K-26))
else:
    ans.append(chr(last+K))

print("".join(ans))

Submission status: Runtime Error

Solution code:
def main():
    word = list(input())
    operation = int(input())
    cost = {}
    for i in range(26):
        cost[chr(ord("a") + i)] = ord("z") - ord("a") - i + 1
    for i in range(len(word)):
        if cost[word[i]] <= operation:
            operation -= cost[word[i]]
            word[i] = "a"
        else:
            continue
    if 0 < operation:
        for i in range(-1, -len(word)-1, -1):
            word[i] = chr(ord(word[i]) + operation)
            operation = 0
            break
    print("".join(word))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    # aまでの必要な回数
    if S[idx] == "a" and idx < L-1:
        idx += 1
        continue
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            # aまで操作できないのに、操作すると辞書順でより後ろの文字列になってしまうので、次の文字へ
            idx += 1
        else:
            # 一番後ろの場合
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        K -= k
        S[idx] = "a"
        idx += 1

print("".join(S))

Submission status: Runtime Error

Solution code:
S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    # aまでの必要な回数
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            idx += 1
        else:
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        K -= k
        S[idx] = "a"
        idx += 1

print("".join(S))

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
slen = len(s)
new_s = ""

for i in range(slen):
  val = ord("z") + 1 - ord(s[i])
  if k >= val:
    k -= val
    new_s += "a"
  else:
    new_s += s[i]
    
if k > 0:
  new_s = new_s[:-1] + chr(ord(s[slen-1]) + k)

print(new_s)

Submission status: Runtime Error

Solution code:
t="abcdefghijklmnopqrstuvwxyz"
s=input()
k=int(input())
a=[t.index(i)for i in s]
ans=""
for i in a:
  if i==0:
    ans+="a"
    continue
  j=i
  if k>=26-i:
    k-=26-i
    j=0
  ans+=t[j]
j+=k
j%=26
ans=ans[:-1]+t[j]
print(ans)

Submission status: Runtime Error

Solution code:
a=list(input())
k=int(input())
al = "abcdefghijklmnopqrstuvwxyz"
alpha2num=lambda x:ord(x)-ord('a')+1
ans=[""]*len(a)

for i in range(len(a)):
    num=alpha2num(a[i])
    need=27-num
    if need==26:
        need=0
    if need<=k and i!=len(a)-1:
        ans[i]="a"
        k-=need
    elif need<=k and i==len(a)-1:
        remain=k%26
        if need<=remain:
            go=remain-need
        ans[-1]=chr(ord("a")+go)
    elif need>k and i!=len(a)-1:
        ans[i]=a[i]
    elif need>k and i==len(a)-1:
        ans[-1]=chr(ord(a[-1])+k)
print(''.join(ans))

Submission status: Runtime Error

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

for i in range(len(s)):
    num_al=ord(s[i])
    a_=123-num_al
    if k==0:break
    if s[i]=='a' and i!=len(s)-1:continue

    if a_<=k and i!=len(s)-1:
        k-=a_
        s[i]='a'
    elif a_>k and i<len(s)-1:continue
    else:
        s[i]=chr(num_al+k) if num_al+k<=122 else chr(num_al+k-26)
        k=0
print(''.join(s))

Submission status: Runtime Error

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

for i in range(len(s)):
    num_al=ord(s[i])
    a_=123-num_al
    if k==0:break
    if s[i]=='a' and i!=len(s)-1:continue

    if a_<=k and i!=len(s)-1:
        k-=a_
        s[i]='a'
    elif a_>k and i<len(s)-1:continue
    else:
        s[i]=chr(num_al+k) if num_al+k<=122 else chr(num_al+k-122)
        k=0
print(''.join(s))

Submission status: Runtime Error

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

ans = ""
for i,value in enumerate(s):
    ask = ord(value)
    if K + ord(value) - ord("a") > 26:
        ans = ans + "a"
        K -= ord("z")  - ord(value) + 1
    else:
        ans = ans + value
    
if K > 0:
    if ord(ans[-1]) + K > ord("z"):
        last = chr(ord(ans[-1]) + K -26)
        ans = ans[:-1] +last
    else:
        last = chr(ord(ans[-1]) + K )
        ans = ans[:-1] +last
        
print(ans)

Submission status: Runtime Error

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

ans = ""
for i,value in enumerate(s):
    
    ask = ord(value)
    if K + ord(value) - ord("a") > 26:
        ans = ans + "a"
        K -= ord("z")  - ord(value) + 1
    else:
        ans = ans + s[i:]
        break
    
if K > 0:
    if ord(ans[-1]) + K > ord("z"):
        last = chr(ord(ans[-1]) + K -26)
        ans = ans[:-1] +last
    else:
        last = chr(ord(ans[-1]) + K )
        ans = ans[:-1] +last
        
print(ans)

Submission status: Runtime Error

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
    S[-1] = chr(j)

print(''.join(S))

Submission status: Runtime Error

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

for i in range(len(S)):
    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
    S[-1] = chr(j)

print(''.join(S))

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
dls = list(map(str,input().split()))
while 1:
    s = str(n)
    for i in dls:
        if i in s:
            break
    else:
        print(n)
        exit()
    n += 1

Submission status: Runtime Error

Solution code:
s = input()
x = int(input())
tank = []
for c in list(s):
    if c=='a':
        tank.append(0)
    else:
        tank.append(ord('z') + 1 - ord(c))
res = ''
for i in range(len(tank)):
    if tank[i] == 0:
        res += s[i]
    elif tank[i] <= x:
        x -= tank[i]
        tank[i] = 0
        res += 'a'
    else:
        res += s[i]

c = res[-1]
if ord(c)+x <= ord('z'):
    res = res[:-1] + chr(ord(c)+x)
else:
    res = res[:-1] + chr(ord(c)+x-ord('z')+ord('a')-1)
print(res)

Submission status: Runtime Error

Solution code:
s = input()
x = int(input())
tank = []
for c in list(s):
    if c=='a':
        tank.append(0)
    else:
        tank.append(ord('z') + 1 - ord(c))
res = ''
for i in range(len(tank)):
    if tank[i] == 0:
        res += s[i]
    elif tank[i] <= x:
        x -= tank[i]
        tank[i] = 0
        res += 'a'
    else:
        res += s[i]
else:
    if x != 0:
        n = ord(s[-1])+x
        res = res[:-1] + chr(n)
print(res)

Submission status: Runtime Error

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 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: Runtime Error

Solution code:
S = list(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: Runtime Error

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

A = [" " for _ in range(K)]

zan = K
for i in range(len(S)):
  n = (ord('z') - ord(S[i]) + 1) % 26 # aに変換するのに必要な回数
  if zan >= n:
    zan -= n
    A[i] = 'a'
  else:
    A[i] = S[i]

if zan > 0:
  A[i] = chr((ord(A[i]) - ord('a') + zan)%26 + ord('a'))
print("".join(A))

Submission status: Runtime Error

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
ans = ""
for i in range(len(s)):
    ans += chr(a[i])
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)



int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif
    string s;
    cin >> s;
    int k, a;
    cin >> k;
    rep(i, s.length()-1){
        a = 'z' - s[i];
        if (k > a){
            k -= a + 1;
            s[i] = 'a';
        }
    }
    k %= 26;
    s[s.length()-1] += k;
    if (s[s.length()-1] > 'z')
        s[s.length()-1] -= 26;
    cout << s << endl;
    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=list(input())
K=int(input())
for i in range(len(s)-1):
    if s[i]!="a"
        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: Runtime Error

Solution code:
import bisect

alp = {s:i for i, s in enumerate('abcdefghijklmnopqrstuvwxyz')}
N = len(alp)
S = input()
K = int(input())
ans = ''
for s in S:
  i = alp[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: Runtime Error

Solution code:
s=input()
k=int(input())
sl=[]
n=len(s)
for i in range(n):
  if s[i]!='a':
    if 26-(ord(s[i])-97)<=k:
      sl.append('a')
      k-=26-(ord(s[i])-97)
    else:
      sl.append(s[i])
  else:
    sl.append(s[i])
if k>0:
  for i in range(n):
    sl[n-i-1]=chr(ord(sl[n-1-i])+k)
    break
print(''.join(sl))

Submission status: Runtime Error

Solution code:
from collections import deque
s=input()
money=int(input())
ans=deque()

d = dict(zip([chr(i) for i in range(97, 97+26)], range(0,26)))
d_r = dict(zip(range(0,26),[chr(i) for i in range(97, 97+26)]))

s_hash = deque([d[i] for i in s])

while len(s_hash)>0:
    #print(money,s_hash,ans)
    n = s_hash.popleft()
    if money >= 26 - n:
        ans.append(0)
        money -= 26 - n
    else:
        ans.append(n)
#print(money,s_hash,ans)
if money>0:
    n = ans.pop()
    ans.append(n+money)
    money = 0
    
print("".join([d_r[i] for i in ans]))

Submission status: Runtime Error

Solution code:
from collections import deque
s=input()
money=int(input())
ans=deque()

d = dict(zip([chr(i) for i in range(97, 97+26)], range(0,26)))
d_r = dict(zip(range(0,26),[chr(i) for i in range(97, 97+26)]))

s_hash = deque([d[i] for i in s])

while len(s_hash)>0:
    #print(money,s_hash,ans)
    n = s_hash.popleft()
    if money > 26 - n:
        ans.append(0)
        money -= 26 - n
    else:
        ans.append(n)
if money>0:
    n = ans.pop()
    ans.append(n+money)
    money = 0
print("".join([d_r[i] for i in ans]))

Submission status: Runtime Error

Solution code:
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    s=list(input())
    k=inp()
    for i in range(len(s)):
        s[i]=ord(s[i])
    for i in range(len(s)):
        if i==len(s)-1:
            s[i]+=k
            if s[i]>=123:
                s[i]-=26
        elif 123-s[i]<=k:
            k-=123-s[i]
            s[i]=97
        s[i]=chr(s[i])
    print(''.join(s))



if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# 2019-11-26 17:11:55(JST)
import sys
from string import ascii_lowercase as alph
ind_alph = dict((char, ind) for ind, char in enumerate(alph))

def main():
    s, k = sys.stdin.read().split()
    s = list(s)
    k = int(k)
    n = len(s)

    i = 0
    while k:
        j = ind_alph[s[i]]
        diff = (26 - j) % 26
        if diff <= k:
            s[i] = 'a'
            k -= diff
        if i == n - 1 and k:
                s[i] = alph[(s[i] + k) % 26]
                k = 0
        i += 1

    print(''.join(s))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
a=[ord(c)-ord('a') for c in input()]
K=int(input())

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

print(''.join(l))

Submission status: Runtime Error

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

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

print(s)

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
ss=[]
for i in range(len(s)):
	ss.append(ord(s[i])-ord("a"))
i=0
while k>0:
	if i==len(s)-1:
		ss[i]=(k+ss[i])%26
		break
	elif k>=26-ss[i]:
		k-=(26-ss[i])
		ss[i]=0
	i+=1
ans=""
for i in range(len(s)):
	ans+=chr(ord("a")+ss[i])
print(ans)


if len(ans)==1:
	print(2/0)
elif len(ans)<=3:
	for i in range(10**12):
		ans+="a"

Submission status: Runtime Error

Solution code:
s=input()
a=[ord(c)-ord('a') for c in s]
K=int(input())

# print(a) #DB

for i in range(len(s)):
    if 26-a[i]>K or a[i]==0:
        continue
    else:
        K-=26-a[i]
        a[i]=0

a[-1]+=K

print(''.join([chr(ord('a')+ai) for ai in a]))

Submission status: Runtime Error

Solution code:
s=input()
a=[ord(c)-ord('a') for c in s]
K=int(input())

# print(a) #DB

for i in range(len(s)):
    if 26-a[i]>K:
        continue
    else:
        K-=26-a[i]
        a[i]=0

a[-1]+=K

print(''.join([chr(ord('a')+ai) for ai in a]))

Submission status: Runtime Error

Solution code:
s = list(input())
K = int(input())
character = 'zabcdefghijklmnopqrstuvwxyza'
limit = len(s) - 1

here = 0
while K:
    tmp = character.find(s[here])
    if tmp + K > 26 and here != limit:
        K -= 26 - tmp + 1
        s[here] = 'a'
        here += 1
    elif here == limit:
        K %= 26
        s[here] = character[tmp + K]
        break
    else:
        here += 1
print(''.join(s))

Submission status: Runtime Error

Solution code:
s = list(input())
K = int(input())
character = 'zabcdefghijklmnopqrstuvwxyz'
limit = len(s) - 1

here = 0
while K:
    tmp = character.find(s[here])
    if tmp + K > 26:
        K -= 26 - tmp + 1
        s[here] = 'a'
    elif here == limit:
        s[here] = character[tmp + K]
        break
    here += 1

print(''.join(s))

Submission status: Runtime Error

Solution code:
s = [ord(x) - ord("a") for x in input()]
k = int(input())

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

s[-1] += k
print("".join([chr(x + ord("a")) for x in s]))

Submission status: Runtime Error

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

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

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

print(new)

Submission status: Runtime Error

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

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

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

print(new)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if k:
    s[-1]=chr(ord(s[-1])+k)

print("".join(s))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

ans = ''
for s in S:
    loc = alp.index(s)
    if s == 'a': continue
    if loc + K >= 26:
        K -= 26 - loc
        ans += 'a'
    else:
        ans += s
if K > 0:
    K %= 26
    ans = ans[:-1] + alp[(alp.index(ans[-1])+K)%26]
print(ans)

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

al=list('bcdefghijklmnopqrstuvwxyza')

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

Submission status: Runtime Error

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

abc="bcdefghijklmnopqrstuvwxyza"

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

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

print("".join(s))