#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
inline int sho(P p){
	int x=p.fs,y=p.sc;
	if(x>0&&y>=0) return 0;
	if(x<=0&&y>0) return 1;
	if(x<0&&y<=0) return 2;
	if(x>=0&&y<0) return 3;
	assert(false);
}
bool comp(const PP& pp,const PP& qq){
	P p=pp.fs,q=qq.fs;
	int s=sho(p),t=sho(q);
	if(s!=t) return s<t;
	ll a=p.fs,b=p.sc,c=q.fs,d=q.sc;
	return b*c<a*d;
}
int gcd(int x,int y){
	if(y==0) return abs(x);
	return gcd(y,x%y);
}
ll cro(P a,P b){
	return a.fs*b.sc-a.sc*b.fs;
}
inline P inv(P p){
	return P(-p.fs,-p.sc);
}
map<P,ll> mp;
vector<PP> vc;
ll inf=1e10;
ll solve(){
	ll ans=inf;
	int N=vc.size();
	{
		int j=1;
		ll mn=inf;
		while(j<N&&cro(vc[0].fs,vc[j].fs)>0) j++;
		int J=j;
		if(j<N&&cro(vc[0].fs,vc[j].fs)>=0) j++;
		j--;
//		show(J);
//		show(j);
		for(int i=1;i<J;i++){
			while(j<N-1&&cro(vc[i].fs,vc[j+1].fs)>0){
				chmin(mn,vc[j+1].sc);
				j++;
			}
			chmin(ans,vc[0].sc+vc[i].sc+mn);
		}
	}
	if(mp.count(inv(vc[0].fs))){
		for(int j=1;;j++){
			if(vc[j].fs==inv(vc[0].fs)) break;
			if(mp.count(inv(vc[j].fs))){
				chmin(ans,vc[0].sc+mp[inv(vc[0].fs)]+vc[j].sc+mp[inv(vc[j].fs)]);
			}
		}
	}
	return ans;
}
int main(){
	int N;
	cin>>N;
	ll mnc=inf;
	rep(i,N){
		ll a,b,c;
		cin>>a>>b>>c;
		if(a==0&&b==0) continue;
		int g=gcd(a,b);
		a/=g,b/=g;
		if(!mp.count(P(a,b))||mp[P(a,b)]>c){
			mp[P(a,b)]=c;
		}
		chmin(mnc,c);
	}
	for(auto pp:mp) vc.pb(PP(pp.fs,pp.sc));
	sort(all(vc),comp);
	N=vc.size();
	if(N<=2){
		puts("-1");
		return 0;
	}
	int id=-1;
	rep(i,N) if(vc[i].sc==mnc) id=i;
	rotate(vc.begin(),vc.begin()+id,vc.end());
//	rep(i,N) cout<<"("<<vc[i].fs.fs<<","<<vc[i].fs.sc<<")  "<<vc[i].sc<<endl;
	ll ans=inf;
	chmin(ans,solve());
	id=-1;
	ll mn=inf;
	rep1(i,N-1){
		if(mn>vc[i].sc) id=i,mn=vc[i].sc;
	}
	rotate(vc.begin(),vc.begin()+id,vc.end());
	chmin(ans,solve());
	if(ans==inf) ans=-1;
	cout<<ans<<endl;
}