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:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    S = list(Scanner.string())
    K = Scanner.int()
    i = 0
    while i < len(S):
        c = S[i]
        n = ord(c) - ord('a')
        if 26 - n <= K:
            c = 'a'
            K -= 26 - n
            S[i] = c
        i += 1
    if K > 0:
        c = S[-1]
        for _ in range(K % 26):
            c = chr(ord(c) + 1)
            if c == chr(ord('z') + 1):
                c = 'a'
        S[-1] = c
    print(''.join(S))


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
k = int(input())
al = [chr(ord('a') + i) for i in range(26)]
ans = ''
for i in range(len(s) - 1):
    num = al.index(s[i])
    if k + num >= 26:
        k -= 26 - num
        ans += 'a'
    else:
        ans += s[i]
ans += al[(k + al.index(s[-1])) % 26]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
k = int(input())
al = [chr(ord('a') + i) for i in range(26)]
ans = ''
for i in range(len(s)):
    num = al.index(s[i])
    if 26 - num <= k:
        k -= 26 - num
        if i != len(s) - 1:
            ans += 'a'
        else:
            ans += al[k % 26]
    else:
        if i != len(s) - 1:
            ans += s[i]
        else:
            ans += al[num + k]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
k = int(input())
al = [chr(ord('a') + i) for i in range(26)]
ans = ''
for i in range(len(s)):
    num = al.index(s[i])
    if 26 - num <= k:
        k -= 26 - num
        ans += 'a'
    else:
        if i != len(s) - 1:
            ans += s[i]
        else:
            ans += al[num + k]
print(ans)

Submission status: Wrong Answer

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

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

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

print(''.join(s))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
s=input()
K=int(input())

ans=[]
#122
for item in s[:len(s)-1]:
    cost=(123-ord(item))
    if item=="a":
        continue
    if K>=cost:
        K-=cost
        ans.append("a")
    else:
        ans.append(item)

K%=26
last=ord(s[-1])
if last+K>122:
    ans.append(chr(last+K-26))
else:
    ans.append(chr(last+K))

print("".join(ans))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
s=input()
K=int(input())

ans=[]
#122
for item in s[:len(s)-1]:
    cost=(123-ord(item))
    if K>=cost:
        K-=cost
        ans.append("a")
    else:
        ans.append(item)

K%=26
last=ord(s[-1])
if last+K>122:
    ans.append(chr(last+K-26))
else:
    ans.append(chr(last+K))

print("".join(ans))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
result = ""
i = 0
#a:97, z:122
while i < len(s)-1:
    s_i = ord(s[i])
    if 123-s_i <= k:
        result = result+"a"
        k -= 123-s_i
    else:
        result = result+s[i]
    i += 1
if k>0:
    result = result + chr((ord(s[i])-97+k)%26+97)
else:
    result = result + s[i]

print(result)

Submission status: Wrong Answer

Solution code:
#C - 次のアルファベット 

#a: 97 z: 122  全部で26文字
# 次のaは123
a=ord('a')
z=ord('z')

s=input()
k=int(input())
ans=""
def change(c):
    global k
    num=ord(c)
    if (num+k)>z:
        k=max(0,k-(z+1-num))
        return 'a'
    else:
        return c 


for i in range(len(s)-1):
    ans+=change(s[i])
k=k%26
l=0
if (ord(s[-1])+k)>122:
    l=a+(ord(s[-1])+k)%123
else:
    l=(ord(s[-1])+k)

ans+=chr(l)
print(ans)

Submission status: Wrong Answer

Solution code:
#C - 次のアルファベット 

#a: 97 z: 122  全部で26文字
# 次のaは123
a=ord('a')
z=ord('z')

s=input()
k=int(input())
ans=""
def change(c):
    global k
    num=ord(c)
    if (num+k)>z:
        k=max(0,k-(z+1-num))
        return 'a'
    else:
        return c 


for i in range(len(s)-1):
    ans+=change(s[i])
k=k%26
ans+=chr(ord(s[-1])+k)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
s = input()
c = np.array([27-(ord(s[i])-96) for i in range(len(s))])
k = int(input())
ind = 0
while k > 0:
    if ind == len(s):
        break
    if c[ind] <= k:
        k -= c[ind]
        c[ind] = 0
        ind += 1
    else:
        ind += 1

if k > 0:
    c[-1] = (c[-1] - k) % 26

ans = ''.join([chr(26-c[i]+97) if c[i] > 0 else 'a' for i in range(len(s))])
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    word = list(input())
    operation = int(input())
    cost = {}
    for i in range(26):
        cost[chr(ord("a") + i)] = ord("z") - ord("a") - i + 1
    for i in range(len(word)):
        if cost[word[i]] <= operation:
            operation -= cost[word[i]]
            word[i] = "a"
        else:
            continue
    if 0 < operation:
        word[-1] = chr((ord(word[-1]) - ord("a") + operation % 26) % 26 + ord("a"))
    print("".join(word))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    word = list(input())
    operation = int(input())
    cost = {}
    for i in range(26):
        cost[chr(ord("a") + i)] = ord("z") - ord("a") - i + 1
    for i in range(len(word)):
        if cost[word[i]] <= operation:
            operation -= cost[word[i]]
            word[i] = "a"
        else:
            continue
    if 0 < operation:
        word[-1] = chr(ord(word[-1]) + operation % 26)
    print("".join(word))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    word = list(input())
    operation = int(input())
    cost = {}
    for i in range(26):
        cost[chr(ord("a") + i)] = ord("z") - ord("a") - i + 1
    for i in range(len(word)):
        if cost[word[i]] <= operation:
            operation -= cost[word[i]]
            word[i] = "a"
        else:
            continue
    operation %= cost["a"]
    if 0 < operation:
        for i in range(-1, -len(word)-1, -1):
            if cost[word[i]] <= operation:
                operation -= cost[word[i]]
                operation %= cost["a"]
                word[i] = "a"
        if 0 < operation:
            word[-1] = chr(ord(word[-1]) + operation)
    print("".join(word))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    word = list(input())
    operation = int(input())
    cost = {}
    for i in range(26):
        cost[chr(ord("a") + i)] = ord("z") - ord("a") - i + 1
    for i in range(len(word)):
        if cost[word[i]] <= operation:
            operation -= cost[word[i]]
            word[i] = "a"
        else:
            continue
    if 0 < operation:
        for i in range(-1, -len(word)-1, -1):
            if cost[word[i]] <= operation:
                operation -= cost[word[i]]
                operation %= cost["a"]
                word[i] = "a"
        if 0 < operation:
            word[-1] = chr(ord(word[-1]) + operation)
    print("".join(word))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    word = list(input())
    operation = int(input())
    cost = {}
    for i in range(26):
        cost[chr(ord("a") + i)] = ord("z") - ord("a") - i + 1
    for i in range(len(word)):
        if cost[word[i]] <= operation:
            operation -= cost[word[i]]
            word[i] = "a"
        else:
            continue
    if 0 < operation:
        for i in range(-1, -len(word)-1, -1):
            if cost[word[i]] <= operation:
                operation -= cost[word[i]]
                word[i] = "a"
        if 0 < operation:
            word[-1] = chr((ord(word[-1]) - ord("a") + operation) % 26 + ord("a"))
    print("".join(word))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x=input()
x=list(x)
y=int(input())
a=(len(x))

for i in range(a):
	if ord(x[i])+y>=123:
		y=y-(123-ord(x[i]))
		x[i]='a'

if (ord(x[a-1])+y)>=123:
	y=y%26

if (ord(x[a-1])+y)>=123:
	y=y-26

x[a-1]=chr(ord(x[a-1])+y)
print(*x,sep='')

Submission status: Wrong Answer

Solution code:
x=input()
x=list(x)
y=int(input())
a=(len(x))

for i in range(a):
	if ord(x[i])+y>=123:
		y=y-(123-ord(x[i]))
		x[i]='a'
while (ord(x[a-1])+y)>=123:
	y=((ord(x[a-1])+y)-97)%26
x[a-1]=chr(ord(x[a-1])+y)
print(*x,sep='')

Submission status: Wrong Answer

Solution code:
x=input()
x=list(x)
y=int(input())
a=(len(x))

for i in range(a):
	if ord(x[i])+y>=123:
		y=y-(123-ord(x[i]))
		x[i]='a'
while (ord(x[a-1])+y)>=123:
	y=((ord(x[a-1])+y)-97)%26
x[a-1]=chr(y+97)
print(*x,sep='')

Submission status: Wrong Answer

Solution code:
x=input()
x=list(x)
y=int(input())
a=(len(x))

for i in range(a):
	if ord(x[i])+y>=123:
		y=y-(123-ord(x[i]))
		x[i]='a'
while (ord(x[a-1])+y)>123:
	y=y-26
x[a-1]=chr(ord(x[a-1])+y)
print(*x,sep='')

Submission status: Wrong Answer

Solution code:
s = list(input())

n = int(input())
z_ = ord('z')
S = []
for i in range(len(s)):
    m = z_ - ord(s[i]) + 1
    if i == len(s) - 1:
        n = n % 26
        if n + ord(s[i]) > z_:
            S.append(chr(n + ord(s[i]) - z_ + ord('a') - 1))
        else:
            S.append(chr(n + ord(s[i])))
    else:
        if m < n:
            S.append('a')
            n -= m
        else:
            S.append(s[i])

print("".join(S))

Submission status: Wrong Answer

Solution code:
s = list(input())

n = int(input())
z_ = ord('z')
S = []
for i in range(len(s)):
    m = z_ - ord(s[i]) + 1
    if i == len(s) - 1:
        n = n % 26
        if n + ord(s[i]) > z_:
            S.append(chr(n + ord(s[i]) - z_ + ord('a') - 1))
        else:
            S.append(chr(n + ord(s[i])))
    else:
        if m <= n:
            S.append('a')
            n -= m
        else:
            S.append(s[i])

print("".join(S))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

goal = ord("z") + 1 
s = input()
k = int(input())
n = len(s)
ans = [0] * n
for i,si in enumerate(s):
  if goal - ord(si) <= k:
    k -= goal - ord(si)
    ans[i] = "a"
  else:
    ans[i] = si
m = k % 26
ans[-1] = chr(((ord(ans[-1]) - ord("a")) + m)%26 + ord("a"))
print(*ans,sep="")

Submission status: Wrong Answer

Solution code:
S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    # aまでの必要な回数
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            idx += 1
        else:
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        K -= k
        S[idx] = "a"
        if idx < L-1:
            idx += 1

print("".join(S))

Submission status: Wrong Answer

Solution code:
S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    # aまでの必要な回数
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            idx += 1
        else:
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        K -= k
        S[idx] = "a"

print("".join(S))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
slen = len(s)
new_s = ""

for i in range(slen):
  val = ord("z") + 1 - ord(s[i])
  if k >= val:
    k -= val
    new_s += "a"
  else:
    new_s += s[i]
    
if k > 0:
  tmp_val = ord(new_s[slen-1]) + k % 26
  if tmp_val > ord("z"):
    tmp_val -= 26
  new_s = new_s[:-1] + chr(tmp_val)

print(new_s)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
slen = len(s)
new_s = ""

for i in range(slen):
  val = ord("z") + 1 - ord(s[i])
  if k >= val:
    k -= val
    new_s += "a"
  else:
    new_s += s[i]
    
if k > 0:
  tmp_val = ord(s[slen-1]) + k % 26
  if tmp_val > ord("z"):
    tmp_val -= 26
  new_s = new_s[:-1] + chr(tmp_val)

print(new_s)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
slen = len(s)
new_s = ""

for i in range(slen):
  val = ord("z") + 1 - ord(s[i])
  if k >= val:
    k -= val
    new_s += "a"
  else:
    new_s += s[i]
    
if k > 0:
  new_s = new_s[:-1] + chr(ord(s[slen-1]) + k % 26)

print(new_s)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

alphabets = "abcdefghijklmnopqrstuvwxyz"
a = {c:i for i, c in enumerate(alphabets)}
s = list(input())
n = len(s)
k = int(input())

def f(k, i):
    if i == n - 1:
        k_ = k % 26
        c = s[i]
        shifted = (k_ + a[c]) % 26
        return alphabets[shifted]

    c = s[i]
    diff = 26 - a[c]
    if diff <= k:
        return "a" + f(k-diff, i+1)
    else:
        return c + f(k, i+1)
        

print(f(k, 0))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

alphabets = "abcdefghijklmnopqrstuvwxyz"
a = {c:i for i, c in enumerate(alphabets)}
s = list(input())
n = len(s)
k = int(input())

def f(k, i):
    if i == n - 1:
        k_ = k % 26
        c = s[i]
        shifted = (k_ + a[c]) % 26
        return alphabets[shifted]

    c = s[i]
    diff = 26 - a[c]
    if diff <= k:
        return "a" + f(k-diff, i+1)
    else:
        return c + f(k, i+1)
        

print(f(k, 0))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

alphabets = "abcdefghijklmnopqrstuvwxyz"
a = {c:i for i, c in enumerate(alphabets)}
s = list(input())
k = int(input())

def f(k, i):
    if k <= 0:
        return "".join(s[i:])
    
    if i == len(s) - 1:
        k_ = k % 26
        c = s[i]
        shifted = (k_ + a[c]) % 26
        return alphabets[shifted]

    c = s[i]
    diff = 26 - a[c]
    if diff <= k:
        return "a" + f(k-diff, i+1)
    else:
        return c + f(k, i+1)
        

print(f(k, 0))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

alphabets = "abcdefghijklmnopqrstuvwxyz"
a = {c:i for i, c in enumerate(alphabets)}
s = list(input())
k = int(input())

def f(k, i):
    if k <= 0:
        return str(s[i:])
    
    if i == len(s) - 1:
        k_ = k % 26
        c = s[i]
        shifted = (k_ + a[c]) % 26
        return alphabets[shifted]

    c = s[i]
    diff = 26 - a[c]
    if diff <= k:
        return "a" + f(k-diff, i+1)
    else:
        return c + f(k, i+1)
        

print(f(k, 0))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

alphabets = "abcdefghijklmnopqrstuvwxyz"
a = {c:i for i, c in enumerate(alphabets)}
s = list(input())
k = int(input())

def search(k, i):
    if k <= 0:
        return str(s[i:])
    elif i == len(s) - 1:
        c = s[i]
        k_ = k % 26
        return alphabets[a[c] + k_] if a[c] + k_ < 26 else "a" 
    else:
        c = s[i]
        diff = 26 - a[c]
        if diff <= k and a[c] > 0:
            return "a" + search(k-diff, i+1)
        else:
            return c + search(k, i+1)
        

print(search(k, 0))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

alphabets = "abcdefghijklmnopqrstuvwxyz"
a = {c:i for i, c in enumerate(alphabets)}
s = list(input())
k = int(input())

def search(k, i):
    if k <= 0:
        return str(s[i:])
    elif i == len(s) - 1:
        c = s[i]
        k_ = k % 26
        return alphabets[a[c] + k_] if a[c] + k_ < 26 else "a" 
    else:
        c = s[i]
        diff = 26 - a[c]
        if diff <= k:
            return "a" + search(k-diff, i+1)
        else:
            return c + search(k, i+1)
        

print(search(k, 0))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

alphabets = "abcdefghijklmnopqrstuvwxyz"
a = {c:i for i, c in enumerate(alphabets)}
s = list(input())
k = int(input())

def search(k, i):
    if k <= 0:
        return ""
    elif i == len(s) - 1:
        c = s[i]
        k_ = k % 26
        return alphabets[a[c] + k_] if a[c] + k_ < 26 else "a" 
    else:
        c = s[i]
        diff = 26 - a[c]
        if diff <= k:
            return "a" + search(k-diff, i+1)
        else:
            return c + search(k, i+1)
        

print(search(k, 0))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    K = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # h_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    a_ord = ord("a")
    z_index = ord("z") - a_ord

    s_ord = [ord(s) - a_ord for s in S]
    for i, s in enumerate(s_ord):
        if z_index + 1 - s > K:
            continue
        else:
            s_ord[i] = 0
            K -= z_index - s + 1

    mod = ord("z") - a_ord + 1
    if K > 0:
        K = K % mod
        s_ord[-1] = (s_ord[-1] + K) % mod

    print("".join([chr(x + a_ord) for x in s_ord]))


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """xyz
4"""
        output = """aya"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """a
25"""
        output = """z"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """codefestival
100"""
        output = """aaaafeaaivap"""
        self.assertIO(input, output)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(len(s)):
    if k==0:break

    num=ord(s[i])
    ch_num=123-num
    if i==len(s)-1:
        s[i]=chr(96+(num+k-96)%26) if num+k>122 else chr(num+k)
        k=0
        break
    elif s[i]=='a':continue
    elif ch_num<=k:
        s[i]='a'
        k-=ch_num
print(''.join(s))

Submission status: Wrong Answer

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

for i in range(len(s)):
    if k==0:break

    num=ord(s[i])
    ch_num=123-num
    if i==len(s)-1:
        s[i]=chr(96+(num+k)%122) if num+k>=122 else chr(num+k)
        k=0
        break
    elif s[i]=='a':continue
    elif ch_num<=k:
        s[i]='a'
        k-=ch_num
print(''.join(s))

Submission status: Wrong Answer

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

for i in range(len(s)):
    if k==0:break

    num=ord(s[i])
    ch_num=123-num
    if i==len(s)-1:
        s[i]=chr(96+(num+k)%122) if num+k>122 else chr(num+k)
        k=0
        break
    elif s[i]=='a':continue
    elif ch_num<=k:
        s[i]='a'
        k-=ch_num
print(''.join(s))

Submission status: Wrong Answer

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

for i in range(len(s)):
    if k==0:break

    num=ord(s[i])
    ch_num=123-num
    if i==len(s)-1:
        s[i]=chr(96+(num+k)%122) if num+k>122 else chr(num+k)
        k=0
    elif s[i]=='a':continue
    elif ch_num<=k:
        s[i]='a'
        k-=ch_num
print(''.join(s))

Submission status: Wrong Answer

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

for i in range(len(s)):
    if k==0:break
    num=ord(s[i])
    ch_num=123-num
    if i==len(s)-1:
        s[i]=chr(96+(num+k)%122) if num+k>122 else chr(num+k)
        k=0

    elif ch_num<=k:
        s[i]='a'
        k-=ch_num
print(''.join(s))

Submission status: Wrong Answer

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

for i in range(len(s)):
    if k==0:break
    num=ord(s[i])
    ch_num=123-num
    if i==len(s)-1:
        s[i]=chr(96+(num+k)%122) if num+k>122 else chr(num+k)

    elif ch_num<=k:
        s[i]='a'
        k-=ch_num
print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
ans = ''
for i in range(len(s)):
    if i == len(s) - 1:  # 最後の文字の時
        diff = (k - cnt) % 26
        ans += chr((ord(s[i]) - ord('a') + (k - cnt)) % 26 + ord('a'))
    elif ord('z') - ord(s[i]) + 1 <= k - cnt:  # 'a'に変更可能な時
        cnt += ord('z') - ord(s[i]) + 1
        ans += 'a'
    else:
        ans += s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
ans = ''
for i in range(len(s)):
    if i == len(s) - 1:  # 最後の文字の時
        diff = (k - cnt) % 26
        ans += chr((ord(s[i]) - ord('a') + (k - cnt)) % 26 + ord('a'))
        break
    if ord('z') - ord(s[i]) + 1 <= k - cnt:  # 'a'に変更可能な時
        cnt += ord('z') - ord(s[i]) + 1
        ans += 'a'
    else:
        ans += s[i]
print(ans)

Submission status: Wrong Answer

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

ans = []

for i in s:
    if i == "a":
        ans.append("a")
        continue
    
    elif ord(i) + K > ord("z") + 1:
        ans.append("a")
        K -= ord("z") + 1 - ord(i)
    
    else:
        ans.append(i)
        


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

Submission status: Wrong Answer

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

ans = []

for i in s:
    if i == "a":
        ans.append("a")
        pass
    
    elif ord(i) + K > ord("z") + 1:
        ans.append("a")
        K -= ord("z") + 1 - ord(i)
    
    else:
        ans.append(i)
        


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

Submission status: Wrong Answer

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

for i in range(len(s)):
    num_al=ord(s[i])
    a_=123-num_al
    if k==0:break
    if s[i]=='a' and i!=len(s)-1:continue
    
    if a_<=k:
        k-=a_
        s[i]='a'
    elif a_>k and i<len(s)-1:continue
    else:
        s[i]=chr(num_al+k)
        k=0
print(''.join(s))

Submission status: Wrong Answer

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

cnt=0
for i in range(len(s)):
    num_al=ord(s[i])
    a_=123-num_al
    if k==0:break
    if s[i]=='a':continue
    if a_<=k:
        k-=a_
        s[i]='a'
    elif a_>k and i<len(s)-1:continue
    else:
        s[i]=chr(num_al+k)
        k=0
print(''.join(s))

Submission status: Wrong Answer

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

cnt=0
for i in range(len(s)):
    num_al=ord(s[i])
    a_=123-num_al
    if k==0:break
    if a_<=k:
        k-=a_
        s[i]='a'
    elif a_>k and i<len(s)-1:continue
    else:
        s[i]=chr(num_al+k)
        k=0
print(''.join(s))

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
alf='abcdefghijklmnopqrstuvwxyza'

cnt=0
for i in range(len(s)):
    num_al=ord(s[i])
    a_=123-num_al
    if a_<=k:
        k-=a_
        s[i]='a'
    elif a_>k and i<len(s)-1:continue
    else:
        s[i]=chr(num_al+k)
        k=0
        break
print(''.join(s))

Submission status: Wrong Answer

Solution code:
#print(ord('a')) # 97
abc = ''
for i in range(97 ,97+26):
    abc += chr(i)
#print(abc)

S = input()
K = int(input())
ans = ''
for i,s in enumerate(S):
    if ord(s) > ord('a') and 27 - (ord(s) - ord('a')) <= K and i!=len(S)-1:
        ans += 'a'
        K -= 26 - (ord(s) - ord('a'))
        #print(K)

    elif i != len(S)-1:
        ans += s
    else:
        #ans += chr(ord(s) + K%26)
        ans += abc[(ord(s) + K%26-ord('a'))%26]
        #print(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
#print(ord('a')) # 97
abc = ''
for i in range(97 ,97+26):
    abc += chr(i)
#print(abc)

S = input()
K = int(input())
ans = ''
for i,s in enumerate(S):
    if ord(s) > ord('a') and 27 - (ord(s) - ord('a')) <= K:
        ans += 'a'
        K -= 26 - (ord(s) - ord('a'))
        #print(K)

    elif i != len(S)-1:
        ans += s
    else:
        #ans += chr(ord(s) + K%26)
        ans += abc[(ord(s) + K%26-ord('a'))%26]

print(ans)

Submission status: Wrong Answer

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

n = len(s)

l = [0]*n
for i in range(n):
    l[i] = ord('z') -ord(s[i]) + 1
#print(l)

ans = list(s)
i = 0
while k > 0:
    if i > n-1:
        break
    if l[i] <= k:
        ans[i] = 'a'
        k -= l[i]
    i += 1
k %= 26
if k > 0:
    ans[-1] = chr((k + ord(ans[-1])-ord('a'))%26+97)
#print(ans)
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
import sys
def main():
    input = sys.stdin.readline
    s = input().rstrip()
    K = int(input())

    def c(x): return ord(x) - ord('a')
    def d(x): return chr(x + ord('a'))
    ans = []
    i = 0
    while K > 0 and i < (len(s) - 1):
        to_a = (26 - c(s[i])) % 26
        if to_a <= K:
            ans.append('a')
            K -= to_a
        else:
            ans.append(s[i])
        i += 1
    if K > 0:
        ans.append(d((c(s[-1]) + K) % 26))
    else:
        ans.append(s[i])
    print(''.join(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

n = len(s)

l = [0]*n
for i in range(n):
    l[i] = ord('z') -ord(s[i]) + 1
#print(l)

ans = list(s)
i = 0
while k > 0:
    if i > n-1:
        break
    if l[i] <= k:
        ans[i] = 'a'
        k -= l[i]
    i += 1
if k > 0:
    ans[-1] = chr((k + ord(ans[-1])-ord('a'))%26+97)
#print(ans)
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = list(STR())
l = len(s)
k = INT()
for i in range(l):
    tmp = ord('z') + 1 - ord(s[i])
    if tmp <= k:
        s[i] = 'a'
        k -= tmp
s[l - 1] = chr((ord(s[l - 1]) - ord('a') + k) % 26 + ord('a'))
print(''.join(s))