// ayy // ' lamo #include #include using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; //CARE typedef complex pt; #define fi first #define se second #define pb push_back const ld eps=1e-8; const int inf=1e9+99; const ll linf=1e18+99; // const int P=1e9+7; // should bound count_{m,n}, N_m int powq(int x,int e,int P) { if(!e) return 1; if(e&1) return int(1LL*powq(x,e-1,P)*x%P); x=powq(x,e>>1,P); return int(1LL*x*x%P); } pair > > prime_REF(vector > A,int P) { int m=(int)A.size(); assert(m); int n=(int)A[0].size(); assert(n); int r=0; for(int i=0;i > molecules; vector elts; for(;;) { int sgn; cin>>sgn; if(!sgn) { assert(cin>>sgn); assert(!(cin>>sgn)); break; } assert(abs(sgn)==1); int N; cin>>N; // todo should bound N itself. map molecule; for(;N--;) { string elt; int cnt; cin>>elt>>cnt; // todo should specify elementt is latin letters // todo should bound cnt assert(elt.size()<=2u); assert(1<=cnt && cnt<=12); molecule[elt] += sgn*cnt; elts.pb(elt); } molecules.pb(molecule); } sort(elts.begin(),elts.end()); elts.resize(unique(elts.begin(),elts.end())-elts.begin()); int m=(int)elts.size(); int n=(int)molecules.size(); assert(n<=10); vector > A(m,vector(n,0)); for(int j=0;j Z; for(int cm=1;cm<=1000;cm++) { vector c(n,0); c.back()=cm; for(int i=n-2;i>=0;i--) { for(int j=0;j1000) good=0; if(!good) continue; for(int i=0;i