#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<long long> A(N), sumA(N+1, 0);
  long long mod_ = 1000000007;
  for (int i=0; i<N; i++){
    cin >> A.at(i);
    sumA.at(i+1) = sumA.at(i)+A.at(i);
    if (sumA.at(i+1) >= mod_) sumA.at(i+1) %= mod_;
  }
  
  long long ans = 0;
  long long sum_comp = 0;
  for (int i=0; i<N-1; i++){
    sum_comp = sumA.at(N) > sumA.at(i+1) ? sumA.at(N)-sumA.at(i+1) : sumA.at(N)+mod_-sumA.at(i+1);
    ans += A.at(i)*sum_comp;
    if (ans >= mod_) ans %= mod_;
  }
  
  cout << ans << endl;
}

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
	int n;
	string abc = "abcdefghijklmnopqrstuvwxyz";
	string abcc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string aa = abcc + abc + abcc + abc;
	int sz = aa.size();
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<int> k(n);
		for (int i = 0; i < n; i++) {
			cin >> k[i];
		}
		string s;
		cin >> s;
		int c = 0;
		for (int i = 0; i < s.size(); i++) {
			for (int j = sz - 1; j >= 0; j--) {
				if (aa[j] == s[i]) {
					cout << aa[j - k[c]];
					c++;
					c %= n;
					break;
				}
			}
		}
		cout << endl;
	}
	return 0;
}