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:
import sys
S = str(input())
K = int(input())

K %= (len(S) * 26)

arr = [ord(S[i]) for i in range(len(S))]
count = K
for i in range(len(S)):
    if i == len(S) - 1:
        count %= 26
        if ord('z') - arr[i] + 1 <= count:
            arr[i] = ord('a')
            count -= ord('z') - ord(S[i]) + 1
        arr[i] += count
        break

    if ord('z') - arr[i] + 1 <= count:
        arr[i] = ord('a')
        count -= (ord('z') - ord(S[i]) + 1)

    if count == 0:
        break

for c in arr:
    sys.stdout.write(chr(c))

print('')

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
d = dict()
alphabet = "abcdefghijklmnopqrstuvwxyz"
for i in range(len(alphabet)):
    d[alphabet[i]]=i
    
def f(s,k):
    s = [s[i] for i in range(len(s))]
    res = s
    L = 0
    for i in range(len(s)):
        l = max((26 - d[s[i]]) % 26, 0)
        if L + l < k:
            res[i] = "a"
            L += l
        else:
            if i==len(s)-1:
                res[i] = alphabet[(d[s[i]] + (k-L)) % 26]
            continue
    return(''.join(res))
print(f(s,k))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-                                                                                                   
def main():
  # input
  s = raw_input()
  K = int(raw_input())
  ch = [123-ord(c) for c in s]
  for i in range(len(s)):
    if ch[i] == 26 and i != len(s)-1:
      continue
    elif ch[i] < K:
      K = K - ch[i]
      ch[i] = 26
    elif ch[i] == K:
      ch[i] = 26
      break
    elif ch[i] > K and i != len(s)-1:
      continue
    else:
      ch[i] = ch[i] - K
      if ch[i] <= 0:
        ch[i] == 26
  # output
  ch = [str(unichr((27-c)+96)) for c in ch]
  print ''.join(ch)
main()

Submission status: Wrong Answer

Solution code:




if __name__=='__main__':
    st = input()
    #lst = list(st)
    ans = ''
    k = int(input())
    for i in st:
        if i=='a':
            ans+=i
            continue
        else:
            if k!=0 and 26-(ord(i)-ord('a'))<=k:
                k-=26-(ord(i)-ord('a'))
                ans+='a'
            else:
                ans+=i
    if k!=0:
        cnt = len(ans)
        res = ''
        for i in range(len(ans)-1,-1,-1):
            cnt-=1
            if ord('z')-ord(ans[i])>=25:
                res ='z'+res
                k-=ord('z')-ord(ans[i])
            else:
                res = chr(ord(ans[i])+k)
                k=0
            if k==0:
                break
        
        print(ans[:cnt]+res)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
#

def join(s):
    return ''.join(s)

#iterate macro
def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)

#modulo macro
def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m

#bisect macro
def index(a, x):
    #Locate the leftmost value exactly equal to x
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1

#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

nh=zip([1,0,-1,0],[0,1,0,-1])

###########

st=slist()
k=i()

for j in range(len(st)):
    o=ord(st[j])
    if k >= 123-o:
        k -= (123-o)
        st[j]='a'
        
n=97+(ord(st[len(st)-1])-97+k)%26

st[len(st)-1] = chr(n)
print join(st)

Submission status: Wrong Answer

Solution code:

sl = list(input() )
k = int( input() )

al ="abcdefghijklmnopqrstuvwxyz"
alen = len(al)

for i in range(0,len(sl) ):
    p = alen - al.find(sl[i])
    if(p<k):
        sl[i] = 'a'
        k = k-p

#print("k,p:",k,p)

if k>0 :
    p = alen - al.find(sl[-1])  # now position
    sl[-1] = al[-p+k]            # 

s = "".join(sl)
print(s)
#print(s,k,(alen-p),al[alen-p])

Submission status: Wrong Answer

Solution code:
from collections import deque

def next_char_ascii_num(c, k):
    n = ord(c) + (k % 26)
    if n <= 122:
        return n
    else:
        return n % 123 + 97

s = input()
k = int(input())
d = deque()
l = len(s)

for i,x in enumerate(s):

    if k <= 0:
        l = i
        break

    else:
        if k >= 25 and l != 1:
            d.append(97)
            k -= (26 - (ord(x) - 97))
        else:
            v =[next_char_ascii_num(x, y) for y in range(k + 1)]
            min_index = v.index(min(v))
            d.append(v[min_index])
            k -= min_index

v += s[l:]
if k > 0:
    d[-1] = next_char_ascii_num(chr(d[-1]), k)

print("".join([chr(x) for x in d]))

Submission status: Wrong Answer

Solution code:
s=[c for c in raw_input()]
K=int(raw_input())

c=0

def single_change(ch,C,k):
    n = 1 + k / 26
    for i in xrange(n):
        while C < k:
            C += 1
            if ch == 'z':
                ch = 'a'
            else:
                ch = chr(ord(ch) + 1)
    return ch

if len(s) == 1:
    s[0] = single_change(s[0],c,K)
else:
    i=0
    while i < len(s):
        if ((ord('a') - ord(s[i]))%26) > K:
            i += 1
            continue
        while s[i] != 'a' and c < K:
            c += 1
            if s[i] == 'z':
                s[i] = 'a'
                break
            s[i] = chr(ord(s[i])+1)
        i += 1
        while i != len(s)-1 and i < len(s) and (K-c) < ((ord('a') - ord(s[i]))%26):
            i += 1

    if K > c:
        s[0] = single_change(s[0],c,K)

print s

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from collections import deque

def next_char_ascii_num(c, k):
    n = ord(c) + (k % 26)
    if n <= 122:
        return n
    else:
        return n % 123 + 97

s = input()
k = int(input())
d = deque()
l = len(s)

for x in s:

    if k <= 0:
        d.append(ord(x))

    else:
        if k >= 25 and l != 1:
            d.append(97)
            k -= (26 - (ord(x) - 97))
        else:
            v =[next_char_ascii_num(x, y) for y in range(k + 1)]
            min_index = v.index(min(v))
            d.append(v[min_index])
            k -= min_index

if k > 0:
    d[-1] = next_char_ascii_num(chr(d[-1]), k)

print("".join([chr(x) for x in d]))

Submission status: Wrong Answer

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

for ix in range(0,len(calc)):
    nes = 26-(ord(calc[ix])-ord('a'))
    if nes <= K:
        calc[ix] = 'a'
        K = K - nes
if K >0 and ord(calc[ix])+K <= 122:
    calc[ix] = chr(ord(calc[ix])+K)
if ord(calc[ix])+K > 122:
    nokori = ord(calc[ix])+K - 122
    calc[ix] = chr(97+nokori%26)
print(''.join(calc))

Submission status: Wrong Answer

Solution code:




if __name__=='__main__':
    st = input()
    #lst = list(st)
    ans = ''
    k = int(input())
    for i in st:
        if i=='a':
            ans+=i
            continue
        else:
            if k!=0 and 26-(ord(i)-ord('a'))<=k:
                k-=26-(ord(i)-ord('a'))
                ans+='a'
            else:
                ans+=i
    if k!=0:
        kk = chr(ord(ans[len(ans)-1])+k)
        print(ans[:len(ans)-1]+kk)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
#read in input
s = map((lambda x: ord(x) - 96), raw_input())
k = int(raw_input())


for i in range(len(s)):
  sv = s[i]
  if (27 - sv) > k:
    continue
  s[i] = 1
  k = k - (27 - sv)

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

print "".join(map((lambda x: chr(x + 96)), s))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
d = dict()
alphabet = "abcdefghijklmnopqrstuvwxyz"
for i in range(len(alphabet)):
    d[alphabet[i]]=i
    
def f(s,k):
    s = [s[i] for i in range(len(s))]
    res = s
    L = 0
    for i in range(len(s)):
        l = max(26 - d[s[i]],0)
        if L + l < k:
            res[i] = "a"
            L += l
        else:
            if i==len(s)-1:
                res[i] = alphabet[(d[s[i]] + (k-L)) % 26]
            continue
    return(''.join(res))
print(f(s,k))

Submission status: Wrong Answer

Solution code:
from collections import deque

def next_char_ascii_num(c, k):
    n = ord(c) + (k % 26)
    if n <= 122:
        return n
    else:
        return n % 123 + 97

s = input()
k = int(input())
d = deque()
l = len(s)

for x in s:

    if k == 0:
        d.append(ord(x))

    else:
        if k >= 25 and l != 1:
            d.append(97)
            k -= (26 - (ord(x) - 97))
        else:
            v =[next_char_ascii_num(x, y) for y in range(k + 1)]
            min_index = v.index(min(v))
            d.append(v[min_index])
            k -= min_index

if k > 0:
    d[-1] = next_char_ascii_num(chr(d[-1]), k)

print("".join([chr(x) for x in d]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

s = raw_input()
k = input()

ret = ""

for c in s:
    if k - (123 - ord(c)) >= 0:
        ret += "a"
        k -= (123 - ord(c))
    else:
        ret += c

print ret[:-1] + chr((ord(ret[-1]) + k - 97) % 26 + 97)

Submission status: Wrong Answer

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

len_s = len(s)
for i in range(0, len_s):
  if len_s - 1 == i:
    s[i] = chr((ord(s[i]) - ord('a') + k) % 26 + ord('a'))
  else:
    need = ord('z') - ord(s[i]) + 1;
    if k >= need:
      s[i] = 'a'
      k -= need
      if 0 == k:
        break

print ''.join(s)

Submission status: Wrong Answer

Solution code:
def r_shift(c, i):
    return chr(ord('a') + int(((ord(c) + i) - ord('a'))) % 26)
s = input()
K = int(input())
r = ''
for c in s[:-1]:
    dis = 26 - (ord(c) - ord('a'))
    if dis <= K:
        K -= dis
        r += 'a'
    else:
        r += c
if K > 0:
    r += r_shift(s[-1], K)
else:
    r += s[-1]
print(r)

Submission status: Wrong Answer

Solution code:
#C-Next Letter
str = input()
K = int(input())
tempK = K
result = ""
for i in range(len(str)-1):
	changeNum = 122-ord(str[i])+1
	if (changeNum <= tempK):
		result += "a"
		tempK -= changeNum
	else:
		result += str[i]
tempK %= 26
if (tempK > 0):
	changeNum = ord(str[-1]) + tempK
	if (changeNum > 122):
		changeNum = changeNum -122 + 97 -1
	else:
		changeNum = changeNum
	result += chr(changeNum)
else:
	result += str[-1]
print(result)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

s = raw_input()
k = input()

ret = ""

for c in s:
    if k - (123 - ord(c)) >= 0:
        ret += "a"
        k -= (123 - ord(c))
    else:
        ret += c

print ret[:-1] + chr(ord(ret[-1]) + k % 26)

Submission status: Wrong Answer

Solution code:
s = input()
d = int(input())
out = ""

for (i,x) in enumerate(s):
    if i != len(s)-1:
        if d >= 123-ord(x):
            out += 'a'
            d -= 123-ord(x)
        else:
            out += x
    else:
        tmp = (ord(x)+d)
        while tmp >122:
            tmp -= 26
        out += chr(tmp)

print(out)

Submission status: Wrong Answer

Solution code:
#C-Next Letter
str = input()
K = int(input())
tempK = K
result = ""
for i in range(len(str)-1):
	changeNum = 122-ord(str[i])+1
	if (changeNum <= tempK):
		result += "a"
		tempK -= changeNum
		if (tempK == 0):
			result += str[i+1:]
			print(result)
			break
	else:
		result += str[i]
tempK %= 26
if (tempK > 0):
	changeNum = ord(str[-1]) + tempK
	if (changeNum > 122):
		changeNum = changeNum -122 + 97 -1
	else:
		changeNum = changeNum
	result += chr(changeNum)
else:
	result += str[-1]
print(result)

Submission status: Wrong Answer

Solution code:
import sys
S = str(input())
K = int(input())

arr = [ord(S[i]) for i in range(len(S))]
count = K
for i in range(len(S)):
    if i == len(S) - 1:
        count %= 26
        if ord('z') - arr[i] + 1 <= count:
            arr[i] = ord('a')
            count -= ord('z') - ord(S[i]) + 1
        arr[i] += count
        break

    if ord('z') - arr[i] + 1 <= count:
        arr[i] = ord('a')
        count -= (ord('z') - ord(S[i]) + 1)

for c in arr:
    sys.stdout.write(chr(c))

print('')

Submission status: Wrong Answer

Solution code:
s=[c for c in raw_input()]
K=int(raw_input())

i=0
c=0

if len(s) == 1:
    n = 1 + K / 26
    for i in xrange(n):
        while c < K:
            c += 1
            if s[0] == 'z':
                s[0] = 'a'
            else:
                s[0] = chr(ord(s[0]) + 1)
else:
    while i < len(s):
        while s[i] != 'a' and c < K:
            c += 1
            if s[i] == 'z':
                s[i] = 'a'
                break
            s[i] = chr(ord(s[i])+1)
        i += 1
        while i != len(s)-1 and i < len(s) and (K-c) < ((ord('a') - ord(s[i]))%26):
            i += 1

print s

Submission status: Wrong Answer

Solution code:
def next_letter(target_string, character_position, last_K):
    """
    与えられた文字列のcharacter_position番目（ただし0からはじまる）の文字をnumber個進める
    """
    number = last_K % 26
    letter = target_string[character_position]
    letter_askii = ord(letter)
    next_letter = chr(letter_askii + number)
    return next_letter

target_string = input()
K = int(input())

#まずはaにできないところまで左からaにしていく
result_string = ""
for letter in target_string:
    next_letter_num_to_a = (ord("z") - ord(letter) + 1) % 26
    if next_letter_num_to_a > K:
        result_string += letter
    else:
        result_string += "a"
        K -= next_letter_num_to_a

# 最後に最下位をすすめる
if K == 0:
    print (result_string)
else:
    last_character_pos = len(target_string) - 1
    result_string = result_string[:last_character_pos] + next_letter(target_string, last_character_pos, K)
    print (result_string)

Submission status: Wrong Answer

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

arr = [ord(S[i]) for i in range(len(S))]
count = K
for i in range(len(S)):
    if i == len(S) - 1:
        count %= 26
        if ord('z') - arr[i] + 1 <= count:
            arr[i] = ord('a')
            count -= ord('z') - ord(S[i]) + 1
        arr[i] += count
        break

    if ord('z') - arr[i] + 1 <= count:
        arr[i] = ord('a')
        count -= (ord('z') - ord(S[i]) + 1)

ans = ''
for c in arr:
    ans += chr(c)

print(ans)

Submission status: Wrong Answer

Solution code:
s=[c for c in raw_input()]
K=int(raw_input())

i=0
c=0

if len(s) == 1:
    n = 1 + K / 26
    for i in xrange(n):
        while c < K:
            c += 1
            if s[0] == 'z':
                s[0] == 'a'
            else:
                s[0] = chr(ord(s[0]) + 1)
else:
    while i < len(s):
        while s[i] != 'a' and c < K:
            c += 1
            if s[i] == 'z':
                s[i] = 'a'
                break
            s[i] = chr(ord(s[i])+1)
        i += 1
        while i != len(s)-1 and i < len(s) and (K-c) < ((ord('a') - ord(s[i]))%26):
            i += 1

print s

Submission status: Wrong Answer

Solution code:
s=[c for c in raw_input()]
K=int(raw_input())

i=0
c=0

if len(s) == 1:
    n = 1 + K / 26
    for i in xrange(n):
        while c < K:
            c += 1
            s[0] = chr(ord(s[0]) + 1)
else:
    while i < len(s):
        while s[i] != 'a' and c < K:
            c += 1
            if s[i] == 'z':
                s[i] = 'a'
                break
            s[i] = chr(ord(s[i])+1)
        i += 1
        while i != len(s)-1 and i < len(s) and (K-c) < ((ord('a') - ord(s[i]))%26):
            i += 1

print s

Submission status: Wrong Answer

Solution code:
def next_letter(target_string, character_position, last_K):
    """
    与えられた文字列のcharacter_position番目（ただし0からはじまる）の文字をnumber個進める
    """
    number = last_K % 26
    letter = target_string[character_position]
    letter_askii = ord(letter)
    next_letter = chr(letter_askii + number)
    return next_letter

target_string = input()
K = int(input())

#まずはaにできないところまで左からaにしていく
result_string = ""
for i, letter in enumerate(target_string):
    next_letter_num_to_a = (ord("z") - ord(letter) + 1) % 26
    if next_letter_num_to_a > K:
        result_string += letter
    else:
        result_string += "a"
        K -= next_letter_num_to_a

# 最後に最下位をすすめる
if K == 0:
    print (result_string)
else:
    last_character_pos = len(target_string) - 1
    result_string = result_string[:last_character_pos] + next_letter(target_string, last_character_pos, K)
    print (result_string)

Submission status: Wrong Answer

Solution code:
#C-Next Letter
str = input()
K = int(input())
tempK = K
result = ""
for i in range(len(str)-1):
	changeNum = 122-ord(str[i])+1
	if (changeNum <= tempK):
		result += "a"
		tempK -= changeNum
	else:
		result += str[i]
tempK %= 26
if (tempK != 0):
	changeNum = ord(str[-1]) + tempK
	if (changeNum > 122):
		changeNum = changeNum -122 + 97 -1
	result += chr(changeNum)
else:
	result += str[-1]
print(result)

Submission status: Wrong Answer

Solution code:
s=[c for c in raw_input()]
K=int(raw_input())

i=0
c=0

if len(s) == 1:
    n = 1 + K / 26
    for i in xrange(n):
        while c < K:
            c += 1
            s[0] = chr(ord(s[0]) + 1)
else:
    while i < len(s):
        while s[i] != 'a' and c < K:
            c += 1
            if s[i] == 'z':
                s[i] = 'a'
                break
            s[i] = chr(ord(s[i])+1)
        i += 1
        while i < len(s) and (K-c) < ((ord('a') - ord(s[i]))%26):
            i += 1

print s

Submission status: Wrong Answer

Solution code:
import string


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

db = {}
scoredb = {}
for i in range(len(string.ascii_lowercase)-1):
    db[string.ascii_lowercase[i]] = string.ascii_lowercase[i+1]
    scoredb[string.ascii_lowercase[i]] = 26-i
db["z"] = "a"
scoredb["z"] = 1

def gotscore ( kwd ):
    score = 0
    max = len(kwd)
    for i in range(len(kwd)):
        score += scoredb[kwd[i]] * (100 * ( max - i  ))
    return score

def rot ( kwd, i ):
    if len(kwd) == 1:
        return db[kwd[i]]
    if len(kwd) == i:
        return kwd[:i] + db[kwd[i]]

    return kwd[:i] + db[kwd[i]] + kwd[i+1:]

def check(kwd, nokori):
    front = "".join(["a" for i in range(len(kwd))])
    # 単純検索
    for i in range(len(kwd)):
        if scoredb[kwd[i]] <= nokori:
            nokori -= scoredb[kwd[i]]
            kwd = kwd[:i] + "a" + kwd[i+1:]

    # 詳細検索
    while nokori > 0:

        kwd = rot(kwd,len(kwd)-1)
        nokori -= 1

    return kwd
print(check(s,K))

Submission status: Wrong Answer

Solution code:
#C-Next Letter
str = input()
K = int(input())
tempK = K
result = ""
for i in range(len(str)-1):
	changeNum = 122-ord(str[i])+1
	if (changeNum <= tempK):
		result += "a"
		tempK -= changeNum
	else:
		result += str[i]
tempK %= 26
if (tempK != 0):
	changeNum = ord(str[-1]) + tempK
	if (changeNum > 122):
		changeNum = changeNum -122 + 97 -1
	result += chr(changeNum)
else:
	result += str[-1]
print(result)

Submission status: Wrong Answer

Solution code:
def f(s,K):
 if K==0:
  return s,"",0
 res=0
 str=""
 for i in range(len(s)):
  if s[i]=="a":
   str+="a"
   res+=1
   continue
  if K>=123-ord(s[i]):
   str+="a"
   res+=1
   K-=123-ord(s[i])
  else:
   break
 if res==0:
  skip=0
  for skip in range(len(s)):
   if K>=123-ord(s[skip]):
    break
  return s[:skip],s[skip:],K
 return str,s[res:],K

ss=input()
KK=int(input())
sol=""
while len(ss)>1:
 x,ss,KK=f(ss,KK)
 sol+=x
if len(ss)==1:
 KK%=26
 if ord(ss[0])+KK<123:
  sol+=chr(ord(ss[0])+KK)
 else:
  sol+=chr(ord(ss[0])+KK-26)
print(sol)

Submission status: Wrong Answer

Solution code:
s=[c for c in raw_input()]
K=int(raw_input())

i=0
c=0

while i < len(s):
    while s[i] != 'a' and c <= K:
        c += 1
        if s[i] == 'z':
            s[i] = 'a'
            break
        s[i] = chr(ord(s[i])+1)
    i += 1
    while i < len(s) and (K-c) < ((ord('a') - ord(s[i]))%26):
        i += 1

print s

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
string = list(raw_input().rstrip())
K = int(raw_input().rstrip())

ref = [(string[x], x) for x in xrange(len(string))]
ref.sort()
#ref.reverse()

# increase to A
i = 0
while (i < len(string)) and (K > 0):
    if (ord(string[ref[i][1]]) + K > ord('z')):
        K -= ord('z') - ord(string[ref[i][1]]) + 1
        string[ref[i][1]] = 'a'
        #print string, K
    i += 1

# increase least
ref = [(string[x], x) for x in xrange(len(string))]
ref.sort()
i = 0
while (K > 0):
    string[ref[i][1]] = chr(((ord(string[ref[i][1]]) + 1 - ord('a')) % 26) + ord('a'))
    K -= 1
    i += 1
    i %= len(string)

print ''.join(string)

Submission status: Wrong Answer

Solution code:
s = input()
N = int(input())
gap_list =[]
for c in s:
	gap_list.append(26 - ord(c) + ord('a'))
for i in range(len(gap_list)):
	if N - gap_list[i] >= 0:
		N -= gap_list[i]
		gap_list[i] = 26
	if i == len(gap_list)-1 and N != 0:
		gap_list[i] -= N
		if gap_list[i] < 0:
			N = abs(gap_list[i])
			while N > 0:
				gap_list[i -1] -= N
				if gap_list[i] < 0:
					N = abs(gap_list[i - 1])
					i -= 1
	if N == 0:
		break
res = ''
for i in range(len(gap_list)):
	res += chr(26 - gap_list[i] + ord('a'))
print(res)

Submission status: Wrong Answer

Solution code:
#C-Next Letter
str = input()
K = int(input())
tempK = K
result = ""
for i in range(len(str)):
	changeNum = 122-ord(str[i])+1
	if (changeNum <= tempK):
		result += "a"
		tempK -= changeNum
	else:
		result += str[i]
if (tempK != 0):
	tempK %= 26
	changeNum = ord(str[-1]) + tempK
	if (changeNum > 122):
		changeNum = changeNum -122 + 97 -1
	result = result[:-1] + chr(changeNum)
print(result)

Submission status: Wrong Answer

Solution code:
s = input()
N = int(input())
gap_list =[]
for c in s:
	gap_list.append(26 - ord(c) + ord('a'))
for i in range(len(gap_list)):
	if N - gap_list[i] >= 0:
		N -= gap_list[i]
		gap_list[i] = 26
	if i == len(gap_list)-1 and N != 0:
		gap_list[i] -= N
		if gap_list[i] < 0:
			gap_list = 26 + gap_list[i]
	if N == 0:
		break
res = ''
for i in range(len(gap_list)):
	res += chr(26 - gap_list[i] + ord('a'))
print(res)

Submission status: Wrong Answer

Solution code:
#C-Next Letter
str = input()
K = int(input())
tempK = K
result = ""
for i in range(len(str)):
	changeNum = 122-ord(str[i])+1
	if (changeNum <= tempK):
		result += "a"
		tempK -= changeNum
	else:
		result += str[i]
if (tempK != 0):
	tempK %= 26
	changeNum = ord(str[-1]) + tempK
	if (changeNum > 122):
		changeNum = 122 - changeNum + 97 -1
	result = result[:-1] + chr(changeNum)
print(result)

Submission status: Wrong Answer

Solution code:
def num_to_char(s_num):
    ch = []
    for num in s_num:
        ch.append(alphabet[(num%26)-1])
    return ch

s = raw_input()
K = input()

alphabet = ['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']
ans = []

s_num = []
for char in s:
    s_num.append(alphabet.index(char) + 1)

for i in xrange(len(s_num)):
    if 27 - s_num[i] < K and (s_num[i] != 1) and (i != len(s_num) - 1):
        K = K - (27 - s_num[i])
        s_num[i] = 27
    elif 27 - s_num[i] < K and (s_num[i] == 1) and (i != len(s_num) - 1):
        pass
    elif 27 - s_num[i] >= K and (s_num[i] != 1) and (i != len(s_num)-1):
        pass
    elif 27 - s_num[i] >= K and (s_num[i] == 1) and (i != len(s_num) - 1):
        pass

    elif (i == len(s_num) - 1):
        s_num[i] = s_num[i] + K

print "".join(num_to_char(s_num))

Submission status: Wrong Answer

Solution code:

in_str = input()

c_l = []
for c in in_str:
    
    c_l.append(c)

steps = int(input())

#result = []
i = 0
for c in range(0, len(c_l)):
    if i + 1 == len(c_l):
        c_l[c] = chr(((ord(c_l[c]) + steps) - ord('a')) % 26 + ord('a'))
    if ord(c_l[c]) - ord('a') - 26 + steps < 0:
        i += 1
        continue
    steps += ord(c_l[c]) - ord('a') - 26
    c_l[c] = 'a'
    #result.append('a')
    i += 1

print (''.join(c_l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
ring = raw_input()
num = input()

str = []
for i in range(len(ring)):
  str.append(ring[i])

for i in range(len(str)):
  if num-1 >= ord("z")-ord(str[i]):
    num =  num - (ord("z")-ord(str[i])+1)
    str[i] = "a"

num = num % 26
while(num > 0):
  if str[-1] == "z":
    num -= 1
    str[-1] = "a"
    continue
  str[-1] = chr(ord(str[-1])+1)
  num -= 1

ans = ""
for i in str:
  ans += i
print ans

Submission status: Wrong Answer

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()


s = input()
K = int(input())
l = len(s)
ans = ['a']*l

ORDa = 97

for i in range(l):
	now = ord(s[i]) - ORDa
	tmp = 26 - now
	
	if K == 0:
		ans[i] = s[i]
	elif tmp <= K:
		ans[i] = 'a'
		K -= tmp
	else:
		ans[i] = s[i]

if K > 0:
	K = K % 26
	tmp = ord(ans[-1])
	if tmp + K > ord('z'):
		aa = tmp + K - ord('z') - 1
		ans[-1] = chr(aa + ORDa)
	else:
		ans[-1] = chr(tmp + K)
		
print("".join(ans))
# last shori

Submission status: Wrong Answer

Solution code:
#C-Next Letter
str = input()
K = int(input())
tempK = K
result = ""
for i in range(len(str)):
	changeNum = 122-ord(str[i])+1
	if (changeNum <= tempK):
		result += "a"
		tempK -= changeNum
	else:
		result += str[i]
if (tempK != 0):
	tempK %= 26
	result = result[:-1] + chr(ord(str[-1]) + tempK)
print(result)

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
for i, c in enumerate(s[:-1]):
    if K >= (123-ord(c)):
        print ('a',end="")
        K-=(123-ord(c))
    else:
        print (c,end="")
print (chr((ord(s[-1])+K-97) %26+97),end="")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
jisho = ["z","y","x","w","v","u","t","s","r","q","p","o","n","m","l","k","j","i","h","g","f","e","d","c","b","a"]

s = list(input())
n = len(s)
k =int(input())
cou = 0
res = ""

for elem in s:
    if jisho.index(elem)+1 <= k:
        res += "a"
        k -= jisho.index(elem)+1
    else:
        res += elem

res = res[0:n-1] + jisho[jisho.index(res[n-1])-k%26]
print(res)

Submission status: Wrong Answer

Solution code:
def f(s,K):
 if len(s)==1:
  K%=26
  if ord(s[0])+K<123:
   return chr(ord(s[0])+K)
  else:
   return chr(ord(s[0])+K-26)
 res=0
 for i in range(len(s)):
  if s[i]=="a":
   continue
  if K>=123-ord(s[i]):
   res+=1
   K-=123-ord(s[i])
  else:
   break
 str=""
 for i in range(res):
  str+="a"
 if res==0:
  for i in range(len(s)):
   if K>=123-ord(s[i]):
    break
  return s[:i]+f(s[i:],K)
 return str+f(s[res:],K)
ss=input()
KK=int(input())
print(f(ss,KK))

Submission status: Wrong Answer

Solution code:
def num_to_char(s_num):
    ch = []
    for num in s_num:
        ch.append(alphabet[(num%26)-1])
    return ch

s = raw_input()
K = input()

alphabet = ['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']
ans = []

s_num = []
for char in s:
    s_num.append(alphabet.index(char) + 1)

for i in xrange(len(s_num)):
    if 27 - s_num[i] < K and (s_num[i] != 1) and (i != len(s_num) - 1):
        K = K - (27 - s_num[i])
        s_num[i] = 27

    elif 27 - s_num[i] < K and (s_num[i] != 1) and (i == len(s_num) - 1):
        s_num[i] = s_num[i] + K

    elif 27 - s_num[i] < K and (s_num[i] == 1) and (i != len(s_num) - 1):
        pass

    elif 27 - s_num[i] < K and (s_num[i] == 1) and (i == len(s_num) - 1):
        s_num[i] = s_num[i] + K


    elif 27 - s_num[i] >= K and (s_num[i] != 1) and (i != len(s_num)-1):
        pass

    elif 27 - s_num[i] >= K and (s_num[i] != 1) and (i == len(s_num)-1):
        s_num[i] = s_num[i] + K

    elif 27 - s_num[i] >= K and (s_num[i] == 1) and (i != len(s_num) - 1):
        pass

    elif 27 - s_num[i] >= K and (s_num[i] == 1) and (i == len(s_num) - 1):
        s_num[i] = s_num[i] + K

    #elif i == len(s_num) - 1:
       # s_num[i] = s_num[i] + K

print "".join(num_to_char(s_num))

Submission status: Wrong Answer

Solution code:
s = list(raw_input())
K = input()
for i in xrange(len(s)):
    if 123-ord(s[i]) <= K:
        K-=123-ord(s[i])
        s[i] = 'a'
if K > 0:
    s[-1] = chr((ord(s[-1])%97+K%26)%26+97)
print ''.join(s)

Submission status: Wrong Answer

Solution code:
s=raw_input()
K=input()
s=list(s)
#a-z 97-122
for i in xrange(len(s)):
    if s[i]=='a':
        continue
    if ord(s[i])+K < 123:
        continue
    else:
        K-=(123-ord(s[i]))
        s[i]='a'
if K>0:
    asc=ord(s[-1])+K
    s[-1]=chr(asc)
print "".join(s)

Submission status: Wrong Answer

Solution code:
s=input()
list=[]
k=int(input())
while k!=0:
    for i in range(len(s)):
        if (ord(s[i])+k)>122:
            list.append('a')
            k=k-(123-ord(s[i]))
        else:
            list.append(s[i])
for i in range(len(s)):
    print(list[i], end='')