akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}
Int tmpi = 0;
double tmpd = 0.0;


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

    Int k, x, y, z;
    vector<Int> a, b, c;
    cin >> x >> y >> z >> k;
    for(Int i=0; i<x; i++){
        cin >> tmpi;
        a.push_back(tmpi);
    }
    for(Int i=0; i<y; i++){
        cin >> tmpi;
        b.push_back(tmpi);
    }
    for(Int i=0; i<z; i++){
        cin >> tmpi;
        c.push_back(tmpi);
    }

    sort(a.begin(), a.end(), greater<Int>());
    sort(b.begin(), b.end(), greater<Int>());
    sort(c.begin(), c.end(), greater<Int>());
    
    vector<Int> ab;
    for(Int i=0; i<x; i++){
        for(Int j=0; j<y; j++){
            ab.push_back(a[i]+b[j]);
        }
    }
    sort(ab.begin(), ab.end(), greater<Int>());

    vector<Int> abc;
    int num = k > x*y ? x*y : k;
    for(Int i=0; i<num; i++){
        for(Int j=0; j<z; j++){
            abc.push_back(ab[i]+c[j]);
        }
    }

    sort(abc.begin(), abc.end(), greater<Int>());
    for(Int i=0; i<k; i++){
        cout << abc[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 43000
def euler_totient(n):
    if n <= 0:
        return 0
    ans = n
    i = 2
    while i * i <= n:
        if n % i == 0:
            ans -= ans // i
            while n % i == 0:
                n //= i
        i += 1
    if n > 1:
        ans -= ans // n
    return ans


def aoj():
    print(euler_totient(int(input())))


if __name__ == "__main__":
    aoj()



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;
void solve()
{
	ll n;
	cin>>n;
	vector<ll> a(n);
	map<ll,ll> f;
	ll s=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		f[a[i]]++;
		s+=a[i];
	}
	ll Q;
	cin>>Q;
	for(ll i=0;i<Q;i++)
	{
		ll b,c;
		cin>>b>>c;
		s-=(f[b]*b);
		s+=(f[b]*c);
		f[c]+=f[b];
		f[b]=0;
		cout<<s<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1;
	//cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
}

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

const int MAXN = 200005, mod = 924844033, g = 5;

inline int read()
{
	int a = 0, c;
	do c = getchar(); while (!isdigit(c));
	while (isdigit(c)) {
		a = a*10+c-'0';
		c = getchar();
	}
	return a;
}

int rev[1<<19|1];

inline int power(int a, int n)
{
	int ans = 1;
	for (; n; n >>= 1) {
		if (n&1) ans = (long long)ans*a%mod;
		a = (long long)a*a%mod;
	}
	return ans;
}

inline int inv(int a)
{ return power(a, mod-2); }

void NTT(int a[], int n, int lgn, int flag)
{
	for (int i = 1; i < n; i++) rev[i] = ((rev[i>>1]>>1)|((i&1)<<(lgn-1)));
	for (int i = 1; i < n; i++)
		if (rev[i] < i)
			swap(a[i], a[rev[i]]);
	for (int k = 2; k <= n; k <<= 1) {
		int dw = power(g, (mod-1)/k);
		if (flag == -1) dw = inv(dw);
		for (int i = 0; i < n; i += k) {
			int w = 1, u, v;
			for (int j = 0; j < k>>1; j++) {
				u = a[i+j], v = (long long)w*a[i+j+(k>>1)]%mod;
				a[i+j] = (u+v)%mod, a[i+j+(k>>1)] = ((u-v)%mod+mod)%mod;
				w = (long long)w*dw%mod;
			}
		}
	}
	if (flag == -1) {
		int invn = inv(n);
		for (int i = 0; i < n; i++)
			a[i] = (long long)a[i]*invn%mod;
	}
}

struct node {
	int to, next;
} edge[MAXN*2];
int head[MAXN], top = 0;
inline void push(int i, int j)
{ edge[++top] = (node) {j, head[i]}, head[i] = top; }

int siz[MAXN], a[MAXN], b[MAXN];
int n;

void dfs(int nd, int f)
{
	siz[nd] = 1;
	for (int i = head[nd]; i; i = edge[i].next) {
		int to = edge[i].to;
		if (to == f) continue;
		dfs(to, nd), siz[nd] += siz[to];
	}
	if (nd != 1) a[siz[nd]]++;
	b[n-siz[nd]]++;
}

int fac[MAXN], ifac[MAXN], inv_num[MAXN];

inline int choose(int n, int m)
{ return (long long)fac[n]*ifac[m]%mod*ifac[n-m]%mod; }

int A[1<<19|1], B[1<<19|1], ans[MAXN];

int main()
{
	n = read();
	fac[0] = ifac[0] = inv_num[1] = 1;
	for (int i = 2; i <= n; i++)
		inv_num[i] = (mod-(long long)mod/i*inv_num[mod%i]%mod)%mod;
	for (int i = 1; i <= n; i++) {
		fac[i] = (long long)fac[i-1]*i%mod;
		ifac[i] = (long long)ifac[i-1]*inv_num[i]%mod;
	}
	for (int i = 1; i < n; i++) {
		int u = read(), v = read();
		push(u, v), push(v, u);
	}
	dfs(1, 0);
	int N = 1, lgn = 0;
	while (N <= 2*n) N <<= 1, lgn++;
	for (int i = 1; i <= n; i++) ans[i] = (long long)n*choose(n, i)%mod;
	for (int i = 0; i <= n; i++) A[i] = (long long)a[i]*fac[i]%mod;
	for (int i = 0; i <= n; i++) B[i] = ifac[n-i];
	NTT(A, N, lgn, 1), NTT(B, N, lgn, 1);
	for (int i = 0; i < N; i++) A[i] = (long long)A[i]*B[i]%mod;
	NTT(A, N, lgn, -1);
	for (int k = 1; k <= n; k++) 
		(ans[k] += (mod-(long long)A[n+k]*ifac[k]%mod)%mod) %= mod;
	memset(A, 0, sizeof A), memset(B, 0, sizeof B);
	for (int i = 0; i <= n; i++) A[i] = (long long)b[i]*fac[i]%mod;
	for (int i = 0; i <= n; i++) B[i] = ifac[n-i];
	NTT(A, N, lgn, 1), NTT(B, N, lgn, 1);
	for (int i = 0; i < N; i++) A[i] = (long long)A[i]*B[i]%mod;
	NTT(A, N, lgn, -1);
	for (int k = 1; k <= n; k++) 
		(ans[k] += (mod-(long long)A[n+k]*ifac[k]%mod)%mod) %= mod;
	for (int k = 1; k <= n; k++)
		printf("%d\n", ans[k]);
	return 0;
}


Measured memory_bytes: 25600
def is_month(x):
    return True if x > 0 and x <= 12 else False

S = input().strip()

former = int(''.join(S[:2]))
later = int(''.join(S[2:]))

if is_month(former) and is_month(later):
    print('AMBIGUOUS')
elif is_month(former) and not is_month(later):
    print('MMYY')
elif not is_month(former) and is_month(later):
    print('YYMM')
else:
    print('NA')

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

int main() {
  long N;
  cin >> N;
  if (N <= 6) return cout << 1 << "\n", 0;
  long ans = N / 11;
  ans *= 2;
  N %= 11;
  cout << ans + (N + 6 - 1) / 6 << "\n";
}

Measured memory_bytes: 3640
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        int s = -n;
        for(int i=1; i*i<=n; ++i){
            if(n % i == 0){
                s += i;
                if(i*i != n)
                    s += n / i;
            }
        }

        if(s < n)
            cout << "deficient number" << endl;
        else if(s == n)
            cout << "perfect number" << endl;
        else
            cout << "abundant number" << endl;
    }
}

Measured memory_bytes: 0
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//int→string
//string→int
//------------------------------------------
inline int toInt(string s) {
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}

template<class T>
inline string toString(T x) {
    ostringstream sout;
    sout << x;
    return sout.str();
}

//sqrt
//-------------------------------------------
template<class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

//repetition
//------------------------------------------
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  FOR(i,0,n)
#define REPR(i, n) for(int i = n;i >= 0;i--)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL func(LL t, LL x){
    LL count = t/x;
    return count;
}

int main() {

    int N; cin >> N;
    VI a(N+1);
    for(int i=1;i<=N;i++){
        scanf("%d", &a[i]);
    }

    int count = 0;
    int button = 1;

    while(count <=100020){
        if(button == 2){
            break;
        }
        button = a[button];
        count++;
    }

    if(count>=100010){
        cout<<-1;
    }else {
        cout << count;
    }
    return 0;
}















































Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	string ss;
	cin >> ss;
	ss[3] = '8';
	cout << ss << endl;
	return 0;
}

Measured memory_bytes: 3608
#include <vector>
#include <map>
#include <cstdio>
std::map<int,std::vector<int>>v;
std::map<int,int>m;
long long r;
int d(int i,int p){
	int h=1;
	for(int c:v[i])if(c-p)h=(h+997LL*d(c,i))%1000000007;
	r+=m[h]++;
	return h;
}
int main(){
	int N,a,b;
	for(scanf("%d",&N);--N;)scanf("%d%d",&a,&b),v[a].push_back(b),v[b].push_back(a);
	d(1,0);
	printf("%lld\n",r);
}

Measured memory_bytes: 27872
#include <cstdio>
#include <iostream>


int main() {
    
    int S;
    std::cin >> S;
    
    int h = S / (60 * 60);
    int m = (S / 60) % 60;
    int s = S % 60;
    printf("%d:%d:%d\n", h, m, s);
    
    return 0;
}

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

int main() {
 int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  
  if((2*a[2]-a[0]-a[1])%2==0) cout<<(2*a[2]-a[0]-a[1])/2<<endl;
  else cout<<(2*a[2]-a[0]-a[1]+1)/2+1<<endl;
  
  
}

Measured memory_bytes: 256
open Printf
open Scanf

let ( ++ ) = Int64.add
let ( -- ) = Int64.sub
let ( ** ) = Int64.mul
let ( // ) = Int64.div
let ( %% ) = Int64.rem
let long = Int64.of_int

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)

let m = 1000_000_007L

let rec foldi i n f a =
  if i > n
  then a
  else foldi (i+1) n f (f a i)

let rec mod_pow a = function
  | 0L -> 1L
  | b -> (if b %% 2L = 0L then 1L else a) ** mod_pow (a ** a %% m) (b//2L) %% m

let make_f n x s =
  let dp = Array.(init n (fun _ -> make (x+1) (-1L))) in
  let rec f (i: int) (x: int): int64 = match i = n with
    | true -> long x
    | false ->
      if dp.(i).(x) < 0L
      then
        let res = (long (n-i-1) ** f (i+1) x %% m ++ f (i+1) (x mod s.(i))) %% m in
        let res = res ** mod_pow (long (n-i)) (m--2L) %% m in
        let () = dp.(i).(x) <- res in
        res
      else dp.(i).(x)
  in f

let () =
  let n = read_int () in
  let x = read_int () in
  let s = Array.(init n read_int) in
  let () = Array.sort (fun x y -> y - x) s in
  let f = make_f n x s in
  let ans = foldi 1 n (fun a i -> a ** long i %% m) (f 0 x) in
  printf "%Ld\n" ans


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int x,a,b;
    cin>>x>>a>>b;
    if (abs(a-x)<abs(b-x)) cout<<"A"<<endl;
    else cout<<"B"<<endl;
    return 0;
}

Measured memory_bytes: 256
c11,c12,c13 = map(int,input().split())
c21,c22,c23 = map(int,input().split())
c31,c32,c33 = map(int,input().split())

a = 0
if c13 - c12 == c23 - c22 == c33 - c32:
  if c12 - c11 == c22 - c21 == c32 - c31:
    if c33 - c23 == c32 - c22 == c31 - c21:
      if c23 - c13 == c22 - c12 == c21 - c11:
        print("Yes")
        a = 1
        
if a == 0:
  print("No")

Measured memory_bytes: 38396
#include<bits/stdc++.h>                          
using namespace std;    
int n,a[105];                                         
int main(){	
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+1+n);
	cout<<a[n]-a[1];
	return 0;
}

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

int main() {
	double  d, t, s;
	cin >> d >> t >> s;

	double time = d / s;
	if (time <= t)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

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

	int now=a[0];
	int ans=0;
	rep(i,n){
		if(a[i]<=now){
			ans++;
			now=a[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define INF 0x3f3f3f3f
#define pb push_back
#define se second
#define fi first
using namespace std;
const int N=1e5+5;
int vis[N],grundy[N];
vector<int> g[N];

void dfs(int u){
    vis[u]=1;
    for(int v:g[u]){
        if(vis[v]) continue;
        dfs(v);
        grundy[u]^=(grundy[v]+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n; cin>>n;
    for(int i=1;i<n;i++){
        int u,v; cin>>u>>v;
        g[u].pb(v); g[v].pb(u);
    }
    dfs(1);
    cout<<(grundy[1]?"Alice":"Bob");
    return 0;
}

Measured memory_bytes: 11264
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)

ll K;
vector<ll> Ans;

int main() {

	scanf("%lld", &K);

	vector<ll> List;
	ll n = 0;

	ll d = 1;

	rep(t, 15) {
		rep(i, 99999) {
			n += d;
			List.push_back(n);
		}
		d *= 10;
		n /= 10000;
	}

	sort(List.begin(), List.end());

	vector<ll> ListS(List.size());

	for (ll i = 0; i < List.size(); ++i) {
		ll t = List[i];
		for (ll j = 1; j <= 16; ++j) {
			ListS[i] += t % 10;
			t /= 10;
		}
	}

	vector<double> S(List.size());
	for (ll i = 0; i < List.size(); ++i) {
		S[i] = (double)List[i] / ListS[i];
	}

	vector<double> MinList(List.size());
	for (ll i = List.size() - 1; i >= 0; --i) {
		if (i == List.size() - 1) MinList[i] = S[i];
		else MinList[i] = min(MinList[i + 1], S[i]);
	}

	ll t = 0;
	for (ll i = 0; i < List.size(); ++i) {
		if (List[i] == List[i + 1]) continue;
		if (MinList[i] == S[i]) {
			++t;
			printf("%lld\n", List[i]);
			if (t == K) return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 49124
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p=p[:X]
q=q[:Y]
s=p+q+r
s.sort(reverse=True)
print(sum(s[:X+Y]))

Measured memory_bytes: 23328
#include<stdio.h>
int main(){
	int N,M,d[100],v[100],sum,val[100];
	for(;;){
		for(int i = 0;i<100;i++){
			val[i] = 0;
		}
		scanf("%d %d",&N,&M);
		if(N == 0&&M == 0)	break;
		for(int i=0;i<N;i++){
			scanf("%d %d",&d[i],&v[i]);
			if(val[d[i]-1]<v[i])	val[d[i]-1]=v[i];
		}
		sum = 0;
		for(int i=0;i<M;i++){
			sum = sum + val[i];
		}
		printf("%d\n",sum);
	}
}

Measured memory_bytes: 2712
#include <iostream>
#include <cmath>
#include <string>
#include<set>
#include<vector>
#define MAX 5000
using namespace std;

int main(void) {
    long long n, i, j, cnt[5]={0}, tmp, sum=0, cnt1;
    string s;
    cin >> n;
    for(i=0; i<n; i++) {
        cin >> s;
        if(s[0]=='M')
            cnt[0]++;
        else if(s[0]=='A')
            cnt[1]++;
        else if(s[0]=='R')
            cnt[2]++;
        else if(s[0]=='C')
            cnt[3]++;
        else if(s[0]=='H')
            cnt[4]++;
    }
    
    for(i=0; i<1<<5; i++) {
        tmp = 1;
        cnt1 = 0;
        for(j=0; j<5; j++) {
            if(1&i>>j) {
                tmp *= cnt[j];
                cnt1++;
            }
        }
        if(cnt1==3)
            sum += tmp;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,ne,c,i,cnt=0;
  while(1){
    scanf("%d",&n);
    if(n==0){
      break;
    }
    ne=n/4;
    for(i=0;i<ne;i++){
      scanf("%d",&c);
      cnt=cnt+c;
    }
    printf("%d\n",cnt);
    cnt=0;
  }
  return 0;
}
      

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,e;
  cin>>a>>b;
  vector<int>c(b);
  vector<int>d(b);
  for(int i=0;i<b;i++){
    cin>>c.at(i)>>d.at(i);
  }
  sort(c.begin(),c.end());
  sort(d.begin(),d.end());
  if(d.at(0)<c.at(b-1)){
     cout<<0;
  }else{
    cout<<d.at(0)-c.at(b-1)+1;
  }
}

Measured memory_bytes: 1024
n=int(input())
x=[int(i) for i in input().split()]

mas=[False]*2020
for i in x:
    mas[i]=True
m=int(input())
a=[int(i) for i in input().split()]

for i in range(m):
    now=x[a[i]-1]
    if now==2019:
        continue
    elif mas[now+1]:
        continue
    mas[now],mas[now+1]=False,True
    x[a[i]-1]+=1

for i in range(2020):
    if mas[i]:
        print(i)


Measured memory_bytes: 5628
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

int n, p1, p2;
int Not, V;
bool used[605];
vector<pair<int, int> > vec;
vector<vector<int> > comp, comp2;
int dp[605][305];

int parent[1205];
void init(){
	for(int i = 1; i <= V; i++) parent[i] = i;
}
int root(int i){
	if(parent[i] == i) return i;
	return parent[i] = root(parent[i]);
}
void unite(int i, int j){
	int root_i = root(i), root_j = root(j);
	if(root_i == root_j) return;
	parent[root_i] = root_j;
}

int main(void)
{
	while(1){
		cin >> n >> p1 >> p2;
		if(n == 0 && p1 == 0 && p2 == 0) break;
		Not = p1 + p2;
		V = 2 * Not;
		
		init();
		int x, y; string s;
		for(int i = 0; i < n; i++){
			cin >> x >> y >> s;
			if(s == "yes"){
				unite(x, y);
				unite(x+Not, y+Not);
			}
			else{
				unite(x, y+Not);
				unite(x+Not, y);
			}
		}
		
		vec.clear();
		comp.clear(), comp2.clear();
		for(int i = 1; i <= Not; i++) used[i] = false;
		for(int i = 1; i <= Not; i++){
			if(used[i]) continue;
			int root_i = root(i);
			int cnt1 = 0, cnt2 = 0;
			vector<int> tmp1, tmp2;
			for(int j = 1; j <= V; j++){
				if(root(j) == root_i){
					if(j <= Not){
						cnt1++;
						used[j] = true;
						tmp1.push_back(j);
					}
					else{
						cnt2++;
						used[j-Not] = true;
						tmp2.push_back(j-Not);
					}
				}
			}
			vec.push_back(make_pair(cnt1, cnt2));
			comp.push_back(tmp1);
			comp2.push_back(tmp2);
		}
		
		/*for(int i = 0; i < vec.size(); i++){
			cout << vec[i].first << " " << vec[i].second << endl;
		}*/
		
		int N = vec.size();
		for(int i = 0; i <= N; i++){
			for(int j = 0; j <= p1; j++){
				dp[i][j] = 0;
			}
		}
		dp[0][0] = 1;
		
		for(int i = 0; i < N; i++){
			for(int j = 0; j <= p1; j++){
				dp[i][j] = min(dp[i][j], 2);
				if(j+vec[i].first <= p1) dp[i+1][j+vec[i].first] += dp[i][j];
				if(j+vec[i].second <= p1) dp[i+1][j+vec[i].second] += dp[i][j];
			}
		}
		
		/*for(int i = 0; i <= N; i++){
			for(int j = 0; j <= p1; j++){
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}*/
		
		if(dp[N][p1] >= 2){
			cout << "no" << endl;
			continue;
		}
		
		int p = p1;
		vector<int> ans;
		for(int i = N-1; i >= 0; i--){
			if(p - vec[i].first >= 0 && dp[i][p - vec[i].first]){
				p -= vec[i].first;
				for(int j = 0; j < comp[i].size(); j++) ans.push_back(comp[i][j]);
			}
			else if(p - vec[i].second >= 0 && dp[i][p - vec[i].second]){
				p -= vec[i].second;
				for(int j = 0; j < comp2[i].size(); j++) ans.push_back(comp2[i][j]);
			}
		}
		
		sort(ans.begin(), ans.end());
		for(int i = 0; i < ans.size(); i++){
			cout << ans[i] << endl;
		}
		cout << "end" << endl;
	}
	return 0;
}


Measured memory_bytes: 3308
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,k,ans=0;
vector<int> G[100010];
int p[100010],d[100010];

int dfs(int s){
  int res=0;
  for(int t:G[s]){
    d[t]=dfs(t);
    res=max(res,d[t]+1);
  }
  if(res>=k-1 && p[s]!=0) {
    ans+=1;
    res=-1;
  }
  //cout << s << " " << res << endl;
  return res;
}

void solve(){
  cin >> n >> k;
  p[0]=0;
  rep(i,n){
    int a;cin >> a;a--;
    if(i==0) {
      if(a!=0) ans+=1;
    }
    else{
      G[a].push_back(i);
      p[i]=a;
    }
  }
  dfs(0);
  cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 11264
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
using namespace std;
int main(){
	string s[7]={"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
	string ss;
	cin>>ss;
	if(ss=="SUN"){
		cout<<7<<endl; 
	}else{
		for(int i=0;i<7;i++){
			if(ss==s[i]){
				cout<<6-i<<endl;
				return 0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<limits.h>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>

int N = 0, M = 0;
bool edge[10][10] = {false};

bool tf[10] = { false };

int ans = 0;

bool solve(int a) {
	//printf("%d ",a);
	bool t = true;
	tf[a] = true;
	for (int i = 0; i < N; i++) {
		if (tf[i] == false)
			t = false;
	}
	if (t) {
	//	printf("Yes");
		ans++;
		tf[a] = false;
	} else {
		for (int i = 0; i < N; i++) {
			if (!tf[i] && edge[a][i])
				solve(i);
		}
		tf[a] = false;
	}
	//printf("\n");
	return true;
}

int main(void) {
	
	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++) {
		int a = 0, b = 0;
		scanf("%d%d", &a, &b);
		edge[a - 1][b - 1] = true;
		edge[b - 1][a - 1] = true;
	}
	for (int i = 0; i < N; i++) {
		memset(tf, false, sizeof(tf));
		tf[0] = true;
		if(edge[0][i])
			solve(i);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
int main()
{
	int D;
    scanf("%d",&D);
    int C[26];
    for(int a = 0; a < 26; a++)
    {
        scanf("%d",&(C[a]));
    }
    int SCORE[365][26];
    for(int a = 0; a < 365; a++)
    {
        for(int b = 0; b <26; b++)
        {
        	scanf("%d",&(SCORE[a][b]));
        }
    }
    int HUMANABC[26] = {0};
    int KEKKA[365] = {0};
    for(int a = 0; a < 365; a++)
    {
    	for(int b = 0; b <26; b++)
        {
        	HUMANABC[b] += C[b];
        }
        int GOUKEI[26] = {0};
        for(int c = 0; c <26; c++)
        {
            GOUKEI[c] = SCORE[a][c] + (365 - a) * (HUMANABC[c]);
        }
        for(int c = 0; c < 26; c++)
        {
            int n = 0;
            if(n < GOUKEI[c])
            {
                n = GOUKEI[c];
                KEKKA[a] = (c + 1);
            }
        }
        HUMANABC[KEKKA[a] - 1] = 0;
    }
	for(int a = 0; a < 365; a++)
    {
    	printf("%d\n",KEKKA[a]);
    }
}


Measured memory_bytes: 3272
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
const int N = 1000003;
int n, a[N], ans;
bool f;
int main(){
    scanf("%d", &n);
    for(Rint i = 0;i < n;++ i){
        scanf("%1d", a + i); -- a[i]; f |= a[i] == 1;
    }
    if(!f) for(Rint i = 0;i < n;++ i) a[i] >>= 1;
    for(Rint i = 0;i < n;++ i) if(!(i & n - 1 - i)) ans ^= a[i] & 1;
    if(!f) ans <<= 1;
    printf("%d", ans);
}

Measured memory_bytes: 4096
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 2;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll n, z, w;
  cin >> n >> z >> w;
  ll a[2010];
  rep(i, n) cin >> a[i];
  int ans;
  if (n == 1)
  {
    ans = abs(w - a[n - 1]);
  }
  else
  {
    ans = max(abs(w - a[n - 1]), abs(a[n - 1] - a[n - 2]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
#AGC13 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7


n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
ans = 1
x = a[0]
flg = 0
for i in range(1,n):
    if flg == 0:
        if x < a[i]:
            flg = 1
        elif x > a[i]:
            flg = -1
    elif flg == 1:
        if x > a[i]:
            flg = 0
            ans += 1
    elif flg == -1:
        if x < a[i]:
            flg = 0
            ans += 1
    x = a[i]
print(ans)


Measured memory_bytes: 58864
X,Y,Z,K=gets.chomp.split.map(&:to_i)
a=gets.chomp.split.map(&:to_i)
b=gets.chomp.split.map(&:to_i)
c=gets.chomp.split.map(&:to_i)

ab = []
a.each do |m|
  b.each do |n|
    ab << m+n
  end
end

ab.sort!.reverse!

abc = []
ab.each_with_index do |m, i|
  next if i >= K
  c.each_with_index do |n, j|
    next if j >= K
    abc << m+n
  end
end

abc.sort!.reverse!

0.upto(K-1) do |i|
  puts abc[i]
end



Measured memory_bytes: 72176
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<ctype.h>

#define MOD 1e7+7
typedef long long ll;

ll mygcd(ll a, ll b) { if (b == 0) return a; return mygcd(b, a % b); }

ll mylcm(ll a, ll b) { return a / mygcd(a, b) * b; }

ll mymax(ll a, ll b) { return (a > b) ? a : b; }

ll mymin(ll a, ll b) { return (a < b) ? a : b; }

ll myasc(const void* a, const void* b) { return *(ll*)a - *(ll*)b; }

ll mydsc(const void* a, const void* b) { return *(ll*)b - *(ll*)a; }

ll n, k, a[200000], b[2000001];

int main() {
	scanf("%lld%lld", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}
	for (int i = 0; i < k; i++) {
		bool flag = true;
		for (int j = 0; j < n; j++) b[j] = 0;
		for (int j = 0; j < n; j++) {
			b[mymax(0, j - a[j])]++;
			b[mymin(n, j + a[j]+1)]--;
		}
		a[0] = b[0];
		for (int j = 1; j < n; j++) a[j] = a[j - 1] + b[j];
		for (int j = 0; j < n; j++) {
			if (a[j] != n) flag = false;
		}
		if (flag) {
			for (int j = 0; j < n; j++) printf("%lld ", n);
			return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%lld ", a[i]);
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
const ll mod = 998244353,N = 2e5+5;
int n,m,k;
ll fac[N];

ll mul(ll x,ll y){
	return x*y%mod;
}

ll qpow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}

ll inv(ll x){
	return qpow(x,mod-2);
}

ll C(ll n,ll m){
	return fac[n]*mul(inv(fac[m]),inv(fac[n-m]))%mod;
}

void init(){
	fac[0]=1;
	for(int i=1;i<=N;i++) fac[i]=mul(fac[i-1],i);
}

int main(){
	init();
	cin>>n>>m>>k;
	ll ans=0;
	for(int i=0;i<=k;i++){
		ans=(ans+mul(mul(m,C(n-1,i)),qpow(m-1,n-i-1)))%mod;
	}
	cout<<ans<<'\n';
	
	return 0;
}

Measured memory_bytes: 5216
#include <iostream>

#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
using namespace std;

template<class T>
void in(vector<T>& V) {
	for (auto itr = V.begin(); itr != V.end(); itr++)cin >> *itr;
	return;
}

template<class T>
void out(vector<T>& V) {
	for (T& itr : V)cout << itr << endl;
	return;
}

string W;

int main() {
	cin >> W;
	bool flag = true;
	for (int c = 'a'; c <= 'z'; c++) {
		int counter = 0;
		for (int n = 0; n < W.size(); n++) {
			if (W[n] == c)counter++;
		}
		if (counter % 2 != 0) {
			flag = false;
			break;
		}
	}
	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

constexpr int nil = -1;

class ILcs
{
public:
    using vvi = std::vector<std::vector<int>>;
    virtual int lcs() = 0;
    virtual int lcs(int i1, int i2) = 0;
};

class LcsLoop : public ILcs
{
public:

    LcsLoop(std::string str1, std::string str2)
        : str1 {" " + str1}
        , str2 {" " + str2}
        , dp {vvi(str1.size() + 1, std::vector<int>(str2.size() + 1))}
    {
        CalcLcs();
    }

    int lcs() override
    {
        return lcs(str1.size() - 1, str2.size() - 1);
    }

    int lcs(int i1, int i2) override
    {
        return dp[i1][i2];
    }

private:

    std::string str1;
    std::string str2;
    vvi         dp;
    
    void CalcLcs()
    {
        for (int i = 0; i < str1.size(); ++i)
            dp[i][0] = 0;
        for (int i = 0; i < str2.size(); ++i)
            dp[0][i] = 0;

        for (int i = 1; i < str1.size(); ++i)
        {
            for (int j = 1; j < str2.size(); ++j)
            {
                if (str1[i] == str2[j])
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                else
                    dp[i][j] = std::max(dp[i][j - 1], dp[i - 1][j]);
            }
        }
    }
};

//class LcsReccursion : public ILcs
//{
//public:
//    LcsReccursion(const std::string& str1, const std::string& str2)
//        : str1 {str1}
//        , str2 {str2}
//        , dp {vvi(str1.size(), std::vector<int>(str2.size(), nil))}
//    {}
//
//    int lcs() override
//    {
//        return lcs(str1.size() - 1, str2.size() - 1);
//    }
//
//    int lcs(int i1, int i2) override
//    {
//        if (dp[i1][i2] != nil)
//            return dp[i1][i2];
//
//        if (i1 == 0 || i2 == 0)
//        {
//            if (i1 == 0 && i2 == 0) return dp[i1][i2] = (str1[i1] == str2[i2]);
//            else if (i1 == 0)       return dp[i1][i2] = std::max(lcs(i1, i2 - 1), (str1[i1] == str2[i2] ? 1 : 0));
//            else                    return dp[i1][i2] = std::max(lcs(i1 - 1, i2), (str1[i1] == str2[i2] ? 1 : 0));
//        }
//
//        dp[i1][i2] = std::max(lcs(i1 - 1, i2), lcs(i1, i2 - 1))
//            + (str1[i1] == str2[i2]);
//        return dp[i1][i2];
//    }
//
//private:
//
//    std::string str1;
//    std::string str2;
//    vvi         dp;
//};

void solve()
{
    using namespace std;

    int n;
    cin >> n;

    string s1, s2;

    for (int i = 0; i < n; ++i)
    {
        cin >> s1 >> s2;
        LcsLoop lcs {s1, s2};
        //LcsReccursion lcs {s1, s2};
        cout << lcs.lcs() << endl;
    }
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 6836
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,t,a,h,hm,res=1;
  cin>>n>>t>>a>>hm;
  a*=1000,t*=1000;
  cerr<<abs(t-6*hm-a)<<endl;
  for(int i=2;i<=n;++i){
    cin>>h;
    if(abs(t-6*h-a)<abs(t-6*hm-a))hm=h,res=i;
    cerr<<abs(t-6*h-a)<<endl;
  }
  cout<<res;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int d[10000000], n, hhS, mmS, ssS, hhG, mmG, ssG;

int main() {
  while(1){
    cin>>n;
    if(n==0) break;
    REP(i,0,24*60*60+2) d[i] = 0;
    REP(i,0,n){
      scanf("%d:%d:%d %d:%d:%d", &hhS, &mmS, &ssS, &hhG, &mmG, &ssG);
      d[hhS*(60*60) + mmS*60 + ssS]++;
      d[hhG*(60*60) + mmG*60 + ssG]--;
      //test
      //cout<<"hhS "<<hhS<<", mmS "<<mmS<<", ssS "<<ssS<<endl;
    }
    int ans = 0;
    REP(i,1,24*60*60+2){
      d[i] += d[i-1];
      ans = max(ans, d[i]);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3460
n,k=map(int,input().split())
s=[]
for i in range(n):
  s.append(0)


for i in range(k):
  d=int(input())
 
  List=list(map(int,input().split()))
  for i in range(d):
    s[List[i]-1]=1
print(n-sum(s))


Measured memory_bytes: 9096
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 200005
#define ll long long
#define mod 1000000007
int fac[N],inv[N],n,m,ans;
int C(int n,int m){if(m>n||n<0||m<0)return 0;return (ll)fac[n]*inv[n-m]%mod*inv[m]%mod;}
int q_pow(int x,int n){int ret=1;for(;n;n>>=1,x=(ll)x*x%mod)if(n&1)ret=(ll)ret*x%mod;return ret;}
int main()
{
	scanf("%d%d",&n,&m);fac[0]=1;
	for(int i=1;i<=n+m;i++)fac[i]=(ll)i*fac[i-1]%mod;inv[n+m]=q_pow(fac[n+m],mod-2);
	for(int i=n+m;i;i--)inv[i-1]=(ll)i*inv[i]%mod;
	for(int i=0,f1=0,f2=0,now=2;i<n+m;i++)
	{
		now=now*500000004ll%mod;
		f1=(f1+(ll)C(i-1,n-1)*now)%mod,f2=(f2+(ll)C(i-1,m-1)*now)%mod;
		printf("%lld\n",((f2+(1-f1-f2)*500000004ll)%mod+mod)%mod);
	}
}

Measured memory_bytes: 3712
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int,Int>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

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


int main() {
    int a,b;
    string op;
    int ans = 0;
    cin >> a >> op >> b;

    if(op[0]=='+'){
        ans = a+b;
    }else{
        ans = a-b;
    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n, a = map(int, input().split())
l = list(map(int, input().split()))

t = 50*n+1
dp = [[0]*t for _ in range(n+1)]

for i in range(n):
  x = l[i]
  for j in reversed(range(n+1)):
    for k in range(t):
      if dp[j][k] != 0:
        dp[j+1][k+x] += dp[j][k]
  dp[0][x] += 1

ans = 0
for i in range(n):
  ans += dp[i][a*(i+1)]

print(ans)

Measured memory_bytes: 42476
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int result = 0;
		for(int i = 500;i<=x;x-=500) 
			result+=1000;
		for(int j = 5;j<=x;x-=5) 
			result+=5;
		
		System.out.println(result);
	}

}


Measured memory_bytes: 22100
import scala.io.StdIn.readInt
import scala.collection.immutable.SortedMap

object Main {
  def main(args:Array[String]) = {
    val prices = SortedMap(2->380,3->550,5->850,10->1520,12->1870,15->2244)
    val dp = new Array[Int](51)
    for(i<-0 to 50 if i!=1) {
      for( (w,p) <- prices if i+w<=50) {
        if( dp(i+w)==0 || dp(i) + p < dp(i+w) ) {
          dp(i+w) = dp(i) + p
        }
      }
    }
    var n = 0
    while({n=readInt;n}!=0) {
      println(dp(n/100))
    }
  }
}

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

int main(){
  int n;
  int ans = 0;
  int buf = 0, tmp = 0;
  int mx = -1;
  cin >> n;
  vector<vector<int> > a(3, vector<int>(n));
  rep(i,2,0){
    rep(j,n,0) cin >> a[i][j];
  }
  rep(i,n,0){
    rep(j,i+1,0) buf += a[0][j];
    rep(k,n,i) tmp += a[1][k];
    if(buf + tmp > mx) mx = buf + tmp;
    buf = 0;
    tmp = 0;
  }
  cout << mx << endl;
  return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        x: usize,
        y: usize,
        z: usize
    }
    println!("{} {} {}", z, x, y);
}


Measured memory_bytes: 4352
import java.util.*;
import java.io.*;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = (int) 1e9 + 7;
	static int inf = (int) 1e8;
	static int[] col;
	static int n, m, k;
	static ArrayList<Integer>[] ad;
	static int[][][] memo;
	static ArrayList<Integer> h;
	static char[][] grid;
	static int[] a;
	static boolean f;
	static int offest = 30;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		long n = sc.nextLong();
		int ans = 0;

		ArrayList<Integer> a = new ArrayList<>();
		for (int i = 2; i <= n / i; i++) {
			if (n % i == 0) {
				int p = 0;
				while (n % i == 0) {
					n /= i;
					p++;
				}
				a.add(p);
			}
		}
		if (n > 1)
			ans++;
		for (int i = 0; i < a.size(); i++) {
			int v = a.get(i);
			int lo = 1;
			int hi = 1000;
			int ad = 0;
			while (lo <= hi) {
				int mid = lo + hi >> 1;
				int x = mid * (mid + 1) / 2;
				if (x <= v) {
					ad = mid;
					lo = mid + 1;
				} else {
					hi = mid - 1;
				}
			}
			ans += ad;
		}
		System.out.println(ans);
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 32916
##main#######################################

arr = list(map(int,list(input().split())))

h1=arr[0]
m1=arr[1]
h2=arr[2]
m2=arr[3]
k=arr[4]

h1=h1*60 + m1
h2=h2*60 + m2

last=h2-k

#ans=int(oki/k)*k
#print(str(int(last/60)) + ':' + str(last%60))
if last<=h1:
	print(0)
else:
	print(last - h1)

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

int main(){
	int a[4];
	char c;
	for(int i = 0; i < 4; i++){
		cin >> c;
		a[i] = c - '0';
	}
	for(int i = 0; i < (1 << 3); i++)
	{
		int ans;
		char op[3];
		ans = a[0];
		for(int j = 0; j < 3; j++){
			if((i & (1 << j)) == 0){
				ans += a[j + 1];
				op[j] = '+';
			} else {
				ans -= a[j + 1];
				op[j] = '-';
			}
		}
		if(ans == 7) {
			for(int j = 0; j < 3; j++)
			{
				cout << a[j];
				cout << op[j];
			}
			cout << a[3];
			cout << "=7";
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var k = int.Parse(line[1]);
            var s = int.Parse(line[2]);
            if (n == 0 && k == 0 && s == 0) break;
            var ans = getAns(n, k, s);
            Console.WriteLine(ans);
        }
    }
    static int getAns(int n, int k, int s)
    {
        var ans = 0;
        var imax = 1 << n;
        for (int i = 0; i < imax; i++)
            if (countbits(i) == k)
            {
                var sum = 0;
                for (int j = 0; j < n; j++)
                    if (((i >> j) & 1) == 1) sum += j + 1;
                if (sum == s) ans++;
            }
        return ans;
    }
    static int countbits(int bits)
    {
        bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
        bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
        bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
        bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
        return ((bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff));
    }
}



Measured memory_bytes: 13876
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string a, b ;
    int i, l ;
    cin >> a ;
    b = a ;
    l = b.size() ;
    for(i=0;i<l/2;i++)
        swap(b[i],b[l-i-1]) ;
    for(i=0;i<l;i++)
    {
        if(b[i]=='b')
            b[i] = 'd' ;
        else
        {
            if(b[i]=='d')
                b[i] = 'b' ;
            else
            {
                if(b[i]=='p')
                    b[i] = 'q' ;
                else
                    b[i] = 'p' ;    
            }    
        }                
    }
    if(a==b)
        cout << "Yes" << endl ;
    else
        cout << "No" << endl ;
    //system("PAUSE");
    return 0 ;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a.at(i);
    for (int i=0; i<n; i++) {
        if (a.at(i) % 2 == 0 && a.at(i) % 3 != 0 && a.at(i) % 5 != 0) {
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))

a=[0]*N
a[0]=L[0]
a[1]=abs(L[0]-L[1])

if N > 2:
	a[2]=min(a[1]+abs(L[2]-L[1]), abs(L[2]-L[0]))

for i in range (3, N):
	a[i] = min(a[i-1]+abs(L[i]-L[i-1]), a[i-2]+abs(L[i]-L[i-2]))

print(a[N-1])

Measured memory_bytes: 13780
/*
     “You just can’t beat the person who won’t give up.”
                                                            */
#include <bits/stdc++.h>
#define ll long long
#define oo 0x3f3f3f3f3f3f3f3fLL
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
const int maxn=2e5+5;
const  double EPS = 1e-9;
const int mod = 1e9+7;

inline void File()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
ll sum(ll i) {
  return ((i * (i + 1)) / 2);
}
int main()
{
    ios_base::sync_with_stdio(0);
    File();
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
      ans += i * sum(n / i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3552
from collections import deque


if __name__ == "__main__":
    operation_num = int(input())
    double_linked_list: deque = deque()

    for _ in range(operation_num):
        operation = input()

        if ("deleteFirst" == operation):
            double_linked_list.popleft()
        elif ("deleteLast" == operation):
            double_linked_list.pop()
        else:
            command, num = operation.split(" ")
            if ("insert" == command):
                double_linked_list.appendleft(num)
            else:
                try:
                    double_linked_list.remove(num)
                except ValueError:
                    pass

    print(" ".join(double_linked_list))



Measured memory_bytes: 69736
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

K = int(input())
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
print(s[K-1])

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979
#define TAU (2.0*PI)
#define N 1000000

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i,j,cnt[123],t;
	double x[123],y[123],cs,sn,mx;
	fill(cnt,cnt+123,0);
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> x[i] >> y[i];
	}
	for(i=0; i<N; ++i){
		cs = cos(TAU*i/N);
		sn = sin(TAU*i/N);
		mx = -INFLL;
		for(j=0; j<n; ++j){
			if(mx < (cs*x[j]+sn*y[j])){
				t = j;
				mx = (cs*x[j]+sn*y[j]);
			}
		}
		++cnt[t];
	}
	for(i=0; i<n; ++i){
		printf("%.10lf\n",((double)(cnt[i])/N));
	}
	return 0;
}



Measured memory_bytes: 896