akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#define MAX_V 10000
#define MAX_E 100000
#define INF 100000000
using namespace std;

typedef struct {
  int u, v, cost;
} edge;

bool comp(const edge& e1, const edge& e2) {
  return e1.cost < e2.cost;
}

edge es[MAX_E];
int V, E;

int par[MAX_E];
int rank[MAX_E];

void init_union(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    rank[i] = 0;
  }
}

int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (rank[x] < rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rank[x] == rank[y]) rank[x]++;
  }
}

bool same(int x, int y) {
  return find(x) == find(y);
}

int kruskal() {
  sort(es, es + E, comp);
  init_union(V);
  int res = 0;
  for (int i = 0; i < E; i++) {
    edge e = es[i];
    if (!same(e.u, e.v)) {
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

int main() {
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int s, t, w;
    cin >> s >> t >> w;
    es[i].u = s;
    es[i].v = t;
    es[i].cost = w;
  }

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

Measured memory_bytes: 4340
#include <cstdio>

int main(){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a * b >= c * d){
        printf("%d\n",a * b);
    }else{
        printf("%d\n",c * d);
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
#define vll vector<ll>
#define inf 1e12
#define pll pair<ll,ll>
#define ff first 
#define ss second 
#define PI acos(-1)
#define prm 998244353
#define endl '\n'
using namespace std;
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//cout << fixed << setprecision(0)
/*
ll power(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y%2==1)res=(res*x)%mod;
		y=y/2;
		x=(x*x)%mod;
	}
	return res;
}
ll inv(ll a) 
{
return power(a,mod-2);
}
 
ll fact[2000007];
ll inr[2000007];
void pre()
{
	fact[0]=1;
	for(ll i=1;i<=2000005;i++)fact[i]=(fact[i-1]*i)%mod;
	inr[0]=1;
	for(ll i=1;i<=2000005;i++)inr[i]=inv(fact[i]);
}
 
ll ncr(ll n,ll r)
{
	ll a=(fact[n]*inr[r])%mod;
	ll b=(a*inr[n-r])%mod;
	return b;
}
 
ll spf[10000050];
void sieve()
{
	for(ll i=2;i*i<=10000030;i++)
	{
		if(spf[i]==0)
		{
			for(ll j=i+i;j<=10000030;j+=i)
			{
				if(spf[j]==0)
				{
					spf[j]=i;
				}
			}
		}
	}
}
*/

int main()
{
    fastio; 
    //sieve();
    //pre();
    ll T=1;
    //cin>>T;  
    while(T--)
    {
    	ll x,k,d;
        cin>>x>>k>>d;
        x=abs(x);
        if(x>0 && (x/d)>=k)
		{
            long long qq=x/d;
            x=x-(k)*d;
            cout<<x;
            return 0;
        }
        long long y=x/d;
        x-=y*d;
        k-=y;
        if(k%2==0)
            cout<<abs(x);
        else
            cout<<min(abs(x-d),abs(x+d));
        return 0;
		//cout<<x+d;
	}
}

Measured memory_bytes: 3652
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
double a=0.0000000000 ;
int N;
cin>>N;
for(int i=1;i<=N;i++){
if(i%2==1)
a=a+1;
}
cout<<fixed<<setprecision(10)<<a/N<<endl;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		ArrayList<Integer> list=new ArrayList<Integer>();
		list.add(scan.nextInt());
		list.add(scan.nextInt());
		list.add(scan.nextInt());
		Collections.sort(list);
		for (int i = 0; i < 3; i++) {
			System.out.print(list.get(i));
			if(i<2)
				System.out.print(" ");
		}
		System.out.println();
	}

}

Measured memory_bytes: 17232
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define MOD 1000000007

long mod_pow(long x, long n, long p=MOD){
  if(x==0) return 0;
  long res=1;
  x %= p;
  while(n>0){
    if(n&1) res=res*x%p;
    x=x*x%p;
    n>>=1;
  }
  return res;
}
inline long mod_inv(long x, long p=MOD){ return mod_pow(x%p, p-2, p); }

long inv2[200];

long p[1<<15];
bool g[15][15];

int main(){
  int n,m;
  cin>>n>>m;
  fill(g[0], g[15], false);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a][b] = g[b][a] = true;
  }

  inv2[0] = 1;
  inv2[1] = mod_inv(2);
  rep(i,2,200) inv2[i] = inv2[i-1] * inv2[1] %MOD;

  for(int ini=1; ini<=2; ini++){
    p[ini] = 1;
    rep(mask, ini+4, 1<<n) if(mask%4 == ini){
      // calc p[mask]
      p[mask] = 1;
      for(int nmask = (mask-1)&mask; nmask>0; nmask = (nmask-1)&mask) if(p[nmask]>0){
        int cnt = 0;
        int dmask = mask - nmask;
        rep(i,n) if( (dmask>>i)%2 ){
          rep(j,n) if(g[i][j] && (nmask>>j)%2) cnt++;
        }
        p[mask] -= p[nmask] * inv2[cnt] %MOD;
      }
      p[mask] %= MOD;
      if(p[mask] < 0) p[mask] += MOD;
    }
  }

  long ans = 1;
  rep(maskA, 1, 1<<n) if(maskA%4 == 1 && p[maskA]>0){
    int outa = 0;
    int ca = 0;
    rep(i,n) if( (maskA>>i)%2 ){
      rep(j,n) if(g[i][j] && ((maskA>>j)%2 == 0)){
        ca++;
        outa |= (1<<j);
      }
    }
    int invmask = (~maskA)&( (1<<n) - 1);
    for(int maskB = invmask; maskB>0; maskB = (maskB-1)&invmask) if(maskB%4 == 2 && p[maskB]>0){
      int outb = 0;
      int cb = 0;
      rep(i,n) if( (maskB>>i)%2 ){
        rep(j,n) if(g[i][j] && ((maskB>>j)%2 == 0)){
          cb++;
          outb |= (1<<j);
        }
      }
      if((outa&maskB)>0 || (outa&maskB)>0) continue;

      ans -= p[maskA] * p[maskB] %MOD * inv2[ca+cb] %MOD;
    }
  }

  ans %= MOD;
  if(ans < 0) ans += MOD;
  rep(i,m) ans = ans*2%MOD;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

const int MOD = 1000000007;
typedef long long ll;


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,K;
  ll sum=0ll,ans=0ll,tmp;
  cin>>N>>K;
  vector<ll> d(N),t(N),f(N,-1000000ll);
  for(int i=0;i<N;i++){
    cin>>t[i]>>d[i];
    f[t[i]-1]=max(f[t[i]-1],d[i]);
  }

  multiset<ll> se;
  
  sort(d.rbegin(),d.rend());
  sort(f.rbegin(),f.rend());
  
  for(int i=0;i<K;i++){
    sum+=d[i];
    se.insert(d[i]);
  }

  tmp=sum;

  for(ll i=1ll;i<=K;i++){
    ll add=f[i-1];
    ll back = *se.begin();
    tmp+=add;
    if(back>add){
      se.erase(se.begin());
      tmp-=back;
    }else{
      se.erase(se.find(add));
      tmp-=add;
    }

    ans=max(ans,tmp+i*i);
  }

  cout<<ans<<endl;
}


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

int main(){
  double a, b, x;
  cin >> a >> b >> x;
  
  double theta;
  if(x > a * a * b / 2){
    theta = (180/M_PI) * atan(2*(a*a*b-x)/a/a/a);
  }else{
    theta = (180/M_PI) * atan(a*b*b/2/x);
  }
  printf("%9.15lf\n", theta);
}

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

int main(){
  	char s;
    
    while(1){
      	scanf("%c",&s);
      	
        if(s == '\n'){
            cout << endl;
            return 0;
        }
        else if((int)s >= 65 && (int)s <= 90){
            s += 32;
          	cout << s;
        }
        else if((int)s >= 97 && (int)s <= 122){
            s -= 32;
          	cout << s;
        }
      	else{
          cout << s;
        }
    }
    return 0;
}


Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    REP(i, n) cin >> v[i];

    vector<ll> seen;               //訪れた頂点を順番に入れる配列
    vector<ll> order(n+1, -1);     //頂点に関して何回目の移動で訪れたかを格納する

    ll period = 1;
    ll length = 0;
    {
        ll p = 1;                  //初めは町1
        while(order[p] == -1){     //同じ町に2回訪れるまでループを回す               
            order[p] = seen.size();//※町1は0番目としている
            seen.push_back(p);
            p = v[p-1];
        }
        period = seen.size() - order[p];
        length = order[p];
    }

    if(k < length) cout << seen[k] << endl;
    else{
        k -= length;                //kをループじゃない部分の長さで引く
        k %= period;                //kをループの周期で割る
        cout << seen[k + length] << endl;
    }
}


Measured memory_bytes: 8356
#include <cstdio>
#include <algorithm>
 
using namespace std;
 
int main() {
    int a[5], k;
    scanf("%d%d%d%d%d%d", a, a + 1, a + 2, a + 3, a + 4, &k);
    sort(a, a + 5);
    puts(a[4] - a[0] <= k ? "Yay!" : ":(");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;

string DoctorTableAD(char c){
	string s;
	switch( c ){
		case ' ': s = "101"; break;
		case 0x27: s = "000000"; break;
		case ',': s = "000011"; break;
		case '-': s = "10010001"; break;
		case '.': s = "010001"; break;
		case '?': s = "000001"; break;
		case 'A': s = "100101"; break;
		case 'B': s = "10011010"; break;
		case 'C': s = "0101"; break;
		case 'D': s = "0001"; break;
		case 'E': s = "110"; break;
		case 'F': s = "01001"; break;
		case 'G': s = "10011011"; break;
		case 'H': s = "010000"; break;
		case 'I': s = "0111"; break;
		case 'J': s = "10011000"; break;
		case 'K': s = "0110"; break;
		case 'L': s = "00100"; break;
		case 'M': s = "10011001"; break;
		case 'N': s = "10011110"; break;
		case 'O': s = "00101"; break;
		case 'P': s = "111"; break;
		case 'Q': s = "10011111"; break;
		case 'R': s = "1000"; break;
		case 'S': s = "00110"; break;
		case 'T': s = "00111"; break;
		case 'U': s = "10011100"; break;
		case 'V': s = "10011101"; break;
		case 'W': s = "000010"; break;
		case 'X': s = "10010010"; break;
		case 'Y': s = "10010011"; break;
		case 'Z': s = "10010000"; break;
	}
	return s;
}
int myatoi(string &bin_s){
	int ret = 0;
	int i = 0;
	while( i < bin_s.length() ){
		ret += (int)((bin_s[i] - '0') * pow(2.0, (double)((bin_s.length() - 1) - i)));
		i++;
	}
	return ret;
}
char DoctorTableDA(string &s){
	int d = myatoi(s);
	char ac[] = " .,-'?";

	for(int i = 0; i < 'Z' - 'A' + 1; i++) if(d == i) return i + 'A';
	for(int i = 0; i < sizeof(ac)/sizeof(*ac); i++) if(i + 26 == d) return ac[i];
	return ' ';
}
string DoctorLovedEncode(string &raw){
	string s;
	string ret;
	for(unsigned int i = 0; i < raw.length(); i++){
		s += DoctorTableAD(raw[i]);
	}
	// padding
	while( s.length() % 5 != 0 ) s += '0';

	for(unsigned int i = 0; i < s.length() / 5; i++){
		string subs = s.substr(i*5,5);
		ret += DoctorTableDA( subs );
	}
	return ret;
}

int main(void){
	while(true){
		string s;

		while( true ){
			char c;
			c = cin.get();
			if( cin.eof() ) return 0;
			if( c == '\n') break;
			else s += c;
		}

		cout << DoctorLovedEncode( s ) << endl;
	}
	return 0;
}

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

int main(void){

    int N; cin>>N;

    vector<double> A(N);
    for (int i = 0; i < N; ++i) {
        cin>>A[i];
    }
    sort(A.begin(), A.end());
    double ans=A[0];
    for (int i = 1; i < N; ++i) {
        ans = (ans+A[i])/2.0;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int s,i,j,k;
long long n;
int main()
{
	scanf("%d%d",&k,&s);
	for(i=0;i<=k;i++) for(j=0;j<=k;j++) if(s>=i+j&&s<=i+j+k) n++;
	printf("%lld",n);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        System.out.printf("%d %d %.5f", a/b, a%b, (double)a/(double)b);
    }
}

Measured memory_bytes: 17188
#include<iostream>
#include<stack>

using namespace std;

int main() {

	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int A[10];
		for (int j = 0; j < 10; j++)cin >> A[j];
		stack<int> B, C;
		B.push(A[0]);
		for (int j = 1; j < 10; j++) {
			if (B.top() < A[j])B.push(A[j]);
			else if (C.empty() == 1 || C.top() < A[j])C.push(A[j]);
			else {
				cout << "NO" << endl;
				break;
			}
			if (j == 9)cout << "YES" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main()
{
  	int k;
  	cin>>k;
  	int n,m;
  	cin>>n>>m;
  	int f=0;
  	for(int i=n;i<=m;i++)
  	{
  	    if(i%k==0)
  	    {
  	        f=1;
  	        break;
  	    }
  	}
  	if(f==1)cout<<"OK"<<endl;
  	else cout<<"NG"<<endl;
}

Measured memory_bytes: 3632
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    vector<ll> suma(n+1), sumb(m+1);
    rep(i, n) {
        int a;
        cin >> a;
        suma[i+1] = suma[i] + a;
    }
    rep(i, m) {
        int b;
        cin >> b;
        sumb[i+1] = sumb[i] + b;
    }

    int ans = 0;
    rep(i, n+1) {
        if(suma[i] > k) continue;
        auto itr = upper_bound(all(sumb), k-suma[i]);
        itr--;
        ans = max(ans, i+int(itr-sumb.begin()));
    }

    cout << ans << endl;
}

Measured memory_bytes: 6368
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vl v(n);
	REP(i, n)cin >> v[i];
	bool ok = true;
	REP(i, n)if (v[i] > i)ok = false;
	if (!ok) {
		cout << -1 << endl;
		return 0;
	}
	ll ans = 0;
	int p = INF;
	RREP(i, n) {
		if (!(p <= i && v[i] == (i - p))) {
			if (v[i] < i - p) {
				cout << -1 << endl;
				return 0;
			}
			ans += v[i];
			p = i - v[i];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
   
 #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
 #endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

   int a,b;
   cin>>a>>b;
   for(int i=1;i<=1e6;i++)
   {
      if(floor(i*0.08)==a &&floor(i*0.1)==b )
      {
         cout<<i;
         return 0;
      }
   }   
   cout<<-1;

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

// double dis(double dx, double dy)
// {
// }

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

    vector<int> per(n);
    rep2(i, 1, n + 1) per[i - 1] = i;

    int first, last;
    int cnt = 0;
    do
    {
        cnt++;
        if (p == per)
        {
            first = cnt;
        }
        if (q == per)
        {

            last = cnt;
        }
    } while (next_permutation(all(per)));

    cout << abs(last - first) << endl;

    return 0;
}

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

vector<ll> Len(51);
vector<ll> Pat(51);

ll rec(ll n, ll x) {
    if (x == 0) return 0;
    if (x == Len[n]) return Pat[n];

    if (x > 0) x--;  //パンが1枚減る
    if (x <= Len[n - 1]) {
        return rec(n - 1, x);
    }
    x -= Len[n - 1];
    if (x > 0) x--;  // ここでパティが1増える
    if (x <= Len[n - 1]) {
        return (ll)1 + Pat[n - 1] + rec(n - 1, x);
    }
    return Pat[n];
}

int main() {
    ll N, X;
    cin >> N >> X;
    Len[0] = 1;
    Pat[0] = 1;

    for (int i = 1; i <= N; i++) {
        Len[i] = 1LL + Len[i - 1] + 1 + Len[i - 1] + 1;
        Pat[i] = 2 * Pat[i - 1] + 1LL;
    }

    cout << rec(N, X) << endl;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<int> X(N);
    rep(i, N) cin >> X[i];
    vector<int> Y = X;
    sort(Y.begin(), Y.end());
    int l = Y[N/2-1], r = Y[N/2];
    // DUMP2(l, r);

    rep(i, N) {
        if (X[i] <= l) cout << r << endl;
        else           cout << l << endl;
    }
}

Measured memory_bytes: 3840
p = 10**9+7
n, a, b = map(int, input().split())

com = [1] * (max(a, b) + 1)
inv = [0] * (max(a, b) + 1)
inv[1] = 1

for i in range(2, max(a,b)+1):
  inv[i] = p - inv[p%i] * (p // i) % p

for i in range(1, max(a,b)+1):
  com[i] = com[i-1] * ((n-i+1) % p) * inv[i] % p

ans = pow(2, n, p) - 1 - com[a] - com[b]

print(ans % p)

Measured memory_bytes: 18820
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
ll a[200009];
ll n;ll k;
int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
    sort(a+1,a+n+1);
    ll l=-1e18,r=1e18;
    ll answer;
    while(l<=r)
    {
        ll mid=(l+r)/2;ll cnt=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]>0){
                cnt+=upper_bound(a+1,a+n+1,(long double)mid/a[i])-a-1;
            }
            else if(a[i]<0){
                cnt+=n-(lower_bound(a+1,a+n+1,(long double)mid/a[i])-a-1);
            }
            else if(mid>=0)cnt+=n;
            if(a[i]*a[i]<=mid)cnt--;
        }
        if(cnt>=k*2)answer=mid,r=mid-1;
        else l=mid+1;
    }
    cout<<answer<<endl;
    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main()
{
    int n;
    cin >>n;
    vector<int> d(n);
    rep(i,n) scanf(" %d", &d[i]);

    int ans=0;
    int lim=1000;
    rep(i,lim+1)
    {
        bool found=false;

        int len=0;
        int t=i;
        while(1)
        {
            ++len;
            t/=10;
            if(t==0) break;
        }

        //start point
        rep(j,n-len+1)
        {
            int val=0;
            rep(k,len) val=val*10+d[j+k];

            if(val==i)
            {
                found=true;
                break;
            }
        }

        if(!found)
        {
            ans=i;
            break;
        }
    }

    printf("%d\n", ans);
    return 0;
}

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

using namespace std;

typedef long long int ll;

int main(){
    int t;
    cin>>t;
    string a;
    cin>>a;
    int arr[200];
    memset(arr, 0, sizeof(arr));
    ll sum = 0;
    int count = 0;
    for(int i = 0;i< t;i++){
        int midCount = 0;
        for(int j = i+1;j< t ;j++){
            if(a[i] != a[j]){
                 arr[a[j]]++;
                int mid = (i+j)/2;
                if(mid*2 == (i+j) ){
                    if(a[mid] != a[i] && a[mid] != a[j])midCount++;
                }
            }
        }
        // cout<<"R :" <<arr['R']<<"G: "<<arr['G']<<" B: "<<arr['B']<<endl;
        if(a[i] == 'R')sum += arr['G']*arr['B'];
        if(a[i] == 'G')sum += arr['R']*arr['B'];
        if(a[i] == 'B')sum += arr['R']*arr['G'];
        // cout<<"Mid Count "<<midCount<<endl;
        sum = sum - midCount;
        // cout<<"SUM "<<sum<<endl;
        memset(arr, 0, sizeof(arr));
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3628
#include <numeric>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

typedef long long ll;

#include <set>

using namespace std;

// 6  9 12 10  8
// *
// 5  7  9  6  3
//             *
// 3  4  5  1  2
//          *
// 0  0  0  0  0

int main(){
  ll n = getInt();
  vector<ll> a(n);
  REP(i,n) a[i] = getInt();

  const ll one = n * (n + 1) / 2;
  const ll sum = accumulate(a.begin(), a.end(), 0ll);

  if(sum % one != 0) goto bad;
  {
    const ll cnt = sum / one;

    REP(i,n){
      const int next = (i + 1) % n;
      const ll d = a[next] - a[i];

      if(d > cnt) goto bad;
      if((cnt - d) % n != 0) goto bad;
    }
  }

  puts("YES");
  return 0;

 bad:
  puts("NO");
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    double a,b;
    int t,b1,i;
    bool f;
    cin>>a>>b;
    b1=b;t=0;
    while(b1>0){
        t++;b1=b1/10;
    }
    for(i=1;i<=t;i++) a=a*10;
    a=a+b;f=false;
    for(i=1;i<=a/4;i++)
        if(i*i==a) {cout<<"Yes";f=true;}
    if(f==false)  cout<<"No";
    return 0;
}

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

using namespace std;

string s;
int K;
unordered_set<string> us;

int main(){
    cin >> s;
    cin >> K;
    string ss;
    vector<string> v={"{","}","|","{{","||"};
    for(int i=0;i<5;i++){
        us.insert(v[i]);
    }
    for(int i=0;i<s.size();i++){
        for(int j=i;j<s.size();j++){
            ss = s.substr(i,j-i+1);
            if(v[4] > ss && us.find(ss) == us.end()){
                us.erase(v[4]);
                us.insert(ss);
                v[4] = ss;
                sort(v.begin(),v.end());
            }
        }
    }
    cout << v[K-1] << endl;
    return 0;
}

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

using namespace std;

const int MX = 200000;

char s[MX + 1];
int dp[1 << 26];

int main() {
	ignore = scanf("%s", s);
	
	dp[0] = 0;
	for (int i = 1; i < (1 << 26); i++) dp[i] = MX + 1;
	
	int mask = 0, last;
	for (int i = 0; s[i] != 0; i++) {
		mask ^= 1 << (s[i] - 'a');
		last = dp[mask] + 1;
		for (int j = 0; j < 26; j++) last = min(dp[mask ^ (1 << j)] + 1, last);
		dp[mask] = min(dp[mask], last);
	}
	
	printf("%d\n", last);
	
	return 0;
}


Measured memory_bytes: 262528
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n>>a>>m;
  if(n%a==0)
  cout<<n/a*m;
  else cout<<(n/a+1)*m;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
   //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  double a;
  if (N % 2 == 0){
    a = N/2;
  }
  else if (N % 2 == 1){
    a = N/2 + 1;
  }
  cout << (a/N) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
string s;

int main(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    
    cin >> s;
    bool good = false;
    for(int i = 0; i < s.length(); i++){
      for(int j = 0; j < s.length(); j++){
        if(i!=j){
          if(s[i] != s[j]){
            good = true;
          }
        }
      }
    }
    if(good){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }



    cout.flush();
    return 0;
}

Measured memory_bytes: 3624
unittest
{
	assert( [ "1", "10", "2" ].parse.expand.solve == 4 );
	assert( [ "2", "9", "3 6" ].parse.expand.solve == 12 );
	assert( [ "5", "20", "11 12 9 17 12" ].parse.expand.solve == 74 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto k = input.front.strip.to!( long );
	input.popFront;
	auto xs = input.front.split.to!( long[] );
	return tuple( k, xs );
}

auto solve( long k, long[] xs )
{
	auto r = 0L;
	
	foreach( x; xs )
	{
		r += min( x, k - x ) * 2;
	}
	
	return r;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	string s,t,u;
	cin >> s >> t >> u;
	string S;
	S[0]=s[0]-32;
	S[1]=t[0]-32;
	S[2]=u[0]-32;
	cout << S[0]<<S[1]<<S[2] << endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string s,p; cin>>s>>p;
    bool ok=false;
    string judge=s+s;
    rep(i,s.size()){
        string tmp=judge.substr(i,p.size());
        if(tmp==p) ok=true;
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int main()
{int  A,B,C,D;
cin >> A >> B >> C >> D;
int x = min(B,D) - max(A,C);
 if(x >= 0)
 {cout << min(B,D) - max(A,C) << endl;}
 else{cout << 0 << endl;}
return 0;}


Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    n = int(input())
    s_list = [int(input()) for _ in range(n)]
    s_list.sort()
    s_sum = sum(s_list)

    for i in s_list:
        if s_sum % 10 != 0:
            break
        if i % 10 == 0:
            continue
        else:
            s_sum -= i
    if s_sum % 10 != 0:
        print(s_sum)
    else:
        print(0)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			Set<Integer> set = new HashSet<>();
			int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
			set.add(a);
			set.add(b);
			set.add(c);

			out.println(set.size());

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


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

ll n;

int main() { // claudio van
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  cin >> n;
  if (n & 1) {
    cout << 0 << "\n";
  } else {
    ll tmp = n;
    ll cnt5 = 0;
    while (tmp) {
      cnt5 += (tmp / 5) / 2;
      tmp /= 5;
    }
    cout << cnt5 << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	static boolean[][] visited;
	static int[][] island;
	static int cnt = 0;
	static int h,w;
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(true) {
				w = sc.nextInt();
	    		h = sc.nextInt();
				if(h == 0 && w == 0)	break;
				island = new int[h][w];
				visited = new boolean[h][w];
				
				for(int i=0;i<h;i++) {
					for(int j=0; j<w; j++) {
						island[i][j] = sc.nextInt();	
					}
	            }
                cnt = 0;
				for(int i=0;i<h;i++) {
					for(int j=0; j<w; j++) {
						if(island[i][j] == 1 && !visited[i][j]) {
						visit(i,j);
						cnt++;
						}
					}
				}
				
				System.out.println(cnt);
				}

			
			
		}
	}
	static void visit(int m,int n) {
		if(!visited[m][n]) {
            visited[m][n] = true;
            
			if(n+1 < w && island[m][n+1] == 1) {
				visit(m,n+1);
			}if(n-1 >= 0 && island[m][n-1] == 1) {
				visit(m,n-1);
			}if(m+1 < h && island[m+1][n] == 1) {
				visit(m+1,n);
			}if(m-1 >= 0 && island[m-1][n] == 1) {
				visit(m-1,n);
			}if(m+1 < h && n+1 < w && island[m+1][n+1] == 1) {
				visit(m+1,n+1);
			}if(m+1 < h && n-1 >= 0 && island[m+1][n-1] == 1) {
				visit(m+1,n-1);
			}if(m-1 >= 0 && n+1 < w && island[m-1][n+1] == 1) {
				visit(m-1,n+1);
			}if(m-1 >= 0 && n-1 >= 0 && island[m-1][n-1] == 1) {
				visit(m-1,n-1);
			}
		}
	}
}





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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int N,M; cin >> N >> M;

    int cnt[100005] = {0};

    for (int i = 0;i < M;i++){
        int l,r; cin >> l >> r;
        cnt[l]++; cnt[r+1]--;
    }

    int sum = 0;
    int ans = 0;

    for (int i = 0;i <= N;i++){
        sum += cnt[i];
        //cout << sum << endl;
        if(sum == M) ans++;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll unsigned long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
int main()
{
	SPEED
	ll n;
	cin >> n;
	n--;
	cout << (n*(n+1))/2;
	return 0;
}

Measured memory_bytes: 256
S = input()
count = 0
if len(S) % 2 == 0:
  for i in range(int(len(S)/2)):
    if S[i] != S[len(S)-1-i]:
      count = count + 1
else:
  for i in range(int(len(S)/2)):
    if S[i] != S[len(S)-1-i]:
      count = count + 1
print(count)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
using namespace std;
const int N=300005;
int a[N],b[N],q[N],n,w,h,Y,ans;
struct P{
	int x,y;
}p[N];
bool cmp(P a,P b){return a.x<b.x;}
void solve(int l,int r){
	if (l==r) return;
	int mid=(l+r)>>1;
	for (int i=mid,y1=0,y2=h;i>=l;i--){
		a[i]=y1;b[i]=y2;
		if (p[i].y>=Y) y2=min(y2,p[i].y);
		if (p[i].y<=Y) y1=max(y1,p[i].y);
	}
	for (int i=mid+1,y1=0,y2=h;i<=r;i++){
		a[i]=y1;b[i]=y2;
		if (p[i].y>=Y) y2=min(y2,p[i].y);
		if (p[i].y<=Y) y1=max(y1,p[i].y);
	}
	for (int i=mid,j=mid+1,h=1,t=0;i>=l;i--){
		for (;j<=r && a[j]<=a[i];j++){
			for (;h<=t && b[q[t]]+p[q[t]].x<=b[j]+p[j].x;t--);
			q[++t]=j;
		}
		for (;h<t && b[i]+p[q[h]].x<=b[q[h+1]]+p[q[h+1]].x;h++);
		ans=max(ans,(p[q[h]].x-p[i].x+min(b[i],b[q[h]])-a[i])*2);
	}
	for (int i=mid+1,j=mid,h=1,t=0;i<=r;i++){
		for (;j>=l && a[j]<=a[i];j--){
			for (;h<=t && b[q[t]]-p[q[t]].x<=b[j]-p[j].x;t--);
			q[++t]=j;
		}
		for (;h<t && b[i]-p[q[h]].x<=b[q[h+1]]-p[q[h+1]].x;h++);
		ans=max(ans,(p[i].x-p[q[h]].x+min(b[i],b[q[h]])-a[i])*2);
	}
	solve(l,mid);solve(mid+1,r);
}
void work(){
	sort(p+1,p+n+1,cmp);
	Y=h/2;
	p[0].x=0;p[n+1].x=w;
	p[0].y=p[n+1].y=Y;
	solve(0,n+1);
}
int main(){
	scanf("%d%d%d",&w,&h,&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y);
	ans=max(h,w)*2+2;
	work();
	swap(w,h);
	for (int i=1;i<=n;i++) swap(p[i].x,p[i].y);
	work();
	printf("%d\n",ans);
}

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

ll n, ans, a[1000], dp[1000][1000];
bool visit[1000][1000];

ll sum(int l, int r){
    ll res = 0;
    for (int i = l; i <= r; i++) res += a[i];
    return res;
}

ll solve(int l, int r){
    if (l == r) return 0;
    if (visit[l][r]){
        return dp[l][r];
    }
    visit[l][r] = 1;
    ll res = INF;
    ll s = sum(l, r);
    for (int i = l; i < r; i++){
        ll suml = solve(l, i);
        ll sumr = solve(i + 1, r);
        if (res > suml + sumr + s) res = suml + sumr + s;
    }
    dp[l][r] = res;
    return res;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    cout << solve(0, n - 1);
    return 0;
}


Measured memory_bytes: 3584
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import Text.Printf

readInt = ( readLn :: IO Int )
getInts = map ( read :: String -> Int ) . words <$> getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = readInt >>= print . ( 48 - )


Measured memory_bytes: 508
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		int N = int.Parse(str);
		string[] str2 = Console.ReadLine().Split();
		int min = 1000000000;
		int max = 0;
		for(var i=0;i<N;i++){
			int a = int.Parse(str2[i]);
			min = Math.Min(a,min);
			max = Math.Max(a,max);
		}
		Console.WriteLine(max-min);
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
using namespace std;
const int mod=1000000007;
const int INF=100100100;
typedef long long ll;
typedef pair<int,int> P;

vector<vector<int>> to;
vector<int> ao,ta;
int v,u;
// vactor<int> aoki;

void dfs(int start, int par = -1,int dep = 0){
    ao[start] = dep;
    for(auto v1 : to[start]){
        if(v1 == par)continue;
        dfs(v1,start,dep+1);
    }
    return;
}
void dfs2(int start, int par = -1,int dep = 0){
    if(ao[start] < dep)ta[start] = -1;
    else ta[start] = dep;
    for(auto v1 : to[start]){
        if(v1 == par)continue;
        dfs2(v1,start,dep+1);
    }
    return;
}



int main(){
    int n;
    cin >> n >> u >> v;
    --u;--v;
    int a,b;
    int ans = 0;
    to.resize(n);ao.resize(n);ta.resize(n);
    rep(i,0,n-1){
        ao[i] = INF;
        ta[i] = INF;
    }

    rep(i,1,n-1){
        cin >> a >> b;
        --a;--b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    
    dfs(v);
    dfs2(u);
    // vecprint(ao);
    // vecprint(ta);
    int sa = ao[u];
    rep(i,0,n-1){
        if(ta[i]!=-1)ans = max(ans,ao[i]);
    }
    ans--;

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 10368
import itertools
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]
M_chr = []
for i in range(1,M+1):
    M_chr.append(i)
As = list(itertools.combinations_with_replacement(M_chr, N))
pointA_max = 0
for i, A in enumerate(As):
    pointA = 0
    for i in range(Q):
        if A[abcd[i][1]-1]-A[abcd[i][0]-1] == abcd[i][2]:
            pointA = pointA + abcd[i][3]
    if pointA_max < pointA:
        pointA_max = pointA
print(pointA_max)

Measured memory_bytes: 84904
#include <iostream>
using namespace std;
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <cstdlib>

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

int main() {

	int n; cin >> n;
	int a[n];
	double ave = 0;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		ave += a[i];
	}
	//cout << ave << ave/n << ave/n+0.5 <<endl;
	if(ave >= 0) ave = floor(ave/n+0.5);
	else ave = floor(ave/n+0.5);
	
	ave = int(ave);
	//cout << ave <<endl;
	for(int i = 0; i < n; i++) {
		ans += pow(ave-a[i], 2);
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
signed main(){
	int n;
	while(cin>>n,n){
		vvi in(n,vi(2));
		rep(i,n)rep(j,2)cin>>in[i][j];
		sort(all(in));
		int tim=0;
		queue<pii>que[2];
		rep(i,n)que[0].push({in[i][0],i});
		while(!que[0].empty()||!que[1].empty()){
			tim=inf;
			rep(i,2)if(!que[i].empty()){
				int t=que[i].front().first;
				if(tim>t)tim=t;
			}
			rep(i,2){
				vp ne;
				while(!que[i].empty()&&que[i].front().first<=tim){
					ne.pb(que[i].front());
					que[i].pop();
				}
				rep(j,ne.size())rep(k,ne.size())
					if(in[ne[j].second][0]<in[ne[k].second][0])swap(ne[j],ne[k]);
				rep(j,ne.size()){
					pii p=ne[j];
					if(i){
						in[p.second][1]--;
						if(in[p.second][1])que[i^1].push({tim+in[p.second][0],p.second});
					}else que[i^1].push({tim+in[p.second][0],p.second});
				}
			}
		}
		cout<<tim<<endl;
	}
}









Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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


  ll A, B ; cin >> A >> B ;
  if(A==B){ cout << "Draw" << endl; return 0;}
  if(A > B ){
    if( B == 1) cout << "Bob" << endl;
    else cout << "Alice";
  }
  else{
    if(A==1) cout <<" Alice" << endl;
    else cout << "Bob" << endl;
  }
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

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

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

  int n;
  cin >> n;

  const int inf = 1e9;
  vector<int> dp(n + 1, inf);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    if (i + 1 <= n)
      chmin(dp[i + 1], dp[i] + 1);
    {
      int j = 6;
      while (i + j <= n) {
        chmin(dp[i + j], dp[i] + 1);
        j *= 6;
      }
    }
    {
      int j = 9;
      while (i + j <= n) {
        chmin(dp[i + j], dp[i] + 1);
        j *= 9;
      }
    }
  }

  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 3596
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
p = li()

minv = p[0]
ans = 1
for i in range(1,n):
    if p[i] <= minv:
        ans += 1
        minv = p[i]

print(ans)

Measured memory_bytes: 25716
#include<iostream>
#include<cmath>
using namespace std;
#define equals(a, b) (fabs(a-b) < 1e-3)

struct Point{
    double x, y, z;
    Point(double x, double y, double z) : x(x), y(y), z(z) {}
    Point() {}
};

double dist(Point a, Point b){
    return sqrt(pow(a.x-b.x,2.0)+pow(a.y-b.y,2.0)+pow(a.z-b.z,2.0));
}

int main(){
    int q;
    cin >> q;
    while(q-- > 0){
        double a[3];
        cin >> a[1] >> a[2] >> a[0];
        int n;
        cin >> n;
        Point p[n];
        for(int i = 0; i < n; i++)  cin >> p[i].x >> p[i].y >> p[i].z;
        int f, g, h;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i==j)     continue;
                for(int k = 0; k < n; k++){
                    if(i==k || j==k)    continue;
                    double b[3];
                    b[0] = dist(p[i], p[j]);
                    b[1] = dist(p[j], p[k]);
                    b[2] = dist(p[k], p[i]);
                    bool valid = true;
                    for(int l = 0; l < 3; l++)  valid &= equals(b[0]/a[0], b[l]/a[l]);
                    if(valid){
                        f = i, g = j, h = k;
                    }
                }
            }
        }
        cout << f+1 << " " << g+1 << " " << h+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3068