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:
from collections import deque
s=input()
money=int(input())
ans=deque()

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
for i in range(n-1):
    t = 123 - ord(s[i])
    if k > t:
        s[i] = "a"
        k -= t
s[-1] = chr(((k+ord(s[-1])) - 96 )%26+96)
print("".join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
for i in range(n):
    t = 123 - ord(s[i])
    if k > t:
        s[i] = "a"
        k -= t
s[-1] = chr((k % 26 )+ord(s[-1]))
print("".join(s))

Submission status: Wrong Answer

Solution code:

S = input()
s = list(S)

K = int(input())

alp = "abcedfghijklmnopqrstuvwxyz"
dic = {}

for i in range(26):
    dic[alp[i]] = (26 - i) % 26

ind = {}
for i in range(26):
    ind[alp[i]] = i

for i in range(len(s)):


    if K >= dic[s[i]]:
        K -= dic[s[i]]
        s[i] = "a"

    if i == len(s)-1:
        s[i] = alp[ (K + ind[s[i]]) % 26 ]

    #print (s,K)

print ("".join(s))

Submission status: Wrong Answer

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

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

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

    print(''.join(s))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

    print(s)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
to_a=[(ord("z")+1-ord(c))%26 for c in s]
is_a=[False for c in s]
for i in range(len(s)):
  if n>=to_a[i]:
    n-=to_a[i]
    is_a[i]=True
    to_a[i]=0
n%=26
for i in range(len(s)-1,-1,-1):
    if not is_a[i]:
        s=s[:i]+chr(ord(s[i])+n)+s[i+1:]
        n=0
        break
if n>0:
    s=s[:-1]+chr(ord("a")+n)
for i in range(len(s)):
  if is_a[i]:
    print("a",end="")
  else:
    print(s[i],end="")

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
to_a=[(ord("z")+1-ord(c))%26 for c in s]
is_a=[False for c in s]
for i in range(len(s)):
  if n>=to_a[i]:
    n-=to_a[i]
    is_a[i]=True
    to_a[i]=0
n%=26
for i in range(len(s)-1,-1,-1):
    if not is_a[i]:
        s=s[:i]+chr(ord(s[i])+n)+s[i+1:]
        break
for i in range(len(s)):
  if is_a[i]:
    print("a",end="")
  else:
    print(s[i],end="")

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
to_a=[(ord("z")+1-ord(c))%26 for c in s]
is_a=[False for c in s]
for i in range(len(s)):
  if n>=to_a[i]:
    n-=to_a[i]
    is_a[i]=True
n%=26
for i in range(len(s)-1):
  if is_a[i]:
    print("a",end="")
  else:
    print(s[i],end="")
print(chr(ord(s[-1])+n))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s_ = input()
n = len(s_)
k = int(input())
s = [ord(s_[i])-97 for i in range(n)]
#print(s)
for i in range(n-1):
    if 26-s[i]<=k:
        k -= (26-s[i])
        s[i] = 0

#print(s,k)
s[n-1] += k
s[n-1] %= 26

#print(s)
ans = [chr(s[i]+97) for i in range(n)]

print(''.join(ans))

Submission status: Wrong Answer

Solution code:
s=list(str(input()))
k=int(input())
n=len(s)
alpha2num=lambda c: ord(c)-ord('a')+1
for i in range(n):
    s[i]=alpha2num(s[i])

c=k
for i in range(n):
    if c-(27-s[i])>=0:
        if s[i]+c>26:
            c=c-(27-s[i])
            s[i]=1
#print(s[-1],c)
s[-1]+=c%26
num2alpha=lambda c: chr(c+96)
for i in range(n):
    s[i]=num2alpha(s[i])

print("".join(map(str,s)))

Submission status: Wrong Answer

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

a = [0] * len(s)
for i in range(len(s) - 1):
  a[i] =  ((ord('z') - ord(s[i])) + 1)%26
  if a[i] == 0:
    pass
  elif K - a[i] >= 0:
    K -= a[i]
    a[i] = 0

for i in range(len(s)-1):
  print(chr((26-a[i])%26+ord('a')), end = '')

if K != 0:
  b = ord('a') + (ord(s[-1])-ord('a') + K)%26
  print( chr( b ) ) 
else:
  print(chr((26-a[-1])%26+ord('a')))

Submission status: Wrong Answer

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

a = [0] * len(s)
for i in range(len(s)):
  a[i] =  ((ord('z') - ord(s[i])) + 1)%26
  if a[i] == 0:
    pass
  elif K - a[i] >= 0:
    K -= a[i]
    a[i] = 0
for i in range(len(s)-1):
  print(chr((26-a[i])%26+ord('a')), end = '')

if K != 0:
  b = ord('a') + (ord(s[-1])-ord('a') + K)%26
  print( chr( b ) ) 
else:
  print(chr((26-a[-1])%26+ord('a')))

Submission status: Wrong Answer

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

a = [0] * len(s)
for i in range(len(s)):
  a[i] =  ((ord('z') - ord(s[i])) + 1)%26
  if a[i] == 0:
    pass
  elif K - a[i] >= 0:
    K -= a[i]
    a[i] = 0
for i in range(len(s)-1):
  print(chr((26-a[i])%26+ord('a')), end = '')

b = ord('a') + (ord(s[-1])-ord('a') + K)%25
print( chr( b ) )

Submission status: Wrong Answer

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

a = [0] * len(s)
for i in range(len(s)):
  a[i] =  ((ord('z') - ord(s[i])) + 1)%26
  if a[i] == 0:
    pass
  elif K - a[i] >= 0:
    K -= a[i]
    a[i] = 0
for i in range(len(s)-1):
  print(chr((26-a[i])%26+ord('a')), end = '')

b = ord('a') + (ord(s[-1])-ord('a') + K)%26
print( chr( b ) )

Submission status: Wrong Answer

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

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

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

print(new)

Submission status: Wrong Answer

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

num = [26 - i for i in range(26)]

a_ = ord('a')

ans = ''
for c in s:
    x = ord(c) - a_
    if num[x] <= k:
        ans += 'a'
        k -= num[x]
    else:
        ans += c
k %= 26
if k > 0:
    c = ans[-1]
    ans = ans[:-1] + chr(a_ + ((ord(c) - a_ + k) % 26))
print(ans)

Submission status: Wrong Answer

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

if k>0:
    if ord("z")-ord(s[-1])>=k:
        s[-1]=chr(ord(s[-1])+k)
    else:
        k-=ord("z")-ord(s[-1])+1
        k%=26
        s[-1]=chr(ord("a")+k)

print("".join(s))

Submission status: Wrong Answer

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

if k>0:
    if ord("z")-ord(s[-1])>k:
        s[-1]=chr(ord(s[-1])+k)
    else:
        k-=ord("z")-ord(s[-1])+1
        k%=26
        s[-1]=chr(ord("a")+k)

print("".join(s))

Submission status: Wrong Answer

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

if k>0:
    if ord("z")-(ord(s[-1])+k)<=0:
        k-=ord("z")-ord(s[-1])+1
        k%=26
        s[-1]=chr(ord("a")+k)
    else:
        s[-1]=chr(ord(s[-1])+k)

print("".join(s))

Submission status: Wrong Answer

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

if k>0:
    if ord("z")-(ord(s[-1])+k)<0:
        k-=ord("z")-ord(s[-1])+1
        k%=26
        s[-1]=chr(ord("a")+k)
    else:
        s[-1]=chr(ord(s[-1])+k)

print("".join(s))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
string="abcdefghijklmnopqrstuvwxyz"
lists=[0 for i in range(len(s))]
for i in range(len(s)):
    lists[i]=s[i]

dic={}
for i in range(26):
    dic[string[i]]=(26-i)%26
print(dic)
ans=0
for i in range(len(s)):
    ans=ans+dic[lists[i]]
    if ans<=k:
        lists[i]="a"
    elif ans>=k:
        ans=ans-dic[lists[i]]
    if i==len(s)-1:

        left=(k-ans)%26
        index=dic[lists[len(s)-1]]
        index-=left
        strings="a"
        for some in dic.keys():
            if dic[some]==index%26:
                strings=some
        lists[i]=strings                   
an=""
for j in lists:
    an+=j
print(an)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
string="abcdefghijklmnopqrstuvwxyz"
lists=[0 for i in range(len(s))]
for i in range(len(s)):
    lists[i]=s[i]

dic={}
for i in range(26):
    dic[string[i]]=26-i

ans=0
for i in range(len(s)):
    ans=ans+dic[lists[i]]
    if ans<=k:
        lists[i]="a"
    elif ans>=k:
        ans=ans-dic[lists[i]]
    if i==len(s)-1:

        left=(k-ans)%26
        index=dic[lists[len(s)-1]]
        index-=left
        strings="a"
        for some in dic.keys():
            if dic[some]==index%26:
                strings=some
        lists[i]=strings                   
an=""
for j in lists:
    an+=j
print(an)

Submission status: Wrong Answer

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

if k:
    if ord("z")-(ord(s[-1])+k)<0:
        k-=ord("z")-ord(s[-1])+1
        k%=26
        s[-1]=chr(ord("a")+k)
    else:
        s[-1]=chr(ord(s[-1])+k)

print("".join(s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
alpha2num = lambda c: ord(c) - ord('a') + 1
num2alpha = lambda c: chr(c+96)

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

N = len(s)
apos = [alpha2num(i) for i in s]

a = []
for i, v in enumerate(apos):
  if i > N - 2:
    break
  diff = 27 - v 
  if K >= diff:
    K -= diff
    a.append(num2alpha(1))
  else:
    a.append(num2alpha(v))

# 残りのKを消化
lastw = (K + apos[-1] - 1) % 26 + 1
a.append(num2alpha(lastw))
print("".join(a))

Submission status: Wrong Answer

Solution code:
alpha2num = lambda c: ord(c) - ord('a') + 1
num2alpha = lambda c: chr(c+96)

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

N = len(s)
apos = [alpha2num(i) for i in s]

a = []
for i, v in enumerate(apos):
  if i > N - 2:
    break
  diff = 27 - v 
  if K >= diff:
    K -= diff
    a.append(num2alpha(1))
  else:
    a.append(num2alpha(v))

# 残りのKを消化
_, lastw = divmod(K + apos[-1] - 1, 26)
lastw += 1
a.append(num2alpha(lastw))
print("".join(a))

Submission status: Wrong Answer

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

ans = ''
i = 0
while(K>0):
  if i == len(S)-1:
    K %= 26
    ans += chr(((ord(S[i])-97)+K)%26+97)
    K = 0
  else:
    a = 26-(ord(S[i])-97)
    if a != 26 and K >= a:
      ans += 'a'
      K -= a
    else:
      ans += S[i]
  i += 1
print(ans)

Submission status: Wrong Answer

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

ans = ''
i = 0
while(K>0):
  if i == len(S)-1:
    K %= 26
    ans += chr(((ord(S[i])-97)+K)%26+97)
    K = 0
  else:
    if S[i] != 'a':
      a = 26-(ord(S[i])-97)
      if K >= a:
        ans += 'a'
        K -= a
      else:
        ans += S[i]
    else:
      ans += S[i]
  i += 1
print(ans)

Submission status: Wrong Answer

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

ans = ''
i = 0
while(K>0):
  if i == len(S)-1:
    K %= 26
    ans += chr(((ord(S[i])-97)+K)%26+97)
    K = 0
  else:
    if S[i] != 'a':
      a = 26-(ord(S[i])-97)
      if K > a:
        ans += 'a'
        K -= a
      else:
        ans += S[i]
    else:
      ans += S[i]
  i += 1
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

s_list=list(s)
len_s=len(list(s))
temp1=k
temp2=0
for i in range(len_s):
	if (123-ord(s_list[i])<=temp1)&(temp1>=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))

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import string

S = list(input())
K = int(input())
alpha = string.ascii_lowercase

s = len(S)
if s == 1:
    K %= 26
    print(alpha[K])
    exit()

for i in range(s):
    num = 26 - alpha.index(S[i])
    if num <= K:
        K -= num
        S[i] = 'a'
    else:
        pass

if K > 0:
    K %= 26
    num = alpha.index(S[-1]) + K
    S[-1] = alpha[num]

print(*S, sep='')

Submission status: Wrong Answer

Solution code:
s = input()
k =int(input())
sn = []
sa = []
num2alpha = lambda c: chr(c+64)
alpha2num = lambda c: ord(c) - ord('A') + 1

for c in s:
    sn.append(alpha2num(c))

for i in range(0,len(sn)-1):
    if 59 - sn[i] <= k:
        k -= 59 - sn[i]
        sn[i] = 33
    else:
        continue

sn[-1] = (sn[-1] + k-33) % 26 + 33

for c in sn:
    sa.append(num2alpha(c))

print("".join(sa))

Submission status: Wrong Answer

Solution code:
s = input()
k =int(input())
sn = []
sa = []
num2alpha = lambda c: chr(c+64)
alpha2num = lambda c: ord(c) - ord('A') + 1

for c in s:
    sn.append(alpha2num(c))

for i in range(0,len(sn)-1):
    if 59 - sn[i] <= k:
        k -= 59 - sn[i]
        sn[i] = 33
    else:
        continue

sn[-1] = (sn[-1] + k-32) % 26 + 32

for c in sn:
    sa.append(num2alpha(c))

print("".join(sa))

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import bisect

mod = 10**9+7
dd = ((-1,0),(1,0),(0,-1),(0,1))

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(list(sys.stdin.readline())[:-1])
def IR(n): return([I() for _ in range(n)])

def GCD(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def LCM(a,b):
    return a * b // GCD(a,b)

def main():
    s = S()
    K = I()
    N = len(s)

    for i in range(N):
        if K==0:
            break
        if ord("z")-ord(s[i])<K:
            K -= ord("z")-ord(s[i])+1
            s[i] = "a"
    
    
    if K>0:
        K %= 26

    if ord(s[N-1])+K > ord("z"):
        s[N-1] = chr(ord(s[N-1])+K-26)
    else:
        s[N-1] = chr(ord(s[N-1])+K)
    return("".join(s))




if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import bisect

mod = 10**9+7
dd = ((-1,0),(1,0),(0,-1),(0,1))

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(list(sys.stdin.readline())[:-1])
def IR(n): return([I() for _ in range(n)])

def GCD(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def LCM(a,b):
    return a * b // GCD(a,b)

def main():
    s = S()
    K = I()
    N = len(s)

    for i in range(N):
        if K==0:
            break
        if ord("z")-ord(s[i])<K:
            K -= ord("z")-ord(s[i])+1
            s[i] = "a"
    
    
    if K>0:
        K %= 26

    s[N-1] = chr(ord(s[N-1])+K)
    return("".join(s))




if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

Solution code:
s = input()
ans = ""
k = int(input())
x = "abcdefghijklmnopqrstuvwxyz"

for i in range(len(s)-1):
    if (26-(ord(s[i])-ord("a")))%26 < k:
        ans += "a"
        k -= (26-(ord(s[i])-ord("a")))%26 
    else:
        ans += s[i]

last = x[(ord(s[-1])-ord("a")+k)%26]
ans += last

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ans = ""
k = int(input())
x = "abcdefghijklmnopqrstuvwxyz"

for i in range(len(s)-1):
    if (26-(ord(s[i])-ord("a")))%26 < k:
        ans += "a"
        k -= (26-(ord(s[i])-ord("a")))%26 
    else:
        ans += s[i]

last = s[len(s)-1]
for j in range(k%26):
    last = x[(int(ord(last))-int(ord("a"))+1)%26]
ans += last

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#CODEFESTIVAL2016 qual A C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
k = I()
n = len(s)
alpha = 'abcdefghijklmnopqrstuvwxyz'
ans = ''
for i in range(n-1):
    a = 26 - alpha.index(s[i])
    if a <= k:
        k -= a
        ans += 'a'
    else:
        ans += s[i]
if k > 0:
    tmp = alpha.index(s[-1])
    ans += alpha[(tmp + k % 27) % 26]
else:
    ans += s[-1]
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#CODEFESTIVAL2016 qual A C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
k = I()
n = len(s)
alpha = 'abcdefghijklmnopqrstuvwxyz'
ans = ''
for i in range(n-1):
    a = 26 - alpha.index(s[i])
    if a <= k:
        k -= a
        ans += 'a'
    else:
        ans += s[i]
if k > 0:
    tmp = alpha.index(s[-1])
    ans += alpha[(tmp + k % 26) % 26]
else:
    ans += s[-1]
print(ans)