#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int (i)=0; (i)<(n) ;++(i)) #define REPN(i,a,n) FOR((i),(a),(a)+(n)) #define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i)) #define PB push_back #define MP make_pair #define SE second #define FI first #define DBG(a) cerr<<(a)< PLL; typedef vector VLL; typedef pairPI; typedef vector VI; const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7; PLL add(PLL a, PLL b){ LL den=a.SE*b.SE; LL num=a.FI*b.SE+a.SE*b.FI; LL g=__gcd(den,num); return MP(num/g,den/g); } bool comp(PLL a, PLL b){ REP(i,5){ b.FI-=(b.SE/a.SE)*a.FI; b.SE-=(b.SE/a.SE)*a.SE; if(b.FI<=0) return false; if(b.SE==0) return true; a.FI-=(a.SE/b.SE)*b.FI; a.SE-=(a.SE/b.SE)*b.SE; if(a.FI<=0) return true; if(a.SE==0) return false; } return a.FI*b.SE a, pair b){ return comp(a.FI,b.FI) ;//or (a.FI==b.FI and comp(a.SE,b.SE)); } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector> l(3); vector sum,mi; REP(i,n){ LL a,b,c; cin >> a >>b >> c; LL g=__gcd(b,c); l[a].emplace_back(b/g,(b+c)/g); } REP(i,3)l[i].emplace_back(1,1); REP(i,l[0].size()){ REP(j,l[1].size()){ PLL t; //cout<