Problem:


Score : 400 points

Problem Statement

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

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

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

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

Constraints

1≤|s|≤10^5

All letters in s are lowercase English letters.

1≤K≤10^9

Input

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

s
K

Output

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

Sample Input 1

xyz
4

Sample Output 1

aya

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

Sample Input 2

a
25

Sample Output 2

z

You have to perform exactly K operations.

Sample Input 3

codefestival
100

Sample Output 3

aaaafeaaivap



Sample input:
xyz
4


Sample output:
aya

Submission status: Accepted

Solution code:
#"a" 97 "z" 122
s = list(ord(i) for i in input())
k = int(input())

for i in range(len(s)-1):
  if s[i] == ord("a"): continue
  t = ord("z")+1-s[i]
  if k >= t:
    s[i] = 97
    k -= t
if k > 0:
  k %= 26
  s[-1] += k
  if s[-1] > ord("z"):
    s[-1] -= 26
print("".join(list(map(chr, s))))

Submission status: Accepted

Solution code:
dic = {"a":0,"b":25,"c":24,"d":23,"e":22,"f":21,"g":20,"h":19,"i":18,"j":17,"k":16,"l":15,"m":14,"n":13,"o":12,"p":11,"q":10,"r":9,"s":8,"t":7,"u":6,"v":5,"w":4,"x":3,"y":2,"z":1}
ls = ["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"]

s = input()
k = int(input())
s_l = []
for i in range(len(s)):
    s_l.append(s[i])

for i in range(len(s_l)):
    if dic[s_l[i]] <= k:
        k -= dic[s_l[i]]
        s_l[i] = "a"

if k > 0:
    s_l[-1] = ls[((26 - dic[s_l[-1]]) + k)%26]

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

Submission status: Accepted

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

ns = []
for c in s[:-1]:
    if c == 'a':
        ns.append(c)
        continue

    ofstoa = ord('z')+1-ord(c)
    if k >= ofstoa:
        ns.append(chr(ord(c) + ofstoa - 26))
        k -= ofstoa
    else:
        ns.append(c)

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

Submission status: Accepted

Solution code:
# 頭から順にaに変えていく

import sys
readline = sys.stdin.readline

S = list(readline().rstrip())
K = int(readline())

z = ord("z")
for i in range(len(S) - 1):
  # aにするためのコストを求める
  if S[i] == "a":
    continue
  cost = z + 1 - ord(S[i])
  if cost <= K:
    S[i] = "a"
    K -= cost

K %= 26
nex = ord(S[-1]) + K
if nex > ord("z"):
  nex -= 26
S[-1] = chr(nex)

print("".join(S))

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
k = inn()
n = len(s)
t = [ord(c)-ord('a') for c in s]
for i in range(n):
    if t[i]>0 and k>=26-t[i]:
        k -= 26-t[i]
        t[i] = 0
if k>0:
    t[n-1] = (t[n-1]+k)%26
print(''.join([chr(t[i]+ord('a')) for i in range(n)]))

Submission status: Accepted

Solution code:
s=input()
k=int(input())
ans=""
for i in s[:-1]:
    if i=="a":
        ans+=i
        continue
    if k>=123-ord(i):
        k-=123-ord(i)
        ans+="a"
    else:
        ans+=i
i=s[-1]
ans+=chr((ord(i)+k-97)%26+97)
print(ans)

Submission status: Accepted

Solution code:
s = input()
k = int(input())
ans = ''
for i,v in enumerate(s):
    if (ord('a') - ord(v))%26 <= k:
        k -= (ord('a') - ord(v))%26
        ans += 'a'
    else:
        ans += v
k %= 26
last = chr(ord('a')+(ord(ans[-1])-ord('a')+k)%26)

print(ans[:-1]+last)

Submission status: Accepted

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

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


print(''.join(Ans))

Submission status: Accepted

Solution code:
s = input()
k = int(input())
f = lambda x: (ord('a') - ord(x))%26
ans = ''
for c in s:
    if k>=f(c):
        ans += 'a'
        k -= f(c)
    else:
        ans += c
ans = ans[:-1] + chr(ord('a') + (ord(ans[-1])-ord('a')+k)%26)
print(ans)

Submission status: Accepted

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

for i in range(n):
    x = ord(s[i]) - ord('a')
    if x == 0 or 26 -x > k: continue
    k -= 26 - x
    s[i] = 'a'

if k:
    s[-1] = chr((ord(s[-1]) - ord('a') + k) % 26 + ord('a'))

print(''.join(s))

Submission status: Accepted

Solution code:
s = list(input())
k = int(input())
n = len(s)
al=[chr(ord('a') + i) for i in range(26)]

for i in range(n):
    now = ord(s[i]) - ord('a')
    if now != 0:
        if k >= 26 - now:
            s[i] = "a"
            k -= 26 - now
        
s[n-1] = al[(ord(s[n-1])-ord("a") + k) % 26]

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

Submission status: Accepted

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

for i in range(n-1):
    t=s[i]
    order=ord(t)-97
    if order==0:
        continue
    elif k>=26-order:
        s[i]='a'
        k-=26-order
    else:
        continue
s[n-1]=chr(97+(ord(s[n-1])-97+k)%26)

print(''.join(s))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = list(input())
K = INT()

def ctoi(c):
	return ord(c) - ord('a')

for i in range(len(s)):
	x = ctoi(s[i])
	if x == 0 or 26-x > K:  continue
	K -= 26-x
	s[i] = "a"
if K:
	s[-1] = ascii_lowercase[(ctoi(s[-1])+K)%26]
print("".join(s))

Submission status: Accepted

Solution code:
# coding: utf-8
S=list(input())
K=int(input())
N=len(S)

L=[]

for i in range(N):
    L.append((26-(ord(S[i])-ord("a")))%26)

for i in range(N):
    if K>=L[i]:
        S[i]="a"
        K-=L[i]

if K>0:
    S[-1]=chr(ord("a")+((ord(S[-1])+K-ord("a"))%26))

print("".join(S))

Submission status: Accepted

Solution code:
def codefes16qa_c():
    s = str(input())
    k = int(input())
    n = len(s)
    ans = ''
    for i in range(n):
        if s[i] == 'a':
            ans += s[i]
            continue
        step2a = 1 + ord('z') - ord(s[i])
        if step2a <= k:
            ans += 'a'
            k -= step2a
        else:
            ans += s[i]
    if k > 0:
        last = ord(ans[-1]) + (k % 26)
        ans = ans[:n-1] + chr(last)
    print(ans)

codefes16qa_c()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

s = list(ns())
n = len(s)
k = ni()

for i in range(n):
    if s[i] != 'a':
        if ord('z') + 1 - ord(s[i]) <= k:
            k -= ord('z') + 1 - ord(s[i])
            s[i] = 'a'

if k >= 1:
    s[-1] = chr((ord(s[-1]) - ord('a') + k) % 26 + ord('a'))

print(*s, sep="")

Submission status: Accepted

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

    for i in range(len(s)-1):
        if s[i] == 'a':
            continue
        else:
            mod = 26-(ord(s[i])-97)%26
            if k >= mod:
                k -= mod
                s[i] = 'a'
            if k == 0:
                break
    
    if k > 0:
        mod = ((ord(s[-1])-97)+k)%26
        s[-1] = chr(mod+97)
    print(''.join(s))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = list(input()) #sys.stdin.readlineは最後が改行
k = int(input())

now = 0

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

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

print(*s,sep='')

Submission status: Accepted

Solution code:
def main():
    s=list(input())
    k=int(input())
    i=0
    while k>=0 and i<len(s)-1:
        if s[i]!='a' and k>=123-ord(s[i]):
            k-=123-ord(s[i])
            s[i]="a"
        i+=1
    if i==len(s)-1:
        s[-1]=chr(97+(k-(123-ord(s[i])))%26)
    print("".join(s))
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
alphabet = list("abcdefghijklmnopqrstuvwxyz")
s = list(input())
S = [alphabet.index(x) for x in s]
K = int(input())
tmp = K
i = 0
while i < len(S) and tmp > 0:
  if S[i] != 0 and 26-S[i] <= tmp:
    tmp -= 26-S[i]
    S[i] = 0
  i += 1
if tmp > 0:
  S[-1] = (S[-1]+tmp)%26
print("".join([alphabet[x] for x in S]))

Submission status: Accepted

Solution code:
X='abcdefghijklmnopqrstuvwxyz'*2
S=input()
k=int(input())
N=[]
for s in S:
    if s=='a':
        N.append(0)
    else:
        N.append(26-X.index(s))
ans=''
for i in range(len(S)):
    if N[i]<=k :
        k-=N[i]
        ans+='a'
    else:
        ans+=S[i]
ans=ans[:-1]+X[X.index(ans[-1])+k%26]

print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_c

s = input()
k = int(input())
n = len(s)
ans = []
for i in range(n):
    t = (ord('z') - ord(s[i]) + 1) % 26
    if k - t >= 0:
        ans.append('a')
        k -= t
    else:
        ans.append(s[i])
if k > 0:
    k %= 26
    ans[-1] = chr(ord(ans[-1]) + k)
print(''.join(ans))

Submission status: Accepted

Solution code:
S=list(input())
k=int(input())
Ans=[0]*len(S)
c=0
for i in range(len(S)):
  if (26-(ord(S[i])-97))%26<=k:
    Ans[i]="a"
    k=k-(26-(ord(S[i])-97))%26
    c=c+(26-(ord(S[i])-97))%26
  else:
    Ans[i]=S[i]
  if i==len(S)-1:
    c=ord(Ans[i])+k%26
    if ord(Ans[i])+k%26>=123:
      c=c-26
    Ans[i]=chr(c)
print("".join(Ans))

Submission status: Accepted

Solution code:
s=list(input())
K=int(input())
i=0
while i<len(s):
    if i==len(s)-1:
        s[i]=chr(97+(ord(s[i])-97+K)%26)
        break
    if K<abs(123-ord(s[i]))%26:
        i+=1
    elif K>=abs(123-ord(s[i]))%26:
        sub=abs(123-ord(s[i]))%26
        s[i]="a"
        K-=sub
        i+=1
print("".join(s))

Submission status: Accepted

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

i=0
l=''
while i<len(S)-1:
    if S[i]=='a':
        l+='a'
    elif 123-ord(S[i])<=K:
        l+='a'
        K-=123-ord(S[i])
    else:
        l+=S[i]
    i+=1

if K>0:
    K%=26
    n=ord(S[-1])+K
    if n>122:
        n-=26
    l+=chr(n)
else:
    l+=S[-1]


print(l)

Submission status: Accepted

Solution code:
s = [ord(i) for i in input()]
k = int(input())
for i in range(len(s)):
    if s[i] == 97: continue
    if 123 - s[i] <= k:
        k -= 123 - s[i]
        s[i] = 97
        if k == 0:
            break
if k != 0:
    s[-1] = s[-1] + k % 26
print("".join([chr(i) for i in s]))

Submission status: Accepted

Solution code:
import sys

s = list(sys.stdin.readline().strip())
K = int(sys.stdin.readline().strip())

i = 0
while i < len(s):
    if K == 0:
        break

    # 最後の文字の場合は限界まで操作する
    if i == len(s) - 1:
        n = (ord(s[i]) - ord("a") + K) % 26
        # print(n)
        s[i] = chr(ord("a") + n)
        break

    if s[i] == "a":
        i += 1
        continue

    # それ以外の場合、aにできるなら操作する
    # aに変換するまでの操作回数
    n = 26 - (ord(s[i]) - ord("a"))
    # print(n)
    if n <= K:
        s[i] = "a"
        K -= n

    i += 1

print("".join(s))

Submission status: Accepted

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

alp = list('abcdefghijklmnopqrstuvwxyz')
moji_li = []
count_li = []
for ss in s_li:
    ind = alp.index(ss)
    moji_li.append(alp.index(ss))
    count_li.append(26 - alp.index(ss))
for i,c in enumerate(count_li):
    #print(i,len(count_li)-1)
    if i == len(count_li)-1:
        moji_li[i]+= k
        break
    else:
        if c == 26:
            continue
        if c<=k:
            k-=c
            moji_li[i]=0
ans = ''
#print('count_li',count_li)
#print(moji_li)
for m in moji_li:
    ans += alp[m%26]
print(ans)

Submission status: Accepted

Solution code:
s=input()
n=int(input())
l=""
for i in range(len(s)):
    f=(26+ord("a")-ord(s[i]))%26
    if n>=f:n-=f;l+="a"
    else:l+=s[i]
    if n==0:print(l+s[i+1:]);exit()
print(l[:-1]+chr(ord(l[-1])+n%26))

Submission status: Accepted

Solution code:
s=list(input())
k=int(input())
for e,i in enumerate(s):
    c=(123-ord(i))%26
    if k>=c:
        s[e]="a"
        k-=c
    else:s[e]=i
l = chr((ord(s[-1])-97+k)%26+97)
print("".join(s[:-1])+l)

Submission status: Accepted

Solution code:
s = list(input())
k = int(input())
abc = "abcdefghijklmnopqrstuvwxyz"
c = 0
for e,i in enumerate(s):
    # print(26-abc.index(i))
    if k-26+abc.index(i)>=0 and i!='a':
        s[e] = 'a'
        k-=26-abc.index(i)
    # print(k)  
k+=abc.index(s[-1])
k%=26
s[-1] = abc[k]

print("".join(s))

Submission status: Accepted

Solution code:
a = list(input())
k = int(input())
abc = "abcdefghijklmnopqrstuvwxyz"
c = 0
for e,i in enumerate(a[:-1]):
    # print(26-abc.index(i))
    if k-26+abc.index(i)>=0 and i!='a':
        a[e] = 'a'
        k-=26-abc.index(i)
    # print(k)  
k+=abc.index(a[-1])
k%=26
a[-1] = abc[k]

print("".join(a))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    k=int(input())
    len_s=len(s)
    new_s=""
    for i,ss in enumerate(s[:-1]):
        t=ord('z')-ord(ss)+1
        if t<=k and ss!='a':
            k-=t
            new_s+='a'
        else:
            new_s+=ss
    if ord(s[-1])+k%26<=ord('z'):
        new_s+=chr(ord(s[-1])+k%26)
    else:
        new_s+=chr(ord(s[-1])+k%26-26) 
    print(new_s)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
k=int(input())
n=len(s)
s=[s[i] for i in range(n)]
l={"a":26,"b":25,"c":24,"d":23,"e":22,"f":21,"g":20,"h":19,"i":18,"j":17,"k":16,"l":15,"m":14,"n":13,"o":12,"p":11,"q":10,"r":9,"s":8,"t":7,"u":6,"v":5,"w":4,"x":3,"y":2,"z":1}
for i in range(n):
    c=s[i]
    if c=="a":
        continue
    if l[c]>k:
        continue
    k-=l[c]
    s[i]="a"
if k>0:
    k=k%26
    c=s[-1]
    for i in l:
        if l[i]==l[c]-k:
            s[-1]=i
s=''.join(s)
print(s)

Submission status: Accepted

Solution code:
z=ord('z')
a=ord('a')
ss=input()
s=list(ss)
k=int(input())
l=len(s)

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

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

ans=''.join(s)
print(ans)

Submission status: Accepted

Solution code:
s=input()
ls = len(s)
k= int(input())
for i in range(ls-1):
    tn = ord('z')-ord(s[i])+1
    if k>=tn and s[i]!='a':
        k-=tn
        print('a',end='')
    else:
        print(s[i],end='')
ik = (k + ord(s[-1])-ord('a')) % 26
print(chr(ord('a')+ik))

Submission status: Accepted

Solution code:
import sys
from string import ascii_lowercase as AL

input = sys.stdin.readline


def main():
    S = input().rstrip()
    K = int(input())

    N = len(S)
    T = [s for s in S]
    for i in range(N):
        if T[i] == "a":
            continue
        idx = AL.index(T[i])
        if 26 - idx <= K:
            K -= (26 - idx)
            T[i] = "a"

    _, r = divmod(K, 26)
    T[-1] = AL[AL.index(T[-1]) + r]

    ans = "".join(T)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools

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

alp = list('abcdefghijklmnopqrstuvwxyz')

index_list = [alp.index(s[i]) for i in range(len(s))]

cnt_list = []
for j in index_list:
    if j > 0:
        cnt_list.append(26-j)
    else:
        cnt_list.append(0)

s_list = list(s)

if sum(cnt_list) <= K:
    num = (K - sum(cnt_list)) % 26
    l = "a" * (len(s)-1) + alp[num]
    print(l)
else:
    i = 0
    for i in range(len(s)):
        if i == len(s)-1:
            if K >= cnt_list[i]:
                num = (K - cnt_list[i]) % 26
                s_list[i] = alp[num]
            else:
                s_list[i] = alp[K-cnt_list[i]]
        elif K >= cnt_list[i]:
            K -= cnt_list[i]
            s_list[i] = 'a'
        else:
            pass
    ans = ''.join(s_list)
    print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    s = list(input().strip())
    K = int(input())
    for i, c in enumerate(s):
        if c == 'a':
            continue
        z = 123 - ord(c)
        if K >= z:
            s[i] = 'a'
            K -= z
        if K == 0:
            break
    
    s[-1] = chr(((ord(s[-1])-97+K))%26+97)

    print(''.join(s))

if __name__ == '__main__':
     main()

Submission status: Accepted

Solution code:
S = input()
K = int(input())
N = len(S)
A = [0]*N

ans = ""
for i in range(N):
  A[i] = (ord("z") - ord(S[i]) + 1) % 26
  if i != N-1:
    if K >= A[i]:
      K -= A[i]
      ans += "a"
    else:
      ans += S[i]
  else:
    K = K % 26
    s = ord(S[i]) + K
    if s > ord("z"):
      s -= 26
    ans += chr(s)
    
print(ans)

Submission status: Accepted

Solution code:
import sys

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


def resolve():
    s = list(input())
    k = int(input())
    alphabet = [chr(i) for i in range(97, 97 + 26)]

    for i in range(len(s)):
        if s[i] == "a":
            continue

        idx = alphabet.index(s[i])
        if 26 - idx <= k:
            s[i] = "a"
            k -= 26 - idx

    if k:
        idx = alphabet.index(s[i]) + k % 26
        s[-1] = alphabet[idx]

    print("".join(s))



if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def main():
    s = input()
    K = int(input())
    new_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']
    d = {
        "a": 0,
        "b": 25,
        "c": 24,
        "d": 23,
        "e": 22,
        "f": 21,
        "g": 20,
        "h": 19,
        "i": 18,
        "j": 17,
        "k": 16,
        "l": 15,
        "m": 14,
        "n": 13,
        "o": 12,
        "p": 11,
        "q": 10,
        "r": 9,
        "s": 8,
        "t": 7,
        "u": 6,
        "v": 5,
        "w": 4,
        "x": 3,
        "y": 2,
        "z": 1,
    }

    for i in range(len(s)-1):
        if d[s[i]] <= K:
            K -= d[s[i]]
            new_s += 'a'
        else:
            new_s += s[i]

    new_s += l[(l.index(s[-1]) + K) % 26]

    print(new_s)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

len_s = len(s)
moji = [0]*(len_s)

for i in range(len_s):
    num = 26-(ord(s[i])-ord('a'))
    if num <= k and num != 26:
        moji[i] = 'a'
        k -= num
    else:
        moji[i] = s[i]

     
if k != 0:
    #print(k)
    moji[len_s-1] = chr(ord(moji[len_s-1])+k%26)
        
print(*moji,sep='')

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    a = list(input())
    K = int(input())
    for i in range(len(a)):
        if a[i]=='a':
            val=0
        else:
            val = 123 - ord(a[i])

        if val <= K:
            a[i] = 'a'
            K -= val
        if i == len(a) - 1 and K > 0:
            a[-1] = chr(ord(a[-1]) + K % 26)
    print(''.join(a))


resolve()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    a = list(input())
    K = int(input())
    for i in range(len(a)):
        if a[i]=='a' and i!=len(a)-1:
            continue
        else:
            val = 123 - ord(a[i])
            if val <= K:
                a[i] = 'a'
                K -= val
            if i == len(a) - 1 and K > 0:
                a[-1] = chr(ord(a[-1]) + K % 26)
    print(''.join(a))


resolve()

Submission status: Accepted

Solution code:
s=input()
k=int(input())
a2n = lambda c: ord(c) - ord('a') + 1
n2a = lambda c: chr(c+64).lower()
ls=list(s)
i=0
while k>0 and i<len(ls):
  a=(1-a2n(ls[i]))%26
  if k>=a:
    ls[i]='a'
    k-=a
  i+=1
if k>0:
  ls[-1]=n2a(a2n(ls[-1])+k%26)
print(''.join(ls))

Submission status: Accepted

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])%26
    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)]
for i in range(n):        
    ans[i] = chr(a[i]+ord('a'))
print(''.join(map(str,ans)))

Submission status: Accepted

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

for i in range(len(s)):
  if s[i] != "a" and ord("z") + 1 - ord(s[i]) <= k :
    k -= ord("z") + 1 - ord(s[i])
    s[i] = "a"
    
    
if k > 0:
  k = k % 26
  if ord(s[-1]) + k <= ord("z"):
    s[-1] = chr(ord(s[-1]) + k)
  else:
    s_num = ord("a") +  ord(s[-1]) + k - ord("z")
    s[-1] = chr(s_num)
  
print("".join(s))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
k=int(input())
ans=[]
for i in range(n):
    if i==n-1:
        ans.append(chr(((ord(s[i])-97+k)%26)+97))
    else:

        if s[i]=="a":
            ans.append("a")
        else:
            if 26-(ord(s[i])-97)<=k:
                ans.append("a")
                k-=(26-(ord(s[i])-97))
            else:
                ans.append(s[i])
print("".join(ans))

Submission status: Accepted

Solution code:
s=list(input())
N=len(s)
K=int(input())
num=123

for i in range(N):
    diff=(num-ord(s[i]))%26
    if K==0:
        break
    if diff<=K:
        s[i]="a"
        K=K-diff
#print(s)
#print(K)
if K>0:
    K=K%26
    s[N-1]=chr(ord(s[N-1])+K)
#print(s)
print("".join(s))

Submission status: Accepted

Solution code:
original_s = list(input())
s = list(map(lambda x:ord(x)-97-26, original_s))
K = int(input())

ans = original_s
for i in range(len(s)):
    if abs(s[i]) <= K and s[i] != -26:
        ans[i] = "a"
        K += s[i]

ans[-1] = chr(((ord(ans[-1]) + K) - 97) % 26 + 97)

print("".join(ans))

Submission status: Accepted

Solution code:
def need(a):
    if a=="a":
        return 0
    else:
        return 123-ord(a)

s=list(input())
x=int(input())
i=0
while x>0:
    count=need(s[i])
    if x>=count:
        s[i]="a"
        x-=count
    
    if i==len(s)-1:
        s[i]=chr(ord(s[i])+(x%26))
        x=0
    i+=1
print("".join(s))

Submission status: Accepted

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

for i in range(len(sl)):
    ord_s = ord(sl[i])
    use = 123 - ord_s
    if k - use >= 0 and sl[i] != "a":
        sl[i] = "a"
        k -= use

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

print("".join(sl))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_c
# 辞書最小にしたい
# 前から貪欲 (OK)
# 実装が分からない

from bisect import bisect_left
from string import ascii_lowercase

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

ac = list(ascii_lowercase) + ['a']
dmap = {}
for i in range(len(ac) - 1):
    # dmap[ac[i]] = min(i, len(ac) - i - 1)
    dmap[ac[i]] = len(ac) - i - 1
dmap['a'] = 0

ans = list(s)
output = []

for idc, c in enumerate(ans):
    if k >= dmap[c]:
        output.append('a')
        k -= dmap[c]
    else:
        output.append(c)

k %= 26
# 最後に残ったkをすすめる
new_char = chr(ord(output[-1]) + k)
output[-1] = new_char
print("".join(output))

Submission status: Accepted

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

for i in range(len(s)-1):
    z2a = (ord('z') + 1 - ord(s[i])) % 26
    if z2a <= K:
        s = s[:i] + 'a' + s[i+1:]
        K -= z2a

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

Submission status: Accepted

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

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

print(''.join(S))

Submission status: Accepted

Solution code:
#CODE FESTIVAL 2016 qual A
"""
もし一周回せるなら回してコストを払う
そうでないなら何もせずに次のアルファベットへ
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
kijun = ord("a")
alpha = [i for i in range(kijun,kijun+26)]
mod = 26

s = readline().rstrip().decode('utf-8')
k = int(readline())

ans = []
for i in s:
    if i == "a":
        ans.append(i)
    elif i == "z":
        if k >= 1:
            ans.append("a")
            k -= 1
        else:
            ans.append(i)
    else:
        if k >= kijun+26 - ord(i):
            ans.append("a")
            k -= kijun+26 - ord(i)
        else:
            ans.append(i)
if k:
    ans[-1] = chr(kijun+(ord(ans[-1])-kijun+k)%mod)
print("".join(ans))

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    S = input()
    K = int(input())

    S = [s for s in S]
    D = [ord('z') - ord(s) + 1 if s != 'a' else 0 for s in S]
    T = []
    for s, d in zip(S, D):
        if d <= K:
            T.append('a')
            K -= d
        else:
            T.append(s)

    c = ord(T[-1])
    K %= 26
    for _ in range(K):
        if c == ord('z'):
            c = ord('a')
        else:
            c += 1
    T[-1] = chr(c)

    print(''.join(T))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    S = input()
    K = int(input())

    S = [s for s in S]
    D = [ord('z') - ord(s) + 1 if s != 'a' else 0 for s in S]
    T = []
    for s, d in zip(S, D):
        if d <= K:
            T.append('a')
            K -= d
        else:
            T.append(s)

    c = ord(T[-1])
    for _ in range(K):
        if c == ord('z'):
            c = ord('a')
        else:
            c += 1
    T[-1] = chr(c)

    print(''.join(T))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
k = int(input())
n = len(s)
le = [""]*n
ne = []

for i in range(n):
    le[i] = s[i]
    if s[i] == "a":
        ne.append(0)
    else:
        ne.append(123-ord(s[i]))
        
rem = k
for i in range(n):
    if rem >= ne[i]:
        rem -= ne[i]
        le[i] = 'a'
        
saigo = ord(le[n-1]) - 97
ssm = (rem+saigo) % 26
le[n-1] = chr(97+ssm)

print(*le,sep = "")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

result=""
for ss in s:
    if ss=="a":
        result+="a"
    else:
        if k>= 123 - ord(ss):
            k-=123-ord(ss)
            result+="a"
        else:
            result+=ss


if k>0:
    k=k%(123-97)
    temp=chr((((ord(result[-1])-97)+k)%(123-97))+97)
    print(result[:-1]+temp)
else:
    print(result)

#print(ord("a")):97
#print(ord("b")):98
#print(ord("z")):122
#97ならそのまま
#aにするには123-ord()をすればいい

Submission status: Accepted

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

# print(diff)

for i in range(len(s)):
    if s[i] != 'a':
        dist = ord('z') - ord(s[i]) + 1
        if dist <= K:
            K -= dist
            s[i] = 'a'
# print(s)
temp = K % 26
s[-1] = chr(ord(s[-1]) + temp)
# print(s)

print(''.join(s))

Submission status: Accepted

Solution code:
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    s = list(input())
    k = int(input())
    for i in range(len(s)):
        if s[i] == 'a':
            continue
        if k >= ord('z') - ord(s[i]) + 1:
            k -= ord('z') - ord(s[i]) + 1
            s[i] = 'a'
            if k == 0:
                break
    
    if k > 0:
        s[-1] = chr((ord(s[-1]) + k - 97)%26 + 97)
    
    print(''.join(s))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
    S = input()
    l = len(S)
    K = int(input())
    i = 0
    ans = ''
    while i < l-1 and K>0:
        n = ord(S[i])-ord('a')
        if n==0:
            ans += 'a'
            i += 1
            continue
        if 25-n<K:
            ans += 'a'
            K -= 26-n
        else:
            ans += S[i]
        i += 1
    if K == 0:
        ans += S[i:]
    else:
        ans += chr((ord(S[-1])-ord('a')+K)%26+ord('a'))
    return ans
print(solve())

Submission status: Accepted

Solution code:
s = input()
K = int(input())
after = []
rem = K
for i in range(len(s)-1):
    if s[i] == 'a':
        after.append('a')
        continue
    c = ord('z') - ord(s[i]) + 1
    if c <= rem:
        rem -= c
        after.append('a')
    else:
        after.append(s[i])

last = ord(s[-1])
if rem > 0:
    last += rem%26
    if last > ord('z'):
        last -= 26
after.append(chr(last))

print(''.join(after))