#include<cstdio> #include<string> #include<cstring> #include<iostream> #include<algorithm> #define M 16 using namespace std; int n,mx; int c[M],p[M],l[M]; int Exgcd(int a,int b,int &x,int &y){ if(!b){ x=1,y=0; return a; } int d=Exgcd(b,a%b,y,x); y-=a/b*x; return d; } bool Check(int x){ for(int i=1;i<=n;i++) for(int j=1+i;j<=n;j++){ int a=p[i]-p[j]; int b=x; int s=c[j]-c[i]; int x,y; int d=Exgcd(a,b,x,y); if(s%d) continue; a/=d,b/=d,s/=d; if(b<0) b=-b; x=(x*s%b+b)%b; if(x<=l[i]&&x<=l[j]) return false; } return true; } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d%d",&c[i],&p[i],&l[i]); mx=max(mx,c[i]); } for(int i=mx;;i++) if(Check(i)){ printf("%d\n",i); return 0; } return 0; }