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 = raw_input()
k = input()

def solve(s, k, i):
    if i == len(s)-1:
        # print "equal"
        t = ord(s[i])+k
        if t > ord("z"):
            t -= ord("a")
            t %= (ord("z")-ord("a") + 1)
            t += ord("a")
        s = s[:i] + chr(t)
        return s
        # print s, k
    elif s[i] != "a" and ord(s[i]) + k > ord("z"):
        # print "carry"
        k = k - ord("z") + ord(s[i]) -1
        s = s[:i] + "a" + s[i+1:]        
        # print s,k
    return solve(s,k,i+1)
    
print solve(s,k,0)

Submission status: Runtime Error

Solution code:
def f(s,K):
 res=0
 str=""
 for i in range(len(s)):
  if s[i]=="a":
   str+="a"
   res+=1
   continue
  if K>=123-ord(s[i]):
   str+="a"
   res+=1
   K-=123-ord(s[i])
  else:
   break
 if res==0:
  skip=0
  for skip in range(len(s)):
   if K>=123-ord(s[skip]):
    break
  return s[:skip],s[skip:],K
 return str,s[res:],K

ss=input()
KK=int(input())
sol=""
while len(ss)>1:
 x,ss,KK=f(ss,KK)
 sol+=x
KK%=26
if ord(ss[0])+KK<123:
 sol+=chr(ord(ss[0])+KK)
else:
 sol+=chr(ord(ss[0])+KK-26)
print(sol)

Submission status: Runtime Error

Solution code:
s = list(input())
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

for i in range(len(s)):
    if K > 26 or s[i] >= alphabet[-K]:
        K -= ord("z") - ord(s[i]) + 1
        s[i] = "a"

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

print("".join(s))

Submission status: Runtime Error

Solution code:
s = raw_input()
K = int(raw_input())
_s, _K = s[:], K
a = "abcdefghijklmnopqrstuvwxyz"
ai = a.index("a")
zi = a.index("z") 
si = [zi - a.index(c) + 1 if c != "a" else 0  for c in s]

def rotation_alphabet(s,i):
    return

for i, (c, ci) in enumerate(zip(s, si)):
    if K == 0:
        break
    if c == "a":
        continue
    if ci <= K:
        s = s[0:i] + "a" + s[i+1:]
        K = K - ci

if K > 0:
    s = s[:-1] + a[a.index(s[-1]) + K]

print(s)

Submission status: Runtime Error

Solution code:
def f(s,K):
 if len(s)==1:
  K%=26
  if ord(s[0])+K<123:
   return chr(ord(s[0])+K)
  else:
   return chr(ord(s[0])+K-26)
 res=0
 for i in range(len(s)):
  if s[i]=="a":
   res+=1
   continue
  if K>=123-ord(s[i]):
   res+=1
   K-=123-ord(s[i])
  else:
   break
 str=""
 for i in range(res):
  str+="a"
 if res==0:
  for i in range(len(s)):
   if K>=123-ord(s[i]):
    break
  return s[:i]+f(s[i:],K)
 return str+f(s[res:],K)
ss=input()
KK=int(input())
print(f(ss,KK))

Submission status: Runtime Error

Solution code:
def num_to_char(s_num):
    ch = []
    for num in s_num:
        ch.append(alphabet[(num%26)-1])
    return ch

s = raw_input()
K = input()

alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
ans = []

s_num = []
for char in s:
    s_num.append(alphabet.index(char) + 1)thon WS) -----------------------------
for i in xrange(len(s_num)):ive/01_Atcoder/codefesA/A.py
    if 27 - s_num[i] < K and (s_num[i] != 1) and (i != len(s_num) - 1):
        K = K - (27 - s_num[i])1_GoogleDrive/01_Atcoder/
        s_num[i] = 271_Atcoder tong$ ls
#kouji.py#	20151121	B.py		Sort		kouji.py~
    elif 27 - s_num[i] < K and (s_num[i] != 1) and (i == len(s_num) - 1):wo.od        s_num[i] = s_num[i] + K
002		20160502	ColorTracking	contest
    elif 27 - s_num[i] < K and (s_num[i] == 1) and (i != len(s_num) - 1):
        passook-Pro:01_Atcoder tong$ mkdir codefesA
tonkous-MacBook-Pro:01_Atcoder tong$ cd codefesA/
    elif 27 - s_num[i] < K and (s_num[i] == 1) and (i == len(s_num) - 1):
        s_num[i] = s_num[i] + K


    elif 27 - s_num[i] >= K and (s_num[i] != 1) and (i != len(s_num)-1):
        pass

    elif 27 - s_num[i] >= K and (s_num[i] != 1) and (i == len(s_num)-1):
        s_num[i] = s_num[i] + K

    elif 27 - s_num[i] >= K and (s_num[i] == 1) and (i != len(s_num) - 1):
        pass

    elif 27 - s_num[i] >= K and (s_num[i] == 1) and (i == len(s_num) - 1):
        s_num[i] = s_num[i] + K

    #elif i == len(s_num) - 1:
       # s_num[i] = s_num[i] + K

print "".join(num_to_char(s_num))

Submission status: Runtime Error

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

def solve(s, k, i):
    if i >= len(s):
        # print "over"
        return s
    if i == len(s)-1:
        # print "equal"
        t = ord(s[i])+k
        if t > ord("z"):
            t -= ord("a")
            t %= (ord("z")-ord("a") + 1)
            t += ord("a")
        s = s[:i] + chr(t)
        # print s, k
    elif ord(s[i]) + k > ord("z"):
        # print "carry"
        k = k - ord("z") + ord(s[i]) -1
        s = s[:i] + "a" + s[i+1:]        
        # print s,k
    return solve(s,k,i+1)
    
print solve(s,k,0)

Submission status: Runtime Error

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

def toA(char):
    return (ord('z')-ord(char)+1)%26


def toC(char,k):
    if(ord('z')-ord(char)>=k):
        return chr(ord(char)+k)
    else:
        return chr(ord('a')+k-ord('z')-ord(char))


for i in range(len(s)):
    if(k==0):
        break
    if(k>=toA(s[i])):
        k-=toA(s[i])
        s[i]='a'
    if(i==len(s)-1) and k>0:
        s[i]= toC(s[i],k)
print("".join(s))

Submission status: Runtime Error

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

def solve(s, k, i):
    if i >= len(s):
        # print "over"
        return s
    if i == len(s)-1:
        # print "equal"
        t = ord(s[i])+k
        if t > ord("z"):
            t -= (ord("z") - ord("a")+1)
        s = s[:i] + chr(t)
        # print s, k
    elif ord(s[i]) + k > ord("z"):
        # print "carry"
        k = k - ord("z") + ord(s[i]) -1
        s = s[:i] + "a" + s[i+1:]        
        # print s,k
    return solve(s,k,i+1)
    
print solve(s,k,0)

Submission status: Runtime Error

Solution code:
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])))






s = input()
K = int(input())
print(move(s,K))

Submission status: Runtime Error

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]

print "".join(ans)