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

namespace TYC
{
	const int N = 2e5 + 5;

	int n, tot, C[N], Fa[N], M[N], R[N], Q[N][2];
	vector<int> E[N];
	struct node {  int ls, rs, v; } tr[N * 150];

	int add(const int p, const int x, const int w, const int l = 1, const int r = n)
	{
		int o = ++tot;
		tr[o] = tr[p];
		if (l == r)
			return tr[o].v += w, o;
		int mid = (l + r) >> 1;
		if (x <= mid)
			tr[o].ls = add(tr[p].ls, x, w, l, mid);
		else
			tr[o].rs = add(tr[p].rs, x, w, mid + 1, r);
		tr[o].v = tr[tr[o].ls].v + tr[tr[o].rs].v;
		return o;
	}

	int merge(const int x, const int y, const int l = 1, const int r = n)
	{
		if (!x || !y)
			return x + y;
		int o = ++tot;
		if (l != r)
		{
			int mid = (l + r) >> 1;
			tr[o].ls = merge(tr[x].ls, tr[y].ls, l, mid);
			tr[o].rs = merge(tr[x].rs, tr[y].rs, mid + 1, r);
		}
		tr[o].v = tr[x].v + tr[y].v;
		return o;
	}

	int del(const int p, const int v, const int l = 1, const int r = n)
	{
		if (r <= v)
			return 0;
		if (l == r)
			return p;
		int o = ++tot, mid = (l + r) >> 1;
		if (v <= mid)
		{
			tr[o].ls = del(tr[p].ls, v, l, mid);
			tr[o].rs = tr[p].rs;
		}
		else
		{
			tr[o].ls = 0;
			tr[o].rs = del(tr[p].rs, v, mid + 1, r);
		}
		tr[o].v = tr[tr[o].ls].v + tr[tr[o].rs].v;
		return o;
	}

	int query(const int o, const int x, const int l = 1, const int r = n)
	{
		if (!o) 
			return 0;
		if (l == r)
			return tr[o].v;
		int mid = (l + r) >> 1;
		if (x <= mid)
			return query(tr[o].ls, x, l, mid);
		else
			return tr[tr[o].ls].v + query(tr[o].rs, x, mid + 1, r);
	}

	void dfs(const int u, const int f)
	{
		Fa[u] = f;
		M[u] = max(M[f], f);
		for (int v : E[u])
			if (v != f)
			{
				dfs(v, u);
				R[u] = merge(R[u], R[v]);
			}
		Q[u][0] = query(R[u], M[u]) + 1;
		Q[u][1] = query(R[u], M[f]) + 1;
		int t = query(R[u], u) + 1;
		R[u] = del(R[u], u);
		R[u] = add(R[u], u, t);
	}

	void dfs(const int u)
	{
		if (u > 1)
		{
			int f = Fa[u];
			C[u] = C[f] + 1;
			if (f > 1)
				C[u] -= query(R[u], M[f]);
			for (int v : E[u])
				if (v != f)
					C[u] += query(R[v], M[u]);
		}
//		if (u != 1)
//			C[u] = C[Fa[u]] + Q[u][0] - (u < M[u] && u < M[Fa[u]]) * Q[u][1];
		for (int v : E[u])
			if (v != Fa[u])
				dfs(v);
	}

	void work()
	{
		scanf("%d", &n);
		for (int i = 1, u, v; i < n; i++)
		{
			scanf("%d%d", &u, &v);
			E[u].push_back(v);
			E[v].push_back(u);
		}
		for (int i = 1; i <= n; i++)
			sort(E[i].begin(), E[i].end());
		dfs(1, 0);
		dfs(1);
//		cerr << tot << "\n";
		for (int i = 2; i <= n; i++)
			printf("%d ", C[i]);
	}
}

int main()
{
//	freopen("AGC029E.in", "r", stdin);
//	freopen("AGC029E.out", "w", stdout);
	TYC::work();
	return 0;
}

Measured memory_bytes: 141300
#include <bits/stdc++.h>
#include <iostream>
#include <vector>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
typedef long long int ll;

#define min(x,y)(x<y?x:y)
 
using namespace std;

#define MAX 10000

int main() {
	FAST;


	int N;
	int a[MAX];
	int res=0;

	cin >> N;
	rep(i,N) cin >> a[i];

	rep(i,N) {
		while (a[i] % 2 == 0) {
			res +=1;
			a[i] = a[i]/2;
		}
	}	

	cout << res << "\n";

    return 0;
}

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

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

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> P(n);
    for(int i = 0; i < n; i++){
        cin >> P[i];
    }

    int x = 0, y = 0, z = 0;
    for(int i = 0; i < n; i++){
        if(P[i] <= a) x++;
    }
    for(int i = 0; i < n; i++){
        if(a < P[i] and P[i] <= b) y++;
    }
    for(int i = 0; i < n; i++){
        if(b < P[i]) z++;
    }

    cout << min(x, min(y, z)) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr 19 21:50:25 JST 2020
 **/

signed main() {
    Int n, m;
    std::cin >> n >> m;
    REP(i, m) {
        Int x;
        std::cin >> x;
        n -= x;
    }
    std::cout << (n < 0 ? -1 : n) << std::endl;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,pair< int , int> >  
long long MOD  = 1e9+7;


signed main(){
    fast;
    int n;cin >> n;
    vector <int> a(n);
    for(int i=0 ; i<n ; i++)
    	cin >> a[i];
    int ans = 0;
   	for(int i=0 ; i<n ; i++){
   		for(int j=i+1 ; j<n ; j++){
   			ans += a[i]*a[j];
   		}
   	}
   	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 500200;
const int mod = 1e9 + 7;
typedef long long ll;
int n;
struct T {
	int to, nxt;
} way[maxn << 1];
int h[maxn], num;
inline void link(int x,int y) {
	way[++num] = {y, h[x]}, h[x] = num;
	way[++num] = {x, h[y]}, h[y] = num;
}
int fac[maxn], ifac[maxn], inv[maxn];
int vis[maxn], fa[maxn], dep[maxn], A, B, cnt = 0, R, _;
inline void dfs0(int x,int fa = 0) {
	vis[x] = 1, ::fa[x] = fa, dep[x] = dep[fa] + 1;
	for(int i = h[x];i;i = way[i].nxt) if(way[i].to != fa) {
		if(!vis[way[i].to]) {
			dfs0(way[i].to, x);
		} else {
			A = x, B = way[i].to, ++ cnt;
		}
	}
}
int dp[maxn], size[maxn];
inline void dfs1(int x, int fa = 0, int is_root = 1) {
	dp[x] = 1; size[x] = 1;
	for(int i = h[x];i;i = way[i].nxt) if(way[i].to != fa && way[i].to != R) {
		if(way[i].to < fa) {
			dfs1(way[i].to, x, 0);
			size[x] += size[way[i].to];
			dp[x] = (ll) dp[x] * dp[way[i].to] % mod;
			dp[x] = (ll) dp[x] * ifac[size[way[i].to]] % mod;
		} else {
			dfs1(way[i].to, x, 1);
		}
	}
	dp[x] = (ll) dp[x] * fac[size[x] - 1] % mod;
	if(is_root) _ = (ll) _ * dp[x] % mod * ifac[size[x]] % mod;
}
inline int calc(int x) {
	cnt = 0, dfs0(x);
	if(cnt != 2) return 0;
	int ans = 0;
	std::pair<int, int> M(A + B, B);
	for(;A != B;) {
		if(dep[A] < dep[B]) std::swap(A, B);
		M = std::max(M, {A + fa[A], A}), A = fa[A];
	}
	B = M.second, A = M.first - B;
	_ = 1, R = B, dfs1(B, A, 1); ans = _;
	_ = 1, R = A, dfs1(A, B, 1);
	return ans + _;
}
int main() {
	fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
	for(int i = 2;i < maxn;++i) {
		inv[i] = ll(mod - mod / i) * inv[mod % i] % mod;
		fac[i] = (ll) fac[i - 1] * i % mod;
		ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
	}
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n; const int M = n + n;
	for(int i = 1, x, y;i <= M;++i) {
		cin >> x >> y;
		link(x, y + n);
	}
	int ans = fac[n + n];
	for(int i = 1;i <= M;++i) if(!vis[i]) {
		ans = (ll) ans * calc(i) % mod;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 26496
#include<bits/stdc++.h>
using namespace std;
#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--)
typedef long long LL;
int N;

int main(){
	cin>>N;
	string S;
	cin>>S;
	REP(i,S.size()){
		int a=S[i]-'A';
		a+=N;
		a%=26;
		string b;
		b.push_back('A'+a);
		cout<<(b);
	}
	cout<<endl;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
	public static void main(String[] args) {
		try {
			Scanner sc = new Scanner(System.in);
			while(true){
				int w = sc.nextInt(), h = sc.nextInt();

				if(w==0&&h==0){
					sc.close();
					break;
				}

				int[][] f = new int[h][w];
				int ch = 0, cw = 0;

				for(int i=0;i<h;i++){
					for(int j=0;j<w;j++){
						f[i][j] = sc.nextInt();
						if(f[i][j]==2){
							ch = i;
							cw = j;
						}
					}
				}

				int ret = solve(f,ch,cw,1);

				System.out.println((ret>10)?-1:ret);
			}
			sc.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static int solve(int[][] f, int ch, int cw, int n){
		//p(f,ch,cw,n);
		if(n>10) return 11;
		int ret = 11, min = 11;

		//up
		if(ch>=1&&f[ch-1][cw]!=1){
			int i = ch-1, j = cw;
			while(true){
				if(i<0){
					ret = 11;
					break;
				} else if(f[i][j]==1){
					f[i][j] = 0;
					ret = solve(f,i+1,j,n+1);
					f[i][j] = 1;
					break; 
				} else if(f[i][j]==3){
					ret = n;
					break;
				}
				i--;
			}
		}
		if(ret<min) min = ret;

		//right
		if(cw<f[0].length-1&&f[ch][cw+1]!=1){
			int i = ch, j = cw+1;
			while(true){
				if(j>=f[0].length){
					ret = 11;
					break;
				} else if(f[i][j]==1){
					f[i][j] = 0;
					ret = solve(f,i,j-1,n+1);
					f[i][j] = 1;
					break;
				} else if(f[i][j]==3){
					ret = n;
					break;
				}
				j++;
			}
		}
		if(ret<min) min = ret;


		//down
		if(ch<f.length-1&&f[ch+1][cw]!=1){
			int i = ch+1, j = cw;
			while(true){
				if(i>=f.length){
					ret = 11;
					break;
				} else if(f[i][j]==1){
					f[i][j] = 0;
					ret = solve(f,i-1,j,n+1);
					f[i][j] = 1;
					break;
				} else if(f[i][j]==3){
					ret = n;
					break;
				}
				i++;
			}
		}
		if(ret<min) min = ret;


		//left
		if(cw>0&&f[ch][cw-1]!=1){
			int i = ch, j = cw-1;
			while(true){
				if(j<0){
					ret = 11;
					break;
				} else if(f[i][j]==1){
					f[i][j] = 0;
					ret = solve(f,i,j+1,n+1);
					f[i][j] = 1;
					break;
				} else if(f[i][j]==3){
					ret = n;
					break;
				}
				j--;
			}
		}
		if(ret<min) min = ret;

		return min;
	}

	public static void p(int[][] f, int ch, int cw, int n){
		System.out.println("step: " + n + " " + ch + ", " + cw);
		for(int i=0;i<f.length;i++){
			for(int j=0;j<f[0].length;j++){
				System.out.print((i==ch&&j==cw)?"*":f[i][j]);
			}
			System.out.println();
		}
		System.out.println();
	}
}

Measured memory_bytes: 36724
N = int(input())
T,A = list(map(int,input().split()))
H = list(map(int,input().split()))
idealH = (T - A) * 1000 / 6
minDeltaHeight = 10000000
minIndex = 0
for i in range(N):
    deltaHight = abs(idealH - H[i])

    if minDeltaHeight > deltaHight:
        minDeltaHeight = deltaHight
        minIndex = i
print(minIndex+1)

Measured memory_bytes: 9268
from operator import itemgetter

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort(key=itemgetter(0))

result = 0
for e in ab:
  count = min(m, e[1])
  result += e[0] * count
  m = max(m-count, 0)
print(result)

Measured memory_bytes: 28968
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define lsc(x)      scanf("%lld",&x)
#define sc(x)       scanf("%d",&x)
#define lpr(x)      printf("%lld ",(long long)x)
#define pr(x)       printf("%d ",x)
#define n_l         printf("\n")
#define VI          vector<int>
#define VII         vector<long long int>
#define m_p         make_pair
#define pb          push_back
#define fi           first
#define se           second
#define mset(x,y)   memset(x,y,sizeof(x))
#define sz(v)       (int)v.size()
#define all(v)      v.begin(), v.end()
#define fr(i, a, n) for(int i=a;i<=n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const int N=(int)1e6+5;
const int mod = 1000000007;
typedef long long ll;
// order_of_key (val): returns the no. of values strictly less than val
// find_by_order (k): returns the kth largest element iterator.(0-based)
// vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x);
// s.substr(pos[0-indexed], len(default=till end))
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ll fmod(ll x){if (x<mod) return x;return x%mod;}
ll mul(ll a, ll b, ll c){
	ll ret=0;while(b){if (b%2) ret=(ret+a)%c;a=(a*2)%c;b>>=1;}
    return ret;
}
int modpow(ll a, ll b){
    ll ret=1;while(b){if (b%2) ret=(ret*a)%mod;a=(a*a)%mod;b>>=1;}
    return (int)ret;
}
inline int inv(int x){ return modpow(x, mod-2);}
int isprime[N];
void calc_prime(){
	isprime[1]=1;for(ll i=2;i<N;i++) if (!isprime[i]) for(ll j=i*i;j<N;j+=i) isprime[j]=1;
}
map<string, int> mp;
ll nc2(ll x){
    return (x*(x-1))/2;
}
int main(){
    //FIO;
    int n;cin>>n;
    fr(i, 1, n) {
        string s;cin >>s;
        sort(all(s));
        mp[s]++;
    }
    ll ans = 0;
    for(auto pp: mp){
        ans += nc2(pp.se);
    }
    lpr(ans);n_l;
    return 0;
}



Measured memory_bytes: 11500
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
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; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int a[200000];

int main() {
  int n;
  while(cin>>n) {
    inputs(a,n);
    vector<int> v(a,a+n);
    sort(ALL(v));
    int mx1 = v[n-1];
    int mx2 = v[n-2];
    REP(i,n) {
      int ans = (a[i] == mx1) ? mx2 : mx1;
      printf("%d\n", ans);
    }
  }
}


Measured memory_bytes: 3200
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N; cin>>N;
    ll arr[N];
    
    for(ll i=0;i<N;++i)
        cin>>arr[i];
    
    sort(arr,arr + N);
    
    if(N < 3)
    {
        cout<<0<<endl;
        return(0);
    }
    
    ll ans = 0;
    for(ll i=0;i<N;++i)
    {
        for(ll j=(i + 1);j<N;++j)
        {
            for(ll k=(j + 1);k<N;++k)
            {
                if((arr[i] != arr[j]) && (arr[j] != arr[k]))
                {
                    if((arr[i] + arr[j] > arr[k]) && (arr[i] + arr[k] > arr[j]) && (arr[j] + arr[k] > arr[i]))
                        ans++;
                }
            }
        }
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int a = sc.nextInt();
	int b = sc.nextInt();
	int sumN = 0;
	int ans = 0;
	int c = 0;
	for(int i = 1; i <= n; i++) {
		c = i;
		while(c > 0) {
			sumN += c % 10;
			c /= 10;
		}
		if(a <= sumN && sumN <= b) {
			ans += i;
		}
		sumN = 0;
	}
	System.out.println(ans);
}
}


Measured memory_bytes: 23508
k=int(input())
arr=[0]*50
for i in range(50):
  if k%50==0:
    arr[i]+=50*min(1,k)+max((k//50-1),0)
  else:
    if i<=(k%50-1):
      if k<50:
        arr[i]+=50
      else:
        arr[i]+=50+(k//50)
    else:
      if k<50:
        arr[i]=0
      else:
        arr[i]+=50+(k//50-1)-k%50
print(50)
print(*arr)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

void solve(int n, int i, int m, vector<int>& s) {
    if (i < n) {
        for (int j = 0; j < m + 1; j++) {
            s[i] = j;
            solve(n, i + 1, max(j + 1, m), s);
        }
    } else {
        for (int i = 0; i < n; i++) {
            cout << static_cast<char>('a' + s[i]);
        }
        cout << endl;
    }
}

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

    vector<int> s(n, 0);
    solve(n, 0, 0, s);
}


Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <array>
#include <vector>
#include <unordered_set>
#include <cstdint>
#include <functional>

using namespace std;
using ll = int64_t;

constexpr ll MOD = 1000000007;
vector<unordered_set<int>> edge;

vector<array<int, 2>> dp;

ll dfs(int v, bool b, int parent = -1){
    if(dp[v][b] != -1) return dp[v][b];
    ll ans = 1;
    for (auto &&u : edge[v]) {
        if(u == parent) continue;
        ll c = dfs(u, false, v);
        if(!b) c += dfs(u, true, v);
        c %= MOD;
        ans *= c;
        ans %= MOD;
    } // end u

    return dp[v][b] = ans;
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    edge.clear(); edge.resize(N);
    for (int i = 0; i < N-1; ++i) {
        int x, y;
        cin >> x >> y; x--; y--;
        edge[x].insert(y);
        edge[y].insert(x);
    } // end i
    dp.clear();
    dp.resize(N, {-1, -1});

    ll ans = dfs(0, true) + dfs(0, false);
    ans %= MOD;

    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int n, k, x, y;

	cin >> n;
	cin >> k;
	cin >> x;
	cin >> y;

	Out(min(n, k) * x + (n - min(n, k)) * y);
	
	return 0;
}


Measured memory_bytes: 256
A, B, M = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
mina, minb = min(a), min(b)
minv = mina+minb
for _ in range(M):
    x, y, c = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    minv = min(minv, a[x]+b[y]-c)


print(minv)

Measured memory_bytes: 18488
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
long double o[613],x;
int l[610];
int j[302];

long long y,z,mod=1000000007;
//string r;
char r[111];

P u[1];
queue<int> q;

stack<int> s;
map<int,int> p;
vector<int> v[666];

bool as(P a,P b)
{
  if(a.x==b.x)
  return a.y<b.y;
  return a.x<b.x;
}

void f(int n)
{
  memset(o,0,sizeof(o));
  for(int t=a-1;t;t--)
  {
    long double y=0;
    for(int h=0;h<v[t].size();h++)
      o[t]+=1+o[v[t][h]],y=max(y,1+o[v[t][h]]);
    if(t==n) o[t]=(o[t]-y)/(v[t].size()-1);
    else o[t]=o[t]/v[t].size();
  }
  //for(int t=1;t<=a;t++)
  //  printf("%Lf ",o[t]);
  x=min(x,o[1]);
}

int main()
{
  
  scanf("%d %d",&a,&b);
  for(int t=1;t<=b;t++)
  {
    scanf("%d %d",&n,&m);
    v[n].push_back(m);
    l[m]=n;
  }
  x=12345678;
  f(0);
  for(int t=1;t<a;t++)
  if(v[t].size()>1) f(t);
  
  printf("%Lf",x);
  
}





Measured memory_bytes: 1408
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::max;

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut map: Vec<Vec<i64>> = vec![vec![]; n + 2];
    for _ in 0..m {
        let a: usize = read();
        let b: usize = read();
        map[a].push(b as i64);
        map[b].push(a as i64);
    }
    for i in 0..n {
        println!("{}", map[i+1].len())
    }
}


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

int main() {
   int n,d;
   cin >> n >> d;
   
   vector<vector<int>> v(11, vector<int>(11));
   
   for(int i=0;i<n;i++){
   		for(int j=0;j<d;j++){
		   cin >> v.at(i).at(j);
		}   
   }
   int c=0;
   for(int a=0;a<n-1;a++){
       for(int b=a+1; b<n;b++){
	        int x=0; 
	        for(int j=0;j<d;j++){
			        x+=(v.at(a).at(j)-v.at(b).at(j)) *(v.at(a).at(j)-v.at(b).at(j)) ; 
			        
                    
			}
			
			for(int k=1;k<401;k++){
					      if(x==k*k){
						      c++;
							  break;
						  }
			}			  
	   } 
   }
   cout << c << endl;

}

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;

    ll r = 0, g = 0, b = 0;
    for (char c : s) {
        switch (c) {
            case 'R':
                r++;
                break;
            case 'G':
                g++;
                break;
            case 'B':
                b++;
                break;
        }
    }

    ll all = r * g * b;

    for (int d = 1; d <= 4000; d++) {
        for (int left = 0; left < n; left++) {
            int center = left + d;
            int right = center + d;
            if (right >= n) break;

            set<char> st;
            st.insert(s[left]);
            st.insert(s[center]);
            st.insert(s[right]);
            if (st.size() == 3) all--;
        }
    }
    cout << all << endl;

}


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

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

ll A;
double B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B;
	A*=(int)(B*100+0.1);
	cout<<A/100<<endl;
	
}


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


Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll ZERO = 0;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

ll gcd(ll a,ll b) {
	if(a == 0 || b == 0) {
		return max(a,b);
	}
	else {
		if(a < b) {
			ll tmp = a;
			a = b;
			b = tmp;
		}
		ll r = a % b;
		while(r != 0) {
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}
}

int main() {
    ll N,M;
    cin >> N >> M;
    string S,T;
    cin >> S >> T;
    ll G = gcd(N,M);
    ll n = N / G;
    ll m = M / G;
    bool ret = true;
    for(int i = 0;i < N;i++) {
        if(i * n >= N) {
            break;
        }
        else if(S.at(i * n) != T.at(i * m)) {
            ret = false;
        }
    }
    if(ret == true) {
        cout << N * M / G << endl;
    }
    else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 512
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>


/* ---------- Namespace ---------- */

using namespace std;


/* ---------- Type Abbreviation ---------- */

template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

using ll = long long;
using PL = P<ll, ll>;
using PS = P<string, ll>;

using VI = V<int>;
using VVI = V<VI>;
using VL = V<ll>;
using VVL = V<VL>;
using VS = V<string>;
using VB = V<bool>;
using VVB = V<VB>;
using VPL = V<PL>;
using VPS = V<PS>;

#define fst first
#define snd second


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)


/* ---------- container ---------- */

#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define GSORT(c) sort(ALL(c), greater<decltype((c).front())>())
#define SZ(x) (LL((x).size()))


/* ---------- repetition ---------- */

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)

#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// Usual REP runs from 0 to n-1 (R: n to 0)
// Natural REP runs from 1 to n (R: n to 1)


/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = 3.14159265358979;
// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};


/* ---------- Short Functions ---------- */

template <typename T>
T square(T a) {
    return a * a;
}


/* ---------- Debug ---------- */
#define GET_VAR_NAME(variable) #variable

#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;
#define testP(p) cout << GET_VAR_NAME(p) << " = (" << (p).fst << ", " << (p).snd << ")" << endl;


/* ^^^^^^^^^^^^^^^ Settting Part ^^^^^^^^^^^^^^^ */

/* ---------- Variances ---------- */


/* ---------- Functions ---------- */


/* ---------- Main Function ---------- */

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

    string X;
    cin >> X;

    ll N = SZ(X);

    ll Scnt = 0;
    ll ans = 0;
    REP(i, N) {
        if (X[i] == 'S') {
            Scnt++;
        } else {
            if (Scnt == 0) {
                ans += 2;
            } else {
                Scnt--;
            }
        }
    }

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

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

#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--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
using V = vector<int>;
using Vll = vector<ll>;
using Vstr = vector<string>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };
const int perm[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

bool isOK(V v, int index, int key) {
  if (v[index] >= key) return true;
  else return false;
}

int binary_search(V v, int key) {
  int left = -1;
  int right = (int)v.size();

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

    if (isOK(v, mid, key)) right = mid;
    else left = mid;
  }

  return right;
}

/*
int prime[1001001];
bool is_prime[1001001];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < n; i++){
    if (is_prime[i]){
      prime[p++] = i;
      for (int j = 2*i; j < n; j+=i) is_prime[j] = false;
    }
  }
  return p;
}
*/

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);

  int N;
  cin >> N;
  V A(N),B(N),C(N);
  REP(i,N) cin >> A[i];
  REP(i,N) cin >> B[i];
  REP(i,N) cin >> C[i];

  sort(ALL(A));
  sort(ALL(C));

  ll ans = 0;
  REP(i,N) {
    auto ra = lower_bound(ALL(A), B[i]);
    auto rc = upper_bound(ALL(C), B[i]);
    int ia = distance(A.begin(), ra);
    int ic = distance(C.begin(), rc);
    ans = ans + (ll)ia * (N - ic);
  }

  print(ans);
}



Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	vector<int> cnt(101, 0);
	for (int i = 1; i <= n; i++) {
		int t = i;
		for (int j = 2; j * j <= t; j++) {
			while (t % j == 0) {
				cnt[j]++;
				t /= j;
			}
		}
		if (t != 1) cnt[t]++;
	}
	int gt5 = 0;
	int gt3 = 0;
	int gt15 = 0;
	int gt25 = 0;
	int gt75 = 0;
	for (int i = 1; i <= 100; i++) {
		if (cnt[i] >= 74) gt75++;
		if (cnt[i] >= 24) gt25++;
		if (cnt[i] >= 14) gt15++;
		if (cnt[i] >= 4) gt5++;
		if (cnt[i] >= 2) gt3++;

	}
	int ans = gt75 + gt25 * (gt3-1) + gt15 * (gt5-1) + gt5*(gt5-1)/2 * (gt3-2);
	ans = max(0, ans);
	cout << ans << endl;
}

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

using namespace std;

const int N = 1e5 + 7;

const long long inf = (long long)1e18;

int main() {
    std :: ios :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long double n;
    long double b;
    cin >> n >> b;
    long long ans = (long long)(1.0 * n * b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3740
/*
Reference : https://www.geeksforgeeks.org/maximum-product-subsequence-size-k/
 
 
*/
#include <bits/stdc++.h> 
using namespace std; 
 
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
bool sortbysecdesc(const pair<int,int> &a, 
                   const pair<int,int> &b) 
{ 
       return a.second>b.second; 
} 
 
/*
Mistakes
 
- while using pairs make sure you comparator datatype it's int by default change it as per the need
- Modify comparator if you want to
*/
#define f first
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll64 int64_t
#define pb push_back
#define pll pair<long long int,long long int>
#define pi pair<int,int>
#define mi map<int,int>
#define ll long long int
#define mll map<long long int,long long int>
#define umi unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<long long int,long long int>>
#define mod 1000000007
#define fp(i,x,n) for(int i=x;i<n;i++)
#define fn(i,x,n) for(int i=x;i>n;i--)
#define fpm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define asort_vp_second(vect) sort(vect.begin(), vect.end(), sortbysec)
#define asort_vp_first(vect) sort(vect.begin(), vect.end())
#define dsort_vp_first(vect) sort(vect.begin(), vect.end(), sortinrev) 
#define dsort_vp_second(vect) sort(vect.begin(), vect.end(), sortbysecdesc)
#define vi vector<int>
#define vll vector<long long int>
#define c(x) cout<<x<<endl;
#define M 1000000007
using namespace std; 
#define int long long int
 
 
signed main()
{
    int n;
    cin>>n;
   int mx = INT_MIN, mn=INT_MAX;
   int x,y;
   vector<int> v,v1;
   fp(i,0,n)
   {
       cin>>x>>y;
       v.pb(x+y);
       v1.pb(x-y);
   }
   sort(v.begin(),v.end());
   sort(v1.begin(),v1.end());
   cout<<max(abs(v[0]-v[v.size()-1]),abs(v1[0]-v1[v1.size()-1]))<<endl;
}

Measured memory_bytes: 6644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N = 1e5;
    vector<bool> primes(N+1, true);
    primes[1] = false;
    rep(i, 2, N+1){
        for(ll j = 2; i * j <= N; j++){
            primes[i*j] = false;
        }
    }
    vector<ll> acc(N+1, 0);
    rep(i, 1, N+1){
        acc[i] = acc[i-1];
        if(i % 2 == 0) continue;
        if(primes[i] && primes[(i+1)/2]) acc[i]++;
    }

    ll Q;
    cin >> Q;
    rep(q, 0, Q){
        ll l, r;
        cin >> l >> r;
        cout << acc[r] - acc[l-1] << endl;
    }
    return 0;
}

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

void func(int a[]){
  sort(a,a+5);
  int cnt = 1;
  for(int i = 1 ; i < 5 ; i++){
    if(a[1] == 10 && i == 4){
      if(a[0] == 1 && a[4] == 13)cnt++;
    }
    if(a[i-1]+1 == a[i])cnt++;
  }
  if(cnt == 5){
    cout << "straight" << endl;
    return;
  }
  
  int c[14];
  int two,three,four;
  two = three = four = 0;
  for(int i = 0 ; i < 14 ; i++)c[i] = 0;
  for(int i = 0 ; i < 5 ; i++)c[a[i]]++;
  for(int i = 0 ; i < 14 ; i++){
    if(c[i] == 4)four++;
    else if(c[i] == 3)three++;
    else if(c[i] == 2)two++;
  }
  
  if(four == 1){
    cout << "four card" << endl;
    return;
  }
  else if(two == 1 && three == 1){
    cout << "full house" << endl;
    return;
  }
  else if(two == 2){
    cout << "two pair" << endl;
    return;
  }
  else if(two == 1){
    cout << "one pair" << endl;
    return;
  }
  else if(three == 1){
    cout << "three card" << endl;
    return;
  }
  cout << "null" << endl;
}
    

int main(){
  int a[5];
  while(scanf("%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4]) != EOF){
    func(a);
  }
  return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>

int main(void){
   
   int A,B,K;
   
   scanf("%d%d%d",&A,&B,&K);
   
   int i;
   int count = 1;
   int Ans[101];
   
   int min;
   if(A >= B){
      min = B;
   }
   else {
      min = A;
   }
   
   for(i = 1;i <= min;i++){
      if(A%i == 0 && B%i == 0){
         Ans[count] = i;
         count++;
      }
   }
   
   printf("%d\n",Ans[count - K]);
   
   return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
const int maxn=12;
int n,D;
int x[maxn][maxn];
int main()
{
    cin>>n>>D;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=D;j++) scanf("%d",&x[i][j]);
    }
    int cnt=0;
    for(int i=1;i<=n-1;i++){
        for(int j=i+1;j<=n;j++){
            int sum=0;
            for(int z=1;z<=D;z++){
                int tmp=(x[i][z]-x[j][z])*(x[i][z]-x[j][z]);
                sum+=tmp;
            }
            int res=sqrt(sum);
            if((res*res)==sum){
                cnt++;
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 256
n=gets.to_i
a=Array.new(n)
for i in 0...n
    a[i]=gets.to_i
end

left=Array.new(n)
right=Array.new(n)

left[0]=a[0]
for i in 1...n
    left[i]=[left[i-1],a[i]].max
end

right[n-1]=a[n-1]
for i in (0...n-1).reverse_each
    right[i]=[right[i+1],a[i]].max
end

for i in 0...n
    if i==0
        p right[i+1]
    elsif i==n-1
        p left[n-2]
    else
        p [left[i-1],right[i+1]].max
    end
end

Measured memory_bytes: 11828
#include <stdio.h>;
//#include "Main.h"
int main(void)
{
	// Your code here!
	int n;
	int a[51];
	int b[51];
	int c[51];
	long int ans=0;

	scanf("%d", &n);
	for (int i = 0; i<n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 0; i<n; i++)
	{
		scanf("%d", &b[i]);
		ans = ans + b[i];
	}
	for (int i = 0; i<n-1; i++)
	{
		scanf("%d", &c[i]);
	}
	for (int i = 0; i<n; i++)
	{
		if (a[i]+1 == a[i+1])
		{
			ans = ans + c[a[i]-1];
		}
	}
	printf("%ld", ans);
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt(),m=scan.nextInt(),x=scan.nextInt(),a,l=0,r=0,i;
		for(i=0;i<m;i++) {
			a=scan.nextInt();
			if(a>x) r++;
			else l++;
		}
		scan.close();
		System.out.print(r>l?l:r);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main(){
  int n;
  cin>>n;
  
  ll ans=0;
  vector<ll> p(n);
  map<ll,int> q;
  rep(i,n){
    cin>>p[i];
    ans+=p[i];
    if(q.count(p[i])) q.at(p[i])++;
    else q[p[i]]=1;
  }

  int z;
  cin>>z;

  rep(i,z){
    ll x,y;
    cin>>x>>y;
    if(q.count(x)) {
      ans+=q.at(x)*(y-x);
      if(q.count(y)) q.at(y)+=q.at(x);
      else q[y]=q.at(x);
      q.at(x)=0;
    }
    cout << ans << endl;
  }

}


Measured memory_bytes: 9028
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  ll a = 1;
  ll b = 1;
  rep(i, n){
    ll x, y;
    cin >> x >> y;
    ll na = (a+x-1)/x * x;
    ll nab = na/x * y;
    ll nb = (b+y-1)/y * y;
    ll nba = nb/y * x;
    if(b <= nab){
      a = na;
      b = nab;
    }
    else{
      a = nba;
      b = nb;
    }
  }

  cout << a + b << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<=n;++i){
		for(int j=0;j<=m;++j){
			if(i*j+(n-i)*(m-j)==k){
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <string.h>
#include <map>
#include <iomanip>
#include <time.h>
using namespace std;
typedef long long ll;

double square(pair<int, int> p) {
    return p.first * p.first + p.second * p.second;
}

pair<int, int> add(pair<int, int> p, pair<int, int> q) {
    return make_pair(p.first + q.first, p.second + q.second);
}

double dot(pair<int, int> p, pair<int, int> q) {
    return p.first * q.first + p.second * q.second;
}

int main() {
    int x1, y1, x2, y2, q;
    cin >> x1 >> y1 >> x2 >> y2;
    pair<int, int> a = make_pair(x2 - x1, y2 - y1);

    cin >> q;
    while (q--) {
        int x, y;
        cin >> x >> y;

        pair<int, int> b = make_pair(x - x1, y - y1);
        double r = dot(a, b) / square(a);

        pair<double, double> c;
        c.first = x1 + r * (x2 - x1);
        c.second = y1 + r * (y2 - y1);

        double dx = x + (c.first - x) * 2, dy = y + (c.second - y) * 2;

        cout << setprecision(16) << dx << " " << dy << endl;


    }
}


Measured memory_bytes: 3292
#include <iostream>
#include <vector>
#include <cstdio>
#include <math.h>
#include <string>
#include <map>
#include <functional>
#include <algorithm>
#include <stack> 
#include <iomanip>
#include <stdio.h>
#include <set>
#include <array>
using namespace std; 

int main()
{
	string s, t;
	int n;
	cin >> n;
	cin >> s >> t;
	for (int i = 0; i < n; ++i) {
		cout << s[i] << t[i];
	}
	cout << endl;
	return 0;
}


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

using lint = long long;

int main() {
    lint L;
    int N;
    std::cin >> L >> N;

    std::vector<lint> A(N);
    for (auto& a : A) std::cin >> a;

    std::vector<lint> rsum(N + 1, 0);
    for (int i = 0; i < N; ++i) rsum[i + 1] = rsum[i] + A[i];

    // Aを左右反転させたもの
    auto B = A;
    std::reverse(B.begin(), B.end());
    for (auto& b : B) b = L - b;

    std::vector<lint> lsum(N + 1, 0);
    for (int i = 0; i < N; ++i) lsum[i + 1] = lsum[i] + B[i];

    A.insert(A.begin(), 0);
    B.insert(B.begin(), 0);  // index合わせ(なくてもいい)

    lint ans = 0; 

    // 右に移動して終わるケース
    for (int r = 1; r <= N; ++r) {
        // r個の区間に右から入る
        int l = N - r;
        int step = std::min(l, r);  // 「階段」の段数

        lint left = (lsum[l] - lsum[l - step]) * 2;
        lint right = (rsum[r] - rsum[r - step]) * 2 - A[r];
        if (r > l) right += A[r - step] * 2;
        // 右側の階段が1段増える

        ans = std::max(ans, left + right);
    }

    // 左に移動して終わるケース
    // さっきのを全体を左右反転させてやるだけ
    for (int l = 1; l <= N; ++l) {
        int r = N - l;
        int step = std::min(l, r);

        lint left = (lsum[l] - lsum[l - step]) * 2 - B[l];
        lint right = (rsum[r] - rsum[r - step]) * 2;
        if (l > r) left += B[l - step] * 2;

        ans = std::max(ans, left + right);
    }

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


Measured memory_bytes: 9572