akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


ll N,K;
ll mo=924844033;
ll from[2020][2];
ll to[2020][2];
ll fact[2020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	
	from[0][0]=1;
	for(i=0;i<min(N,2*K);i++) {
		
		FOR(x,N) if(i>=K) swap(from[x][0],from[x][1]);
		
		for(x=i;x<N;x+=2*K) {
			ZERO(to);
			// prev
			for(y=0;y<N;y++) {
				// prev
				(to[y+1][1] += from[y][1])%=mo;
				// none
				(to[y][1] += from[y][0]+from[y][1])%=mo;
				// next
				if(x+K<N) (to[y+1][0] += from[y][0]+from[y][1])%=mo;
			}
			
			swap(from,to);
		}
		FOR(x,N+1) (from[x][0] += from[x][1])%=mo, from[x][1]=0;
	}
	fact[0]=1;
	FOR(i,N+1) fact[i+1]=fact[i]*(i+1)%mo;
	ll ret=0;
	FOR(i,N+1) ret += from[i][0]*fact[N-i]%mo*((i%2)?-1:1);
	
	cout<<(ret%mo+mo)%mo<<endl;
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 384
def merge(array, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  l = []
  r = []
  (0..(n1-1)).each do |i|
    l << array[left+i]
  end
  (0..(n2-1)).each do |i|
    r << array[mid+i]
  end
  l[n1] = Float::INFINITY
  r[n2] = Float::INFINITY

  count = 0
  i = 0
  j = 0
  (left..(right-1)).each do |k|
    count += 1
    if l[i] <= r[j] then
      array[k] = l[i]
      i += 1
    else
      array[k] = r[j]
      j += 1
    end
  end
  return count
end

def merge_sort(array, left, right)
  count = 0
  if left+1 < right then
    mid = (left + right) / 2
    count += merge_sort(array, left, mid)
    count += merge_sort(array, mid, right)
    count += merge(array, left, mid, right)
  end
  return count
end

n = gets.chomp.to_i
array = gets.chomp.split.map(&:to_i)
count = merge_sort(array, 0, n)
puts array.join(' ')
puts count

Measured memory_bytes: 215560
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        ArrayList<Integer> arr = new ArrayList<Integer>();
        for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            arr.add(a);
        }
        Collections.sort(arr);

        int ans = 0;

        for (int i = 0; i<n ; i++){
            for (int j = i+1; j<n; j++){
                for (int k = j+1; k<n; k++){
                    if (!arr.get(i).equals(arr.get(j)) && !arr.get(j).equals(arr.get(k)) && !arr.get(i).equals(arr.get(k))){
                        if (arr.get(i)+arr.get(j) > arr.get(k)){
                            ans++;
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 37504
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#define lli long long int
#define rep(i,n) for(int i=0; i<n; i++)
#define loop(i, j, n) for(int i=j; i<n; i++)
using namespace std;
using Graph = vector<vector<int>>;
int main()
{
	int n, k;
	string s, t;
	cin >> s;
	n = s.size();

	rep(i,n){
		s.erase(s.end()-1);
		k = s.size();
		if(k%2 == 0){
			if(equal(s.begin(), s.begin()+(k/2-1), s.begin()+k/2) == 1){
				cout << k <<endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
  ull N;
  cin >> N;
  unordered_map<ll, ll> pos, neg;

  for(auto i = 1; i<=N; ++i) {
    ull Ai;
    cin >> Ai;
    ++pos[i+Ai];
    ++neg[i-Ai];
  }
  
  auto ans = 0ull;
  for(auto [k, v]: pos) {
    ans += v * neg[k];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 33320
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
long long dp[200005];
pair<long long,long long> deq[200005];
long long h[200005];

int main(){
	int n;
	long long C;
	cin>>n>>C;
	for(int i=0;i<n;i++) cin>>h[i];
	dp[0]=0;
	int l=0,r=0;
	deq[0]=make_pair(h[0],dp[0]+h[0]*h[0]);
	for(int i=1;i<n;i++){
		while(r>=l+1&&deq[l+1].second-deq[l].second<=2*h[i]*(deq[l+1].first-deq[l].first)) l++;
		dp[i]=deq[l].second+h[i]*h[i]-2*h[i]*deq[l].first+C;
		long long x=h[i],y=dp[i]+h[i]*h[i];
		while(r>=l+1&&(y-deq[r-1].second)*(deq[r].first-deq[r-1].first)<=(deq[r].second-deq[r-1].second)*(x-deq[r-1].first)) r--;
	//	cout<<r<<endl;
		deq[++r]=make_pair(x,y);
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define has_str(s, c)	((s).find(c) != string::npos)
typedef long long ll;
const int N = 1e5+5;
vector<int> edges[N];
int n, m;
int dist[N];
bool visited[N];
int in_degree[N];
void dfs (int a) {
    visited[a] = true;
    for(int b : edges[a]) {
        dist[b] = max(dist[b], dist[a]+1);
        --in_degree[b];
        if(in_degree[b] == 0)
            dfs(b);
    }
}
int main() {
#ifdef LOCAL
    freopen("input.in.txt", "rt", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> m;
    while (m--) {
        int a, b;
        cin >> a >> b;
        in_degree[b]++;
        edges[a].push_back(b);
    }
    for(int i = 1; i <= n; ++i) {
        if(!visited[i] && in_degree[i] == 0)
            dfs(i);
    }
    int ans = 0;
    for(int i = 1; i <= n; ++i)
        ans = max(ans, dist[i]);
    cout << ans << endl;
    return 0;
}

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

int main() {
  int64_t a;
  int64_t c=0;
  int64_t z=0;
  int64_t h=0;
  vector<int64_t> vec;
  vector<int64_t> ans;
  cin>>a;
  if(a==1){h=0;}
 
  if(a!=1){while(a>=2){
    if(a==2){vec.push_back(2);
            break;}
  if(a>=3){c=0;
    for(int64_t i=2;i<=sqrt(a); i++){
    c=0;
  if(a%i==0){vec.push_back(i);
    a=a/i; 
             c=1;
      break;}
  }}
    if(c==0){vec.push_back(a);
      break;}
  }
   sort(vec.begin(), vec.end());
  vec.push_back(4);
  int64_t t=vec.size();
 

  for(int64_t i=0;i<t-1;i++){
  if(vec.at(i)==vec.at(i+1)){z++;}
    else{
        ans.push_back(z+1);
    z=0;}
  }
  int64_t s=ans.size();
  for(int64_t i=0;i<s;i++){
  for(int64_t j=0;j<100;j++){
  if(j*(j+1)/2<=ans.at(i)&&ans.at(i)<(j+1)*(j+2)/2){h=h+j;
                                                   break;}
  }
  }}
   
  cout<<h<<endl;
  
}

Measured memory_bytes: 3728
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
int n = sc.nextInt();
int k = sc.nextInt();
if(k%2!=0){
    out.println((long)pow(n/k,3));
}else{
    int temp=0,t=0;
    for (int a = 1; a <= n; a++) {
        if(a%k==k/2)temp++;
        if(a%k==0)t++;
    }
    out.println((long)pow(temp,3)+(long)pow(t,3));
}
}}

Measured memory_bytes: 23764
n,m=map(int, input().split())
list_R=[]
list_L=[]
for _ in range(m):
    L,R=map(int,input().split())
    list_L.append(L)
    list_R.append(R)
L=max(list_L)
R=min(list_R)

if L>R:
    print(0)
else:
    print(R-L+1)

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

#include <string>

int main()
{
	string str;

	cin >> str;

	int l = str.length() -1;

	l /= 2;

	for (int i = l ; i >= 0; i--)
	{
		string A, B;


		A = str.substr(0, i);
		B = str.substr(i, i);
		if (A == B)
		{
			cout << i * 2 << endl;
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a,b,c;
	char o;
	while(1){
		scanf("%d %c %d",&a,&o,&b);
		if(o=='?'){
			break;
		}
		if(o=='+'){
			c=a+b;
		}
		else if(o=='-'){
			c=a-b;
		}
		else if(o=='*'){
			c=a*b;
		}
		else if(o=='/'){
			c=a/b;
		}
		printf("%d\n",c);
	}
	return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    string s;
    cin >> s;

    int n = s.length();

    int par = 0;
    int cnt = 0;
    rep(i, n){
        int pt = s[i]=='g' ? 0 : -1;
        if(par < i-par){
            cnt += pt+1;
            par++;
        }else{
            cnt += pt;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

int bal;
void solve(){
	rep(i,0,4){
		char ch;
		cin>>ch;
		if(ch == '+') bal++;
		else bal--;
	}
	cout<<bal<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds; 
using ll = long long int;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order() - 0 indexing
// order_of_key() - number of elements strictly smaller
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
//---------------------------------------GL HF------------------------------------------------------
// -------------------------------------ManavJ07----------------------------------------------------
signed main()
{
	fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	int t=1;
	//cin>>t;
	while(t--)
	{
		ll N,K;
		cin>>N>>K;
		ll ar[N];
		cn(ar,N);
		s(ar,N);
		ll sum=0;
		for(ll i=0;i<K;i++)
			sum+=ar[i];
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        
        int[] costs = new int[n];
        int[] amounts = new int[n];
        for (int i = 0; i < n; i++) {
            costs[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            amounts[i] = sc.nextInt();
        }
        Arrays.sort(costs);
        Arrays.sort(amounts);
        
        long left = 0;
        long right = 1000000000000l;
        while (left < right) {
            long center = (left + right) / 2;
            boolean ok = true;
            
            // okがどうかの判定
            long count = 0;
            for (int i = 0; i < n; i++) {
                if (center < (long)costs[n - 1 - i] * amounts[i]) {
                    long tmp = center / amounts[i];
                    count += costs[n - 1 - i] - tmp;
                }
                
                if (count > k) {
                    ok = false;
                }
            }
            
            if (ok) {
                right = center;
            } else {
                left = center + 1;
            }
        }
        
        System.out.println(left);
    }
}


Measured memory_bytes: 96084
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
int main() {
	int a[3], n;
	cin >> n;
	rep(i,n) {
		rep(j,3) {
			cin >> a[j];
		}
		sort(a, a + 3);
		if((a[0] * a[0]) + (a[1] * a[1]) == a[2] * a[2]) {
			cout << "YES" << endl;
		} else { 
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1168
# coding:utf-8
x = int(input())

if x >= 400 and x <= 599:
    print(8)
elif x >= 600 and x <= 799:
    print(7)
elif x >= 800 and x <= 999:
    print(6)
elif x >= 1000 and x <= 1199:
    print(5)
elif x >= 1200 and x <= 1399:
    print(4)
elif x >= 1400 and x <= 1599:
    print(3)
elif x >= 1600 and x <= 1799:
    print(2)
elif x >= 1800 and x <= 1999:
    print(1)


Measured memory_bytes: 9132
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

LL rec (LL a, LL b) {
    if (b % a == 0) {
        return 2 * (b - a);
    }

    return ((b - a) / a) * 2 * a + a + b % a + rec(b % a, a);
}

int main() {
    LL N, X;

    cin >> N >> X;

    LL Y = N - X;

    cout << X + rec(Y, X+Y) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int X,Y,A,B,C;
struct Node
{
	int val,bel;
}a[1000005];
bool operator < (Node A,Node B)
{
	if(A.val==B.val)return A.bel<B.bel;
	return A.val<B.val;
}
int main()
{
	scanf("%d%d%d%d%d",&X,&Y,&A,&B,&C);
	int n=A+B+C,m=X+Y;
	ll ans=0; 
	for(int i=1;i<=A;++i)
	{
		scanf("%d",&a[i].val);
		a[i].bel=1;
	}
	for(int i=A+1;i<=A+B;++i)
	{
		scanf("%d",&a[i].val);
		a[i].bel=2;
	}
	for(int i=A+B+1;i<=A+B+C;++i)
	{
		scanf("%d",&a[i].val);
		a[i].bel=3;
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for(int i=1;i<=n;++i)
	{
		if(a[i].bel==1)
		{
			if(X)X--,m--,ans+=a[i].val;
			else continue;
		}
		else if(a[i].bel==2)
		{
			if(Y)Y--,m--,ans+=a[i].val;
			else continue;
		}
		else
		{
			m--;ans+=a[i].val;
		}
		if(!m)break;
	}
	printf("%lld\n",ans); 
}

Measured memory_bytes: 4352
use std::io::*;

mod disjoint_set {
    pub struct DisjointSet {
        parent: Vec<usize>,
        size: Vec<usize>,
        edge: Vec<usize>,
    }
    impl DisjointSet {
        pub fn new(n: usize) -> DisjointSet {
            DisjointSet {
                parent: (0..n).collect(),
                size: vec![1; n],
                edge: vec![0; n],
            }
        }
        pub fn root(&mut self, x: usize) -> usize {
            if x == self.parent[x] {
                x
            } else {
                let tmp = self.parent[x];
                self.parent[x] = self.root(tmp);
                self.parent[x]
            }
        }
        pub fn merge(&mut self, x: usize, y: usize) {
            let x = self.root(x);
            let y = self.root(y);
            if x == y {
                self.edge[x] += 1;
                return;
            }
            if self.size[x] > self.size[y] {
                self.size[x] += self.size[y];
                self.edge[x] += self.edge[y] + 1;
                self.parent[y] = x;
            } else {
                self.size[y] += self.size[x];
                self.edge[y] += self.edge[x] + 1;
                self.parent[x] = y;
            }
        }
        pub fn same(&mut self, x: usize, y: usize) -> bool {
            self.root(x) == self.root(y)
        }
        pub fn size(&mut self, x: usize) -> usize {
            let x = self.root(x);
            self.size[x]
        }
        pub fn edge_size(&mut self, x: usize) -> usize {
            let x = self.root(x);
            self.edge[x]
        }
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let h: usize = itr.next().unwrap().parse().unwrap();
    let _w: usize = itr.next().unwrap().parse().unwrap();

    let mut edges = Vec::new();
    for _ in 0..n {
        let r: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let c: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let a: usize = itr.next().unwrap().parse().unwrap();
        edges.push((a, r, c));
    }
    edges.sort();
    edges.reverse();

    let mut ds = disjoint_set::DisjointSet::new(200020);
    let mut ans = 0;
    for &(a, r, c) in edges.iter() {
        if ds.same(r, h + c) {
            if ds.edge_size(r) < ds.size(r) {
                ans += a;
                ds.merge(r, h + c);
            }
        } else {
            if ds.edge_size(r) + ds.edge_size(h + c) < ds.size(r) + ds.size(h + c) {
                ans += a;
                ds.merge(r, h + c);
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 17268
import bisect

N = int(input())
L = list(sorted(map(int, input().split())))
s = 0
for i in range(N):
    for j in range(i+1, N):
        a, b = L[i], L[j]
        lc, rc = abs(a-b), a+b
        l = bisect.bisect_left(L, lc+1, j+1)
        r = bisect.bisect_left(L, rc, j+1)
        s += r - l
print(s)

Measured memory_bytes: 47328
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main()
{
	int N;
	cin >> N;
	int happiness = 0;
	vector<int> A(N), B(N), C(N - 1);
	rep(i, N) {
		cin >> A.at(i);
	}

	rep(i, N) {
		cin >> B.at(i);
		happiness += B.at(i);
	}

	rep(i, N-1) {
		cin >> C.at(i);
	}

	rep(i, N - 1) {
		if (A.at(i + 1) - A.at(i) == 1) {
			happiness += C.at(A.at(i) - 1);
		}
	}

	cout << happiness << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;

// グローバル変数


// 関数：


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N, D;
	cin >> N >> D;
	
	int counter = 1;
	while ( N-(2*D+1) > 0) {
		counter = counter + 1;
		N = N - (2*D+1);
	}
	
	cout << counter << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

int main() {
	ll N, a = 0;
	cin >> N;
	vector<ll> A(N + 2);
	A[0] = 0;
	A[N + 1] = INT32_MAX;
	for (int i = 1;i <= N;i++) {
		cin >> A[i];
		A[i] += A[i - 1];
	}
	if (A[N] % 2 == 0) {
		auto it = upper_bound(all(A), A[N] / 2);
		auto it2 = it;it2--;
		cout << min(*it - A[N] / 2, A[N] / 2 - *it2) * 2 << endl;
	}
	else {
		auto it = upper_bound(all(A), A[N] / 2);
		auto it2 = it;it2--;
		cout << min((*it - A[N] / 2) * 2 - 1, (A[N] / 2 - *it2) * 2 + 1) << endl;
	}
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)
template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N;
signed main() {
	cin>>N;
	rep(i,N){
		int a;cin>>a;
		if(a%2==0){
			if(a%3&&a%5){
				cout<<"DENIED"<<endl;return 0;
			}
		}
	}
	cout<<"APPROVED"<<endl;
}


Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}

template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }

  ll x = 1;

  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

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

  ll n;
  std::cin>>n;

  
  std::unordered_map<ll,ll> mp;
  std::vector<ll> kind,sum(n+1,0);


  rep(i,0,n){
    ll a;
    std::cin>>a;
    ll temp=mp[a];
    mp[a]=temp+1;
  }

  for(auto itr=mp.begin();itr!=mp.end();++itr){
    kind.push_back(itr->second);
  }

  std::sort(all(kind));

  ll m=kind.size();
  ll over=m;

  rep(i,1,n+1){
    sum[i]=sum[i-1]+over;
    over=m-(ll)(std::upper_bound(all(kind),i)-kind.begin());
  }

  rep(i,1,n+1){
    ll left=0,right=n+1;

    while(right-left>1){
      ll mid=left+(right-left)/2;

      if(sum[mid]>=i*mid)left=mid;
      else right=mid;
    }

    std::cout<<left<<"\n";
  }

 
  return 0;
}

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

int arr[100];

void prime_factor(int N)
{
  	int i = 2;
 	while(1)
    {
      
      	if (i == N)
        {
         	arr[i] +=1;
          	//cout << i << endl;
            break;    
        }
      
      
     	if(N%i == 0)
        {
         	arr[i] += 1;
          	//cout << i << endl;
       		N /= i;
        }
      	else
        {
        	++i; 
        }
      	

    }
}

int cal_arr(){
  	int ans=0;
  	int more_24 = 0;
  	int more_14 = 0;
 	int more_4 = 0;
  	int num_2_3 = 0;
  	int more_74 = 0;
  
  	for(int i = 2; i <= 100; ++i){
      	if (arr[i] >= 24){
         	++more_24; 
        }
      	else if (arr[i] >= 14){
         	++more_14; 
        }
     	else if (arr[i] >= 4)
        {
          	++more_4;
        }
      	else if (arr[i] >= 2)
          	++num_2_3;
      
      	if (arr[i] >= 74)
          	++ more_74;
    }
  	//cout << more_74 << endl;
  	//(2,24)
//  	ans += more_24*(more_14+more_4+num_2_3) + more_24*(more_24-1)/2;
  	ans += more_24*(more_14+more_4+num_2_3 + more_24-1); 

  	//(4,14)
  	//ans += (more_14+more_24) * (more_4) + (more_14+more_24 + more_14+more_24-1)/2;
	ans += (more_14+more_24) * (more_4+more_14+more_24-1);
  	//(2,4,4)
  	ans+= (more_24+more_14+more_4)*(more_24+more_14+more_4-1)/2* num_2_3 + (more_24+more_14+more_4)*(more_24+more_14+more_4-1)/2*(more_24+more_14+more_4-2);
    //ans += more_4*(more_4-1)/2 * num_2_3  + more_4*(more_4-1)*(more_4-2)/6 ;
  	return ans+more_74;
}

int main(){
	int N;
  	cin >> N;
  	for(int i = N; i >= 2; --i)
    {
    	prime_factor(i);
    }
  	//cout << arr[2] << endl;

  	cout << cal_arr() << endl;
  	
 	return 0; 
}

Measured memory_bytes: 256
// C - Many Requirements

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int N, M, Q;
ll ans = 0;

int a[50];
int b[50];
int c[50];
int d[50];

ll calc_score(vector<int>& A) {
	ll result = 0;
	for (int i=0; i<Q; i++) {
		if (A[b[i]] - A[a[i]] == c[i]) result += d[i];
	}

	return result;
}

void dfs(vector<int>& A, int min_A) {
	if (A.size() == N) {
		ans = max(ans, calc_score(A));
		return;
	}

	for (int i=min_A; i<=M; i++) {
		A.push_back(i);
		dfs(A, i);
		A.pop_back();
	}
}

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

	for (int i=0; i<Q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}

	vector<int> A;
	dfs(A, 1);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
signed main(){
    int n;
    int all = 0;
    for(int i = 1; i<=999;i++){
        for(int j = 1; j <= 10;j++){
            if(i%3 == 0)all+=20;
            else if(j%2)all+=20;
            else all+=19;
        }
    }
    cin >> n;
    rep(i,n){
        int y,m,d; cin >> y >> m >> d;
        int sum = 0;
        for(int i = 1; i<=y-1;i++){
            for(int j = 1; j <= 10;j++){
                if(i%3 == 0)sum+=20;
                else if(j%2)sum+=20;
                else sum+=19;
            }
        }
        for(int j = 1; j<=m-1;j++){
            if(j%2 || y%3 == 0)sum+=20;
            else sum+=19;
        }
        sum += d-1;
        cout << all - sum<< endl;
    }
}




Measured memory_bytes: 3068
#include<stdio.h>

int main(void)

{


int a,b,c;

int tmp,i,j;

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

if(a>b)

{

tmp = a;

a = b;

b = tmp;

}

if(a>c)

{

tmp = a;

a = c;

c = tmp;

}

if(b>c)

{

tmp = b;

b = c;

c = tmp;

}

printf("%d %d %d\n",a,b,c);

return 0;

}

Measured memory_bytes: 1024
N,M=gets.split.map &:to_i
A=$<.map{|e|e.split.map &:to_i}
r=N
j=Hash.new 0
v={}
(M-1).times{
 c=Hash.new k=x=0
 N.times{|i|
  j[i]+=1 while v[A[i][j[i]]]
  (x<c[A[i][j[i]]]+=1) && x=c[k=A[i][j[i]]]
 }
 v[k]=1
 r=[r,x].min
}
p r

Measured memory_bytes: 5372
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

int main(){
    int n, ret = 0;
    cin >> n;
    vector<int> h(n);
    in_arr(int, h, n);
    while(any_of(h.begin(), h.end(), [](int x){ return x > 0; })){
        int start = -1, end = h.size();
        for(int i = 0; i < h.size(); ++i){
            if(h[i] != 0){
                start = i;
                break;
            }
        }
        
        for(int i = start + 1; i < h.size(); ++i){
            if(h[i] == 0){
                end = i;
                break;
            }
        }
        
        for(int i = start; i < end; ++i){
            --h[i];
        }
        ret++;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<int>
#define pb emplace_back
#define all(x) (x).begin(), (x).end()
#define deb(x) cout << #x << " - " << x << endl;
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;
const ll MAX_N = 1e6 + 7;
using namespace std;

int main() {
    IOS;
    int n; cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                sum+=__gcd(i,__gcd(j,k));
            }    
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int a[200000];
int b[200000];

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) { cin >> a[i] >> b[i]; a[i] *= 2; b[i] *= 2; }
	sort(a, a + n);
	sort(b, b + n);
	
	//rep(i, n) cout << "a[" << i << "] = " << a[i] << endl;
	//rep(i, n) cout << "b[" << i << "] = " << b[i] << endl;
	
	int low;
	if (n % 2 == 1) low = a[(n - 1) / 2];
	else low = (a[n / 2 - 1] + a[n / 2]) / 2;
	
	int high;
	if (n % 2 == 1) high = b[(n - 1) / 2];
	else high = (b[n / 2 - 1] + b[n / 2]) / 2;
	
	//cout << "high = " << high << ", low = " << low << endl;
	if (n % 2 == 1) cout << (high - low) / 2 + 1 << endl;
	else cout << high - low + 1 << endl;
	return 0;
}

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

typedef long long int ll;



int main()
{
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    ll t = 1;
    for(ll i = n;i > n - 2;i--){
        t *= i;
    }
    for(ll i = 1;i <= 2;i++){
        t /= i;
    }
    ans += t;
    t = 1;
    for(ll i = m;i > m - 2;i--){
        t *= i;
    }
    for(ll i = 1;i <= 2;i++){
        t /= i;
    }
    ans += t;
    cout << ans;
 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  ll n,c=0,a=0,b=0;
  bool f=false;
  cin>>n;
  string s[n];
  for(int i=0;i<n;i++){
    cin>>s[i];
    for(int j=0;j<s[i].size()-1;j++){
      if(s[i][j]=='A'){
        if(s[i][j+1]=='B')c++;
      }
    }
    if(s[i][0]=='B'){
      b++;
      if(s[i][s[i].size()-1]!='A')f=true;
    }
    if(s[i][s[i].size()-1]=='A'){
      a++;
      if(s[i][0]!='B')f=true;
    }
  }
  cout<<(f?c+min(a,b):c+max(min(a,b)-1,0LL));
}

Measured memory_bytes: 768
import sys
def input():
	return sys.stdin.readline().strip()

N, A, B, K = list(map(int, input().split()))

mod = 998244353

fact_list = [1]
for i in range(1, N + 1):
	fact_list.append((fact_list[-1]*i) % mod)

def pow(x, y, mod=1000000007):
	pow_list = [x]
	i = 1
	while 2**i <= y:
		a = pow_list[-1]**2
		if mod != 0:
			a = a % mod
		pow_list.append(a)
		i += 1
	ans = 1
	for bit in range(len(pow_list)):
		if (2**bit) & y != 0:
			ans *= pow_list[bit]
			if mod != 0:
				ans = ans % mod
	return ans

def fact(n, mod=1000000007):
	return fact_list[n]
  
rev_list = [1]
for i in range(N):
  rev_list.append(pow(fact(i + 1, mod), mod - 2, mod))

def mod_rev(x, mod):
	"""
	関数powが必要
	"""
	return rev_list[x]


def comb(a, b, mod=1000000007):
	"""
	関数mod_rev, fact, powが必要
	"""
	if a < b or b < 0:
		return 0
	a_fact = fact(a, mod)
	b_fact = fact(b, mod)
	a_b_fact = fact(a - b, mod)
	if mod != 0:
		return (a_fact * mod_rev(b, mod) * mod_rev(a - b, mod))%mod
	else:
		return a_fact//(b_fact*a_b_fact)

ans = 0
for r in range(N + 1):
	rest = K - r * A
	if rest % B == 0 and rest // B >= 0 and rest // B <= N:
		b = rest // B
		ans += comb(N, r, mod)*comb(N, b, mod)
		ans %= mod

print(ans)

Measured memory_bytes: 65500
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

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

    int n; cin >> n;

    cout << (n + 1) / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }

struct edge{lint to,cost;};
vector <edge> G[100000];
lint d[100000];
void dijkstra(lint s){
    priority_queue <P,vector<P>,greater<P>> que;
    fill(d,d+100000,INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        lint v=p.second;
        if(d[v]<p.first)continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
  int main(){
lint N;
cin>>N;
rep(i,N-1){
    lint a,b,c;
    cin>>a>>b>>c;
    --a;--b;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
}
lint Q,K;
cin>>Q>>K;
K--;
dijkstra(K);
vector<lint>x;
vector<lint>y;
rep(i,Q){
    lint a,b;
    cin>>a>>b;
    --a;--b;
    x.push_back(d[a]);
    y.push_back(d[b]);
}

rep(i,Q){
    cout<<x[i]+y[i]<<endl;
}

  }
  

Measured memory_bytes: 13012
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_B&lang=jp
#  Matrix Chain Multiplication : python3
#  2018.12.03 yonezawa

from collections import deque
import sys
input = sys.stdin.readline

def main():
    nmax = 1000000
    n = int(input())
    p = []
    calc = [[nmax for i in range(n + 1)] for i in range(n + 1)]

    for i in range(n):
        (a,b) = map(int,input().split())
        p.append(a)
    else:
        p.append(b)

    for i in range(n+1):
        calc[i][i] = 0

    for i in range(1,n):
        calc[i][i+1] = p[i-1] * p[i] * p[i +1] 
    
    for s in range(2,n):
        for i in range(1,n + 1 - s ):
#            print (i,i+s)
            for j in range(s):
                m = calc[i][i+j] + calc[i+j+1][i+s] + p[i-1]*p[i+j]* p[i+s]
#                print ("m=",m,"calc:",i,i+j,"+calc",i+j+1,i+s,"p:",i-1,i+j,i+s)
                if calc[i][i+s] > m:
                    calc[i][i+s] = m
    print (calc[1][n])
if __name__ == '__main__':
    main()


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

int main(){
    int n;
    cin>>n;
    priority_queue<int> a;
    rep(i,n){
        int val;
        cin>>val;
        a.push(val);
    }
    int alice=0,bob=0;
    bool flag=true;
    while(!a.empty()){
        if(flag){
            alice+=a.top();
            a.pop();
            flag=!flag;
        }else{
            bob+=a.top();
            a.pop();
            flag=!flag;
        }
    }
    cout<<alice-bob<<endl;
    return 0;
}

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

int main() {
    long long int A, B, K;
    cin >> A >> B >> K;
    long long int a, b;
    if(K <= A) {
        cout << A - K << " " << B << endl;
    } else if(K <= A + B) {
        cout << 0 << " " << B - K + A << endl;
    } else {
        cout << 0 << " " << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <set>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;

const ll MOD = 998244353;
const ld PI = acos((long double)(-1));

#define no "no"
#define No "No"
#define NO "NO"
#define yes "yes"
#define Yes "Yes"
#define YES "YES"
#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define view(_list) foreach(e, _list){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e)
#define INF 1e+9
#define EPS 0.00000001

int main() {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    println(15 - a - b - c - d - e);
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <math.h>
 
int main() {
    int m[10];
    int ans[3];
    for(int i=0; i<10; i++) scanf("%d", &m[i]);
 
    ans[0] = 0; ans[1] = 0; ans[2] = 0;
    for(int j=0; j<10; j++) {
        if(m[ans[0]] < m[j]) {
            ans[0] = j;
        }
    }
    if(ans[1] == ans[0]) {
        if(ans[1] == 0) ans[1] = 1;
        else ans[1] = ans[0]-1;
    }
    for(int j=0; j<10; j++) {
        if(m[ans[1]] < m[j] && ans[0] != j) {
            ans[1] = j;
        }
    }
    if(ans[2] == ans[0]) {
        if(ans[2] == 0) ans[2] = 2;
        else ans[2] = ans[0]-2;
    }
    for(int j=0; j<10; j++) {
        if(m[ans[2]] < m[j] && ans[0] != j && ans[1] != j) {
            ans[2] = j;
        }
    }
    printf("%d\n%d\n%d\n", m[ans[0]], m[ans[1]], m[ans[2]]);
    return 0;
}


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

string ten_to_two(int n,int k){
    string s="";
    int l;
    for(int i=k-1;i>=0;i--){
        l = n / int(pow(3.0f,i));
        s = s + to_string(l);
        n -= l * int(pow(3.0f,i));
    }   
    return s;
}

bool check(int a,int b,int c,int k){
    int p[3];
    int len = int(pow(3.0f,k));
    for(int j=0;j<len;j++){
        string s = ten_to_two(j,k);
        p[0] = a;
        p[1] = b;
        p[2] = c;
        for(int i=0;i<k;i++){
            char u=s[i];
            int l = int(u)-48;
            p[l] = 2 * p[l];
        }
        // cout <<"a" << p[0] << "  b" << p[1] << "  c"<<p[2] << endl;
        if(p[0] < p[1] && p[1] < p[2]){
            return true;
            break;
        }
    }
    return false;
}

int main()
{
    int a,b,c,k;
    bool f=false;
    cin >> a >> b >> c >> k ;
    f = check(a,b,c,k);
    if(f){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 4056
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {
	string s;
	cin >> s;
	int k, u, p, c;
	k = 0;
	u = 0;
	p = 0;
	c = 0;
	for (int i = 0; i != s.size(); i++){
		if (s[i] == 'K')k++;
		else if (s[i] == 'U')u++;
		else if (s[i] == 'P')p++;
		else if (s[i] == 'C')c++;
	}
	cout << min(k, min(u, min(p, c)));
	cout << endl;
	char cc;
	cin >> cc;
	return 0;
}

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

ll a,b,ans,sum=1,arc,mx,l;
int main() {
    cin>>a;
    for(int i=0;i<a;i++){
        cin>>arc;
        if(i && arc <= sum){
            l++;
        }else{
            l=0;
        }
        mx = max(l,mx);
        sum = arc;
    }
    cout<<mx;
}

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

int n,b[2][100100],f[2][100100];
bool v[100100];

int dfs(int s, int now, int maxi, int num){
  v[now] = true;
  
  for(int i=0;i<2;i++){
    if(!v[b[i][now]]){
      if(maxi == f[i][now])num++;
      else if(maxi < f[i][now]){
	maxi = f[i][now];
	num = 1;
      }
      if(b[i][now] == s)return num;
      return dfs(s,b[i][now],maxi,num);
    }
  }
  if(maxi == f[1][s])return num+1;
  else if(maxi < f[1][s])return 1;
  else return num;
}

int main(){
  while(cin >> n,n){
    for(int i=0;i<n;i++){
      cin >> b[0][i] >> f[0][i] >> b[1][i] >> f[1][i];
      v[i] = false;
    }

    int ans = 1;
    for(int i=0;i<n;i++){
      if(!v[i]){
	v[i] = true;
	ans = (ans * dfs(i,b[0][i],f[0][i],1) ) % 10007;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>

int main() {
  int i, length_a, length_b;
  char number_a[101], number_b[101];
  scanf("%s", number_a);
  scanf("%s", number_b);
  length_a = strlen(number_a);
  length_b = strlen(number_b);
  if(length_a > length_b) {
    printf("GREATER\n");
  } else if(length_a < length_b) {
    printf("LESS\n");
  } else {
    if(strcmp(number_a, number_b) > 0) {
      printf("GREATER\n");
    } else if(strcmp(number_a, number_b) < 0) {
      printf("LESS\n");
    } else {
      printf("EQUAL\n");
    }
  }
  return 0;
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(A == B && A != C){
        cout << "Yes" << endl;
        return 0;
    }
    if(A == C && A != B){
        cout << "Yes" << endl;
        return 0;
    }
    if(B == C && A != B){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
G = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
    S = list(map(int, input().split()))
    tmp_n = S[1]
    for j in range(tmp_n):
        G[i][S[j+2]-1] = 1
for i in range(n):
    print(*G[i])


Measured memory_bytes: 6392
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int A, B;
    cin >> A >> B;

    if (A <= 8 && B <= 8) print("Yay!");
    else print(":(");

}


Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $n);
$d = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = 0;
for ($i = 0; $i < $n - 1; $i++) {
    for ($j = $i + 1; $j < $n; $j++) {
        $ans += $d[$i] * $d[$j];
    }
}
echo $ans.PHP_EOL;

Measured memory_bytes: 4856