akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abl/tasks/abl_c

#include <atcoder/all>

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N, M;
  cin >> N >> M;

  dsu d(N);

  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    --a, --b;
    d.merge(a, b);
  }

  ll group_ct = d.groups().size();
  ll res = group_ct - 1;

  cout << res << "\n";
}


Measured memory_bytes: 8920
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <ctime>
#include <complex>

#define enp 	printf("**Entry Point**\n")
#define A		first
#define B		second
#define MP		make_pair

using namespace std;

typedef long long ll;

const int INF = 0x6fffffff;
const int MINF = 0x80000000;
const ll mod = 100003;
const int cons = 100001;
const double pi = 3.141592653589793;



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

	string st;
	for (int i = 0; i < s.length(); i++)
	{
		st.push_back(s[i]);

		while (st.size() > 1)
		{
			if (st[st.size() - 2] == 'S' && st[st.size() - 1] == 'T')
			{
				st.pop_back();
				st.pop_back();
			}
			else break;
		}
	}

	printf("%d\n", st.length());

	return 0;
}

Measured memory_bytes: 1152
n, k = gets().split(' ').map(&:to_i)
s = gets().strip.split('').map(&:to_i)


spl = [0]
s.each_with_index{|si, i|
	next if i == 0
	if s[i - 1] != si
		spl.push(i)
	end
}
spl.push(s.length)

mx = 0
spl.each_with_index{|spli, i|
	if i == 0 && s[0] == 0
		j = i + k * 2
	else
		next if s[spli] == 0
		j = i + k * 2 + 1
	end
	j = spl.length - 1 if j >= spl.length

	mx = spl[j] - spli if mx < spl[j] - spli
}

puts mx


Measured memory_bytes: 8572
s = input().split("T")
x,y = map(int,input().split())
xmove = []
ymove = []
for i in range(len(s)):
    if i % 2 == 1:
        ymove.append(s[i].count("F"))
    else:
        xmove.append(s[i].count("F"))
#リストで持つdpだとTLEしたのでメモ化再帰で書く

def solve(l,cor):
    dp = {0}
    for c in l:
        dp = {c+i for i in dp}|{i-c for i in dp}
    return cor in dp

if solve(xmove[1:],x-xmove[0]) and solve(ymove,y):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 66012
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<queue>
#define mem(x) memset(x,0,sizeof(x)) 
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi=acos(-1); 
const double eps=1e-6;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<char,char> pcc;
const ll p=1e9+7;
//int gcd(int a,int b)
//{
//	return b==0?a:gcd(b,a%b);
//}
ll qpow(ll x,ll q,ll p)
{
    ll ans=1;
    while(q)
    {
        if(q&1)
        ans=(ans*x)%p;
        x=(x*x)%p;
        q>>=1;
    }
    return ans%p; 
} 
ll f[100005];
int main()
{
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	for(ll i=k;i>=1;i--)
	{
		ll c=k/i;
		f[i]=qpow(c,n,p);
		for(int j=i*2;j<=k;j+=i)
		f[i]=(f[i]-f[j]+p)%p;
		ans+=f[i]*i;
		//cout<<f[i]<<endl;
		ans%=p;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4400
/* Everything happens for a reason.
Be patient, things will be at their rightful place.
It was meant to happen this way, accept it.
And now decide what you can do about it.
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ip pair<ll,ll>
#define vii vector<ll>
#define vpp vector<ip>
#define vdd vector<ld>
#define vb vector<bool>
#define pi  pair<ll,ip>
#define sc(x) scanf("%lli",&x)
#define c(x) cin >> x
#define fo(i,k,n) for( int i=k;i<n;i++)
#define hu 200010
#define pq priotity_queue<ll>
#define pqs priority_queue<ll,vii,greater<ll>>
#define ppq priority_queue<ip,vpp,greater<ip>>
#define INF INT_MAX
#define ff first
#define ss second
using namespace std;
const ll M = 1000000000+7;
//Grid Movement
ll dx[] = {-1, 0, 1, 0};
ll dy[] = {0, -1, 0, 1};

ld Pi= acos(-1);

ll lcm(ll a,ll b)
{
    return (a*b)/(__gcd(a,b));
}

ll mex(ll x, ll y) 
{ 
	ll res = 1;	  
	x = x % M; 
	if (x == 0) return 0; 
	while (y > 0) 
	{ 
		if (y & 1) 
		res = (res*x) % M; 
		y = y>>1; 
		x = (x*x) % M; 
	} 
	return res; 
} 

bool comp(ll comp1,ll comp2)
{
    return comp1>comp2;
}

void yes()
{
    printf("YES\n");
}

void no()
{
    printf("NO\n");
}

ll inv(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
 
    if (m == 1)
      return 0;
 
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
 
    if (x < 0)
       x += m0;
 
    return x;
}

void sieve(ll n)
{
    vii primes(n+1);
    vb is_prime(n+1);
	is_prime.resize(n+1);
	primes.resize(n+1);
 
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i<=n; i++)
	{
	    if(is_prime[i])
	    {
	    	primes.pb(i);
	        for (int j = i*i; j<=n; j+=i)
	            is_prime[j] = false;
	    }
	}
}

void solve()
{
    string s;
    cin >> s;
    if(s[s.length()-1]=='s')s+="es";
    else s+="s";
    cout<<s;
}

int main()
{
//	ios_base::sync_with_stdio(0); cin.tie(0);
    ll t=1;
 //   sc(t);
    while(t--) solve();
}





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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n + 1);
    for (int a, b; cin >> a >> b; graph[a].emplace_back(b)) {
        graph[b].emplace_back(a);
    }
    vector<int> result = {1};
    vector<bool> visited(n + 1);
    function<void(int)> dfs = [&](int node) {
        visited[node] = true;
        while (true) {
            bool flag = true;
            for (int i : graph[node]) {
                if (!visited[i]) {
                    flag = false;
                    visited[i] = true;
                    node = i;
                    result.emplace_back(node);
                    break;
                }
            }
            if (flag) {
                break;
            }
        }
    };
    dfs(1);
    reverse(begin(result), end(result));
    dfs(1);
    cout << result.size() << '\n';
    for (auto it = result.rbegin(); it != result.rend(); it++) {
        cout << *it << ' ';
    }
    return 0;
}

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



void sort(int n, int* a){
	for(int i=0; i<n; i++){
		for(int j=i; j<n; j++){
			if(a[j] < a[i]){
				int tmp = a[j];
				a[j] = a[i];
				a[i] = tmp;
			}
		}
	}

	for(int i=0; i<n; i++){
		if(i == n-1)
			cout << a[i] << endl;
		else
			cout << a[i] << " ";
	}
}


int main(){
	int n = 3;
	int a[n];

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

	sort(n, a);
}


Measured memory_bytes: 3124
N = int(input())
S = list(input())
S = [int(s) for s in S]

first_presence = [-1] * 10
last_presence = [-1] * 10

for i, s in enumerate(S):
    if first_presence[s] == -1:
        first_presence[s] = i
    last_presence[s] = i

ans = 0
for k1 in range(10):
    for k3 in range(10):
        i1 = first_presence[k1]
        i3 = last_presence[k3]

        if (i1 < 0) or (i3 < 0):
            continue
        if i1 >= i3:
            continue
        presence = set()
        for s in range(i1 + 1, i3):
            presence.add(S[s])

        ans += len(presence)

print(ans)


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

int main()
{
    int n;
    string S;

    cin >> n;
    cin >> S;

    for (int i = 0; i < n; i++){
        if (S[i] == 'x' && S[i + 1] == 'x'){
            cout << i + 1 << endl;
            return (0);
        }
    }
    cout << n << endl;
    return (0);
}



Measured memory_bytes: 3344
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
void Debug(auto a);
 
 
signed main(){
    int n;
    cin >> n;
    vec(a,100010);
    vec(b,100010);
    vec(c,100010);
    vec(d,100010);
    REP(i,n){
        int t;
        if(i%2==0){
            cin >> t;
            a[t]++;
            c[t]++;
        }
        else{
            cin >> t;
            b[t]++;
            d[t]++;
        }
    }
    Sort(c);
    Sort(d);
    Reverse(c);
    Reverse(d);
    REP(i,100010){
        int a_max = -1;
        int b_max = -2;
        if(a[i] == c[0]){
            a_max = a[i];
        }
        if(b[i] == d[0]){
            b_max = b[i];
        }
        if(a_max == b_max){
            if(d[1]>= c[1]){
                d[0] = d[1];
            }
            else{
                c[0] = c[1];
            }
        }
    }
    cout << n - (d[0] + c[0]) << endl;
 
 
    return 0;
}

Measured memory_bytes: 3328
from sys import stdin
import sys

n = stdin.readline().rstrip().split()
a = stdin.readline().rstrip().split()

if '0' in a:
    print(0)
    sys.exit()

total = 1
for i in a:
    total = total*int(i)

    if(total > 1000000000000000000):
        print(-1)
        sys.exit()

print(total)

Measured memory_bytes: 19232
/*
 * 
 * Author : yash1402_
 * 
*/

#include <bits/stdc++.h>
 
using namespace std;

typedef long long int lli;
typedef vector<lli> vlli;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pair<lli,lli>> vplli;
typedef pair<lli,lli> plli;

#define rep(_I,_A,_B) for(lli _I=_A;_I<_B;_I++)

#define opv(_VAR) cout << #_VAR << ":" << _VAR << "\n";
#define opvec(_VEC) cout << #_VEC << ":"; for(auto _ELE:_VEC) cout << _ELE << " "; cout<<"\n";
 
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define B begin()
#define E end()
#define A assign
#define S size()

#define ipa(_VEC) for(auto &_ITER:_VEC) cin>>_ITER;
#define all(_VEC) _VEC.B,_VEC.E

void solve(){
	lli temp;
	cin >> temp;
	
	if(temp >= 30) cout << "Yes\n";
	else cout << "No\n";
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	lli t=1;
	//cin>>t;
	rep(tt,1,t+1){
		solve();
	}
}



Measured memory_bytes: 3612
import bisect
N, Q = [int(x) for x in input().split()]
S = str(input())

ac_list = []
for (idx, (s1, s2)) in enumerate(zip(S[:-1], S[1:])):
  if s1 == 'A' and s2 == 'C':
    ac_list.append(idx+1)

for _ in range(Q):
  l, r = [int(x) for x in input().split()]
  index_l = bisect.bisect_left(ac_list, l)
  index_r = bisect.bisect_left(ac_list, r)
  print(index_r - index_l)



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

constexpr int inf = 1e9;

int main() {
    int n, m;
    while(cin >> n >> m, n) {
        vector<vector<int>> land(n, vector<int>(n, inf)), sea(n, vector<int>(n, inf));
        for(int i = 0; i < n; ++i) {
            land[i][i] = sea[i][i] = 0;
        }
        for(int i = 0; i < m; ++i) {
            int x, y, t; char sl;
            cin >> x >> y >> t >> sl;
            auto& d = (sl == 'L' ? land : sea);
            d[x - 1][y - 1] = d[y - 1][x - 1] = min(t, d[y - 1][x - 1]);
        }
        for(int k = 0; k < n; ++k) {
            for(int i = 0; i < n; ++i) {
                for(int j = 0; j < n; ++j) {
                    land[i][j] = min(land[i][j], land[i][k] + land[k][j]);
                    sea[i][j] = min(sea[i][j], sea[i][k] + sea[k][j]);
                }
            }
        }

        int r; cin >> r;
        vector<int> z(r);
        for(int i = 0; i < r; ++i) {
            cin >> z[i]; z[i]--;
        }

        vector<int> dp(n, inf);
        dp[z[0]] = 0;
        for(int i = 1; i < r; ++i) {
            vector<int> nxt(n, inf);
            for(int from = 0; from < n; ++from) { // ship from
                if(dp[from] == inf) continue;
                nxt[from] = min(nxt[from], dp[from] + land[z[i - 1]][z[i]]); // not use
                for(int to = 0; to < n; ++to) { // ship to
                    nxt[to] = min(nxt[to], dp[from] + land[z[i - 1]][from] + sea[from][to] + land[to][z[i]]);
                }
            }
            dp = move(nxt);
        }

        cout << *min_element(begin(dp), end(dp)) << endl;
    }
}



Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int n;
  cin >> n;
  vector<P> p(n);
  rep(i, n) cin >> p[i].second >> p[i].first;
  sort(ALL(p));
  ll t = 0;
  bool ok = true;
  rep(i, n) {
    t += p[i].second;
    if (t > p[i].first) ok = false;
  }
  if (ok) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}
long long power(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = pow(m, n / 2);
        return t * t;
    } else {
        return pow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k) {
    ll denomi = 1;
    for (int i = n; i > n - k; i--) {
        denomi *= i;
        denomi %= mod;
    }
    ll numera = 1;
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}
// struct SegmentTree {
//     vector<int> ar;
//     ll size = 1;
//     SegmentTree(int n) {
//         ar.resize(4 * n - 1, INF);
//         while (size < n) {
//             size *= 2;
//         }
//     }
//     void update(ll idx, ll x) {
//         ll k = size + idx;
//         ar[k] = x;
//         while (k != 1) {
//             k /= 2;
//             ar[k] = min(ar[k * 2], ar[k * 2 + 1]);
//         }
//     }
//     ll find(ll s, ll t){
//     }
// }
signed main() {
    ll n, k;
    cin >> n >> k;
    cout << nCkmod(k, n) << endl;
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a=in();
    string s=in<string>();
    if(a>=3200){
        print(s);
    }else{
        print("red");
    }
    return 0;
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	cout << ((s[2]==s[3] and s[4]==s[5]) ? "Yes":"No") << endl;




}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100000

int getDepth(int);
int getSibling(int);
int getHeight(int);

struct nibunki {
  int parent;
  int left;
  int right;
};

struct nibunki array[MAX];
int height[MAX];

int main(){

  int n, i, id, degree, left, right, root;

  scanf("%d", &n);

  for( i=0; i<n; i++){
    array[i].parent = array[i].left = array[i].right = -1;
  }

  for( i=0; i<n; i++){
    scanf("%d %d %d", &id, &left, &right);
    array[id].left = left;
    array[id].right = right;

    if( left != -1 ) array[left].parent = id;
    if( right != -1 ) array[right].parent = id;
  }

  for( i=0; i<n; i++){
    if( array[i].parent == -1 ) root = i;
  }

  getHeight(root);

  for( i=0; i<n; i++){
    printf("node %d: parent = %d, ", i, array[i].parent);

    printf("sibling = %d, ", getSibling(i));

    degree = 0;
    if( array[i].left != -1 ) degree++;
    if( array[i].right != -1 ) degree++;

    printf("degree = %d, ", degree);

    printf("depth = %d, ", getDepth(i));

    printf("height = %d, ", height[i]);

    if( array[i].parent == -1 ) printf("root");
    else if( array[i].left == -1 && array[i].right == -1 ) printf("leaf");
    else printf("internal node");

    printf("\n");
  }

  return 0;
}

int getDepth(int u){
  int d=0;

  while( array[u].parent != -1 ){
    u = array[u].parent;
    d++;
  }

  return d;
}

int getSibling(int u){
  int parent;

  parent = array[u].parent;

  if( parent == -1 ) return -1;

  if( array[parent].left != u && array[parent].left != -1 ) return array[parent].left;

  if( array[parent].right != u && array[parent].right != -1 ) return array[parent].right;

  return -1;
}

int getHeight(int u){
  int h1 = 0, h2 = 0;

  if( array[u].left != -1 ) h1 = getHeight(array[u].left) + 1;

  if( array[u].right != -1 ) h2 = getHeight(array[u].right) + 1;

  return height[u] = ( h1 > h2 ? h1 : h2 );
}

Measured memory_bytes: 608
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    s=chomp(readline())
    ans=0
    for i in 3:n
        if s[i-2:i]=="ABC"
            ans+=1
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 170540
/*
❤️❤️❤️I_love_QMsh❤️❤️❤️
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

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

using namespace std;
using namespace __gnu_pbds; // gp_hash_table<int, int> table;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // <int> .find_by_order(int) .order_of_key(int)

template<typename T> bool smin(T &a, const T &b) { bool ret = b < a; return a = (ret ? b : a), ret; }
template<typename T> bool smax(T &a, const T &b) { bool ret = a < b; return a = (ret ? b : a), ret; }

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

mt19937 rnd;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<bool> dis(10);
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    dis[x] = 1;
  }
  for (int t = n; ; t++) {
    int x = t;
    bool ok = 1;
    while (x > 0) {
      ok &= !dis[x % 10];
      x /= 10;
    }
    if (ok) {
      return cout << t, 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

string s, t;

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  string s, t;
  cin >> s >> t;
  cout << (t + s);

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 256
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    
    for i in range(H):
        for j in range(W):
            if i==0 or j==0:                 
                print("#", end="")
            elif  i==H-1 or j==W-1:
                print("#", end="")
            else:
                print(".", end="")
        print()
    
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

int main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    map<string, int> mp;
    for (int i = 1; i <= k; i++) {
        for (int j = 0; j < n - i + 1; j++) {
            mp[s.substr(j, i)]++;
        }
    }
    int cnt = 0;
    for (auto x : mp) {
        cnt++;
        if (cnt == k) {
            cout << x.first << endl;
            return 0;
        }
    }
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define pb push_back
#define INF 1000000000000000000
#define PI 3.14159265358979323846
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector<pii> vii;

bool order (pair<pair<string, int>, int> a, pair<pair<string, int>, int> b) {
    if (a.f.f == b.f.f) return a.f.s > b.f.s;
    else return a.f.f < b.f.f;
}

int main()
{
    FAST_IO;

    vector<pair<pair<string, int>, int> > rest;
    int n;
    cin >> n;
    FOR(i, 1, n) {
        string s; int num;
        cin >> s >> num;
        rest.pb({{s,num}, i});
    }

    sort(rest.begin(), rest.end(), order);

    FOR(i, 0, rest.size()-1) cout << rest[i].s << "\n";

    return 0;
}


Measured memory_bytes: 256
# d: 現在のケタ数
# val: 現在の値
# all: ここに格納していく(参照型にしておく)


def rec(d: int, val: int, all):
    all.append(val)

    if d == 10:
        return

    for i in range(-1, 2):
        add = (val % 10) + i
        if add >= 0 and add <= 9:
            rec(d+1, val*10+add, all)


def main():
    K = int(input())
    all = []
    for v in range(1, 10):
        rec(1, v, all)
    all.sort()
    print(all[K-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 76796
import scala.math._
import scala.collection.mutable.ListBuffer

object Main {
  val rt = Runtime.getRuntime()
  val sc = new java.util.Scanner(System.in)
  val nMax = 10000
  val l = Array.ofDim[Short](nMax, 2)
  def main(args: Array[String]) {
    while(true) {
      val n = sc.nextInt()
      if(n == 0) return

      for(i <- 0 until n) {
        l(i)(0) = sc.nextShort()
        l(i)(1) = (sc.nextShort() + sc.nextShort()).toShort
      }
      println(l.take(n).maxBy(_(1)).mkString(" "))
      rt.gc()
    }

  }
}

Measured memory_bytes: 85944
n, nFlips = map(int, input().split())
s = input().rstrip()

segs = []
i = 0
while i < n:
    if s[i] == '0':
        j = i
        while j + 1 < n and s[j + 1] == '0':
            j += 1
        segs.append((i, j))
        i = j + 1
    else:
        i += 1
segs = segs or [(0, n - 1)]

ret = 0
left = 0
for right in range(len(segs)):
    while right - left + 1 > nFlips:
        left += 1
    size = segs[right][1] - segs[left][0] + 1
    size += segs[left][0] - segs[left - 1][1] - 1 if left - 1 >= 0 else segs[left][0]
    size += segs[right + 1][0] - segs[right][1] - 1 if right + 1 < len(segs) else n - segs[right][1] - 1
    # print('(%d, %d) -> %d' % (left, right, size))
    ret = max(ret, size)
print(ret)


Measured memory_bytes: 8316
n = int(input())
t, a = (float(_) for _ in input().split())
h = [float(_) for _ in input().split()]
 
p = 0
ans = 9999999999
for i in range(n):
    at = t - h[i]*0.006
    if(abs(at-a) < ans):
        ans = abs(at-a)
        p = i+1
 
print(p)

Measured memory_bytes: 3060
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+5;

const int mod = 1e9+7;

string s;
long long ans;
long long p2[N];
long long p3[N];

int main(){
    p2[0] = p3[0] = 1;
    for(int i = 1; i < N; i++){
        p2[i] = p2[i - 1] * 2;
        p3[i] = p3[i - 1] * 3;
        p2[i] %= mod;
        p3[i] %= mod;
    }
    int cnt1 = 0;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '1'){
            ans += (p2[cnt1] * p3[s.size() - i - 1]) % mod;
            ans %= mod;
            cnt1++;
        }
    }
    ans += p2[cnt1];
    ans %= mod;
    cout << ans << endl;
}

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

int main(){
  int r, g, b;
  cin >> r >> g >> b;
  if ((r * 100 + g * 10 + b) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define LIM 1000007
#define ll long long
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  while (h--) {
    string s;
    cin >> s;
    cout << s << endl << s << endl;
  }
  return 0;
}


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


#define long long long int

using namespace std;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef pair<int, int> pi;


int main() {
    std::ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    unordered_map<int, vector<int>> v;
    for (int i = 0; i < n; ++i) {
        int key;
        cin >> key;
        v[key].push_back(i);
    }
    for (const auto &p : v) {
        if (p.second.size() > 1) {
            cout << "NO";
            return 0;
        }
    }

    cout << "YES";
    return 0;
}

Measured memory_bytes: 17864
#include<set>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<iostream>

using namespace std;

typedef long long ll;
int mod=1e9+7;
const int maxn=1e5+10;

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

int a[maxn],b[maxn],c[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
    }
    for(int i=2;i<=n;i++)
    {
        scanf("%d",&c[i]);
    }
    int ans=0;
    set<int>s;
    int last=-5;
    for(int i=1;i<=n;i++)
    {
        ans+=b[a[i]];

        if(last==a[i]-1)
            ans+=c[a[i]];
        last=a[i];
    }
    cout<<ans;

    return 0;
}


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

#define MAX_Y 50
#define MAX_X 50

int X, Y;
bool F[MAX_Y][MAX_X];

struct S {
    int ty, tx, ky, kx;
    int t;
    S(int ty, int tx, int ky, int kx, int t) : ty(ty), tx(tx), ky(ky), kx(kx), t(t){} 
};

const int dty[] = {0, 1, 0, -1},
          dtx[] = {1, 0, -1, 0},
          dky[] = {0, -1, 0, 1},
          dkx[] = {-1, 0, 1, 0};

bool used[MAX_Y][MAX_X][MAX_Y][MAX_X];
int bfs(int ty, int tx, int ky, int kx) {
    memset(used, 0, sizeof(used));
    queue<S> q;
    q.push(S(ty, tx, ky, kx, 0));
    while (!q.empty()) {
        S s = q.front(); q.pop();
        if (s.ty == s.ky && s.tx == s.kx) return s.t;
        if (s.t >= 100) break;
        for (int i = 0; i < 4; i++) {
            int nty = s.ty + dty[i],
                ntx = s.tx + dtx[i],
                nky = s.ky + dky[i],
                nkx = s.kx + dkx[i],
                nt  = s.t + 1;
            if (0 <= nty && nty < Y && 0 <= ntx && ntx < X) {
                if (F[nty][ntx]) {
                    nty = s.ty, ntx = s.tx;
                }
            } else {
                nty = s.ty, ntx = s.tx;
            }
            if (0 <= nky && nky < Y && 0 <= nkx && nkx < X) {
                if (F[nky][nkx]) {
                    nky = s.ky, nkx = s.kx;
                }
            } else {
                nky = s.ky, nkx = s.kx;
            }
            if (used[nty][ntx][nky][nkx]) continue;
            q.push(S(nty, ntx, nky, nkx, nt));
            used[nty][ntx][nky][nkx] = true;
        }
    }
    return -1;
}

int main() {
    while (cin >> X >> Y, X || Y) {
        int tx, ty, kx, ky;
        cin >> tx >> ty >> kx >> ky;
        ty--, tx--, ky--, kx--;
        for (int i = 0; i < Y; i++) {
            for (int j = 0; j < X; j++) {
                cin >> F[i][j];
            }
        }
        int t = bfs(ty, tx, ky, kx);
        if (t >= 0) {
            cout << t << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 7536
#include<iostream>
using namespace std;
int main()
{
  int n,m,t,i;
  cin >> n >> m;
  if(n%2==1){
    for(i=1;i<=m;i++)
      cout << i << " " << n-i << endl;
  }else{
    t=n/2;
    for(i=1;i<=t/2&&m>0;i++,m--)
      cout << i << " " << t+1-i << endl;
    for(i=1;i<=(t-1)/2&&m>0;i++,m--)
      cout << t+i << " " << n-i << endl;
  }
  return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long n,sum1,sum2,sum3,sum4,sum5,ans;
char a[100001][200];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		if(a[i][0]=='M')sum1++;
		if(a[i][0]=='A')sum2++;
		if(a[i][0]=='R')sum3++;
		if(a[i][0]=='C')sum4++;
		if(a[i][0]=='H')sum5++;
	}
	ans+=sum1*sum2*sum3;
	ans+=sum1*sum2*sum4;
	ans+=sum1*sum2*sum5;
	ans+=sum1*sum3*sum4;
	ans+=sum1*sum3*sum5;
	ans+=sum1*sum4*sum5;
	ans+=sum2*sum3*sum4;
	ans+=sum2*sum3*sum5;
	ans+=sum2*sum4*sum5;
	ans+=sum3*sum4*sum5;
	cout<<ans;
}

Measured memory_bytes: 19840
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>


using namespace std;
#define MAX 100000

int main(){
    int K;

    cin >> K;

    int gu = 0;
    int ki = 0;
    if (0 == K % 2)
    {
        gu = ki = K / 2;
    }
    else{
        gu = K / 2;
        ki = gu + 1;
    }

    cout << gu * ki;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
unsigned long long A, B, C, T;
int main(void){
	//IO("test.in", "test.out");
	scanf("%llu%llu%llu", &A, &B, &C);
	if(A % C != 0) A = A + C - A % C;
	B = B - B % C;
	if(A <= B) T = (B - A) / C + 1;
	else T = 0;
	printf("%llu\n", T);
}

Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}


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


	int N = getint(), K = getint();

	int A[200200];
	rep(i, N) A[i] = getint();
	ll owa = ll(N) * N;

	rep(p, K) {
		int B[400200] = {};
		rep(i, N) {
			B[max(0, i - A[i])]++;
			B[i + A[i] + 1]--;
		}
		ll kei = B[0];
		A[0] = B[0];
		rep1(i, N - 1) {
			kei +=(A[i] = A[i - 1] + B[i]);
		}
		if (kei == owa) break;
	}

	rep(i, N) cosp(A[i]);

	Would you please return 0;
}

Measured memory_bytes: 6072
#include <stdio.h>

int main(void){
    char c;
    int i;
    int n = 0;
    char S[5];
    /*for(i=0;i<4;i++){
        if(S[i]='+'){
            n++;
        }else if(S[i]=='-'){
            n--;
        }
    }*/
    scanf("%s",S);
    for(i=0;i<4;i++){
        if(S[i]=='+'){
            n=n+1;
        }else if(S[i]=='-'){
            n=n-1;
        }
    }
    // printf("%c\n",S[2]);
    printf("%d\n",n);    
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
  double N, M, d; cin >> N >> M >> d;
  double ans;
  if(d) ans = 2*(N-d)/N/N*(M-1);
  else ans = 1/N*(M-1);
  cout << setprecision(10);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const* argv[])
{
	int x, y;
	for (int i=0; ; i++) {
		std::cin >> x >> y;
		if (x == 0 && y == 0) {
			break;
		} else if (x > y) {
			std::cout << y << " " << x << std::endl;
		} else {
			std::cout << x << " " << y << std::endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3088
declare -r PREPROCESS='
BEGIN {
    t = 0; x = 0; y = 0
}
{
    print ($1 - t) " " ($2 - x) " " ($3 - y)
    t = $1; x = $2; y = $3
}'

read # N
while read dt dx dy; do
    if (( d = dt - ${dx#-} - ${dy#-}, d < 0 || d % 2 )); then
        echo No
        exit
    fi
done < <(awk "${PREPROCESS}")

echo Yes


Measured memory_bytes: 684
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  int a[N];
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  vector<int> kais(N);
  for(int i=0; i<N; i++){
    kais[a[i]]++;
  }
  sort(kais.begin(),kais.end());
  reverse(kais.begin(),kais.end());
  int sum = 0;
  for(int i=0; i<K; i++){
    sum += kais[i];
  }
  cout << N-sum << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>s;
    cnt=0;
    rrep(i,1,Size(s)){
        if(s[i]=='E')cnt++;
    }
    ans=cnt;
    rrep(i,1,Size(s)){
        if(s[i]=='E')cnt--;
        if(s[i-1]=='W')cnt++;
        ans=min(ans,cnt);
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 720
#include <stdio.h>

#define N 100
#define X 100
#define INF 0x3f3f3f3f

int main() {
	static int xx[N];
	int n, i, x, a, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &xx[i]);
	ans = INF;
	for (x = 1; x <= X; x++) {
		a = 0;
		for (i = 0; i < n; i++)
			a += (xx[i] - x) * (xx[i] - x);
		if (ans > a)
			ans = a;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
using namespace std;
 
int N, M, X, A[200];
 
int main()
{
	scanf("%d%d%d", &N, &M, &X);
	for (int i = 0; i < M; ++i) scanf("%d", A + i);
 
	int left = 0, right = 0;
	for (int i = 0; i < M; ++i) {
		if (A[i] < X) ++left;
		else ++right;
	}
	printf("%d\n", min(left, right));
 
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pf push_front
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix[i]<<(i!=N-1?' ':'\n');
	return;
}


const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+17; //(+1までok)
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

inline int in(){int x; cin>>x; return x;}

int main(void){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	
	int A,B,C,D;
	cin>>A>>B>>C>>D;
	print(min(A,B)+min(C,D));
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>

using namespace std;

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

    int a[n][2], b[m][2], point[n];

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

    for (int j = 0; j < m; j++) {
        cin >> b[j][0] >> b[j][1];
    }   

    for (int i = 0; i < n; i++) {
        int kyori = abs(a[i][0] - b[0][0]) + abs(a[i][1] - b[0][1]);
        point[i] = 0;
        for (int j = 1; j < m; j++) {
            if (abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1]) < kyori) {
                kyori = abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1]);
                point[i] = j;
            }   
        }   
    }   

    for (int i = 0; i < n; i++) {
        cout << point[i] + 1 << endl;
    }   

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
int main(){
    ll n;
    string s;
    cin>>n;
    while(n>0){
        int a=n%26ll;
        char ch;
        n/=26;
        if(a==0){
            ch='z';
            n--;
            s+=ch;
        }
        else{
            ch='a'+a-1;
            s+=ch;
        }
    }
    reverse(s.begin(),s.end());
    cout<<s<<endl;
    }

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

LL f[MAXN][3];
char opt[2];
int n;

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), f[0][0] = Read(), f[0][1] = f[0][2] = -1LL << 60;
	for (int i = 1; i < n; i ++)
	{
		scanf("%s", opt);
		int x = Read();
		if (opt[0] == '+')
		{
			f[i][2] = f[i - 1][2] + x;
			f[i][1] = max(f[i][2], f[i - 1][1] - x);
			f[i][0] = max(f[i][1], f[i - 1][0] + x);
		}
		else
		{
			f[i][2] = f[i - 1][1] + x;
			f[i][1] = max(f[i][2], max(f[i - 1][0], f[i - 1][2]) - x);
			f[i][0] = max(f[i][1], f[i - 1][1] + x);
		}
	}
	return printf("%lld\n", max(max(f[n - 1][0], f[n - 1][1]), f[n - 1][2])), 0;
}


Measured memory_bytes: 2560
N = int(input())
S = ["*"]*(N+1)
S[1:] = list(input())
Q = int(input())
q1,q2,q3 = [0]*Q,[0]*Q,[0]*Q
for i in range(Q):
    tmp = input().split()
    q1[i],q2[i] = map(int,tmp[:2])
    if q1[i] == 2:
        q3[i] = int(tmp[2])
    else:
        q3[i] = tmp[2]

class BIT:
    def __init__(self, n, init_list):
        self.num = n + 1
        self.tree = [0] * self.num
        for i, e in enumerate(init_list):
            self.update(i, e)

    #a_kにxを加算
    def update(self, k, x):
        k = k + 1
        while k < self.num:
            self.tree[k] += x
            k += (k & (-k))
        return

    def query1(self, r):
        ret = 0
        while r > 0:
            ret += self.tree[r]
            r -= r & (-r)
        return ret

    #通常のスライスと同じ。lは含み、rは含まない
    def query2(self, l, r):
        return self.query1(r) - self.query1(l)

s_pos = [BIT(N+1,[0]*(N+1)) for _ in range(26)]

for i in range(1,N+1):
    s_pos[ord(S[i]) - ord("a")].update(i,1)

alphabets = [chr(ord("a") + i) for i in range(26)]

for i in range(Q):
    if q1[i] == 1:
        s_pos[ord(S[q2[i]]) - ord("a")].update(q2[i],-1)
        S[q2[i]] = q3[i]
        s_pos[ord(q3[i]) - ord("a")].update(q2[i],1)
    else:
        ans = 0
        for c in alphabets:
            if s_pos[ord(c) - ord("a")].query2(q2[i],q3[i]+1) > 0:
                ans += 1
        print(ans)











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

int main(){
  ll n, k, q;
  cin >> n >> k >> q;

  vector<ll> points(n+1, k);
  vector<ll> keep(n+1, 0);
  int a;
  for(int i = 1; i <= q; i++){
    cin >> a;
    keep[a]++;
  }

  for(int i = 1; i <= n; i++){
    points[i] -= (q - keep[i]);
    // cout << points[i];
  }
  // cout << endl;

  for(int i = 1; i <= n; i++){
    if(points[i] <= 0){
      cout << "No" << endl;
    }else{
      cout << "Yes" << endl;
    }
  }


  return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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

	int sum = 0;
	rep(i,n){
		int a;
		cin >> a;
		sum += min(a * 2, (k - a) * 2);
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;


int main(void) {
	int a, p;
	cin >> a >> p;
	cout << (3 * a + p)/2 << endl;
	return 0;
}

Measured memory_bytes: 256