akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int N;
int a[200001],b[200001];


int main (){
      cin>>N;
      rep0(i,N) cin>>a[i];
      rep0(i,N) cin>>b[i];
      int maxab=0;
      rep0(i,N) maxab=max(maxab,a[i]);
      rep0(i,N) maxab=max(maxab,b[i]);
      int cnt=0;
      while(maxab>0){
            maxab>>=1;
            cnt++;
      }
      int ans=0;
      for(int k=cnt;k>=0;k--){
            ll hoge = 1ll<<(k+1);
            rep0(i,N) a[i]%=hoge;
            rep0(i,N) b[i]%=hoge;
            sort(b,b+N);
            ll T = 1ll<<k;
            ll piyo=0;
            rep0(i,N){
                  int huga =lower_bound(b,b+N,2*T-a[i])-lower_bound(b,b+N,T-a[i]);
                  int mochi =lower_bound(b,b+N,4*T-a[i])-lower_bound(b,b+N, 3*T-a[i]);
                  piyo+=(huga+mochi);
            }
            int hie=piyo%2;
            ans=2*ans+hie;
      }
      cout<<ans<<endl;

      return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;


const int mod=1000000007;
//const int mod=998244353;


long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

vector<long long int> fact,fact_inverse;
template<typename type>
void tabulate(type n){
    fact.resize(n+1);
    fact_inverse.resize(n+1);
    fact[0]=1;
    fact_inverse[0]=binpow(1, mod-2, mod);
    for (int i=1; i<n+1; i++) {
        fact[i]=fact[i-1]*i;
        fact[i]%=mod;
        fact_inverse[i]=binpow(fact[i], mod-2, mod);
    }
}
template<typename type>
long long int nCk(type n,type k){
    return fact[n]*fact_inverse[n-k]%mod*fact_inverse[k]%mod;
}
template<typename type>
long long int nPk(type n,type k){
    return fact[n]*fact_inverse[n-k]%mod;
}

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,n,m,k,q,x,a,b,c,d,y,l,r;
    tabulate(2e5+100);
    cin >> n >> m >> a >> b;
    a=n-a;
    ll ans=0;
    for(ll i=1; i<=a; i++){
        ans+=nCk(i+b-2,i-1)*nCk(n+m-i-b-1,n-i)%mod;
        ans%=mod;
    }
    cout << ans << el;
    return 0;
}


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

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

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


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

	cout<<(n-1)/2<<endl;

	return 0;
}
	

Measured memory_bytes: 256
#include<cstdio>
const int N=4007,P=924844033;
int f[N][N][2],vis[N];
void inc(int&a,int b){a+=b-P,a+=a>>31&P;}
void dec(int&a,int b){a-=b,a+=a>>31&P;}
int mul(int a,int b){return 1ll*a*b%P;}
int main()
{
    int n,k,x,y=0,ans=0;
    scanf("%d%d",&n,&k),x=(n-1)/k+1,f[0][0][1]=1;
    for(int i=((n-1)%k+1)*2;i;--i) vis[y+=x]=1;
    for(;y<2*n;) vis[y+=x-1]=1;
    for(int i=1;i<=2*n;++i)
	for(int j=0;j<=n;++j)
	{
	    f[i][j][0]=f[i][j][1]=f[i-1][j][1];
	    if(!vis[i-1]&&j) inc(f[i][j][1],f[i-1][j-1][0]);
	}
    for(int i=0,k=1;i<=n;k=mul(k,++i)) ((n-i)&1? dec:inc)(ans,mul(f[2*n][n-i][1],k));
    printf("%d",ans);
}


Measured memory_bytes: 124544
from collections import deque


def main():
    input()  # n
    friendliness = [int(x) for x in input().split()]
    friendliness.sort(reverse=True)
    edges = deque()
    edges.append(friendliness[0])
    ans = 0
    for fri in friendliness[1:]:
        ans += edges.popleft()
        edges.append(fri)
        edges.append(fri)
    print(ans)


if __name__ == '__main__':
    main()


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

unsigned long long a[9];

unsigned calc()
{
	unsigned res = 0;
	for (int i = 0; i < 32; i++){
		unsigned bit = 1u << i;
		unsigned s = 0;
		for (int j = 0; j < 8; j++) s += a[j];
		if ((s ^ a[8]) & bit){
			for (int j = 0; j < 8; j++){
				s -= a[j] & bit;
				a[j] ^= bit;
				s += a[j] & bit;
			}
			res |= 1u << i;
		}
	}
	return res;
}

int main()
{
	int n;
	scanf("%d", &n);
	while (n--){
		for (int i = 0; i < 9; i++) scanf("%llx", a + i);
		printf("%x\n", calc());
	}
}

Measured memory_bytes: 1196
#include <iostream>
using namespace std;
int main(void){
    int x=0,n,max_x=0;
    string s;
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++){
        
        if(s[i]=='I') x++;
        else x--;
        if(max_x<=x)max_x=x;
    }
    cout<<max_x;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define nl cout<<"\n"
#define pb push_back
#define se second
#define fi first
#define pi =3.14159265358979323846264338327950L;
typedef long long int ll;
int mod=1e9+7;
ll n,a,b,c,d;
map<ll,ll> mp;


ll solve(ll x){
	//usleep(100000);
	//cout<<x<<endl;
	ll ans=1e18;;
	if(x<ans/d){
		ans=x*d;
	}
	if(mp[x]>0) return mp[x];
	if(x==0){
		return 0;
	}
	if(x==1){
		return d;
	}
	ans=min(ans,d*(x%3)+b+solve(x/3));
	ans=min(ans,d*(3-x%3)+b+solve((x+2)/3));
	ans=min(ans,d*(5-x%5)+c+solve((x+4)/5));
	ans=min(ans,d*(x%5)+c+solve(x/5));
	ans=min(ans,d*(x%2)+a+solve(x/2));
	ans=min(ans,d*(2-x%2)+a+solve((x+1)/2));
	mp[x]=ans;
	return ans;
}

int main(){
	//~ ios_base :: sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	//~ freopen("input.txt", "r", stdin); 
    //~ freopen("output.txt", "w", stdout); 
	int t;
	cin>>t;
	while(t--){
		mp.clear();
		cin>>n>>a>>b>>c>>d;
		cout<<solve(n)<<endl;
	}
    return 0;
}


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

int main(void) {
  int a, b, r;
  cin >> a >> b;
  if(a == b) r = a + b;
  else if(a > b) r = 2 * a - 1;
  else r = 2 * b - 1;
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 256
// AtCoder Beginner Contest 130 - Problem E: Common Subsequence (https://atcoder.jp/contests/abc130/tasks/abc130_e) 
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAX { 2010 };
const ll MOD { 1000000007 };

// dp[n][m] = # de subsequências comuns de xs[1..n] e ys[1..m]
ll dp[MAX][MAX];

ll solve(int N, int M, const vector<ll>& xs, const vector<ll>& ys)
{
    dp[0][0] = 1;

    for (int i = 1; i <= N; ++i)
        dp[i][0] = 1;

    for (int i = 1; i <= M; ++i)
        dp[0][i] = 1;

    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= M; ++j)
        {
            // Princípio da Inclusão/Exclusão
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
            dp[i][j] = (dp[i][j] - dp[i - 1][j - 1]) % MOD;
            dp[i][j] = (dp[i][j] + MOD) % MOD;

            // Se há a coincidência dos termos, gera-se novas subsequências que adicionam este termo
            if (xs[i] == ys[j])
            {
                dp[i][j] += dp[i - 1][j - 1];
                dp[i][j] %= MOD;
            }

//            if (xs[i - 1] == ys[j])
//            {
 //               dp[i][j] += dp[i][j - 1];
  //              dp[i][j] %= MOD;
   //         }

 //           cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
        }
    }

    return dp[N][M];
}

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

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

    vector<ll> xs(N + 1), ys(M + 1);

    for (int i = 1; i <= N; ++i)
        cin >> xs[i];

    for (int i = 1; i <= M; ++i)
        cin >> ys[i];

    auto ans = solve(N, M, xs, ys);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 31744
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{   
    ll N, H, W; 
    cin >> N >> H >> W;
    cout<<(N-H+1)*(N-W+1)<<endl;

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG //提出時に消す
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
#define INF 1000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

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

  int n;
  cin >> n;
  ll ans = 1;
  double logs = 0;
  bool zeros = false, flag = true;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    ans *= a;
    logs += log10((double)a);
    /*if (ans > 1000000000000000000LL) {
      flag = false;
    }*/
    if (logs > 18) flag = false;
    if (a == 0) {
      zeros = true;
      break;
    }
  }
  if (zeros) cout << 0 << endl;
  else if (!flag) cout << -1 << endl;
  else {
    if (ans > 1000000000000000000LL) cout << -1 << endl;
    else cout << ans << endl;
  }
}

Measured memory_bytes: 3992
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int K,A,B;
    scanf("%d%d%d",&K,&A,&B);
    int i;
    for(i=A;i<=B;i++)
    {
        if(i%K==0)
        {
            printf("OK");
            return 0;
        }
    }
    printf("NG");
    return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int books[1005],m,c,ri,le,mid,ans,sum[205],n;
bool flag=false;

int main(){
    while(1){
        cin >> m >> n;
        if(n==0&&m==0)break;
        for(int i=0;i<n;i++){
                cin >> books[i];
                ri+=books[i];
        }
        mid=ri/2;
        le=0;

        for(int i=0;i<1000;i++){
            for(int j=0;j<m;j++){
                for(;;){
                    if(c==n){
                        flag=true;
                        break;
                    }
                    if(sum[j]+books[c]>mid)break;
                    else sum[j]+=books[c];
                    c++;
                    }
                }

                if(flag==true){
                    ri=mid;
                    mid=ri/2;
                }else{
                    le=mid;
                    mid=(le+ri)/2;
                }
                flag=false;
                c=0;
                for(int o=0;o<n+1;o++)sum[o]=0;
            }
            cout << ri << endl;
            ri=0,le=0,mid=0;
            for(int i=0;i<1000;i++)books[i]=0;
    }

 return 0;
}

Measured memory_bytes: 1164
#include <stack>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	stack<int> a;
	int d;
	
	while(cin>>d){
		if(d==0) {
			cout<<a.top()<<endl;
			a.pop();
		}
			else a.push(d);
	}

	
}

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

int n,a[300500],b[300500];

int main()
{
	cin>>n;
	string x;
	cin>>x;
	for(int i=0;i<n;i++)
	{
	 if(x[i]=='E') a[i+2]++;
	 a[i+1]+=a[i];
	 }
   for(int i=n-1;i>=0;i--)
   {
    if(x[i]=='W') b[i]++;
    b[i+1]+=b[i+2];
	}
	int min=1e8;
   for(int i=1;i<=n;i++)
   {
    int need=0;
    need+=n-i-b[i];
    need+=i-1-a[i];
	if(need<min) min=need;
	}
	cout<<min<<endl;
 return 0;
 }

Measured memory_bytes: 3076
from sys import exit

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


def main():
    n = ii()
    a = li()

    cnt = 1
    for i in a:
        if i == cnt:
            cnt+=1
    if cnt == 1:
        print(-1)
    else:
        print(n-cnt+1)

    
main()


Measured memory_bytes: 26140
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")
}

fn main() {
    let n: usize = read();
    let mut a: Vec<usize> = vec![];

    for _ in 0..n {
        a.push(read());
    }

    a.sort();
    let mut b: Vec<i64> = vec![0; 1_000_001];

    for i in 0..a.len() {
        let ai = a[i];
        if b[ai] == -1 {
            continue;
        }
        if b[ai] == 1 {
            b[ai] = -1;
            continue;
        }

        b[ai] = 1;
        let mut tmp = ai;
        while tmp + ai <= b.len() - 1 {
            tmp += ai;
            b[tmp] = -1;
        }
    }
    // println!("{:?}", b);
    println!("{}", b.iter().filter(|&x| *x == 1).count());
}


Measured memory_bytes: 11304
import sys

for line in sys.stdin:
    n = int(line)
    cnt = 0
    if n <= 36:
        for i in xrange(10):
            for j in xrange(10):
                for k in xrange(10):
                    for l in xrange(10):
                        if i + j + k + l == n:
                            cnt += 1
    print cnt

Measured memory_bytes: 6236
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
const int maxn = 5e5 + 50;
typedef pair<int, int> P;

void solve();
int main()
{
	int t = 1;
//	cin >> t;
	for(int i=0; i<t; i++)
	{
		solve();
		cout << '\n';
	}
	return 0;
}

// type below

void solve()
{
	int a; cin >> a;
	int arr[a + 50];
	unordered_map<int, int> M;
	for(int i=0; i<a; i++)
	{
		cin >> arr[i];
		M[arr[i]] ++;
	}
	int cnt = 0;
	for(int i=0; i<a; i++)
	{
		M[arr[i]] --;
		bool yes = true;
		for(int j=1; j * j <= arr[i]; j++)
		{
			if(arr[i] % j != 0) continue;
			if(M[j] || M[arr[i] / j])
			{
				yes = false;
				break;
			}
		}
		if(yes) cnt ++;
		M[arr[i]] ++;
	}
	cout << cnt << '\n';
}

Measured memory_bytes: 32544
#include <map>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, M, a[200009], b[200009]; map<int, int> d;
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i], d[a[i]]++;
	cin >> M;
	for (int i = 0; i < M; i++) cin >> b[i];
	bool f = true;
	for (int i = 0; i < M; i++) {
		if (!d[b[i]]) f = false;
		else d[b[i]]--;
	}
	cout << (f ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std; 
using ll = long long;
vector<vector<ll>> memo (1e5+5, vector<ll> (4, -1));

ll dp(vector<int> &a, vector<int> &b, vector<int> &c, int i, int p){
	if(i >= a.size())
		return 0;
	if(p < 3 && memo[i][p] != -1)
		return memo[i][p];
	memo[i][p] = 0;
	if(p == 0){
		memo[i][p] = max(memo[i][p], dp(a, b, c, i+1, 1)+b[i]);
		memo[i][p] = max(memo[i][p], dp(a, b, c, i+1, 2)+c[i]);
	}else if (p == 1){
		memo[i][p] = max(memo[i][p], dp(a, b, c, i+1, 0)+a[i]);
		memo[i][p] = max(memo[i][p], dp(a, b, c, i+1, 2)+c[i]);
	}else if(p == 2){
		memo[i][p] = max(memo[i][p], dp(a, b, c, i+1, 1)+b[i]);
		memo[i][p] = max(memo[i][p], dp(a, b, c, i+1, 0)+a[i]);
	}else{
		memo[i][p] = max(memo[i][p], dp(a, b, c, i+1, 1)+b[i]);
		memo[i][p] = max(memo[i][p], dp(a, b, c, i+1, 2)+c[i]);
		memo[i][p] = max(memo[i][p], dp(a, b, c, i+1, 0)+a[i]);
	}
	return memo[i][p];
}

signed main() { 
	cin.tie(0);
	cin.sync_with_stdio();
	int n; 
	cin>>n;
	vector<int> a(n), b(n), c(n);
	for(int i = 0; i < n; i++){
		int aa, bb, cc;
		cin>>aa>>bb>>cc;
		a[i] = aa;
		b[i] = bb;
		c[i] = cc;
	}
	cout<<dp(a, b, c, 0, 10);
}


Measured memory_bytes: 17792
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
int A[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) {
		int a; cin >> a; a--;
		A[a] = i;
	}
	int at = 0, res = 0;
	rep(i, 1, N) {
		if(A[i] < A[i - 1]) {
			MAX(res, i - at);
			at = i;
		}
	}
	MAX(res, N - at);
	cout << N - res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

int main() {
  int n;
  cin >> n;
  
  long ans = 0;
  char c = '0';
  char now;
  for(int i=0; i<n; i++){
    cin >> now;
    if(c!=now){
      ans++;
      c=now;
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int N; ll K; cin >>N >>K;
  vector<int> A(N); rep(i, N){ cin >>A[i]; A[i]--; }
  vector<int> B(N+1, -1);
  B[0] = 0;
  // B[i] := i回テレポーターを使ってたどり着ける町。
  // 0回なら町0、N回以下でループする
  int city = 0;
  int loopcity = 0; // ループが始まる町
  set<int> S;
  S.insert(0);
  for (int i=1; i<=N; i++){
    city = A[city];
    B[i] = city;
    if (S.count(city)){
      loopcity = city; // ここからループが始まっていた
      break;
    }
    S.insert(city);
  }
  // loopcity以降でループする
  // loopcityが格納されたBのindex以前ならループは発生しない
  int loopindex1 = -1, loopindex2 = -1;
  rep(i, N+1) if (B[i] == loopcity){
    if (loopindex1 == -1) loopindex1 = i;
    else loopindex2 = i;
  }
  if (K <= loopindex1){
    cout <<B[K]+1 <<endl; return 0;
  }
  K -= loopindex1;
  int loopnum = loopindex2 - loopindex1;
  // K = 0 ならループが始まる最初の町、以降loopnumごとに最初の町が現れる
  K %= loopnum;
  int res = B[loopindex1 + K] + 1;
  cout <<res <<endl;
}

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

int main(void) {
    std::vector<u_int> vec;

    u_int a;
    while (std::cin >> a) {
        vec.push_back(a);
    }

    std::sort(vec.begin(), vec.end(), std::greater<u_int>());
    for (u_int i = 0; i < 3; ++i) {
        std::cout << vec[i] << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1204
use std::io::Read;
use std::str::*;
fn main() {
    let mut line = String::new();
    drop(std::io::stdin().read_to_string(&mut line));
    let line:Vec<_> = line.split_whitespace().collect();
    let mut line:Vec<_> = line.iter().filter_map(|x|i32::from_str(x).ok()).collect();
    line.sort();
    let line = line;
    print!("{}", if line == [5,5,7] { "YES" } else { "NO" });
}

Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String str = in.readLine();
    if(str.equals("SUN"))
      System.out.println("7");
    else if(str.equals("MON"))
      System.out.println("6");
    else if(str.equals("TUE"))
      System.out.println("5");
    else if(str.equals("WED"))
      System.out.println("4");
    else if(str.equals("THU"))
      System.out.println("3");
    else if(str.equals("FRI"))
      System.out.println("2");
    else if(str.equals("SAT"))
      System.out.println("1");
  }
}

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

#define min(a,b) (a<b?a:b)

int main() {
	int e, x, yy, zzz, ans;
	while(1) {
		cin >> e;
		if(!e) break;
		ans = 1000000;
		for(int i=0;; ++i) {
			zzz = i*i*i;
			if(zzz>e) break;
			for(int j=0;; ++j) {
				yy = j*j;
				if(yy>e-zzz) break;
				x = e-yy-zzz;
				ans = min(ans, x+i+j);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void){
  int w, a, b;
  scanf("%d%d%d", &w, &a, &b);
  
  if(a + w < b) printf("%d\n", b - a - w);
  else if(b + w < a) printf("%d\n", a - b - w);
  else printf("0\n");
  
  return 0;
}

Measured memory_bytes: 128
n = gets.to_i
t, a = gets.split(" ").map{|d|d.to_i}
puts gets.split(" ").each_with_index.map{|d, i|
  [i, (t - d.to_i * 0.006 - a).abs]
}.min{|a,b|
  a[1] <=> b[1]
}[0] + 1

Measured memory_bytes: 1788
import java.util.*
import kotlin.math.*

typealias Num = Int

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}

fun <T> MutableList<T>.removeLast() = this.removeAt(this.lastIndex)

const val mod = 998244353L

fun main() {
	abc000X()
}

fun abc000X() {
	val n = int()
	val t = str()
	val bits = t.count {it=='1'}

	val high = bits+1
	val low = bits-1
	val highd = IntArray(n) {0}
	val lowd = IntArray(n) {0}
	highd[0] = 1
	lowd[0] = 1

	var highv = (t.last()-'0').toLong()
	var lowv = (t.last()-'0').toLong()

	for(i in 1 until t.length) {
		highd[i] = highd[i-1]*2%high
		if(low>0)
			lowd[i] = lowd[i-1]*2%low

		if(t[n-i-1]=='1') {
			highv = (highv+highd[i])%high
			if(low>0)
				lowv = (lowv+lowd[i])%low
		}
	}

	for(i in t.indices.reversed()) {
		val v =
				if(t[n-i-1]=='1') {
					if(low>0)
						(lowv-lowd[i]+low)%low
					else
						-1
				} else {
					(highv+highd[i])%high
				}
		println(if(v==-1L) 0 else f(v)+1)
	}
}

fun f(i:Long):Int = when(i) {
	0L->0
	else->1+f(i%java.lang.Long.bitCount(i))
}


Measured memory_bytes: 58420
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    static double calcArea(double x1, double y1, double x2, double y2, double x3, double y3) {
        double a = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        double b = Math.sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
        double c = Math.sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
        double z = (a + b + c) / 2;

        return Math.sqrt(z * (z - a) * (z - b) * (z - c));
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(",");
        double x1 = Double.parseDouble(s[0]);
        double y1 = Double.parseDouble(s[1]);
        double area = 0;

        s = br.readLine().split(",");
        double befx = Double.parseDouble(s[0]);
        double befy = Double.parseDouble(s[1]);

        String line;
        while ((line = br.readLine()) != null) {
            String[] second = line.split(",");
            double nowx = Double.parseDouble(second[0]);
            double nowy = Double.parseDouble(second[1]);

            area += calcArea(x1, y1, befx, befy, nowx, nowy);

            befx = nowx;
            befy = nowy;
        }

        System.out.printf("%.6f%n", area);
    }
}


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

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)b - *(int*)a;
}

int main(){

  int n,m;
  scanf("%d%d",&n,&m);

  int k;
  int tmp;
  int ans[30][30] = {0};
  for(int i = 0; i < n; ++i){
    scanf("%d",&k);
    for(int j = 0; j < k; ++j){
      scanf("%d",&tmp);
      ans[i][tmp-1] = 1;
    }
  }

  int count = 0;
  for(int i = 0; i < m; ++i){
    int flag = 0;
    for(int j = 0; j < n; ++j){
      if(ans[j][i] == 0) flag = 1;
    }
    if(flag == 0) count ++;
  }

  printf("%d",count);

  return 0;
}


Measured memory_bytes: 1736
#include <iostream>

using namespace std;

typedef struct Stack {
        int array[100];
        int top;

        Stack()
                :top(0)
        {
                for (int i = 0; i < 100; i++) {
                        array[i] = 0;
                }
        }
} Stack;

int main()
{
        Stack stack;
        int car;

        while (cin >> car) {
                if (car) {
                        stack.array[stack.top++] = car;
                } else {
                        cout << stack.array[--stack.top] << endl;
                        stack.array[stack.top] = 0;
                }
        }

        return 0;
}

Measured memory_bytes: 3092
from collections import defaultdict
n=int(input())
mod=10**9+7
d=defaultdict(int)
for i in range(2,n+1):
  c=i
  for j in range(2,c+1):
    if c%j==0:
      cnt=0
      while c%j==0:
        cnt+=1
        c//=j
      d[j]+=cnt
ans=1
for v in d.values():
  ans=(ans*(v+1))%mod
print(ans)

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

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

    vector<long long int> div(n+1, 1);
    for(int i=2; i<=n; i++){
        for (int j=i; j<=n; j+=i){
            div[j] += 1;
        }
    }

    long long int ans = 0;
    for(int i=1; i<=n; i++){
        ans += i * div[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 81324
def bubbleSort(array):
    sortCompleted = False
    while sortCompleted != True:
        sortCompleted = True
        for i in range(len(array)-1):
            if array[i] > array[i+1]:
                array[i], array[i+1] = array[i+1], array[i]
                sortCompleted = False

def getMaxDistance(array):
    maxDistance = 0
    for i in range(len(array)-1):
        distance = abs(array[i] - array[i+1])
        if maxDistance < distance:
            maxDistance = distance
    return maxDistance

def function(K, An): 
    bubbleSort(An)
    An.append(K+An[0])
    maxDistance = getMaxDistance(An)
    minDistance = K - maxDistance
    return str(minDistance)

if __name__ == '__main__':
    K, N = map(int, input().split())
    An = list(map(int,input().split()))
    print(function(K, An))


Measured memory_bytes: 27600
s=input()
N=list(map(int,s))
for p in range(1<<3):
    t = N[0]
    ans = str(t)
    for i in range(1,4):
        if p&1:
            t+=N[i]
            ans+='+'+str(N[i])
        else:
            t-=N[i]
            ans+='-'+str(N[i])
        p>>=1
    if t==7:
        print(ans+'=7')
        exit()

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

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

	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n-i; j++){
			if(y-(10000*i+5000*j) == 1000*(n-i-j)){
				cout << i << " " << j << " " << n-i-j << endl;
				return 0;
			}
				
		}
	}
	cout << "-1 -1 -1" << endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main() {
	int n;
	cin >> n;
	map<string,int> mp;
	rep(i,n){
		string s;
		cin >> s;
		mp[s]++;
	}

	int ma = -1;
	for(auto m : mp) ma = max(ma,m.second);

	vector<string> ans;
	for(auto m : mp) if(m.second == ma) ans.push_back(m.first);

	sort(all(ans));

	for(auto a : ans) cout << a << endl;

	return 0;
}


Measured memory_bytes: 27376
n = int(input())
for i in range(1,n+1):
    if i % 3 == 0:
        print(" "+str(i),end = "")
    else:
        x = i
        while x:
            if x % 10 == 3:
                print(" "+str(i),end = "")
                break
            x //= 10
print()
            


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


void solve(std::vector<long long> A){
    if(A[0] + A[1] + A[2] >= 22){
        cout<<"bust"<<endl;
    }else{
        cout<<"win"<<endl;
    }
}

int main(){
    std::vector<long long> A(3);
    for(int i = 0 ; i < 3 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int l,r,d,cnt=0;
	cin>>l>>r>>d;
	for(int i=l;i<=r;i++){
		if(i%d==0)cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


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

int gcd(int a, int b) {
  if(b == 0) return a;
  else if(b > a) return gcd(b, a);
  else {
    int t = a;
    a = b;
    b = t % b;
    return gcd(a, b);
  }
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int a, b, c;
  cin >> a >> b >> c;
  
  int t = gcd(a, b);
  int lcm = (a*b) / t;
  
  bool ok = false;
  for(int i = a; i <= lcm; i += a) {
    if(i % b == c) ok = true;
  }
  if(ok) {
    cout << "YES" << endl;
    return 0;
  }
  else {
    cout << "NO" << endl;
    return 0;
  }
}

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

#define int long long

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

int N;
int a[100000], b[100000];

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
    }
    int ans = 0;
    for (int i = N - 1; i >= 0; i--) {
        if ((a[i] + ans) % b[i] != 0) {
            ans += b[i] - (a[i] + ans) % b[i];
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    int n;cin>>n;

    int result = 0;
    int i=0;
    for(;result<n;i++){
        result += i;
    }
    int remove = result - n;
    //dump(remove)
    FOR(j,1,i){
        if(j == remove){
            continue;
        }
        cout<< j << endl;
    }

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int partition(int,int);
#define N 100000
int n,A[N];
int main(){
  int i,z;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  z=partition(0,n-1);
  for(i=0;i<n;i++){
    if(i)
      printf(" ");
    if(i==z)
      printf("[%d]",A[i]);
    else if(i!=z)
      printf("%d",A[i]);
  }
  printf("\n");
  return 0;
}
int partition(int p,int r){
  int i,x,y,z;
  x=A[r];
  y=p-1;
  for(i=p;i<r;i++){
    if(A[i]<=x){
      y++;
      z=A[y];
      A[y]=A[i];
      A[i]=z;
    }
  }
  z=A[y+1];
  A[y+1]=A[r];
  A[r]=z;
  return y+1;
}




Measured memory_bytes: 2116
#include <iostream>

using namespace std;

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

	int even = 0;
	int odd = 0;

	for (int i = 1; i <= k; i++)
	{
		if (i % 2== 0)
		{
			even++;
		}
		else
		{
			odd++;
		}
	}

	cout << odd * even << endl;
}

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

#define                 ll            long long
#define                 mx            100005
#define                 read          freopen("in.txt", "r", stdin);
#define                 optimize      ios::sync_with_stdio(0); cin.tie(0);

using namespace std;

map <string, int> m;
map <string, int> :: iterator it;

int main()
{
	// read
	optimize

	string s[mx];

	ll n,ans=0;

	cin >> n;

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

		sort(s[i].begin(), s[i].end());

		m[s[i]]++;
	}

	for(it = m.begin(); it!=m.end(); it++)
	{
		ll x = it->second-1;
		ans += (x*x+x)/2;
	}

	cout << ans << endl;


	return 0;
}

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

import sys
input=sys.stdin.readline

n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=-10**18
for pos in range(n):
    value=0
    points=[]
    s=set()
    for j in range(n):
        s.add(pos)
        pos=p[pos]-1
        value+=c[pos]
        points.append(value)
        if pos in s:
            break
    loop_value=max(0,points[-1])
    l=len(s)
    for j in range(l):
        if j<(k%l):
            ans=max(ans,points[j]+loop_value*(k//l))
        else:
            ans=max(ans,points[j]+loop_value*(k//l-1))
print(ans)

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

#define ll long long
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll mod=1000000007;

using namespace std;

ll n,k,a,b,c;
ll d[101000][4];
int main(){
    ios;
	cin>>n;
	for (ll i=1;i<=n;i++){
		cin>>a>>b>>c;
		if (i==1){
            d[1][1]=a;
            d[1][2]=b;
            d[1][3]=c;
            continue;
		}
        d[i][1]=max(d[i-1][2]+a,d[i-1][3]+a);
        d[i][2]=max(d[i-1][1]+b,d[i-1][3]+b);
        d[i][3]=max(d[i-1][2]+c,d[i-1][1]+c);
	}
    cout<<max({d[n][1],d[n][2],d[n][3]});
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    int sum = 0;
    vector<int> d(N),e(N);

    for (int i = 0; i < N; i++) {
        cin >> d.at(i);
    }

    for (int i = 0; i < N; i++) {
            e.at(i) = d.at(i);
    }

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

        int M = N - 2;

        sum = abs(e.at(M/2) - e.at(N/2));

        cout << sum << endl;

}

Measured memory_bytes: 1024
N = int(input())
R = [list(map(int, input().split())) for n in range(N)]
B = [list(map(int, input().split())) for n in range(N)]

RY = sorted(R, key=lambda x: x[1], reverse=True)
BX = sorted(B, key=lambda x: x[0])

ans = 0

for b in BX:
  for index, r in enumerate(RY):
    if b[0] > r[0] and b[1] > r[1]:
      ans += 1
      RY.pop(index)
      break

print(ans)

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

int main()
{
    ll a,b,x;
    cin >> a >> b >> x;
    ll ans = 0;
    if(a%x == 0) ans = b/x - a/x + 1;
    else ans = b/x - a/x;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N; cin >> N;
    vector<int> a(N);
    double mean = 0;
    rep (i, 0, N) {
        cin >> a[i];
        mean += a[i];
    }
    mean = round(mean / a.size());

    double cost = 0;
    rep (i, 0, N) {
        if (mean != a[i])
            cost += pow(a[i]-mean, 2);
    }

    cout << (long long)cost << endl;
}

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

int main()
{
    int N, A;
    cin >> N >> A;
    int b = N % 500;
    if (b == 0) {
        cout << "Yes" << endl;
    } else if (A < b) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


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

using namespace std;

int main(void) {
	int N; cin >> N;
	vector<long long> A, B, C;
	int val;
	for (int i = 0; i < N; i++) {
		cin >> val;
		A.push_back(val);
	}
	for (int i = 0; i < N; i++) {
		cin >> val;
		B.push_back(val);
	}
	for (int i = 0; i < N; i++) {
		cin >> val;
		C.push_back(val);
	}

	sort(A.begin(), A.end());
	sort(C.begin(), C.end());

	long long res = 0;
	for (int i = 0; i < N; i++) {
		long long low = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
		long long up = C.end() - (upper_bound(C.begin(), C.end(), B[i]));
		res += low * up;
	}
	cout << res << endl;
}

Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;

namespace AtCoderProject
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadInputInt().Take(4).ToArray();
            WriteLine(Min(input[0], input[1]) + Min(input[2], input[3]));
        }

        #region READER
        static IEnumerable<string> ReadInput()
        {
            for (; ; )
            {
                yield return Console.ReadLine();
            }
        }
        static IEnumerable<int> ReadInputInt()
        {
            return ReadInput().Select(s => int.Parse(s));
        }
        #endregion
    }
}


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

vector<int> sum;

int main(){
  int N,K;
  cin >> N >> K;
  sum.resize(N+1,0);
  rep(i,N) {
    int a;
    cin >> a;
    sum[a]++;
  }
  int res = 0;
  sort(sum.begin(),sum.end());
  if (sum.size() - 1 > K) {
    rep (i,sum.size() - (1+K) ){
      res += sum[i+1];
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;
int c[N];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int>q(n);

    f(i,0,n-1){
        cin >> q[i];  
        c[q[i]]++;
    }
    f(i,1,n+1){
        cout << c[i] << "\n";
    }

    return 0;
}
 

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



int main() 
{
  ll N,K; cin>>N>>K;
  vector<pair<ll,ll>> ab(N);
  rep(i,N)
  {
    ll a,b; cin>>a>>b;
    ab.at(i)=pair<ll,ll> (a,b);
  }
  sort(ab.begin(),ab.end());
  ll sum=0;
  for(ll i=0;;i++)
  {
    sum+=ab.at(i).second;
    if(sum>=K)
    {
      cout<<ab.at(i).first<<endl;
      break;
    }  
  }  
  return 0;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    set <int> ms = {a, b, c};
    if(ms.size()==2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	string s, t;
	cin >> s >> t;
	cout << (s + t.back() == t? "Yes": "No") << '\n';
}



Measured memory_bytes: 3620
#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long ll;


int main() {
    string s;
    cin >> s;
    deque<char> deq;
    for (auto x:s)deq.push_back(x);

    int q;
    cin >> q;
    bool rev = false;
    for (int i = 0; i < q; i++) {
        int ope;
        cin >> ope;
        if (ope == 1)rev = !rev;
        else {
            int f;
            char c;
            cin >> f >> c;
            if ((f == 1) == rev) deq.push_back(c);
            else deq.push_front(c);
        }
    }

    string ret;
    for (auto x:deq)ret.push_back(x);
    if (rev)reverse(ret.begin(), ret.end());

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
char s[110][110];
int dp[110][110];

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

ll a[1010101][110];

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	rep(i, n) {
		rep(j, 10) {
			a[i][j] = 0;
		}
	}
	rep(i, n) {
		string res;
		res += s[i];
		int x = stoi(res);
		rep(j, 10) {
			if (j == x)a[i][j]++;
			a[i + 1][j] = a[i][j];
		}
	}
	int ans = 0;
	map<int, int>mp;
	for (int i = 1;i < n-1;++i) {
		string res;
		res += s[i];
		int x = stoi(res);
		rep(j, 10) {
			rep(k, 10) {
				int res = 0;
				if (a[i - 1][j] != 0) {
					if (a[n - 1][k] - a[i][k] != 0) {
						res = j * 100 + x * 10 + k;
						mp[res]++;
					}
				}
			}
		}
	}
	for (auto p : mp) {
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 27008
N = int(input())
H = list(map(int, input().split()))
H.append(10**9+1)
H.reverse()
res = 0
x = [0]*(N+1)
for i in range(N):
    if H[i+1] >= H[i]:
        x[i+1] = x[i]+1

print(max(x))

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

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

    ll ans = 1;
    unordered_map<ll, ll> cnt;
    cnt[-1] = 3;
    for (int i = 0; i < n; i++) {
        ans *= cnt[a[i] - 1];
        ans %= MOD;
        cnt[a[i]]++;
        cnt[a[i] - 1]--;
    }
    cout << ans << endl;
}

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

int main() {
    int N, X;
    cin >> N >> X;
    int m[N];

    int a;  //m[N]の全要素の合計
    for(int i = 0; i < N; i++) {
        cin >> m[i];
        a += m[i];
    }
    
    int b = X - a;  //ドーナツを全種類1個ずつ作った後残るお菓子の素の量
    int c = m[0];   //m[N]で最小の要素の値

    for(int i = 1; i < N; i++) {
        if(m[i] < c) {
            c = m[i];
        }
    }

    int ans = N + b / c;

    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 256