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:
#[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 can_change_to_a(ch,K):
        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: Wrong Answer

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


arr = [ord(S[i]) for i in range(len(S))]

count = K
for i in range(len(S)):
    if i == len(S) - 1:
        for j in range(count):
            arr[i] += 1
            if arr[i] == ord('z') + 1:
                arr[i] = ord('a')
        break

    if ord('z') - ord(S[i]) + 1 <= count:
        arr[i] = ord('a')
        count -= (ord('z') - ord(S[i]) + 1)

ans = ''
for c in arr:
    ans += chr(c)

print(ans)

Submission status: Wrong Answer

Solution code:
S = raw_input()
K = input()
M = ord('z')+1
ans = []
aa = ans.append
for s in S:
    o = ord(s)
    if M-o <= K:
        aa('a')
        K -= M-o
    else:
        aa(s)
if K > 0:
    K %= 26
    a = ord(ans[-1]) + K
    if a > ord('z'):
        a -= 26
    ans[-1] = chr(a)
print ''.join(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
#

def join(s):
    return ''.join(s)

#iterate macro
def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)

#modulo macro
def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m

#bisect macro
def index(a, x):
    #Locate the leftmost value exactly equal to x
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1

#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

nh=zip([1,0,-1,0],[0,1,0,-1])

###########

st=slist()
k=i()

for j in range(len(st)):
    o=ord(st[j])
    if k >= 123-o:
        k -= (123-o)
        st[j]='a'
n=97+(ord(st[len(st)-1])-97+k)%26

st[len(st)-1] = chr(n)
print join(st)

Submission status: Wrong Answer

Solution code:
def cost_for_next_a(c):
    return 123 - ord(c)

s = input()
K = int(input())

new_s = ""


for i in range(len(s)):
    if cost_for_next_a(s[i]) <= K:
        new_s += "a"
        K -= cost_for_next_a(s[i])
    elif i != len(s) - 1:
        new_s += s[i]
    else:
        new_s += chr(ord(s[i]) + K)

print(new_s)

Submission status: Wrong Answer

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

k = K
while True:
    flag = False

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

c = chr(ord(S[-1])+k)
S[-1] = c

print "".join(S)

Submission status: Wrong Answer

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))
print(''.join(s))

Submission status: Wrong Answer

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

s_ans = list(s)
for i,ch in enumerate(s):
    if can_change_to_a(ch,K):
        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: Wrong Answer

Solution code:
z = ord('z')
s = raw_input()
K = int(raw_input())
used = 0
ret = ""
for i in xrange(len(s)):
    if i+1 == len(s):
        ret += chr(ord(s[i]) + K - used)
    elif K - used < z - ord(s[i]) + 1:
        ret += s[i]
    else:
        used += z - ord(s[i]) + 1
        ret += 'a'

print ret

Submission status: Wrong Answer

Solution code:
def f(c):
    return ord("z") - ord(c) + 1

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

Submission status: Wrong Answer

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

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

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

print(''.join(s_ans))

Submission status: Wrong Answer

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

from __future__ import division, print_function, absolute_import, unicode_literals

a = 'abcdefghijklmnopqrstuvwxyz'
S = input()
k = int(input())

ans = ''
for s in S:
    # 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: Wrong Answer

Solution code:
S = raw_input()
K = input()
M = ord('z')+1
ans = []
aa = ans.append
for s in S:
    if K == 0:
        break
    o = ord(s)
    if M-o <= K:
        aa('a')
        K -= M-o
    else:
        aa(s)
if K > 0:
    K %= 26
    a = ord(ans[-1]) + K
    if a > ord('z'):
        a -= 26
    ans[-1] = chr(a)
print ''.join(ans)

Submission status: Wrong Answer

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

for i in xrange(len(s)):
    n = 123 - ord(s[i])
    if n <= k:
        s = s[:i] + 'a' + s[i + 1:]
        k -= n

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

Submission status: Wrong Answer

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 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: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s=list(input())

k=int(input())

ans = []

for alf in s:
    if alf == 'a':
        ans = ans + ['a']
    else:
        if 123 - ord(alf) <= k:
            k -= 123 - ord(alf)
            ans = ans + ['a']
        else:
            ans = ans + [alf]
if 0 < k:
    amari = (ord(ans[-1])-97+k)%26
    ans[-1] = chr(amari+97)
    
print(''.join(map(str,ans)))

Submission status: Time Limit Exceeded

Solution code:
def Next(x):
    return chr((ord(x)-ord("a")+1)%26+ord("a"))

def Next_k(x,k):
    if k==0:
        return x
    else:
        return Next_k(Next(x),k-1)

def g(x):
    return (ord("z")-ord(x)+1)%26

A={chr(ord("a")+a):a for a in range(26)}

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

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

U=""
for s in S:
    U+=s

print(U)

Submission status: Time Limit Exceeded

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
    else:
        ans += s[i]

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

Submission status: Time Limit Exceeded

Solution code:
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: Time Limit Exceeded

Solution code:
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)):
    if i == len(s) - 1:
        ans += alphabet[(table[s[i]] + k) % a_len]
    else:
        gap = a_len - table[s[i]]
        if gap <= k:
            ans += "a"
            k -= gap
        else:
            ans += s[i]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
Ans = ''
for s in S[:-1]:
    if (123 - ord(s)) <= K:
        Ans += 'a'
        K -= 123 - ord(s)
    else:
        Ans += s

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


print(Ans)

Submission status: Time Limit Exceeded

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

a = []
for i in range(n):
    a.append(ord(s[i])-ord('a'))

for i in range(n):
    need = 26 - a[i]
    if(k>=need):
        a[i]=0
        k-=need


k %= 26

for ii in range(n):
    i = n-1-ii
    rem = 25 - a[i]
    if(rem<=k):
        a[i]+=rem
        k-=rem
    else:
        a[i]+=k
        k=0
        
        break
ans = ''
for i in range(n):        
    ans += chr(a[i]+ord('a'))
print(ans)

Submission status: Time Limit Exceeded

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

i=0
while i<len(S)-1:
    if S[i]!='a' and 123-ord(S[i])<=N:
        N-=123-ord(S[i])
        S[i]='a'
    i+=1

while N:
    if S[-1]=='z':
        S[-1]='a'
    else:
        S[-1]=chr(ord(S[-1])+1)
    N-=1

print(''.join(S))

Submission status: Time Limit Exceeded

Solution code:
import re
s = input()
k = int(input())
n = len(s)
for i in range(n):
  si = s[i]
  num = ord(si)
  if num == 97 or 123-num > k:
    continue
  k -= (123-num)
  s = re.sub(si,'a',s,1)
if k > 0:
  t = k%26
  s = s[:n-1] + chr(ord(s[n-1])+t)
print(s)

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
n = len(s)
for i in range(n):
  num = ord(s[i])
  if num == 97 or 123-num > k:
    continue
  k -= (123-num)
  s = bytearray(s.encode())
  s[i] = 97
  s = s.decode()
if k > 0:
  t = k%26
  s = bytearray(s.encode())
  s[n-1] += t
  s = s.decode()
print(s)

Submission status: Time Limit Exceeded

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.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: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    s = S()
    k = II()
    ans = ""
    for si in s[:-1]:
        x = (ord("a") - ord(si)) % 26
        if x <= k:
            k -= x
            ans += "a"
        else:
            ans += si
    ans += chr(ord("a") + (k - (ord("a") - ord(s[-1])) % 26) % 26)
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

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:
            # aまで操作できないのに、操作すると辞書順でより後ろの文字列になってしまうので、次の文字へ
            idx += 1
        else:
            # 一番後ろの場合
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        if S[idx] != "a":
            K -= k
        S[idx] = "a"
        if idx < L-1:
            idx += 1

print("".join(S))

Submission status: Time Limit Exceeded

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 += chr(ord('a') + (ord(c) + k % 26 - ord('a')) % 26)
            break
        d = ord('z') - ord(c) + 1
        if d < k:
            k -= d
            ans += 'a'
        else:
            ans += c
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
ans = ""
alpha = "abcdefghijklmnopqrstuvwxyz"
l = len(alpha)
for i in range(len(s)-1):
    if l - alpha.index(s[i]) <= k:
        k -= l - alpha.index(s[i])
        ans += "a"
    else:
        ans += s[i]
ans += alpha[(alpha.index(s[-1]) + k + l**100) % l]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
alp = 'abcdefghijklmnopqrstuvwxyz'
alp_dict = {s:i for i, s in enumerate('abcdefghijklmnopqrstuvwxyz')}
N = len(alp)
S = input()
K = int(input())
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: Time Limit Exceeded

Solution code:
s = input().strip()
K = int(input())
if K>len(s)*26:
    d = (K-len(s)*26)//26
    K = K-26*d
x = ""
for i in range(len(s)):
    if i<len(s)-1 and (26-(ord(s[i])-ord("a")))%26 <= K:
        x += "a"
        K -= (26-(ord(s[i])-ord("a")))%26
    elif i<len(s)-1:
        x += s[i]
    elif i==len(s)-1:
        k = ord(s[i])+K%26
        if k<=122:
            x += chr(k)
        else:
            x += chr(k-26)
print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
ans=''
for c in s:
    if c!='a' and ord('z')+1-ord(c)<=K:
        ans+='a'
        K-=ord('z')+1-ord(c)
    else:
        ans+=c
if K>0:
    ans=ans[:-1]+chr(ord(ans[-1])+K%26)

print(ans)

Submission status: Time Limit Exceeded

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
ans = ''
for s in S:
    if 123 - ord(s) <= K and s != 'a':
        ans += 'a'
        K -= 123-ord(s)
    else:
        ans += s
if K > 0:
    ans = ans[:-1] + chr((ord(ans[-1])+K-97) % 26+ord('a'))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = [ord(i) for i in input()]
K = int(input())

ret = ''
for c in s[:-1] :
    if c == 97 :
        ret += 'a'
        continue
        
    if c + K > 122 :
        ret += 'a'
        K -= 123 - c
    else :
        ret += chr(c)
        
K %= 26
ret += chr((s[-1] + K - 97) % 26 + 97)
        
print(ret)

Submission status: Time Limit Exceeded

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

ret = ''
for i, c in enumerate(s) :
    if i == len(s) - 1 :
        K %= 26
        if ord(c) + K > 122 :
            ret += chr(ord(c) + K - 26)
        else :
            ret += chr(ord(c) + K)
    
    elif ord(c) + K > 122 :
        ret += 'a'
        K -= 123 - ord(c)
    else :
        ret += c
        
print(ret)

Submission status: Time Limit Exceeded

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

here = 0
while K:
    tmp = character.find(s[here])
    if tmp == 1 and here != limit:
        continue

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from string import ascii_lowercase

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

b = ord('a')

ret = ''
for c in s[:-1]:
    if c == 'a':
        ret += 'a'
        continue
    need = 26 - (ord(c) - b)
    if k >= need:
        k -= need
        ret += 'a'
    else:
        ret += c

k %= 26

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

print(ret)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    K = int(input())
    ans = ""
    for i, s in enumerate(S):
        tmp = ord(s) - ord('a')
        if i == len(S) - 1:
            ans += chr((tmp + K) % 26 + ord('a'))
        elif s == 'a':
            ans += s
        elif 26 - tmp <= K:
            ans += 'a'
            K -= 26 - tmp
        else:
            ans += s

    print(ans)
            


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
alphabet_small = {chr(i):i-97 for i in range(97, 97+26)}
s = input()
k = int(input())
ans =""
for character in s:
    i = alphabet_small[character]
    #print(i,character)
    if i != 0 and k >= 26 - i:
        k -= 26 - i
        ans += "a"
    else:
        ans += character


if k > 0:
    k %= 26
    ans = ans[:-1] + chr((alphabet_small[ans[-1]]+k)%26+97)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
alphabet_small = [chr(i) for i in range(97, 97+26)]
s = input()
k = int(input())
ans = ""
for num,character in enumerate(s):
    for i in range(26):
        if character == alphabet_small[i]:
            if i != 0 and k >= 26-i:
                k -= 26-i
                ans += "a"
            else:
                ans += character
            break

if k > 0:
    k %= 26
    for i in range(26):
        if ans[-1] == alphabet_small[i]:
            ans = ans[:-1] + alphabet_small[(i+k)%26]
            break

print(ans)

Submission status: Time Limit Exceeded

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-1):
	if (123-ord(s_list[i])<=temp1)&(temp1>=0):
		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))
row=""
for i in range(len(s_list)):
	row+=s_list[i]
print(row)

Submission status: Time Limit Exceeded

Solution code:
#n,x=map(int,input().split())
#a=[int(i) for i in input().split()]
import string
alp=string.ascii_lowercase
di={}
for i in range(26):
    di[alp[i]]=i
s=input()
a=[]
for i in s:
    a.append(i)
l=a.pop()
if a:
    a=a[::-1]
k=int(input())
ans=''
i=0
while a:
    t=a.pop()
    d=(26-di[t])%26
    if d<=k:
        k-=d
        ans+='a'
    else:
        ans+=t
    i+=1
kk=k%26
ans+=alp[(alp.index(l)+kk)%26]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#n,x=map(int,input().split())
#a=[int(i) for i in input().split()]
import string
alp=string.ascii_lowercase
di={}
for i in range(26):
    di[alp[i]]=i
s=input()
a=[]
for i in s:
    a.append(i)
l=a.pop()
if a:
    a=a[::-1]
k=int(input())
ans=''
i=0
while a:
    t=a.pop()
    d=(26-di[t])%26
    if d<=k:
        k-=d
        ans+='a'
    else:
        ans+=t
    i+=1
ans+=alp[(alp.index(l)+k%26)%26]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#n,x=map(int,input().split())
#a=[int(i) for i in input().split()]
import string
alp=string.ascii_lowercase
s=input()
a=[]
for i in s:
    a.append(i)
l=a.pop()
if a:
    a=a[::-1]
k=int(input())
ans=''
i=0
while a:
    t=a.pop()
    d=(26-alp.index(t))%26
    if d<=k:
        k-=d
        ans+='a'
    else:
        ans+=t
    i+=1
ans+=alp[(alp.index(l)+k%26)%26]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import string
alp=string.ascii_lowercase
s=input()
k=int(input())
ans=''
i=0
while i<len(s)-1:
    t=s[i]
    d=(26-alp.index(t))%26
    if d<=k:
        k-=d
        ans+='a'
    else:
        ans+=t
    i+=1
if k>0:
    ans+=alp[(alp.index(s[-1])+k%26)%26]
else:
    ans+=s[-1]
print(ans)

Submission status: Time Limit Exceeded

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:

aord = ord("a")
s = list(raw_input())
k = int(input())
i = 0

while k > 0 and i < len(s):
	if k >= ord('z') - ord(s[i]) + 1:
		if s[i] == "a": continue
		k -= ord('z') - ord(s[i]) + 1
		s[i] = "a"

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


s = input()
K = int(input())
n = len(s)


def code(s):
    return ord(s)-97

def char(c):
    c = c % 26
    return chr(c+97)


ans = ""
for p in range(n):
    c = code(s[p])
    if c == 0:
        ans += "a"
        continue
    if 26-c > K:
        ans += s[p]
        continue
    ans += "a"
    K -= 26-c
ans = ans[:-1] + char(code(ans[-1])+K)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(map(ord, input()))
K = int(input())

asca = 97
ascz = 122
start = 0
lens = len(s)

loop = lambda x: asca if x == ascz else x+1

for k in range(K):
    for i in range(start, lens):
        c = s[i]
        if i == lens - 1:
            s[i] = loop(c)
            break
        if c == asca:
            start += 1
            continue
        v = c + (K-k)
        if v > ascz:
            s[i] = loop(c)
            break
        else:
            continue
print(''.join(map(chr, s)))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import string


def solve(s, k, dp):
    if dp[(s, k)] == 1:
        return
    elif k == 0:
        return

    dp[(s, k)] = 1

    for i in range(len(s)):
        new_s = s[0:i] + get_next_letter(s[i]) + s[i+1:]
        new_k = k - 1
        solve(new_s, new_k, dp)
    return


def get_next_letter(c):
    if c == 'z':
        return 'a'
    else:
        return alphabet[alphabet.index(c)+1]


def get_lexical_first(dp):
    possible_answers = [k[0] for k in dp.keys() if k[1] == 0]
    possible_answers.sort()
    return possible_answers[0]


if __name__ == '__main__':
    s = str(input())
    k = int(input())
    alphabet = list(string.ascii_lowercase)
    dp = defaultdict(int)
    solve(s, k, dp)
    ans = get_lexical_first(dp)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import string


def solve(s, k, dp):
    if dp[(s, k)] == 1:
        return
    elif k == 0:
        return

    dp[(s, k)] = 1

    for i in range(len(s)):
        new_s = s[0:i] + get_next_letter(s[i]) + s[i+1:]
        new_k = k - 1
        solve(new_s, new_k, dp)
    return

def get_next_letter(c):
    if c == 'z':
        return 'a'
    else:
        return alphabet[alphabet.index(c)+1]

def get_lexical_first(dp):
    possible_answers = []
    for k in dp.keys():
        if k[1] == 0:
            possible_answers.append(k[0])
    possible_answers.sort()
    return possible_answers[0]


if __name__ == '__main__':
    s = str(input())
    k = int(input())
    alphabet = list(string.ascii_lowercase)
    dp = defaultdict(int)
    solve(s, k, dp)
    ans = get_lexical_first(dp)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

def next_char_ascii_num(c, k):
    n = ord(c) + (k % 26)
    if n <= 122:
        return n
    else:
        return n % 123 + 97

s = input()
k = int(input())
d = deque()
l = len(s)

for i, x in enumerate(s):

    if k <= 0:
        l = i
        break

    else:
        if k >= 25 and l != 1:
            d.append(97)
            k -= (26 - (ord(x) - 97))
        else:
            v =[next_char_ascii_num(x, y) for y in range(k + 1)]
            min_index = v.index(min(v))
            d.append(v[min_index])
            k -= min_index


if k > 0:
    d[-1] = next_char_ascii_num(chr(d[-1]), k)
elif l != len(s):
    d += s[l:]

print("".join([chr(x) for x in d]))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

def next_char_ascii_num(c, k):
    n = ord(c) + (k % 26)
    if n <= 122:
        return n
    else:
        return n % 123 + 97

s = input()
k = int(input())
d = deque()
l = len(s)

for i, x in enumerate(s):

    if k <= 0:
        l = i
        break

    else:
        if k >= 25 and l != 1:
            d.append(97)
            k -= (26 - (ord(x) - 97))
        else:
            v =[next_char_ascii_num(x, y) for y in range(k + 1)]
            min_index = v.index(min(v))
            d.append(v[min_index])
            k -= min_index


if k > 0:
    d[-1] = next_char_ascii_num(chr(d[-1]), k)
else:
    d += s[l:]

print("".join([chr(x) for x in d]))