stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define pb push_back

#define mp make_pair

#define SZ(x) ((int)(x).size())

#define all(x) x.begin(),x.end()

#define mem0(s) memset(s,0,sizeof(s))

#define meminf(s) memset(s,0x3f,sizeof(s))

#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))

double pi=acos(-1);

typedef long long ll;

typedef unsigned long long ull;

inline ll lowbit(ll x){return x&(-x);}

inline ll min(ll a,ll b){return a<b?a:b;}

inline ll max(ll a,ll b){return a>b?a:b;}

const int INF=0x3f3f3f3f,max_n=200005,mod=19260817;

inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

inline ll pow(ll a,ll b,ll mod){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

ll a[max_n],b[max_n];int x;

vector<int>v[max_n];

ll ans1;

int main()

{

	int n;cin>>n;

	for(int i=1;i<=n;i++)

	{

		cin>>x;

		a[i]=x+i;

		b[i]=i-x;

	}

	for(int i=1;i<=n;i++)

	{

		if(b[i]>=2&&b[i]<=199999)

		{

			v[b[i]].push_back(i);

		}

	}

	for(int i=1;i<=n;i++)

	{

		x=a[i];

		if(x>=2&&x<=199999)

		{

			if(v[x].size()!=0)

			{

				//¶þ·ÖµØÕÒµÚÒ»¸ö´óÓÚiµÄÊý×Ö

				int ll=upper_bound(v[x].begin(),v[x].end(),i)-v[x].begin();

				//cout<<ll<<endl;

				ans1+=v[x].size()-ll;

			}

		}

	}

	cout<<ans1<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.3831459688639764x):
#include <bits/stdc++.h>

using namespace std;

const long long N = 2e5+5 , M = 1e9+7, OO = 0x3f3f3f3f;

typedef long long ll;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);

const double Pii = 3.14159265359;

ll n;

ll a[N], d[N], fr[N];



int main()

{

    FIO

    cin >> n;

    for(int i=0; i<n; ++i)

    {

        cin >> a[i];

        d[i] = i-a[i];

    }

    for(int i=0; i<n; ++i)

        if(d[i] < N && d[i] >= 0) fr[d[i]]++;

    ll ans =0;

    for(int i=0; i<n; ++i)

    {

        int didx = a[i]+i;

        if(didx >= 0 && didx < N) ans += fr[didx];

        //cout << didx << " " << fr[didx] << endl;

    }

    cout << ans << endl;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define pb push_back

#define mp make_pair

#define SZ(x) ((int)(x).size())

#define all(x) x.begin(),x.end()

#define mem0(s) memset(s,0,sizeof(s))

#define meminf(s) memset(s,0x3f,sizeof(s))

#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))

double pi=acos(-1);

typedef long long ll;

typedef unsigned long long ull;

inline ll lowbit(ll x){return x&(-x);}

inline ll min(ll a,ll b){return a<b?a:b;}

inline ll max(ll a,ll b){return a>b?a:b;}

const int INF=0x3f3f3f3f,max_n=200005,mod=19260817;

inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

inline ll pow(ll a,ll b,ll mod){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

ll a[max_n],b[max_n];int x;

vector<int>v[max_n];

ll ans1;

int main()

{

	int n;cin>>n;

	for(int i=1;i<=n;i++)

	{

		cin>>x;

		a[i]=x+i;

		b[i]=i-x;

	}

	for(int i=1;i<=n;i++)

	{

		if(b[i]>=2&&b[i]<=199999)

		{

			v[b[i]].push_back(i);

		}

	}

	for(int i=1;i<=n;i++)

	{

		x=a[i];

		if(x>=2&&x<=199999)

		{

			if(v[x].size()!=0)

			{

				//¶þ·ÖµØÕÒµÚÒ»¸ö´óÓÚiµÄÊý×Ö

				int ll=upper_bound(v[x].begin(),v[x].end(),i)-v[x].begin();

				//cout<<ll<<endl;

				ans1+=v[x].size()-ll;

			}

		}

	}

	cout<<ans1<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.305986287322844x):
#include<bits/stdc++.h>

using namespace std;

int main()

{

	int n;

	long long int ans=0;

	cin>>n;

	long long int a[n];

	for(int i=0;i<n;i++)

	cin>>a[i];

    

    map<long long int,long long int> m1,m2;

    

    for(int i=0;i<n;i++)

    {

    m1[i+a[i]]++;

    m2[i-a[i]]++;

    }



    for(auto it:m1)

    {

    ans+=(it.second)*(m2[it.first]);

    }

    cout<<ans;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define pb push_back

#define mp make_pair

#define SZ(x) ((int)(x).size())

#define all(x) x.begin(),x.end()

#define mem0(s) memset(s,0,sizeof(s))

#define meminf(s) memset(s,0x3f,sizeof(s))

#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))

double pi=acos(-1);

typedef long long ll;

typedef unsigned long long ull;

inline ll lowbit(ll x){return x&(-x);}

inline ll min(ll a,ll b){return a<b?a:b;}

inline ll max(ll a,ll b){return a>b?a:b;}

const int INF=0x3f3f3f3f,max_n=200005,mod=19260817;

inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

inline ll pow(ll a,ll b,ll mod){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

ll a[max_n],b[max_n];int x;

vector<int>v[max_n];

ll ans1;

int main()

{

	int n;cin>>n;

	for(int i=1;i<=n;i++)

	{

		cin>>x;

		a[i]=x+i;

		b[i]=i-x;

	}

	for(int i=1;i<=n;i++)

	{

		if(b[i]>=2&&b[i]<=199999)

		{

			v[b[i]].push_back(i);

		}

	}

	for(int i=1;i<=n;i++)

	{

		x=a[i];

		if(x>=2&&x<=199999)

		{

			if(v[x].size()!=0)

			{

				//¶þ·ÖµØÕÒµÚÒ»¸ö´óÓÚiµÄÊý×Ö

				int ll=upper_bound(v[x].begin(),v[x].end(),i)-v[x].begin();

				//cout<<ll<<endl;

				ans1+=v[x].size()-ll;

			}

		}

	}

	cout<<ans1<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.444863354010022x):
#include<iostream>

#include<algorithm>

#define ll long long

using namespace std;

int a[200005],b[200005];

int main()

{

    int n;

    cin>>n;

    for(int i=0;i<n;i++)

        cin>>a[i];

    ll ans=0;

    for(int i=0;i<n;i++)

    {

        if(i+a[i]<=n)

            b[a[i]+i]++;

        if(i-a[i]>=0)

            ans+=b[i-a[i]];

    }

    cout<<ans<<endl;

    return 0;

}
// Slower C++ solution:
#include <cstring>

#include <iostream>

#include <vector>

#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

typedef long long int64;

int P[400000];

int M[200000];



int main() {

	memset(P, 0, sizeof(P));

	memset(P, 0, sizeof(M));

	int N;

	cin >> N;

	int tmp;

	int64 ans = 0;

	for (int i = 0; i < N; ++i) {

		cin >> tmp;

		if (tmp < 200000) {

			++P[i+tmp];

			if (i-tmp > 0) ++M[i-tmp];

		}

	}

	for (int i = 1; i < N; ++i) {

		ans += (int64)P[i] * M[i];

	}

	cout << ans << "\n";

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.5865261967765012x):
#include <cstring>

#include <iostream>

#include <vector>

#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

typedef long long int64;

int P[200000];

int M[200000];



int main() {

	memset(P, 0, sizeof(P));

	memset(P, 0, sizeof(M));

	int N;

	cin >> N;

	int tmp;

	int64 ans = 0;

	for (int i = 0; i < N; ++i) {

		cin >> tmp;

		if (i+tmp < 200000) ++P[i+tmp];

		if (i-tmp > 0) ++M[i-tmp];

	}

	for (int i = 1; i < N; ++i) {

		ans += (int64)P[i] * M[i];

	}

	cout << ans << "\n";

	return 0;

}
// Slower C++ solution:
#include <cstring>

#include <iostream>

#include <vector>

#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

typedef long long int64;

int P[400000];

int M[200000];



int main() {

	memset(P, 0, sizeof(P));

	memset(P, 0, sizeof(M));

	int N;

	cin >> N;

	int tmp;

	int64 ans = 0;

	for (int i = 0; i < N; ++i) {

		cin >> tmp;

		if (tmp < 200000) {

			++P[i+tmp];

			if (i-tmp > 0) ++M[i-tmp];

		}

	}

	for (int i = 1; i < N; ++i) {

		ans += (int64)P[i] * M[i];

	}

	cout << ans << "\n";

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.8056295391265134x):
#include <cstring>

#include <iostream>

#include <vector>

#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

typedef long long int64;

map<int, int> P;

map<int, int> M;



int main() {

	//memset(P, 0, sizeof(P));

	//memset(P, 0, sizeof(M));

	int N;

	cin >> N;

	int tmp;

	int64 ans = 0;

	for (int i = 0; i < N; ++i) {

		cin >> tmp;

		if (i+tmp < 200000) ++P[i+tmp];

		if (i-tmp > 0) ++M[i-tmp];

	}

	for (int i = 1; i < N; ++i) {

		ans += (int64)P[i] * M[i];

	}

	cout << ans << "\n";

	return 0;

}
// Slower C++ solution:
#include <cstring>

#include <iostream>

#include <vector>

#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

typedef long long int64;

int P[200000];

int M[200000];



int main() {

	memset(P, 0, sizeof(P));

	memset(P, 0, sizeof(M));

	int N;

	cin >> N;

	int tmp;

	int64 ans = 0;

	for (int i = 0; i < N; ++i) {

		cin >> tmp;

		if (i+tmp < 200000) ++P[i+tmp];

		if (i-tmp > 0) ++M[i-tmp];

	}

	for (int i = 1; i < N; ++i) {

		ans += (int64)P[i] * M[i];

	}

	cout << ans << "\n";

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.768410471145691x):
#include <cstring>

#include <iostream>

#include <vector>

#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

typedef long long int64;

map<int, int> P;

map<int, int> M;



int main() {

	//memset(P, 0, sizeof(P));

	//memset(P, 0, sizeof(M));

	int N;

	cin >> N;

	int tmp;

	int64 ans = 0;

	for (int i = 0; i < N; ++i) {

		cin >> tmp;

		if (i+tmp < 200000) ++P[i+tmp];

		if (i-tmp > 0) ++M[i-tmp];

	}

	for (int i = 1; i < N; ++i) {

		ans += (int64)P[i] * M[i];

	}

	cout << ans << "\n";

	return 0;

}
// Slower C++ solution:
#include <cstring>

#include <iostream>

#include <vector>

#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

typedef long long int64;

int P[400000];

int M[200000];



int main() {

	memset(P, 0, sizeof(P));

	memset(P, 0, sizeof(M));

	int N;

	cin >> N;

	int tmp;

	int64 ans = 0;

	for (int i = 0; i < N; ++i) {

		cin >> tmp;

		if (tmp < 200000) {

			++P[i+tmp];

			if (i-tmp > 0) ++M[i-tmp];

		}

	}

	for (int i = 1; i < N; ++i) {

		ans += (int64)P[i] * M[i];

	}

	cout << ans << "\n";

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.8520896765533275x):
#include <cstring>

#include <iostream>

#include <vector>

#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

typedef long long int64;

int P[200000] = {0,};

int M[200000] = {0,};



int main() {

	//memset(P, 0, sizeof(P));

	//memset(P, 0, sizeof(M));

	int N;

	cin >> N;

	int tmp;

	int64 ans = 0;

	for (int i = 0; i < N; ++i) {

		cin >> tmp;

		if (i+tmp < 200000) ++P[i+tmp];

		if (i-tmp > 0) ++M[i-tmp];

	}

	for (int i = 1; i < N; ++i) {

		ans += (int64)P[i] * M[i];

	}

	cout << ans << "\n";

	return 0;

}
// Slower C++ solution:
#include <cstring>

#include <iostream>

#include <vector>

#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

typedef long long int64;

int P[200000];

int M[200000];



int main() {

	memset(P, 0, sizeof(P));

	memset(P, 0, sizeof(M));

	int N;

	cin >> N;

	int tmp;

	int64 ans = 0;

	for (int i = 0; i < N; ++i) {

		cin >> tmp;

		if (i+tmp < 200000) ++P[i+tmp];

		if (i-tmp > 0) ++M[i-tmp];

	}

	for (int i = 1; i < N; ++i) {

		ans += (int64)P[i] * M[i];

	}

	cout << ans << "\n";

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.7976946629360389x):
#include <cstring>

#include <iostream>

#include <vector>

#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

typedef long long int64;

int P[200000] = {0,};

int M[200000] = {0,};



int main() {

	//memset(P, 0, sizeof(P));

	//memset(P, 0, sizeof(M));

	int N;

	cin >> N;

	int tmp;

	int64 ans = 0;

	for (int i = 0; i < N; ++i) {

		cin >> tmp;

		if (i+tmp < 200000) ++P[i+tmp];

		if (i-tmp > 0) ++M[i-tmp];

	}

	for (int i = 1; i < N; ++i) {

		ans += (int64)P[i] * M[i];

	}

	cout << ans << "\n";

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define N 5010

#define mod 1000000007

using namespace std;

ll jc[N],inv[N];

ll K(ll x,int y=mod-2){

	ll t=1; for (;y;y>>=1,x=x*x%mod) if (y&1) t=t*x%mod; return t;

}

ll C(int x,int y){

	return jc[x]* inv[y]%mod *inv[x-y]%mod;

}

void U(ll &x,int y){

	if ((x+=y)>=mod) x-=mod;

}



int a[N],tot,cnt; ll f[N],g[N];

ll doit(int cc=cnt){

	memset(f,0,sizeof f); f[0]=1; tot=0;

	for (int i=1;i<=cc;++i){

		memset(g,0,sizeof g);

		for (int j=0;j<=a[i];++j)

			for (int k=tot;~k;--k)

				U(g[k+j],f[k]*C(a[i],j)%mod*C(a[i],j)%mod*jc[j]%mod);

		tot+=a[i];

		memcpy(f,g,sizeof g);

	}

	for (int i=tot;~i;--i) f[i]=f[i]*jc[tot-i]%mod;

	for (int i=tot;~i;--i){

		for (int j=i-1;~j;--j)

			U(f[j],mod-f[i]*C(i,j)%mod);

	}

	return f[0];

}



int n,x,y,sz[N]; vector<int>G[N];

void dfs(int x,int fff){

	int mx=0; sz[x]=1;

	for (auto y:G[x]) if (y-fff){

		dfs(y,x); sz[x]+=sz[y];

		mx=max(mx,sz[y]);

	}

	mx=max(mx,n-sz[x]);

	if (mx*2==n) exit(0*printf("%lld",jc[mx]*jc[mx]%mod));

	if (mx*2>n) return;

	for (auto y:G[x]) if (y-fff) a[++cnt]=sz[y];

	if (x-1) a[++cnt]=n-sz[x]; a[++cnt]=1;

	exit(0*printf("%lld",(doit()+doit(cnt-1))%mod));

}



int main(){

	jc[0]=1; for (int i=1;i<N;++i) jc[i]=jc[i-1]*i%mod;

	inv[N-1]=K(jc[N-1]); for (int i=N;i--;) inv[i-1]=inv[i]*i%mod;

	cin>>n;

	for (int i=n;--i;) cin>>x>>y, G[x].push_back(y), G[y].push_back(x);

	dfs(1,0);

}

// Faster C++ solution for the same problem (measured speedup: 1.098535122986633x):
#include<bits/stdc++.h>

#define ll long long

#define N 5010

#define mod 1000000007

#define rep(i,l,r) for (int i=l;i<=r;++i)

using namespace std;

ll jc[N],inv[N],f[N],g[N],res;

int n,x,y,sz[N],a[N],tot,cnt;

vector<int>G[N];

ll K(ll x,int y=mod-2){

	ll t=1; for (;y;y>>=1,x=x*x%mod) if (y&1) t=t*x%mod; return t;

}

ll C(int x,int y){

	return jc[x]* inv[y]%mod *inv[x-y]%mod;

}

void U(ll &x,ll y){

	if ((x+=y)>=mod) x%=mod;

}



void dfs(int x,int fa){

	int mx=0; sz[x]=1;

	for (auto y:G[x]) if (y-fa)

		dfs(y,x), sz[x]+=sz[y], mx=max(mx,sz[y]);

	mx=max(mx,n-sz[x]);

	if (mx*2==n) exit(!(cout<<jc[mx]*jc[mx]%mod));

	if (mx*2>n) return;

	for (auto y:G[x]) if (y-fa) a[++cnt]=sz[y];

	if (x-1) a[++cnt]=n-sz[x];

	memset(f,0,sizeof f); f[tot=0]=1;

	rep(i,1,cnt){

		memset(g,0,sizeof g);

		rep(j,0,a[i]) rep(k,0,tot)

			U(g[k+j],f[k]*C(a[i],j)%mod*C(a[i],j)%mod*jc[j]%mod);

		memcpy(f,g,sizeof g);

		tot+=a[i];

	}

	rep(i,0,tot) U(res,mod+(i&1?-1:1)*f[i]*jc[n-i]%mod);

	exit(!(cout<<res));

}



int main(){

	jc[0]=1; rep(i,1,N-1) jc[i]=jc[i-1]*i%mod;

	inv[N-1]=K(jc[N-1]); for(int i=N;i--;) inv[i-1]=inv[i]*i%mod;

	cin>>n;

	rep(i,1,n-1) cin>>x>>y, G[x].push_back(y), G[y].push_back(x);

	dfs(1,0);

}
// Slower C++ solution:
#include <cstdio>

#include <vector>

#include <utility>

#include <algorithm>



int main() {

  int N;

  scanf("%d", &N);



  std::vector<std::pair<int, int>> AB(N);

  for (int i=0; i<N; ++i)

    scanf("%d %d", &AB[i].first, &AB[i].second);



  std::sort(AB.begin(), AB.end());

  printf("%d\n", AB.back().first+AB.back().second);

  

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.842380751692611x):
#include <cstdio>



int main() {

  int n;

  scanf("%d", &n);



  int max_a = 0;

  int res = 0;

  for (int i = 0; i < n; ++i) {

    int a, b;

    scanf("%d %d", &a, &b);

    if (a > max_a) {

      max_a = a;

      res = a + b;

    }

  }

  printf("%d\n", res);

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <algorithm>

#include <iomanip>

#include <vector>

#include <map>

#include <cmath>

#include <queue>

#include <utility>

#include <functional>

#include <deque>

#include <cctype>

#include <stack>

#include <bitset>



using ll = long long;

typedef unsigned long long ull;

typedef std::pair<ll, ll>P;

struct edge { ll to, cost; };

std::vector<edge>v[100010], w[100010];

typedef std::vector<std::vector<int>>ma;



ll min(ll a, ll b) {

	if (a >= b)return b;

	else return a;

}

ll max(ll a, ll b) {

	if (a >= b)return a;

	else return b;

}

ll gcd(ll a, ll b) {

	if (b == 0) return a;

	return gcd(b, a%b);

}

ll lcm(ll a, ll b) {

	ll g = gcd(a, b);

	return a / g * b;

}



const ll Z = 1000000007;

const ll INF = 1 << 30;

const ll INF2 = 9000000000000000000LL;

bool flag = true;

bool fl = true;

bool f = true;

int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

std::string abc = "abcdefghijklmnopqrstuvwxyz";



int main() {

	int n, a[100000], b[100000], ans = 0, ma = 0, mi = INF;

	std::cin >> n;

	for (int i = 0;i < n;i++) {

		std::cin >> a[i] >> b[i];

		mi = min(b[i], mi);

		if (mi == b[i])ma = a[i];

	}

	std::cout << ma + mi << std::endl;

}

// Faster C++ solution for the same problem (measured speedup: 6.433817639184475x):
#include "bits/stdc++.h"



using namespace std;

using ll=long long;

using ull=unsigned long long;



typedef pair<int,int>Pi;

typedef pair<long long,long long>P;

typedef pair<long long,P>PP;

typedef pair<P,P>PPP;



const long long MOD=1e9+7;

const long long INF=5e18;

const int di[4]={1,0,-1,0};

const int dj[4]={0,1,0,-1};



#define fr first

#define sc second

#define pb push_back

#define eb emplace_back

#define ALL(x) (x).begin(),(x).end()

#define ALLR(x) (x).rbegin(),(x).rend()



int n,a,b,mx,le;



void input(){

	cin>>n;

	return;

}



void solve(){

	for(int i=0;i<n;i++){

		cin>>a>>b;

		if(a>=mx)mx=a,le=b;

	}

	cout<<le+mx<<endl;

	return;

}



int main(){

	input();

	solve();

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

string f="snuke";

int main()

{

	int h,w;

	int x,y;

	string n[100][100];

	cin>>h>>w;

	for(int i=1;i<=h;i++)

	{

		for(int j=1;j<=w;j++)

		{

			cin>>n[i][j];

			if(n[i][j]==f)

			{

				x=i;

				y=j;

			}

		}

	}

	char z='A'+y-1;

	cout<<z<<x<<endl;

 	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.346793185859948x):
#include<bits/stdc++.h>

using namespace std;

string s;

int a,b,c,sum=0;

int main(){

    scanf("%d %d",&a,&b);

    for(int i=1;i<=a*b;i++){

        cin>>s;sum++;

        if(s=="snuke")break;

    }

    c=sum%b==0?b:sum%b;

    printf("%c%.0lf",64+c,ceil((sum+0.00)/b));

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define rep(i,x,y) for(int i=(x);i<(y);++i)

#define mp(a,b) make_pair((a),(b))

#define debug(x) #x << "=" << (x)

 

#ifdef DEBUG

#define _GLIBCXX_DEBUG

#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl

#else

#define dump(x)

#endif



typedef long long int ll;

typedef pair<int,int> pii;

//template<typename T> using vec=std::vector<T>;



const int INF=1<<30;

const long long int INFLL=1LL<<58;

const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};



template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){

	os << "[";

	for (const auto &v : vec) {

		os << v << ",";

	}

	os << "]";

	return os;

}



vector<pair<int,int>> graph[100000];



pair<int,int> dfs(int v,int p){

    pair<int,int> res(v,0);

    for(auto &e:graph[v]){

        if(e.first==p) continue;

        

        auto tmp=dfs(e.first,v);

        tmp.second+=e.second;

        if(res.second<tmp.second) res=tmp;

    }

    

    return res;

}



void solve(){

    int n;

    cin >> n;

    rep(i,0,n-1){

        int s,t,w;

        cin >> s >> t >> w;

        graph[s].push_back(make_pair(t,w));

        graph[t].push_back(make_pair(s,w));

    }

    

     int v=dfs(0,-1).first;

     cout << dfs(v,-1).second << endl;

}



int main(){

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	solve();

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4792154611802038x):
#include <bits/stdc++.h>

using namespace std;



#define rep(i,x,y) for(int i=(x);i<(y);++i)

#define debug(x) #x << "=" << (x)



#ifdef DEBUG

#define _GLIBCXX_DEBUG

#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl

#else

#define show(x)

#endif



typedef long long int ll;

typedef pair<int,int> pii;

template<typename T> using vec=std::vector<T>;



const int inf=1<<30;

const long long int infll=1LL<<62;

const double eps=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};



template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){

    os << "[";

    for (const auto &v : vec) {

    	os << v << ",";

    }

    os << "]";

    return os;

}



//???????????¶??¨??¨?????´???????±???????.

pair<int,int> farthest_vertex(const vector<vector<pair<int,int>>> &graph,int v,int p){

    pair<int,int> res(v,0); //(??????????????????,?????¢)

    for(auto &e:graph[v]){

        if(e.first==p) continue;



        auto tmp=farthest_vertex(graph,e.first,v);

        tmp.second+=e.second;

        if(res.second<tmp.second) res=tmp;

    }

    return res;

}



void solve(){

    int n;

    cin >> n;



    vector<vector<pii>> graph(n);

    rep(i,0,n-1){

        int s,t,w;

        cin >> s >> t >> w;

        graph[s].push_back(make_pair(t,w));

        graph[t].push_back(make_pair(s,w));

    }

    auto tmp=farthest_vertex(graph,0,-1);

    cout << farthest_vertex(graph,tmp.first,-1).second << endl;

}



int main(){

    std::cin.tie(0);

    std::ios::sync_with_stdio(false);

    cout.setf(ios::fixed);

    cout.precision(10);

    solve();

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<string>

#include<string.h>

#include<algorithm>

#include<stdio.h>

#include<cmath>

#include<vector>

#include<utility>

#include<stack>

#include<queue>

#include<list>

#include<bitset>

#include<functional>



#define FOR(i, a, b) for(int i=(a);i<=(b);i++)

#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)

#define MOD 1000000007

#define INF 1000000000



using namespace std;





int main(void) {

	int n;

	int a, dp[100001] = {};

	int count = 0;



	cin >> n;

	FOR(i, 1, n) {

		cin >> a;

		dp[a]++;

	}

	FOR(i, 1, 100000) {

		if (dp[i] != 0) {

			count++;

		}

	}



	if (count % 2 == 0) {

		cout << count - 1 << endl;

	}

	else {

		cout << count << endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4223543488994648x):
#include<iostream>

#include<vector>

#include<algorithm>



using namespace std;



int main(void) {

	int n;



	cin >> n;



	vector<int> a(n);



	for (int i = 0; i < n; i++) {

		cin >> a[i];

	}



	sort(a.begin(), a.end());

	

	a.erase(unique(a.begin(), a.end()),a.end());



	if (a.size() % 2 == 0) {

		cout << a.size()-1 << endl;

	}

	else {

		cout << a.size() << endl;

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



int main() {

  int n;

  set<int> st;

  scanf("%d", &n);

  for (int i = 1; i <= n; ++i) {

    int x;

    scanf("%d", &x);

    st.insert(x);

  }

  int dd = n - (int)st.size();

  if (dd & 1) dd ++;

  printf("%d\n", n - dd);

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.5818386603572687x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int i,j,k,n,m,ans,a[110001],s[110001];

int main(){

	while (scanf("%d",&n)!=EOF){

		memset(a,0,sizeof(a));

		for (i=m=1;i<=n;i++) scanf("%d",&k),a[k]++,m=max(m,k);

		for (i=1,s[0]=0;i<=m;i++) s[i]=s[i-1]+a[i];

		for (i=1,ans=n,j=m;i<=j;){

			while (a[i]<=1&&i<=j) i++;

			while (a[j]<=1&&i<=j) j--;

			if (i>j) break;

			if (i!=j) k=min(a[i],a[j])-1,a[i]-=k,a[j]-=k,ans-=2*k;else{

				if (a[i]&1) ans-=(a[i]-1);else ans-=a[i];

				break;

			}

		}

		printf("%d\n",ans);

	}

	return 0;

}