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:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    k = int(input().strip())
    ans = []
    for i, c in enumerate(s):
        if i == len(s)-1:
            ans.append(chr(ord('a') + (ord(c) + k % 26 - ord('a')) % 26))
            break
        d = (ord('z') - ord(c) + 1) % 26
        if d <= k:
            k -= d
            ans.append('a')
        else:
            ans.append(c)
    print(''.join(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    ans = list(s[:])
    k = int(input().strip())
    for i in range(len(s)):
        d = (ord('z') - ord(s[i]) + 1) % 26
        if k - d >= 0:
            ans[i] = 'a'
            k -= d
        if i == len(s) - 1:
            # print((ord(ans[i]) + k%26) % 26)
            ans[i] = chr(ord('a') + (ord(ans[i]) - ord('a') + k%26) % 26)
    print(''.join(ans))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
x = int(input())
tank = []
for c in list(s):
    if c=='a':
        tank.append(0)
    else:
        tank.append(ord('z') + 1 - ord(c))
res = ''
for i in range(len(tank)):
    if tank[i] == 0:
        res += s[i]
    elif tank[i] <= x:
        x -= tank[i]
        tank[i] = 0
        res += 'a'
    else:
        res += s[i]

c = res[-1]
x %= 26
if ord(c)+x <= ord('z'):
    res = res[:-1] + chr(ord(c)+x)
else:
    res = res[:-1] + chr(ord(c)+x-ord('z')+ord('a')-1)
print(res)

Submission status: Accepted

Solution code:
s=input()
k=int(input())
ls=[]
lord=[]
for i in range(len(s)):
    ls.append(s[i])
    lord.append(ord(s[i]))
i=0
while k>0 and i<len(s):#z的码值为122，再变成a，次数需要增加1，则123。
    if lord[i]!=97 and k>=123-lord[i]:    #如原本为a,则不变
        k=k-(123-lord[i])
        lord[i]=97
        ls[i]='a'
    i+=1

if k>0:
    lord[-1]=lord[-1]+k%26
    ls[-1]=chr(lord[-1])
for x in ls:
    print(x,end="")

Submission status: Accepted

Solution code:
S = input()
K = int(input())
V = []
for e in S:
    V.append(ord(e)-97)
for i in range(len(S)):
    if S[i] == 'a':
        continue
    if K < 26-V[i]:
        pass
    else:
        K -= 26-V[i]
        V[i] = 0
V[-1] += K
V[-1] %= 26
V = [chr(e+97) for e in V]
print("".join(V))

Submission status: Accepted

Solution code:
import string

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

str=string.ascii_lowercase
abc=str+str

s_len=len(s)
for i in range(s_len):
  si_inx=abc.index(s[i])

  if i==s_len-1:
    k%=26
    s[i]=abc[si_inx+k]
    break

  if s[i]=='a':
    continue

  if k>=26-si_inx:
    k-=26-si_inx
    s[i]='a'
  else:
    continue

print(''.join(s))

Submission status: Accepted

Solution code:
import string

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

str=string.ascii_lowercase
abc=str+str

s_len=len(s)
for i in range(s_len):
  si_inx=abc.index(s[i])

  if i==s_len-1:
    k%=26
    s[i]=abc[si_inx+k]
    break

  if s[i]=='a':
    continue

  if k>=26-si_inx:
    k-=26-si_inx
    s[i]='a'
  else:
    continue

  if k<=0:
    break

print(''.join(s))

Submission status: Accepted

Solution code:
s=input()
slist=[i for i in s]
K=int(input())
cost = []
for i in s:
    if i=="a":
        cost.append(0)
    else:
        cost.append(ord("z")-ord(i)+1)

for i,c in enumerate(cost):
    if c<=K:
        K = K-c
        slist[i]="a"

lastord = (ord(slist[-1])-ord("a")+K)%26+ord("a")
slist[-1]=chr(lastord)

print("".join(slist))

Submission status: Accepted

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

alpha=list('abcdefghijklmnopqrstuvwxyz')

ans=[]
for i in range(len(s)):
    ki= 26-alpha.index(s[i]) if s[i]!='a' else 0
#    print(ki,k)
    if(i==len(s)-1):
        kn=k+alpha.index(s[i])
        kn=kn%26
        ans.append(alpha[kn])
    elif(ki<=k):
        ans.append('a')
        k-=ki
    else:
        ans.append(s[i])
print(''.join(ans))

Submission status: Accepted

Solution code:
S=input()
K=int(input())
c2i=lambda c: ord(c)-ord("a")
i2c=lambda i: chr(i+ord("a"))
A=list(map(c2i, S))
for i in range(len(A)):
    if A[i] and 26-A[i]<=K:
        K-=26-A[i]
        A[i]=0
A[-1]+=K
A[-1]%=26
print("".join(map(i2c,A)))

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.buffer.readline

def main():
    s = list(input())
    K = int(input())
    
    l = len(s)
    for i in range(l-1):
        moji = s[i]
        if moji == "a":
            continue
        else:
            a = ord("z")-ord(moji)+1
            if a <= K:
                s[i] = "a"
                K -= a

    K %= 26
    use = ord(s[-1])+K
    if use >= 123:
        use -= 26
    s[-1] = chr(use)
    print("".join(map(str,s)))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(len(s)):
    need = (123-ord(s[i]))%26
    if need <= K:
        s[i] = "a"
        K -= need
if 0 < K:
    tmp = ord(s[-1]) + K%26
    tmp -= 26 if 123 <= tmp else 0
    s[-1] = chr(tmp)
print("".join(s))

Submission status: Accepted

Solution code:
s = input()
ints = [ord(i) - ord('a') for i in s]
K = int(input())
n = len(s)
i = 0
while i < n:
    if ints[i] != 0 and 25 - ints[i] + 1 <= K:
        K -= 25 - ints[i] + 1
        ints[i] = 0
    i += 1

K %= 26
ints[-1] = (ints[-1] + K) % 26
s_ = ''
for i in ints:
    s_ += chr(i + ord('a'))

print(s_)

Submission status: Accepted

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

z = ord("z")
a = ord("a")
for i in range(len(s)-1):
    if s[i] == "a":
        continue
    if z - ord(s[i]) + 1 <= k:
        k -= z - ord(s[i]) + 1
        s[i] = "a"

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

Submission status: Accepted

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

cnt = K
ans = ''

for s in S:
    if s == 'a':
        ans += 'a'
    elif cnt >= 123 - ord(s):
        cnt -= 123 - ord(s)
        ans += 'a'
    else:
        ans += s

last = ans[-1]
last = chr((ord(last) - 97 + cnt) % 26 + 97)
print(ans[:-1] + last)

Submission status: Accepted

Solution code:
N = 26
ord_a = ord('a')
S = [ord(s) - ord_a for s in input()]
K = int(input())


for i in range(len(S)):
    r = (N - S[i]) % N
    if K >= r:
        K -= r
        S[i] = 0


S[-1] += K % N
S[-1] %= N

answer = ''.join(chr(s + ord_a) for s in S)
print(answer)

Submission status: Accepted

Solution code:
s = input()
k = int(input())
l = [(26 - (ord(c) - ord('a'))) % 26 for c in s]
for i in range(len(s) - 1):
    if k >= l[i]:
        k -= l[i]
        s = s[:i] + 'a' + s[i + 1 :]

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

Submission status: Accepted

Solution code:
alp1 = list('abcdefghijklmnopqrstuvwxyz'[::-1])
num = [i for i in range(1,26)]
alp = {}
for a,n in zip(alp1,num):
    alp[a] = n
s = input()
K = int(input())
ans =''
now = 0
while True:
    if s[now] == 'a':
        ans += 'a'
    elif K >= alp[s[now]]:
        K -= alp[s[now]]
        ans += 'a'
    else:
        ans += s[now]
    now += 1
    if now == len(s):
        break
if K:
    alp1 = alp1[::-1]
    last = ans[-1]
    ans = ans[:-1]
    ind = alp1.index(last)
    ind = (ind+K)%26
    ans += alp1[ind]
    print(ans)
else:
    print(ans)

Submission status: Accepted

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

res=[]
for i in range(len(s)):
    num = ord(s[i])-97

    if i==len(s)-1:
        res.append(chr((num+k)%26+97))
    elif s[i] == "a":
        res.append("a")
    elif 26 - num <= k:
        res.append("a")
        k-=26-num
    else:
        res.append(s[i])

print("".join(res))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
a=[ord(i)-ord('a') for i in s]
k=int(input())
for i in range(n):
    if a[i]+k>=26 and a[i]>0:
        k-=26-a[i]
        a[i]=0
k%=26
a[-1]+=k
a=[chr(i + ord('a')) for i in a]
print(*a,sep="")

Submission status: Accepted

Solution code:
s = input()
k = int(input())
alp = 'bcdefghijklmnopqrstuvwxyza'
t = alp.find(s[0])
if len(s) == 1:
    s = alp[(k+t)%26]
else: 
    if k >= 25-t:
        s = 'a' + s[1:]
        k -= 25-t
    for i in range(1, len(s)-1):
        t = alp.find(s[i])
        if k >= 25-t:
            s = s[:i] + 'a' + s[i+1:]
            k -= 25-t
    s = s[:len(s)-1] + alp[(k+alp.find(s[-1]))%26]
print(s)

Submission status: Accepted

Solution code:
from sys import stdin
import string

alpha = string.ascii_lowercase
nokori = [26-i for i in range(26)];nokori[0] = 0
s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())
sin = ""
for i in s:
    if nokori[alpha.index(i)] <= k:
        k -= nokori[alpha.index(i)]
        sin += "a"
    else:
        sin += i
q = alpha.index(sin[-1])
q += k
print(sin[:-1]+alpha[q%26])

Submission status: Accepted

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

for i in range(len(s)):
    if K == 0:
        continue
    n = ord(s[i]) - ord("a")
    if n == 0:
        continue
    m = 26 - n
    if K >= m:
        s[i] = "a"
        K -= m

if K != 0:
    K %= 26
    s[-1] = chr(ord(s[i]) + K)

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

Submission status: Accepted

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

N = len(S)
T = list(S)
for i in range(N - 1):
    if T[i] == 'a':
        continue
    if K >= ord('z') - ord(T[i]) + 1:
        K -= ord('z') - ord(T[i]) + 1
        T[i] = 'a'

T[N - 1] = chr(ord('a') + (ord(T[N - 1]) - ord('a') + K) % 26)
print("".join(T))

Submission status: Accepted

Solution code:
s = input()
l = ''
n = int(input())
alp = [chr(ord('a')+i) for i in range(26)]
for i in range(len(s)):
  if i != len(s)-1:
    if s[i] != 'a':
      if 97+26-ord(s[i]) <= n:
        n -= (123-ord(s[i]))
        l += 'a'
      else:
        l += s[i]
    else:
      l += 'a'
  else:
    t = ord(s[i])
    if t+n <= 122:
      l += chr(t+n)
    else:
      n = n%26
      if t+n <= 122:
        l += chr(t+n)
      else:
        l += chr(t+n-26)
print(l)

Submission status: Accepted

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

for i in range(len(S)):
  n = ord(S[i])
  if S[i] == 'a':
    continue
  if ord('z') - n + 1 <= K:
    K -= ord('z') - n + 1
    S[i] = 'a'
assert K >= 0
if K != 0:
  n = ord(S[-1])
  n -= ord('a')
  n += K
  n %= 26
  n += ord('a')
  S[-1] = chr(n)
print(''.join(S))

Submission status: Accepted

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

A = [" " for _ in range(len(S))]

zan = K
for i in range(len(S)):
  n = (ord('z') - ord(S[i]) + 1) % 26 # aに変換するのに必要な回数
  if zan >= n:
    zan -= n
    A[i] = 'a'
  else:
    A[i] = S[i]

if zan > 0:
  A[-1] = chr((ord(A[-1]) - ord('a') + zan)%26 + ord('a'))
print("".join(A))

Submission status: Accepted

Solution code:
S = [s for s in input()]
K = int(input())
N = len(S)

# print(S, K)

ord_a = ord('a')

T = [0]*N
for i in range(N):
    s = S[i]
    a = ord(s)
    r = (ord_a + 26 - a) % 26
    if r <= K:
        K -= r
        s = 'a'
    T[i] = s
if K > 0:
    t = T[N - 1]
    a = ord(t)
    a = ord_a + (a - ord_a + K) % 26
    T[N - 1] = chr(a)
print(''.join(T))

Submission status: Accepted

Solution code:
s = input()
k = int(input())
ans = ""
l = 26
for i in range(len(s)-1):
    if l - ord(s[i]) + 97 <= k and s[i] != "a":
        k -= l - ord(s[i]) + 97
        ans += "a"
    else:
        ans += s[i]
ans += (chr(((ord(s[-1]) - 97) + k + l) % l + 97))
print(ans)

Submission status: Accepted

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

ans = ''
for i, c in enumerate(s):
    dif = ord('z') - ord(c) + 1
    dif %= 26
    if i == len(s) - 1:
        K %= 26
        if ord(c) + K > ord('z'):
            K -= 26
        ans += chr(ord(c) + K)
    elif dif <= K:
        ans += 'a'
        K -= dif
    else:
        ans += c
print(ans)

Submission status: Accepted

Solution code:
s = str(input())
n = int(input())
k = ord("z")
a = [0]*len(s)
for i in range(len(s)):
    a[i] = ord(s[i])
for i in range(len(s)):
    if a[i] == ord("a"):
        continue
    if n>=k+1-a[i]:
        n = n-k-1+a[i]
        a[i] = ord("a")
    
    if n<=0:
        break
if n>0:
    a[-1] += n%26
ans = ""
for i in range(len(s)):
    ans += chr(a[i])
print(ans)

Submission status: Accepted

Solution code:
alf = {c:i for i,c in enumerate('abcdefghijklmnopqrstuvwxyz')}
a = 'abcdefghijklmnopqrstuvwxyz'
s = input()
k = int(input())
diff = [26-alf[c] if c != 'a' else 0 for c in s]
ans = []
for i in range(len(s)):
    if k >= diff[i]:
        ans.append('a')
        k -= diff[i]
    else:
        ans.append(s[i])
    # print(ans,k)
if k > 0:
    ans[-1] = a[(alf[ans[-1]] + k % 26)]
print(''.join(ans))

Submission status: Accepted

Solution code:
a=input()
n=len(a)
m=int(input())
ans=""
for i in range(n-1):
  if a[i]=="a":
    ans += "a"
    continue
  x=ord(a[i])-97
  if m>=26-x:
    ans += "a"
    m -= 26-x
  else:
    ans += a[i]
ans += chr((ord(a[n-1])-97+m)%26+97)
print(ans)

Submission status: Accepted

Solution code:
from string import ascii_lowercase

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

d = {c: (26 - i) % 26 for i, c in enumerate(ascii_lowercase)}

ret = ''
for c in s[:-1]:
    if d[c] <= k:
        k -= d[c]
        ret += 'a'
    else:
        ret += c

k %= 26
idx = (ascii_lowercase.index(s[-1]) + k) % 26
c = ascii_lowercase[idx]
ret += c

print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
    s = list(input())
    K = int(input())
    lowercase = [chr(i) for i in range(97, 97+26)]
    en = []
    for i in range(26):
        en.append(26-i)
    dic = defaultdict(int)

    for i,j in zip(lowercase,en):
        dic[i] = j

    for i in range(len(s)):
        if s[i]=="a":
            pass
        else:
            now = dic[s[i]]
            if now<=K:
                s[i]="a"
                K -= now
            else:
                pass
    K %= 26
    s[-1] = chr(ord(s[-1])+K)
    print("".join(s))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
K=int(input())
for i in range(len(s)-1):
    if s[i]!="a":
        a= ord("z")+1 - ord(s[i])
        if K>=a:
            s[i]="a"
            K-=a
if K:
    s[-1]=chr((K+ord(s[-1])-ord("a"))%(ord("z") - ord("a")+1)+ord("a"))
print("".join(s))

Submission status: Accepted

Solution code:
s = input()
K = int(input())
alp = 'abcdefghijklmnopqrstuvwxyz'

ans = ''
for i,w in enumerate(s):
    if i != len(s)-1 and (26-(ord(w)-ord('a')))%26 <= K:
        ans += 'a'
        K -= (26-(ord(w)-ord('a')))%26
    elif i != len(s)-1:
        ans += w
    if i == len(s)-1:
        #ans = ans[:-1]
        lastlidx = (ord(w)-ord('a') + K%26)%26
        ans += alp[lastlidx]
print(ans)

Submission status: Accepted

Solution code:
S = input()
K = int(input())
alp = '0bcdefghijklmnopqrstuvwxyza'
alp_dict = {s:i for i,s in enumerate(alp)}


cnt = 0
ans = ''
for i,s in enumerate(S):
  if cnt + (26-alp_dict[s]) <= K:
    cnt += (26-alp_dict[s])
    ans += 'a'
  else:
    ans += s

if (K-cnt)%26==0:
  print(ans)
else:
  rest = (K-cnt)%26
  print(ans[:-1]+alp[(alp_dict[ans[-1]]+rest)%26])

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_c
# 前の方からgreedyに`a`に変えていって、残った回数は最後の一文字で無限に回す?


def ord_until_a(char):
    if char == 'a':
        return 0
    return ord('a') + 26 - ord(char)
    # return 26 - (ord(char) - ord('a'))


S = input()
K = int(input())
ans = []
for s in S:
    diff = ord_until_a(s)
    if K >= diff:
        ans.append('a')
        K -= diff
    else:
        ans.append(s)

if K > 0:
    K %= 26
    last = ord(ans[-1]) + K
    if last > ord('z'):
        last -= 26
    ans[-1] = chr(last)

print(''.join(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
k=int(input())
sl=[]
n=len(s)
for i in range(n):
  if s[i]!='a':
    if 26-(ord(s[i])-97)<=k:
      sl.append('a')
      k-=26-(ord(s[i])-97)
    else:
      sl.append(s[i])
  else:
    sl.append(s[i])
if k>0:
  if k%26!=0:
    sl[n-1]=chr(ord(sl[n-1])+k%26)
print(''.join(sl))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
K = int(input())
T = []
for i in range(N):
    s = ord(S[i]) - 97
    a = (26-s) % 26
    if a <= K:
        K -= a
        T.append("a")
    else:
        T.append(S[i])
T[-1] = chr((ord(T[-1]) - 97 + K) % 26 + 97)
print("".join(T))

Submission status: Accepted

Solution code:
S = [(ord("z") + 1 - ord(s)) % 26 for s in input()]
K = int(input())

for i in range(len(S)):
  if S[i] > K: continue
  K -= S[i]
  S[i] = 0

S[-1] = (S[-1] - K) % 26
print(*[chr(ord("z") - (s-1) % 26) for s in S], sep="")

Submission status: Accepted

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

c = [ord(s1)-ord('a') for s1 in s]
sl = list(s)

for i in range(len(s)):
    if c[i] and 26-c[i] <= K:
        sl[i] = 'a'
        K -= 26-c[i]
sl[len(s)-1] = chr((ord(sl[len(s)-1]) - ord('a') + K) % 26 + ord('a'))

print(''.join(sl))

Submission status: Accepted

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

for i in range(N - 1):
    d = (ord("a") - ord(S[i])) % 26
    if d <= K:
        S[i] = "a"
        K -= d

S[-1] = chr((ord(S[-1]) - ord("a") + K) % 26 + ord("a"))
print("".join(S))

Submission status: Accepted

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

S = [0 for _ in range(N)]

for i in range(N):
    S[i] = ord(s[i])-97

tmp = K
ans = ''

for i in range(N):
    if S[i]==0:
        ans += 'a'
    elif 26-S[i] <= tmp:
        ans += 'a'
        tmp -= 26-S[i]
    else:
        ans += s[i]
        
if tmp:
    ans = ans[:-1]+chr((ord(ans[-1])-97+tmp)%26+97)
    
print(ans)

Submission status: Accepted

Solution code:
s = input()
K = int(input())
alpha = "bcdefghijklmnopqrstuvwxyza"
dic = {j : 25 - i for i, j in enumerate(alpha)}
inv_dic = {j : i for i, j in dic.items()}
s_ls = [dic[_s] for _s in s]
remain = K
ind = 0
len_s = len(s)
while ind < len_s and remain > 0:
    _s = s_ls[ind]
    if _s <= remain:
        remain -= _s
        s_ls[ind] = 0
    ind += 1
if remain > 0:
    s_ls[ind - 1] = (s_ls[ind - 1] - remain) % 26
print("".join([inv_dic[_s] for _s in s_ls]))

Submission status: Accepted

Solution code:
from sys import stdin
import string
s = (stdin.readline().rstrip())
K = int(stdin.readline().rstrip())

alp = string.ascii_lowercase*3
ans = ""
for i in s:
    ind = alp.index(i)
    cnt = 0
    if i == "a":
        ans += "a"
        continue
    for j in alp[ind+1:]:
        cnt += 1
        if K - cnt < 0:
            ans += i
            cnt = 0
            break
        if j == "a":
            ans += "a"
            K = K - cnt
            cnt = 0
            break
if K != 0:
    ind = (K % 26) + alp.index(ans[-1])
    ans = ans[:-1]+alp[ind]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 必要な回数を連想配列で対応付ける。
alpha = "bcdefghijklmnopqrstuvwxyza"
last_process = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
need_char_point = {}
need_point_char = {}
pointa = 0
for i in reversed(range(len(alpha))):
    need_char_point[alpha[pointa]] = i
    need_point_char[i] = alpha[pointa]
    pointa += 1

# print(need_point)
s = str(input())
k = int(input())
ans = ""
for i in range(len(s)):
    if k >= need_char_point[s[i]]:
        k -= need_char_point[s[i]]
        ans += "a"
    else:
        ans += s[i]
if k > 0:
    k %= 26
    for i in range(len(last_process)):
        if ans[-1] == last_process[i]:
            tmp = i
            break
    hoge = list(ans)
    hoge[-1] = last_process[tmp+k]
    ans = "".join(hoge)

print(ans)

Submission status: Accepted

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

    s = list(map(lambda x: ord(x), s))
    B = [0 for _ in range(len(s))]
    for i in range(len(s)):
        b = 26 - (s[i] - ord("a"))
        if b == 26:
            B[i] = 0
        elif b <= K:
            K -= b
            B[i] = 0
        else:
            B[i] = b

    if K != 0:
        B[-1] -= K
        B[-1] %= 26

    ans = list(map(lambda c: chr(ord("a") + (26 - c) % 26), B))
    print("".join(ans))


main()

Submission status: Accepted

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) & (n != 0):
        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: Accepted

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

alp = "abcdefghijklmnopqrstuvwxyza"
to_a = {alp[i]: 26 - i for i in range(1, len(alp))}

for i, s in enumerate(S):
    if to_a[s] > k:
        continue
    else:
        S[i] = "a"
        k -= to_a[s]
    if k == 0:
        break

k %= 26
i = alp.index(S[-1]) + k
S[-1] = alp[i]

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

Submission status: Accepted

Solution code:
s=input()
K=int(input())
ns=len(s)
ls=list(s)
for i in range(ns):
    if K==0:
        break
    if ls[i]=="a":
        continue
    toa=ord("z")+1-ord(ls[i])
    #print("toa",toa)
    if toa<=K:
        ls[i]="a"
        #K-=(ord("z")+1-ord(s[i]))
        K-=toa
        #print("K",K)
ls[-1]=chr(ord(ls[-1])+K%26)
#ans=str(ls)
ans="".join(ls)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def main():
    s = input().strip()
    K = int(input())
    ans = ""
    for c in s:
        if c == "a":
            ans += c
        else:
            cost = 26 - (ord(c) - ord("a"))
            if cost <= K:
                K -= cost
                ans += "a"
            else:
                ans += c
    finalletter = ans[-1]
    ans = ans[:-1] + chr(ord("a") + (ord(finalletter) - ord("a") + K) % 26)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

n = len(s)
for i in range(n - 1):
    tmp = (26 - ord(s[i]) + ord('a')) % 26 #aにするために必要な回数
    if tmp <= K:
        K -= tmp
        s[i] = 'a'

K %= 26 #最後の一回で調整する
tmp = ord(s[n - 1]) + K
if tmp >= 123:
    tmp -= 26
s[n - 1] = chr(tmp)

print (*s, sep = '')

Submission status: Accepted

Solution code:

S = input()
s = list(S)

K = int(input())

alp = "abcdefghijklmnopqrstuvwxyz"
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: Accepted

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 s[i]==97:
            s[i]='a'
            continue
        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: Accepted

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

def calcCostToGetA(char):
  if char=='a':
    return 0
  return (ord("z")+1)-ord(char)

for i in range(len(s)):
  cost=calcCostToGetA(s[i])
  if cost<=K:
    s[i]='a'
    K-=cost
    if K==0:
      break

if K>0:
  s[-1]=chr(ord(s[-1])+K%26)
  
print("".join(s))

Submission status: Accepted

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:
        diff = (26 - ind_alph[s[i]]) % 26
        if diff <= k:
            s[i] = 'a'
            k -= diff
        if i == n - 1 and k:
                s[i] = alph[(ind_alph[s[i]] + k) % 26]
                k = 0
        i += 1

    print(''.join(s))

if __name__ == '__main__':
    main()

Submission status: Accepted

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[(ind_alph[s[i]] + k) % 26]
                k = 0
        i += 1

    print(''.join(s))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

komoji = list('abcdefghijklmnopqrstuvwxyz')
komoji2 = komoji + komoji
index = {}

num = 1
for k in komoji:
    index[k] = num
    num += 1

cost = []
for s in S:
    c = 27 - index[s]
    if c == 26:
        c = 0
    cost.append(c)

ans = []

for num, c in enumerate(cost):
    if c <= K:
        K -= c
        ans.append('a')
    else:
        ans.append(S[num])
        continue
if K != 0:
    K %= 26
    last = ans[-1]
    last = komoji2[komoji.index(last) + K]
    ans[-1] = last
print(''.join(ans))

Submission status: Accepted

Solution code:
s = input()
k = int(input())
r = []
for c in s:
    n = ord('z') - ord(c) + 1
    if k >= n and c != 'a':
        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: Accepted

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]!=0:
		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: Accepted

Solution code:
s = list(input())
k = int(input())
a = "azyxwvutsrqponmlkjihgfedcb"
for i in range(len(s)-1):
  t = a.index(s[i])
  if k < t:
    continue
  else:
    s[i] = "a"
    k -= t
s[len(s)-1] = a[(a.index(s[len(s)-1])-k)%26]
print(*s, sep="")

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
s = [ord(x) - ord("a") for x in input()]
k = int(input())

for i in range(len(s)):
    if s[i] == 0: continue
    r = 26 - s[i]
    if r <= k:
        k -= r
        s[i] = 0

s[-1] = (s[-1] + k) % 26
print("".join([chr(x + ord("a")) for x in s]))

Submission status: Accepted

Solution code:
alpha2num = lambda c: ord(c) - ord('a') + 1
num2alpha = lambda c: chr(c+ord('a')-1)
S = list(map(alpha2num, input()))
K = int(input())
#まず左からaにできるか
for i in range(len(S)):
    if K <= 0:
        break
    if S[i] == 1:
        continue
    elif 27 - S[i] <= K:
        K -= (27 - S[i])
        S[i] = 1
# 残りのKを処理
if K >= 1:
    S[-1] = (S[-1] + K) % 26
    if S[-1] == 0:
        S[-1] = 26
S = list(map(num2alpha, S))
print(*S, sep='')

Submission status: Accepted

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)
    is_a[-1]=False
for i in range(len(s)):
  if is_a[i]:
    print("a",end="")
  else:
    print(s[i],end="")

Submission status: Accepted

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 s[i]:###これないとaの時に消費する
        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))