akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define N 200005
#define M 1000005

int n;
char s[M];

int f[N];
ll ans;

struct node{
	int ed,sz[26];
	node *fa,*ch[26];
}t[M],*pos[N];
int _t,cnt[26];
inline node* ins(){
	int len=strlen(s+1);
	for(int i=1;i<=len;i++)
		cnt[s[i]-'a']++;
	node *u=t;
	for(int i=len;i;i--){
		for(int j=0;j<26;j++)
			if(cnt[j])
				u->sz[j]++;
		int c=s[i]-'a';
		if(!u->ch[c]){
			u->ch[c]=t+(++_t);
			u->ch[c]->fa=u;
		}
		u=u->ch[c];
		cnt[c]--;
	}
	ans+=u->ed;
	u->ed++;
	return u;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		f[i]=s[1]-'a';
		pos[i]=ins();
	}
	for(int i=1;i<=n;i++)
		ans+=pos[i]->fa->sz[f[i]]-pos[i]->ed;
	printf("%lld",ans);
}

Measured memory_bytes: 321600
//by The_One_solver
#include<bits/stdc++.h>
using namespace std;
double  n,a,b;
int main()
{
    cin>>a>>b>>n;
    if(n==b)
    {
        cout<<floor(((a*(n-1))/b));
    }
    else if(n<b)
    {
        cout<<floor(((a*n)/b));
    }
    else {
            cout<<floor(((a*(b-1))/b));
         }

    return 0;
}


Measured memory_bytes: 3864
n, m = map(int, input().split())
prob = [0]*n
AC = 0
WA = 0
for _ in range(m):
    p, s = input().split()
    p = int(p)
    if prob[p-1] == -1:
        continue
    if s == 'WA':
        prob[p-1] += 1
    else:
        WA += prob[p-1]
        AC += 1
        prob[p-1] = -1
print(AC, WA)


Measured memory_bytes: 9484
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  map<string, vector<int> > in;

  string goku;
  int id;
  while( cin >> goku >> id ){
    in[goku].push_back(id);
  }
    for( map < string, vector<int> >::iterator it = in.begin() ; it != in.end() ; it++ ){

      cout << (*it).first << endl;
    vector <int>& go = (*it).second;
    sort(go.begin(),go.end());
    for(vector <int>::iterator  it_p = go.begin() ; it_p != go.end() ; it_p++ ){
      cout << (*it_p);
      if(it_p+1 != go.end() )cout << " ";
    }
    cout << endl;
    }

  return 0;
}

Measured memory_bytes: 1244
from math import *
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
doo=max([abs(x[i]-y[i]) for i in range(n)])
d1=d2=d3=0
for i in range(n):
    d1+=abs(x[i]-y[i])
    d2+=(x[i]-y[i])**2
    d3+=abs(x[i]-y[i])**3
print(d1)
print(d2**0.5)
print(d3**(1/3))
print(doo)


Measured memory_bytes: 5708
#include<bits/stdc++.h>
#define ll long long
#define dl double
using namespace std;

//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************
ll mod=1000000007;
void solve()
{

	int n,k;
    cin >> n >> k;
    vector<int> v(n);
    vector<vector<int>> dp(n);
    for(int i=0;i<n;i++)
    {
        cin >> v[i];
        dp[i].resize(k+1);
        dp[i][0]=1;
    }
    for(int i=1;i<=k;i++)
    {
        if(i<=v[0])
        dp[0][i]=1;
    }
    for(int i=1;i<n;i++)
    {
        vector<int> temp(k+1);
        temp[0]=1;
        for(int j=1;j<=k;j++)
        {
            temp[j]=(temp[j-1]+dp[i-1][j])%mod;
            if(v[i]<j)
            {
                dp[i][j]=(temp[j]-temp[j-v[i]-1]+mod)%mod;
            }
            else{
                dp[i][j]=temp[j]%mod;
            }
          //  cout << temp[j] << " ";
        }
        //cout << endl;
    }
    cout << dp[n-1][k] << endl;
    
    
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 39936
#include <stdio.h>

int main(){
    int H, W;
    int h,w;
    
    scanf("%d %d", &H, &W);
    scanf("%d %d", &h, &w);
    
    //int remain_row = H-h;
    printf("%d", (H-h)*(W-w));
    return 0;
}

Measured memory_bytes: 128
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static final int MOD = 1000000007;

	static int add(int a, int b) {
		int res = a + b;
		return res >= MOD ? res - MOD : res;
	}

	static int sub(int a, int b) {
		int res = a - b;
		return res < 0 ? res + MOD : res;
	}

	static int mul(int a, int b) {
		int res = (int) ((long) a * b % MOD);
		return res < 0 ? res + MOD : res;
	}

	static int pow(int a, int e) {
		if (e == 0) {
			return 1;
		}
		int r = a;
		for (int i = 30 - Integer.numberOfLeadingZeros(e); i >= 0; i--) {
			r = mul(r, r);
			if ((e & (1 << i)) != 0) {
				r = mul(r, a);
			}
		}
		return r;
	}

	static int inv(int a) {
		return pow(a, MOD - 2);
	}

	static void solve() throws Exception {
		int n = scanInt() - 1;
//		System.err.println("N = " + n);
		int facts[] = new int[n + 1];
		facts[0] = 1;
		for (int i = 1; i <= n; i++) {
			facts[i] = mul(facts[i - 1], i);
		}
		int ansNum = mul(facts[n], n), ansDen = 1;
		for (int i = 1; i < n; i++) {
			int looseness = 2 * i - n - 1;
			if (looseness < 0) {
				continue;
			}
			int curNum = mul(facts[n - i + looseness], facts[i]),
				curDen = facts[looseness];
//			if (i < 10) {
//				System.err.println("i = " + i + ", ans = " + mul(curNum, inv(curDen)));
//			}
			ansNum = sub(mul(ansNum, curDen), mul(ansDen, curNum));
			ansDen = mul(ansDen, curDen);
		}
//		System.err.println("i = " + n + ", ans = " + facts[n]);
		out.print(mul(ansNum, inv(ansDen)));
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 23764
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int s, w; cin>>s>>w;
	if(s<=w) cout<<"unsafe"<<endl;
	else cout<<"safe"<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    rep(x, sx+1, tx+1) cout << 'R';
    rep(y, sy+1, ty+1) cout << 'U';

    cout << 'R';
    for(ll y = ty-1; y >= sy-1; y--) cout << 'D';
    for(ll x = tx; x >= sx; x--) cout << 'L';
    cout << 'U';

    rep(y, sy+1, ty+1) cout << 'U';
    rep(x, sx+1, tx+1) cout << 'R';

    cout << 'U';
    for(ll x = tx-1; x >= sx-1; x--) cout << 'L';
    for(ll y = ty; y >= sy; y--) cout << 'D';
    cout << 'R' << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define INF 1020304050

int main()
{
  int n;cin>>n;
  vector<int> a(n);
  int i;
  rep(i,n)cin>>a[i];
  rep(i,n)a[i]*=(-1);
  vector<int> dec(n,INF);
  rep(i,n)
  {
    int ind=upper_bound(all(dec),a[i])-dec.begin();
    dec[ind]=a[i];
  }
  int ans=0;
  rep(i,n)
  {
    if(dec[i]!=INF)ans++;
    else break;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define add(x) accumulate(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end() 
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
                void solve(){
                        int a,b,c;
                        cin>>a>>b>>c;
                        int k=a;
                        a=c;
                        c=b;
                        b=k;
                        // c=a;
                        cout<<a<<" "<<b<<" "<<c;
                }
                int main(){ 
                        hs;
                        ll t;
                        t=1;
                        // cin>>t;
                        for (int i=1; i<=t; i++){
                                //cout<<"Case #"<<i<<": ";
                                solve();
                         }
        return 0; 
}         
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
const int N(1e5 + 5);
int n, dp[N], v[N];
int main() {
    DAU
    cin >> n >> v[1] >> v[2];
    dp[2] = abs(v[1] - v[2]);
    for (int i = 3; i <= n; ++i) {
        cin >> v[i];
        dp[i] = min(dp[i-2] + abs(v[i] - v[i-2]), dp[i-1] + abs(v[i] - v[i-1]));
    }
    cout << dp[n];
    PLEC
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
//constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	//N=10000,K=50;
	//vector<vector<int>>dp(N+1,vector<int>(K+1,MOD));
	//for(int i=0;i<=K;i++)dp[0][i]=0;
	//for(int i=1;i<=N;i++){
	//	for(int j=1;j<=K;j++){
	//		for(int k=0;k<i;k++){
	//			dp[i][j]=min(dp[i][j],max(dp[k][j],dp[i-k-1][j-1])+1);
	//		}
	//	}
	//}
	cin>>K;
	vector<vector<long long int>>r(51,vector<long long int>(51,0));
	for(int i=1;i<=50;i++){
		r[1][i]=i;
	}
	for(int i=2;i<=50;i++){
		for(int j=1;j<=50;j++){
			r[i][j]=r[i-1][j-1]+r[i][j-1]+1;
			r[i][j]=min(r[i][j],MOD*MOD);
		}
	}
	//for(L=1;L<=N;L++){
	//	for(R=1;R<=K;R++){
	//		//cout<<dp[L][R]<<"";
	//		if(dp[L][R]>50)continue;
	//		int box=0;
	//		for(int i=1;i<=50;i++){
	//			if(r[R][i]>=L){
	//				box=i;
	//				break;
	//			}
	//		}
	//		if(box!=dp[L][R]){
	//			cout<<L<<" "<<R<<endl;
	//		}
	//	}
	//}
	while(K--){
		cin>>L>>R;
		for(int i=1;i<=50;i++){
			if(r[R][i]>=L){
				cout<<i<<endl;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3220
#include <iostream>
using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;

	int cnt = 0 ;
	for ( int i = a ; i <= b ; i++ ){
    	if ( c % i == 0 ) {
          cnt++;
        }
	}

	cout << cnt << endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
//#define TASK "file"

#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long i64;
typedef long double dbl;
const dbl PI = acos(-1.0L);
const dbl EPS = 1e-12L;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

namespace task {
int a, b;
string s, t, u;

int main() {
  cin >> s >> t >> a >> b >> u;
  if (u == s) {
    cout << a - 1 << ' ' << b << '\n';
  } else {
    cout << a << ' ' << b - 1 << '\n';
  }
  return 0;
}
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(11);
  cout.setf(ios::fixed);
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#elif defined(TASK)
  freopen(TASK".in", "r", stdin);
  freopen(TASK".out", "w", stdout);
#endif
  return task::main();
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define y1 hogwhoasjfd

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int w, h;
int n;
int x1[1005], x2[1005];
int y1[1005], y2[1005];

bool fld[1005*6+2][1005*6+2];

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

int compress(int *x1, int *x2, int w)
{
    vi xs;

    rep(i, n) {
        for (int d = -1; d <= 1; ++d) {
            int tx1 = x1[i] + d, tx2 = x2[i] + d;

            if (0 <= tx1 && tx1 <= w) xs.PB(tx1);
            if (0 <= tx2 && tx2 <= w) xs.PB(tx2);
        }
    }

    sort(all(xs));
    xs.erase(unique(all(xs)), end(xs));

    rep(i, n) {
        x1[i] = lower_bound(all(xs), x1[i]) - begin(xs);
        x2[i] = lower_bound(all(xs), x2[i]) - begin(xs);
    }

    return xs.size();
}

int main()
{
    omajinai;
    while (cin >> w >> h, w) {
        cin >> n;

        memset(fld, 0, sizeof fld);

        rep(i, n) {
            cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        }

        w = compress(x1, x2, w);
        h = compress(y1, y2, h);

        rep(i, n) {
            for (int y = y1[i]; y <= y2[i]-1; ++y) {
                for (int x = x1[i]; x <= x2[i]-1; ++x) {
                    fld[y][x] = true;
                }
            }
        }

        int ans = 0;

        rep(y, h-1) rep(x, w-1) {
            if (fld[y][x]) continue;

            ans++;

            queue<pii> q;
            q.push(pii(y, x));

            while (q.size()) {
                pii p = q.front(); q.pop();
                rep(i, 4) {
                    int ny = p.fst + dy[i], nx = p.scd + dx[i];

                    if (ny < 0 || ny >= h-1 || nx < 0 || nx >= w-1 || fld[ny][nx]) continue;

                    fld[ny][nx] = true;
                    q.push(pii(ny, nx));
                }
            }
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 38740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<int> V(N), W(N);
    for(int i=0; i<N; i++) cin >> V[i];
    for(int i=0; i<N; i++) {
        if(i % 2 == 0) {
            W[i/2] = V[N-i-1];
        }
        else {
            W[N-1-i/2] = V[N-i-1];
        }
    }
    for(int i=0; i<N; i++) cout << W[i] << " " ;
}

Measured memory_bytes: 4812
import sys
try:
    while True:
        edges = [0]*101
        while True:
            a, b = map(int, input().split())
            if not a:
                break
            edges[a] += 1
            edges[b] += 1

        if edges[1]%2 == 1 and edges[2]%2 == 1 and all(n%2==0 for n in edges[3:]):
            print("OK")
        else:
            print("NG")
except EOFError:
    pass


Measured memory_bytes: 5608
x,y=map(int,input().split())
m=0
if x==1:
  m+=300000
elif x==2:
  m+=200000
elif x==3:
  m+=100000
if y==1:
  m+=300000
elif y==2:
  m+=200000
elif y==3:
  m+=100000
if m==600000:
  print(1000000)
else:
  print(m)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
//typedef pair<ll, ll> P;
//typedef pair<double, P> T;

const ll mod = 1000000007;
const ll INF = 100000010000;


ll ans;

ll gcd(ll x, ll y)
{
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2 == 1)
	{
		return x * pow_mod(x, y - 1) % mod;
	}
	else
	{
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x)
{
	return pow_mod(x, mod - 2);
}

void init()
{

}

void output()
{
	//cout << ans << endl;
}



void solve()
{
	char C;
	cin >> C;
	if (C == 'z')
	{
		cout << 'a' << endl;
	}
	else
	{
		printf("%c", C + 1);
	}
}

int main()
{
	init();

	solve();



	output();
	ll N;
	cin >> N;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
up = []
down = []
down_sum = 0
for i,j in zip(A,B):
    if i - j > 0:
        up.append(i - j)
    elif i - j < 0:
        down.append(j - i)
        down_sum += j - i
if down_sum == 0:
    ans = 0
else:
    up_sum = 0
    ans = len(down)
    up.sort(reverse=True)
    for i in up:
        up_sum += i
        ans += 1
        if up_sum >= down_sum:
            break
    if up_sum < down_sum:
        ans = -1
print(ans)

Measured memory_bytes: 18356
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Z = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        int[] a = new int[N];
        for (int i=0;i<N;i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        if (N==1) {
            System.out.println(Math.abs(a[N-1]-W));
        } else {
            System.out.println(Math.max(Math.abs(a[N-1]-W), Math.abs(a[N-1]-a[N-2])));
        }
    }
}

Measured memory_bytes: 24404
#include <bits/stdc++.h>
using namespace std;

int  main() {
  int n, a = 0;
  cin >> n;
  vector<string> vec(n);
  for(int i = 0; i<n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int j = 0;
  while(j < n) {
    if(j < n-1 && vec.at(j) != vec.at(j+1)) {
      a++;
      j++;
    } else if(j == n-1) {
		a++;
      	j++;
    } else {
      int k = 2;
      while(j+k<n && vec.at(j) == vec.at(j+k)) {
        k++;
      }
      a++;
      j+=k;
    }
  }
  cout << a <<endl;
}



Measured memory_bytes: 9592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#define pi 3.14159265358979323846264338327950

int main() {
    int n, x, d, a; std::cin >> n >> d >> x;
    for (int i = 0; i < n; i++) {
        std::cin >> a;
        for (int i = 1; i <= d; i += a)
            x += 1;
    }
    std::cout << x;

	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

struct Edge{
	Edge(int arg_to,ll arg_dist){
		to = arg_to;
		dist = arg_dist;
	}
	int to;
	ll dist;
};

ll ans;
int V;
vector<Edge> G[SIZE];


ll recursive(int node_id,int parent){

	ll max_path1 = 0;
	ll max_path2 = 0;

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i].to;
		if(child == parent)continue;

		ll tmp_dist = G[node_id][i].dist+recursive(child,node_id);

		if(tmp_dist > max_path1){

			max_path2 = max_path1;
			max_path1 = tmp_dist;

		}else if(tmp_dist > max_path2){

			max_path2 = tmp_dist;
		}
	}
	ans = max(ans,max_path1+max_path2);

	return max_path1;
}


int main(){

	scanf("%d",&V);

	int from,to;
	ll dist;

	for(int loop = 0; loop < V-1; loop++){

		scanf("%d %d %lld",&from,&to,&dist);
		G[from].push_back(Edge(to,dist));
		G[to].push_back(Edge(from,dist));
	}

	ans = 0;
	recursive(0,-1);

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

	return 0;
}



Measured memory_bytes: 17996
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int n;
string s1,s2;
long long ans,mod=1000000007;
int b[100001],x;
int main()
{
	cin>>n;
	cin>>s1>>s2;
	for(int i=0;i<=n-1;i++)
	{
		if(s1[i]!=s1[i+1])
		{
			x++;
			b[x]=1;
		}
		if(s1[i]==s1[i+1])
		{
			x++;
			b[x]=2;
			i++;
		}
	}
	
	if(b[1]==1)  ans=3;
	else         ans=6;
	for(int i=2;i<=x;i++)
	{
		if(b[i-1]==1&&b[i]==2)  ans=(ans*2)%mod;
		if(b[i-1]==1&&b[i]==1)  ans=(ans*2)%mod;
		if(b[i-1]==2&&b[i]==2)  ans=(ans*3)%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
def solve(a, b, c, d, e):
	if a == b == c == d == e:
		for i in range(5):
			print 3
	elif [a,b,c,d,e].count(1) > 0 and [a,b,c,d,e].count(2) > 0 and [a,b,c,d,e].count(3) > 0:
		for i in range(5):
			print 3
	else:
		w = sorted([a,b,c,d,e])[0]
		l = sorted([a,b,c,d,e])[-1]
		if w == 1:
			for f in [a,b,c,d,e]:
				if l == 2:
					if f == 2:
						print 2
					else:
						print 1
				else:
					if f == 3:
						print 1
					else:
						print 2
		elif w == 2:
			for f in [a,b,c,d,e]:
				if l == 1:
					if f == 1:
						print 1
					else:
						print 2
				else:
					if f == 3:
						print 2
					else:
						print 1
		else:
			for f in [a,b,c,d,e]:
				if l == 2:
					if f == 2:
						print 2
					else:
						print 1
				else:
					if f == 1:
						print 1
					else:
						print 2
				

a = input()
while a != 0:
	b = input()
	c = input()
	d = input()
	e = input()
	solve(a, b, c, d, e)
	a = input()

Measured memory_bytes: 6472
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(205), LIM(1e7), M(LIM + 10), INF(0x3f3f3f3f);
struct edge { int next, to, cap; } e[N * N * 2];
int n, a[M], head[N], e_num = -1, cnt, L[N], R[N], cntl, cntr;
int lev[N], cur[N], S, T, not_prime[M], prime[M];
inline int Abs(int x) { return x < 0 ? -x : x; }
inline void Add(int from, int to, int cap)
{
	e[++e_num] = (edge) {head[from], to, cap}, head[from] = e_num;
	e[++e_num] = (edge) {head[to], from,  0 }, head[to]   = e_num;
}

void Init()
{
	not_prime[1] = 1;
	for (int i = 2; i <= LIM; i++)
	{
		if (!not_prime[i]) prime[++cnt] = i;
		for (int j = 1; j <= cnt && 1ll * i * prime[j] <= LIM; j++)
		{
			not_prime[i * prime[j]] = 1;
			if (!(i % prime[j])) break;
		}
	}
}

int bfs()
{
	std::queue<int> Q; Q.push(S);
	memset(lev, 0, (T + 1) << 2), lev[S] = 1;
	while (!Q.empty())
	{
		int x = Q.front(); Q.pop();
		for (int i = head[x]; ~i; i = e[i].next)
		{
			int to = e[i].to; if (lev[to] || !e[i].cap) continue;
			lev[to] = lev[x] + 1, Q.push(to);
		}
	}
	return lev[T];
}

int dfs(int x, int f)
{
	if (x == T || !f) return f;
	int ans = 0, cap;
	for (int &i = cur[x]; ~i; i = e[i].next)
	{
		int to = e[i].to;
		if (lev[to] == lev[x] + 1 && e[i].cap)
		{
			cap = dfs(to, std::min(f - ans, e[i].cap));
			e[i].cap -= cap, e[i ^ 1].cap += cap, ans += cap;
			if (ans == f) break;
		}
	}
	if (!ans) lev[x] = 0;
	return ans;
}

int Dinic()
{
	int ans = 0;
	while (bfs()) memcpy(cur, head, (T + 1) << 2), ans += dfs(S, INF);
	return ans;
}

int main()
{
	Init(), n = read(), memset(head, -1, sizeof head);
	for (int i = 1; i <= n; i++) ++a[read()];
	for (int i = 0; i <= LIM; i++) if (a[i] != a[i + 1])
		(i & 1) ? R[++cntr] = i + 1 : L[++cntl] = i + 1;
	S = 0, T = cntl + cntr + 1;
	for (int i = 1; i <= cntl; i++) Add(S, i, 1);
	for (int i = 1; i <= cntr; i++) Add(i + cntl, T, 1);
	for (int i = 1; i <= cntl; i++) for (int j = 1; j <= cntr; j++)
		if (!not_prime[Abs(L[i] - R[j])]) Add(i, j + cntl, 1);
	int f = Dinic(), ans = f, tl = cntl - f, tr = cntr - f;
	ans += tl - (tl & 1) + tr - (tr & 1), ans += 3 * (tl & 1);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;

#define INF 2147483647
#define LINF 9223372036854775807

#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n);

    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n)cin>>c[i];

    sort(all(a));sort(all(b));sort(all(c));
    vector<ll> pat(n+1,0),conb(n,0),cona(n,0);

    int bp=n-1,cp=n-1;
    while(bp >= 0){
        while(c[cp] > b[bp] && cp>=0 ){
            --cp;
        }
        conb[bp] = n-1 - cp;
        --bp;
    }

    bp=n-1;
    int ap=n-1;
    while(ap >= 0){
        while(b[bp] > a[ap] && bp>=0 ){
            --bp;
        }
        cona[ap] = n-1 - bp;
        --ap;
    }

    rep1(i,1,n+1){
        pat[i] = pat[i-1] + conb[n-i];
        //db2(i,pat[i]);ln;
    }

    rep(i,n){
        ans += pat[ cona[i] ];
    }

    /*
    ln;
    rep(i,n)cout<<cona[i]<<" ";
    ln;
    rep(i,n)cout<<conb[i]<<" ";
    ln;
    */

    cout<<ans<<endl;
    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(((i%2) && s[i]=='R') || (!(i%2) && s[i]=='L'))
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	string s; int N,K;
	cin >> N >> s >> K;
	char c = s[K-1];
	rep(i,N){
		if(s[i] != c)s[i] = '*';
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
int main(void) {
   int i,n;
   int c[100];
 
   scanf("%d", &n);
   for (i = 0; i < n; i++) {
       scanf("%d", &c[i]); 
   }
   
   for (i = 0; i < n; i++) { 
       if (c[i] % 2 == 0 && c[i] % 3 != 0 && c[i] % 5 != 0) { 
           puts("DENIED"); 
           return 0; 
       } 
   } 
   puts("APPROVED");
 
   return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
ll a[100010],S[100010],S2[100010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),K=gi();ll ans=0;
	for(int i=1;i<=n;++i)a[i]=gi(),S[i]=a[i]+S[i-1],S2[i]=(a[i]>0)*a[i]+S2[i-1];
	for(int l=1,r=K;r<=n;++l,++r)ans=std::max(ans,std::max(S[r]-S[l-1],0ll)+S2[l-1]+S2[n]-S2[r]);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"

using namespace std;
using VI = vector<int>;
using VPI = vector<pair<int, int>>;
using LL = long long;

#define FOR(a,n) for(int i=a;i<n;i++)
#define rFOR(a,n) for(int i=n-1;i>=a;i--)
#define IN(n,a) for(int i=0;i<n;i++) cin>>a[i]
#define pIN(n,t) for(int i=0;i<n;i++){int a,b; cin>>a>>b; t.emplace_back(a,b);}
#define SORT(a) sort(a.begin(), a.end())
#define ALL(a) a.begin(), a.end()

int main()
{
	LL n, k, s, a, b;
	cin >> n >> k >> s;

	a = s / 2;
	b = s / 2;
	if (s % 2 == 1)b++;

	FOR(0, n)
	{
		if (i < k)cout << s << " ";
		else
		{
			if (s == 1) cout << "10" << " ";
			else cout << s / 2 + 1 << " ";
		}
	}
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;

int main() {
  
  string s;
  cin >> s;
  
  int count = 0;
  if(s[0] == '1'){count++;}
   if(s[1] == '1'){count++;}
   if(s[2] == '1'){count++;}
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iomanip>
#include<iostream>
#include<cmath>
using namespace std;

int main(void){
    double n,D1 = 0,D2 = 0,D3 = 0,D4 = 0;
    int x[100],y[100];
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> x[i];
    }
    for (int i = 0; i < n; i++){
        cin >> y[i];
    }
    for (int i = 0; i < n; i++){
        D1 += fabs(x[i] - y[i]);
        D2 += pow(fabs(x[i] - y[i]),2);
        D3 += pow(fabs(x[i] - y[i]),3);
        if (fabs(x[i] - y[i]) > D4){
            D4 = fabs(x[i] - y[i]);
        }
    }
    D2 = sqrt(D2);
    D3 = pow(D3,1.0/3.0);
    cout << fixed << setprecision(8) << D1 << endl;
    cout << fixed << setprecision(8) << D2 << endl;
    cout << fixed << setprecision(8) << D3 << endl;
    cout << fixed << setprecision(8) << D4 << endl;
}


Measured memory_bytes: 3444
#include <stdio.h>

int main() {
  int L, R, d, ctr = 0;
  scanf("%d %d %d", &L, &R, &d);

  for(int i = L; i <= R; i++) {
    if(i % d == 0) {
      ctr++;
    }
  }
  printf("%d", ctr);
  return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;


int main()
{
    int N;cin >> N;
    vector<int> vec1,vec2,vec3;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec1.push_back(b);
    }
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec2.push_back(b);
    }
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec3.push_back(b);
    }
    sort(vec1.begin(),vec1.end());
    sort(vec3.begin(),vec3.end());
    long long ans =0;
    for(int a = 0;a < N;a++){
        ans += ((lower_bound(vec1.begin(),vec1.end(),vec2.at(a)) - vec1.begin())) * ( N - (upper_bound(vec3.begin(),vec3.end(),vec2.at(a))-vec3.begin()));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1784
import numpy as np

H, N = map(int, input().split())
AB = np.array([list(map(int, input().split())) for i in range(N)])
A = AB[:, 0]
B = AB[:, 1]

# インデックスはライフ 値はそれを以下にする最小MP
dp = np.array([0]*(H+1))
# dp = np.array([0 for i in range(H+1)])

for i in range(1, H+1):
    dp[i] = min(dp[np.maximum(i - A, 0)] + B)

print(dp[-1])

Measured memory_bytes: 12640
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main(void){
  string S;
  cin >> S;
  //入力終了

  //文字が既に出現したか
  int appeared[26];
  rep(i, 26)
    appeared[i] = 0;

  //Sの各文字の出現情報をappered[]に記録
  rep(i, S.size() )
    appeared[S[i]-'a' ]++;

  //Sに現れない文字(辞書順最小)が見つかればそこで終了
  rep(i, 26){
    if(appeared[i] == 0){
      cout << (char)(i+'a') << endl;
      return 0;
    }
  }

  //上のループを抜ける＝Sに現れない文字がない
  cout << "None" << endl;
  
  return 0;
}


Measured memory_bytes: 3732
#include<iostream>
#include<algorithm>
#define F 21000
using namespace std;
int n,p[20010],d[20010];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>p[i];
		d[p[i]-1]=i;
	}
	for(int i=0;i<n;i++){
		if(i)cout<<" ";
		cout<<i*F+1;
	}cout<<endl;
	for(int i=0;i<n;i++){
		if(i)cout<<" ";
		cout<<(n-i)*F+d[i]+1;
	}cout<<endl;
	return 0;	
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int main() {
  int n, k;
  cin >> n >> k;
  long long h[110000];

  for (int i = 0; i < n; i++) cin >> h[i];

  long long dp[110000];
  for (int i = 0; i < 110000; i++) dp[i] = INF;
  dp[0] = 0;

  for (int i = 0; i < n; i++)
    for (int j = 1; j <= k; j++) {
      chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end() 
#define endl "\n"
#define int long long int
#define ll long long
#define ld long double
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
const int mod = 1000000007;
const int N=200005;
const int inf=1e18;
vector<vector<int>>adj(N);

bool isprime(int n){for(int i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
int factorial(int n){return (n==1 || n==0) ? 1:n*factorial(n-1);} 
int gcd(int a,int b){if (a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}
int max(int a,int b){int sol=a>b?a:b;return sol;}
int min(int a,int b){int sol=a<b?a:b;return sol;} 

void fun(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}


signed main(){
    flash;
    fun();
    int t=1;
    //cin>>t;
    while(t--){
        int n,a,b;
        cin>>n>>a>>b;
        string s;
        cin>>s;
        int cnt=0,cntb=0;
        for(int i=0;i<n;i++){
            if(s[i]=='a' && cnt<a+b){
                Yes();
                cnt++;
            }
            else if(s[i]=='b' && cnt<a+b && cntb<b){
                cntb++;
                cnt++;
                Yes();
            }
            else
                No();            
        }
        
    }
    return 0;
}

Measured memory_bytes: 8252
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

int main(){
    long long x;
    cin >> x;
    int a, b;
    for (int i = -200;i <= 200;i++){
        for (int j = -200;j <= 200;j++){
            if (pow(i, 5) - pow(j, 5) == x){
                a = i;
                b = j;
            }
        }
    }

    cout << a << " " << b << endl;
}

Measured memory_bytes: 3976
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 505;const ll inf=1e16;
int n,a[N][N];
ll f[2][N][N],qz1[N][N],qz2[N][N];
int main() {
	read(n);rep(i,1,n)rep(j,1,n)if(i!=j)read(a[i][j]);
	rep(i,1,n)rep(j,1,n)qz1[i][j]=a[i][j]+qz1[i][j-1];//hang
	rep(i,1,n)rep(j,1,n)qz2[i][j]=a[i][j]+qz2[i-1][j];//lie
	rep(i,0,1)rep(j,0,n)rep(k,0,n)f[i][j][k]=inf;
	f[0][0][0]=0;
	rep(t,0,n-1){
		int p=t&1,q=p^1;//p-->q
		rep(i,0,t+1)rep(j,0,i)f[q][i][j]=inf;
		rep(x,0,t)rep(y,0,x)if(f[p][x][y]<inf){
			ll tmp=f[p][x][y]+qz1[t+1][y]+qz2[t][t+1]-qz2[x][t+1];
			umin(f[q][x][y],tmp);umin(f[q][t+1][x],tmp);
		}
	}
	ll res=inf;rep(i,0,n)rep(j,0,i)umin(res,f[n&1][i][j]);
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


  
int main(){
  int n;
  cin>>n;
  long long a[n],b[n];
  long long x=0;
  REP(i,n){
    cin>>a[i]>>b[i];
    x -= b[i];
  }
  
  vector<long long> ab;
  REP(i,n){
    ab.push_back(a[i]+b[i]);
  }
  sort(ab.begin(),ab.end(),greater<long long>());
  for(int i=0;i<n;i+=2){
    x += ab[i];
  }
  
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0), cout.tie(0)
#define REP(a, b) for (int i = a; i <= b; i++)
int main()
{
    fastio;
    //freopen(input.txt, 'r', stdin);
    //freopen(output.txt,'w', stdout);
    ll tc;
    cin >> tc;
    cout<<(tc)+pow(tc,2)+pow(tc,3)<<'\n';
}

Measured memory_bytes: 4268
n, m = map(int, input().split())
M = list(list(map(int, input().split())) for x in range(m))
M = sorted(M, key=lambda x:x[1])
c = -1
cnt = 0
for i in range(m):
  if M[i][0] <= c < M[i][1]:
    pass
  else:
    cnt += 1
    c = M[i][1] - 1
print(cnt)

Measured memory_bytes: 29948
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define mp  make_pair
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	string s1,s2;
	cin>>s1>>s2;
	ll c=0;
	for(ll i=0;i<s1.size();++i){
		if(s1[i]==s2[i])
			c++;
	}
	cout<<c<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int ai[] = new int[3];
		ai[0] = sc.nextInt();
		ai[1] = sc.nextInt();
		ai[2] = sc.nextInt();

		int c5 = 0;
		int c7 = 0;
		for (int i=0; i < 3; i++){
			switch(ai[i]){
			case 5:
				c5++;
				break;
			case 7:
				c7++;
				break;

			}
		}
		if (c5==2 && c7==1){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}

}


Measured memory_bytes: 8916
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	string s;
	cin>>s;
	if(regex_match(s, regex("A[a-z]+C[a-z]+")))cout<<"AC"<<endl;
	else cout<<"WA"<<endl;
	return 0;
	
}


Measured memory_bytes: 384
object Main extends App {
	import scala.math._

	case class Point(val x: Int, val y: Int, val t: Int)

	def test(A: Point, B: Point): Int = abs(B.x - A.x) + abs(B.y - A.y)

	val n = scala.io.StdIn.readInt
	val a = new Array[Point](n)
	for(i<-0 until n){
		val tp = scala.io.StdIn.readLine.split(" ").map(_.toInt)
		a(i) = Point(tp(1), tp(2), tp(0))
	}

	var flag = true
	var Spoint = Point(0,0,0)
	var Epoint = Point(0,0,0)

	for(i<-0 until n){
		Epoint = a(i)
		val time = test(Spoint, Epoint)
		val delta = Epoint.t - Spoint.t
		if((delta - time)%2 == 1 || time > delta) flag = false
		Spoint = a(i)
	}

	if(flag) println("Yes")
	else println("No")
}

Measured memory_bytes: 54216
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static void Swap<T>(ref T a, ref T b)
    {
	var t = a;
	a = b;
	b = t;
    }

    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var a = new int[5];
	for (int i = 0; i < 5; i++)
	{
	    a[i] = int.Parse(ReadLine());
	}

	int rmax = 0;
	for (int i = 0; i < 5; i++){
	    int r = a[i] % 10;
	    if (r != 0){ r = 10 - r; }
	    if (r > rmax)
	    {
		Swap(ref a[0], ref a[i]);
		rmax = r;
	    }
	}

	int ans = a[0];
	for (int i = 1; i < 5; i++){
	    int r = a[i] % 10;
	    ans += a[i];
	    if (r != 0)
	    {
		ans += (10 - r);
	    }
	}

	WriteLine(ans);
    }
}


Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	static BufferedReader br;
	static PrintWriter pw;
	static int inf = (int) 1e9;
	static long mod = (long) 1e9 + 7;

	public static void main(String[] args) throws NumberFormatException, IOException, InterruptedException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(System.out);
		int t=Integer.parseInt(br.readLine());
		HashSet<String> h=new HashSet<>();
		while(t-->0)
		{
			String s=br.readLine();
			h.add(s);
		}
		pw.println(h.size());
		
		pw.flush();

	}

	static int n;
	static boolean[] visited;
	static ArrayList<Integer>[] g;

	static void bfs(int s, int[] arr) {
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(s);
		visited = new boolean[n];
		visited[s] = true;
		arr[s] = 0;
		while (!q.isEmpty()) {
			int u = q.remove();

			for (int v : g[u])
				if (!visited[v]) {
					visited[v] = true;
					q.add(v);
					arr[v] = arr[u] + 1;
				}
		}
	}

	static class Edge implements Comparable<Edge> {
		int node, cost, con;

		Edge(int a, int b, int c) {
			node = a;
			cost = b;
			con = c;
		}

		public int compareTo(Edge e) {
			return cost - e.cost;
		}
	}

	static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int d, int u) {
			x = d;
			y = u;
		}

		public int compareTo(pair o) {
			return y - o.y;
		}

	}

	static class triple implements Comparable<triple> {
		int x;
		int y;
		int z;

		public triple(int a, int b, int c) {
			x = a;
			y = b;
			z = c;
		}

		public int compareTo(triple o) {
			return x - o.x;
		}
	}

	static int[] nxtarr() throws IOException {
		StringTokenizer st = new StringTokenizer(br.readLine());
		int[] a = new int[st.countTokens()];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		return a;
	}

	static long pow(long a, long e) // O(log e)
	{
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

	static int gcd(int a, int b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}
}


Measured memory_bytes: 66412
#include <bits/stdc++.h>
using namespace std;

int main() {
 string a;
 cin >> a;
  int cnt = 0;
  if(a.at(0) != 'A'){
    cout << "WA" << endl;
    return 0;
  }
  for(int i = 2; i < a.size()-1; i++){
   if(a.at(i) == 'C') cnt++;
  }
  if(cnt != 1){
    cout << "WA" << endl;
    return 0;
  }
int upper = 0;
for(int i = 0; i < a.size(); i++){
  if(isupper(a.at(i))) upper++;
}

  if(upper == 2) cout << "AC" << endl;
  else cout << "WA" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
    int N;
    cin >> N;

    int ans;
    if (1<= N and N < 2)
        ans = 1;
    else if (2<= N and N < 4)
        ans = 2;
    else if (4 <= N and N < 8)
        ans = 4;
    else if (8 <= N and N < 16)
        ans = 8;
    else if (16 <= N and N < 32)
        ans = 16;
    else if (32 <= N and N < 64)
        ans = 32;
    else if (64 <= N)
        ans = 64;
    
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace JOI
{
    class Sugoroku
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var X = Console.ReadLine().Split(' ');
            var M = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ');

            for (var i = 0; i < A.Length; i++)
            {
                if (Array.IndexOf(X, (int.Parse(X[int.Parse(A[i]) - 1]) + 1).ToString()) < 0 && int.Parse(X[int.Parse(A[i]) - 1]) < 2019)
                {
                    X[int.Parse(A[i]) - 1] = (int.Parse(X[int.Parse(A[i]) - 1]) + 1).ToString();
                }
            }


            for (var j = 0; j < N; j++)
            {
                Console.WriteLine(X[j]);
            }
        }
    }
}


Measured memory_bytes: 19712