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

Solution in JavaScript (node.js v5.12) (judge verdict: Wrong Answer)

'use strict';
const inputs = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const CODE_A = 97;
let s = inputs[0];
let K = parseInt(inputs[1]);
let cur = 0;
let result = '';
let lastFailedCur = -1;
let lastFailedCode = -1;

while (cur < s.length) {
	let distance = 26 - (s.charCodeAt(cur) - CODE_A);
	
	if (distance === 26) {
		result += 'a';

	} else if (distance <= K) {
		K -= distance;
		result += 'a';
	} else {
		lastFailedCur = cur;
		lastFailedCode = s.charCodeAt(cur);
		result += s[cur];
	}
	
	cur++;
	
}

if (K > 0) {
	K = K % 26;

	if (lastFailedCode === -1) {
		lastFailedCur = s.length - 1;
		lastFailedCode = s.charCodeAt(s.length - 1);
	}
	
	result = result.substr(0, lastFailedCur) +
		String.fromCharCode(CODE_A + (lastFailedCode + K - CODE_A + 1) % 26) +
		result.substr(lastFailedCur + 1);
}

console.log(result);