akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <stdint.h>

#pragma optimize("O3")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

#define sync                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define MP make_pair
#define endl '\n'

const ll MOD = 998244353;
const ll INF = 1e12+1;
const int base = 2e5+1;
const ll MAX = 3*1e5+1;
const double EPS = 1e-9;
const double PI = acos(-1.);
const ll MAXN = 1e5;





int main()
{
    int n;
    ll res = 0;
    cin >> n;
    vector<string> s(n);
    vi t(n);
    FOR(i,0,n) cin >> s[i] >> t[i];
    string x;
    cin >> x;
    bool was = 0;
    FOR(i,0,n)
    {
        if(was) res += t[i];
        if(s[i] == x) was = 1;
    }
    cout << res;
    return 0;
}








Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int mod=1e9+7;
int main(){
    ll h,w;cin>>h>>w;
    vector<vector<ll> >a(h,vector<ll>(w));
    rep(i,h){
        rep(j,w)cin>>a[i][j];
    }
    rep(i,h){
        rep(j,w){
            ll x;cin>>x;
            a[i][j]-=x;
        }
    }
    vector<vector<vector<ll> > >dp(h,vector<vector<ll> >(w,vector<ll>(160*160)));
    ll k=80*160;
    dp[0][0][k-a[0][0]]=1;
    dp[0][0][k+a[0][0]]=1;
    rep(i,h){
        rep(j,w){
            rep(l,160*160){
                if(dp[i][j][l]){
                    if(l+a[i][j]<160*160){
                        if(i+1<h)dp[i+1][j][l+a[i+1][j]]=1;
                        if(j+1<w)dp[i][j+1][l+a[i][j+1]]=1;
                    }
                    if(l-a[i][j]>=0){
                        if(i+1<h)dp[i+1][j][l-a[i+1][j]]=1;
                        if(j+1<w)dp[i][j+1][l-a[i][j+1]]=1;
                    }
                }
            }
        }
    }
    ll ans=inf;
    rep(i,160*160){
        if(dp[h-1][w-1][i]){
            ans=min(abs(k-i),ans);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 648704
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
               int count = 0;
               for ( int i = 0; i < 6; i++ ) {
                   char c = s.charAt(i);
                   if ( c == '1' ) count++;
               }
               System.out.println(count);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 INF=1001001001;

int main() {
  int N,M;
  cin>>N>>M;
  vector<int>ans(N);
  vector<bool>used(N,false);
  if(N>1){ans[0]=1;}
  for(int i=0;i<M;i++){
    int s,c;
    cin>>s>>c;
    s--;
    if(N>1&&s==0&&c==0){cout<<-1<<endl;return 0;}
    if(used[s]&&ans[s]!=c){cout<<-1<<endl;return 0;}
    used[s]=true;
    ans[s]=c;
  }
  for(int i=0;i<N;i++){
    cout<<ans[i];
  }cout<<endl;
  return 0;  
}

Measured memory_bytes: 3588
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

t = 0
pre = -1
for i in range(n):
    a_ = a[i] - 1
    t += b[a_]
    if i > 0 and a_ - 1 == pre:
        t += c[pre]
    pre = a_
print(t)


Measured memory_bytes: 3064
# 少しひっかけ問題っぽいです。
n = int(input())
p = list(map(int, input().split()))
a = 0
# 配列の最初と最後は除外する。
for i in range(1, n-1):
    # 配列の２番目なので、２通りを判定する。
    if (p[i-1] < p[i] < p[i+1]) or (p[i+1] < p[i] < p[i-1]):
        a += 1
print(a)


Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
#define fast                         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int                          long long int
#define double                       long double
#define ff                           first
#define ss                           second
#define pb                           push_back
#define eb                           emplace_back
#define all(x)                       (x).begin(), (x).end()
#define sz(x)                        ((int)(x).size())
#define len(x)                       ((int)(x).length())
#define pii                          pair<int,int>
#define vi                            vector<int>
#define vd                           vector<double>
#define vs                            vector<string>
#define mp                          map<int,int>
#define ms(x,y)                     memset(x,y,sizeof(x))
#define ump                         unordered_map<int,int>

#define lb                            lower_bound
#define ub                            upper_bound
#define nx                            cout<<"\n";
#define inf                           9223372036854775807
#define PI                            3.14159265

const int MOD = 1e9 + 7;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
inline int add(int a, int b) {    return ((a % MOD) + (b % MOD)) % MOD;}

inline int multi(int a, int b) {   return ((a % MOD) * (b % MOD)) % MOD;}

inline int sub(int a, int b) {       a %= MOD; b %= MOD; a -= b; if (a < 0) a += MOD; return a;}

inline int power(int a, int b) {       a %= MOD; int res = 1; while (b > 0) {if (b & 1) {res = multi(res, a);} a = multi(a, a); b >>= 1;}  return res;}

bool isPrime(int  x) {      if (x <= 4 || x % 2 == 0 || x % 3 == 0) {return x == 2 || x == 3;} for (int i = 5; i * i <= x; i += 6) {if (x % i == 0 || x % (i + 2) == 0) { return 0;}} return 1;}

double dp[305][305][305];

double solve(int i, int j, int k, int n)
{
  if (i + j + k == 0)return 0;
  if (dp[i][j][k] > -0.5)return dp[i][j][k];
  double ans = 0;
  double m = (double)n / (i + j + k);
  if (i) {
    ans += (solve(i - 1, j, k, n) + 1) * ((double)i / n);
  }
  if (j) {
    ans += (solve(i + 1, j - 1, k, n) + 1) * ((double)j / n);
  }
  if (k) {
    ans += (solve(i, j + 1, k - 1, n) + 1) * ((double)k / n);
  }
  ans += (1 - (1.0 / m));
  ans *= m;
  return dp[i][j][k] = ans;
}
int32_t main()
{
  fast ;


  int n; cin >> n;
  int a(0), b(0), c(0);
  ms(dp, -1);
  for (int i = 0; i < n; i++)
  {
    int x; cin >> x;
    if (x == 1)a++;
    else if (x == 2)b++;
    else c++;
  }
  cout << fixed << setprecision(12) << solve(a, b, c, n);



}



Measured memory_bytes: 443648
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char const* argv[]) {
    int N, a;
    std::cin >> N;
    a = 0;
    for (size_t i = 1; i < N + 1; i++) {
        a += i;
    }
    std::cout << a;


    return 0;
}

Measured memory_bytes: 256
program main
      implicit none
      integer(8) :: n, k, i, j
      integer(16) :: sta, fin
      integer(16) :: cnt

      read *, n, k

      cnt = 0
      do j = k, n+1
        sta = j*(j-1)/2
        fin = (n+1)*n/2 - (n+1-j)*(n-j)/2
        cnt = cnt + fin-sta+1
      end do

      print *, mod(cnt,1000000007)

end program main


Measured memory_bytes: 2772
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define rrep(i, a, b) for(ll i = a; i >= b; i--)
typedef long long int ll;
typedef vector< ll > vi;

int main() {
	ll n, wt;
	cin >> n >> wt;
	ll w[n], v[n];
	rep(i, 0, n) cin >> w[i] >> v[i];
	ll tot = 0;
	for(ll &i : v) tot += i;
	vi dp(tot + 5, 1e18+5);
	dp[0] = 0;
	rep(i, 0, n) rrep(val, (tot - v[i]), 0) dp[val + v[i]] = min(dp[val + v[i]], dp[val] + w[i]);
	ll ans = 0;
	rep(val, 0, (tot + 1)) if(dp[val] <= wt) ans = val;
	cout << ans << endl;
}


Measured memory_bytes: 1024
import java.io.*;

public class Main{
 public static void main(String[] args){
	try{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String[] str = br.readLine().split(" ");
	
	int a = Integer.parseInt(str[0]);
	int b = Integer.parseInt(str[1]);

	System.out.println(a*b + " " + 2*(a+b));
	
	}catch(IOException e){
	
	System.out.println(e);
	} 
	
 }
}

Measured memory_bytes: 17056
// aribon2-1_a
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define debug(x) cout << #x << ": " << (x) << endl
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define all(x) x.begin(), x.end()
#define INF ((1 << 16)-1)
#define MOD (1000000007)
#define print(arr, n) REP(i, n) cout << arr[i] << " ";

struct PreMain {PreMain(){std::cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    std::ifstream in("../arg.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    string s;
    cin >> s;

    int N = 1 << (s.size() - 1);
    ll ans = 0;
    REP(x, N){
        int n = x;
        ll tmp = s[0] - '0';
        REPN(i, 1, s.size()) {
            if (n & 1) {
                ans += tmp;
                tmp = s[i] - '0';
            } else {
                tmp = 10 * tmp + s[i] - '0';
            }
            n >>= 1;
        }
        ans += tmp;
    }
    cout << ans << endl;

    return 0;
}




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

#define ff first
#define ss second
#define mp make_pair
#define MOD 1000000007
#define oo 1000000000000000000

using namespace std;

const int N = 100005;

int n;

vector<int> g[N];

vector<int> bfs(int s){
    vector<int> dist(n+1, -1);
    queue<int> q;
    q.push(s);
    dist[s] = 0;
    
    while(!q.empty()){
        int u = q.front(); q.pop();
        for(int v: g[u]){
            if(dist[v] == -1){
                dist[v] = dist[u]+1;
                q.push(v);
            }
        }
    }
    return dist;
}

int main(){

    scanf("%d", &n);

    for(int i = 1; i < n; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> d1 = bfs(1);
    vector<int> d2 = bfs(n);

    int l = 0, r = 0;
    for(int i = 1; i <= n; i++){
        if(d1[i] <= d2[i]) l++;
        else r++;
    }

    if(l > r) printf("Fennec\n");
    else if(r >= l) printf("Snuke\n");




    return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int T;
	cin >>T;
	Rep0(tt, T) {
		int N;
		cin >>N;
		vector<ll> A(N, 0);
		Rep0(i, N)
			cin >>A.at(i);
		string S;
		cin >>S;
		Rev(A);
		Rev(S);
		if (S.at(0)=='1') {
			cout <<1 <<endl;
			continue;
		}
		set<ll> D0;
		bool OK=true;
		D0.insert(0);
		Rep0(i, N) {
			ll AA=A.at(i);
			auto itr=D0.end();
			Rep0(i, D0.size()) {
				itr--;
				AA=min(AA, AA^*itr);
			}
			if ('0'==S.at(i)) {
				if (AA!=0)
					D0.insert(AA);
			} else {
				if (AA!=0) {
					OK=false;
					break;
				}
			}
		}
		if (OK)
			cout << 0 <<endl;
		else
			cout << 1 <<endl;
	}
	return 0;
}



Measured memory_bytes: 3572
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")

#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

inline void setin(string s) {
	freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
	freopen(s.c_str(), "w", stdout);
}

template <typename T> inline T range(T l, T r) {
	return uniform_int_distribution <T>(l, r)(rng);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 2e5 + 15;
int n, a[N], pos[N], r_of[N];

vector <int> ans;

set <pii> is;

struct segment_tree {
	pii t[N << 2];
	segment_tree() {
		fill(t, t + (N << 2), mp(inf, inf));
	}
	void update(int v, int tl, int tr, int pos, int val) {
		if(tl == tr)
			t[v] = {val, pos};
		else {
			int mid = tl + tr >> 1;
			if(pos <= mid)
				update(v << 1, tl, mid, pos, val);
			else
				update(v << 1 | 1, mid + 1, tr, pos, val);
			t[v] = min(t[v << 1], t[v << 1 | 1]);
		}
	}
	pii get(int v, int tl, int tr, int l, int r) {
		if(tl > r || tr < l || l > r)
			return {inf, inf};
		if(tl >= l && tr <= r)
			return t[v];
		int mid = tl + tr >> 1;
		return min(get(v << 1, tl, mid, l, r), get(v << 1 | 1, mid + 1, tr, l, r));
	}
} t[2];

inline void add(int l) {
	pii nxt = t[l & 1].get(1, 0, n - 1, l, r_of[l]);
	if(nxt.f != inf)
		is.insert({nxt.f, l});
}

inline void upd(int i, int j, int l) {
	t[i & 1].update(1, 0, n - 1, i, inf);
	t[j & 1].update(1, 0, n - 1, j, inf);

	r_of[j + 1] = r_of[l];
	add(j + 1);

	r_of[l] = i - 1;
	add(l);

	r_of[i + 1] = j - 1;
	add(i + 1);
}

inline void solve() {
	while(!is.empty()) {
		int l = is.begin()->se;
		int i = pos[is.begin()->f];
		is.erase(is.begin());
		pii nxt = t[(i & 1) ^ 1].get(1, 0, n - 1, i + 1, r_of[l]);
		assert(nxt.f != inf);
		upd(i, nxt.se, l);
		ans.pb(a[i]);
		ans.pb(nxt.f);
	}
}

main() {
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	// setin("input.txt");
	cin >> n;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		t[i & 1].update(1, 0, n - 1, i, a[i]);
		pos[a[i]] = i;
	}
	r_of[0] = n - 1;
	add(0);

	solve();
	for(int i : ans)
		cout << i << ' ';
	return 0;
}

Measured memory_bytes: 19060
#include <bits/stdc++.h>
//#define int long long
#define rep(i, l, r) for(int i = l; i <= r; ++ i)
using namespace std;
const int MAXN = 1e5 + 10, mod = 1e9 + 7, INF = 1e9;

signed main()
{
	int x;
	scanf("%d", &x);
	if(x == 0) puts("1");
	else if(x == 1) puts("0"); 
	return 0;
}


Measured memory_bytes: 3760
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n; cin >> n;
    int now; cin >> now;
    int ans = 0;
    rep(i, n - 1) {
        int a; cin >> a;
        if(a >= now) now = a;
        else {
            ans += now - a;
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int G[101][101];
int d[101];
int f[101];
bool flag[101];
int n,v,k,p;
int t;

void check(int i){
	if(flag[i])return;
	flag[i]=true;
	t++;
	d[i]=t;
	for(int j=1;j<=n;j++){
		if(G[i][j]==1)check(j);
	}
	t++;
	f[i]=t;
	return;
}


int main(){
	cin >>n;
	for(int i=0;i<n;i++){
		cin >> v>>k;
		for(int j=0;j<k;j++){
			cin >> p;
			G[v][p]=1;
		}
	}
	t=0;
	for(int i=1;i<=n;i++)check(i);
	for(int i=1;i<=n;i++){
		cout << i<< " "<<d[i]<< " "<<f[i] <<endl;
	}
}

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

int N;
vector<pair<int,int> > G[100001];

bool visited[100001];
int col[100001];

void dfs(int v){
    pair<int,int> pa;
    int ta,we;
    int i;
    for(i=0; i<G[v].size(); i++){
        pa=G[v][i];
        ta=pa.first;
        we=pa.second;
        if(visited[ta]==0){
            visited[ta]=1;
            if(we==1){
                col[ta]=(!col[v]);
            }else{
                col[ta]=col[v];
            }
            dfs(ta);
        }
    }
}

int main(){
    //input
    cin >> N;
    int u,v,w;
    int i;
    for(i=0; i<N-1; i++){
        cin >> u >> v >> w;
        G[u].push_back(make_pair(v,w%2));
        G[v].push_back(make_pair(u,w%2));
    }

    //calc
    fill(visited,visited+N+1,0);
    visited[1]=1;
    col[1]=1;
    dfs(1);

    //output
    for(i=1; i<=N; i++){
        cout << col[i] << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 11672
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

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

  // int num = 0;

  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int x3, y3, x4, y4;

  x3 = x2 - (y2 - y1);
  y3 = y2 + (x2 - x1);
  x4 = x1 - (y2 - y1);
  y4 = y1 + (x2 - x1);

  cout << to_string(x3) + " " + to_string(y3) + " " + to_string(x4) + " " + to_string(y4) << endl;

  
  // cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
map<ll,int>mp,g;
ll f[N];
ll C[N][N];
void solve(int n){
	for(int i=1;i<=n;i++) C[i][0]=C[i][i]=1;
	for(int i=2;i<=n;i++)
		for(int j=1;j<i;j++)
			C[i][j]=C[i-1][j]+C[i-1][j-1];	
}
int main(){
	ll n;int a,b;
	solve(50);
	cin>>n>>a>>b;
	map<ll,int>::reverse_iterator it;
	for(int i=1;i<=n;i++){
		cin>>f[i],mp[f[i]]++;
	}
	sort(f+1,f+n+1,greater<ll>());
	ll cnt=0,x=0;
	for(int i=1;i<=a;i++){
	   x+=f[i];
	   if(f[i]==f[a]) cnt++;
	}
	printf("%.6f\n",(double)x/a);
	ll c=0;
	x=f[a];
	if(cnt<a) c=C[mp[x]][cnt];
	else {
		for(int i=a;i<=b&&mp[x]>=i;i++){
			c+=C[mp[x]][i];
		}
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3952
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int time,num;
    cin>>time>>num;
    vector<int> line(num+1,0);
    for(int i=0;i<time;++i){
        int a,b;
        cin>>a>>b;
        for(int j=0;j<=num-b;++j){
            line[j+b]=max(a+line[j],line[j+b]);
        }
    }
    int ans=0;
    for(int i=0;i<num+1;++i){
        ans = max(ans,line[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3120
n,m=map(int,input().split())
x=[0]*n
x[0]=1
y=[1]*n
for i in range(m):
  a,b=map(int,input().split())
  if x[a-1]==1:x[b-1]=1
  y[a-1]-=1
  y[b-1]+=1
  if y[a-1]==0:x[a-1]=0
print(sum(x))

Measured memory_bytes: 4596
#include <cstdio>
#include <cstdlib>
#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>
#include <list>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
// using namespace boost::multiprecision;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define isu isupper
#define isl islower
#define lb(a,k) lower_bound(all(a),k)
#define ub(a,k) upper_bound(all(a),k)
#define bs(a,k) binary_search(all(a),k)
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

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

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

bool ok(ll N, ll K, vl a, ll mid) {
    ll ck = 0;
    rep (i, N) ck += (a[i]-1)/mid;
    return ck <= K;
}

int main() {
    ll N, K;
    cin >> N >> K;

    vl a(N);
    ll m = 0;
    rep (i, N) {
        cin >> a[i];
        chmax(m, a[i]);
    }

    // l:NG, r:OK
    int l = 0, r = m+1;
    while (r-l > 1) {
        ll mid = (l+r)/2;
        (ok(N, K, a, mid) ? r : l) = mid;
    }

    cout << r << endl;
}


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

//{{{
#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// clang-format off
void _print() { cerr << "]\033[0m\n"; }
template <typename T> void __print(T x) { cerr << x; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifdef LOCAL
#define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x)
#define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n"
#else
#define debug(x...)
#define debug_arr(x...)
#endif
// clang-format on
//}}}

int T;

const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int n, q;

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    while (cin >> n)
    {
        int ans = -1;
        for (int i = 0; i <= 1000; i++)
        {
            if (i * 1000 >= n)
            {
                ans = i * 1000 - n;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
  int l, r;
  cin >> l >> r;
  int ans = 0;
  if (r-l < 2019 && l%2019 < r%2019){
    ans = 2019;
    for (int i = l; i <= r; i++){
      for (int j = i+1; j <= r; j++){
        if(ans > (i%2019)*(j%2019)%2019){
          ans = (i%2019)*(j%2019)%2019;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define pie 3.1415926535897
 
 void koch(int n,double p1x,double p1y,double p2x,double p2y){
       double sx,sy,tx,ty,ux,uy,th;
       if(n==0)return;
       th=pie*60.0/180.0;
       sx=(p1x*2.0+p2x*1.0)/3.0;
       sy=(p1y*2.0+p2y*1.0)/3.0;
       tx=(p1x*1.0+p2x*2.0)/3.0;
       ty=(p1y*1.0+p2y*2.0)/3.0;
       ux=(tx-sx)*cos(th)-(ty-sy)*sin(th)+sx;
       uy=(tx-sx)*sin(th)+(ty-sy)*cos(th)+sy;
       koch(n-1,p1x,p1y,sx,sy);
       printf("%f %f\n",sx,sy);
       koch(n-1,sx,sy,ux,uy);
       printf("%f %f\n",ux,uy);
       koch(n-1,ux,uy,tx,ty);
       printf("%f %f\n",tx,ty);
       koch(n-1,tx,ty,p2x,p2y);
       }
                    
 
 int main(){
       int n;
       double p1x;
       double p1y;
       double p2x;
       double p2y;
       p1x=0.0;
       p1y=0.0;
       p2x=100.0;
       p2y=0.0;
        
       scanf("%d",&n);
       printf("%f %f\n",p1x,p1y);
       koch(n,p1x,p1y,p2x,p2y);
       printf("%f %f\n",p2x,p2y);
       return 0;
       }


Measured memory_bytes: 2140
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,k;cin>>n>>k;
  V<ll> v(n);rep(i,0,n)cin>>v[i];

  ll ok=INF,ng=0,mid;
  while(abs(ok-ng)>1){
    mid=(ok+ng)/2;
    ll cnt=0;
    rep(i,0,n){
      cnt+=((v[i]+mid-1)/mid)-1;
    }

    if(cnt<=k)ok=mid;
    else ng=mid;
  }
  cout<<ok<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000
const int MAX = 10000000;
ll fac[MAX], finv[MAX], inv[MAX];
const int mod = 1e9 + 7;
bool is_prime(int n) {
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) return false;
	}
	return n != 1;
}

vector<int> divisor(int n) {
	vector<int> res;
	for(int i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			res.push_back(i);
			if(i != n / i) res.push_back(n / i);
		}
	}
	return res;
}

map<ll, ll> prime_factor(int n) {
	map<ll, ll> res;
	for(int i = 2; i * i <= n; i++) {
		while(n % i == 0) {
			++res[i];
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

int eratosthenes(int n) {
	bool is_prime[n + 1];
	memset(is_prime, true, sizeof(is_prime));
	// prime[n];

	is_prime[0] = is_prime[1] = false;
	int ans = 0;
	rep(i, 2, n + 1) {
		if(is_prime[i]) {
			// prime[ans++] = i;
			ans++;
			for(int j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
	return ans;
}


void comInit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	rep(i, 2, MAX) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

ll comb(ll n, ll k) {
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	comInit();
	int N, M;
	cin >> N >> M;
	map<ll, ll> m = prime_factor(M);
	ll rsl = 1;
	for(map<ll, ll>::iterator it = m.begin(); it != m.end(); it++) {
		rsl *= (comb(N + it->second - 1, N - 1) % mod);
		rsl %= mod;
	}
		
	cout << rsl << endl;
}


Measured memory_bytes: 234624
from collections import deque
n,m,=map(int,input().split())
p=list(map(int,input().split()))
way=[[] for _ in range(n)]
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    way[x].append(y)
    way[y].append(x)
ans=0
top=[False]*n
for i in range(n):
    l=deque([i])
    s=set([])
    t=set([])
    while l:
        now=l.popleft()
        for to in way[now]:
            if top[to]:
                continue
            else:
                top[to]=True
                l.append(to)
                s.add(to)
                t.add(p[to]-1)
    ans+=len(s&t)
cnt=0
for i in range(n):
    if top[i]:
        continue
    else:
        if i+1==p[i]:
            cnt+=1
print(ans+cnt)

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

using ll = long long;
using P = pair<ll, ll>;

const ll MAX = 1e5;
const ll INF = 1e9;

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

// 最大公約数（a > b）
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  int N;
  cin >> N;
  ll a[N];
  for (int i = 0; i < N; i++) scanf("%lld", a + i);

  sort(a, a + N);
  ll ans = gcd(a[1], a[0]);
  for (int i = 2; i < N; i++) {
    ans = gcd(max(ans, a[i]), min(ans, a[i]));
  }

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


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i,n) cin >> A[i];

    int cost_mi=1e9;
    for(int x=-100; x<=100; x++){
        int cost = 0;
        rep(j,n) cost+=pow(abs(A[j]-x), 2);
        cost_mi = min(cost_mi, cost);
    }
    cout << cost_mi << endl;
    
    return 0;
}

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

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0 ; i<N ; i++)
    cin >> A.at(i);
  
  vector<int> left(N, 0), right(N, 0);
  left.at(0) = 0;
  right.at(N-1) = 0;
  for (int i=0 ; i<N-1 ; i++)
    left.at(i+1) = gcd(left.at(i), A.at(i));
  for (int i=N-2 ; i>=0 ; i--)
    right.at(i) = gcd(right.at(i+1), A.at(i+1));
  
  vector<int> ans(N);
  for (int i=0 ; i<N ; i++)
    ans.at(i) = gcd(left.at(i), right.at(i));
  
  sort(ans.begin(), ans.end());
  
  cout << ans.at(N-1) << endl;
}

Measured memory_bytes: 4828
/**Which of the favors of your Lord will you deny ?**/

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

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second
#define INF INT_MAX

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>
using indexed_set = tree<
                    TIn, null_type, less<TIn>,
                    rb_tree_tag, tree_order_statistics_node_update>;

/*
PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

*/

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 3e5+7;
const LL LINF = 1e17;

string to_str(LL x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

LL ara[nmax];

int main()
{
    optimizeIO();

    LL n;
    cin>>n;

    LL v = 3*n;

    for(LL i=1;i<=v;i++)
    {
        cin>>ara[i];
    }

    sort(ara+1,ara+v+1);

    LL ans = 0;

    for(LL i=n+1;i<=v;i+=2)
        ans += ara[i];

    cout<<ans<<endl;

    return 0;
}


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

#define xx first
#define yy second



void solve() {
    int n, m, k; cin >> n >> m >> k;
    vector<int> a(n), b(m);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < m; i++)
        cin >> b[i];

    vector<ll> sa(n + 1, 0), sb(m + 1, 0);
    for (int i = 0; i < n; i++)
        sa[i + 1] = sa[i] + a[i];
    for (int i = 0; i < m; i++)
        sb[i + 1] = sb[i] + b[i];

    int ptr = m, mx = -1;
    for (int i = 0; i <= n; i++) {
        while (ptr >= 0 && sa[i] + sb[ptr] > k)
            ptr--;
        if (ptr >= 0) 
            mx = max(mx, i + ptr);
    }
    cout << mx << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


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

string i2s(int x){
  stringstream ss;
  ss<<x;
  string res;
  ss>>res;
  return res;
}

int s2i(string s){
  stringstream ss;
  ss<<s;
  int res;
  ss>>res;
  return res;
}

ll t[20];

ll rec(ll i,ll size,ll sum){
  if(i==size){
    if(sum==-D)return 1;
    else return 0;
  }
  
  int left=-9;
  int right=9;
  if(i==0)left=-8;
  
  ll res=0;
  for(ll a=left;a<=right;a++){
    ll ex;
    if(i==0){
      if(a<=0)ex=9+a;
      else ex=10-a;
    }else{
      if(a<=0)ex=10+a;
      else ex=10-a;
    }

    ll next=sum+t[i]*a;
    if( abs(next+D) >= t[i] )continue;
    
    res+=rec(i+1,size,next)*ex;
  }
  return res;
}

ll solve1(int m){
  ll A=1,B=1;
  for(int i=1;i<m;i++)B*=10;
  for(int i=0;i<m/2;i++){
    t[i]=B-A;
    B/=10;
    A*=10;
  }
  return rec(0,m/2,0)*10LL;
}

ll solve2(int m){
  ll A=1,B=1;
  for(int i=1;i<m;i++)B*=10;
  for(int i=0;i<m/2;i++){
    t[i]=B-A;
    B/=10;
    A*=10;
  }
  return rec(0,m/2,0);
}

ll solve(int m){
  if(m%2==0){
    return solve2(m);    
  }else{
    return solve1(m);
  }
}

int main(){
  cin>>D;
  ll ans=0;
  for(int i=2;i<=18;i++){
    ans+=solve(i);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void) {
    ll n;
    cin >> n;
    map<p, ll> I{};
    vector<vector<ll>> g(n+1);
    for(ll i = 0; i < n-1; i++){
        ll a, b, c;
        cin >> a >> b >> c;
        I[p(a, b)] = c; I[p(b, a)] = c;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ll q, k;
    cin >> q >> k;
    vector<p> vp;
    for(ll i = 0; i < q; i++){
        ll a, b;
        cin >> a >> b;
        vp.push_back(p(a, b));
    }
    queue<ll> que;
    vector<ll> dist(n+1, -1);
    dist[k] = 0; que.push(k);
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(ll nv : g[v]){
            if(dist[nv] != -1) continue;
            dist[nv] = dist[v] + I[p(v, nv)];
            que.push(nv);
        }
    }
    for(ll i = 0; i < q; i++){
        ll a = vp[i].first, b = vp[i].second;
        cout << dist[a] + dist[b] << endl;
    }
    return 0;
}


Measured memory_bytes: 23280
#include<tuple>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;

void MAIN() {
    scanf("%d", &N);
    using Tuple = tuple<LL, LL, LL>;
    vector<Tuple> X;
    X.reserve(N);

    REP (i, N) {
	LL a, b;
	scanf("%lld%lld", &a, &b);
	X.emplace_back(-a-b, a, b);
    }

    sort(X.begin(), X.end());
    LL ans = 0;
    REP (i, N) {
	LL s, a, b;
	tie(s, a, b) = X[i];
	if (i % 2) ans -= b;
	else ans += a;
    }
    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <queue>
using namespace std;

int main(void){
	std::priority_queue<int> q;
	int a;
	string s;
	while(cin>>s,s[2]!='d'){
		if(s[2]=='s'){
			cin>>a;
			q.push(a);
		}else{
			cout<<q.top()<<endl;
			q.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 6952
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <string>
#include <limits>

using namespace std;

#define MAXV 100010
#define MAXVALUE 100000000010

typedef unsigned long long ll;
typedef vector<pair<ll, ll>> vec_int_pairs;
typedef vector<ll> vecint;
typedef vector<vector<ll>> vecint2;
typedef vector<vector<vector<ll>>> vecint3;
typedef vector<vector<pair<ll, ll>>> vet_2_int_pairs;
typedef map<ll, ll> int_int_map;

int main()
{
    int n;
    
    cin >> n;
    
    vector<double> p(n);
    
    for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	
	vector< vector<double> > dp(n + 1, vector<double>(n + 1, 0));
	
	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		dp[i][0] = dp[i - 1][0] * (1 - p[i - 1]);
		dp[0][i] = 1;
	}
    
    for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= i; ++j) {
			if (i - 1 >= j) {
				dp[i][j] += dp[i - 1][j] * (1 - p[i - 1]);
			}
			
			dp[i][j] += dp[i - 1][j - 1] * p[i - 1];
		}
	}
	
	double ans = 0.0;
	for (int j = int(n / 2) + 1; j <= n; ++j) {
		ans += dp[n][j];
	}

	printf("%.10f", ans);

    return 0;
}


Measured memory_bytes: 70656
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

const int mod = 1e9 + 7;
vector<long long int> fac;

long long int mypow(long long int a, long long int b) {
    if (b == 0) return 1;
    if (b == 1) return a;
    long long int res = mypow(a, b / 2);
    res = res * res % mod;
    if (b % 2 == 1) res = res * a % mod;
    return res;
}

long long int myc(long long int a, long long int b) {
    return fac[a] * mypow(fac[b], mod - 2) % mod * mypow(fac[a - b], mod - 2) % mod;
}

int main() {
    int n;
    cin >> n;
    fac.push_back(1);
    for (int i = 1; i <= n + 1; i++) {
        fac.push_back(fac.back() * i % mod);
    }
    vector<int> va(n + 1, 0);
    vector<int> c(n + 1, 0);
    for (int i = 0; i <= n; i++) {
        cin >> va[i];
        c[va[i]]++;
    }
    int num = max_element(c.begin(), c.end()) - c.begin();
    int index1 = -1, index2 = -1;
    for (int i = 0; i <= n; i++) {
        if (va[i] == num) {
            if (index1 == -1) {
                index1 = i;
            } else {
                index2 = i;
            }
        }
    }
    int range = index2 - index1 + 1;
    vector<long long int> res(n + 2, 0);
    for (int i = 1; i <= n + 1; i++) {
        res[i] = myc(n + 1, i);
        if (1 + n + 1 - range >= i) res[i] -= myc(n + 1 - range, i - 1);
        res[i] %= mod;
        res[i] += mod;
        res[i] %= mod;
        cout << res[i] << endl;
    }
}


Measured memory_bytes: 5536
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {
    long double x1, x2, y1, y2, pow1, pow2, distance;
    scanf("%Lf %Lf %Lf %Lf", &x1, &y1, &x2, &y2);
    pow1 = powl((x1 - x2), 2);
    pow2 = powl((y1 - y2), 2);
    distance = sqrtl(pow1 + pow2);
    printf("%5Lf\n", distance);
    
    return 0;
}

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


int main(){
    int A,B,M;
    cin >> A>>B>>M;
    int a[A],b[B];
    for(int i=0;i<A;i++){
        cin >> a[i];
    }
    for(int i=0;i<B;i++){
        cin >> b[i];
    }
    int small=INT_MAX;
    int smalla= INT_MAX;
    int smallb=INT_MAX;
    for(int i=0;i<A;i++){
        if(a[i]<smalla){
            smalla=a[i];
        }
    }
    for(int i=0;i<B;i++){
        if(b[i]<smallb){
            smallb=b[i];
        }
    }
    small=smalla+smallb;
    int pre=0;
    for(int i=0;i<M;i++){
        int x,y,c;
        cin >> x>>y>>c;
        pre=a[x-1]+b[y-1]-c;
        if(pre<small){
            small=pre;
        }
    }
    cout << small;
    return 0;
} 

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
  //input
  int n;cin >> n;
  int a[n];rep(i,n)cin >> a[i];

  //solve
  int ans;
  if(*min_element(a,a+n) == *max_element(a,a+n)){
    ans = 0;
  } else {
    ans = 1000000000;
  }
  
  for(int i = *min_element(a,a+n);i < *max_element(a,a+n);++i){//i,何に合わせるか
    int sum = 0;
    for(int j=0;j<n;++j){
      sum += (i-a[j])*(i-a[j]);
    }
    if(ans > sum)ans = sum;
  }

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

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

int main(){
	int N,M;
	cin >> N >> M;
	vector<int> L(M);
	vector<int> R(M);
	for(int i=0;i<M;i++)cin >> L[i] >> R[i];
	
	int l=1,r=N;
	
	for(int i=0;i<M;i++){
		l=max(l,L[i]);
		r=min(r,R[i]);
	}
	cout << max(0,r-l+1) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int d(double a[2],double b[2],double c[2],double g[2])
{
	double e[2]={b[1]-a[1],-(b[0]-a[0])};
	double f[2]={c[0]-a[0],c[1]-a[1]};
	double x[2]={g[0]-a[0],g[1]-a[1]};
	if((e[0]*f[0]+e[1]*f[1])*(e[0]*x[0]+e[1]*x[1])>0)
		return 1;
	return 0;
}

int main()
{
	int c;
	double p[4][2];
	for(c=0;~scanf("%lf%lf",&p[c%4][0],&p[c%4][1]);)
	{
		if(c==3)
			puts(d(p[0],p[1],p[2],p[3])&d(p[1],p[2],p[0],p[3])&d(p[2],p[0],p[1],p[3])?"YES":"NO"),c=0;
		else
			c++;
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int main(void){
    int n;
    cin >> n;

    string key;
    map<string,int> mp;
    rep(i,n) {
        cin >> key;
        mp[key]++;
    }

    string s[] = {"AC", "WA", "TLE", "RE"};
    rep(i,sizeof(s)/sizeof(s[0])) cout << s[i] << " x " << mp[s[i]] << endl;
    return 0;
}


Measured memory_bytes: 3632