#include <bits/stdc++.h>

using namespace std;

int main(void) {
	int e;
	while(1) {
		cin >> e;
		if(e == 0) {
			break;
		}
		
		int tmpx, tmpy, tmpz, tmpe;
		tmpe = e;
		for(tmpz = 0; pow(tmpz, 3) <= tmpe; tmpz++){}
		tmpz--;
		tmpe = tmpe - pow(tmpz, 3);
		if(tmpe == 0){
			tmpy = 0; tmpx = 0;
		}else{
			for(tmpy = 0; pow(tmpy, 2) <= tmpe; tmpy++){}
			tmpy--;
			tmpe = tmpe - pow(tmpy, 2);
			if(tmpe == 0){
				tmpx = 0;
			}else{
				tmpx = tmpe;
			}
		}
		int tmpm = tmpx + tmpy + tmpz;
		//cout << tmpz << " ! " << endl;

		int tmp;
		for(int z = 0; z <= tmpz + 1; z++) {
			for(int y = tmpy; y <= min(tmpm - z, int(pow(e - pow(z, 3), 1.0 / 2.0))); y++) {
				int x = e - pow(y, 2) - pow(z, 3);
				tmp = x + y + z;
				if(tmp < tmpm) {
					tmpm = tmp;
				}
			}
		}

		cout << tmpm << endl;
	}
	return 0;
}
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include<cctype>
#include<cmath>

using namespace std;

string str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

char encode(char a,int k){
	int b;
	if(isupper(a))b=a-'A';
	else b=a-'a'+26;
	if(b-k>=0)return str[b-k];
	return str[52-abs(b-k)];
}

int main(void){
	
	int n;
	while(cin >> n,n){
		vector<int>k(n);
		for(int i=0;i<n;i++){
			cin >> k[i];
		}
		string s;
		cin >> s;
		for(int i=0;i<s.size();i++)s[i]=encode(s[i],k[i%n]);
		cout << s << endl;
	}
	
	return 0;
}