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:
s = list(input())
k = int(input())
n = len(s)
for i in range(n):
    d = ord('z')-ord(s[i])+1
    if d<=k:
        s[i] = 'a'
        k -= d

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


print(''.join(s))

Submission status: Wrong Answer

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

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

print(''.join(s))

Submission status: Wrong Answer

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

s[-1] = chr(ord(s[-1])+k%26)

print(''.join(s))

Submission status: Wrong Answer

Solution code:
makeA = lambda c: (ord('z')-ord(c)+1) % 26
s = list(map(makeA,list(input())))
#print(s)
K = int(input())
len_s = len(s)
#print(len_s)
for i in range(len_s-1):
    if s[i] <= K:
        K -= s[i]
        s[i] = 0
        print(s)
if K > 0:
    s[-1] = (s[-1] + 26 - (K % 26)) % 26
#print(s)
makeS = lambda n: chr((26-n)%26+ord('a'))
print(''.join(list(map(makeS,s))))

Submission status: Wrong Answer

Solution code:
makeA = lambda c: (ord('z')-ord(c)+1) % 26
s = list(map(makeA,list(input())))
print(s)
K = int(input())
len_s = len(s)
print(len_s)
for i in range(len_s-1):
    if s[i] <= K:
        K -= s[i]
        s[i] = 0
        print(s)
if K > 0:
    s[-1] = (s[-1] + 26 - (K % 26)) % 26
print(s)
makeS = lambda n: chr((26-n)%26+ord('a'))
print(''.join(list(map(makeS,s))))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
z = ord('z') + 1

res = ""
flg = False
for i,c in enumerate(S):
    if z - ord(c) <= K:
        res += 'a'
        K -= z-ord(c)
    else:
        res += chr(ord(c))

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

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
z = ord('z') + 1

res = ""
flg = False
for i,c in enumerate(S):
    if z - ord(c) <= K:
        res += 'a'
        K -= z-ord(c)
    else:
        res += chr(ord(c))

res = res[:-1] + chr((ord(res[-1]) + K)%26)
print(res)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
z = ord('z') + 1

res = ""
flg = False
for i,c in enumerate(S):
    if z - ord(c) <= K:
        res += 'a'
        K -= z-ord(c)
    else:
        res += chr(ord(c))

res = res[:-1] + chr(ord(res[-1]) + K%26)
print(res)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
z = ord('z') + 1

res = ""
flg = False
for i,c in enumerate(S):
    if z - ord(c) <= K:
        res += 'a'
        K -= z-ord(c)
    else:
        res += chr(ord(c))

print(res)

Submission status: Wrong Answer

Solution code:
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if k == 0:
            break
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        k %= 26
        ans[-1] = chr((ord(ans[-1]) + k - 97) % 26 + 97)
    print(''.join(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if k == 0:
            break
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        k %= 26
        ans[-1] = chr(ord(ans[-1]) + k)
    print(''.join(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if k == 0:
            break
        if ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        k %= 26
        ans[-1] = chr(ord(ans[-1]) + k)
    print(''.join(ans))



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
f=lambda x:(x-97)%26
for i in range(len(s)):
    j=26-f(ord(s[i]))
    if j>k:
        continue
    k-=j
    s[i]='a'
k%=26
s[-1]=chr(f(ord(s[-1])+k)+97)
print(*s,sep='')

Submission status: Wrong Answer

Solution code:
s = str(input())
k = int(input())
S = []
for i in range(len(s)):
    S.append(ord(s[i]) - 97)
i = 0
while k > 0:
    if 26 - S[i] <= k:
        k -= 26 - S[i]
        S[i] = 0
        i += 1
    else:
        i += 1
    if i >= len(s):
        S[-1] += k
        break
ans = ''
for x in S:
    ans += chr((x % 26) + 97)
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(map(str, input().rstrip()))
k = int(input())

diff = [ord("a") + 26 - ord(x) for x in s]

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

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

    s[-1] = chr(tmp)

print("".join(s))

Submission status: Wrong Answer

Solution code:
s = list(map(str, input().rstrip()))
k = int(input())

diff = [123 - ord(x) for x in s]

for i in range(len(s)):
    if diff[i] <= k:
        s[i] = "a"
        k -= diff[i]
    else:
        continue

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

s[-1] = chr(tmp)

print("".join(s))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    s = rl().rstrip()
    K = int(rl())
    
    ans = []
    for si in s:
        if si == 'a':
            ans.append('a')
            continue
        cnt = ord('z') - ord(si) + 1
        if cnt <= K:
            ans.append('a')
            K -= cnt
        else:
            ans.append(si)
    
    for i in range(len(s))[::-1]:
        if K == 0:
            break
        cnt = min(ord('z') - ord(ans[i]), K)
        ans[i] = chr(ord(ans[i]) + cnt)
        K -= cnt
    print(''.join(ans))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import os


# 実装を行う関数
def resolve():
    s = list(input())
    k = int(input())

    # 各桁をaにするために必要な処理回数を求める。(1桁ずつ求めていく)
    need_cnt_list = [26 - (ord(i) % 97) for i in s]
    # アルファベット(小文字)のaASCIIは97。なので、mod97でアルファベットを番号に置換できる(a=0 z=25)。ちなみに大文字Aは65。
    # for i in s:
    #     work += 26 - (ord(i) % 97)

    ans = []

    zan_cnt = k

    for num, i in enumerate(need_cnt_list):
        # 値を1週させてaにできる場合、該当文字をaにする。
        if zan_cnt >= i:
            zan_cnt -= i
            # 該当文字をaにする。
            ans.append("a")
        # 値を1週させてaにできない場合、その桁は何も処理せず次の桁に進む。
        else:
            ans.append(s[num])

    # 最後に、最終桁を延々と処理した結果が答え。
    # ※「余ったkを全て最終桁に使用した場合の最終桁の文字」で最終文字を置換
    now_last = ord(ans[-1]) - 97
    last = zan_cnt % 26 + now_last

    # 最終桁の文字を置き換え
    ans[-1] = chr(last + 97)
    print("".join(ans))
    return


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """xyz
4"""
        output = """aya"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """a
25"""
        output = """z"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """codefestival
100"""
        output = """aaaafeaaivap"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def test_1original_1(self):
        test_input = """bbb
100000000"""
        output = """aaz"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import os


# 実装を行う関数
def resolve():
    s = list(input())
    k = int(input())

    # 各桁をaにするために必要な処理回数を求める。(1桁ずつ求めていく)
    need_cnt_list = [26 - (ord(i) % 97) for i in s]
    # アルファベット(小文字)のaASCIIは97。なので、mod97でアルファベットを番号に置換できる(a=0 z=25)。ちなみに大文字Aは65。
    # for i in s:
    #     work += 26 - (ord(i) % 97)

    ans = []

    zan_cnt = k

    for num, i in enumerate(need_cnt_list):
        # 値を1週させてaにできる場合、該当文字をaにする。
        if zan_cnt >= i:
            zan_cnt -= i
            # 該当文字をaにする。
            ans.append("a")
        # 値を1週させてaにできない場合、その桁は何も処理せず次の桁に進む。
        else:
            ans.append(s[num])

    # 最後に、最終桁を延々と処理した結果が答え。
    # ※「余ったkを全て最終桁に使用した場合の最終桁の文字」で最終文字を置換
    now_last = ord(ans[-1]) - 97
    last = zan_cnt % 26 + now_last

    # 最終桁の文字を↑に置き換え
    ans[-1] = chr(last + 97)
    print("".join(ans))
    return


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """xyz
4"""
        output = """aya"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """a
25"""
        output = """z"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """codefestival
100"""
        output = """aaaafeaaivap"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def test_1original_1(self):
        test_input = """bbb
100000000"""
        output = """aaz"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import os


# 実装を行う関数
def resolve():
    s = list(input())
    k = int(input())

    # 各桁をaにするために必要な処理回数を求める。(1桁ずつ求めていく)
    need_cnt_list = [26 - (ord(i) % 97) for i in s]
    # アルファベット(小文字)のaASCIIは97。なので、mod97でアルファベットを番号に置換できる(a=0 z=25)。ちなみに大文字Aは65。
    # for i in s:
    #     work += 26 - (ord(i) % 97)

    ans = []

    # # kが全ての桁をaに変換できる場合
    # sum_need_cnt_list = sum(need_cnt_list)
    # if k >= sum_need_cnt_list:
    #     # 全桁をaにして・・
    #     ans = ["a" for i in range(len(s))]
    #     # 最後に、最終桁を延々と処理した結果が答え。
    #     # ※「余ったkを全て最終桁に使用した場合の最終桁の文字」で最終文字を置換
    #     last = (k - sum_need_cnt_list) % 26
    #     ans[-1] = chr(last + 97)
    #     print("".join(ans))
    #     return

    # kが全ての桁をaに変換できるほど大きくない場合
    # else:
    # 各桁をaにできるか検証。(1桁ずつ求めていく)
    zan_cnt = k

    for i in need_cnt_list:
        # 値を1週させてaにできる場合、該当文字をaにする。
        if zan_cnt >= i:
            zan_cnt -= i
            # 該当文字をaにする。
            ans.append("a")
        # 値を1週させてaにできない場合、その桁は何も処理せず次の桁に進む。
        else:
            ans.append(chr(97 + 26 - i))

    # 最後に、最終桁を延々と処理した結果が答え。
    # ※「余ったkを全て最終桁に使用した場合の最終桁の文字」で最終文字を置換
    now_last = ord(ans[-1]) - 97
    last = (zan_cnt + now_last) % 26

    # 最終桁の文字を↑に置き換え
    ans[-1] = chr(last + 97)
    print("".join(ans))
    return


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """xyz
4"""
        output = """aya"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """a
25"""
        output = """z"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """codefestival
100"""
        output = """aaaafeaaivap"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def test_1original_1(self):
        test_input = """bbb
100000000"""
        output = """aaz"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import os


# 実装を行う関数
def resolve():
    s = list(input())
    k = int(input())


    # 各桁をaにするために必要な処理回数を求める。(1桁ずつ求めていく)
    need_cnt_list = [26 - (ord(i) % 97) for i in s]
    # アルファベット(小文字)のaASCIIは97。なので、mod97でアルファベットを番号に置換できる(a=0 z=25)。ちなみに大文字Aは65。
    # for i in s:
    #     work += 26 - (ord(i) % 97)

    ans = []

    # kが全ての桁をaに変換できる場合
    sum_need_cnt_list = sum(need_cnt_list)
    if k >= sum_need_cnt_list:
        # 全桁をaにして・・
        ans = ["a" for i in range(len(s))]
        # 最後に、最終桁を延々と処理した結果が答え。
        # ※「余ったkを全て最終桁に使用した場合の最終桁の文字」で最終文字を置換
        last = (k - sum_need_cnt_list) % 26
        ans[-1] = chr(last + 97)
        print("".join(ans))
        return

    # kが全ての桁をaに変換できるほど大きくない場合
    else:
        # 各桁をaにできるか検証。(1桁ずつ求めていく)
        use_cnt = 0

        for i in need_cnt_list:
            # 値を1週させてaにできる場合、該当文字をaにする。
            if k - use_cnt >= i:
                use_cnt += i
                # 該当文字をaにする。
                ans.append("a")
            # 値を1週させてaにできない場合、その桁は何も処理せず次の桁に進む。
            else:
                ans.append(chr(97 + 26 - i))

        # 最後に、最終桁を延々と処理した結果が答え。
        # ※「余ったkを全て最終桁に使用した場合の最終桁の文字」で最終文字を置換
        last = (k - use_cnt) % 26
        # 最終桁の文字を↑に置き換え
        ans[-1] = chr(last + 97)
        print("".join(ans))
        return


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """xyz
4"""
        output = """aya"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """a
25"""
        output = """z"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """codefestival
100"""
        output = """aaaafeaaivap"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def test_1original_1(self):
        test_input = """bbb
100000000"""
        output = """aaz"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Wrong Answer

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


ans = []
for c in s[:-1]:
    to_a = ord('z')-ord(c)+1
    if k < to_a:
        ans.append(c)
    else:
        k -= to_a
        ans.append('a')
else:
    c = s[-1]
    x = ord(c)-ord('a')
    y = (k+x) % 26
    ans.append(chr(ord('a')+y))


print(''.join(ans))

Submission status: Wrong Answer

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


ans = []
for c in s[:-1]:
    to_a = ord('z')-ord(c)+1
    if k < to_a:
        ans.append(c)
    else:
        k -= to_a
        ans.append('a')
else:
    c = s[-1]
    x = ord(c)-ord('a')
    ans.append(chr(ord('a')+(k+x) % 26))


print(''.join(ans))

Submission status: Wrong Answer

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

'''
ordの位置
#z = 122
#a = 97
左の文字からNで'a'に出来るかを確認
aに出来るならaにして使った分をNから引く
繰り返して行き一番最後にあまりをすべて使う'''
  
for i, s in enumerate(S):
  if ord(s) - 97 > 0  and 122 - ord(s) < N:
    S[i] = "a"
    N -= 123 - ord(s)
else:
  S[i] = chr(((ord(S[i]) + N) % 96 + 96 ))
  
print("".join(S))

Submission status: Wrong Answer

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

'''
ordの位置
#z = 122
#a = 97
左の文字からNで'a'に出来るかを確認
aに出来るならaにして使った分をNから引く
繰り返して行き一番最後にあまりをすべて使う'''
  
for i, s in enumerate(S):
  if ord(s) - 97 > 0  and 122 - ord(s) < N:
    S[i] = "a"
    N -= 123 - ord(s)
else:
  S[i] = (chr((ord(S[i]) + N) % 122 ))
  
  
print("".join(S))

Submission status: Wrong Answer

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

'''
ordの位置
#z = 122
#a = 97
左の文字からNで'a'に出来るかを確認
aに出来るならaにして使った分をNから引く
繰り返して行き一番最後にあまりをすべて使う'''
  
for i, s in enumerate(S):
  if ord(s) - 97 > 0  and 122 - ord(s) < N:
    S[i] = "a"
    N -= 123 - ord(s)
else:
  S[i] = (chr(ord(S[i]) + N % 122 ))
  
  
print("".join(S))

Submission status: Wrong Answer

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

'''
ordの位置
#z = 122
#a = 97
左の文字からNで'a'に出来るかを確認
aに出来るならaにして使った分をNから引く
繰り返して行き一番最後にあまりをすべて使う'''
  
for i, s in enumerate(S):
  if ord(s) - 97 > 0  and 122 - ord(s) < N:
    S[i] = "a"
    N -= 123 - ord(s)
else:
  print(chr(ord(S[i]) + N % 122 ))
  
  
print("".join(S))

Submission status: Wrong Answer

Solution code:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = input()
K = int(input())
ans = ''
for i in range(len(s)):
    s_i = alphabet.index(s[i])
    if (26 - s_i <= K) & (s_i != 0):
        K -= 26 - s_i
        s_i = 0
    ans += alphabet[s_i]
if K > 0:
    s_i = (alphabet.index(s[-1]) + K) % 26
    ans = ans[:-1] + alphabet[s_i]
print(ans)

Submission status: Wrong Answer

Solution code:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = input()
K = int(input())
ans = ''
for i in range(len(s)):
    s_i = alphabet.index(s[i])
    if (26 - s_i < K) & (s_i != 0):
        K -= 26 - s_i
        s_i = 0
    ans += alphabet[s_i]
if K > 0:
    s_i = (alphabet.index(s[-1]) + K) % 26
    ans = ans[:-1] + alphabet[s_i]
print(ans)

Submission status: Wrong Answer

Solution code:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = input()
K = int(input())
ans = ''
for i in range(len(s) - 1):
    s_i = alphabet.index(s[i])
    if (26 - s_i < K) & (s_i != 0):
        K -= 26 - s_i
        s_i = 0
    ans += alphabet[s_i]
s_i = (alphabet.index(s[-1]) + K) % 26
ans += alphabet[s_i]
print(ans)

Submission status: Wrong Answer

Solution code:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = input()
K = int(input())
ans = ''
for i in range(len(s) - 1):
    s_i = alphabet.index(s[i])
    if s_i == 0:
        continue
    elif 26 - s_i < K:
        K -= 26 - s_i
        s_i = 0
    ans += alphabet[s_i]
s_i = (alphabet.index(s[-1]) + K) % 26
ans += alphabet[s_i]
print(ans)

Submission status: Wrong Answer

Solution code:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = input()
K = int(input())
ans = ''
for i in range(len(s) - 1):
    s_i = alphabet.index(s[i])
    if s_i == 0:        
        continue
    elif 26 - s_i < K:
        K -= 26 - s_i
        s_i = 0
    ans += alphabet[s_i]
s_i = (alphabet.index(s[-1]) + K) % 26
ans += alphabet[s_i]
print(ans)

Submission status: Wrong Answer

Solution code:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = input()
K = int(input())
ans = ''
for i in range(len(s) - 1):
    s_i = alphabet.index(s[i])
    if s_i == 0:
        ans += s[s_i]
        continue
    if 26 - s_i < K:
        K -= 26 - s_i
        s_i = 0
    ans += alphabet[s_i]
s_i = (alphabet.index(s[-1]) + K) % 26
ans += alphabet[s_i]
print(ans)

Submission status: Wrong Answer

Solution code:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = input()
K = int(input())
ans = ''
for i in range(len(s) - 1):
    s_i = alphabet.index(s[i])
    if 26 - s_i < K:
        K -= 26 - s_i
        s_i = 0
    ans += alphabet[s_i]
s_i = (alphabet.index(s[-1]) + K) % 26
ans += alphabet[s_i]
print(ans)

Submission status: Wrong Answer

Solution code:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = input()
K = int(input())
ans = ''
for i in range(len(s) - 1):
    s_i = alphabet.index(s[i])
    if 26 - s_i <= K:
        K -= 26 - s_i
        s_i = 0
    ans += alphabet[s_i]
s_i = (alphabet.index(s[-1]) + K) % 26
ans += alphabet[s_i]
print(ans)

Submission status: Wrong Answer

Solution code:
alphabet = "abcdefghijklmnopqrstuvwxyz"
a_len = len(alphabet)
table = {c: idx for idx, c in enumerate(alphabet)}

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

ans = ""
for c in s[:-1]:
    gap = a_len - table[c]
    if gap <= k:
        ans += "a"
        k -= gap
    else:
        ans += c

ans += alphabet[(table[s[-1]] + k) % a_len]
print(ans)

Submission status: Wrong Answer

Solution code:
alphabet = "abcdefghijklmnopqrstuvwxyz"
a_len = len(alphabet)
table = {c: idx for idx, c in enumerate(alphabet)}

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

for i in range(len(s)):
    if i == len(s) - 1:
        s = s[0:i] + alphabet[(table[s[i]] + k) % a_len]
    else:
        gap = a_len - table[s[i]]
        if gap <= k:
            s = s[0:i] + "a" + s[i + 1:]
            k -= gap
        else:
            continue

print(s)

Submission status: Wrong Answer

Solution code:
alphabet = "abcdefghijklmnopqrstuvwxyz"
a_len = len(alphabet)
table = {c: idx for idx, c in enumerate(alphabet)}

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

ans = ""
idx = 0
while k > 0:
    if idx != len(s) - 1:
        gap = a_len - table[s[idx]]
        if gap <= k:
            ans += "a"
            k -= gap
        else:
            ans += s[idx]
    else:
        ans += alphabet[(table[s[idx]] + k) % a_len]
        k = 0
    idx += 1

ans += s[idx:]

print(ans)

Submission status: Wrong Answer

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

ans = []

for i in range(len(s)):
    if 123 - ord(s[i]) <= k:
        ans.append("a")
        k -= 123 - ord(s[i])
    else:
        ans.append(s[i])

last = chr((ord(ans[-1])-97+k)%26 + 97)
ans[-1] = last
print(*ans, sep = "")

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
d = {}
dd = {}
for i, ss in enumerate('abcdefghijklmnopqrstuvwxyz'):
    d[ss] = i
    dd[i] = ss
ans = ''

for ss in s[:-1]:
    if k >= 26 - d[ss]:
        k -= 26 - d[ss]
        ans += 'a'
    else:
        ans += ss
k = (d[s[-1]] + k) % 26
ans += dd[k]
print(*ans, sep='')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=list(map(ord,list(input())))
k=int(input())

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

c=0
while k>0:
    if c==len(s)-1:
        s[c]=(s[c]+k)%26
        k=0
    elif s[c]+k>=26:
        k-=26-s[c]
        s[c]=0
        c+=1
    else:
        c+=1

seq=""
for i in range(len(s)):
    seq+=chr(s[i]+97)

print(seq)

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    for i in range(len(s)):
        if s[i] == "a":
            continue
        si = ord(s[i]) - 97
        if k >= 26 - si:
            s[i] = "a"
            k -= 97 + 26 - si
            if k == 0:
                break

    s[-1] = chr(97 + (ord(s[-1]) - 97 + k) % 26)

    print(*s, sep="")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    for i in range(len(s)):
        si = ord(s[i])
        if k >= 97 + 26 - si:
            s[i] = "a"
            k -= 97 + 26 - si
            if k == 0:
                break

    s[-1] = chr(97 + (ord(s[-1]) - 97 + k) % 27)

    print(*s, sep="")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    for i in range(len(s)):
        si = ord(s[i])
        if k >= 97 + 26 - si:
            s[i] = "a"
            k -= 97 + 26 - si
            if k == 0:
                break

    s[-1] = chr(97 + (ord(s[-1]) - 97 + k) % 26)

    print(*s, sep="")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(N):
  if i<N-1:
    a=26-al.index(s[i])
    if K>=a:
      K -= a
      s=s[0:i]+al[(al.index(s[i])+a)%26]+s[i+1:]
  else:
    K %= 26
    p= (K+al.index(s[i]))% 26
    s=s[0:N-1]+al[p]
    K=0
    
print(s)

Submission status: Wrong Answer

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

for i in range(N):
  if i<N-1:
    a=26-al.index(s[i])
    if K>=a:
      K -= a
      s=s[0:i]+"a"+s[i+1:]
  else:
    p= (K+al.index(s[i]))% 26
    s=s[0:N-1]+al[p]
    K=0
    
print(s)

Submission status: Wrong Answer

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

for i in range(len(s)):
  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: Wrong Answer

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

for i in range(N):
  if i<N-1:
    a=26-al.index(s[i])
    if K>=a:
      K -= a
      s=s[0:i]+"a"+s[i+1:]
  else:
    p= (K+al.index(s[i]))% 26
    s=s[0:i]+al[p]+s[i+1:]
    K=0
    
print(s)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#"a" 97 "z" 122
s = list(ord(i) for i in input())
k = int(input())
for i in range(len(s)):
  if 123 - s[i] <= k:
    k -= 123-s[i]
    s[i] = 97

if k > 0:
  for i in range(1,len(s)+1):
    if s[-i] == 97: continue
    s[-i] += k
    if s[-i] > 122:
      while 97 > s[-i] or s[-i] > 122:
        s[-i] = s[-i]-123+91
    k = 0
    break
if k > 0:
  s[-i] += k
  if s[-i] > 122:
      while 97 > s[-i] or s[-i] > 122:
        s[-i] = s[-i]-123+91
print("".join(list(map(chr, s))))

Submission status: Wrong Answer

Solution code:
dic = {"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}
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: Wrong Answer

Solution code:
dic = {"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}
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)%26]

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

Submission status: Wrong Answer

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

ns = []
for c in s[:-1]:
    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: Wrong Answer

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にするためのコストを求める
  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: Wrong Answer

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にするためのコストを求める
  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))