1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
#define W = 1

int main() {
	int a,b,*tab,k=0;
	cin>>a;
	tab = new int [a];
	for(int i=0;i<a;i++) cin>>tab[i];
	cin>>b;
	char c[b+2];
	short int d[b+2];
	cin>>c;
	for(int i=0;i<b;i++) d[i]=(c[i]%10-1)/3-1;
	while(1==1) {
		tab[k%a]+=d[k%b];
		if(tab[k%a]==0) break;
		k++;
	}
	cout<<k+1;
	return 0;
}