#include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; cin>>n; string g[n+1]; int h[n]; vectorv; for(int i=0;i>g[i]; } for(int i=0;i>h[i]; int q; cin>>q; for(int i=0;i>start>>end>>s; int temp=0; for(int j=start;j<=end;j++) { string str=""; str=str+g[j]; int pos=s.find(str); if(pos!=string::npos) { temp=temp+h[j]; // int l=str.length(); //s.erase(s.begin()+pos); while(pos!=string::npos) { pos=s.find(str,pos+1); if(pos!=string::npos) temp=temp+h[j]; } } v.push_back(temp); str=""; } } sort(v.begin(),v.end()); int x=v.size(); cout<