#include #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 max=0,min=1000000000; for(int a0 = 0; a0 < s; a0++){ int first; int last; string d; long long int val=0; cin >> first >> last >> d; for(int i=first;i<=last;i++){ if (d.find(genes[i]) != std::string::npos) { val+=health[i]; } } if(val>max) max=val; else if(val