Problem:


Score : 400 points

Problem Statement

Mr. Takahashi has a string s consisting of lowercase English letters.
He repeats the following operation on s exactly K times.

Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of z is a.

For example, if you perform an operation for the second letter on aaz, aaz becomes abz.
If you then perform an operation for the third letter on abz, abz becomes aba.

Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s.
Find the such string.

Constraints

1≤|s|≤10^5

All letters in s are lowercase English letters.

1≤K≤10^9

Input

The input is given from Standard Input in the following format:

s
K

Output

Print the lexicographically smallest string after performing exactly K operations on s.

Sample Input 1

xyz
4

Sample Output 1

aya

For example, you can perform the following operations: xyz, yyz, zyz, ayz, aya.

Sample Input 2

a
25

Sample Output 2

z

You have to perform exactly K operations.

Sample Input 3

codefestival
100

Sample Output 3

aaaafeaaivap



Sample input:
xyz
4


Sample output:
aya

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 24 21:28:20 2016

@author: dotha
"""

#aまでいけそうなら動かす。駄目そうならその項は終わり

def move(s, k):
    if len(s) == 1:
        return chr(97+(ord(s) + k - 97)%26)
    if s[0] == 'a' or 123-ord(s[0]) > k:
        return s[0] + move(s[1:], k)
    else:
        return 'a' + move(s[1:], k-(123-ord(s[0])))

def move_(l,k):
    if l =='a' or 123-ord(l) > k:
        return (l,k)
    else:
        return ('a', k-(123-ord(l)))

s = input()
K = int(input())
answer=[]
#print(move(s,K))

for l in s:
    (x,K) = move_(l,K)
    answer.append(x)

answer[-1] = chr(97++(ord(answer[-1]) + K - 97)%26)
    
print(''.join(answer))

Submission status: Accepted

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

for i in range(0, len(s)):
	if (s[i] != 'a'):
		if (122 - ord(s[i]) + 1 <= K):
			K -= (122 - ord(s[i]) + 1)
			s = s[:i] + 'a' + s[i+1:]
			if (K == 0):
				break

if (K >= 0):
	K %= 26
	x = ord(s[len(s) - 1]) + K
	lc = chr(x) if x <= 122 else chr(x - 26)
	s = s[:len(s) - 1] + lc

print (s)

Submission status: Accepted

Solution code:
def needed_to_flip(c):
    return ord('z') - ord(c) + 1

s = list(raw_input())
K = int(raw_input())
#s = list('xyz')
#K = 4


for i, c in enumerate(s):
	if c == 'a' and i != len(s) - 1:
		continue
	needed = needed_to_flip(c)
	#print "%s: needed: %d, has: %d" % (c, needed, K)
	if K >= needed:
		K -= needed
		s[i] = 'a'
		
	#print "flip: %s needed: %d, has: %d" % (s[i], needed,K) 
	if i == len(s) - 1:
		s[i] = chr(ord(s[i]) + (K % 26))

print ''.join(s)

Submission status: Accepted

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

def cord(c):
    return ord(c)-97

def cchr(n):
    return chr(n+97)

def smcheck(c, k):
    return 26-cord(c) <= k

def smcnt(c, k):
    return 26-cord(c)

ans = ''
for c in s:
    sc = smcnt(c, K)
    if sc <= K and sc < 26:
        K -= sc
        ans += cchr((cord(c) + sc)%26)
        # print(K,ans)
    else:
        ans += c
if K>26:
    K = K%26
if K>0:
    lc = ans[-1]
    ans = ans[:-1]
    ans += cchr((cord(lc)+K)%26)

print(ans)

Submission status: Accepted

Solution code:
s = raw_input()
K = int(raw_input())
s_list = list(s)
for i in range(len(s_list)):
    # how long does it take to force a
    lag = ord('z') - ord(s_list[i]) + 1
    if s_list[i] != 'a' and K >= lag and i < len(s_list) - 1:
        # not a and can conv
        s_list[i] = 'a'
        K -= lag
    elif i == len(s_list) - 1:
        s_list[i] = chr(ord('a') + ((ord(s_list[i]) - ord('a') + K) % 26))
print "".join(s_list)

Submission status: Accepted

Solution code:
import string

# -*- coding: utf-8 -*-
s = raw_input()
k = int(raw_input())

a_ls = list(string.ascii_lowercase)
a_len = len(a_ls)

end = ''

for c in s:
    idx = a_ls.index(c)
    for_overflow = a_len - idx
    if c is not 'a' and k - for_overflow >= 0:
        end += 'a'
        k -= for_overflow
    else:
        end += c

if k > 0:
    end = end[:len(end)-1] + a_ls[(a_ls.index(end[-1]) + k) % a_len]

# output
print end

Submission status: Accepted

Solution code:
s = list(raw_input())
k = input()
for i in xrange(len(s)-1):
    if s[i] == 'a':
        continue
    need = ord('z') - ord(s[i]) + 1
    if need <= k:
        k -= need
        s[i] = 'a'
s[-1] = chr(((ord(s[-1]) + k - ord('a')) % 26) + ord('a'))
print ''.join(s)

Submission status: Accepted

Solution code:
def dist(c):
    return (ord('z') - ord(c) + 1) % 26

s = list(input())
k = int(input())
i = 0
while 0 < k and i < len(s):
    d = dist(s[i])
    if d <= k:
        k -= d
        s[i] = 'a'
    i += 1

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

Submission status: Accepted

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

k = K

for i,s in enumerate(S):
    cost = ord('z')-ord(s)+1
    if cost <= k and s != "a":
        k-=cost
        S[i] = 'a'


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

print "".join(S)

Submission status: Accepted

Solution code:
s = raw_input()
k = int(raw_input())
albets = 'abcdefghijklmnopqrstuvwxyz'
dic = {}
for idx, letter in enumerate(albets):
    dic[letter] = 26 - idx
dic['a'] = 0
ans = ''
for l in s[:-1]:
    if k >= dic[l]:
        ans += 'a'
        k -= dic[l]
    else:
        ans += l
ans += albets[(26 - dic[s[-1]] + k) % 26]
print ans

Submission status: Accepted

Solution code:
o = ord('a')
s = [ord(c) - o for c in raw_input().strip()]
k = int(raw_input())
for i, c in enumerate(s):
    if c and 26 - c <= k:
        k -= 26 - c
        s[i] = 0
k %= 26
s[-1] += k
if s[-1] >= 26:
    s[-1] -= 26
print ''.join(chr(o + c) for c in s)

Submission status: Accepted

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

ORD_A = ord("a")


def str2list(s):
    return list(map(lambda c: ord(c) - ORD_A, s))


def list2str(xs):
    return "".join(map(lambda x: chr(x + ORD_A), xs))


def find_min(s, k):
    def to_a_cost(x):
        return (26 - x) % 26
    xs = str2list(s)
    n = len(s)
    for i in range(n):
        c = to_a_cost(xs[i])
        if c <= k:
            k -= c
            xs[i] = 0
    k %= 26
    for i in range(n)[::-1]:
        if xs[i] != 0:
            xs[i] += k
            break
    else:
        xs[-1] += k
    return list2str(xs)


def main():
    s = input()
    k = int(input())
    print(find_min(s, k))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def f(c):
    if c == "a":
        return 0
    return ord("z") - ord(c) + 1

s = input()
K = int(input())
ans = list(s)
for i, c in enumerate(s):
    n = f(c) 
    # print(c, n, K)
    if n <= K:
        ans[i] = "a"
        K -= n
if K > 0:
    ans[-1] = chr((ord(ans[-1]) - ord("a") + K) % 26 + ord("a"))
print("".join(ans))

Submission status: Accepted

Solution code:
s=raw_input()
k=int(raw_input())
news=""
for i in xrange(len(s)):
    if s[i]=='a':
        news+="a"
        continue
    tmp=ord('z')-ord(s[i])+1
    if k-tmp>=0:
        news+="a"
        k-=tmp
    else:
        news+=s[i]
if k>0:
    news=news[0:len(s)-1]+chr((k+ord(news[-1])-ord('a'))%26+ord('a'))
print(news)

Submission status: Accepted

Solution code:
import string

s=raw_input()
K=int(raw_input())
ans=''
for c in s:
    ci=string.lowercase.index(c)
    m=(26-ci)%26
    if K>=m:
        K-=m
        ans+='a'
    else:
        ans+=string.lowercase[ci]
K%=26
last=ans[-1]
lasti=string.lowercase.index(last)
nl=string.lowercase[lasti+K]
ans=ans[:-1]+nl
print ans

Submission status: Accepted

Solution code:
#[int(x)-1 for x in input().split()]
s= input()
K=int(input())
def can_change_to_a(st,remains):
    if ord('z')+1 - ord(st) <= remains:
        return True
    return False

s_ans = list(s)
for i,ch in enumerate(s):
    if ch=='a':
        continue
    if K >= ord('z')+1-ord(ch):
        K -= ord('z')+1-ord(ch)
        s_ans[i]='a'

s_ans[-1]= chr(  (ord(s_ans[-1])-ord('a')+K )%26 + ord('a'))

print(''.join(s_ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from __future__ import division, print_function, absolute_import, unicode_literals

S = input()
k = int(input())

ans = ''
for s in S:
    if s == 'a':
        ans += s
        continue
    # print(ord('z') - ord(s) + 1)
    tmp = ord('z') - ord(s) + 1
    if k >= tmp:
        ans += 'a'
        k -= tmp
    else:
        ans += s
if k > 0:
    k = k % 26
    ans = ans[:-1] + chr(ord(ans[-1]) + k)
print(ans)

Submission status: Accepted

Solution code:
from string import lowercase as alpha

morph = { ch : chr(ord(ch) + 1) for ch in alpha }
morph['z'] = 'a'
s = raw_input().strip()
a = list(s)
k = int(raw_input())

z_next = ord('z') + 1
for i, ch in enumerate(a):
    if ch == 'a':
        continue
    z_dist = z_next - ord(ch) 
    if z_dist <= k:
        k -= z_dist
        a[i] = 'a'
k %= 26
a[-1] = chr(ord(a[-1]) + k)

print(''.join(a))

Submission status: Accepted

Solution code:
s = map(ord, raw_input())
k = int(raw_input())

for i in xrange(len(s)):
    if s[i] == 97:
        continue
    n = 123 - s[i]
    if n <= k:
        s[i] = 97
        k -= n

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

print ''.join(map(chr, s))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

alpha = "abcdefghijklmnopqrstuvwxyz"

s = raw_input()
K = int(raw_input())
dic = dict([alpha[i], i] for i in xrange(len(alpha)))

ans = [] 
for si in s:
    d = 26 - dic[si] if si != "a" else 0
    if d <= K:
        ans.append("a")
        K -= d
    else:
        ans.append(si)

if K > 0:
    ans[-1] = alpha[(dic[ans[-1]] + K) % 26]

print "".join(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
k = int(input())
t = list(map(lambda c: ord(c)-ord('a'), s))
for i in range(len(t)):
    if t[i] != 0 and 26-t[i] <= k:
        k -= 26-t[i]
        t[i] = 0
if k:
    t[i] = (t[i]+k) % 26
    k = 0
ans = ''.join(map(lambda c: chr(c+ord('a')), t))
print(ans)

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(10000)

s = list(input())
K = read()

for i in range(len(s)):
  d = ord('z') - ord(s[i]) + 1
  if s[i] != 'a' and d <= K:
    s[i] = 'a'
    K -= d

K %= 26

s[-1] = chr(ord(s[-1]) + K)

print(''.join(s))

Submission status: Accepted

Solution code:
S = list(input())
K = int(input())
N = len(S)
for i in range(N):
    if S[i] == 'a':
        continue
    diff = ord('z') - ord(S[i]) + 1
    if diff <= K:
        K -= diff
        S[i] = 'a'
if K != 0:
    K %= 26
    S[i] = chr(ord(S[i]) + K)
print("".join(S))

Submission status: Runtime Error

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(an))

Submission status: Runtime Error

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)

    print(''.join(S))




if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  string s;
  int64 K;
  cin >> s >> K;
  int N = s.size();
  for (int i = 0; i < N; i++) {
    int idx = s[i] - 'a';
    if (K >= 26 - idx) {
      K -= 26 - idx;
      s[i] = 'a';
    }
  }
  if (K != 0) {
    int tmp = s[N - 1] - 'a' + K;
    s[N - 1] = tmp + 'a';
  }
  cout << s << endl;
  return 0;
}

Submission status: Runtime Error

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)
print(*s, sep='')

Submission status: Runtime Error

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

i = 0
for j in range(len(s)):
  if s[j] != 'a':
    if 26+ord('a')-ord(s[j]) <= K-i:
      i += 26+ord('a')-ord(s[j])
      s = s[:j] + 'a' + s[j+1:]

if i < K:
  for k in range(1, len(s)+1):
    if s[-k] != 'a':
      if 26+ord('a')-ord(s[-k]) <= K-i:
        s = s[:-k] + 'a' + s[-k+1:]
        i += 26+ord('a')-ord(s[-k])
  if i < K:
    s = s[:-1] + chr(ord(s[-1])+K-i)
print(s)

Submission status: Runtime Error

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] += k

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    K = int(input())
    ans = ''
    for s in S:
        if s=='a':
            ans += s
        else:
            if 123 - ord(s) <= K:
                ans += 'a'
                K -= 123 - ord(s)
            else:
                ans += s
    if K > 0:
        ans = ans[:-1] + (chr(ord(ans[-1]) + K))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    K = int(input())
    ans = ''
    for s in S:
        if 123 - ord(s) <= K:
            ans += 'a'
            K -= 123 - ord(s)
        else:
            ans += s
    if K > 0:
        ans = ans[:-1] + (chr(ord(ans[-1]) + K))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

a = 123
for i in range(len(ans)):
    if i != len(ans)-1:
        if a - ans[i] <= k:
            k = k-(a - ans[i])
            ans[i] = 97
            ans[i] = chr(ans[i])
        else:
            ans[i] = chr(ans[i])
    
    else:
        if ans[i] + k >= 123:
            tmp = ans[i]+k - 122
            ans[i] = 96+tmp
            ans[i] = chr(ans[i])            
        else:
            ans[i] += k
            ans[i] = chr(ans[i])

print("".join(ans))

Submission status: Runtime Error

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])
  print(b,K,S)
  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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

print("".join(S))

Submission status: Runtime Error

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

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

print("".join(S))

Submission status: Runtime Error

Solution code:
from math import ceil

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

ans = []
a = ord('z') + 1
for i in s:
    if k == 0:
        ans.append(ord(i))
    elif a - ord(i) <= k and i != 'a':
        k -= a - ord(i)
        ans.append(ord('a'))
    else:
        ans.append(ord(i))
ans[-1] += k
if ans[-1] >= a:
    ans[-1] -= ceil((ans[-1] - (a - 1)) / 26)
print(*map(chr, ans), sep='')

Submission status: Runtime Error

Solution code:
from math import ceil

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

ans = []
a = ord('z') + 1
for i in s:
    if k == 0:
        ans.append(ord(i))
    elif a - ord(i) <= k:
        k -= a - ord(i)
        ans.append(ord('a'))
    else:
        ans.append(ord(i))
ans[-1] += k
if ans[-1] >= a:
    ans[-1] -= ceil((ans[-1] - (a - 1)) / 26)
print(*map(chr, ans), sep='')

Submission status: Runtime Error

Solution code:
from math import ceil

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

ans = []
a = ord('z') + 1
for i in s:
    if a - ord(i) <= k and i != 'a':
        k -= a - ord(i)
        ans.append(ord('a'))
    else:
        ans.append(ord(i))
ans[-1] += k
if ans[-1] >= a:
    ans[-1] -= ceil((ans[-1] - (a - 1)) / 26)
print(*map(chr, ans), sep='')

Submission status: Runtime Error

Solution code:
from math import ceil

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

ans = []
a = ord('z') + 1
for i in s:
    if k == 0:
        break
    elif a - ord(i) <= k:
        k -= a - ord(i)
        ans.append(ord('a'))
    else:
        ans.append(ord(i))
ans[-1] += k
if ans[-1] >= a:
    ans[-1] -= ceil((ans[-1] - (a - 1)) / 26)
print(*map(chr, ans), sep='')

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a = input().replace("S", " S").replace("H", " H").replace("D", " D").replace("C", " C").split()
m, s, h, d, c = [], [], [], [], []
ans = []
for i in range(len(a)):
    if a[i][1] in ["2", "3", "4", "5", "6", "7", "8", "9"]:
        m.append(i)
    else:
        if a[i][0] == "S":
            s.append(i)
            if len(s) == 5:
                ans = s
                break
        elif a[i][0] == "H":
            h.append(i)
            if len(h) == 5:
                ans = h
                break
        elif a[i][0] == "D":
            d.append(i)
            if len(d) == 5:
                ans = d
                break
        else:
            c.append(i)
            if len(c) == 5:
                ans = c
                break
ch = 0
d = ""
for i in ans:
    d += "".join(a[ch:i])
    ch = i+1
if d == "":
    print(0)
else:
    print(d)

Submission status: Runtime Error

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

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

print(''.join(s))

Submission status: Runtime Error

Solution code:
S = input()
K = int(input())
z = ord('z') + 1

res = ""
flg = False
for i,c in enumerate(S):
    if z - ord(c) <= K:
        res += 'a'
        K -= z-ord(c)
    else:
        res += chr(ord(c))

res = res[:-1] + chr(ord(res[-1]) + K)
print(res)

Submission status: Runtime Error

Solution code:
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if k == 0:
            break
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        ans[-1] = chr(ord(ans[-1]) + k)
    print(''.join(ans))



if __name__ == '__main__':
    main()

Submission status: Runtime Error

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



if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

alphabet = "abcdefghijklmnopqrstuvwxyz"
a_len = len(alphabet)
table = {c: idx for idx, c in enumerate(alphabet)}

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

ans = ""
for i in range(len(s[:-1])):
    gap = a_len - table[s[i]]
    if gap <= k:
        ans += "a"
        k -= gap
    elif k == 0:
        ans += s[i:-1]
    else:
        ans += s[i]

ans += alphabet[(table[s[-1]] + k) % a_len]
print(ans)

Submission status: Runtime Error

Solution code:
import sys

alphabet = "abcdefghijklmnopqrstuvwxyz"
a_len = len(alphabet)
table = {c: idx for idx, c in enumerate(alphabet)}

rl = sys.stdin.readline
s = rl().rstrip("\n")
k = int(rl())

ans = ""
for i in range(len(s[:-1])):
    gap = a_len - table[s[i]]
    if gap <= k:
        ans += "a"
        k -= gap
    elif k == 0:
        ans += s[i:-1]
    else:
        ans += s[i]

ans += alphabet[(table[s[-1]] + k) % a_len]
print(ans)

Submission status: Runtime Error

Solution code:
import sys

alphabet = "abcdefghijklmnopqrstuvwxyz"
a_len = len(alphabet)
table = {c: idx for idx, c in enumerate(alphabet)}

rl = sys.stdin.readline
s = rl().rstrip()
k = int(rl())

ans = ""
for i in range(len(s[:-1])):
    gap = a_len - table[s[i]]
    if gap <= k:
        ans += "a"
        k -= gap
    elif k == 0:
        ans += s[i:-1]
    else:
        ans += s[i]

ans += alphabet[(table[s[-1]] + k) % a_len]
print(ans)

Submission status: Runtime Error

Solution code:
s = str(input())
k = int(input())
S = []
for i in range(len(s)):
    S.append(ord(s[i]) - 97)
i = 0
while k > 0:
    if 26 - S[i] <= k:
        k -= 26 - S[i]
        S[i] = 0
        i += 1
    else:
        i += 1
    if i >= len(s):
        S[-1] += k
        break
ans = ''
for x in S:
    ans += chr(x + 97)
print(ans)

Submission status: Runtime Error

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

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

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

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

'''
ordの位置
#z = 122
#a = 97
左の文字からNで'a'に出来るかを確認
aに出来るならaにして使った分をNから引く
繰り返して行き一番最後にあまりをすべて使う'''
  
for i, s in enumerate(S):
  if ord(s) - 97 > 0  and 122 - ord(s) < N:
    S[i] = "a"
    N -= 123 - ord(s)
else:
  S[i] = chr((ord(S[i]) + N))
  
print("".join(S))

Submission status: Runtime Error

Solution code:
from collections import deque
s = input()
k = int(input())
a = ord("a")
l = deque(list())
l1 = []
for i in range(len(s)):
    s1 = s[i]
    l.append(((a+26)-ord(s1))%26)
#print(l)
while k!=0:
    if len(l)!=0:
        t = l.popleft()
        if k>=t:
            l1.append("a")
            k -= t
        else:
          if t=="a":
            l1.append(t)
          else:
            l1.append(chr((ord('a')-t+26)))
    else:
        l1[-1] = chr(int(ord(l1[-1])+k))
        k = 0
l2 = []
if len(l)>=1:
  for t in l:
    if t==0:
      l2.append("a")
    else:
      l2.append(chr((ord('a')-t+26)))
  l1 += l2
print("".join(l1))

Submission status: Runtime Error

Solution code:
from collections import deque
s = input()
k = int(input())
a = ord("a")
l = deque(list())
l1 = []
for i in range(len(s)):
    s1 = s[i]
    l.append(((a+26)-ord(s1))%26)
#print(l)
while k!=0:
    if len(l)!=0:
        t = l.popleft()
        if k>=t:
            l1.append("a")
            k -= t
        else:
          if t=="a":
            l1.append(t)
          else:
            l1.append(chr((ord('a')-t+26)))
    else:
        l1[-1] = chr(int(ord(l1[-1])+k))
        k = 0
l2 = []
if len(l)>=1:
  for t in l:
    if t==0:
      l2.append("a")
    else:
      l2.append(chr((ord('a')-t+26)))
  l1 += l2
print("".joiin(l1))

Submission status: Runtime Error

Solution code:
from collections import deque
s = input()
k = int(input())
a = ord("a")
l = deque(list())
l1 = []
for i in range(len(s)):
    s1 = s[i]
    l.append(((a+26)-ord(s1))%26)
while k!=0:
    if len(l)!=0:
        t = l.popleft()
        if k>=t:
            l1.append("a")
            k -= t
        else:
            l1.append(chr(ord('a')-t+26))
    else:
        l1[-1] = chr(int(ord(l1[-1])+k))
        k = 0
print(''.join(l1))

Submission status: Runtime Error

Solution code:
from collections import deque
s = input()
k = int(input())
a = ord("a")codefestival
100
l = deque(list())
l1 = []
for i in range(len(s)):
    s1 = s[i]
    l.append(((a+26)-ord(s1))%26)
while k!=0:
    if len(l)!=0:
        t = l.popleft()
        if k>=t:
            l1.append("a")
            k -= t
        else:
            l1.append(chr(ord('a')-t+26))
    else:
        l1[-1] = chr(int(ord(l1[-1])+k))
        k = 0
print(''.join(l1))

Submission status: Runtime Error

Solution code:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = input()
K = int(input())
ans = ''
for i in range(len(s) - 1):
    s_i = alphabet.index(s[i])
    elif (26 - s_i < K) & (s_i != 0):
        K -= 26 - s_i
        s_i = 0
    ans += alphabet[s_i]
s_i = (alphabet.index(s[-1]) + K) % 26
ans += alphabet[s_i]
print(ans)

Submission status: Runtime Error

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    for i in range(len(s)):
        if si == "a":
            continue
        si = ord(s[i]) - 97
        if k >= 26 - si:
            s[i] = "a"
            k -= 97 + 26 - si
            if k == 0:
                break

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

    print(*s, sep="")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#"a" 97 "z" 122
s = list(ord(i) for i in input())
k = int(input())
for i in range(len(s)):
  if 123 - s[i] <= k:
    k -= 123-s[i]
    s[i] = 97

if k > 0:
  s[-1] += k
  if s[-1] >= 123: s[-1] = s[-1]-26
print("".join(list(map(chr, s))))

Submission status: Runtime Error

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

ns = []
for c in s[:-1]:
    ofstoa = ord('z')+1-ord(c)
    if k >= ofstoa:
        ns.append('a')
        k -= ofstoa
    else:
        ns.append(c)

last = ord(s[-1])
if last + k > ord('z'):
    ns.append(chr(last + k - 26))
else:
    ns.append(chr(last + k))

print(''.join(ns))

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]
        ans[i] = 'a'
    if k == 0: break
    if i == n-1:
        ans[i] = chr(ord(s[i]) + k)

print(''.join(ans))