akhauriyash/Code-Regression huggingface dataset:
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }

const int mx = 1e5+123;
map<int,int> cnt;

int main()
{
    optimize();

    int n;
    cin >> n;
    vi a(n);
    for ( int i = 0; i < n; i++ ) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    int ans = 0;
    sort ( all ( a ) );
    int Sz = unique( all ( a ) ) - a.begin();

    for ( int i = 0; i < Sz; i++ ) {
        if ( cnt[a[i]] >= a[i] ) ans += cnt[a[i]] - a[i];
        else ans += cnt[a[i]];
    }

    cout << ans << endl;


    return 0;
}


















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

unsigned long long int m = 10;

int seven(unsigned long long int n){

  for(int i=1;; i++){
    m = m % n;
    if(m == 1){
      return i;
    } else {
      m = m * 10;
    }
  }
  
}

int main(){
  
  unsigned long long int k=0;
  cin >> k;
  
  if(k % 2 == 0 || k % 5 == 0){
    
    cout << -1 << endl;

  } else if(k % 7 == 0){

    k = 9*k / 7;
    cout << seven(k) << endl;
    
  } else {

    k = 9*k;
    cout << seven(k) << endl;

  }

}


Measured memory_bytes: 3628
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
A3=list(map(int,input().split()))
list=[A1,A2,A3]
N=int(input())
b=[]
for i in range(N):
  b.append(int(input()))
for k in range(N):
  for i in range(3):
    for j in range(3):
      if list[i][j]==b[k]:
        list[i][j]=0
if list[0][0]==list[1][1]==list[2][2]==0 or list[0][2]==list[1][1]==list[2][0]==0 or list[0][0]==list[0][1]==list[0][2]==0 or list[1][0]==list[1][1]==list[1][2]==0 or list[2][0]==list[2][1]==list[2][2]==0 or list[0][0]==list[1][0]==list[2][0]==0 or list[0][1]==list[1][1]==list[2][1]==0 or list[0][2]==list[1][2]==list[2][2]==0 :
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    X = []
    for i in range(N):
        X += [(A[i], 2), (B[i], 1), (C[i], 0)]
    X.sort()
    cnt = [0] * 4
    cnt[3] = 1
    for x in X:
        size, part = x
        cnt[part] += cnt[part+1]
    print(cnt[0])


if __name__ == "__main__":
    main()


Measured memory_bytes: 126516
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

//?´?????????????????§????
//Union-Find??¨
struct UnionFind {
	vector<int> p; //parent
	int sz; //size ???????????°
	vector<int> mi;
	UnionFind(int n) :p(n, -1), sz(n), mi(n) {}
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (size(x) < size(y)) swap(x, y);
		p[x] += p[y]; p[y] = x; sz--;
		mi[x] = min(mi[x],mi[y]);
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }
	//?????????????´???°
	int size(int x) { return -p[root(x)]; }
	int solve() {
		int ret = 0;
		rep(i, 0, mi.size())
			ret += mi[root(i)];
		return ret;
	}
};

signed main() {
	int N; cin >> N;
	UnionFind UF(N);
	map<string, int> mp;
	rep(i, 0, N) {
		string a; int x; cin >> a >> x;
		mp[a] = i;
		UF.mi[i] = x;
	}
	int M; cin >> M;
	rep(i, 0, M) {
		string s, t; cin >> s >> t;
		UF.unite(mp[s], mp[t]);
	}
	cout << UF.solve() << endl;
	dumpc(UF.p);
	dumpc(UF.mi);
	return 0;
}

Measured memory_bytes: 3684
<?php

# 試行回数　番号
fscanf(STDIN, "%d %d", $op_times, $number);

# 配列にキーの値がいくつあるか記録する
while($input = fscanf(STDIN, "%d %d", $a, $b)) {
    $tmp[$a] = isset($tmp[$a]) ? $tmp[$a] + $b: $b;
}

# キーで配列昇順
ksort($tmp);

# 配列に値を埋める
foreach ($tmp as $index => $item) {
    if ( ($number = $number - $item) >0) {
        $target = $index;
    } else{
        $target = $index;
        break;
    }
}

# 出力
echo $target;

Measured memory_bytes: 13044
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

N = INT()
p = [INT() for _ in range(N)]

print(int(sum(p)-1/2*max(p)))

Measured memory_bytes: 3896
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) int(a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
	string s;
	cin>>s;
	if (s[2]==s[3] && s[4]==s[5])  cout<<"Yes";
	else  cout<<"No";
	re 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a,p;
	int k;

	setvbuf(stdout,NULL,_IONBF,0);
	scanf("%d %d",&a,&p);
	fflush(0);

	k=a*3+p;
	printf("%d\n",k/2);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
const double pie  =3.141592653589793238463;
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define POP(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(),A.end());
#define REV(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n" 
const ll dx[4] = { -1, 1, 0, 0};
const ll dy[4] = {0, 0, -1, 1};
ll XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
ll YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
#define precise(x) cout<<fixed<<setprecision(x)
#define t1(x)                cerr<<#x<<": "<<x<<endl
#define t2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define t4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define t5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define t6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
using namespace std;
void SieveOfEratosthenes(ll n) 
{ 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // for (ll p=2; p<=n; p++) 
       // if (prime[p]) 
          // cout << p << " "; 
} 

ll power(ll x, ll y) 
{ 
    ll res = 1; 
    while (y > 0) 
    { 
        if (y & 1) 
            res = res * x; 
        y = y >> 1; 
        x = x * x; 
    } 
    return res; 
}
int escape(vector<vector<char>>v,ll i,ll j,ll n,ll m)
{
    if(i>=n || j>=m || i<0 || j<0)
        return 0;
    if(v[i][j]!='.')
        return 0;
    if(i==n-1 && j==m-1)
        return 1;
    escape(v,i+1,j,n,m);
    escape(v,i,j+1,n,m);
    escape(v,i-1,j,n,m);
    escape(v,i,j-1,n,m);

    return 1;
}
int main()
{
    // fastio
    ll t,i,j,k,l,m,n,a,x,b,y,z,c,d,e,p,nl,np,q,r;
    string str2,str3;
    string s;
    cin>>a>>b;
    cout<<a*b<<endl;

}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/


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

	ll n, z, w;
	cin >> n >> z >> w;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	// 最後に引くのがYさんとは限らない
	// 2通り考える
	// もう一つあった、Xさんが全部引くパターン

	// Xさんのスコアを最大化するとは？
	// →Yさんの数とより離れたのをとる
	// Yさんのスコアを最小化は？
	// →Xさんの数に近づける

	ll x, y;
	ll ans = 0;

	if (n == 1) {
		x = a[0];
		y = w;
		ans = abs(x - y);
	}
	else {
		ans = max(abs(a[n - 1] - w), abs(a[n - 1] - a[n - 2]));
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
	int m, k;
	cin >> m >> k;
	int p = pow(2, m);
	if (k >= p) {
		cout << -1 << endl;
		return 0;
	}
	if (m == 1) {
		if (k == 0) {
			cout << "0 0 1 1" << endl;
			return 0;
		} else {
			cout << -1 << endl;
			return 0;
		}
	}
	for (int i = p-1; i >= 0; i--) {
		if (i != k) cout << i << ' ';
	}
	cout << k << ' ';
	for (int i = 0; i < p; i++) {
		if (i != k) cout << i << ' ';
	}
	cout << k << endl;
	return 0;
}

Measured memory_bytes: 4096
S = input()
T = input()
dic_S = {}
dic_T = {}
for i in range(len(S)):
    if S[i] not in dic_S:
        dic_S[S[i]] = T[i]
    elif dic_S[S[i]] != T[i]:
        print('No')
        exit()

    if T[i] not in dic_T:
        dic_T[T[i]] = S[i]
    elif dic_T[T[i]] != S[i]:
        print('No')
        exit()
print('Yes')

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

void trace(const vector<int>& A) {
    for(int i = 0; i < A.size(); i++) {
      if (i > 0) {
        cout << " ";
      }
      cout << A[i];
    }
    cout << endl;
}

int bubbleSort(vector<int>& A) {
  int sw = 0;
  bool flag = 1;

  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = A.size() - 1; j >= i + 1; j--) {
      if (A[j] < A[j-1]) {
        swap(A[j], A[j-1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main(){
  vector<int> A;
  A.reserve(100);

  int N, a;
  cin >> N;
  while(N--){
    cin >> a;
    A.push_back(a);
  }

  int sw = bubbleSort(A);

  trace(A);
  cout << sw << endl;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	for (int i = 0; i < 3; ++i) {
		if (s[i] == t[i]) {
			++cnt;
		}
	}
	cout << cnt << '\n';
	
	return 0;
}


Measured memory_bytes: 256
Num = [int(n) for n in input().rstrip().split()]

D = [int(n) for n in input().rstrip().split()]

# numbers = [ n for n in range(10) if not n in D]

flag = 0

for i in range(Num[0],10*Num[0]+1):
    for j in str(i):
        if int(j) in D:
            flag = 1
            break

    if flag == 0:
        print(i)
        break
    else:
        flag =0 
        

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

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

    int a,b;
    cin >> a >> b;
    if(a*b%2==1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 892
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: u32,
        b: u32,
    }
    let n = b - a;
    let s: Vec<u32> = (1..n+1).scan(0, |acc,i| {
        *acc += i;
        Some(*acc)
    }).collect();
    println!("{}", s[(n - 1) as usize] - b);
}


Measured memory_bytes: 4352
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}




int main() {

	string S;
	ll a=0,b=0,c=0;
	cin >> S;
	rep(i, S.size()) {
		if (S.at(i) == 'a')a++;
		else if (S.at(i) == 'b')b++;
		else c++;
	}
	if (Max(a, b, c) - Min(a, b, c) <= 1)cout << "YES" << endl;
	else cout << "NO" << endl;
}



Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
 
struct edge { long long to, cost;};
typedef pair<long long, long long> P_dij;
 
vector<long long> dijkstra(long long s, long long n, vector<edge> G[]){
    vector<long long> d = {};
    long long INF = 10000000000000000;
    d.resize(n);
    for(int i=0; i<n; i++){
        d[i] = INF;
    }
    priority_queue<P_dij, vector<P_dij>, greater<P_dij>> que;
    d[s] = 0;
    que.push(P_dij(0, s));
    while(!que.empty()){
        P_dij p = que.top();
        que.pop();
        long long v = p.second;
        if(d[v] < p.first)continue;
        for(int i=0;i<G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P_dij(d[e.to], e.to));
            }
        }
    }
    return d;
}
 
long long i, j, k;
vector<edge> edge_yen[200001];
vector<edge> edge_snu[200001];
 
int main(){
    long long n, m, s, t;
    cin >> n >> m >> s >> t;
    for(i=0; i<m; i++){
        long long u, v, a, b;
        cin >> u >> v >> a >> b;
        edge e1;
        e1.to = v, e1.cost = a;
        edge_yen[u].push_back(e1);
        edge e2;
        e2.to = u, e2.cost = a;
        edge_yen[v].push_back(e2);
        edge e3;
        e3.to = v, e3.cost = b;
        edge_snu[u].push_back(e3);
        edge e4;
        e4.to = u, e4.cost = b;
        edge_snu[v].push_back(e4);
    }
 
    vector<long long> dist_yen = dijkstra(s, n+1, edge_yen);
    vector<long long> dist_snu = dijkstra(t, n+1, edge_snu);
 
    long long ans[200001];
    long long Max = 0;
    long long FIRST = 1e15;
    for(i=n; i>=1; i--){
        long long val = FIRST - (dist_yen[i] + dist_snu[i]);
        Max = max(val, Max);
        ans[i] = Max;
    }
    for(i=1; i<=n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main() {
	int n;
	string s;
	cin >> n >> s;
	int r = 0, p = 1e9 + 7;
	long a = 1;
	for (int i = 0; i < n; i++)
		(a *= i + 1) %= p;
	for (int i = 0; i < n + n; i++) {
		if (s[i] == 'B'^i & 1)
			r++;
		else (a *= r--) %= p;
	}
if(r) a=0;
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i];

    ll ans = 0;
    rep(i, 0, N)
    {
        ans += A[i] / 2;

        if (i + 1 < N)
        {
            if (A[i] % 2 == 1 && A[i + 1] >= 1)
            {
                --A[i + 1];
                ++ans;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    string s, t;
    cin >> s >> t;

    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) {
            ans++;
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
mod reader {
    use std::fmt::Debug;
    use std::str::FromStr;
    use std::collections::VecDeque;
    use std::io::{self, Read};

    fn _read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_to_string(&mut buf);
        buf
    }

    fn _read_vec_deque_string() -> VecDeque<String> {
        _read_line().split_whitespace().map(|s| s.to_string()).collect()
    }

    pub struct Reader {
        buf : VecDeque<String>
    }

    impl Reader {
        pub fn new() -> Reader {
            Reader {buf : VecDeque::new()}
        }

        fn update_buf(&mut self) {
            if self.buf.is_empty() {
                self.buf = _read_vec_deque_string();
            }
        }

        pub fn next<T>(&mut self) -> T where T: FromStr, T::Err: Debug {
            self.update_buf();
            self.buf.pop_front().unwrap().parse::<T>().unwrap()
        }
    }
}

mod data {
    pub struct UnionFind {
        root : Vec<usize>
    }

    impl UnionFind {
        pub fn new(size : usize) -> UnionFind {
            let mut v = Vec::with_capacity(size);
            for i in 0..size {
                v.push(i);
            }
            UnionFind {root : v}
        }

        pub fn find(&mut self, x : usize) -> usize {
            let xroot = self.root[x];
            if x != xroot {
                self.root[x] = self.find(xroot);
            }
            self.root[x]
        }

        pub fn unite(&mut self, x : usize, y : usize) {
            let xroot = self.find(x);
            self.root[xroot] = self.find(y);
        }

        pub fn same(&mut self, x : usize, y : usize) -> bool {
            self.find(x) == self.find(y)
        }
    }
}

fn with_large_stack(func : fn() -> ()) {
    use std::thread::Builder;
    let builder = Builder::new();
    let th = builder.stack_size(10000000);

    th.spawn(move || {
        func();
    }).unwrap().join();
}

fn main() {
    with_large_stack(_main);
}

fn _main() {
    let mut reader = reader::Reader::new();
    
    let n : usize = reader.next();
    type Index = usize;
    let mut vertex : Vec<(i32, i32, Index)> = Vec::with_capacity(n);
    for i in 0..n {
        let x : i32 = reader.next();
        let y : i32 = reader.next();
        vertex.push((x, y, i));
    }

    type Cost = i32;
    let mut edge : Vec<(Index, Index, Cost)> = Vec::with_capacity(n * 2);
    vertex.sort_by(|a, b| a.0.cmp(&b.0));
    for i in 0..n - 1 {
        edge.push((vertex[i].2, vertex[i + 1].2, vertex[i + 1].0 - vertex[i].0));
    }
    vertex.sort_by(|a, b| a.1.cmp(&b.1));
    for i in 0..n - 1 {
        edge.push((vertex[i].2, vertex[i + 1].2, vertex[i + 1].1 - vertex[i].1));
    }

    edge.sort_by(|a, b| a.2.cmp(&b.2));
    let mut uf = data::UnionFind::new(n);
    let mut cost = 0;
    for e in edge {
        if !uf.same(e.0, e.1) {
            uf.unite(e.0, e.1);
            cost += e.2;
        }
    }
    println!("{}", cost);
}

Measured memory_bytes: 27648
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

typedef vector<INTV> Graph;

void bfs(const int &s, const Graph &G, const int &N, int &ans, INTV &res){
  INTV dist(N, -1);
  vector<INTV> vec(N);
  queue<int> que; que.push(s); dist[s] = 0;
  vec[s] = {s};
  while(!que.empty()){
    int pos = que.front(); que.pop();
    for(int nx : G[pos]){
      if(nx == s){
        if(dist[pos]+1 < ans){
          ans = dist[pos]+1;
          res = vec[pos];
          return;
        }
      } else if(dist[nx] == -1){
        dist[nx] = dist[pos]+1;
        vec[nx] = vec[pos]; vec[nx].eb(nx);
        que.push(nx);
      }
    }
  }
}

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

  int N, M, a, b; cin >> N >> M;
  Graph G(N);
  REP(i, M){
    cin >> a >> b; a--; b--;
    G[a].eb(b);
  }
  int ans = VERYBIG;
  INTV v;
  REP(i, N){
    bfs(i, G, N, ans, v);
    // ans = min(ans, bfs(i, G, N).first);
  }
  if(ans == VERYBIG){
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  for(int i : v){
    cout << i+1 << endl;
  }
}

Measured memory_bytes: 10112
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define INF 1e18
#define int long long
#define MAX 200010

signed main() {
    int n, p; cin >> n >> p;
    int even = 0;
    int odd = 0;
    for(int i = 0; i < n; i++) {
        int a; cin >> a;
        if(a % 2 == 0) even++;
        else odd++;
    }

    vector<vector<int>> comb(60, vector<int> (60, 0));

    for(int i = 0; i < 60; i++) comb[i][0] = 1;

    for(int i = 1; i < 60; i++) {
        for(int j = 1; j < 60; j++) {
            comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
        }
    }

    int comb_e = 0;
    for(int i = 0; i <= even; i++) {
        comb_e += comb[even][i];
    }

    int comb_o = 0;
    for(int i = 0; i <= odd; i++) {
        comb_o += comb[odd][i] * (p == 0 ? abs(i % 2 - 1) : (i % 2));
    }

    int ans = comb_e * comb_o;

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


Measured memory_bytes: 256
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n; cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,t; cin >> n >> t;
  vector<pair<int,int>> ct(n);
  rep(i,n){
    int cost,time; cin >> cost >> time;
    ct[i] = make_pair(cost,time);
  }
  sort(ct.begin(),ct.end());
  int ans=-1;
  rep(i,n){
    if(ct[i].second<=t){
      ans = ct[i].first;
      break;
    }
  }
  if(ans == -1) cout << "TLE" << endl;
  else cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define L long long

using namespace std;

L n,m;

L get(L x){
	return min(n+x,(m-x*2)/2);
}

void f(L s,L e){
	if(e<=s+3)
	{
		L ma=-1,mad;
		for(L i=s;i<=e;i++)
		{
			L temp=get(i);
			if(temp>ma)
			{
				ma=temp;
				mad=i;
			}
		}
		printf("%lld\n",ma);
		return;
	}
	L m1=(s*2+e)/3;
	L m2=(s+e*2)/3;
	L temp1=get(m1);
	L temp2=get(m2);
	if(temp1<temp2) f(m1,e);
	else f(s,m2);
}

int main()
{
	scanf("%lld %lld",&n,&m);
	L i;
	f(0,m/2);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
      
int main(void){
    /* 宣言と初期化 */
    int hai[10];
    int id[2];
    int i;
    int temp2nd;
    int temp3rd;
    int tempmax;
               
for(i=0;i<10;i++)
{
   cin >> hai[i];
}
    /* 代入 */
    temp2nd=hai[0];
    tempmax=hai[0];
    temp3rd=hai[0];
    /* 計算 */
for(int j=9;j>1;j--){
    for(i=0;i<j;i++){
        /* 最大値求める */
        if(hai[j]<hai[i])
       {tempmax=hai[i];
         hai[i]=hai[j];
         hai[j]=tempmax;
        }
    }
    }
 
    /* 表示 */
    printf("%d\n",hai[9]);
    printf("%d\n",hai[8]);
    printf("%d\n",hai[7]);
               
    return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> a(n), b(n);
  for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
  vector<int> od(n);
  iota(od.begin(), od.end(), 0);
  sort(od.begin(), od.end(), [&](int i, int j){
    return a[i] - b[j] > a[j] - b[i];
  });
  long long tak = 0, aok = 0;
  for(int i = 0; i < n; i++){
    if(i&1) aok += b[od[i]];
    else tak += a[od[i]];
  }
  cout << tak - aok << endl;
  return 0;
}


Measured memory_bytes: 1408
import sys
from fractions import gcd

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]



a, b = na()

if a >= 13:
    ans = int(b)
elif a >= 6:
    ans = int(b/2)
else:
    ans = int(0)


print(ans)

Measured memory_bytes: 5076
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int b = sc.nextInt();
		int c = sc.nextInt();
       if(a==b){System.out.println(c);}
      else{if(a==c){System.out.println(b);}
           else{System.out.println(a);}
          }		
	}
}


Measured memory_bytes: 21844
if __name__ == "__main__":
    tcase = int(input())
    pcase = [ int(i) for  i in input().split(' ')]
    leng = len(pcase) + 1
    items = [0]*leng
    for i in pcase:
        items[i-1] +=1
    for i in items:
        print(i)

Measured memory_bytes: 32320
#include <bits/stdc++.h>
        using namespace std;
        #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        #define trace1(x)                cerr<<#x<<": "<<x<<endl
        #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
        #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
        #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
        #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
        #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
        #define ll long long
        #define endl '\n'
        int main()
        {
            IOS;
            ll n,h,w;
            cin>>n>>h>>w;
            ll ans=0;
            for(ll i=0;i<n;i++)
            {
                for(ll j=0;j<n;j++)
                {
                    ll l=n-i;
                    ll r=n-j;
                    if(l>=w&&r>=h)
                        ans++;
                }
            }
            cout<<ans;
        }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

ll g_i(ll x,ll n) {
  ll res = 0;

  ll y = n/x;

  for(ll i = 1; i <= y; i++) {
    res += i * x;
  }

  return res;
}

int main() {
  ll n; cin >> n;
  ll ans = 0;

  for(ll i = 1; i <= n; i++) {
    ans += g_i(i,n);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>

namespace {
	inline char itoc(int i)
	{
		return '0' + i;
	}
} /* namespace  */

std::string itobina(int a)
{
	const int b=(-2);
	std::string ret;

	while (a != 0) {
		int p = a / b;
		int q = a % b;
		if (q < 0) {
			p += 1;
			q -= b;
		}
		ret.push_back(itoc(q));
		a = p;
	}

	if (ret.size() == 0) {
		ret = "0";
	}
	else {
		std::reverse(ret.begin(), ret.end());
	}

	return ret;
}

int main(int argc, const char *argv[])
{
	int N;
	std::cin >> N;
	std::cout << itobina(N) << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

//#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string a, b;
    cin >> a >> b;
    int n1, n2;
    cin >> n1 >> n2;
    string s;
    cin >> s;
    if (s == a) n1--;
    else n2--;
    cout << n1 << " " << n2;
}
/*

*/


Measured memory_bytes: 888
#include <bits/stdc++.h>
using ll = long long;
//#define int ll
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)

std::string highlight(std::string s) {
#ifdef _MSC_VER
    return s;
#else
    return "\033[33m" + s + "\033[0m";
#endif
}

#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        print_to(os, ", ", "\n", __VA_ARGS__);            \
        std::cerr << highlight(os.str());                 \
    } while (0)
#define dump_(a)                                          \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #a << " = [";          \
        print_to_(os, ", ", "]\n", all(a));               \
        std::cerr << highlight(os.str());                 \
    } while (0)
#else
#define dump(...)
#define dump_(...)
#endif

template <typename T>
void print_to(std::ostream &os, const char *, const char *tail, const T &fst) {
    os << fst << tail;
}
template <typename Fst, typename... Rst>
void print_to(std::ostream &os, const char *del, const char *tail, const Fst &fst, const Rst &... rst) {
    os << fst << del;
    print_to(os, del, tail, rst...);
}
template <typename Iter>
void print_to_(std::ostream &os, const char *del, const char *tail, Iter bgn, Iter end) {
    for (Iter it = bgn; it != end;) {
        os << *it;
        if (++it != end) {
            os << del;
        } else {
            os << tail;
        }
    }
}
template <typename Fst, typename... Rst>
void println(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, "\n", "\n", fst, rst...);
}
template <typename Fst, typename... Rst>
void print(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, " ", "\n", fst, rst...);
}
template <typename Iter>
void println_(Iter bgn, Iter end) {
    print_to_(std::cout, "\n", "\n", bgn, end);
}
template <typename Iter>
void print_(Iter bgn, Iter end) {
    print_to_(std::cout, " ", "\n", bgn, end);
}

// const int MOD = 1000000007;
namespace trush {
    int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
             std::ios::sync_with_stdio(0), 0);
}

using namespace std;

int main() {
    int n, a, b;
    while (cin >> n >> a >> b) {
        ll sum = 0;
        for (int i = 1; i <= n; ++i) {
            int t = i;
            int s = 0;
            while (t) {
                s += t % 10;
                t /= 10;
            }
            if (a <= s && s <= b) sum += i;
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s; cin >> s;
    if (s[0]=='A') cout <<"T"<<endl;
    else if (s[0]=='T') cout <<"A"<<endl;
    else if (s[0]=='G') cout <<"C"<<endl;
    else if (s[0]=='C') cout <<"G"<<endl;
}


Measured memory_bytes: 3584
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	fst := s[:len(s)/2]
	snd := s[len(s)/2:]

	var res int
	for i := 0; i < len(fst); i++ {
		if fst[i] != snd[len(snd)-1-i] {
			res++
		}
	}
	fmt.Println(res)
}


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

bool graph[60][60];
bool visited[60];
int n, m;

void dfs(int v){
    if(visited[v]) return;
    visited[v] = true;
    for(int i = 0; i < n; i++)
    {
        if(graph[v][i]) dfs(i);
    }
    
}

int main(){
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            graph[i][j] = false;
        }
    }
    int a[m], b[m];
    for(int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        graph[a[i]][b[i]] = true;
        graph[b[i]][a[i]] = true;
    }
    int ans=0;
    for(int i = 0; i < m; i++)
    {
        for(int i = 0; i < n; i++)
        {
            visited[i]=false;
        }
        graph[a[i]][b[i]] = false;
        graph[b[i]][a[i]] = false;
        dfs(0);
        for(int i = 0; i < n; i++)
        {
            if(!visited[i]){
                ans++;
                break;
            }
        }
        graph[a[i]][b[i]] = true;
        graph[b[i]][a[i]] = true;        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll STOP = 6300;

void setIO() 
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
}

ll x;
int main()
{
    setIO();
    cin >> x;
    for(ll i = -STOP; i <= STOP; i++)
        for(ll j = -STOP; j <= STOP; j++)
            if(i * i * i * i * i - j * j * j * j * j == x)
            {
                cout << i << " " << j << endl;
                return 0;
            }

    return 0;
}


Measured memory_bytes: 3636
#!/usr/bin/ruby
M=999
while(n=gets.to_i)>0 do
	a=(1..(2*n)).map.to_a
	b=[];n.times{b.push(gets.to_i)}
	h=[b,a-b];f=0;m=0
	while true do
		x=h[f].map{|e|e>m ?e: M}.min
		if x<M then h[f]-=[x];m=x else m=0 end
		if h[f].size==0 then p h[1].size,h[0].size;break end
		f^=1
	end
end

Measured memory_bytes: 2836
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
count = 0
for i in range(n):
  for j in range(i+1,n):
    a = 0
    for k in range(d):
      a +=(x[i][k]-x[j][k])**2
    a = a**0.5
    if a % 1 == 0:
      count += 1
print(count)

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

using namespace std;
#undef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool x) { return (x ? "T" : "F"); }
string to_string(const char* s) { return to_string((string)s); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename V>
string to_string(V v) {
    bool f = true; string res = "[";
    for (const auto& x: v) {
        if (!f) res += ", ";
        f = false;
        res += to_string(x); } res += "]";
    return res;
}
void debug() { cerr << endl; }
template <typename H, typename... T>
void debug(H h, T... t) { cerr << " " << to_string(h); debug(t...); }
#ifdef LOCAL
#define dbg(args...) cerr<<"("<<#args<<") =", debug(args)
#else
#define dbg(args...) 2019
#endif

using ll=long long ;

const int N = 51*51*51; 
ll dp[N];

void solve() {
    int n, X,D;
    cin >> n >> X >> D;
    vector<ll> cost(n);
    vector<vector<int>> g(n);
    cin >> cost[0];
    for (int i = 1; i < n; i++) {
        cin >> cost[i];
        int u; cin >> u;u--;
        g[u].emplace_back(i);
    }
    vector<int> sz(n, 1);
    function<void(int)> dfs = [&](int u){
        for (int v: g[u]) {
            dfs(v);
            sz[u] += sz[v];
            cost[u] += cost[v];
        }
    };
    dfs(0);
    dbg(sz,cost);
    memset(dp, 0x3f, sizeof dp);
    dp[0] = 0;
    int lim = n*n*n;
    for (int i = 0; i < n; i++) {
        int can_buy = i?min(n,D):n;
        int b = 1;
        while (can_buy>0) {
            int c = min(can_buy, b);
            for (int k = lim; k >= c*sz[i]; k--) {
                dp[k] = min(dp[k], dp[k-c*sz[i]] + c*cost[i]);
            }
            can_buy -= c;
            b <<= 1;
        }
    }
    vector<int> id(n);
    iota(id.begin(), id.end(), 0);
    sort(id.begin(), id.end(), [&](auto& u, auto& v){
        return sz[u]*cost[v] > sz[v]*cost[u];
    });
    dbg(id);
    ll res = 0;
    for (int k = 0; k <= lim; k++) {
        if (dp[k] > X) continue;
        ll cash = X-dp[k];
        ll val = k;
        dbg(cash, val);
        for (int i: id) {
            int buy = cash/cost[i];
            if (i) buy = min(buy, max(0,D-n));
            cash -= buy*cost[i];
            val += buy*sz[i];
        }
        res = max(res, val);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

vector<bool> primes(100001, true);

void makePrime(){
  primes[0] = primes[1] = false;
  ll n = primes.size();
  for(ll i = 2; i*i <= n; i++){
    if(!primes[i]) continue;
    for(ll j = i*i; j < n; j += i){
      primes[j] = false;
    }
  }
}

int main(void){
  makePrime();
  int n = primes.size();
  vector<int> a(n+1);
  a[0] = 0;
  REP(i, n){
    a[i+1] = a[i];
    if(i%2 == 0) continue;
    if(!primes[i])continue;
    if(primes[(i+1)/2]) a[i+1]++;
  }
  int q;
  cin >> q;
  vector<int> ans(q);
  REP(i, q){
    int l, r;
    cin >> l >> r;
    ans[i] = a[r+1] - a[l];
  }
  REP(i, q) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <float.h>
#include <math.h>

using namespace std;

int main(int argc, char* argv[]){
  int64_t n, t, a;
  vector<int64_t> h;
  cin >> n;
  cin >> t >> a;
  for (int64_t i = 0; i < n; i++){
    int64_t hi;
    cin >> hi;
    h.push_back(hi);
  }
  float d_max = FLT_MAX;
  int64_t i_best = -1;
  for (int64_t i = 0; i < n; i++){
    int64_t hi = h[i];
    float d = fabs((float)(a - t) + (float) hi * 0.006f);
    if (d < d_max){
        d_max = d;
        i_best = i;
    }
  }
  std::cout <<  i_best + 1 << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;


vector<ll> a(55), p(55);

ll solve(ll n, ll x){
    if(n == 0) return 1; // !!!!!
    else if(x <= 1) return 0;
    else if(x <= 1+a[n-1]) return solve(n-1, x-1);
    else if(x == 2+a[n-1]) return 1+p[n-1];
    else if(x <= 2+2*a[n-1]) return 1+p[n-1]+solve(n-1, x-2-a[n-1]);
    else return p[n];
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, x; cin >> n >> x;
    a[0] = p[0] = 1;
    for(int i=1; i<=n; ++i){
        a[i] = 2*a[i-1]+3;
        p[i] = 2*p[i-1]+1;
    }

    cout << solve(n, x) << endl;
    
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(a - x) < abs(b - x)) {
		cout << "A" << endl;
	}
	else {
		cout << "B" << endl;
	}

	return 0;
}

Measured memory_bytes: 256