#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
long long start_time;
void start_clock(){
struct timeval tv;
gettimeofday(&tv, NULL);
start_time=(tv.tv_sec*1000000+tv.tv_usec);
}
long long current_clock(){
struct timeval tv;
gettimeofday(&tv, NULL);
long long current_time=(tv.tv_sec*1000000+tv.tv_usec);
// cout << current_time-start_time << "(us)\n";
return current_time-start_time;
}
unsigned long long xor128(){
static unsigned long long x=123456789,y=362436069,z=521288629,w=88675123;
unsigned long long t;
t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
using pl=pair<long long,long long>;
using Graph=vector<vector<pl>>;
vector<long long> dis(long long v,long long n,Graph &g){
vector<long long> d(n,8e18);
queue<long long> q;
q.push(v);
d[v]=0;
while(!q.empty()){
long long od=q.front();q.pop();
for(auto &nx : g[od]){
if(d[nx.first]>4e18){
d[nx.first]=d[od]+nx.second;
q.push(nx.first);
}
}
}
return d;
}
int main(){
start_clock();
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long n;
cin >> n;
Graph g1(n);
Graph g2(n);
Graph g3(n);
for(long long i=1;i<n;i++){
long long u,v,w;
cin >> u >> v >> w;
u--;v--;
g1[u].push_back({v,w});
g1[v].push_back({u,w});
}
for(long long i=1;i<n;i++){
long long u,v,w;
cin >> u >> v >> w;
u--;v--;
g2[u].push_back({v,w});
g2[v].push_back({u,w});
}
for(long long i=1;i<n;i++){
long long u,v,w;
cin >> u >> v >> w;
u--;v--;
g3[u].push_back({v,w});
g3[v].push_back({u,w});
}
set<long long> st;
vector<long long> lis;
for(long long i=0;i<n;i++){lis.push_back(i);}
long long res=0;
long long ct=1;
long long knd=start_time%2;
while(st.size()<n){
if(current_clock()>1900000){break;}
long long u;
while(true){
swap(lis[xor128()%lis.size()],lis[lis.size()-1]);
u=lis.back();
lis.pop_back();
if(st.find(u)==st.end()){break;}
}
if(knd==0){
ct++;
if(ct==8){ct=1;}
}
while(true){
if(current_clock()>1900000){break;}
st.insert(u);
vector<long long> d1=dis(u,n,g1);
vector<long long> d2=dis(u,n,g2);
vector<long long> d3=dis(u,n,g3);
long long v=0,f=0;
if(knd==1){ct=1+(xor128()%7);}
for(long long i=0;i<n;i++){
long long cr=d1[i]+d2[i]+d3[i];
long long cf=0;
if(ct&1ll){cf+=d1[i];}
if(ct&2ll){cf+=d2[i];}
if(ct&4ll){cf+=d3[i];}
res=max(res,cr);
if(f<cf){
v=i;
f=cf;
}
}
if(st.find(v)!=st.end()){break;}
u=v;
}
}
cout << res << "\n";
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxzeXMvdGltZS5oPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmxvbmcgbG9uZyBzdGFydF90aW1lOwoKdm9pZCBzdGFydF9jbG9jaygpewogIHN0cnVjdCB0aW1ldmFsIHR2OwogIGdldHRpbWVvZmRheSgmdHYsIE5VTEwpOwogIHN0YXJ0X3RpbWU9KHR2LnR2X3NlYyoxMDAwMDAwK3R2LnR2X3VzZWMpOwp9Cgpsb25nIGxvbmcgY3VycmVudF9jbG9jaygpewogIHN0cnVjdCB0aW1ldmFsIHR2OwogIGdldHRpbWVvZmRheSgmdHYsIE5VTEwpOwogIGxvbmcgbG9uZyBjdXJyZW50X3RpbWU9KHR2LnR2X3NlYyoxMDAwMDAwK3R2LnR2X3VzZWMpOwogIC8vIGNvdXQgPDwgY3VycmVudF90aW1lLXN0YXJ0X3RpbWUgPDwgIih1cylcbiI7CiAgcmV0dXJuIGN1cnJlbnRfdGltZS1zdGFydF90aW1lOwp9Cgp1bnNpZ25lZCBsb25nIGxvbmcgeG9yMTI4KCl7CiAgc3RhdGljIHVuc2lnbmVkIGxvbmcgbG9uZyB4PTEyMzQ1Njc4OSx5PTM2MjQzNjA2OSx6PTUyMTI4ODYyOSx3PTg4Njc1MTIzOwogIHVuc2lnbmVkIGxvbmcgbG9uZyB0OwogIHQ9KHheKHg8PDExKSk7eD15O3k9ejt6P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ik7CiAgICAgIHZlY3Rvcjxsb25nIGxvbmc+IGQzPWRpcyh1LG4sZzMpOwogICAgICBsb25nIGxvbmcgdj0wLGY9MDsKICAgICAgaWYoa25kPT0xKXtjdD0xKyh4b3IxMjgoKSU3KTt9CiAgICAgIGZvcihsb25nIGxvbmcgaT0wO2k8bjtpKyspewogICAgICAgIGxvbmcgbG9uZyBjcj1kMVtpXStkMltpXStkM1tpXTsKICAgICAgICBsb25nIGxvbmcgY2Y9MDsKICAgICAgICBpZihjdCYxbGwpe2NmKz1kMVtpXTt9CiAgICAgICAgaWYoY3QmMmxsKXtjZis9ZDJbaV07fQogICAgICAgIGlmKGN0JjRsbCl7Y2YrPWQzW2ldO30KICAgICAgICByZXM9bWF4KHJlcyxjcik7CiAgICAgICAgaWYoZjxjZil7CiAgICAgICAgICB2PWk7CiAgICAgICAgICBmPWNmOwogICAgICAgIH0KICAgICAgfQogICAgICBpZihzdC5maW5kKHYpIT1zdC5lbmQoKSl7YnJlYWs7fQogICAgICB1PXY7CiAgICB9CiAgfQogIGNvdXQgPDwgcmVzIDw8ICJcbiI7CiAgcmV0dXJuIDA7Cn0=