P8584探索未知
#include<bits/stdc++.h>
using namespace std;
long long f[3]={0,1,-1};
long long n,t,fz,fm,s;
int gbs(int x,int y)
{
for(long long i=max(x,y);i<=x*y;i++)
{
if(i%x==0&&i%y==0)
{
return(i);
}
}
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
long long a,b;
cin>>a>>b>>t;
if(i==1)
{
fm=b;
fz=f[t]*a;
}
else
{
fz=fz*gbs(fm,b)/fm+f[t]*a*gbs(fm,b)/b;
fm=gbs(b,fm);
}
}
if(fz%fm==0)
cout<<fz/fm;
else
cout<<fz<<'/'<<fm;
}