akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
#define PI 3.1415926536
typedef long long ll;
typedef pair<int, int> P;

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<char>> a(N), b(M);
	rep(i, N) {
		a[i] = vector<char>(N);
		string s;
		cin >> s;
		rep(j, N) {
			a[i][j] = s[j];
		}
	}
	rep(i, M) {
		b[i] = vector<char>(M);
		string s;
		cin >> s;
		rep(j, M) {
			b[i][j] = s[j];
		}
	}
	rep(i, N-M+1)rep(j, N-M+1) {
		bool ok = true;
		rep(p, M)rep(q, M) {
			if (a[i + p][j + q] != b[p][q]) {
				ok = false;
				break;
			}
		}
		if (ok) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    String ans = "No";
    if(x % 2 == 1) {
      if(x < 9) {
        if(y == 8 || y == 10 || y == 12) ans = "Yes";
        if(y % 2 == 1 && y < 9) ans = "Yes";
      }
      if(x == 9) {
        if(y == 11) ans = "Yes";
      }
    }
    if(x % 2 == 0) {
      if(x > 2 && x < 8) {
        if(y == 9 || y == 11) ans = "Yes";
        if(y % 2 == 0 && y < 8) ans = "Yes";
      }
      if(x > 6 && x < 12) {
        if(y % 2 == 0) ans = "Yes";
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll MOD = 1e9 + 7;
// return a^b O(log b)
template<typename T>
T mypow(T a, T b){
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}

// nCk O(n + klogMOD)
long long comb(int n, int k){
    long long res = 1;
    k = std::min(n - k, k);
    for (int i = n - k + 1; i <= n; i++)
        res = (res * i) % MOD;
    for (int i = 1; i <= k; i++)
        res = (res * mypow(static_cast<long long>(i), static_cast<long long>(MOD - 2))) % MOD;
    return res;
}

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

    ll n, a, b;
    cin >> n >> a >> b;
    ll res = (mypow(2LL, n) - 1 + (MOD - comb(n, a)) % MOD + (MOD - comb(n, b)) % MOD) % MOD;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

const int MAX_N = 1e2+10;
const int MAX_W = 1e5+10;

struct Item
{
	int w;
	ll v;
};

int N, W;
ll dp[MAX_N][MAX_W];
Item items[MAX_N];

void solve() {
	for (int i = 0; i < N; ++i) {
		Item item = items[i];
		for (int w = 0; w <= W; ++w) {
			if (w < item.w) {
				dp[i+1][w] = dp[i][w];
			}
			else {
				dp[i+1][w] = max(dp[i][w], dp[i][w-item.w] + item.v);
			}
		}
	}
}


int main(int argc, char const *argv[])
{
	cin >> N >> W;
	for (int i = 0; i < N; ++i) {
		cin >> items[i].w >> items[i].v;
	}

	solve();

	cout << dp[N][W] << endl;
	return 0;
}

Measured memory_bytes: 79360
#include <iostream>
#include <stdint.h>

using namespace std;

int32_t A[200001];
int64_t cnt;

bool calc(int32_t i)
{
  int32_t X = A[i];
  if (X>i)
    return false;
  for (int j=0; j<X; ++j) {
    if (A[i-j] == (X-j))
      A[i-j] = 0;
    else if (A[i-j] < (X-j))
      return false;
    else
      break;
  }
  cnt += X;
  return true;
}

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

  cin >> A[0];
  if (A[0]!=0) {
    cout << -1 << endl;
    return 0;
  }
  
  cnt = 0;
  
  for (int32_t n=1; n<N; ++n) {
    cin >> A[n];
  }

  for (int32_t n=N-1; n>0; --n) {
    if (A[n] == 0)
      continue;
    
    if (!calc(n)) {
      cout << -1 << endl;
      return 0;
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}


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

typedef long long ll;

const int MAXN = 1 << 18; // 2.6e5
const int N = 200005;
ll seg[2 * MAXN], rj[N]; // root is seg[1]

int c[N], b[N];
ll n, a[N];

vector<int> g[N];

void build()
{
    for (int i = N - 1; i >= 0; i--)
        seg[i] = max(seg[i << 1], seg[i << 1 | 1]);
}

void update(int p, ll val)
{
    for (seg[p += N] = val; p > 0; p >>= 1)
        seg[p >> 1] = max(seg[p], seg[p ^ 1]);
}

ll query(int l, int r) // [l, r]
{
    ll res = -1e9;
    for (l += N, r += N; l <= r; l >>= 1, r >>= 1)
    {
        if (l & 1)
            res = max(res, seg[l++]);
        if (!(r & 1))
            res = max(res, seg[r--]);
    }
    return res;
}

void f(int p, int pr)
{
    int v = query(a[p], a[p]);

    int r = query(0, a[p] - 1);

    update(a[p], r + 1);

    rj[p] = query(0, N - 1);

    for (int i : g[p])
        if (i != pr)
            f(i, p);

    update(a[p], v);
}

int main()
{
    cin >> n;

    for (int i = 1; i <= n; ++i)
        cin >> a[i], c[i] = a[i];

    sort(c, c + n);
    for (int i = 1; i <= n; ++i)
        a[i] = lower_bound(c, c + n, a[i]) - c;

    for (int i = 0; i < n - 1; ++i)
    {
        int t1, t2;
        cin >> t1 >> t2;

        g[t1].push_back(t2);
        g[t2].push_back(t1);
    }

    f(1, -1);

    for (int i = 1; i <= n; ++i)
        cout << rj[i] << endl;
}

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

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

int main()
{
  int n;
  string str;
  
  cin >> n;
  while (n--){
    int out = 0, base = 0, point = 0;
    while (out < 3){
      cin >> str;
      if (str == "HIT"){
        if (base < 3) base++;
        else point++;
      }
      else if (str == "HOMERUN"){
        point += base + 1;
        base = 0;
      }
      else out++;
    }
    cout << point << endl;
  }
}

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

int INF=1000000,sx=0,sy=0,gx,gy;
queue<pair<int,int> > que;
vector<int> dx(4,0),dy(4,0);

int bfs(vector<vector<char> > &map,vector<vector<int> > &d){
    pair<int,int> p;
    p.first=sx;
    p.second=sy;
    d.at(sx).at(sy)=0;
    que.push(p);
    while(que.size()>0){
        p=que.front();
        que.pop();
        if(p.first==gx&&p.second==gy){
            return d.at(p.first).at(p.second);
        }
        for(int i=0;i<4;i++){
            int nx=p.first+dx.at(i),ny=p.second+dy.at(i);
            if(0<=nx&&nx<map.size()&&0<=ny&&ny<map.at(0).size()&&map.at(nx).at(ny)!='#'&&d.at(nx).at(ny)==INF){
                pair<int,int> np;
                np.first=nx;
                np.second=ny;
                que.push(np);
                d.at(nx).at(ny)=d.at(p.first).at(p.second)+1;
            }
        }
    }
    return -1;
}




int main(){
    int H,W,white=0;
    cin>>H>>W;
    vector<vector<char> > map(H,vector<char> (W));
    vector<vector<int> > d(H, vector<int>(W,INF));
    dx.at(0)=1;
    dx.at(2)=-1;
    dy.at(1)=1;
    dy.at(3)=-1;
    gx=H-1;
    gy=W-1;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>map.at(i).at(j);
            if(map.at(i).at(j)=='.'){
                white++;
            }
        }
    }
    int ans=bfs(map,d);
    if(ans==-1){
        cout<<"-1"<<endl;
    }
    else{
        cout<<white-ans-1<<endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<bool> f;
vector<vector<int> > g;
bool dfs(int v,int s){
  f[v] = true;
  //cout<<v<<" g:"<<g[v][0]<<" s:"<<s<<endl;
  //cout<<g[v].size()<<endl;
  for(auto i : g[v]){
    //cout<<v<<" i:"<<i<<" s:"<<s<<endl;
    if(s==i) return 1;
    //cout<<v<<" i:"<<i<<" s:"<<s<<"....2"<<endl;
    if(f[i])continue;
    if(dfs(i,s))return 1;
  }

  return 0;
}
int main(){
  int v,e,s,t;
  cin>>v>>e;
  g.resize(v);
  f.resize(v);
  bool flag =0;
  for(int i=0;i<e;i++){
    cin>>s>>t;
    g[s].push_back(t);
  }
  for(int i=0; i<v;i++){
    if(g[i].empty())continue;
    flag=dfs(i,i);
    //cout<<flag<<endl;
    if(flag)break;
    for(int i=0;i<v;i++)f[i]=false;
  }
  cout<<flag<<endl;

  return 0;
}



Measured memory_bytes: 3180
// #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")

#include <bits/stdc++.h>
using namespace std;

typedef long long int64;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double dl;
typedef pair<int,int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define uint(n) ((unsigned int)(n))
#define int64(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define dl(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)

const int INF=1061109567;
const int NINF=-1044266559;
const int64 LINF=4557430888798830399;
const dl eps=1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)

#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define Log(x,y) log(x)/log(y)
#define SZ(a) ((int)(a).size())
#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 repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define repd1(i,n) for(int i=((int)(n));i>=1;i--)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MINF(x) MS(x,63)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileio(x)\
	freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define fileio2(filename,name) fstream name(filename,ios::in|ios::out)
#define sqr(x) ((x)*(x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf

const int maxn=INF;

int d,t,s;

int main()
{
	cin>>d>>t>>s;
	cout<<(t*s>=d?"Yes":"No");

	return 0;
}

Measured memory_bytes: 3648
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut iter = buf.split_whitespace();
    let n = iter.next().unwrap().parse::<usize>().unwrap();
    let k = iter.next().unwrap().parse::<i64>().unwrap();
    let a = (0..n).map(|_| iter.next().unwrap().parse::<i32>().unwrap()).collect::<Vec<_>>();
    let mut res : i64 = 0;
    let m = 1000000007;
    let mul =  (k * (k-1) / 2) % m;
    for i in 0..n {
        for j in 0..n {
            if a[j] < a[i] {
                res = (res + mul) % m;
                if i < j { res = (res + k) % m; }
            }
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
import math
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

a, b, c, d, e = sorted((a, b, c, d, e), key=lambda x: x%10 if x%10>0 else 10, reverse=True)

ans = int(math.ceil(a / 10))*10 \
        + int(math.ceil(b / 10))*10 \
        + int(math.ceil(c / 10))*10 \
        + int(math.ceil(d / 10))*10 \
        + e
print(ans)


Measured memory_bytes: 3064
from typing import Set


class UnionFind:
    """Union-Find: O(α(N))"""

    __slots__ = ["_data_size", "_first_idx", "_parents"]

    def __init__(self, data_size: int, is_zero_origin: bool = True) -> None:
        self._data_size = data_size
        self._first_idx = 0 if is_zero_origin else 1
        self._parents = [-1] * (data_size + self._first_idx)

    def __getitem__(self, x: int) -> int:
        """Find the group (root) of vertex x."""
        while self._parents[x] >= 0:
            x = self._parents[x]

        return x

    def __len__(self) -> int:
        """Count the number of groups (roots)."""
        return len(self.groups)

    @property
    def groups(self) -> Set[int]:
        """Return the set of groups (roots)."""
        return {
            self[x] for x in range(self._first_idx, self._data_size + self._first_idx)
        }

    def is_connected(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are connected or not."""
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self[x], self[y]
        if x == y:
            return
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x

    def unite_all(self, *vertices: int) -> None:
        """Unite the groups of all of the given vertices."""
        x = vertices[0]
        for y in vertices[1:]:
            self.unite(x, y)

    def get_size(self, x: int) -> int:
        """Return the size of the group vertex x belongs."""
        return -self._parents[self[x]]


def unionfind():
    # https://judge.yosupo.jp/problem/unionfind
    # https://atcoder.jp/contests/practice2/tasks/practice2_a
    N, Q, *TUV = map(int, open(0).read().split())
    tree = UnionFind(N)
    res = []
    for t, u, v in zip(*[iter(TUV)] * 3):
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    unionfind()


Measured memory_bytes: 60808
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
// #include <stdio.h>


int main(){
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	int cnt = 1;
	int ans = n;
	for(int i=0;i<n; i++){
		std::cin >> a[i];
		if(a[i]==cnt){
			cnt++;
			ans--;
		}
	}
	if(ans==n) ans=-1;
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;

long long gcm(long long n, long long m) {
	if (n == 0) return m;
	else return gcm(m%n, n);
}



int main()
{
	long long a, b;
	while (cin >> a) {
		cin >> b;
		cout << gcm(a, b) << " " << (a*b) / gcm(a, b) << endl;
	}
		





}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

ll n,a,b;
ll h[111111];

bool ok(ll x){
  vector<ll> tmp;
  ll cnt=0;
  rep(i,n){
    if(h[i]-b*x>0){
      cnt+=(h[i]-b*x+a-b-1)/(a-b);
    }
  }
  return cnt<=x;
}

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>a>>b;
  rep(i,n){
    cin>>h[i];
  }
  ll lb=0,ub=1000000000;
  rep(hoge,100){
    ll mid=(lb+ub)/2;
    if(ok(mid))ub=mid;
    else lb=mid;
  }
  cout<<ub<<endl;
	return 0;
}


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

#define ll long long int
#define hell 1000000007
#define vi vector <ll>
#define pb push_back
#define pii pair<ll,ll>
#define vii vector <pii>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sep(i,a,b)  for(ll i=a-1;i>=b;i--)
#define inf (ll)(1e16)

using namespace std;

ll mi;

ll helper(vi &a,ll s,ll e,vector < vi > &dp)
{
    if(s>e)
        return dp[s][e]=0;
    if(s==e)
        return dp[s][e]=a[s];
    if(dp[s][e]!=-1)
        return dp[s][e];
    return dp[s][e]=max(a[s]-helper(a,s+1,e,dp),a[e]-helper(a,s,e-1,dp));
}

void solve()
{
    ll n;
    cin>>n;
    vi a(n);
    rep(i,0,n)
        cin>>a[i];
    vector < vi > dp(n+1,vi (n+1,-1));
    cout<<helper(a,0,n-1,dp);
}

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


Measured memory_bytes: 71040
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
 
typedef long long lld;
typedef vector<lld> vlld;
const lld mod=(lld)1e9+7;
 
int main() {
      lld n;
      cin>>n;
      vlld a(n),b(n);
      
      for(int i=0;i<n;i++)
      {
            cin>>a[i]>>b[i];
      }
      int f=0;
      for(int i=0;i<n;i++)
      {
          if(i+2<n && a[i]==b[i])
          {
                int c=3,j=i,p=0;
               while(c--)
               {
                     if(a[j]==b[j])
                     {
                          p++;    
                     }
                     j++;
               }
               if(p==3)
               {
                     f=1;
                     break;
               }
          }
      }
      if(f)
      cout<<"Yes";
      else
      cout<<"No";
      
      
      
 
  return 0;
}

Measured memory_bytes: 3632
dice=input().split()
q=int(input())

do = [(2,3,5,4), (6,3,1,4), (2,6,5,1), (2,1,5,6), (1,3,6,4), (2,4,5,3)]

def check(top, front):
    top_index=dice.index(top)
    front_index=dice.index(front)+1
    tmp=do[top_index]
    tmp_index=tmp.index(front_index)
   # print(top_index,front_index,tmp,tmp_index) 
    i = 0
    if tmp_index == 3:
        i = tmp[0]
    else:
        i = tmp[tmp_index+1]
    print(dice[i-1])


for i in range(q):
    top,front=input().split()
    check(top,front)


Measured memory_bytes: 5592
#include<iostream>
#include<cstring>
//#include<bits/stdc++.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#define  si(a)       scanf("%d",&a)
#define  sl(a)       scanf("%lld",&a)
#define  sii(a,b)    scanf("%d%d",&a,&b)
#define  sll(a,b)    scanf("%lld%lld",&a,&b)
#define  queues      priority_queue
#define mod 998244353
#define mem(a)  memset(a,0,sizeof(a));
#define def(a) ((a)&(-a))
#define fi  first
#define se  second
#define mp  make_pair
#define  pb push_back
#define mem(a,b) memset(a,b,sizeof(a));
typedef long long ll;
//priority_queue<ll,vector<ll >,greater<ll > >q;
const int INF=0x3f3f3f3f;
//const double E=exp(1);
//const double PI=acos(-1);
using namespace std;
//__builtin_popcount
//priority_queue
const ll MAX=100000;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll kc(ll a,ll b)
{
    ll c=1;
    while(b)
    {
        if(b&1)c=(c*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return c;
}
bool cmp(double x,double y)
{
    return x>y;
}
ll F[50003*3];
ll Find(ll a)
{
    return F[a]<0?a:F[a]=Find(F[a]);
}
ll same(ll a,ll b)
{
    if(Find(a)==Find(b))return 1;
    return 0;
}
ll up1(ll a,ll b)
{
    ll x,y;
    x=Find(a);
    y=Find(b);
    if(x!=y)
        F[x]=y;
    return 0;
}
int read() {
    int x=0,f=1;char s=getchar();
    for(;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1;
    for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';
    return x*f;
}

int main()
{
   // ios::sync_with_stdio(false);
    int t;
    cin>>t;
    int sum=0;
    for(int i=1;i<=t;i++)
    {
        int a;
        cin>>a;
        if(a!=i)sum++;
    }
    if(sum==2||sum==0)cout<<"YES\n";
    else cout<<"NO\n";
}



Measured memory_bytes: 256
#include<iostream>

int gcd(int a, int b){
  int r = a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

int main(){
  int a, b;
  std::cin >> a >> b;
  std::cout << gcd(a,b) << std::endl;

}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string a,b,c;
  cin>>a>>b;
  int i=0,cnt=0,ans=0;
  while(1)
  {
      if(cnt<a.size())
      {
          c+=a[i];
          cnt++;
      }
      if(ans<b.size())
      {
          c+=b[i];
          ans++;
      }
      i++;
      if(i>=(a.size()+b.size()))
      {
          break;
      }
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
L = []
id = []

for i in range(M) : 
    tmp = []
    tmp = list(map(int, input().split()))
    tmp.append(i)
    L.append(tmp)
    
LL = sorted(L)
num = []

for i in range(len(LL)) : 
    if i == 0 : 
        cnt = 1

    else : 
        if(LL[i][0] == LL[i-1][0]) : 
            cnt += 1
        else : 
            cnt = 1
        
    id.append(LL[i][2])
    num.append(str(LL[i][0]).zfill(6) + str(cnt).zfill(6))

numnum = [x for _ , x in sorted(zip(id, num))]

for x in numnum : 
    print(x)

Measured memory_bytes: 48304
#include<bits/stdc++.h>
#define inf 1000000000
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef map<int,int> mii;
int main()
{
    int i,j;
    int n,k;
    scanf("%d %d",&k,&n);
    vi vec;
    for(i=0;i<n;i++){
        scanf("%d",&j);
        vec.pb(j);

    }
    int mx=0;
    for(i=1;i<vec.size();i++)
        mx=max(mx,vec[i]-vec[i-1]);
    mx=max(mx,k+vec.front()-vec.back());
    printf("%d",k-mx);
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 2e5;
int n, rt = 1, mx[nsz + 5], pr[nsz + 5], ans[nsz + 5];
vector<int> g[nsz + 5];
map< pair<int, int>, int> dp0, dp1;

int qry0(int u, int w) {
    if (dp0.count(make_pair(u, w)))  return dp0[make_pair(u, w)];
    int &res = dp0[make_pair(u, w)];
    res = 1;
    loop (i, g[u].size()) {
        int v = g[u][i];
        if (v == pr[u] || v > w)  continue;
        res += qry0(v, w);
    }
    return res;
}

int qry1(int u, int w) {
    if (dp1.count(make_pair(u, w)))  return dp1[make_pair(u, w)];
    int &res = dp1[make_pair(u, w)];
    if (u > w)  return res = 0;
    res = 1;
    loop (i, g[u].size()) {
        int v = g[u][i];
        if (v == pr[u] || v > w)  continue;
        res += qry1(v, w);
    }
    return res;
}

void dfs(int u = rt) {
    loop (i, g[u].size()) {
        int v = g[u][i];
        if (v == pr[u])  continue;
        pr[v] = u;
        mx[v] = max(mx[u], u);
        dfs(v);
    }
    if (u == rt)  return;
    if (u > mx[u]) {
        ans[u] = qry0(u, mx[u]);
    } else if (pr[u] == mx[u]) {
        ans[u] = qry0(u, mx[u]) - qry1(u, mx[pr[u]]);
    } else {
        ans[u] = 0;
    }
}

void pre(int u = rt) {
    loop (i, g[u].size()) {
        int v = g[u][i];
        if (v == pr[u])  continue;
        ans[v] += ans[u];
        pre(v);
    }
}

int main() {
    scanf("%d", &n);
    cont (i, n - 1) {
        int u, v;
        scanf("%d%d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs();
    pre();
    circ (u, 2, n) {
        printf("%d ", ans[u]);
    }
}

Measured memory_bytes: 53376
#include<stdio.h>
int record[100000];
int main(){
	int n,x,y,min,i,j;
	scanf("%d %d %d",&n,&x,&y);
	for (i=1;i<=n-1;i++)
	  for (j=i+1;j<=n;j++){
	  	if (j<=x||i>=y)
	  	{ record[j-i]++;continue;}
	  	if (i<=x&&j>=y)
	  	{record[j-i-(y-x)+1]++;continue; }
	  	if (i<=x&&j<=y&&j>=x){
	  	  min=j-i;
	  	  if (x-i+1+y-j<min)
	  	    min=x-i+1+y-j;
	  	  record[min]++;
	  	  continue;
		  }
		if (i>=x&&i<=y&&j>=y){
			min=j-i;
			if (i-x+1+j-y<min)
			  min=i-x+1+j-y;
			record[min]++;
			continue;
		}
	  if (i>=x&&j<=y){
	  	min=j-i;
	  	if (i-x+1+y-j<min)
	  	  min=i-x+1+y-j;
	  	record[min]++;
	  	continue;
	  }
	  }
	for (i=1;i<=n-1;i++)
	  printf("%d\n",record[i]);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll N;
ll A[50];
int main(){
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  ll ans=0;
  while(1){
    sort(A,A+N);
    if(A[N-1]<N)break;

    //    cout<<ans<<' ';
    //    for(int i=0;i<N;i++)cout<<A[i]<<' ';
    //    cout<<endl;
    
    if(A[N-1]<N*2){
      A[N-1]-=N;
      for(int i=0;i<N-1;i++)A[i]++;
      ans++;
      continue;
    }
    
    
    ll tmp=0;
    for(int i=0;i<N;i++){
      if(A[i]<N)continue;
      ll v=A[i]/N;
      tmp+=v;
      A[i]-=v*N;
      A[i]-=v;
    }
    for(int i=0;i<N;i++)A[i]+=tmp;
    ans+=tmp;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
A,B,C = map(int, input().split())

ABC_lis = [A,B,C]
ABC_lis = sorted(ABC_lis)

ans = 0

while ABC_lis[0] < ABC_lis[1]:
    ABC_lis[0]=  ABC_lis[0] + 2
    ans = ans + 1

if ABC_lis[0] > ABC_lis[1]:
    ABC_lis[1] = ABC_lis[1] + 1
    ABC_lis[2] = ABC_lis[2] + 1
    ans = ans + 1

while ABC_lis[1] < ABC_lis[2]:
    ABC_lis[0] = ABC_lis[0] + 1
    ABC_lis[1] = ABC_lis[1] + 1
    ans = ans + 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

int main(){
vector<int> A(2);
rep(i,2){
	cin>>A[i];
  }
  rep(i,2){
	  if(A[i]==2){
		  A[i]=2;
		}
		else if(A[i]==4||A[i]==6||A[i]==9||A[i]==11){
			A[i]=1;
		  }
		  else{
			  A[i]=0;
			}
	}
	if(A[0]==A[1]){
	  cout<<"Yes"<<endl;
	  }
	  else {
		  cout<<"No"<<endl;
		}
}



Measured memory_bytes: 256
fun main(args: Array<String>){
    val input :MutableList<Int> = mutableListOf()
    repeat(5){
        input.add(readLine()!!.toInt())
    }
    var max = 0
    var index = 0
    for(i in 0..4){
        if(input[i] % 10 == 0){
        }
        else if(max < 10 - input[i]%10){
            max = 10 - input[i]%10
            index = i
        }
    }
    var time = 0
    for(i in 0..4){
        if(i == index){
        }
        else{
            time += input[i]
            if(input[i] % 10 != 0){
                time += 10 - input[i]%10
            }
        }
    }
    time += input[index]
    println(time)
}


Measured memory_bytes: 31868
#include<bits/stdc++.h>
using namespace std;
#define int long long

int N, K;
int A[200000];
int F[200000];

bool ok(int score) {
  int k = 0;
  for(int i=0; i<N; i++) {
    k += max(0LL, ((F[i]*A[i] - score) + (F[i]-1)) / F[i]);
  }
  return k<=K; 
}

signed main() {
  cin >> N >> K;
  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<N; i++) cin >> F[i];

  sort(A, A+N);
  sort(F, F+N, greater<int>());

  int l=0, r = 0;
  for(int i=0; i<N; i++) r = max(r, A[i]*F[i]);
  while (r-l>1) {
    int m = l + (r-l)/2;
    if(ok(m)) r=m;
    else      l=m;
  }
  if(ok(l)) r = l;
  cout << r << endl;
}


Measured memory_bytes: 3328
#include<stdio.h>
int main(){
  long int N,K;
  scanf("%ld %ld",&N,&K);
  
  N=N%K;
  if(N>K-N){
    printf("%ld\n",K-N);
  }
  else{
    printf("%ld\n",N);
  }
}
  

Measured memory_bytes: 128
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    l=parseMap(split(readline()))
    ans=0
    for i in 1:n
        for j in i+1:n
            for k in j+1:n
                if l[i]==l[k] || l[j]==l[k] || l[i]==l[j]
                    continue
                end
                if l[i]<l[j]+l[k] && l[j]<l[i]+l[k] && l[k]<l[i]+l[j]
                    ans+=1
                end
            end
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 164416
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <algorithm>

using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int st = a > c ? a : c;
	int en = b > d ? d : b;

	if (st > en) {
		cout << 0 << endl;
	}
	else {
		cout << en - st << endl;
	}
}


Measured memory_bytes: 256
n = int(input())
s = input()
c = [[0 for i in range(3)] for i in range(len(s))]
color = ['R','G','B']

for i in range(3):
	c[0][i] = (s[0]==color[i])

for i in range(1, len(s)):
	for j in range(3):
		if s[i]==color[j]:
			c[i][j] = c[i-1][j]+1
		else:
			c[i][j] = c[i-1][j]

res = 0
for i in range(len(s)-2):
	for j in range(i+1, len(s)-1):
		if s[i] != s[j]:
			for k in range(3):
				if s[i] != color[k] and s[j]!= color[k]:
					#print(i,j,k)
					res += c[n-1][k] - c[j][k]

					if 2*j-i<n:
						#possible principle 2 (j-1==k-j)
						res += -c[2*j-i][k] + c[2*j-i-1][k]

print(res)

	

Measured memory_bytes: 74708
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

  


void solve(void)
{
  int P = 50;
  vector<int> pow_2;
  for (int i = 0; i <= P; i++)
  {
    pow_2.push_back(pow(2,i));
  }
  
  int N;cin>>N;
  set<int> SET;
  vector<int> vec(N);
  map<int,int> mp;
  for (int i = 0; i < N; i++)
  {
    int X;cin>>X;
    SET.insert(X);
    mp[X]++;
    vec[i] = X;
  }
  sort(ALL(vec));
  int ANS = 0;
  for (int i = N-1; i >= 0; i--) 
  {
    int X = vec[i];
    if(mp[X] <= 0)continue;
    mp[X]--;
    if(mp[X] <= 0)
    {
      SET.erase(X);
    }

    int T = *upper_bound(ALL(pow_2),X);
    T -= X;
    if(SET.find(T) != SET.end())
    {
      if(mp[T] <= 0)continue;

      ANS++;
      mp[T]--;
      if(mp[T] <= 0)
      SET.erase(SET.find(T));
    }
  }

  cout<<ANS<<endl; 
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 23936
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n ;
  vi a(n),b(n),c(n);
  REP(i,n-1){
	  cin>>b[i];
	  if (i!=0){
		ans+=min(b[i],b[i-1]);
	  }
  }

  ans+=b[0];
  ans+=b[n-2];


  cout<<ans<<endl;
  return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

#define D  double
typedef pair<D,int>T;
int N;
int X[1111],Y[1111],R[1111];
D dist[1111];
D INF=1e15;
D EPS=1e-12;

int table2[1111][1111];
D table[1111][1111];

signed main(){

    cin>>X[0]>>Y[0]>>X[1]>>Y[1];
    cin>>N;
    rep(i,N)cin>>X[i+2]>>Y[i+2]>>R[i+2];
    N+=2;

    rep(i,N)rep(j,N){
        table2[i][j]=(X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]);
        table[i][j]=sqrt(1.0*table2[i][j]);
    }

    fill_n(dist,1111,INF);
    dist[0]=0;
    priority_queue<T,vector<T>,greater<T>>que;
    que.push(make_pair(0,0));
    while(que.size()){
        D d;
        int idx;
        tie(d,idx)=que.top();
        que.pop();
        if(dist[idx]+EPS<d)continue;
        rep(i,N){
            int foo=table2[i][idx];
            int bar=R[i]+R[idx];
            D cost;
            if(foo<=bar*bar)cost=0.0;
            else cost=table[i][idx]-bar;
            if(dist[i]>cost+dist[idx]){
                dist[i]=cost+dist[idx];
                que.push(T(dist[i],i));
            }
        }
    }
    printf("%.20f\n",dist[1]);
    return 0;
}


Measured memory_bytes: 21872
#include <iostream>

using namespace std;

int main(void){
  int n;
  cin>>n;
  int A[50];
  for(int i=0;i<50;i++){
    A[i]=0;
  }
  A[0]=1;
  A[1]=1;
  for(int i=2;i<=n;i++){
    A[i]=A[i-1]+A[i-2];
  }
  cout<<A[n]<<endl;
  return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string T, P;
    cin >> T >> P;
    for (int ti = 0; ti <= (int)(T.size() - P.size()); ti++) {
        int tmp = 0;
        for (int si = 0; si < (ll)P.size(); si++) {
            if (T[ti + si] == P[si]) {
                tmp++;
            }
        }
        // cout << ti << endl;
        if (tmp == (ll)P.size()) {
            cout << ti << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3224
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<list>
using namespace std;

int main() {
	int N, A, q = 0;
	cin >> N;
	cin >> A;
	q = N - 500 * (N / 500);
	if (N < 500) {
		if (N <= A)cout << "Yes\n";
		else cout << "No\n";
	}
	else {
		if (q <= A)cout << "Yes\n";
		else cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 384
<?php namespace Track;

function main($lines) {
  $vv = [];
  foreach ($lines as $index=>$value) {
    $vv[] = $value;
  }

  foreach($vv as $value){
    $count = 0;
    //   var_dump($value);
      if($value[0] == 0 && $value[1] == 0){
          break;
      }
      for($i=1; $i<=$value[0]; $i++){
          for($j=$i; $j<=$value[0]; $j++){
              for($k=$j; $k<=$value[0]; $k++){
                  if($i + $j + $k == $value[1] && $i != $j && $j != $k && $i != $k){
                    $count++;
                    // echo $i,$j,$k.PHP_EOL;
                  }
              }
          }
      }
    echo $count.PHP_EOL;
  }
}

$array = array();
while (true) {
  $stdin = fgets(STDIN);
  if ($stdin == "") {
    break;
  }
  $array[] = explode(" ",rtrim($stdin));
}
main($array);


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

int main(){
  int N; cin >> N;
  vector<int> H(N);
  int length; length = 0;
  for(int i=0; i < N; i++){
    cin >> H[i];
    length += H[i];
  }
  int maax; maax = *max_element(H.begin(), H.end());
  length -= 2 * maax;
  if(length > 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int a=0,b=0;
string s,u="",t="";
cin >> s;
for(int i=0;i<s.size();i++){
    if(i%2==0){
        t+='0';
        u+='1';
    }
    else if(i%2==1){
        t+='1';
        u+='0';
    }
}

for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
        a++;
    }
    if(s[i]!=u[i]){
        b++;
    }
}
cout << min(a,b) << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 848
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector< vector<int> > VVI;
typedef vector< vector<int> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair

int main(){
  int N;
  cin>>N;
  VI A(N),B(N);
  rep(i,N) cin>>A[i]>>B[i];
  ll ans=0;
  VL X(N);
  rep(i,N) X[i]=A[i]+B[i];
  sort(all(X));
  rep(i,(N+1)/2) ans+=X[N-1-i*2];
  rep(i,N) ans-=B[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
function main (s) {
	s=s.split(" ");
	var a,b;
	a=parseInt(s[0]);
	b=parseInt(s[1]);
	console.log(((a*b)%2==0)?"Even\n":"Odd\n");
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline int read() {
	int x = 0, fh = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fh = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + c - '0';
		c = getchar();
	}
	return x * fh;
}
const int N = 1010;
int n, ans, i, a[N];
int main() {
    n = read();
    for (i = 1; i <= n * 2; i++) a[i] = read();
    sort (a + 1, a + 1 + n * 2);
    for (i = 1; i <= n * 2; i += 2) ans += a[i];
    cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int a, b, c, d;
string s;
/**********************************************/

int main(){
    cin >> a >> b >> c >> d;
//    cout << a+b << " " << c+d << endl;
    if(a+b > c+d){
        cout << "Left" << endl;
    }else if(a+b < c+d){
        cout << "Right" << endl;
    }else{
        cout << "Balanced" << endl;
    }
}


Measured memory_bytes: 256
/*
created by sanyam singhal
*/

#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long int
#define mod 1000000007
#define w(t) int t;	cin>>t while(t--)
#define triplet pair<int,pair<int,int>>
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define fastIO ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
#define loop(i, k, n) for(ll i=k; i<n; i+=1)
#define loop2(i, k, n) for(ll i=k; i>=n; i--)

const ll inf = 1e18;
int dp[3005][3005];

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

string getLCS(string &s, string &t){
  int n = s.size();
  int m = t.size();
  // cout<<len<<endl;
  int i=n, j=m;
  int len = dp[n][m];
  string ans = "";

  while(i>0 && j>0) {
    // cout<<i<<" "<<j;
    if(s[i-1]==t[j-1]) {
      // cout<<"-1\n";
      ans += s[i-1];
      // cout<<s[i-1];
      i--; 
      j--;
      len--;
    }
    else {
      // cout<<"-2\n";
      if(dp[i-1][j] > dp[i][j-1])
        i--;
      else
          j--;
    }
    // cout<<endl;
  }
  // cout<<"remain len = "<<len<<endl;
  reverse(ans.begin(), ans.end());
  return ans;
}

int LCS(string &s, string &t, int n, int m){
  if(n==0 || m==0)
    return dp[n][m] = 0;
  else if(dp[n][m]!=-1)
    return dp[n][m];
  else{
    if(s[n-1]==t[m-1]){
      return dp[n][m] = 1 + LCS(s, t, n-1, m-1);
    }
    else{
      return dp[n][m] = max(LCS(s, t, n-1, m), LCS(s, t, n, m-1));
    }
  }
}

void solve(){
  string s,t;
  cin>>s>>t;
  memset(dp, -1, sizeof(dp));
  int n = s.size();
  int m = t.size();
  int x = LCS(s, t, n, m);

  // for(int i=0; i<=m; i++){
  //   for(int j=0; j<=m; j++){
  //     if(dp[i][j]==-1)
  //       cout<<"0 ";
  //     else
  //       cout<<dp[i][j]<<" ";
  //   }
  //   cout<<endl;
  // }

  cout<<getLCS(s, t)<<endl;
}

int main(){

  fastIO;
  //take_fileIO();

  solve();

  return 0;
}

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

int main(){
    int N;
    cin >> N;
    int a[N];

    int max, min;

    for(int i=0; i<N; i++){
        cin >> a[i];
        if( i==0 ){
            max=a[i];
            min=a[i];
        }else{
            if( max < a[i] ){
                max = a[i];
            }
            if( min > a[i] ){
                min = a[i];
            }
        }
    }

    cout << max-min << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
K += 1
k = K.bit_length()
K_bit = [(K >> i) & 1 for i in range(k)]  # Kのbitのリスト(下から)
A = LI()
A_bit = [[(A[i] >> j) & 1 for j in range(k)] for i in range(N)]  # Aiたちのbitのリスト(下から)

X = [0]*(k+1)  # 下i桁で最適なもの
for i in range(k):
    a = sum(A_bit[j][i] == 0 for j in range(N))  # 0の個数
    X[i+1] = X[i]
    if a >= N//2+1:
        X[i+1] += 2**i


def f(x):
    return sum(x^A[i] for i in range(N))


ans = 0
for i in range(k-1,-1,-1):
    if K_bit[i] == 1:
        ans = max(ans,f(((K >> (i+1)) << (i+1))+X[i]))

print(ans)


Measured memory_bytes: 130816
#include<iostream>
using namespace std;
int data[2000001],size;
void fswap(int *x,int *y){
  int tmp;
  tmp=*x;
  *x=*y;
  *y=tmp;
}
void maxheap(int x){
  int left=2*x,right=2*x+1,largest=x;
  if(left<=size&&data[left]>data[x]) largest=left;
  if(right<=size&&data[right]>data[largest]) largest=right;
  if(largest!=x){
    fswap(&data[x],&data[largest]);
    maxheap(largest);
  }
}
void extract(){
  data[1]=data[size--];
  maxheap(1);
}
void insert(int x){
  data[++size]=x;
  int cur=size;
  while(cur!=1&&data[cur]>data[cur/2]){
    fswap(&data[cur],&data[cur/2]);
    cur/=2;
  }
}
int main(){
  char s[8];
  while(cin>>s&&(s[0]!='e'||s[1]!='n')){
    if(s[0]=='i'){
      int x; cin>>x;
      insert(x);
    }else{
      cout<<data[1]<<endl;
      extract();
    }
  }
  return 0;
}



Measured memory_bytes: 6928
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

c = input()
boin = ["a", "i", "u", "e", "o"]
if c in boin:
	print("vowel")
else:
	print("consonant")

Measured memory_bytes: 3904
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 3e5 + 5;

ll A[N];

ll s[61], u[61];

int main()
{
    fast;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

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

    for (int j = 0; j < n; j++) {
        for (ll i = 0; i < 61; i++) {
            if (A[j] & (1LL << i))
                s[i]++;
            else
                u[i]++;
        }
    }

    ll ans = 0;

    for (ll i = 0; i < 61; i++) {
        ans = (ans + (((s[i] * u[i]) % mod) * ((1LL << i) % mod)) % mod) % mod;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 2560