akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;i++)
#define REP1(i,n) for(long long i=1;i<=n;i++)
#define REPB(i,n) for(long long i=((n)-1);i>=0;i--)
#define REPB1(i,n) for(long long i=(n);i>0;i--)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();ite++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define REV(arr) reverse(ALL(arr))
typedef long long ll;
typedef pair<int,int> pii;
//---------------------
#define MAXN 100000
#define SIZEBREAK if(id>=s.size()) {lasta=0;break;}
#define INSIZE ((id+1)<s.size())
//---------------------
string s;



int main(){
	cin>>s;
	ll id=-1,ret=0,lasta=0;
	while(id+1<s.size()){
		if(INSIZE){
			if(s[++id]!='A'){
			  	lasta=0;
				continue;
			}
		}else{
			break;
		}
		ll a=1;
		while(1) {
			if(INSIZE){
				if(s[++id]=='A') a++;
				else{id--;break;}
			}else{
				break;
			}
		}
		if(INSIZE){
			if(s[++id]!='B'){
				lasta=0;id--;continue;
			}
		}else{
			break;
		}
		if(INSIZE){
			if(s[++id]!='C'){
				lasta=0;id--;continue;
			}
		}else{
			break;
		}
		ll bc=1;
		while(1) {
		  	if(INSIZE){
		  		if(s[++id]=='B'){
		  			if(INSIZE){
		  				if(s[++id]=='C'){
		  					bc++;
		  				}else{
		  					id--;
		  					break;
		  				}
		  			}else{
		  				break;
		  			}
		  		}else{
		  			id--;
		  			break;
		  		}
		  	}else{
		  		break;
		  	}
		}
		ret+=bc*(a+lasta);
		//cout<<bc<<" "<<a<<" "<<lasta<<endl;
		if( INSIZE && s[id+1]=='A' && s[id]=='C') lasta+=a; else lasta=0;
	} 
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 640
local n=io.read("n")
local b={}
for i=1,n do
    b[i]=io.read("n")
end

local a={}
for i=1,n do
    for j=#b,1,-1 do
        if b[j]==j then
            table.remove(b,j)
            a[i]=j
            break
        end
    end
end

if #a==n then
    for i=n,1,-1 do
        print(a[i])
    end
else
    print(-1)
end

Measured memory_bytes: 888
N = int(input())
B = []
X = [[0]*19 for _ in range(19)]

for _ in range(N):
    s = input()
    if '.' not in s: s = s+'.0'
    a1, a2 = s.split('.')
    a2 = a2 + '0'*(9-len(a2))
    A = int(a1)*10**9 + int(a2)

    d2 = d5 = 0
    while A%2==0:
        A//=2
        d2+=1
    d2 = min(18, d2)

    while A%5==0:
        A//=5
        d5+=1
    d5 = min(18, d5)

    B.append((d2,d5))
    X[d2][d5] += 1

C = [[0]*19 for _ in range(19)]
for n2 in range(19):
    s = 0
    for n5 in range(18, -1, -1):
        s += X[n2][n5]
        C[n2][n5] = s

D = [[0]*19 for _ in range(19)]
for n5 in range(19):
    s = 0
    for n2 in range(18, -1, -1):
        s += C[n2][n5]
        D[n2][n5] = s

ans = 0
for n2, n5 in B:
    if n2*2>=18 and n5*2>=18: ans-=1
    ans += D[18-n2][18-n5]
    
print(ans//2)


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n), v;
    vector<bool> visit(n, 0);
    for(int i = 0; i < n; i++)  cin >> a[i];
    int ans = 0;
    for(int pos = 0; pos < n; pos++){
        int i = pos;
        if(visit[i])    continue;
        while(!visit[i]){
            v.push_back(i);
            visit[i] = true;
            i = (i + a[i])%n;
        }
        int vlen = v.size();
        for(int j = 0; j < vlen; j++){
            if(v[j] == i){
                ans += vlen-j;
                break;
            }
        }
        v.clear();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3812
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> b(n - 1);
    for(int i = 0; i < n - 1; ++i){
        cin >> b.at(i);
    }
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        if(i == 0){
            ans += b.at(0);
        }else if(i < n - 1){
            ans += min(b.at(i), b.at(i - 1));
        }else{
            ans += b.at(i - 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n,c,k,ans=1,now=0,sum=1;
  int t[10000000],T;
  cin>>n>>c>>k;
  for(int i=0;i<n;i++){
    cin>>t[i];
  }
  sort(t,t+n);
  for(int i=1;i<n;i++){
    if(t[now]+k<t[i]||sum==c) ans++,sum=1,now=i;
    else sum++;
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

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

    int K, A, B;
    cin >> K >> A >> B;
    cout << (B / K - A / K > 0 || A % K == 0 || B % K == 0 ? "OK" : "NG") << endl;

    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
ll INF = 1LL<<60;

int main(){
    ll N; cin >> N;
    vector<ll> A(N+1),B(N+1),C(N+1);
    rep(i,N) { 
        cin >> A[i];
        A[i]--;
    }
    rep(i,N) cin >> B[i];
    rep(i,N-1) cin >> C[i];

    ll pr = A[0];
    ll ans = 0;
    rep(i,N){
        ans += B[A[i]];
        if(pr + 1 == A[i]){
            ans += C[A[i]-1];
        }
        pr = A[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import Data.List
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  n <- readLn :: IO Int
  abz <- replicateM n $ (\[x,y] -> (x,y)) . map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
  let abz' = sortBy compTuple abz

  putStrLn $ solve abz'


compTuple :: (Ord a, Ord b) => (a,b) -> (a,b) -> Ordering
compTuple (x,y) (z,u) = case compare u y of
                          LT -> LT
                          GT -> GT
                          EQ -> compare z x


solve :: [(Int,Int)] -> String
solve [] = "Yes"
solve [(x,y)] = if y - x >= 0 then "Yes" else "No"
solve ((x,y):(z,u):xyz) = if y - x >= u
                          then solve ((z,u):xyz)
                          else solve ((z,y-x):xyz)


Measured memory_bytes: 97660
# include <bits/stdc++.h>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// I DON'T KNOW WHO YOU ARE BUT I WILL FIND YOU AND SEE YOUR CODE _/\_

# define MOD         1000000007
# define gc          getchar
# define LL          long long
# define pb          push_back
# define mp          make_pair
# define vi          vector<int>
# define MAXN        1000005
# define INF         1e10
# define all(v)      v.begin(),v.end()

template<class T> void in(T &x) { register T c=gc();x=0;T neg=0;for(;((c<48||c>57)&&c!='-');c=gc());if(c=='-'){neg=1;c=gc();}for(;c>47&&c<58;c=gc()){x=(x<<1)+(x<<3)+c-48;}if(neg)x=-x;}
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
LL power(LL a,LL b,LL m){ if(b==0) return 1; if(b==1) return a%m; LL t=power(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}
LL lcm(LL a, LL b) { LL ret = a*b; ret /= __gcd(a,b); return ret;}
LL nC2(LL n) {LL ret = n*(n-1)/2; return ret;}

vi adj[105];
LL cost[105][105],dist[105][105];

int main()
{
	for(int i=0;i<105;i++)
	{
		for(int j=0;j<105;j++)
		{
			cost[i][j]=dist[i][j]=1e10;
		}
	}
	int n,m,a,b,c;
	cin>>n>>m;
	vector<pair<int,int> > edge;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b>>c;
		a--;
		b--;
		adj[a].pb(b);
		adj[b].pb(a);
		cost[a][b]=cost[b][a]=c;
		edge.pb(mp(a,b));
	}

	for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            dist[i][j] = cost[i][j];

    for (int k = 0; k < n; k++)
    {
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (dist[i][k] + dist[k][j] < dist[i][j])
                    dist[i][j] = dist[i][k] + dist[k][j];
            }
        }
    }

    int ans=0;

    for(int i=0;i<edge.size();i++)
    {
    	//cout<<edge[i].first <<" "<<edge[i].second<<" "<<dist[edge[i].first][edge[i].second] <<" "<<cost[edge[i].first][edge[i].second]<<endl;
    	if(cost[edge[i].first][edge[i].second] > dist[edge[i].first][edge[i].second])
    		ans++;
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
constexpr int MOD = 1000000007;
constexpr ll INF = 50000000000000000;
typedef std::pair<int,int> P;
constexpr ll SIZE= 100010;
namespace std {
    template <>
    class hash<std::pair<string, string>> {
    public:
        size_t operator()(const std::pair<string, string>& x) const{
            return hash<string>()(x.first) ^ hash<string>()(x.second);
        }
    };
}
ll N,A[100010],B[SIZE];
string S,T,q;
ll ans=0,sum=0,wa=0;
unordered_map<pair<string,string>,ll> M;
int main() {
    std::ios_base::sync_with_stdio(false);
    cin>>N>>q;
    S=q.substr(0,N),T=q.substr(N,N);
    reverse(ALL(T));
    REP(Bit,1<<N){
        string s="",t="";
        // if(Bit==0||Bit==(1<<N)-1)continue;
        REP(i,N){
            if(Bit&(1<<i))s+=S[i];
            else t+=S[i];
        }
        //reverse(ALL(t));
        DEB(s)DEB(t)END
        M[{s,t}]++;
    }
    REP(Bit,1<<N){
        string s="",t="";
        // if(Bit==0||Bit==(1<<N)-1)continue;
        REP(i,N){
            if(Bit&(1<<i))s+=T[i];
            else t+=T[i];
        }
        DEB(s)DEB(t)DEB(M[make_pair(s,t)])END
        ans+=M[{t,s}];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 95348
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
void solve(long long N, std::vector<long long> A){
    double tmp=0;
    rep(i,N){
        tmp+=(double)1/(double)A[i];
    }
    opf((double)1/tmp)
    return;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int h, r;
	cin >> h >> r;
	if (h + r > 0)
		cout << 1 << endl;
	else if (h + r < 0)
		cout << -1 << endl;
	else
		cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 3084
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

N = int(input())
a = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(N-1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append(v)
    G[v].append(u)
lis = [float('inf')] * N
ans = [0] * N

def dfs(v, p):
    i = bisect_left(lis, a[v])
    tmp = lis[i]
    lis[i] = a[v]
    ans[v] = bisect_left(lis, float('inf'))
    for c in G[v]:
        if c == p:
            continue
        dfs(c, v)
    lis[i] = tmp

dfs(0, -1)
print('\n'.join(map(str, ans)))

Measured memory_bytes: 224744
#include<bits/stdc++.h>
#define INF            1e9
#define REP(i,n)       for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)      for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPI(i,ini,n)  for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPR(i,n)      for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)     for(lint i=(n);i>0;--i)
#define REPRI(i,ini,n) for(lint i=(ini)-1,i##_len=(n);i>=i##_len;--i)
#define REPC(i,obj)    for(auto i:obj)
#define R_UP(a,b)      (((a)+(b)-1)/(b))
#define ALL(obj)       (obj).begin(),(obj).end()
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
void subset_sum(const vector<int>::iterator&first, const vector<int>::iterator&last, map<int, int>&result, int sum = 0)
{
	if (first == last)
	{
		result[sum]++;
		return;
	}
	subset_sum(first + 1, last, result, sum);
	subset_sum(first + 1, last, result, sum + *first);
}
signed main()
{
	int n = in();
	vector<int>a(n);
	REPC(&i, a)i = in();
	map<int, int>subsum;
	subset_sum(ALL(a), subsum);
	int q = in();
	REP(i, q)
	{
		int m = in();
		cout << (subsum[m] != 0 ? "yes" : "no") << endl;
	}
}


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

#define ULL_INT unsigned long long int

ULL_INT GCD(ULL_INT a, ULL_INT b) {
	if (a < b) swap(a, b);
	a = a % b; return (a == 0 ? b : GCD(a, b));
}

ULL_INT LCM(ULL_INT a, ULL_INT b) {
	return a * b / GCD(a, b);
}

int main() {
	ULL_INT a, b;
	while (cin >> a >> b) 
		cout << GCD(a, b) << " " << LCM(a, b) << endl;
	return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string days[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
	string s;
	cin>>s;
	for(int i=0;i<7;i++)
	{
		if(days[i]==s)
		{
			for(int j=i+1;j<=i+7;j++)
			{
				if(days[j%7]=="SUN")
				{
					cout<<j-i;
					return 0;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
//#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>
#include "random"
#include "chrono"
#include "cstring"

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target_ans("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;

#define int long long
//#define int unsigned int
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

vi xx = { 1, 0, -1, 0 };
vi yy = { 0, 1, 0, -1 };
string dir = "LRUD";

const int N = 5e5 + 50, oo = 3e18 + 500;
const int mod = 998244353;
//const int mod = 1e9 + 7;
//const int mod = 1e9 + 9;
const double eps = 1e-12, PI = 2 * acos(0.0);
int n, m, k;
long long cnt = 0;
int lg = 18;
vi g[N];
vi rg[N];
vi visit(N, 0);

int pr[N], sz[N];

void make_set(int v)
{
	pr[v] = v;
	sz[v] = 1;
}

int find_set(int v)
{
	if (v == pr[v])
		return v;

	return pr[v] = find_set(pr[v]);
}

void union_sets(int u, int v, int w, int &ans)
{
	u = find_set(u);
	v = find_set(v);

	if (u == v)
		return;

	ans += w;
	cnt--;

	if (sz[u] < sz[v])
		swap(u, v);

	pr[v] = u;
	sz[u] += sz[v];
}

double logr(int a)
{
	return log(a) / log(10);
}

int mult(int a, int b)
{
	if (a == 0 || b == 0)
		return 0;

	if (a == -1 || b == -1)
		return -1;

	if (logr(a) + logr(b) > 18)
	{
		return -1;
	}

	int res = a*b;
	int x = 1000000000000000000;

	if (res > x)
	{
		res = -1;
	}
	return res;
}

signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	/*freopen("abbreviation.in", "r", stdin);
	freopen("abbreviation.out", "w", stdout);*/
	//ПРОВЕРЯЙ ДЕФАЙНЫ ТУПОЙ!!!

	cin >> n;
	cnt = 1;
	for (int i = 0; i < n; i++)
	{
		cin >> k;
		cnt = mult(cnt, k);
	}
	cout << cnt;
}



Measured memory_bytes: 30280
a = input()
b = input().split()
c = input().split()
a = 100000
kekka = 0
for i in range(len(c)):
  ave = int(b[0]) - int(c[i]) * 0.006
  sa  = int(b[1]) - ave
  if sa < 0:
    sa *= -1
  if sa < a:
    a = sa
    kekka = i + 1
    
print(kekka)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int i=1,n=sc.nextInt();
		while(i<=n){
			int x=i;
			if(x%3==0){
				System.out.printf(" %d",i);
			}else{
				while(x>=1){
					if(x%10==3){
						System.out.printf(" %d",i);
						break;
					}
					x/=10;
				}
			}
			i++;
		}
		System.out.printf("\n");
	}
};

Measured memory_bytes: 33932
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

const int M = 1046527;
char H[M][14];
int getChar(char ch){
	if(ch=='A')	return 1;
	else if(ch=='C')	return 2;
	else if(ch=='G')	return 3;
	else if(ch=='T')	return 4;
	else return 0;
}

ll getKey(char str[]){
	ll sum = 0,p=1,i;
	for(i=0;i<strlen(str);i++){
		sum+= p*(getChar(str[i]));
		p*=5;
	}
	return sum;
}

int h1(int key) { return key%M;}
int h2(int key) { return 1+(key%(M-1));}

int find(char str[]){
	ll key,i,h;
	key = getKey(str);
	for(i=0;;i++){
		h = (h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)	return 1;
		else if(strlen(H[h])==0)	return 0;
	}
	return 0;
}

int insert(char str[]){
	ll key,i,h;
	key = getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)	return 1;
		else if(strlen(H[h])==0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
	int i,n,h;
	char str[14],com[9];
	for(i=0;i<M;i++)	H[i][0]='\0';
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s",com,str);
		
		if(com[0]=='i'){
			insert(str);
		}else{
			if(find(str)){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
	
	return 0;
}




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

int main(){
  int a, b, n;
  set<int> se;
  cin >> a >> b >> n;
  for(int i = a; i < a + n; i++){
  	se.insert(i);
  }
  for(int i = b; i > b - n; i--){
  	se.insert(i);
  }
  
  for(auto x: se){
  	if(a <= x && x <= b)cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define pb push_back
const int N=100005;
const int MOD=1e9+7;
 

// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
int n,m; 
vector<int> adj[N];
vector<bool> visited;
vector<int> vv;

void dfs(int v)
{
	visited[v]=1;
	for(auto it:adj[v])
	{
		if(!visited[it])
		{
			dfs(it);
		}
	}
	vv.pb(v);
	
}
void topo()
{
	visited.assign(n+2,0);
	//vv.clear();
 for(int i=1;i<=n;i++)
{	
	if(!visited[i])
	dfs(i);
}

}

int32_t main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * do smth instead of nothing and stay organized
*/

cin>>n>>m;
for(int i=1;i<=m;i++)
{
	int x,y;
	cin>>x>>y;
	adj[x].pb(y);
}
topo();
int dp[N];
memset(dp,0,sizeof(dp));
int ans=0;
for(auto i:vv)
{
	for(auto j:adj[i])
	{
		dp[i]=max(dp[i],dp[j]+1);
	}
	ans=max(ans,dp[i]);
}
cout<<ans<<endl;



}



Measured memory_bytes: 9460
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <numeric>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int L = C * D / gcd(C, D);
    //cout << L << endl;
    int ans = B - A + 1;
    ans -= B / C - (A - 1) / C;
    ans -= B / D - (A - 1) / D;
    ans += B / L - (A - 1) / L;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    ll N;
    cin >> N;
    ll mini = INF;
    ll ans = 0;
    vector<ll> P(N);
    REP(i,N){
        cin >> P[i];
        if(P[i]<=mini){
            ans++;
        }
        mini = min(mini,P[i]);
    }
    cout << ans << endl;
    return 0;
}

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

const int MOD = 2019;

string S;
int csum[200000];

signed main() {
  cin >> S;
  int N=S.size();

  csum[0] = (int)(S[N-1]-'0') % MOD;
  //cerr << csum[0] << endl;
  int p10 = 1;
  for(int i=N-2; i>=0; i--) {
    int index = N-1-i;
    p10 = (p10 * 10) % MOD;
    int s = (int)(S[i] - '0') * p10;
    s %= MOD;
    csum[index] = (csum[index-1] + s) % MOD;
    //cerr << index << "\t" << S[i] << "\t" << s << "\t" << csum[index] << endl;
  }
  
  map<int,int> mp;
  mp[0]++;
  int ans = 0;
  for(int i=0; i<N; i++) {
    ans += mp[csum[i]];
    //cerr << i << "\t" << csum[i] << "\t" << mp[csum[i]] << endl;
    mp[csum[i]]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 5316
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
class compare{
  public:
  bool operator()(pair<ll,ll> p1,pair<ll,ll> p2){
      ll m1=min(p1.fi,p1.se),m2=min(p2.fi,p2.se);
      return m1<m2;
  }
};
int main(){
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,compare > pq; 
    ll ans=0;
    if(n==2){
        ans+=a[n-1];
    }
    if(n>2){
        ans+=a[n-1];
        pq.push({a[n-1],a[n-2]});
        pq.push({a[n-1],a[n-2]});
        for(int i=n-3;i>=0;i--){
            pair<ll,ll> t=pq.top();
           // cout<<t.fi<<" "<<t.se<<endl;
            ans+=min(t.fi,t.se);
            pq.pop();
            pq.push({a[i],t.fi});
            pq.push({a[i],t.se});
        }
    }
    cout<<ans;
}

Measured memory_bytes: 8956
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include <iomanip>
#include<sstream>
using namespace std;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    int a, b;
    while (cin >> a >> b)
    {
        if (a % b == 0)
            a = a / b;
        else a = a / b + 1;
        cout << a << '\n';
    }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main(){
    string str, str2;
    int n;
    int play1 = 0;
    int play2 = 0;
    cin >> n;
    for (int i = 0; i < n; i++)  {
        cin >> str >> str2;
        if (str > str2) {
            play1 += 3;
        } else if (str < str2) {
            play2 += 3;
        } else {
            play1 += 1;
            play2 +=1;
        }
    }
    cout << play1 << " " << play2 << endl;
}


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

int main(void){
    string str;
    int cnt;
    cnt = 0;
    
    cin >> str;
    
    for(int i = 0; i < 3; i++){
        if(i == 0){
            if(str[i] == 'R') cnt++;
        }
        else{
            if((str[i] == 'R' && str[i-1] == str[i]) || (str[i] == 'R' && cnt == 0)) cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pair<int,int> a, pair<int,int> b) {
	return a < b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	llint n;
	cin >> n;
	vllint a(n);
	rep(i, n) {
		cin >> a[i];
	}
	llint tmp = 0;
	rep(i, n) {
		tmp = a[i] - tmp;
	}
	tmp /= 2;
	rep(i, n) {
		if (i == n - 1) {
			cout << (llint)tmp * 2 << endl;
		}
		else {
			cout << (llint)tmp * 2 << " ";
			tmp = a[i] - tmp;
		}
	}

	return 0;
}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template <typename T> T read() {T t; cin >> t; return t;}

void panic() {
  cout << "No" << endl;
  exit(0);
}

void Main() {
  int n = read<int>();
  vvi E(n);
  rep(i, n-1) {
    int u = read<int>() - 1;
    int v = read<int>() - 1;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  int k = read<int>();

  priority_queue<pii, vector<pii>, greater<pii> > pq;

  vector<int> P(n);
  vb used(n);
  rep(j, k) {
    int u = read<int>() - 1;
    P[u] = read<int>();
    pq.emplace(P[u], u);
    used[u] = 1;
  }

  while (!pq.empty()) {
    int u = pq.top().snd;
    //_p("P[%d]: %d\n", u, P[u]);
    pq.pop();
    forr(v, E[u]) {
      if (used[v]) {
        if (abs(P[v] - P[u]) != 1) {
          panic();
        }
        continue;
      }
      P[v] = P[u] + 1;
      used[v] = 1;
      pq.emplace(P[v], v);
    }
  }
  cout << "Yes" << endl;
  forr(p, P) cout << p << endl;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


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

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> as(n - 1);
	for (auto &&a : as)
	{
		cin >> a;
	}

	vector<int64_t> cnt(n, 0);
	for (auto &&a : as)
	{
		cnt[a - 1]++;
	}

	for (auto &&x : cnt)
	{
		cout << x << endl;
	}

	return 0;
}

Measured memory_bytes: 6428
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void main(){
	bool[string] kagi;
	auto N = readInt();
	for(int i; i < N; ++i) {
		auto s = readln().strip();
		kagi[s] = true;
	}
	auto M = readInt();
	auto opened = false;
	for(int i; i < M; ++i) {
		auto s = readln().strip();
		if((s in kagi) !is null) {
			if(opened) {
				writeln("Closed by ", s);
			} else {
				writeln("Opened by ", s);
			}
			opened = !opened;
		} else {
			writeln("Unknown ", s);
		}
	}
}

Measured memory_bytes: 2588
#include<bits/stdc++.h>
#define N 100010
using namespace std;
template<typename T>inline void read(T &x)
{
	x=0;
	static int p;p=1;
	static char c;c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-'0');c=getchar();}
	x*=p;
}
int n;
int h[N],l,q;
int st[N][19];
int main()
{
	read(n);
	for(int i=1;i<=n;i++) read(h[i]);
	read(l);read(q);
	for(int i=1;i<=n;i++)
	{
		int pos=upper_bound(h+1,h+n+1,h[i]+l)-h-1;
		if(h[i]+l>=h[n])st[i][0]=n;
		else st[i][0]=pos;
	}
	for(int len=1;len<=18;len++)
		for(int i=1;i<=n;i++) st[i][len]=st[st[i][len-1]][len-1];
	while(q--)
	{
		static int a,b;
		read(a);read(b);
		if(a>b)swap(a,b);
		int now=a,ans=0;
		for(int i=18;i>=0;i--)
			if(st[now][i]<b)now=st[now][i],ans+=(1<<i);
		printf("%d\n",ans+1);
	}
	return 0;
}

Measured memory_bytes: 8704
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long s = sc.nextLong();
        long ans = solve(n,s);
        System.out.println(ans);
    }
    static long helper(long n, long base){
        long ans = 0;
        while(n>0){
            ans += n%base;
            n=n/base;
        }
        return ans;
    }
    static long solve(long n, long s){
        if(n<s) return -1;
        if(n==s) return n+1;
        long dif = n-s;
        long upper = (long) Math.floor(Math.sqrt(dif))+1;
        long ans = Long.MAX_VALUE;
        for(long b=2;b<=upper;b++){
            if(dif%(b-1)==0){
                long k=dif/(b-1);
                long cur1 = helper(n,b);
                if(cur1==s) ans = Math.min(ans,b);
                long cur2 = helper(n,k+1);
                if(cur2==s) ans = Math.min(ans,k+1);
            }
        }
        if(ans==Long.MAX_VALUE) return -1;
        else return ans;
    }
}


Measured memory_bytes: 23636
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int l,r;
    cin>>l>>r;
    if(r-l>=2019){
        cout<<0<<endl;
        return;
    }
    int ans=inf;
    Rep(i,l,r){
        REP(j,i+1,r){
            ans=min(ans,(i*j)%2019);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;

double solve(int n, double a, double b){
    if(n==0)return 0.0;
    return 0.25 * ( 2.0 * a + 1.0*b*(n-1)) + solve(n-1,((2.0*n+2.0)*a + 3.0*b)/(2.0*n), b*(2.0*n+4.0)/(2.0 * n) );
}

int main(int argc, char const *argv[]) {
    int n;cin>>n;
    double a,b;cin>>a>>b;
    cout<<setprecision(50)<<solve(n,2*a + b,4 * b)<<endl;
    return 0;
}

Measured memory_bytes: 6528
N, M, X, Y = map(int, input().split())

x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.append(X)
y.append(Y)

max_x = max(x)
min_x = min(x)

for i in range(len(y)):
    if max_x >= y[i] and min_x <= y[i]:
        print('War')
        exit()
print('No War')


Measured memory_bytes: 3060
N, M=map(int, input().split())
_min_list=[]
_max_list=[]
for i in range(M):
	_min,_max=map(int, input().split())
	_min_list.append(_min)
	_max_list.append(_max)

min_value=max(_min_list)
max_value=min(_max_list)

if min_value > max_value:
	print(0)
else:
	print(max_value-min_value+1)


Measured memory_bytes: 11016
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let arr = scan_array ~sep:' ' Int.of_string

let memo = Array.make_matrix n n None

let rec solve i j t =
  match memo.(i).(j)with
  | Some v ->  v
  | None ->
    if t then
      if i = j then arr.(i)
      else
        let v = max (solve (succ i) j false + arr.(i))
            (solve i (pred j) false + arr.(j))  in
        memo.(i).(j) <- Some v; v
    else
    if i = j then -arr.(i)
    else
      let v = min (solve (succ i) j true - arr.(i))
          (solve i (pred j) true -arr.(j)) in
      memo.(i).(j) <- Some v; v

let () =
  solve 0 (pred n) true
  |> Printf.printf "%d\n"


Measured memory_bytes: 145340
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n; cin >> n;
	vi a(n); rep(i,n) cin >> a[i];
	int m = 0;
	rep(i,n) m = max(m,a[i]);
	vector<bool> dp(m+1,true);
	vector<bool> exist(m+1,false);
	rep(i,n){
		if(exist[a[i]]) dp[a[i]] = false;
		exist[a[i]] = true;		
		int b = a[i]*2;
		while(b<=m){
			dp[b] = false;			
			b += a[i];
		}
	}
//	rep(i,m+1) cout << i << " : " << dp[i] << endl;
	int ans = 0;
	rep(i,n) ans += dp[a[i]];
	cout << ans << endl;
}


Measured memory_bytes: 4248
n = int(input())
b = list(map(int, input().split()))
a = [0]*n
a[0]=b[0]
for i in range (1,n-1):
    if (b[i-1] >= b[i]):
        a[i] = b[i]
    else:
        a[i] = b[i-1]
a[n-1]=b[n-2]
print(sum(a))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=0;i<(n);i++)
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}

int main(){
    long r,d,x;cin>>r>>d>>x;
    For(i,10){
        x=x*r-d;
        cout<<x<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }

// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }

int main()
{
	uint64_t n, a, b;
	cin >> n >> a >> b;

	uint64_t r = n / (a + b);
	uint64_t m = n % (a + b);

	printf("%lld\n",r * a + min(a, m));

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <numeric>
#include <utility>
#include <tuple>
#include <climits>
#include <fstream>
#include <bitset>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <random>
#include <chrono>
#include <ios>
#include <iomanip>
#include <functional>
#include <array>

using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORA(i, a) for (auto &i : a)
#define FORB(i, a, b) for (int i = a; i >= b; --i)
#define SZ(a) ((int) a.size())
#define ALL(a) begin(a), end(a)

typedef int64_t ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define fi first
#define se second

// start of code

const int MAXN = 102030;
string S[2];
int pref[2][MAXN];

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

	FOR(i, 0, 1) {
		cin >> S[i];
		pref[i][0] = 0;
		FOR(j, 0, SZ(S[i]) - 1) pref[i][j + 1] = pref[i][j] + (S[i][j] - 'A' + 1);
	}
	int q;
	cin >> q;
	while (q--) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		cout << ((pref[0][b] - pref[0][a - 1]) % 3 == (pref[1][d] - pref[1][c - 1]) % 3 ? "YES" : "NO") << endl;
	}

	return 0;
}


Measured memory_bytes: 1744
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,i=0;cin>>N;
  for(;N>=0;N-=4)if(N/3<=i++&&N%3==0)N=-10;
  if(N<-9)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function dfs(v::Int, p::Int, adj::Array{Array{Pair{Int, Int}, 1},1}, dist::Array{Int,1})
    for edge in adj[v]
        tail, weight = first(edge), last(edge)
        if tail == p
            continue
        end
        dist[tail] = dist[v] + weight
        dfs(tail, v, adj, dist)
    end
end

function main()
    n = parseInt(readline())
    adj = [Pair{Int, Int}[] for i in 1:n]
    for i in 1:n-1
        a, b, c = readline() |> split |> parseMap
        push!(adj[a], Pair(b, c))
        push!(adj[b], Pair(a, c))
    end
    q, k = readline() |> split |> parseMap
    dist = [0 for i in 1:n]
    dfs(k, -1, adj, dist)
    for j in 1:q
        l, r = readline() |> split |> parseMap
        println(dist[l] + dist[r])
    end
end

main()


Measured memory_bytes: 172360