#include using namespace std; int main(){ int n; cin >> n; vector genes(n); for(int genes_i = 0; genes_i < n; genes_i++){ cin >> genes[genes_i]; } vector health(n); for(int health_i = 0; health_i < n; health_i++){ cin >> health[health_i]; } int s; cin >> s; int min = 100000, max =0; for(int a0 = 0; a0 < s; a0++){ int first; int last; string d; cin >> first >> last >> d; // your code goes here int total = 0; for (int i=0; i < d.length();i++) { string temp ; //cout << d[i] << " " << endl; if ((d[i] == 'a')&&(d[i+1]=='a')) temp = "aa"; else temp = d[i]; for (int j = first; j<= last;j++) { //cout << d[i] << " " << genes[j] << endl; if(temp == genes[j]) total += health[j]; } } if (total < min) min = total; if (total > max) max = total; } cout << min << " " << max; return 0; }