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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
#define MAXN 303030
using namespace std;

vector<pii> g[MAXN];

vi used(MAXN , 0);
vector<ll> dist(MAXN , 0);

void dfs(int cur , ll d){
	used[cur] = 1;
	dist[cur] = d;
	
	for(pii to : g[cur]){
		if(!used[to.fi]){
			dfs(to.fi , d + to.se);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 

	int n;
	cin >> n;
	rep(i , n - 1){
		int a , b , c;
		cin >> a >> b >> c;
		--a;
		--b;
		g[a].pb({b , c});
		g[b].pb({a , c});
	}
	
	int m , k;
	cin >> m >> k;
	
	--k;
	
	dfs(k , 0);
	
	rep(i , m){
		int u , v;
		cin >> u >> v;
		--u;
		--v;
		cout << dist[u] + dist[v] << nl;
	}
	

	return 0;
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
using u64 = uint64_t;

int main() {
	u64 N, M;
	cin >> N >> M;
	
	u64 As = 0;
	
	for(u64 i=0; i<M; i++) {
		u64 A;
		cin >> A;
		As += A;
	}
	
	if(As > N) {
		cout << -1;
	} else {
		cout << N - As;
	}
	
	return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

#define X first
#define Y second

using Pair = pair<int, int>;
const int BLOCK = 100000;

void solve()
{
	int h, w;
	cin >> h >> w;

	int ans = 0;

	vector< vector<int> > initial_maze( h, vector<int>(w, -1) );

	string s;
	for(int i = 0; i < h; ++i)
	{
		cin >> s;
		for(int j = 0; j < w; ++j)
		{
			initial_maze[i][j] = ((s[j] == '.') ? -1 : BLOCK);
		}
	}

	for(int i = 0; i < w; ++i)
	{
		for(int j = 0; j < h; ++j)
		{
			if (initial_maze[j][i] == BLOCK)
			{
				continue;
			}
			vector< vector<int> > maze( initial_maze );

			queue<Pair> que;
			Pair p(make_pair(i, j));
			maze[j][i] = max(0, maze[j][i]);
			que.push(p);

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

			while(!que.empty())
			{
				Pair now = que.front();
				que.pop();

				for(int k = 0; k < 4; ++k)
				{
					int next_x = now.X + dx[k];
					int next_y = now.Y + dy[k];
					if (next_x < 0 || w <= next_x || next_y < 0 || h <= next_y)
					{
						continue;
					}

					if (maze[next_y][next_x] == -1)
					{
						Pair next(make_pair(next_x, next_y));
						maze[next.Y][next.X] = maze[now.Y][now.X] + 1;
						que.push(next);
					}
				}
			}

			for(int y = 0; y < h; ++y)
			{
				for(int x = 0; x < w; ++x)
				{
					if (maze[y][x] != BLOCK)
					{
						ans = max(ans, maze[y][x]);
					}
				}
			}
		}
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n, u, k, v, g[101][101] = {}, i, j;

  scanf("%d", &n);
  for(i = 0; i < n; ++i){
    scanf("%d%d", &u, &k);
    for(j = 0; j < k; ++j){
      scanf("%d", &v);
      g[u-1][v-1] = 1;
    }
  }
  for(i = 0; i < n; ++i){
    for(j = 0; j < n; ++j) printf(j != 0 ? " %d" : "%d", g[i][j]);
    puts("");
  }

  return 0;
}



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

int main() {
  long long R;
  cin >> R;
  
  string result;
  if (R < 1200) {
    result = "ABC";
  } else if (R < 2800) {
    result = "ARC";
  } else {
    result = "AGC";
  }
  
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  lint a, b, c, k; cin >> a >> b >> c >> k;
  if (k <= a + b) {
    cout << min(a, k) << endl;
  } else {
    cout << a - (k - (a + b)) << endl;
  }

  return 0;
}


Measured memory_bytes: 3180
#include <iostream>
#include <cmath>
using namespace std;
 
int t[100005],x[100005],y[100005];
 
int main(){
	int n;
	cin >> n;
	bool flag = true;
	for(int i=1;i<=n;i++){
		cin >> t[i] >> x[i] >> y[i];
		int tmp = abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
		if(tmp>t[i]-t[i-1]||(tmp%2==0&&(t[i]-t[i-1])%2==1)||(tmp%2==1&&(t[i]-t[i-1])%2==0)){
			flag = false;
		}
	}
	if(flag) cout << "Yes" << endl;
	else{
		cout << "No" << endl;
	} 
	return 0;
}

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

using namespace std;

#define LL long long
#define N 32000000

const LL mod=1000000007;
LL n,ans,d[N];

void upd(LL &x,LL k){x=((x+k)%mod+mod)%mod;}

LL pw(LL x,LL k){
	if (k==0) return 1;
	LL tmp=pw(x*x%mod,k>>1);
	return k&1?tmp*x%mod:tmp;
}

int main(){
	scanf("%lld",&n);
	for (LL i=1;i<=3e7;++i) d[i]=d[i/10]+1;
	for (LL l=1,r=0,s=0;l<1e7;++l){
		for (;s<n;s+=d[++r]);
		if (s==n) upd(ans,1);
		s-=d[l];
	}
	for (LL i=1;i<=n/8;++i)
		if (n%i==0) upd(ans,pw(10,n/i)-pw(10,n/i-1)-i+1);
		else upd(ans,1);
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 235904
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
    const int MAX = 510000;
const int MOD = 1000000007;

        signed main() {
            int n;
            cin>>n;
            string s[n],x;int t[n];
            for(int i=0;i<n;i++)cin>>s[i]>>t[i];
            int a=0,ans=0;
            cin>>x;
            for(int i=0;i<n;i++){
                if(a==1)ans+=t[i];
                if(x==s[i])a=1;
            }
            cout<<ans;
         return 0;

        }


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <list>
#include <stack>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ld eps = (ld)1 / 1e10;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll suff[200005], kl[3000];

int main()
{
    fast_io;
    string a;
    ll n, i, t = 1, ans = 0;
    cin >> a;
    n = a.size();
    kl[0]++;
    for (i = n - 1; i >= 0; i--, t = (t * 10) % 2019)
    {
        suff[i] = suff[i + 1];
        suff[i] += (a[i] - '0') * t;
        suff[i] %= 2019;
        ans += kl[suff[i]];
        //cout << i << ' ' << suff[i] << '\n';
        kl[suff[i]]++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 5276
S = set()
q = int(input())
for i in range(q):
    a = input().split()
    if a[0] == "0":
        S.add(int(a[1]))
        print(len(S))
    elif a[0] == "1":
        print(1 if int(a[1]) in S else 0)
    else:
        if int(a[1]) in S:
            S.remove(int(a[1]))



Measured memory_bytes: 23356
if __name__ == '__main__':
  num_resident = int(input())
  
  x_list = [int(a) for a in input().split()]
  min_x = min(x_list)
  max_x = max(x_list)
  
  fin_ps = 0
  for i in range(min_x, max_x + 1):
    sum_ps = 0
    for x_i in range(num_resident):
      sum_ps += pow((x_list[x_i] - i), 2)
    
    if(i == min_x):
      fin_ps = sum_ps 
      
    if(sum_ps < fin_ps):
      fin_ps = sum_ps
  
  print(fin_ps)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(string S){
	bool flg = true;
	if (S.length()%2 == 1) flg = false; else {
		rep(i, S.length()-1) {
			if (!(S[i] == 'h' && S[i+1] == 'i')) flg = false;
			i++;
		}
	}
	
	if (flg) cout << "Yes" << endl; else cout << "No" << endl;
}

int main(){	
	string S;
	cin >> S;
	solve(S);
	return 0;
}



Measured memory_bytes: 256
<?php
  $n = trim(fgets(STDIN));
  $h = explode(" ", trim(fgets(STDIN)));
  
  $dp[0] = 0;
  $dp[1] = abs($h[0]-$h[1]);
  
  for($i=2; $i<$n; $i++){
      $a = abs($h[$i]-$h[$i-1]) + $dp[$i-1];
      $b = abs($h[$i]-$h[$i-2]) + $dp[$i-2];
      $dp[$i] = min($a,$b);
  }
  
  echo $dp[$n-1];

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

int main(){
    
    string S;
    
    cin >> S;
    
    sort(S.begin(), S.end());
    
    char c;
    c = 97;
    
    
    for(int i = 0; i < S.length(); i++){
        
        if(S[i] != c ){
            cout << c << endl;
            return 0;
        }else if(S[i + 1] != S[i] && i != S.length() - 1){
            if(c == 121){
                cout << "None" << endl;
                return 0;
            }
            c++;
        }else if (i == S.length() - 1){
            c++;
            cout << c << endl;
        }
    }
    
    return 0;
}

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

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

signed main() {
  int n;
  cin>>n;
  vector<int>v(n);
  for(int i=1;i<=n;i++){
    int k=1;
    while(i*k<=n){
      v[i*k-1]++;
      k++;
    }
  }
  int ans=0;
  rep(i,n){
    ans+=(i+1)*v[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 81376
#include<bits/stdc++.h>
using namespace std;
int arr[1000000];
int main()
{
	int n,temp;
  	cin >> n;
  	for(int i=0;i<n;i++)
    {
    	cin >> temp;
      	arr[temp-1] = i+1;
    }
  	for(int i=0;i<n;i++)
      	cout << arr[i] << " ";
 	cout << "\n";
  	
  	return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
    return x;
}
 
Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
 
}
 
Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
    return y;
}
 
void treeDelete(Node z){
  Node y;
  Node x; 
 
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
 
  if(y->left != NIL) x = y->left;
  else x = y->right;
 
  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
 
  if(y != z) z->key = y->key;
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
 while(x != NIL){
   y = x;
   if(z->key < x->key) x = x->left;
   else x = x->right;
 }
  
 z->parent = y;
 if(y == NIL){
   root = z;
 }
 else if(z->key < y->key) {
   y->left = z;
 }
 else {
   y->right = z; 
 }
  
  
}
 
void inorder(Node u){
  if(u->left != NIL)inorder(u->left);
  printf(" %d",u->key);
  if(u->right != NIL)inorder(u->right); 
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL)preorder(u->left);
  if(u->right != NIL)preorder(u->right);
}
 
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ){
        printf("yes");
      puts("");
      }
      else {
        printf("no");
        puts("");
      }
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      puts("");
      preorder(root);
      puts("");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
 
  return 0;
}




Measured memory_bytes: 25180
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

bool is_prime(ll num){
    if(num <= 3){
        return num > 1;
    }
    else if(num % 2 == 0 || num % 3 == 0){
        return false;
    }
    else{
        for(ll i = 5; i * i <= num; i += 6){
            if(num % i == 0 || num % (i + 2) == 0){
                return false;
            }
        }

        return true;
    }
}

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

    ll x;
    cin >> x;
    while(!is_prime(x)){
        ++x;
    }
    cout << x << endl;
}

Measured memory_bytes: 256
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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")
    };
}


use std::cmp;
use std::collections::VecDeque;


fn main(){
    input! {
        n: usize, m: usize,
        xy: [(usize1, usize1); m],
    }

    let mut indeg = vec![0;n];
    let mut e = vec![vec![]; n];
    for (x, y) in xy {
        e[x].push(y);
        indeg[y] += 1;
    }

    let mut q = VecDeque::new();
    for i in 0 .. n {
        if indeg[i] == 0 {
            q.push_front(i);
        }
    }

    let mut topo = Vec::new();
    while let Some(v) = q.pop_back() {
        topo.push(v);
        for &i in &e[v] {
            indeg[i] -= 1;
            if indeg[i] == 0 {
                q.push_front(i);
            }
        }
    }

    let mut dp = vec![0; n];
    for i in topo.into_iter().rev() {
        dp[i] = e[i].iter().map(|&j| dp[j]+1).max().unwrap_or(0);
    }

    println!("{}", dp.into_iter().max().unwrap());
}




Measured memory_bytes: 14588
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

const int MAXN = 500003;

pair<int,int> maxa(pair<int,int> a, int f,int s,pair<int,int> b){
	if(f)a.first++;
	a.second+=s;
	if(a.first > b.first)return a;
	else if(a.first == b.first){
		if(a.second < b.second)return a;
		else return b;
	}else return b;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	while(cin>>n,n){
		vector<int> p(n);
		REP(i,n)cin>>p[i];
		pair<int,int> dp[2][MAXN + 503];
		fill(dp[0],dp[2],make_pair(0,INF));// num of 500 and imamade ni tukatta okane
		dp[1][0] = make_pair(0,0);
		REP(i,n){
			fill(dp[i&1],dp[i&1] + MAXN,make_pair(0,INF));// num of 500 and imamade ni tukatta okane
			for(int j = MAXN;j >= 0;j--){
				if(p[i] % 1000 <= 500 && p[i] % 1000 > 0 && (dp[(i+1)&1][j].second != INF || j==0) ){
					dp[i&1][j + (5000-p[i])%500] = maxa(dp[(i+1)&1][j],1,p[i],dp[i&1][j + (5000-p[i])%500]);
					//toriaezu 1000(+500)
				}else{
					if(p[i] %1000 > 0 &&  dp[(i+1)&1][j + p[i]%500].second != INF){
						dp[i&1][j] = maxa(dp[(i+1)&1][j + p[i]%500],1,p[i],dp[i&1][j]);
					}//1000n + iikanjino
					if(p[i] %1000 == 0 &&  dp[(i+1)&1][j + 500].second != INF){
						dp[i&1][j] = maxa(dp[(i+1)&1][j + 500],1,p[i],dp[i&1][j]);
					}// 1000n + 500
					if(dp[(i+1)&1][j].second != INF || j==0)//toriaezu 1000(not +500)
						dp[i&1][j + (5000-p[i])%500] = maxa(dp[(i+1)&1][j],0,p[i],dp[i&1][j + (5000-p[i])%500]);
				}
				dp[i&1][j] = maxa(dp[i&1][j],0,0,dp[(i+1)&1][j]);
			}
		}
		pair<int,int> ans = make_pair(0,0);
		for(int j = MAXN + 500;j >= 0;j--){
			ans = maxa(dp[(n-1)&1][j],0,0,ans);
		}
		cout << ans.first << ' ' << ans.second << endl;
	}
  return 0;
}

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

const int mod = 1e9 + 7;
struct mint {
    long long x;
    mint(long long x = 0): x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

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

    int n; cin >> n;
    int tmp; cin >> tmp;
    mint k = tmp;

    vector<int> a(n);
    REP(i, n) cin >> a[i];

    vector<int> cnt(n, 0);
    REP(i, n) REP(j, n)
        if (a[i] > a[j]) cnt[i]++;

    mint sum = 0;
    REP(i, n) sum += cnt[i];

    vector<int> cnt2(n, 0);
    REP(i, n) for (int j = i + 1; j < n; j++)
        if (a[i] > a[j]) cnt2[i]++;

    mint sum2 = 0;
    REP(i, n) sum2 += cnt2[i];

    mint ans = sum * (k - 1) * ((mint)1 + (k - 1)) / (mint)2;
    ans += sum2 * k;

    if (tmp == 1) cout << sum2 << '\n';
    else cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct UnionFind {
    vector<int> par, size;
    UnionFind(int x) {
        par.resize(x);
        size.resize(x, 1);
        for(int i = 0; i < x; i++) {
            par[i] = i;
        }
    }
    int find(int x) {
        if (par[x] == x)
            return x;
        return par[x] = find(par[x]);
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int consize(int x) {
        return size[find(x)];
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (size[x] < size[y]) {
            par[x] = y;
            size[y] += size[x];
        } else {
            par[y] = x;
            size[x] += size[y];
        }
    }
};
signed main() {
    int N,M,K;
    cin >> N >> M >> K;
    vector<set<int>> Set(N);
    UnionFind uf(N);
    for(int i = 0; i < M; i++) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        uf.unite(a,b);
        Set[a].insert(b);
        Set[b].insert(a);
    }
    for(int i = 0; i < K; i++) {
        int c,d;
        cin >> c >> d;
        c--;d--;
        if(!uf.same(c,d)){
            continue;
        }
        Set[c].insert(d);
        Set[d].insert(c);
    }
    for(int i = 0; i < N; i++) {
        int ans = uf.size[uf.find(i)]-1;
        ans-=Set[i].size();
        cout << ans;
        if(i+1 != N) {
            cout << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 28308
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  string s,t;
  cin>>s>>t;
  int cnt=0;
  for (int i = 0; i < 3; ++i)
  {
    if(s[i]==t[i])
      cnt++;
  }
  cout<<cnt;
}

Measured memory_bytes: 256
N=int(input())
S=input()
W=[0]*N
B=[0]*N
tmp=0
for i in range(N):
	if S[i]=="#":
		tmp+=1
	B[i]=tmp
tmp=0
for i in range(N):
	if S[i]==".":
		tmp+=1
	W[i]=tmp
Max_W=(max(W))
tmp=float("inf")
for i in range(N-1):
	tmp=min(tmp,B[i]+(Max_W-W[i]))
print(min(tmp,max(B),max(W)))


Measured memory_bytes: 18864
def main():
    N = int(input())
    ans = 1
    c = 0
    for n in range(N, -1, -1):
        cc = 0
        nn = n
        while nn % 2 == 0 and n > 0:
            nn //= 2
            cc += 1
        if cc > c:
            ans = n
            c = cc
    print(ans)


main()


Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        long[] dp = new long[30];
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0) break;
            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    dp[i] = 1;
                } else if (i == 1) {
                    dp[i] = 2;
                } else if (i == 2) {
                    dp[i] = 4;
                } else {
                    dp[i] = dp[i-3] + dp[i-2] + dp[i-1];
                }
            }
            System.out.println(dp[n-1]/3650 + 1);
        }
    }
}

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

#define int long long
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int a,b;cin>>a>>b;
  if(a*b<=0)fin("Zero");
  if(a>0)fin("Positive");
  if((b-a)&1)fin("Positive");
  fin("Negative");
}


Measured memory_bytes: 256
#coding:utf-8

D,N = map(int, input().split())

if N == 100:
    if D == 0:
        print("101")
    elif D == 1:
        print("10100")
    else:
        print("1010000")

else:
    if D == 0:
        print(N)
    elif D == 1:
        print(N*100)
    else:
        print(N*10000)


Measured memory_bytes: 2940
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};


int main(){
    ll A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;

    //water
    vector<ll> x,y;
    llrep(i,F/(100*A)+1){
        llrep(j,F/(100*B)+1){
            x.push_back(100*A*i + 100*B*j);
        }
    }


    //sugar
    llrep(i,F/C+1){
        llrep(j,F/D+1){
            y.push_back(C*i + D*j);
        }
    }

    float max_ratio = 0;
    ll max_water=-1;
    ll max_sugar=-1;

    llrep(i,x.size()){
        llrep(j,y.size()){
            if (x[i] + y[j] > F) continue;
            if ( ( E * x[i] ) >=  (100 * y[j]) ){
                if ( y[j] * 100 >= (x[i] * max_ratio) ){
                    max_water = x[i];
                    max_sugar = y[j];
                    if (max_water > 0){
                        max_ratio = (float)(max_sugar * 100) / max_water;
                    }
                }
            }
        }
    }


    cout << max_water+max_sugar << " " << max_sugar << endl;

    return 0;
}


Measured memory_bytes: 5876
#include <stdio.h>

 
int main(void) {
    int n,i;
     
    scanf("%d",&n);
     
    for(i=1;i<=n;i++){
        if(i % 3 == 0)
        	printf(" %d",i);
        else if (i % 10 == 3)
        	printf(" %d",i);
        else if (i % 100 == 3)
        	printf(" %d",i);
        else if (i % 1000 == 3)
        	printf(" %d",i);
        else if (i / 10 == 3)
        	printf(" %d",i);
        else if (i / 100 == 3)
        	printf(" %d",i);
        else if (i / 1000 == 3)
        	printf(" %d",i);
        else if (i % 1000 / 100 == 3)
        	printf(" %d",i);
        else if (i % 1000 % 100 / 10 == 3)
        	printf(" %d",i);
        else{}
        
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}




int dis[10][10];






int main()
{

	string str;
	cin >> str;


	int n = str.size();
	bool flg = true;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (str[i] == str[j]) {
				cout << "no" << endl;
				return 0;
			}




		}


	}
	cout << "yes" << endl;

	return 0;

}



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

using namespace std;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
	
	string S; cin>>S;

	const long MOD = 1e9+7;
	array<long, 13> dp[2];
	dp[0][0] = 1;
	for (int i = 1; i < 13; i++)
	    dp[0][i] = 0;
	int dpi = 0;
	for (auto c : S) {
	    auto& cdp = dp[dpi];
	    auto& ndp = dp[(dpi+1)%2];
        for (int k = 0; k < 13; k++) {
            ndp[k] = 0;
        }
	    if (c == '?') {
	        for (int k = 0; k < 13; k++) {
                for (int n = 0; n < 10; n++) {
                    ndp[(k*10+n)%13] += cdp[k];
                }
	        }
	    } else {
            int n = c-'0';
            for (int k = 0; k < 13; k++) {
                ndp[(k*10+n)%13] += cdp[k];
            }
	    }
        for (int k = 0; k < 13; k++) {
            ndp[k] %= MOD;
        }
        dpi = (dpi+1)%2;
	}
	cout << dp[dpi][5] << endl;
	
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <typeinfo>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  string S; cin >> S;
  string str;
  int n;
  int min_n = 1000;
  for(int i = 0; i < S.length() - 2; i++) {
    str = S.substr(i, 3);
    n = stoi(str.c_str());
    min_n = min(min_n, abs(n-753));
  }
  cout << min_n << endl;

  return 0;
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
#if !DEBUG
    using System.IO;
#endif

public class Program {
    public static void Main() {
        #region SetAutoFlushIsFalse
#if !DEBUG
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
#endif
        #endregion
        var arr = ReadLib.ReadAsIntArray();
        var n = arr[0];
        var x = arr[1];
        var mArr = ReadLib.ReadNTimesAsInt(n);

        var val = CalcVal(n, x, mArr);
        Console.WriteLine(val);
        #region Flush
#if !DEBUG
        Console.Out.Flush();
        sw.Close();
#endif
        #endregion

    }


    private static int CalcVal(int n, int x, int[] mArr) {
        var mSum = mArr.Sum();
        var mMin = mArr.Min();

        var score = n;
        var remeined = x - mSum;

        score += remeined / mMin;
        return score;
    }
}

static class ReadLib {
    public static long ReadAsLong() {
        return long.Parse(Console.ReadLine());
    }

    public static int ReadAsInt() {
        return int.Parse(Console.ReadLine());
    }

    public static int[] ReadAsIntArray() {
        return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    public static long[] ReadAsLongArray() {
        return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
    }

    public static ulong[] ReadAsULongArray() {
        return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
    }

    public static string[] ReadAsStringArray() {
        return Console.ReadLine().Split(' ');
    }

    public static int[] ReadNTimesAsInt(int n) {
        return Enumerable.Range(1, n).Select(s => int.Parse(Console.ReadLine())).ToArray();
    }

    public static int[][] ReadNTimesAsIntArray(int n) {
        return Enumerable.Range(1, n).Select(s => ReadAsIntArray()).ToArray();
    }

}

Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <set>
#include <map>

using namespace std;

class AffineCipher
{
public:
	string decode (string, vector <int> );
	vector<int> make_alpha (void);
private:
	int gcd (int, int );
	bool decide_variable (int, int, string );
	bool check_code (string );
};

int AffineCipher::gcd (int a, int b )
{
	if (a > b){
		swap(a,b);
	} // end if
	while (b % a != 0 ){
		b = b % a;
		if (a > b ){
			swap(a, b );
		} // end if
	} // end while

	return a;
}

bool AffineCipher::decide_variable (int a, int b, string str )
{
	set <char> code; 
	set <char> source;
	int i;

	for (i = 0; i < str.length(); ++i ){
		if (isalpha(str[i]) ){
			source.insert (str[i] );
		} // end if
	} // end for
	set <char>::iterator it = source.begin();

	for (; it != source.end(); ++it ){
		char c = (a*((*it) - 'a' ) + b ) % 26 + 'a';
		if (code.count (c) ){
			return false;
		}else{
			code.insert (c);
		} // end if
	} // end for

	return true;
}

bool AffineCipher::check_code (string str )
{
	const string keyword[] = { "this", "that" };

	for (int i = 0; i < sizeof(keyword)/sizeof(keyword[0]); ++i){
		if (str.find(keyword[i] ) != string::npos ){
			return true;
		} // end if
	} // end for

	return false;
}

string AffineCipher::decode (string str, vector <int> alpha )
{
	int len = str.length();
	int a, b;
	multimap <int, int> table;
 	int i;

	for (i = 0; i < alpha.size(); ++i){		
		a = alpha[i];
		for (b = 0; b < 26; ++b){
			if (!decide_variable (a, b, str ) ){
				continue;
			}else{
				table.insert (make_pair (a, b ) );
			} // end if
		} // end for
	} // end for

	string res = "";
	multimap <int, int>::iterator it = table.begin();
	for (; it != table.end(); ++it){
		a = (*it).first;
		b = (*it).second;
		res = "";
		for (i = 0; i < len; ++i){
			char c = 0;
			if (isalpha(str[i] ) ){
				c = (a*(str[i] - 'a' ) + b ) % 26 + 'a';
			}else{
				c = str[i];
			} // end if
			res += c;
		} // end for
		if (!check_code (res ) ){
			continue;
		}else{
			break;
		} // end if
	} // end for

	return res;
}

vector <int> AffineCipher::make_alpha (void)
{
	vector <int> alpha;
	int i;

	for (i = 1; i < 26; ++i){
		if (gcd(i, 26 ) == 1 ){
			alpha.push_back(i);
		} // end if
	} // end for

	return alpha;
}
	
int main()
{
	AffineCipher AC;
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;
	
	vector <int> alpha = AC.make_alpha();
	int i;

	for (i = 0; i < n; ++i){
		string res = "";
		getline (cin, str );
		res = AC.decode (str, alpha );
		cout << res << endl;
	} // end for
		
	return 0;
}

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

int main(){
    int n, u, v; cin >> n >> u >> v;
    u--; v--;
    vector<vector<int> > graph(n);
    for(int i = 0; i < n-1; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<int> used1(n, -1), used2(n, -1);
    used1[u] = 0; used2[v] = 0;
    queue<int> q;
    q.push(u);
    while(!q.empty()){
        int mid = q.front();
        q.pop();
        int k = used1[mid];
        for(int i = 0; i < graph[mid].size(); i++){
            if(used1[graph[mid][i]] != -1) continue;
            q.push(graph[mid][i]);
            used1[graph[mid][i]] = k + 1;
        }
    }
    q.push(v);
    while(!q.empty()){
        int mid = q.front();
        q.pop();
        int k = used2[mid];
        for(int i = 0; i < graph[mid].size(); i++){
            if(used2[graph[mid][i]] != -1) continue;
            q.push(graph[mid][i]);
            used2[graph[mid][i]] = k + 1;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(used1[i] < used2[i]){
            ans = max(ans, used2[i]-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6656
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;

void main()
{
    auto nx = readln.split.to!(long[]);
    auto N = nx[0];
    auto X = nx[1];

    auto xs = readln.split.to!(long[]);

    BigInt[] cs;
    cs.length = N+1;
    foreach (i, x; xs) cs[i+1] = cs[i] + x;

    auto r = BigInt("10")^^30;
    foreach (k; 1..N+1) {
        BigInt s = N*X + k*X;
        foreach (j; 0..N/k+1) {
            s += (cs[N-j*k] - cs[max(0, N-(j+1)*k)]) * (j ? (2*(j+1)+1) : 5);
        }
        r = min(r, s);
    }

    writeln(r);
}

Measured memory_bytes: 32496
import numpy as np
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
cnt = 0
ans = 0
ind = np.argsort(A)
for i in range(N):
  m = min(M - cnt, B[ind[i]])
  ans += A[ind[i]] * m
  cnt += m
  if cnt >= M:
    break
print(ans)  

Measured memory_bytes: 21600
n, m = map(int, input().split())
tree = [-i for i in range(n+1)]

def search_root(num, tree=tree):
    if tree[num] < 0:
        return num
    else:
        tree[num] = search_root(tree[num])
        return tree[num]

for _i in range(m):
    x, y, z = map(int, input().split())
    x, y = [search_root(x), search_root(y)]
    if x==y:
        continue
    else:
        tree[x] = y
print(sum(1 for i in tree if i<0))

Measured memory_bytes: 7088
#include <stdio.h>
#include <limits.h>
#include <algorithm>
 
using namespace std;
 
int cmp_count = 0;
 
 
void merge(int A[],int left,int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1+1],R[n2+1];
    for(int i = 0; i < n1; i++) L[i] = A[left + i];
    for(int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] =  INT_MAX;
 
    int i = 0, j = 0;
    for(int k = left;k < right; k++){
        if(L[i] <= R[j]){
            A[k] = L[i++];
            cmp_count++;
        }else{
            A[k] = R[j++];
            cmp_count++;
        }
    }
}
 
void mergeSort(int A[],int left,int right){
    if(left+1 < right){
        int mid = (left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}
 
int main(){
    int n;
    scanf("%d",&n);
    int S[n];
    for(int i = 0; i < n; i++) scanf("%d",&S[i]);
 
    mergeSort(S,0,n);
 
    for(int i = 0; i < n-1; i++) printf("%d ",S[i]);
    printf("%d\n",S[n-1]);
    printf("%d\n",cmp_count);
 
}



Measured memory_bytes: 6448
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    string S;
    cin >> S;
    int n = S.length();
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        A[i] = S[i] - '0';
    }
    int m = n - 1;
    int M = 1 << m;

    auto check = [&](int mask) -> string {
        string res;
        res += (char) ('0' + A[0]);
        int ans = A[0];
        for (int i = 0; i < n - 1; ++i) {
            if ((mask >> i) & 1) {
                res += '+';
                ans += A[i + 1];
            } else {
                res += '-';
                ans -= A[i + 1];
            }
            res += (char)('0' + A[i + 1]);
        }

        if (ans == 7) {
            res += "=7";
            return res;
        } else {
            return "";
        }
    };

    for (int i = 0; i < M; ++i) {
        auto res = check(i);
        if (!res.empty()) {
            cout << res << '\n';
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long int n;
    cin >> n;
    long long int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    
    sort(a, a+n);
    int f=0;
    for(int i=0;i<n-1;i++){
        if(a[i] == a[i+1]) f=1;
    }
    
    if(f==1) cout << "NO" << endl;
    else cout << "YES" << endl;
    
    return 0;
}


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

int main()
{
    long long int n, a=100, count=0;
    scanf("%lld", &n);
    while(a<n){
    	a=a+(a/100);
    	count++;
	}
	printf("%lld\n", count);
	return 0;
}

Measured memory_bytes: 1696
#include<iostream>
using namespace std;
int main(){
	
	int n,Length[100],i,j;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>Length[i+1];
	}for(j=n;;j--){
		if(j==0){
			break;
		}if(j==1){
			cout<<Length[j]<<endl;
		}else{
			cout<<Length[j]<<" ";
		}
	}
	return 0;

}

Measured memory_bytes: 1160
//  SMOKE SHISHA PLAY FIFA  // 
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i,start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll t=1;
	//cin >> t;
	while(t--)
	{
		string s;
		cin>>s;
		lp(i,0,2)
			cout<<s[i];
		cout<<endl;		
	}
	return 0;	
}


Measured memory_bytes: 3652
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=3005;
const int mod=998244353;

int n,s,a[N],p[N],dp[N][N];
ll rec(int i,int x){
    if(x==0) return p[n-i+1];
    if(i>n or x<0) return 0;
    int &cache=dp[i][x];
    if(cache!=-1) return cache;
    return cache=(rec(i+1,x-a[i])+2*rec(i+1,x))%mod;
}
signed main(){
    FastIO;
    p[0]=1;
    rep(i,1,3000) p[i]=p[i-1]*2%mod;
    cin>>n>>s;
    rep(i,1,n) cin>>a[i];
    memset(dp,-1,sizeof dp);
    cout<<rec(1,s);
    return 0;
}


Measured memory_bytes: 39092
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;
using namespace __gnu_pbds;

// typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;
 
 ll mod=1e9 +7;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

const ll M=200006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

bool mysort(pair<ll,ll>&p1,pair<ll,ll>&p2)
{
  return p1.second<p2.second;
}

int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // compute();
    // Sieve();
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
      ll x,k,d;
      cin>>x>>k>>d;
      x=abs(x);
      // cout<<x<<"\n";
      ll tmp=x/d;
      // cout<<tmp<<"\n";
      if(k<tmp)
      {
        cout<<x-(d*k);
        return 0;
      }
      k-=tmp;
      x=x-(tmp*d);
      if(k%2==0) cout<<x;
      else cout<<d-x;
    }

    return 0;
}

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

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

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

ll LIM = 1000000;

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N; cin >> N;
	vector<ll> V(N);
	vector<ll> cnt(LIM+10, 0);
	vector<bool> isok(LIM+10, false);
	REP(i, N) cin >> V[i];

	REP(i, N)
		++cnt[V[i]];

	for (ll i = 1; i <= LIM; ++i)
		isok[i] = (cnt[i] == 1);

	for (ll i = 1; i <= LIM; ++i)
	{
		if (cnt[i])
			for (ll j = 2; j*i <= LIM; ++j)
				isok[j*i] = false;
	}

	ll res{0};
	REP(i, N)
		res += isok[V[i]];
	std::cout << res << std::endl;
	return 0;
}

Measured memory_bytes: 12916