#include #include #include #include #include #include using namespace std; int main() { int n; cin>>n; vector g(n); vector h(n); unordered_map > m; cin>>g[0]; int gmax=g[0].size(); for (int i=1; i>g[i]; if (g[i].size()>gmax){ gmax=g[i].size(); } if (m.find(g[i])==m.end()){ vector vg(1,i); m[g[i]]=vg; } else { m[g[i]].push_back(i); } } for (int i=0; i>h[i]; } int s; cin>>s; int minh, maxh; if (true){ int f, l; string st; cin>>f>>l>>st; int z=st.size(); int hval=0; for (int j=0; j=0 && (j-k) vt=m[t]; //ampersand int mz=vt.size(); for (int ind=0; ind=f && vt[ind]<=l){ hval+=h[vt[ind]]; } } } } } minh=hval; maxh=hval; } for (int i=1; i>f>>l>>st; int z=st.size(); int hval=0; for (int j=0; j=0 && (j-k) vt=m[t]; //ampersand int mz=vt.size(); for (int ind=0; ind=f && vt[ind]<=l){ hval+=h[vt[ind]]; } } } } } if (hval>maxh){ maxh=hval; } if (hval