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:
def up(c, i):
    i %= 26
    b = ord('z')-ord(c)+1
    if i >= b:
        i -= b
        c = 'a'
    c = chr(ord(c)+i)
    return c



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

a = ord('a')
ans = ''

for i in range(len(s)):
    b = ord('z')-ord(s[i])+1
    if i == len(s)-1:
        ans += up(s[i], K)
    elif b == 25:
        ans += 'a'
    elif K >= b:
        K -= b
        ans += 'a'
    else:
        ans += s[i]

print(ans)

Submission status: Wrong Answer

Solution code:
def up(c, i):
    i %= 26
    b = ord('z')-ord(c)+1
    if i >= b:
        i -= b
        c = 'a'
    c = chr(ord(c)+i)
    return c



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

a = ord('a')
ans = ''

for i in range(len(s)):
    b = ord('z')-ord(s[i])+1
    if i == len(s)-1:
        ans += up(s[i], K)
    elif b == 25:
        pass
    elif K >= b:
        K -= b
        ans += 'a'
    else:
        ans += s[i]

print(ans)

Submission status: Wrong Answer

Solution code:
def up(c, i):
    i %= 26
    b = ord('z')-ord(c)+1
    if i >= b:
        i -= b
        c = 'a'
    c = chr(ord(c)+i)
    return c



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

a = ord('a')
ans = ''

for i in range(len(s)):
    b = ord('z')-ord(s[i])+1
    if i == len(s)-1:
        ans += up(s[i], K)
    elif K >= b:
        K -= b
        ans += 'a'
    else:
        ans += s[i]

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
k = int(input())
goal = ord('z') + 1
ans = []
for c in S:
    d = goal - ord(c)
    if k >= d:
        k -= d
        ans.append('a')
    else:
        ans.append(c)
last = (k + ord(ans[-1]) - ord('a')) % 26
ans[-1] = chr(ord('a') + last)
print(''.join(ans))

Submission status: Wrong Answer

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

for i, c in enumerate(s):
	if K <= 0:
		break
	diff = (123 - ord(c)) % 26
	if diff <= K:
		s[i] = 'a'
		K -= diff

print(''.join(s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = [c for c in input()]
k = int(input())
l = len(s)
for i in range(l):
    t = ord('z')-ord(s[i])+1
    if t <= k:
        k -= t
        s[i] = 'a'
s[-1] = chr((ord(s[-1]) - ord('a') + k) % 26 + ord('a'))
print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = [c for c in input()]
k = int(input())
l = len(s)
for i in range(l):
    t = ord('z')-ord(s[i])+1
    if t <= k:
        k -= t
        s[i] = 'a'
s[-1] = chr((ord(s[-1]) - ord('a') + k) % (ord('z')-ord('a')+1) +ord('a'))
print(''.join(s))

Submission status: Wrong Answer

Solution code:
alphabet = "abcdefghijklmnopqrstuvwxyz"
my_listChar = []

def moveChar(inputchar):
    index = alphabet.find(inputchar)
    return alphabet[(index + 1) % 26]

def nextChar(inChar, maxNoOfConverted, inputString):
    maxNum = int(maxNoOfConverted)
    output = inChar
    my_listChar.append(output)
    for charInd in range(maxNum):
        output = moveChar(output)
        if (output <= inChar):
            my_listChar.pop()
            my_listChar.append(output)
            return (charInd + 1)
    #print output
    return 0

def convertStr(inputString, ith):
    remainNo = int(ith)
    if (len(inputString) == 1):
        movingSteps = remainNo
        output = inputString
        while(movingSteps > 0):
            output = moveChar(output)
            movingSteps = movingSteps - 1
        return output
    for charInd in range(len(inputString)):
        usedNo = nextChar(inputString[charInd], remainNo, inputString)
        remainNo = remainNo - usedNo

input2 = raw_input("")
input1 = raw_input("")
output = convertStr(input2, input1)
if my_listChar:
    print ''.join(my_listChar)
else:
    print output
#print join(',',my_listChar)

Submission status: Wrong Answer

Solution code:
a=[ord(i) for i in input()]
s = int(input())
for i in range(len(a)):
 if 26+97-a[i]<=s:
     aa=a[i]
     a[i]=97
     s-=26+97-aa
if s>0:
 a[-1]+=s
 if a[-1]>97+25:
     a[-1]=(a[-1]-97)%26+97
b=""
for i in a:
 b+=chr(i) 
print(b)

Submission status: Wrong Answer

Solution code:
a=[ord(i) for i in input()]
s = int(input())
for i in range(len(a)):
 if 26+97-a[i]<s:
     aa=a[i]
     a[i]=97
     s-=26+97-aa
if s>0:
 a[-1]+=s
 if a[-1]>97+25:
     a[-1]=(a[-1]-97)%26+97
b=""
for i in a:
 b+=chr(i) 
print(b)

Submission status: Wrong Answer

Solution code:
a=[ord(i) for i in input()]
s = int(input())
for i in range(len(a)):
 if 26+97-a[i]<s:
     aa=a[i]
     a[i]=97
     s-=26+97-aa
if s>0:
 a[-1]+=s
 if a[-1]>97+25:
     a[-1]=(a[-1]-97)%26+97
b=[chr(i) for i in a]
print(b)

Submission status: Wrong Answer

Solution code:
#coding=UTF-8


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

num_s=[]

for moji in s:
    num_s.append(ord(moji)-ord('a'))

#a にしたら優勝
ans=''
for idx in range(0,len(num_s)-1,1):
    if num_s[idx]==0:
        ans=ans+'a'
    elif K > (26 - num_s[idx]):
        K=K-(26 - num_s[idx])
        ans=ans+'a'
    else:
        #回せないと不利になる一方
        ans=ans+s[idx]

#残りは最後に
ans=ans+chr( (num_s[len(num_s)-1] + K)%26 + ord('a'))

print(ans)

Submission status: Wrong Answer

Solution code:
s=raw_input()
K=int(raw_input())
ozp1=123



ls=list(s)
for i in range(len(ls)):
    nowwork=ozp1-ord(ls[i])
    if i==len(ls)-1:
        K%=26
        ls[i]=chr(ord(ls[i])+K)
    if K==0:
        break

    if ls[i]=="a":
        continue
    if nowwork<=K:
        K-=nowwork
        ls[i]="a"

print "".join(ls)

Submission status: Wrong Answer

Solution code:
s=raw_input()
K=int(raw_input())
ozp1=123



ls=list(s)
for i in range(len(ls)):
    nowwork=ozp1-ord(ls[i])
    if nowwork<=K:
        K-=nowwork
        ls[i]="a"
    elif i==len(ls)-1:
        ls[i]=chr(ord(ls[i])+K)
    if K==0:
        break
print "".join(ls)

Submission status: Wrong Answer

Solution code:
jisho = ["z","y","x","w","v","u","t","s","r","q","p","o","n","m","l","k","j","i","h","g","f","e","d","c","b","a"]

s = list(input())
n = len(s)
k =int(input())
res = ""

for elem in s:
    if jisho.index(elem)+1 <= k:
        res += "a"
        k -= jisho.index(elem)+1
    else:
        res += elem

res = res[0:n-1] + jisho[jisho.index(res[n-1])-k%26]
print(res)

Submission status: Wrong Answer

Solution code:
s = bytearray(raw_input())
N = int(raw_input())
dis = [ord('z')-c for c in s]

for idx, d in enumerate(dis[:-1]):
    if d+1 <= N:
        s[idx] = 'a'
        N -= (d+1)

if N > 0:
    N %= 26
    t = (dis[-1]-N) % 26
    s[-1] = chr(ord('z') - t)
print s

Submission status: Wrong Answer

Solution code:
s = bytearray(raw_input())
N = int(raw_input())
dis = [ord('z')-c for c in s]
print dis
for idx, d in enumerate(dis[:-1]):
    if d+1 <= N:
        s[idx] = 'a'
        N -= (d+1)
print N
if N > 0:
    N %= 26
    t = (dis[-1]-N) % 26
    print t
    s[-1] = chr(ord('z') - t)
print s

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline()

def main():
    s = list(input())
    n = int(input())
    A = []

    for c in s:
        if (ord('a') - ord(c)) % 26 <= n:
            A.append('a')
            n -= (ord('a') - ord(c)) % 26
        else:
            A.append(c)

    # print(''.join(*A))

    # for itm in A:
    #     print(itm,end = '')

    A[-1] = chr(ord(A[-1]) + n % 26)
    print(''.join(A))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline()

def main():
    s = list(input())
    n = int(input())
    A = []

    for c in s:
        if (ord('a') - ord(c)) % 26 <= n:
            A.append('a')
            n -= (ord('a') - ord(c)) % 26
        else:
            A.append(c)

    # print(''.join(*A))

    for itm in A:
        print(itm,end = '')
    print()
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def decoder(str_int):
    s_=''
    for a in str_int:
        s_ = s_+(alpbet[a])
    return s_

def encoder(s):
    return [alpbet.index(a) for a in s]

s = raw_input()
K = input()

alpbet = 'abcdefghijklmnopqrstuvwxyz'
inc_count = K
str_int = encoder(s)

for i in range(len(str_int)):
    if i == len(str_int)-1:
        str_int[i] = (str_int[i] + inc_count) % 26
    else:
        if str_int[i] > 0:
            cost = 26 - str_int[i]
            if inc_count > cost:
                inc_count -= cost
                str_int[i] = 0


        
print decoder(str_int)

Submission status: Wrong Answer

Solution code:
def decoder(str_int):
    s_=''
    for a in str_int:
        s_ = s_+(alpbet[a])
    return s_

def encoder(s):
    return [alpbet.index(a) for a in s]

s = raw_input()
K = input()

alpbet = 'abcdefghijklmnopqrstuvwxyz'
encoder = lambda s: [alpbet.index(a) for a in s]
inc_count = K
str_int = encoder(s)
for i in range(len(str_int)):
    if i != len(str_int)-1:
        if str_int[i] > 0:
            cost = 26 - str_int[i]
            if inc_count > cost:
                inc_count -= cost
                str_int[i] = 0
    else:
        str_int[i] = (str_int[i] + inc_count) % 26
        
print decoder(str_int)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created:  2016-09-28
#

# Usage
#
"""
import sys

def input_single_line():
    """Receive Inputs."""
    return input()

def input_two_line():
    """Receive Two Lined Inputs.
    Like this.

    N
    1 2 3 4 5
    """
    n = sys.stdin.readline()
    n = n.rstrip("\n")
    target = sys.stdin.readline()
    target = target.rstrip("\n")
    # target = target.split(" ")

    return n, target


def check_a_becombility(one_str: str) -> int:
    """Check how can this str become "a"
    >>> check_a_becombility("a")
    0
    >>> check_a_becombility("z")
    1
    >>> check_a_becombility("b")
    25
    """
    if ord(one_str) == 97:
        return 0  # Because this is "a"

    return 123 - ord(one_str)


def make_suzuki_process(target_str :str, chance: int) -> str:
    """Suzuki Process.
    >>> make_suzuki_process("xyz", 4)
    'aya'
    >>> make_suzuki_process("a", 25)
    'z'
    >>> make_suzuki_process("codefestival", 100)
    'aaaafeaaivap'
    >>> make_suzuki_process("aaaa", 1000)
    'aaaa'
    """
    target_str = list(target_str)
    costs = [check_a_becombility(i) for i in target_str]

    for pos, each_cost in enumerate(costs):
        if chance - each_cost >= 0:
            chance = chance - each_cost
            target_str[pos] = "a"

    if chance > 0:
        target_str[-1] = chr(ord(target_str[-1]) + chance % 26)

    return "".join(target_str)

if __name__ == "__main__":
    import doctest
    doctest.testmod()

    inputted = input_two_line()

    print(make_suzuki_process(inputted[0], int(inputted[1])))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created:  2016-09-28
#

# Usage
#
"""
import sys

def input_single_line():
    """Receive Inputs."""
    return input()

def input_two_line():
    """Receive Two Lined Inputs.
    Like this.

    N
    1 2 3 4 5
    """
    n = sys.stdin.readline()
    n = n.rstrip("\n")
    target = sys.stdin.readline()
    target = target.rstrip("\n")
    # target = target.split(" ")

    return n, target


def check_a_becombility(one_str: str) -> int:
    """Check how can this str become "a"
    >>> check_a_becombility("a")
    0
    >>> check_a_becombility("z")
    1
    >>> check_a_becombility("b")
    25
    """
    if ord(one_str) == 97:
        return 0  # Because this is "a"

    return 123 - ord(one_str)


def make_suzuki_process(target_str :str, chance: int) -> str:
    """Suzuki Process.
    >>> make_suzuki_process("xyz", 4)
    'aya'
    >>> make_suzuki_process("a", 25)
    'z'
    >>> make_suzuki_process("codefestival", 100)
    'aaaafeaaivap'
    >>> make_suzuki_process("aaaa", 1000)
    'aaaa'
    """
    target_str = list(target_str)
    costs = [check_a_becombility(i) for i in target_str]

    for pos, each_cost in enumerate(costs):
        if chance - each_cost >= 0:
            chance = chance - each_cost
            target_str[pos] = "a"

    if chance > 0:
        temp = ord(target_str[-1]) + chance
        if temp > 122:
            target_str[-1] = chr(chance % 25 + ord(target_str[-1]))
        else:
            target_str[-1] = chr(temp)

    return "".join(target_str)

if __name__ == "__main__":
    import doctest
    doctest.testmod()

    inputted = input_two_line()

    print(make_suzuki_process(inputted[0], int(inputted[1])))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created:  2016-09-28
#

# Usage
#
"""
import sys

def input_single_line():
    """Receive Inputs."""
    return input()

def input_two_line():
    """Receive Two Lined Inputs.
    Like this.

    N
    1 2 3 4 5
    """
    n = sys.stdin.readline()
    n = n.rstrip("\n")
    target = sys.stdin.readline()
    target = target.rstrip("\n")
    # target = target.split(" ")

    return n, target


def check_a_becombility(one_str: str) -> int:
    """Check how can this str become "a"
    >>> check_a_becombility("a")
    0
    >>> check_a_becombility("z")
    1
    >>> check_a_becombility("b")
    25
    """
    if ord(one_str) == 97:
        return 0  # Because this is "a"

    return 123 - ord(one_str)


def make_suzuki_process(target_str :str, chance: int) -> str:
    """Suzuki Process.
    >>> make_suzuki_process("xyz", 4)
    'aya'
    >>> make_suzuki_process("a", 25)
    'z'
    >>> make_suzuki_process("codefestival", 100)
    'aaaafeaaivap'
    """
    target_str = list(target_str)
    costs = [check_a_becombility(i) for i in target_str]

    for pos, each_cost in enumerate(costs):
        if chance - each_cost >= 0:
            chance = chance - each_cost
            target_str[pos] = "a"

    if chance > 0:
        temp = ord(target_str[-1]) + chance
        if temp > 122:
            target_str[-1] = chr(temp % 97)
        else:
            target_str[-1] = chr(temp)

    return "".join(target_str)

if __name__ == "__main__":
    import doctest
    doctest.testmod()

    inputted = input_two_line()

    print(make_suzuki_process(inputted[0], int(inputted[1])))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
ans=[]
for c in s:
    if (ord('a')-ord(c))%26 <= k:
        ans.append('a')
        k-=(ord('a')-ord(c))%26
    else:
        ans.append(c)
ans[-1]=chr(ord(ans[-1])+k)
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
s=str(input())
K=int(input())
ans=''
alpha='abcdefghijklmnopqrstuvwxyz' #26
a=len(s)
for i in range(a):
    t=alpha.index(s[i])
    if i==a-1:
        ichi=(t+K)%26
        ans += alpha[ichi]
    elif s[i]!='a' and K>26-alpha.index(s[i]):
        ans += 'a'
        K -= 26-alpha.index(s[i])
    else:
        ans += s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import string
import sys
s = input()
k = int(input())
a = [ord(_) for _ in s]
for i in range(len(s)-1):
   df = ord('z') - a[i] + 1
   if k >= df:
       a[i] = ord('a')
       k -= df
   if k == 0:
        break
if k != 0:
    k = k % 26
    a[len(a)-1] += k -26 if ord('z') < k + a[len(a)-1] else k
[print(chr(_), end="") for _ in a]
print("")

Submission status: Wrong Answer

Solution code:
import string
import sys
s = input()
k = int(input())
a = [ord(_) for _ in s]
for i in range(len(s)-1):
   print(k)
   df = ord('z') - a[i] + 1
   if k >= df:
       a[i] = ord('a')
       k -= df
   if k == 0:
        break
if k != 0:
    k = k % 26
    a[len(a)-1] += k -26 if ord('z') < k + a[len(a)-1] else k
[print(chr(_), end="") for _ in a]
print("")

Submission status: Wrong Answer

Solution code:
import string
import sys
s = input()
k = int(input())
a = [ord(_) for _ in s]
for i in range(len(s)-1):
   print(k)
   df = ord('z') - a[i] + 1
   if k >= df:
       a[i] = ord('a')
       k -= df
   if k == 0:
        break
if k != 0:
    k = k % 26
    print(k)
    a[len(a)-1] += k -26 if ord('z') < k + a[len(a)-1] else k
[print(chr(_), end="") for _ in a]
print("")

Submission status: Wrong Answer

Solution code:
import string
import sys
s = input()
k = int(input())
a = [ord(_) for _ in s]
for i in range(len(s)-1):
   df = ord('z') - a[i] + 1
   if k >= df:
       a[i] = 97
       k -= df
   if k == 0:
        break
if k != 0:
    k = k % 26
    a[len(a)-1] += k
[print(chr(_), end="") for _ in a]
print("")

Submission status: Wrong Answer

Solution code:
import string
import sys
s = input()
k = int(input())
a = [ord(_) for _ in s]
for i in range(len(s)-1):
   df = ord('z') - a[i] + 1
   if k >= df:
       a[i] = 97
       k -= df
   if k == 0:
        break
if k != 0:
    k = k % 26
    a[len(a)-1] = 97+k
[print(chr(_), end="") for _ in a]

Submission status: Wrong Answer

Solution code:
#import ascii
#def ctoi(ch):
#	return ch - 97

def itoc(i):
	return chr(i+97)
s = raw_input()
s = map(lambda x: ord(x) - 97, s)
K = input()
N = len(s)
#print("s", s)
for i in range(N):
	if s[i] + K <= 25:
		pass
	elif s[i] != 0:
		K = K - (25 - s[i]) - 1
		s[i] = 0
	else:
		pass
	if K == 0:
		break
#print(s)
#print(K)

for i in range(N-1, -1, -1):
	if s[i] + K <= 25:
		s[i] = s[i] + K
		K = 0
		break
	else:
		K = K - (26 - s[i])
		s[i] = 0
#print(K)
tmp = [itoc(item) for item in s]
print("".join(tmp))

Submission status: Wrong Answer

Solution code:
#import ascii
#def ctoi(ch):
#	return ch - 97

def itoc(i):
	return chr(i+97)
s = raw_input()
s = map(lambda x: ord(x) - 97, s)
K = input()
N = len(s)
#print("s", s)
for i in range(N):
	if s[i] + K <= 25:
		pass
	elif s[i]!=0:
		K = K - (25 - s[i]) - 1
		s[i] = 0
	else:
		pass
	if K == 0:
		break
#print(s)
#print(K)

for i in range(N-1, -1, -1):
	if s[i] + K <= 25:
		#print("aaaa")
		s[i] = s[i] + K
		K = 0
		break
	#else:
	#	K = K - (25 - s[i])
	#	s[i] = 25
#print(K)
tmp = [itoc(item) for item in s]
print("".join(tmp))

Submission status: Wrong Answer

Solution code:
#import ascii
#def ctoi(ch):
#	return ch - 97

def itoc(i):
	return chr(i+97)
s = raw_input()
s = map(lambda x: ord(x) - 97, s)
K = input()
N = len(s)
#print("s", s)
for i in range(N):
	if s[i] + K <= 25:
		pass
	else:
		K = K - (25 - s[i]) - 1
		s[i] = 0
	if K == 0:
		break
#print(s)
#print(K)

for i in range(N-1, -1, -1):
	if s[i] + K <= 25:
		#print("aaaa")
		s[i] = s[i] + K
		K = 0
		break
	else:
		K = K - (25 - s[i])
		s[i] = 25
tmp = [itoc(item) for item in s]
print("".join(tmp))

Submission status: Wrong Answer

Solution code:
s = u'{0}'.format(input())
K = int(input())

alphabet = 'abcdefghijklmnopqrstuvwxyz'
alphabets = list(alphabet)
dalphabets = {x:y for (x,y) in zip(alphabets,range(len(alphabets)))}

count = K
S = ['']*len(s)
for idx,val in enumerate(s):
    num = dalphabets[val]
    if (26-num) <= count:
        S[idx] = 'a'
        count -= (26-num)
    else:
        S[idx] = val

count %= 26
num = dalphabets[S[-1]]
S[-1] = alphabets[(num+count)%26]

print(''.join(S))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    s = input()
    k = int(input())
    a = [ord(_) - ord('a') for _ in s]
    l = len(s)
    for i in range(l):
        if k < 1:
            break
        c = a[i]
        if c == 0:
            break
        d = 26 - c
        if k >= d:
            a[i] = 0
            k -= d
    a[-1] = (a[-1] + k) % 26
    return ''.join([chr(_ + ord('a')) for _ in a])

print(f())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    s = input()
    k = int(input())
    a = [ord(_) - 97 for _ in s]
    l = len(s)
    for i in range(l):
        if k < 1:
            break
        c = a[i]
        if c == 0:
            break
        d = 26 - c
        if k >= d:
            a[i] = 0
            k -= d
    a[-1] = (a[-1] + k) % 26
    return ''.join([chr(_ + 97) for _ in a])

print(f())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    s = input()
    k = int(input())
    a = [ord(_) - 97 for _ in s]
    l = len(s)
    for i in range(l):
        if k < 1:
            break
        c = a[i]
        if c == 0:
            break
        if c + k > 25:
            a[i] = 0
            k -= 26 - c
    k %= 26
    a[-1] = a[-1] + k
    return ''.join([chr(_ + 97) for _ in a])

print(f())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    s = input()
    k = int(input())
    a = [ord(_) - 97 for _ in s]
    l = len(s)
    for i in range(l):
        if k < 1:
            break
        c = a[i]
        if c == 0:
            break
        if c + k > 25:
            a[i] = 0
            k -= 26 - c
    a[-1] = (a[-1] + k) % 26
    return ''.join([chr(_ + 97) for _ in a])

print(f())

Submission status: Wrong Answer

Solution code:

sl = list(input() )
k = int( input() )

al ="abcdefghijklmnopqrstuvwxyz"
alen = len(al)

for i in range(0,len(sl) ):
    p = alen - al.find(sl[i])
    if(p<k):
        sl[i] = 'a'
        k = k-p

#print("k,p:",k,p)

if k>0 :
    p = alen - al.find(sl[-1])  # now position
    sl[-1] = al[(k-p)%26]            # 

s = "".join(sl)
print(s)
#print(s,k,(alen-p),al[alen-p])

Submission status: Wrong Answer

Solution code:

sl = list(input() )
k = int( input() )

al ="abcdefghijklmnopqrstuvwxyz"
alen = len(al)

for i in range(0,len(sl) ):
    p = alen - al.find(sl[i])
    if(p<k):
        sl[i] = 'a'
        k = k-p

#print("k,p:",k,p)

if k>0 :
    p = alen - al.find(sl[-1])  # now position
    sl[-1] = al[k%26-p]            # 

s = "".join(sl)
print(s)
#print(s,k,(alen-p),al[alen-p])

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
d = dict()
alphabet = "abcdefghijklmnopqrstuvwxyz"
for i in range(len(alphabet)):
    d[alphabet[i]]=i
    
def f(s,k):
    s = [s[i] for i in range(len(s))]
    res = s
    L = 0
    for i in range(len(s)):
        l = max((26 - d[s[i]]) % 26, 0)
        if i==len(s)-1:
            res[i] = alphabet[(d[s[i]] + (k-L)) % 26]
        else:
            if L + l <= k:
                res[i] = "a"
                L += l
            else:
                continue
    return(''.join(res))
f(s,k)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
d = dict()
alphabet = "abcdefghijklmnopqrstuvwxyz"
for i in range(len(alphabet)):
    d[alphabet[i]]=i
    
def f(s,k):
    s = [s[i] for i in range(len(s))]
    res = s
    L = 0
    for i in range(len(s)):
        l = max((26 - d[s[i]]) % 26, 0)
        
        if i==len(s)-1:
            res[i] = alphabet[(d[s[i]] + (k-L)) % 26]
        else:
            if L + l < k:
                res[i] = "a"
                L += l
            else:
                continue
    return(''.join(res))
print(f(s,k))

Submission status: Wrong Answer

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


s_l = ['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']

def s_i(st):
    for i in range(26):
        if st == s_l[i]:
            return i + 1
            break

j = 0
while k > 0 and j < len(s)-1:
    a = s_i(s[j])
    if s[j] == 'a':
        pass
    elif 27 - a <= k:
        k = k - (27 - a)
        s = s[:j] + 'a' + s[j+1:]
    elif j == len(s) - 1:
        t = (a+k)%26 - 1
        if t >= 0:
            s = s[:j] + s_l[t]
        else:
            s = s[:j] + s_l[t + 26]
        break
    else:
        pass
    j += 1

print s

Submission status: Wrong Answer

Solution code:
def next_letter(target_string, character_position, last_K):
    """
    与えられた文字列のcharacter_position番目（ただし0からはじまる）の文字をnumber個進める
    """
    number = last_K % 26
    letter = target_string[character_position]
    letter_askii = ord(letter)
    next_letter = chr(letter_askii + number)
    # result_string = target_string[:character_position] + next_letter + target_string[character_position+1:]
    # return  result_string
    # print (next_letter)
    return next_letter

target_string = input()
K = int(input())

#まずはaにできないところまで左からaにしていく
result_string = ""
for i, letter in enumerate(target_string):
    if K == 0:
        break
    next_letter_num_to_a = (ord("z") - ord(letter) + 1) % 26
    if next_letter_num_to_a > K:
        # continue
        result_string += letter
    else:
        # target_string = target_string[:i] + "a" + target_string[i+1:]
        result_string += "a"
        K -= next_letter_num_to_a

# 最後に最下位をすすめる
if K == 0:
    # print (target_string)
    print (result_string)
else:
    last_character_pos = len(target_string) - 1
    # target_string = next_letter(target_string, last_character_pos, K)
    result_string = result_string[:last_character_pos] + next_letter(target_string, last_character_pos, K)
    print (result_string)
    # print (target_string)

Submission status: Wrong Answer

Solution code:
def next_letter(target_string, character_position, last_K):
    """
    与えられた文字列のcharacter_position番目（ただし0からはじまる）の文字をnumber個進める
    """
    number = last_K % 26
    letter = target_string[character_position]
    letter_askii = ord(letter)
    next_letter = chr(letter_askii + number)
    # result_string = target_string[:character_position] + next_letter + target_string[character_position+1:]
    # return  result_string
    print (next_letter)

target_string = input()
K = int(input())

#まずはaにできないところまで左からaにしていく
result_string = ""
for i, letter in enumerate(target_string):
    if K == 0:
        break
    next_letter_num_to_a = (ord("z") - ord(letter) + 1) % 26
    if next_letter_num_to_a > K:
        # continue
        result_string += letter
    else:
        # target_string = target_string[:i] + "a" + target_string[i+1:]
        result_string += "a"
        K -= next_letter_num_to_a

# 最後に最下位をすすめる
if K == 0:
    # print (target_string)
    print (result_string)
else:
    last_character_pos = len(target_string) - 1
    # target_string = next_letter(target_string, last_character_pos, K)
    result_string = result_string[:last_character_pos] + next_letter(target_string, last_character_pos, K)
    print (result_string)
    # print (target_string)

Submission status: Wrong Answer

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


s_l = ['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']

def s_i(st):
    return ord(st) - 96

def i_s(i):
    return chr(i+96)

j = 0
while k > 0:
    a = s_i(s[j])
    if s[j] == 'a' and j < len(s)-1:
        pass
    elif 27 - a <= k:
        k = k - (27 - a)
        s = s[:j] + 'a' + s[j+1:]
    elif j == len(s) - 1:
        t = (a+k)%26 - 1
        if t >= 0:
            s = s[:j] + i_s(t)
        else:
            s = s[:j] + i_s(t+26)
        break
    else:
        pass
    j += 1

print s

Submission status: Wrong Answer

Solution code:
import sys
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:
        count %= 26
        if ord('z') - arr[i] + 1 <= count:
            arr[i] = ord('a')
            count -= ord('z') - ord(S[i]) + 1
        arr[i] += count
        break

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

    if count == 0:
        break

for c in arr:
    sys.stdout.write(chr(c))

print('')

Submission status: Wrong Answer

Solution code:
s = raw_input()
K = input()
base = ord('a')
result = ''
    
def willA(c, i):
    a = 26 - (ord(c) - base)
    if ord(c) - base + i >= 27:
        return True, a
    else:
        return False,0
    
for i in xrange(len(s) - 1):
    f, n = willA(s[i], K)
    K = K - n
    if f:
        result += 'a'
    else:
        result += s[i]

K = K % 26
result += chr( base + (((ord(s[-1:]) - base) + K) % 26))

print result

Submission status: Wrong Answer

Solution code:
s = raw_input()
K = input()
base = ord('a')
result = ''
    
def willA(c, i):
    a = 26 - (ord(c) - base)
    if ord(c) - base + i >= 27:
        return True, a
    else:
        return False,0
    
for i in xrange(len(s) - 1):
    f, n = willA(s[i], K)
    K = K - n
    if f:
        result += 'a'
    else:
        result += s[i]

K = K % 26
result += chr( base + (((ord(s[-1:]) - base) + K) % 26))

Submission status: Wrong Answer

Solution code:
s = raw_input()
K = input()
base = ord('a')
result = ''

if len(s) == 1:
    K = K % 26
    print chr( base + (((ord(s[0]) - base) + K) % 26))
    
def willA(c, i):
    a = 26 - (ord(c) - base)
    if ord(c) - base + i >= 27:
        return True, a
    else:
        return False,0
    
for i in xrange(len(s) - 1):
    f, n = willA(s[i], K)
    K = K - n
    if f:
        result += 'a'
    else:
        result += s[i]

K = K % 26
result += chr( base + (((ord(s[-1:]) - base) + K) % 26))

Submission status: Wrong Answer

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

# K %= (len(S) * 26)

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

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

    if count == 0:
        break

for c in arr:
    sys.stdout.write(chr(c))

print('')