akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define AMAX 1000005
int main()
{
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    vector<int> cnt(AMAX);
    for(int x : a){
        if(cnt[x] != 0){
            cnt[x] = 2;
            continue;
        }
        for(int j=x; j<AMAX; j+=x){
            cnt[j]++;
        }
    }

    int ans = 0;
    for(int x : a){
        if(cnt[x]==1) ans++;
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 8008
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
#define yn(f) cout<<(f?"yes":"no")<<endl
#define Yn(f) cout<<(f?"Yes":"No")<<endl
#define YN(f) cout<<(f?"YES":"NO")<<endl
#define COUT(x) cout<<(x)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int a,b; cin>>a>>b;
  if(b<a) COUT(a-1);
  else COUT(a);
}













Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <algorithm>      //sort,二分探索,など
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <iterator>       //集合演算(積集合,和集合,差集合など)
#include <map>            //map(辞書)
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列

using namespace std;


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


    int n;
    cin >> n;
	map<int, int> a;
	int64_t sum = 0;
	for(int i = 0, tmp; i < n; ++i){
		cin >> tmp;
		sum += tmp;
		++a[tmp];
	}
    int q;
    cin >> q;
	vector<int> b(q);
	vector<int> c(q);
	for(int i = 0; i < q; ++i){
		cin >> b[i] >> c[i];
	}
	for(int i = 0; i < q; ++i){
		sum += a[b[i]] * (c[i] - b[i]);
		a[c[i]] += a[b[i]];
		a[b[i]] = 0;
		cout << sum << "\n";
	}
    
	return 0;
}

Measured memory_bytes: 8508
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.nio.Buffer;
import java.util.*;


public class Main {
    public static Scanner r=new Scanner(System.in);
    public static void solve(int n,int m){
        int l1=1,r1=n/2;
        int l2=n/2+1,r2=n;
        while(l1<r1&&m>0){
            System.out.println(l1+" "+r1);
            ++l1;
            --r1;
            --m;
        }
        while(l2<r2&&m>0){
            System.out.println(l2+" "+r2);
            ++l2;
            --r2;
            --m;
        }
    }
    public static void main(String[] args) {
        int n=r.nextInt();
        int m=r.nextInt();
        if(n%2==0){
            solve(n-1,m);
        }
        else{
            solve(n,m);
        }
    }
}


Measured memory_bytes: 53180
N,A,B=map(int,input().split())

def sum_keta(n):
    sum=0
    while n>0:
        sum+=n%10
        n=n//10
    return sum

total=0
for n in range(1,N+1):
    if A<=sum_keta(n)<=B:
        total+=n
    else:
        continue

print(total)

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000001;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main () {
  COMinit();
  long X, Y;
  cin >> X >> Y;
  int flag = 0;
  long ans = 0, sub;
  for(int i = 1; i <= min(X, Y); i++){
    if(i == (X - i + Y - i)){
      sub = i;
      flag = 1;
      break;
    }
  }
  if(flag == 0){
    cout << 0 << endl;
    return 0;
  }
  cout << COM(sub, X - sub) << endl;
  return 0;
}

Measured memory_bytes: 23808
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long long unsigned int llu;
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define YUGEN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define lp(i,start,end) for(int i=start;i<end;i++)
#define MAX 105
#define BPC(x)  __builtin_popcountll(x)
#define test() ll t; cin>>t; while(t--)
#define gcd(a,b)  __gcd(a,b)
#define SIZE 26
ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}

int main()
 {
    YUGEN;
      ll a,b,c,d;
      cin>>a>>b>>c>>d;
      ll ans=max({a*c,a*d,b*c,b*d});
      cout<<ans;
 }




Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
vector<int>p;
vector<int>rank;
int find(int x){
  if(x==p[x]){
    return x;
  }
  return p[x]=find(p[x]);
}
int same(int x,int y){
  if(find(x)==find(y)){
    return 1;
  }
  return 0;
}
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(rank[x]>rank[y]){
    p[y]=x;
  }else{
    p[x]=y;
    if(rank[x]==rank[y]){
      rank[y]++;
    }
  }
}
int main(){
  int n,q;
  cin>>n>>q;
  for(int i=0;i<n;i++){
    p.push_back(i);
    rank.push_back(0);
  }
  int co,x,y;
  for(int i=0;i<q;i++){
    cin>>co>>x>>y;
    if(co==0){
      unite(x,y);
    }else{
      cout<<same(x,y)<<endl;
    }
  }
  return(0);
}



Measured memory_bytes: 3292
#!/usr/bin/env python3

if __name__ == '__main__':
    n = int(input())
    ary = []
    city = []
    ans = []
    for i in range(n):
        x, y = input().split()
        city.append(x)
        ary.append([x, int(y), i+1])
    
    cities = sorted(set(city), key=city.index)
    cities.sort()
    for c in cities:
        tmp = [x for x in ary if x[0] == c]
        tmp.sort(reverse=True)
        for t in tmp:
            ans.append(t)

    for s in ans:
        print(s[2])

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

#define all(x) (x).begin(),(x).end()
#define fastio ios_base::sync_with_stdio(false)

typedef double db;
typedef long long ll;
typedef unsigned long long ull;

typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;


int main() {
	fastio;
	
	string s,t; cin >> s >> t;

	int n = s.length(), m = t.length();

	int dp[n + 1][m + 1];

	memset(dp, 0, sizeof(dp));

	dp[0][0] = (s[0] == t[0]) ? 1 : 0;

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < m; ++j) {
			if(i == 0 and j == 0)
				continue;
			if(i == 0) {
				if(s[i] == t[j])
					dp[i][j] = 1;
				else
					dp[i][j] = dp[i][j - 1];
				continue;
			}
			if(j == 0) {
				if(s[i] == t[j])
					dp[i][j] = 1;
				else
					dp[i][j] = dp[i - 1][j];
				continue;
			}
			else {
				if(s[i] == t[j])
					dp[i][j] = 1 + dp[i - 1][j - 1];
				else
					dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}

	// int maxlen = dp[n - 1][m - 1];
	

	string ans = " ";

	// for(int i = 0; i < n; ++i) {
	// 	for(int j = 0; j < m; ++j)
	// 		cout << dp[i][j] << " ";
	// 	cout << endl;
	// }

	int i = n - 1, j = m - 1;

	while(i >= 0 and j >= 0) {
		if(s[i] == t[j]) {
			ans += s[i];
			--i, --j;
		}
		else {
			if(dp[i - 1][j] > dp[i][j - 1]) 
				--i;
			else
				--j;
		}
	}
	reverse(all(ans));

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

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

int main(){
    int pay=0;
    string s;
    cin>>s;
    for (int i=0; i<3; i++) {
        if(s[i]=='o'){
            pay += 100;
        }
    }
    cout<<700+pay<<endl;
    return 0;
}


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


	int n, m, i, j;
	int c[1011], d[1011];
	int dp[1011][1001];

int main() {
	
	cin >> n >> m;
	for(i = 0; i < n; i++) {
		cin >> d[i];
	}
	for(i = 0; i < m; i++) {
		cin >> c[i];
	}
	
	for(i = 0; i < n+1; i++) {
		for(j = 0; j < m+1; j++) {
			dp[i][j] = 1000111000;
		}
	}
	
	for(i = 0; i < m+1; i++) {
		dp[n][i] = 0;
	}
	
	for(i = n-1; i >= 0; i--) {
		for(j = m-1; j >= 0; j--) {
			dp[i][j] = min(dp[i+1][j+1]+(c[j]*d[i]), dp[i][j+1]);
		}
	}
	
	cout << dp[0][0] << endl;
	
	return 0;
}

Measured memory_bytes: 4352
#include <stdio.h>

#define MAX_PRIME	(123456 * 2)


int prime[MAX_PRIME + 1];

void make_prime(void)
{
    int i;
    int j;
    int n;
    int c;
    
    for (i = 2; i * i <= MAX_PRIME; i++){
        if (prime[i] == 0){
            for (j = i * 2; j <= MAX_PRIME; j += i){
				prime[j] = 1;
            }
        }
    }
}
	


int main(void)
{
	int n;
    int i;
	int count;
	
	make_prime();

    while (scanf("%d", &n) != EOF){
		
		count = 0;
		for (i = 2; i < n; i++){
			if (prime[i] == 0 && prime[n - i + 1] == 0){
				count++;
			}
		}
		printf("%d\n", count);
    }
    
    return (0);
}

Measured memory_bytes: 1560
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

double PI = acos(-1);

int main()
{
    double a, b, x;
    cin >> a >> b >> x;

    double theta;
    if (a*a*b/2.0 <= x) {
        theta = atan(2 * (a * a * b - x) / (a * a * a));
    } else {
        theta = PI / 2 - atan(2 * x / (a * b * b));
    }

    cout << fixed << setprecision(10) << 180.0 * theta / PI << endl;
}

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

long long a,b,c;

int main()
{
	cin >> a >> b >> c;
	if(a+b>=c)cout << "No";
	else if((c-a-b)*(c-a-b)<=4*a*b)cout << "No";
	else cout << "Yes";
	return 0;
}

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

int main() {

    int n;
    cin >> n;

    int *xs = new int[n];
    int *ys = new int[n];
    double rs = 0.0;

    for (int i = 0; i < n; ++i) {
        cin >> xs[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> ys[i];
    }

    for (int i = 0; i < n; ++i) {
        rs += fabs(xs[i] - ys[i]);
    }
    cout << fixed << setprecision(7) << rs << endl;

    rs = 0.0;
    for (int i = 0; i < n; ++i) {
        rs += pow(xs[i] - ys[i], 2);
    }
    cout << fixed << setprecision(7) << sqrt(rs) << endl;

    rs = 0.0;
    for (int i = 0; i < n; ++i) {
        rs += pow(fabs(xs[i] - ys[i]), 3);
    }
    cout << fixed << setprecision(7) << cbrt(rs) << endl;

    rs = 0.0;
    for (int i = 0; i < n; ++i) {
        if (rs < fabs(xs[i] - ys[i])) {
            rs = fabs(xs[i] - ys[i]);
        }
    }
    cout << fixed << setprecision(7) << rs << endl;

    delete[] xs;
    delete[] ys;

    return 0;
}

Measured memory_bytes: 1348
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#define NUM 100

using namespace std;

int main(void){
    int n, k;
    scanf("%d %d", &n, &k);

    vector<int> D(n);
    for(int i = 0; i < n; i++){
        int v;
        scanf("%d", &v);
        D[i] = v;
    }

    int max_value = 0;
    for(int i = 0; i <= k; i++){
        for(int j = 0; i + j <= k; j++){
            if(i + j > n){
                continue;
            }

            vector<int> v;
            for(int t = 0; t < i; t++){
                v.push_back(D[t]);
            }
            for(int t = 0; t < j; t++){
                v.push_back(D[D.size() - t - 1]);
            }

            if(v.size() != 0){
                sort(v.begin(), v.end());
            }

            for(int l = 0; i + j + l <= k; l++){
                if(i + j < l){
                    continue;
                }
                int value = 0;
                for(int t = l; t < v.size(); t++){
                    value += v[t];
                }
                max_value = max(max_value, value);
                //printf("value %d\n", value);
            }
        }
    }

    printf("%d\n", max_value);
}


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



int main(){
  while(1){


    
  int n;
  int p;
  cin>>n>>p;
  if(n==0 && p==0){break;}
  int al=p;
  int a[100]={};
  int j=-1;
  while(j==-1){
    for(int i=0;i<n;i++){
      if(p>0){p--; a[i]++; if(a[i]==al){j=i; break;}}
      else{p+=a[i]; a[i]=0;}
    }
  }
  cout<<j<<endl;





  }
  
  return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>

int main(void){

	int a,b,c;
	int kosu = 0;

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

	for(;a<=b;a++){
		if(c%a==0){
			kosu++;
		}
	}
	printf("%d\n",kosu);

	return 0;
}

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

int main()
{
 long long int n,i,sum=0;
 cin>>n;
 for(i=1;i<=n;i++)
 {
     if(i%3!=0 && i%5!=0)
     {
         sum+=i;
     }
 }
 cout<<sum;


}


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

bool kaibun(string s){
    bool ans = true;
    rep(i,s.size()/2+1){
        if(s[i]!=s[s.size()-1-i]){
            ans = false;
        }
    }
    return ans;
}

int main() {
    string s;
    cin >> s;
    string a,b;
    a=s.substr(0,(s.size()-1)/2);
    b=s.substr((s.size()+3)/2-1,(s.size()-1)/2);
    if(kaibun(s)&&kaibun(a)&&kaibun(b)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();

		int a[][] = new int [n][m];
		int b[] = new int[m];
		int ans[] = new int[n];
		int k,c,l,i,j;

		for(k=0;k<n;k++) {
			for(c=0;c<m;c++) {
				a[k][c] = scan.nextInt();
			}
		}

		for(l=0;l<m;l++) {
			b[l] = scan.nextInt();
		}

		for(i=0;i<n;i++) {
			for(j=0;j<m;j++) {
				ans[i] += a[i][j] * b[j];
			}
			System.out.println(ans[i]);
		}
		scan.close();

	}

}



Measured memory_bytes: 40216
#include <map>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

const int N=20;

int n,a[N];

struct State{
	int l,r,cl,cr;
	State(int _l=0,int _r=0,int _cl=0,int _cr=0) {l=_l;r=_r;cl=_cl;cr=_cr;}
	friend bool operator < (State a,State b) {
		if (a.l!=b.l) return a.l<b.l;
		if (a.r!=b.r) return a.r<b.r;
		if (a.cl!=b.cl) return a.cl<b.cl;
		return a.cr<b.cr;
	}
};

map<State,ll> h;

ll Dp(int l,int r,int cl,int cr) {
	State now=State(l,r,cl,cr);
	if (h.count(now)) return h[now];
	if (l+1>=r) return h[now]=0;
	ll ans=1e15;
	fo(i,l+1,r-1) ans=min(ans,Dp(l,i,cl,cl+cr)+Dp(i,r,cl+cr,cr)+(ll)(cl+cr)*a[i]);
	return h[now]=ans;
}

int main() {
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	printf("%lld\n",a[1]+a[n]+Dp(1,n,1,1));
	return 0;
}

Measured memory_bytes: 32896
#include <iostream>

using namespace std;
int A[200000],n;

int binary_searcher(int key)
{
    int mid;
    int left=0;
    int right=n-1;
    while(left<right)
    {
        mid=(left+right)/2;
        if(A[mid]==key || A[right]==key) return 1;
        else if(key<=A[mid]) right=mid;
        else left=mid+1;
    }
    return 0;
}

int main()
{
    int i,q,sum=0;
    int key;
    cin>>n;
    for(int i=0;i<n;i++) cin>>A[i];
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>key;
        if(binary_searcher(key))
	  	sum++;
    }
    cout<<sum<<endl;
    return 0;

}



Measured memory_bytes: 3376
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
    string a;
    cin >> a;
    if(a[0] == 'A')cout << "T" << endl;
    else if(a[0] == 'T')cout << "A" << endl;
    else if(a[0] == 'G')cout << "C" << endl;
    else cout << "G" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std;

int N, W, w0, v0;
int w[105], v[105];
int wt[4], vi[4][105];

int dfs(int wtf, int left) {
	if (wtf == 4 || left <= 0) return 0;
	int ans = dfs(wtf + 1, left), m = 0;
	for (int i = 0; i != wt[wtf]; ++i) {
		left -= w[0] + wtf;
		if (left < 0) break;
		m += vi[wtf][i];
		int x = m + dfs(wtf + 1, left);
		ans = max(ans, x);
	}
	return ans;
}

int main() {
	scanf("%d%d", &N, &W);
	for (int i = 0; i != N; ++i)
		scanf("%d%d", &w[i], &v[i]);
	for (int i = 0; i != N; ++i)
		vi[w[i] - w[0]][wt[w[i] - w[0]]++] = v[i];
	for (int i = 0; i != 4; ++i)
		sort(vi[i], vi[i] + wt[i], greater<int>());
	printf("%d\n", dfs(0, W));
	return 0;
}


Measured memory_bytes: 128
n, a, b = map(int, input().split())

l =[i for i in range(1,n+1)]

x = 0
for j in range(n):
     y = [int(i) for i in str(l[j])]
     if sum(y) >=a and sum(y) <=b:
         x += l[j]

print(x)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc100/abc100_b.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int d, n;
  cin >> d >> n;

  d = pow(100, d);
  ll ans = d * n;
  if (n == 100) {
    ans += d;
  }

  cout << ans << endl;
}

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

typedef struct fox{ int val; fox *left, *right; } fox_n;

fox_n* init()
{
    fox_n* root = new fox_n;
    root->val = -1;
    root->left = NULL;
    root->right = NULL;
    return root;
}

void insert(fox_n* root, int key)
{
    static bool first = true;
    static bool add_leaf = true;  // true:left, false:right.
    if(first){ first = false; root->val = key; return; }  // initialize.
    fox_n* canis;
    fox_n* water = root;  // water from root to leaf.
    do{
        canis = water;
        if(key < canis->val){  // canis chases water.
            water = canis->left;
            add_leaf = true;
        }else{
            water = canis->right;
            add_leaf = false;
        }
    }while(water != NULL);

    fox_n* leaf = new fox_n;  // add new leaf.
    leaf->val = key;
    leaf->left = NULL;
    leaf->right = NULL;
    if(add_leaf){ canis->left = leaf; }else{ canis->right = leaf; }
    return;
}

void inorder(fox_n* root)
{
    if(!root) return;
    inorder(root->left);
    printf(" %d", root->val);
    inorder(root->right);
    return;
}

void preorder(fox_n* root)
{
    if(!root) return;
    printf(" %d", root->val);
    preorder(root->left);
    preorder(root->right);
    return;
}

int main()
{
    fox_n* root = init();
    int i, n, key; string str;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> str;
        if(str[0] == 'i'){ cin >> key; insert(root, key); }
        else{ inorder(root); printf("\n"); preorder(root); printf("\n"); }
    }
    return 0;
}

Measured memory_bytes: 16820
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    char c;
    string ans;
    cin >> c;
    if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u') ans = "vowel";
    else ans = "consonant";
    cout << ans << endl;
    return 0;
}


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

int main(){
    int H,W,N;
    cin >> H >> W >> N;
    int m = max(H,W);
    if(N % m == 0) cout << N / m << endl;
    else cout << N / m + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

typedef struct {
  unsigned char a0: 1;
  unsigned char a1: 1;
  unsigned char a2: 1;
  unsigned char a3: 1;
  unsigned char a4: 1;
  unsigned char a5: 1;
  unsigned char a6: 1;
  unsigned char a7: 1;
}boolean;

void set_boolean(boolean *bool, int ad, char in) {
  switch (ad) {
  case 0:
    bool->a0 = in;
    break;
  case 1:
    bool->a1 = in;
    break;
  case 2:
    bool->a2 = in;
    break;
  case 3:
    bool->a3 = in;
    break;
  case 4:
    bool->a4 = in;
    break;
  case 5:
    bool->a5 = in;
    break;
  case 6:
    bool->a6 = in;
    break;
  case 7:
    bool->a7 = in;
    break;
  default:
    break;
  }
}

char check_boolean(boolean *bool, int ad) {
  switch (ad) {
  case 0:
    return bool->a0;
    break;
  case 1:
    return bool->a1;
    break;
  case 2:
    return bool->a2;
    break;
  case 3:
    return bool->a3;
    break;
  case 4:
    return bool->a4;
    break;
  case 5:
    return bool->a5;
    break;
  case 6:
    return bool->a6;
    break;
  case 7:
    return bool->a7;
    break;
  default:
    printf("miss");
    return 0;
    break;
  }
}

void sieve(boolean *list, long max) {
  int i,j;
  long k;

  for(k = 0; k <= max; k++)
    set_boolean(list+k/8, (int)(k%8), 0);

  
  list[0].a0 = 1;
  list[0].a1 = 1;

  for(i = 2; 2*i <= max; i++)
    set_boolean(list+i/4, (2*i)%8, 1);
  
  for(i = 3; i <= (int)sqrt(max); i++)
    if(check_boolean(list+i/8,(int)i%8) == 0)
      for(j = i; i*(long)j <= max; j+=2)
	set_boolean(list+i*j/8,(int)(i*j%8), 1);
  
}

int main() {
  int N,i,t;
  scanf("%d", &N);
  long a[N],max;
  max = 0;
  for(i = 0; i < N; i++) {
    scanf("%ld", a+i);
    if(a[i] > max) max = a[i];
  }
  
  boolean *list;
  list = (boolean *)malloc(sizeof(boolean)*(max/8+1));
  sieve(list,max);

  t = 0;
  for(i = 0; i < N; i++) {
    if(check_boolean(list+a[i]/8, (int)a[i]%8) == 0) t++;
  }
  printf("%d\n", t);

  free(list);
  return 0;
}

Measured memory_bytes: 12772
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=105;
int n;
int a[N];
bool checker(int l,int r,int ch){
    if(ch<l) return false;
    if(ch>=r) return false;
    return true;
}
signed main(){
    scanf("%lld",&n);
    if(n==1){
        printf("1\n");
        exit(0);
    }
    a[1]=2;
    for(int i=2;i<N;i++) a[i]=(a[i-1]<<1);
    for(int i=1;i<N;i++)
        if(checker(a[i],a[i+1],n)){
            printf("%lld\n",a[i]);
            exit(0);
        }
    exit(0);
}


Measured memory_bytes: 256
class SegTree
  attr_reader :size, :e, :f
  attr_accessor :seg

  def self.create(a=[],e,f)
    n = 1
    n *= 2 while n < a.size
    this = new(n,e,f)
    a.size.times do |i|
      this.seg[i+n] = a[i]
    end
    (n-1).downto(1) do |i|
      this.seg[i] = f[ this.seg[i*2],this.seg[i*2+1] ]
    end
    this
  end

  def initialize(n=2**32,e,f)
    @size = n
    @e = e
    @f = f
    @seg = Array.new(size*2, e)
  end

  def [](i)
    i += size
    seg[i]
  end

  def update(i,x)
    i += size
    seg[i] = x
    while i > 1
      i /= 2
      seg[i] = f[ seg[i*2], seg[i*2+1] ]
    end
  end

  def query(a,b)
    ans = e
    a += size; b += size
    while a < b
      (ans = f[ ans, seg[a] ]; a += 1) if a.odd?
      (b -= 1; ans = f[ ans, seg[b] ]) if b.odd?
      a /= 2; b /= 2
    end
    ans
  end

  def inspect
    { size: size, seg: seg }.to_s
  end
end

# SegTree.new(N,E,F) := 要素数N、単位元E、演算Fで初期化、ただしNは2の冪
# SegTree.create(A,E,F) := モノイドA、単位元E、演算Fで初期化で初期化
# update(i,x) := A[i]をxに更新
# query(a,b) := 半開区間[a,b)でのA[i]の演算結果
#
# 単位元を追加してモノイドにする例（gcd）
# E = -1
# F = -> x,y { x == E ? y : y == E ? x : x.gcd(y) }
# T = SegTree.create(a,E,F)

n = gets.to_i
Black = gets.chomp.chars.map{|c| c == "#" ? 1 : 0 }
White = Black.map{|i| 1 - i }

E = 0
F = -> x,y { x + y }
BlackTree = SegTree.create(Black,E,F)
WhiteTree = SegTree.create(White,E,F)

ans = 10**6
0.upto(n) do |i|
  num = BlackTree.query(0,i) + WhiteTree.query(i,n)
  ans = num if ans > num
end

puts ans


Measured memory_bytes: 30228
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll X, ll Y) {
  cout << (abs(X - Y) <= 1 ? "Brown" : "Alice") << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll Y;
	ll X;
	scanf("%lld", &X);
	scanf("%lld", &Y);
	solve(X, Y);
	return 0;
}


Measured memory_bytes: 256
n,*as=$<.read.split.map &:to_i
m,s=1000,0
as.each_cons(2){|ac,an|
  if ac<an
    q,m=m.divmod(ac)
    s+=q
  else
    m+=ac*s
    s=0
  end
}
puts m+s*as[-1]

Measured memory_bytes: 14364
n = int(input())
a = list(map(int,input().split()))
b = []
c = []
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    if i % 2 == 1:
        c.append(a[i])
c.reverse()
c += b
if n % 2 == 1:
    c.reverse()
print(*c)

Measured memory_bytes: 25156
#include<stdio.h>

int main(){
  int o,n,k,i,j;
  int key;
  int A[110];
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d",&A[i]);

  /*for(o=1;o<=n;o++)
    {
      if(o == n){printf("%d\n",A[o]);}
      else printf("%d ",A[o]);
    }
  */
  for(j=1;j<=n;j++)
    {   
	      key = A[j];		
	      i = j-1;
	      while(i>0 && A[i]>key)
		{
		  A[i+1]=A[i];  
		  i = i-1;
		}
	      A[i+1] = key;
	      for(k=1;k<=n;k++){
		if(k == n)printf("%d\n",A[k]);
		else printf("%d ",A[k]);
	      }
    }
  
  return 0;
}

Measured memory_bytes: 0
#define REP(i, t, n)    for (int i = t; i < n; i++)
#define ALL(n)              (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
 
using namespace std;
 
typedef bool             BOOL;
typedef short            WORD;
typedef unsigned short   U_WORD;
typedef long             DWORD;
typedef unsigned long    U_DWORD;
typedef long long        QWORD;
typedef unsigned long long U_QWORD;
 
 
 
#define M_MAX     (393)
#define N_MAX     (393)
#define LEN_MAX   (393)
typedef pair<DWORD, DWORD> PAIR;
 
int N, M;
DWORD Dp[N_MAX + 1][LEN_MAX + 1] = {};
DWORD adwMelody[M_MAX] = {};
DWORD adwPoint[N_MAX] = {};
vector<PAIR> vFraseLength;
 
 
void input()
{
    cin >> N;
    REP(i, 0, N) {
        PAIR tempLength;
        cin >> tempLength.first >> tempLength.second;
        vFraseLength.push_back(tempLength);
        cin >> adwPoint[i];
    }
 
    cin >> M;
    REP(i, 0, M) {
        cin >> adwMelody[i];
    }
 
}
 
void CalcDpTable()
{
    REP(i, 0, N) {
        PAIR nowFrase = vFraseLength[i];
        DWORD   nowPoint = adwPoint[i];
        REP(j, 0, LEN_MAX + 1) {
            if (j >= nowFrase.first) {
                DWORD tmpVal = Dp[i][j];
                REP(k, nowFrase.first, nowFrase.second+1) {
                    if (j < k) break;
                    tmpVal = max(tmpVal, max(Dp[i][j-k] + nowPoint, Dp[i+1][j-k] + nowPoint));
                }
                Dp[i+1][j] = tmpVal;
            } else {
                Dp[i + 1][j] = Dp[i][j];
            }
        }
    }
    return;
}
 
void makeAns()
{
    vector<DWORD> ans;
    REP(i, 0, M) {
        DWORD tmpAns = Dp[N][adwMelody[i]];
 
        if (tmpAns == 0) {
            cout << -1 << endl;
            return;
        } else {
            ans.push_back(tmpAns);
        }
    }
 
    REP(i, 0, M) {
        cout << ans[i] << endl;
    }
    return;
}
 
void solve_main()
{
    input();
 
    CalcDpTable();
 
    makeAns();
}
 
int main()      
{
#ifdef FOR_IDE
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
 
    solve_main();
    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    
    int a[26] = {0};
    
    for(int i = 0; i < s.size(); ++i)
    {
        if(a[s[i] - 'a'] == 0)
        {
            a[s[i] - 'a']++;
        }
    }
    
    for(int i = 0; i < 26; ++i)
    {
        if(a[i] == 0)
        {
            char ch = 'a' + i;
            cout << ch << endl;
            return 0;
        }
    }
    
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define BigInt      __int128
#define endl        '\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define sim         template < class c
#define ris         return * this
#define dor         > debug & operator <<
#define eni(x)      sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

using namespace std;

sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug 
{
	~debug() 
	{ 
		cerr<<endl; 
	}
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) 
	{
		ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) 
	{
	  	*this << "[";
	  	for (auto it = d.b; it != d.e; ++it)
	    	*this << ", " + 2 * (it == d.b) << *it;
	  	ris << "]";
	}
};
#define fuck(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		char c;
		cin >> c;
		if(c >= 'a' && c <= 'z') c = 'a';
		else c = 'A';
		cout<<c;
	}
	return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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


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

	for (int i = 1; i <= n; i++){
		if(floor(i*1.08)==n){
			cout<<i<<endl;
			return 0;
		}
	}

	cout<<":("<<endl;

}

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

using namespace std;

int l1, l2;
char s[3005], t[3005];
int dp[3005][3005];
pair <int, int> to[3005][3005];

int solve(int n, int m) {
    if (dp[n][m] != -1) return dp[n][m];
    if (n >= l1 || m >= l2) return 0;

    if (s[n] == t[m]) {
        to[n][m] = make_pair(n + 1, m + 1);
        return dp[n][m] = solve(n + 1, m + 1) + 1;
    }

    if (solve(n + 1, m) > solve(n, m + 1)) {
        dp[n][m] = solve(n + 1, m);
        to[n][m] = make_pair(n + 1, m);
    }
    else {
        dp[n][m] = solve(n, m + 1);
        to[n][m] = make_pair(n, m + 1);
    }

    return dp[n][m];
}

int main() {
    scanf("%s%s", s, t);

    l1 = strlen(s);
    l2 = strlen(t);

    memset(dp, -1, sizeof(dp));
    for (int i = 0; i <= l1; i++) {
        for (int j = 0; j <= l2; j++) to[i][j] = make_pair(-1, -1);
    }

    solve(0, 0);

    pair <int, int> cur = make_pair(0, 0);

    string res = "";

    while (cur.first != -1) {
        int a = cur.first;
        int b = cur.second;
        if (to[a][b].first == a + 1 && to[a][b].second == b + 1) res += s[a];

        cur.first = to[a][b].first;
        cur.second = to[a][b].second;
    }

    cout << res << endl;
}


Measured memory_bytes: 106624
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    int count = 0;
    int powed = a == 0 ? 1 : a == 1 ? 100 : 10000;
    while (true) {
        if (ans % powed == 0 && (ans / powed) % 100 != 0) {
            count++;
        }
        if (count == b) {
            cout << ans;
            return 0;
        }
        ans++;
    }
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  priority_queue<int> q;
  q.push(A+B);
  q.push(A-B);
  q.push(A*B);
  
  cout << q.top() << endl;
  return 0;
}

Measured memory_bytes: 256
N,X,M = map(int,input().split())
S = X
A = [X]
exists = [0]*M
exists[X] = 1

for i in range(2,N+1):
  A_i = (A[-1]*A[-1])%M
  A.append(A_i)
  S += A_i
  if exists[A_i] == 0:
    exists[A_i] = 1
  else:
    S -= A_i
    del A[-1]
    B = A[A.index(A_i):]
    S += ((N-len(A))//len(B))*sum(B) + sum(B[:((N-len(A))%len(B))])
    break

print(S)

Measured memory_bytes: 12308
#include <iostream>


using namespace std;

int main()
{
int n ,x ,mx= -1;
scanf("%d",&n);
char s;
for(int i=0;i<=n;i++){
	scanf("%c",&s);
	if(s=='I'){
	x++;
	}
mx= max(x,mx);
	 if(s=='D'){
	x--;
	} }
printf("%d",mx);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    ll n;cin >> n;
    ll s=0;
    for(ll i=1;i<=n;i++){
        if(!(i%3==0 && i%5==0)){
            if(!(i%3==0)){
                if(!(i%5==0)){
                    s+=i;
                }
            }
        }
    }
    cout << s << "\n";

}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

signed main() {
	ll a, b, c; scanf("%lld%lld%lld", &a, &b, &c);
	if (a == b&&b == c&&a % 2 == 0) {
		puts("-1"); return 0;
	}
	int cnt = 0;
	while (1) {
		if (a % 2 || b % 2 || c % 2)break;
		cnt++;
		ll d, e, f;
		d = b / 2 + c / 2; e = a / 2 + c / 2; f = a / 2 + b / 2;
		a = d; b = e; c = f;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
string s, t;

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> s >> t;
    int c = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != t[i])
        {
            c++;
        }
    }
    cout << c;
}

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

// 基本テンプレート
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// 型
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// 定数
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int w, a, b;
    cin >> w >> a >> b;
    if(a+w<b) P(b-a-w);
    else {
        if(b+w<a) P(a-b-w);
        else P(0);
    }
    return 0;
}



Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	int a,b,c,x,i,j,k,t,cnt=0;
	cin>>a>>b>>c>>x;
	for(i=0 ; i<=a ; i++){
		for(j=0 ; j<=b ; j++){
			for(k=0 ; k<=c ; k++){
				t = 500*i + 100*j + 50*k;
				if(t==x)cnt++;
				}
			}
		}
	cout<<cnt<<nw;
	
	return 0;
}

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

int n;
ll knap(ll n, vector<pair<int,int>> &v) {// run knapsack with these parameters
  vector<ll> dp(n+10, 0);
  iota(dp.begin(), dp.end(), 0);
  for(int j=0;j<v.size();j++) {
    //cerr << "DOING " << v[j].first  << " " << v[j].second <<endl;
    for(int i=0;i<=n-v[j].first;i++) {
      //cerr << dp[i+v[j].first] << " " << dp[i] + v[j].second <<endl;
      dp[i+v[j].first] = max(dp[i+v[j].first],dp[i]+v[j].second);
    }
  }
//  for(int i=0;i<n;i++) cerr << dp[i] <<" "; cerr <<endl;
  return dp[n];
}
int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  cin >> n;
  vector<int> A(3), B(3);
  for(int i=0;i<3;i++) cin >> A[i];
  for(int i=0;i<3;i++) cin >> B[i];
  for(int i=0;i<3;i++) {
    if (A[i] > B[i]) {
      swap(A[i], A[2]), swap(B[i], B[2]);
    }
  }
  int cnt = 0;
  vector<pair<int,int>> v1, v2;
  v1.emplace_back(1,1);
  for(int i=0;i<3;i++) {
    if (A[i]<=B[i]) {
      cnt++;
      v1.emplace_back(A[i], B[i]);
    }
    else v2.emplace_back(B[i], A[i]);
  }
  // maximize a to b
  ll tot=knap(n, v1);
  // maximize b to a
  tot=knap(tot,v2);
  cout << tot <<endl;
}


Measured memory_bytes: 195584
#!/usr/bin/env python3
while True:
    n, m = map(int, input().split())
    if n == 0:
        exit()
    a = list(map(int, input().split()))
    ans = -1
    for i in range(n):
        for j in range(n):
            if i == j: continue
            s = a[i] + a[j]
            if s <= m:
                ans = max(ans, s)
    print([ans, 'NONE'][ans == -1])




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

using namespace std;

int main()
{int n,m;
cin>>n;
map <int ,int> x;
for(int i=0;i<n;i++)
{
    long long s;cin>>s;
    x[s]++;
}
cin>>m;
for(int i=0;i<m;i++)
{
   long long s;cin>>s;
    x[s]--;
    if(x[s]<0)
    {
        cout<<"NO"<<endl;
        return 0;
    }
    
}
 cout<<"YES"<<endl;
        return 0;
}
//mmmm

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

struct edge { ll to, cost; };
typedef pair<ll, ll>P; //firstは最短距離、secondは頂点番号
ll d[213456];//始点sから終点tまでのコストd[t]
vector<edge> G[213456];//コスト
void dijkstra(ll s) {
	//greater<P>を指定→firstが小さい順
	priority_queue<P, vector<P>, greater<P> >que;
	fill(d, d + 213456, INF);//←TLE気を付ける
	d[s] = 0; que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) { continue; }
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

ll cost[12345678], cnt[12345678];
signed main() {
	ll n, k, a, b, ans = 1; cin >> n >> k;
	vector<vector<ll> > GG(123456);
	rep2 (i, n) {
		cin >> cost[i] >> cnt[i];
	}
	rep (i, k) {
		cin >> a >> b;
		GG[a].push_back(b);
		GG[b].push_back(a);
	}

	rep2(h, n) {
		queue<ll> que, cn;
		vector<bool> visit(n + 2, false); visit[h] = true;
		for (int i = 0; i < GG[h].size(); i++) {
			G[h].push_back({ GG[h][i], cost[h] });
			que.push(GG[h][i]); cn.push(2); visit[GG[h][i]] = true;
		}
		while (que.size()) {
			if (cn.front() > cnt[h]) { que.pop(); cn.pop(); continue; }
			for (int i = 0; i < GG[que.front()].size(); i++) {
				if (!visit[GG[que.front()][i]]) {
					G[h].push_back({ GG[que.front()][i], cost[h] });
					que.push(GG[que.front()][i]); cn.push(cn.front() + 1); visit[GG[que.front()][i]] = true;
				}
			}
			que.pop(); cn.pop();
		}
	}

	dijkstra(1);
	cout << d[n] << endl;
	return 0;
}


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

int main(){
    double r;
    cin >> r;
    double pi = 3.14159265358979;
    double ans1 = r * r * pi;
    double ans2 = 2 * r * pi;
    printf("%lf %lf\n", ans1,ans2);
    return 0;
}



Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=4e5+5;
ll a[N];
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int x,y;
    cin >>x >> y;
    if(x<=8&&y<=8)  cout <<"Yay!"<<"\n";
    else    cout <<":(";

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

void merge(int *A,int left,int mid,int right,int *count){
	int n1,n2,i,j,k;
	int *L,*R;
	n1=mid-left;
	n2=right-mid;
	mymalloc(L,n1+1);
	mymalloc(R,n2+1);
	for(i=0;i<n1;i++){
		L[i]=A[left+i];
	}
	for(j=0;j<n2;j++){
		R[j]=A[mid+j];
	}
	L[n1]=INT_MAX;R[n2]=INT_MAX;
	i=0;j=0;
	for(k=left;k<right;k++){
			(*count)++;
		
		if(L[i]<=R[j]){
			A[k]=L[i];
			i++;
		}
		else{
			A[k]=R[j];
			j++;
		}
	}
	free(L);free(R);
}

void mergeSort(int *A,int left,int right,int *count){
	int mid;
	if(left+1<right){
		mid=(right-left)/2+left;
		mergeSort(A,left,mid,count);
		mergeSort(A,mid,right,count);
		merge(A,left,mid,right,count);
	}
}

main(){
	int i,count,n,*A;
	scanf("%d",&n);
	mymalloc(A,n);
	for(i=0;i<n;i++){
		scanf(" %d",&A[i]);
	}
	count=0;
	mergeSort(A,0,n,&count);
	for(i=0;i<n;i++){
		printf("%d",A[i]);
		if(i!=n-1){
			printf(" ");
		}
	}
	printf("\n");
	printf("%d\n",count);
	free(A);
	return 0;
}

Measured memory_bytes: 4484
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

ll dp(ll l,ll r,vector<vector<ll>>&dpv,ll &n,vector<ll>&a){
  if(dpv[l][r]!=-INF)return dpv[l][r];
  if(l==r)return dpv[l][r]=0;

  if((r-l)%2==n%2){
    return dpv[l][r]=max(dp(l+1,r,dpv,n,a)+a[l],dp(l,r-1,dpv,n,a)+a[r-1]);
  }else{
    return dpv[l][r]=min(dp(l+1,r,dpv,n,a)-a[l],dp(l,r-1,dpv,n,a)-a[r-1]);
  }
}

bool solve(){
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];

  vector<vector<ll>>dpv(n+1,vector<ll>(n+1,-INF));

  cout<<dp(0,n,dpv,n,a)<<endl;

  return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(30);
  solve();
}


Measured memory_bytes: 71040