akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll i,j,k,n,s=0,arr[3];
	for(i=0;i<3;i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr+3);
	for(i=1;i<3;i++)
	{
		s=s+abs(arr[i]-arr[i-1]);
	}
	cout<<s;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, k;
#include <cassert>
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

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

  cin >> n >> k;

  FOR(i, 1, k + 1) {
    mint t = c(k - 1, i - 1);
    mint p = c(n - k + 1, i);
    cout << t * p << endl;
  }
}


Measured memory_bytes: 6220
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (n); ++i)

int main() {
  ll n, x, m;
  cin >> n >> x >> m;
  vector<bool> used(m * 2);
  vector<ll> one_cycle;

  int start = 0;
  ll now = x;
  rep(i, 0, n) {
    used[now] = true;
    one_cycle.push_back(now);
    now = now * now % m;
    if (used[now]) {
      rep(j, 0, one_cycle.size()) if (one_cycle[j] == now) {
        start = j;
        break;
      }
      break;
    }
  }

  ll s1 = 0, s2 = 0, loop = one_cycle.size() - start;
  rep(i, 0, start) s1 += one_cycle[i];
  rep(i, start, one_cycle.size()) s2 += one_cycle[i];
  ll ans = s1 + (n - start) / loop * s2;
  rep(i, 0, (n - start) % loop) {
    ans += now;
    now = now * now % m;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3892
#9
N, A, B = map(int, input().split())
sum = 0
ans = 0
for i in range(1, N+1):
    i = str(i)
    for k in range(len(i)):
        sum += int(i[k])
    if A<=sum<=B:
        ans += int(i)
    sum = 0
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(void){
    int a;
    int b;
    scanf("%d %d", &a, &b);
    
    int num[3]={a+b,a-b, a*b};
    int max = num[0];
    int i;

    for(i=0;i<3;i++){
        if(num[i]>=max){
            max=num[i];
        }
    }

    printf("%d\n",max);
    return 0;
}

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

int c[33], s[444][33];
int sco(int t, const vector<int> &v) {
    int r = 0, l = 0, d = v.size();
    for(int i = 0; i < d; i++)
        if(v[i] == t)
            r += s[i][t] - c[t] * (i + 1 - l) * (i - l) / 2, l = i + 1;
    r -= c[t] * (d + 1 - l) * (d - l) / 2;
    return r;
}
int main() {
    int d;
    cin >> d;
    for(int i = 0; i < 26; i++)
        cin >> c[i];
    for(int i = 0; i < d; i++)
        for(int j = 0; j < 26; j++)
            cin >> s[i][j];
    vector<int> ss, tt;
    int M = -1e9;
    for(int a = 10; a < 16; a++) {
        for(int b = 0; b < 4; b++) {
            for(int z = 5; z < 16; z++) {
                int r = 0, l[33] = {};
                ss.clear();
                for(int i = 0; i < d; i++) {
                    auto m = 0.;
                    int t = 0;
                    for(int j = 0; j < 26; j++) {
                        double p = s[i][j];
                        p += c[j] * (i + 1 - l[j]) * .4 * a;
                        for(int k = 1; k < z; k++)
                            if(i + k < d)
                                p -= s[i + k][j] * (z - k) * .05 / z * b;
                        if(p > m)
                            m = p, t = j;
                    }
                    ss.push_back(t);
                    r -= c[t] * (i + 1 - l[t]) * (i - l[t]) / 2;
                    l[t] = i + 1;
                    r += s[i][t];
                }
                for(int j = 0; j < 26; j++)
                    r -= c[j] * (d + 1 - l[j]) * (d - l[j]) / 2;
                if(r > M)
                    M = r, tt.swap(ss);
            }
        }
    }
    random_device rd;
    mt19937 mt(rd());
    uniform_int_distribution<> rc(0, 25), r0(0, d - 1), r2(1, 6);
    uniform_real_distribution<> ru(0, 1);
    int cnt = 0;
    auto ti = clock();
    for(;;) {
        auto T = (clock() - ti) / 1.9 / CLOCKS_PER_SEC;
        if(T > 1)
            break;
        auto U = pow(2e3, 1 - T) * pow(6e2, T);
        for(int cn = 0; cn < 100; cn++, cnt++) {
            auto uu = tt;
            int di;
            if(rc(mt) < 13) {
                int x0 = r0(mt), xc = rc(mt);
                uu[x0] = xc;
                di = sco(tt[x0], uu) + sco(xc, uu) - sco(tt[x0], tt) -
                     sco(xc, tt);
            } else {
                int x2 = r2(mt);
                uniform_int_distribution<> r1(0, d - 1 - x2);
                int x1 = r1(mt);
                x2 += x1;
                swap(uu[x1], uu[x2]);
                di = sco(tt[x1], uu) + sco(tt[x2], uu) - sco(tt[x1], tt) -
                     sco(tt[x2], tt);
            }
            if(ru(mt) <= exp(di / U))
                tt.swap(uu);
        }
    }
    M = 0;
    for(int j = 0; j < 26; j++)
        M += sco(j, tt);
    for(int i : tt)
        cout << i + 1 << '\n';
    cerr << M << endl;
    cerr << cnt << endl;
    return 0;
}


Measured memory_bytes: 4316
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	long long int N,K;
	cin>>N>>K;
	N%=K;
	if(N<=K/2)
		cout<<N<<endl;
	else
		cout<<K-N<<endl;
	
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
n2 = int((M ** 0.5) + 1)
divisor = []
for i in range(1, n2 + 1):
    if M % i == 0:
        divisor.append(i)
        divisor.append(M // i)

#print(divisor)
ans = min(filter(lambda e:e >= N, divisor))
#print(ans)
ans = M // ans
print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include<iostream>
#include<string>

using namespace std;
int sta[8][8];
int a,b;
int dx[]={ 0, 0, 0, 0, 0, 0,-3,-2,-1, 1, 2, 3};
int dy[]={-3,-2,-1, 1, 2, 3, 0, 0, 0, 0, 0, 0};
void bc(int y,int x){

	for(int i=0;i<12;i++){
		if(y+dy[i]>=0&&y+dy[i]<8&&x+dx[i]>=0&&x+dx[i]<8){
			if(sta[y+dy[i]][x+dx[i]]==1){
				sta[y+dy[i]][x+dx[i]]=0;
				bc(y+dy[i],x+dx[i]);
			}
		}
	}

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

	int n;
	string inp;

	cin>>n;
	
	for(int i=1;i<=n;i++){
		
		for(int j=0;j<8;j++){
			cin>>inp;
			for(int k=0;k<8;k++){
				sta[j][k]=inp[k]-'0';
			}
		}
		cin>>a;
		cin>>b;
		sta[b-1][a-1]=0;
		bc(b-1,a-1);
		cout<<"Data "<<i<<":"<<endl;
		for(int j=0;j<8;j++){
			for(int k=0;k<8;k++){
				cout<<sta[j][k];
			}
			cout<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1208
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

int powM(int x, int n){
    if(n == 0){
        return 1;
    }
    if(n % 2 == 0){
        return powM(x * x % MOD, n / 2);
    }
    return powM(x, n-1) * x % MOD;
}

int factM(int n){
    static vector<int> t = {1};

    if((int)t.size() > n){
        return t[n];
    }

    for(int i = t.size(); i <= n; i++){
        t.push_back(t[i-1] * i % MOD);
    }
    return t[n];
}

class Combination{
    private:
        vector<int> t;

    public:
        Combination(int n): t(n+1){
            t[n] = powM(factM(n), MOD-2);

            for(int i = n-1; i >= 0; i--){
                t[i] = t[i+1] * (i+1) % MOD;
            }
        }

        int comb(int n, int k){
            if(k == 0){
                return 1;
            }
            if(n < k || n <= 0 || k < 0){
                return 0;
            }
            return factM(n) * t[k] % MOD * t[n-k] % MOD;
        }

        int getInv(int n){
            return t[n];
        }
};

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

    int b, w;
    cin >> b >> w;

    Combination c(b + w);
    int pb = 1;
    int pbw = 1;
    for(int i = 1; i <= b + w; i++){
        int ans = (pb - pbw * powM(2, MOD - 2) % MOD + MOD) % MOD;
        cout << ans * powM(powM(2, MOD - 2), i - 1) % MOD << endl;

        pb = (2 * pb % MOD + MOD - c.comb(i - 1, b - 1)) % MOD;
        pbw = (2 * pbw % MOD + MOD - c.comb(i - 1, b - 1)) % MOD;
        pbw = (pbw + MOD - c.comb(i - 1, i - w)) % MOD;
    }

    return 0;
}


Measured memory_bytes: 5488
#include<iostream>
using namespace std;
int d[100005][2];
bool good[35];

long long int check(int n){
	int i,j,k;
	int a;
	long long int s=0;
	bool b=true;
	for(i=0;i<n;i++){
		a=d[i][0];
		b=true;
		for(j=0;j<30;j++){
			if(a<=0)break;
			if(a%2!=0 && !good[j]){
				b=false;
				break;
			}
			a/=2;
		}
		if(b)s+=d[i][1];
	}
	return s;
}

int main(){
	int n,m;
	long long int i,j,k;
	long long int s=0;
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>d[i][0]>>d[i][1];
	}
	for(i=1,j=0;i<=m;i*=2,j++){
		good[j]=true;
	}
	for(;j>=0;j--){
		if((m&(1<<j))==0){
			good[j]=false;
			continue;
		}
		good[j]=false;
		k=check(n);
		//cout<<k<<endl;
		good[j]=true;
		if(s<k)s=k;
	}
	k=check(n);
	if(s<k)s=k;
	cout<<s<<endl;
	return 0;
}
		
	


Measured memory_bytes: 1152
N, K = map(int, input().split())
List = list(map(int, input().split()))

ans = [0]
for i in range(min(N, K)+1):
    for j in range(min(N, K)-i+1):
        if j==0:
            temp = List[:i]
        else:
            temp = List[:i]+List[-j:]
        for k in range(min(i+j, K-(i+j))+1):
            ans.append(sum(sorted(temp)[k:]))
    

print(max(ans))

Measured memory_bytes: 4884
#include<stdio.h>
 
int main(){
 while(1){
  int a,b;
  char op;
  scanf("%d %c %d", &a, &op, &b);
  if(op == '?'){break;}
  switch(op){
   case '+': printf("%d\n", a+b); break;
   case '-': printf("%d\n", a-b); break;
   case '*': printf("%d\n", a*b); break;
   case '/': printf("%d\n", a/b); break;
   default: break;
  }
 }
return 0;
}

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

int main() {
  string S,P="abcdefghijklmnopqrstuvwxyz";
  cin >> S;
  vector<bool> b(26,1);
  b.push_back(0);
  for(int i=0; i<26; i++){
    if(b.at(26)){
      break;
    }
    for(int j=0; j<S.size(); j++){
      if(P.at(i)==S.at(j)){
        b.at(i)=0;
      }
    }
    if(b.at(i)){
      cout << P.at(i) << endl;
      b.at(26)=1;
    }
  }
  if(b.at(26)){
  }
  else{
    cout << "None" << endl;
  }
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll N; cin >> N;
	ll sumMax = 0;
	ll tmax = 0;
	repe(i, 0, N) {
		ll sum = 0;
		ll t = i;
		while (t != 0) {
			t /= 2;
			sum++;
		}

		if (sumMax < sum) {
			sumMax = sum;
			tmax = i;
		}
	}

	cout << tmax << endl;
	return 0;
}

Measured memory_bytes: 256
#ifndef ONLINE_JUDGE
    #include "debug.cpp"
#endif

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ar array



void solve(){
	int n;
	cin >> n;
	vector<int> a(n,0), b(n,0);
	for(int i = 0;i < n; i++){
		cin >> a[i] >> b[i];
	}	
	bool ans = 0;
	for(int i = 0;i + 2 < n; i++){
		bool curr = 1;
		for(int ii =i;ii<i+3;ii++){
			if(a[ii]!=b[ii]) curr=0;
		}
		if(curr){
			ans = 1;
		}
	}
	if(ans) cout << "Yes\n";
	else cout << "No\n";
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int TC = 1;
    while(TC--)
        solve();

    return 0;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x,y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x,y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define d4(x,y,z,w)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z << " | "<< #w << "--> " << w <<endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=1e9+7;
const long long maxn=2*1e5+10;
const long long inf=99999999999;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRand(ll l, ll r){ uniform_int_distribution<ll> uid(l, r); return uid(rng); }
 
ll power(ll x, ll y){  
	ll p=mode, res=1;
    x = x % p;
    while (y > 0) {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}  

vector<ll> adj[maxn];

void solve(){
	
	ll n,m;
	cin>>n>>m;
	vector<ll> v(n+1);
	for (int i=1;i<=n;i++) cin>>v[i];
	for (int i=1;i<=m;i++){
		ll a,b;
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}

	ll ans=0;
	for (int i=1;i<=n;i++){
		bool ok=true;
		for (auto j:adj[i]){
			ok&=(v[i]>v[j]);
		}
		ans+=ok;
	}
	cout<<ans<<endl;
	
	
	return;
}
 
int main(){ 
    
    #ifndef ONLINE_JUDGE
		//freopen("input.txt", "r", stdin);
    #endif
    srand(time(0)); 
    
    ios::sync_with_stdio(0);
    cin.tie(0);
 	
	//T{ solve(); }
	solve();
	
	return 0;
}

Measured memory_bytes: 12212
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
#include <complex>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
const D EPS = (1e-10);    // 許容誤差。問題によって変える
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// 内積　dot(a,b) = |a||b|cosθ
D dot(P a, P b) {
  return (conj(a)*b).X;
}
// 外積　cross(a,b) = |a||b|sinθ
D cross(P a, P b) {
  // return (conj(a)*b).Y;
  return (a.X*b.Y-a.Y*b.X);
}

bool is_parallel(P a1, P a2, P b1, P b2) {
  return EQ(cross(a1-a2, b1-b2), 0.0);
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    double x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
    
    if (is_parallel(P(x1, y1), P(x2, y2), P(x3, y3), P(x4, y4))) {
      std::cout << "YES" << std::endl;
    }else {
      std::cout << "NO" << std::endl;
    }
  }

  
  return 0;
}

Measured memory_bytes: 1224
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> w;
  for (int i = 0; i < n; i++) {
    int tmp;
    std::cin >> tmp;
    w.push_back(tmp);
  }
  std::vector<int> sum;
  int total = 0;
  for (int x : w) {
    total += x;
    sum.push_back(total);
  }
  int result = INT_MAX;
  for (int s : sum) {
    result = std::min(result, abs(total-s*2));
  }
  std::cout << result << '\n';

  return 0;
}


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

const int MAX_N = 220000;
long long int n;
long long int c[MAX_N];
std::vector<long long int> edge[MAX_N];
int ancestor[MAX_N];
int treeSize[MAX_N];
std::vector<int> children[MAX_N];
long long int ans[MAX_N];
int noAncector[MAX_N];

long long int pickTwoCount(const long long int& nodeNum)
{
  return nodeNum * (nodeNum - 1) / 2 + nodeNum;
}

void dfs(const int& x, const int& last = -1)
{
  if (ancestor[c[x]] != -1)
  {
    children[ancestor[c[x]]].push_back(x);
  }

  int preAncestor = ancestor[c[x]];
  ancestor[c[x]] = x;
  
  for (const auto& to : edge[x])
  {
    if (to == last) continue;
    dfs(to, x);
    treeSize[x] += treeSize[to];
    long long int tmp = treeSize[to];
    for (const auto& child : children[x])
    {
      tmp -= treeSize[child];
    }
    ans[c[x]] -= pickTwoCount(tmp);
    children[x].clear();
  }
  if (preAncestor == -1)
  {
    noAncector[c[x]] -= treeSize[x];
  }
  ancestor[c[x]] = preAncestor;
}

int main()
{
  std::cin >> n;
  for (int i = 0; i < n; ++i)
  {
    std::cin >> c[i];
    --c[i];
  }
  for (int i = 0; i < n - 1; ++i)
  {
    int u, v;
    std::cin >> u >> v;
    --u; 
    --v;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  std::fill(ancestor, ancestor + MAX_N, -1);
  std::fill(ans, ans + n, pickTwoCount(n));
  std::fill(treeSize, treeSize + MAX_N, 1);
  std::fill(noAncector, noAncector + MAX_N, n);

  dfs(0);

  for (int i = 0; i < n; ++i)
  {
    ans[i] -= pickTwoCount(noAncector[i]);
    std::cout << ans[i] << std::endl;
  }

  return 0;
}

Measured memory_bytes: 50680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e+6

int main()
{
  int N, M;
  cin >> N >> M;
  vector<vector<int>> graph(3 * N);
  for (int i = 0; i < M; i++)
  {
    int u, v;
    cin >> u >> v;
    u--, v--;
    graph.at(u).push_back(N + v);
    graph.at(N + u).push_back(2 * N + v);
    graph.at(2 * N + u).push_back(v);
  }
  int S, T;
  cin >> S >> T;
  S--;
  T--;

  int min_cnt[3 * N];
  for (int i = 0; i < 3 * N; i++)
  {
    min_cnt[i] = INF;
  }

  queue<int> que;
  que.push(S);
  min_cnt[S] = 0;

  while (que.size())
  {
    int now = que.front();
    que.pop();

    if (now == T)
      break;

    for (auto next : graph.at(now))
    {
      if (min_cnt[next] != INF)
        continue;
      que.push(next);
      min_cnt[next] = min_cnt[now] + 1;
    }
  }

  cout << (min_cnt[T] != INF ? min_cnt[T] / 3 : -1) << endl;
}

Measured memory_bytes: 17792
str = input().split()
if int(str[0]) > int(str[1]):
    a = int(str[0])
    if int(str[0])-1 > int(str[1]):
        b = int(str[0])-1
    else:
        b = int(str[1])
else:
    a = int(str[1])
    if int(str[1])-1 > int(str[0]):
        b = int(str[1])-1
    else:
        b = int(str[0])

c = a + b
print(c)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  unsigned long long int a,b;
  while(cin>>a>>b)
  cout<<__gcd(a,b)<<" "<<(a*b)/__gcd(a,b)<<endl;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define re register
#define int long long
using namespace std;
int n,m,k;
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0'){
	t=(t<<3)+(t<<1)+v-48;
	v=getchar();}
	return t;
}
signed main(){
n=read();
m=read();
k=read();
if(n>m)swap(n,m);
if(m>k)swap(m,k);
if(n>m)swap(n,m);
if(n==k){
	puts("No");
}
else if(n==m||m==k){
	puts("Yes");
}
else puts("No");
}

Measured memory_bytes: 256
n=int(input())
a= [list(map(int, input().split())) for i in range(n)]

# 奇数の時
if n%2==1:
    # 下限
    a.sort()
    l=a[n//2][0]

    a.sort(key=lambda x:x[1])

    r=a[n//2][1]
    print(r-l+1)

else:
    a.sort()
    l=a[n//2-1][0]+a[n//2][0]
    a.sort(key=lambda x:x[1])
    r=a[n//2-1][1]+a[n//2][1]
    print(r-l+1)

Measured memory_bytes: 112592
#include<stdio.h>
#define k 10000

int main()
{
  int C[k+1];
  int i,j,n;

  scanf("%d",&n);

  int A[n+1];
  int B[n+1];


  for(i=0; i<=k; i++){
    C[i] = 0;
  }
  
  for(i=0; i<n; i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }
  
  for(i=1; i<=k; i++){
    C[i] = C[i] + C[i-1];
  }
  
  for(j=n; j>0; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
  for(i=1; i<=n-1; i++){
    printf("%d ",B[i]);
  }
  
  printf("%d\n",B[i]);
  
  return 0;
}



Measured memory_bytes: 18260
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();

		long min = a * (n - 1) + b;
		long max = b * (n - 1) + a;

		long ans = 0;

		if (a == b || n == 2) {
			ans = 1;
		} else if (a > b || n == 1) {
		} else {
			ans = max - min + 1;
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 22100
/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////		
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto i:a)
#define what(A) cout<<#A<<" is "<<A<<endl;
ll dp[3005][3005][2];
void solve()
{
	IN(n);
	vl v;
	FOR(i, 0, n)
	{
		IN(in);
		v.push_back(in);
	}
	FOR(i, 0, n) dp[i][i][0] = v[i];
	FOR(i, 1, n)
	{
		FOR(j, 0, n)
		{
			if (j + i < n)
			{
			//	cout << j << " " <<i+ j<<endl;
				if (v[j + i] + dp[j][j+i-1][1] > v[j] + dp[j + 1][j + i][1])
				{
					dp[j][j + i][0] = v[j + i] + dp[j][j+i-1][1];
					dp[j][j + i][1] = dp[j][j+i-1][0];
				}
				else
				{
					dp[j][j + i][0] = v[j] + dp[j+1][j+i][1];
					dp[j][j + i][1] = dp[j+1][j+i][0];
				}
				//what(dp[j][j+i][0])
					//what(dp[j][j+i][1])
			}
		}
	}
	cout << dp[0][n-1][0] - dp[0][n-1][1];
}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
		ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}

Measured memory_bytes: 85496
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,h,w;
  cin >> w >> h >> a >> b;
  double s=double(w)*double (h)/2.0;
  printf("%lf ",s);
  if (a*2==w && h==2*b) printf("1\n");
  else printf("0\n");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba"){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
    return 0;
}

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

int		main(void)
{
	int A, B;

	cin >> A >> B;
	int ans = 0;

	if (A > B)
	{
		ans += A;
		A--;
	}
	else
	{
		ans += B;
		B--;
	}
	ans += max(A, B);
	cout << ans << endl;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

immutable inf = 10^^9 + 7;

void main() {
    int n;
    scan(n);

    auto f = new int[][](n, 10);
    auto p = new int[][](n, 11);

    foreach (i ; 0 .. n) {
        f[i] = readln.split.to!(int[]);
    }

    foreach (i ; 0 .. n) {
        p[i] = readln.split.to!(int[]);
    }

    long ans = -inf;

    foreach (cmb ; 1 .. (1<<10)) {
        long t;

        foreach (mise ; 0 .. n) {
            int cnt;

            foreach (j ; 0 .. 10) {
                if (f[mise][j] && (cmb & (1<<j))) {
                    cnt++;
                }
            }

            t += p[mise][cnt];
        }

        ans = max(ans, t);
    }

    writeln(ans);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 380
#include<stdio.h>
int main()
{
    int i,j,n,s=0,m,x,p,min,max=0;
    scanf("%d%d", &n,&x);
    int a[n+5];
    for(i=0;i<n;i++)
    {
        scanf("%d", &a[i]);
        s=s+a[i];
        if(a[i]>max)
            max=a[i];
    }
    x=x-s;
    min=max;
    for(i=0;i<n;i++)
    {
        if(a[i]<min)
            min=a[i];
    }
    p=x/min;
    p=p+n;
    printf("%d\n", p);
}


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

int main(){
  int n; cin >> n;
  vector<int> a(n), b(n);
  rep(i, n){
    int x, y; cin >> x >> y;
    a[i] = x + y;
    b[i] = x - y;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  cout << max(abs(a[0] - a[n - 1]), abs(b[0] - b[n - 1])) << endl;
  return 0;
}


Measured memory_bytes: 4840
#include<stdio.h>
int main(void)
{
int a,b,c,d,e;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  
  if(a<=b)
  for(int f=1;f<=a;f=f+1)
  {
  e=e+c;
  }
  else
  {
     for(int f=1;f<=b;f=f+1)
     {
      e=e+c;
      }
     for(int h=b+1;h<=a;h=h+1)
     {
      e=e+d;
     }
  }  
  printf("%d",e);
return 0;
}

Measured memory_bytes: 128
//

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int h,w;

bool onboard(int a,int b){
    if(a<0||a>=h||b<0||b>=w)return false;
    else return true;
}

signed main (){
    cin>>h>>w;
    vector<vector<int>>a(h,vector<int>(w));
    vector<tuple<int,int,int,int>>ans;
    rep(i,0,h)rep(j,0,w)cin>>a[i][j];
    int il=0,jl=0;
    rep(i,0,h){
        if(i&1){
            for(int j=w-1;j>=0;j--){
                if(a[il][jl]&1){
                    a[il][jl]--;
                    a[i][j]++;
                    ans.pb({il+1,jl+1,i+1,j+1});
                }
                il=i;
                jl=j;
            }
        }else{
            rep(j,0,w){
                if(i==0&&j==0)continue;
                if(a[il][jl]&1){
                    a[il][jl]--;
                    a[i][j]++;
                    ans.pb({il+1,jl+1,i+1,j+1});
                }
                il=i;
                jl=j;
            }
        }
    }
    cout<<ans.size()<<nnn;
    for(auto i:ans){
        cout<<get<0>(i)<<spa<<get<1>(i)<<spa<<get<2>(i)<<spa<<get<3>(i)<<nnn;
    }
    return 0;
}

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

int partition(int A[], int left, int right){
  int x = A[right];
  int j = left;
  for ( int i = left; i < right; i++){
    if(A[i] <= x){
      swap(A[i], A[j]);
      j ++ ;
    }
  }
  swap(A[right], A[j]);
  return j;
}

int main(){
  int n;
  cin >> n;
  int A[n+1];
  for ( int i = 0; i < n; i++){
    cin >> A[i];
  }
  int mid = partition(A, 0, n-1);
  for ( int i = 0; i < n; i++){
    if ( i ) cout << " ";
    if ( i == mid){
      cout << "[" << A[i] << "]";
    } else {
      cout << A[i];
    }
  }
  cout << endl;

  return 0;
}


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

int main() {
  long long  N, A[5];
  cin >> N >> A[0] >> A[1] >> A[2] >> A[3] >> A[4];
  long long minnum = 1000000000000001;
  int mini;
  for (int i = 0; i < 5; i++) {
    if (A[i] <= minnum) {
      minnum = A[i];
      mini = i;
    }
  }
  long long cnt;
  if (N % minnum == 0) cnt = N / minnum;
  else cnt = N / minnum + 1;
  cout << cnt + 5 - 1 << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a = 0;
int b = 0;
int cnt = 0;


int main() {
string a;
string b;
string ab;
string ba;
cin >> a >> b;
int newa = stoi(a);
int newb = stoi(b);
  for(int i = 1;i <= newb;i++){
  ab = ab + a;
  }
  for(int j = 1;j <= newa;j++){
  ba = ba + b;
  }
  if(ab <= ba){
    cout << ab << endl;
  }
  else{
    cout << ba <<endl;
  }
}


Measured memory_bytes: 256
import sys


class Person:
    def __init__(self, number):
        self.number = number
        self.total_sales = 0

    def sales(self, price, quantity):
        self.total_sales += price * quantity


while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    persons = []
    for i in range(n):
        num, price, quantity = tuple(map(int, sys.stdin.readline().split(' ')))
        person = filter(lambda x: x.number == num, persons)
        if person:
            person[0].sales(price, quantity)
        else:
            person = Person(num)
            person.sales(price, quantity)
            persons.append(person)
    over_million = filter(lambda x: x.total_sales >= 1000000, persons)
    if not over_million:
        print 'NA'
    else:
        for p in over_million:
            print p.number

Measured memory_bytes: 4604
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
//回答が整数の場合
double ans=0;
//整数値の入力
int n;
cin >> n;
double table;

for (int i = 0; i < n; ++i) {
    cin >> table;
    string tani;
    cin >> tani;
    if(tani=="BTC"){table=table*380000;}
    ans=ans+table;
   // cout << table << endl;
}
//回答
cout << ans << endl;
return 0;
}



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

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int main() {
  string s;
  cin >> s;
  vector<char> ok;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') {
      if (ok.size() != 0)
        ok.pop_back();
    } else {
      ok.push_back(s[i]);
    }
  }
  for (char c : ok) {
    cout << c;
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc119/tasks/abc119_a
// A - Still TBD

package main

import "fmt"

func main() {
	var y, m, d int
	fmt.Scanf("%d/%d/%d", &y, &m, &d)
	if y > 2019 || (y == 2019 && m > 4) {
		fmt.Println("TBD")
	} else {
		fmt.Println("Heisei")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  char a,b;
  cin>>a>>b;
  int f = (b=='H');
  if(a=='D')f=!f;
  if(f)cout<<"H"<<endl;
  else cout<<"D"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef double ld;
#define vll vector<ll>
#define vvll vector< vll >
#define vld vector< ld >
#define vvld vector< vld >
#define pll pair<ll ,ll >
#define vllp vector< pll >
#define F first
#define S second
#define MAX 1000000007
using namespace std;

ll mini(ll a,ll b)
{
    return a<b?a:b;
}
     
ll maxi(ll a,ll b)
{
    return a>b?a:b;
}

int main()
{
    string s,t;
    cin>>s>>t;
    ll l1=s.length(),l2=t.length();
    ll j,i;
    ll dp[l1+1][l2+1]={0};
    
    for (i = 0; i <=l1; ++i)
    {
        for (j=0;j<=l2;++j)
        {
            if(i==0||j==0){dp[i][j]=0;continue;}
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]=maxi(dp[i-1][j-1],dp[i-1][j]);
                dp[i][j]=maxi(dp[i][j],dp[i][j-1]);
            }
        }        
    }
    if(dp[l1][l2]==0){cout<<" "<<endl;}
    else
    {
        string p="";
        i=l1,j=l2;
        while(i>0 && j>0)
        {
            if(s[i-1]==t[j-1])
            {
                p=s[i-1]+p;
                i--;j--;continue;
            }
            if(dp[i-1][j]>dp[i][j-1])
            {
                i--;
            }
            else j--;
        }
        cout<<p<<endl; 
    }
return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll A,B;
    string S;
    cin >> A>>B;
    cout << (A - 1) * (B - 1) << endl;

}


Measured memory_bytes: 256
result = ''
n,m = gets.split(' ').map(&:to_i)
hash = {}
m.times do
  a,b = gets.split(' ').map(&:to_i)
  if hash[a].nil?
    hash[a] = b
  else
    result = -1 if hash[a] != b
  end
end

result = -1 if hash[1] == 0 && n != 1

if result == -1
  puts result
else
  if hash.empty?
    result = '0' if n == 1
    result = '10' if n == 2
    result = '100' if n == 3
  else
    1.upto(n) do |i|
      result << hash[i].to_s unless hash[i].nil?
      result << '0' if hash[i].nil? && i != 1
      result << '1' if hash[i].nil? && i == 1
    end
  end
  puts result.to_i
end


Measured memory_bytes: 1788
S,N,A,K,i,T;
main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d%d",&A,&K);
		while(A%K%(T=A/K+1))A=A/K*K-T+A%K%T;
		S^=T-1;
	}
	puts(S?"Takahashi":"Aoki");
}

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

using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void){
    int n,m;cin>>n>>m;
    vint a(n);vin(a);
    int sum=accumulate(all(a),0);
    sort(rall(a));
    int ans=0;
    rep(i,n){
        if(4*m*a[i]>=sum)ans++;
    }

    if(ans>=m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			String st=in.next();
			int cnt=0;
			boolean judge=false;
			if(st.equals("0000"))
				return;
			for(int i=0;i<4;i++)
			{
				if(st.charAt(0)==st.charAt(i))
					judge=true;
				else
				{
					judge=false;
					break;
				}
			}
			if(judge)
			{
				System.out.println("NA");
				continue;
			}
			for(;;)
			{
				if(st.equals("6174"))
					break;
				String max="";
				String min="";
				++cnt;
				char ch[]=(st+"").toCharArray();
				Arrays.sort(ch);
				
				for(int k=0;k<ch.length;k++)
					min+=ch[k];
				while(min.length()<4)
					min="0"+min;
				
				StringBuilder sb=new StringBuilder(min);
				max=sb.reverse().toString();
				st=(Integer.valueOf(max)-Integer.valueOf(min))+"";
			}
			System.out.println(cnt);
		}
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
ll a[101010];
P res;

int main(){
  cin>>n;
  rep(i,n){
    cin>>a[i];
  }
  sort(a,a+n);
  ll idx=lower_bound(a,a+n,(a[n-1]+1)/2)-a;
  ll d=INF;
  ll h=(a[n-1]+1)/2;
  if(a[idx]!=a[n-1]){
    res=P(a[n-1],a[idx]);
    d=a[idx]-h;
  }
  if(idx>0&&d>h-a[idx-1]){
    res=P(a[n-1],a[idx-1]);
  }
  cout<<res.fi<<" "<<res.se<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a;
	int b;
	int c;
	int d;
	int e;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	if (a > b) {
		cout << b * c + (a - b)*d << "\n";
	}
	else if (a < b) {
		cout << a * c << "\n";
	}
	else if (a == b) {
		cout << a * c << "\n";
	}
	cin >> e;
}

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

int main(){
    int n;
    while(cin >> n, n){
        int x = 10, y = 10, mat[21][21] = {}, a, b;
        for(int i = 0; i < n; i++){
            cin >> a >> b;
            mat[b][a]++;
        }
        
        int m;
        cin >> m;

        char w;
        int d;
        for(int i = 0; i < m; i++){
            int dy = 0, dx = 0;
            cin >> w >> d;
            if(w == 'N')    dy = 1;
            if(w == 'S')    dy = -1;
            if(w == 'E')    dx = 1;
            if(w == 'W')    dx = -1;
            for(int j = 0; j < d; j++){
                x += dx, y += dy;
                if(mat[y][x] == 1)  n--, mat[y][x]--;
            }
        }

        if(n == 0)  cout << "Yes" << endl;
        else        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3060
N = int(input())
S = input()
ans = N
E = [0] * (N + 1)
for i in range(N):
    E[i+1] = E[i] + (S[i] == 'E')
for i in range(N):
    LR = i - E[i] + E[N] - E[i+1]
    if LR < ans: ans = LR
print(ans)

Measured memory_bytes: 15244
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef unsigned long long ull;
#define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a)
#define fordec(a,b,c) for(int a=b, _c=c; a>=_c; --a)
#define forv(a,b) for(auto &a:b)
#define ii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define all(a) begin(a), end(a)
#define reset(f, x) memset(f, x, sizeof(f))
#define sz(x) (int)(x.size())
#define bit(x, i) (x>>(i-1)&1ll)
#define onbit(x, i) (x|(1ll<<(i-1)))
#define offbit(x, i) (x&~(1ll<<(i-1)))
template<class T> void Max(T &x, T y){ return x = (x > y) ? x : y;}
template<class T> void Min(T &x, T y){ return x = (x < y) ? x : y;}

const int N=1e5+5;
int n, f[N][4][4][4],x,y,z;
tuple<int,int,int> trace[N][4][4][4];
string s[N];
char c[N][4][4][4];

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

  cin>>n>>x>>y>>z;
  forinc(i,1,n) cin>>s[i];

  x=min(x,3); y=min(y,3); z=min(z,3);

  auto u=[&](int x){return min(x+1,3);};
  auto v=[&](int x){return x-1;};
  f[0][x][y][z]=1;
  forinc(t,0,n-1){
    forinc(i,0,3){
      forinc(j,0,3){
        forinc(k,0,3){
          if(!f[t][i][j][k]) continue;
          tuple<int,int,int> now=mt(i,j,k);

          if(s[t+1]=="AB") {
            if(i){
              f[t+1][v(i)][u(j)][k]=1;
              trace[t+1][v(i)][u(j)][k]=now;
              c[t+1][v(i)][u(j)][k]='B';
            }
            if(j){
              f[t+1][u(i)][v(j)][k]=1;
              trace[t+1][u(i)][v(j)][k]=now;
              c[t+1][u(i)][v(j)][k]='A';
            }
          }
          else if(s[t+1]=="BC"){
            if(k){
              f[t+1][i][u(j)][v(k)]=1;
              trace[t+1][i][u(j)][v(k)]=now;
              c[t+1][i][u(j)][v(k)]='B';
            }
            if(j){
              f[t+1][i][v(j)][u(k)]=1;
              trace[t+1][(i)][v(j)][u(k)]=now;
              c[t+1][(i)][v(j)][u(k)]='C';
            }
          }
          else{
            if(k){
              f[t+1][u(i)][j][v(k)]=1;
              trace[t+1][u(i)][(j)][v(k)]=now;
              c[t+1][u(i)][j][v(k)]='A';
            }
            if(i){
              f[t+1][v(i)][j][u(k)]=1;
              trace[t+1][v(i)][(j)][u(k)]=now;
              c[t+1][v(i)][j][u(k)]='C';
            }
          }
        }
      }
    }
  }
  tuple<int,int,int> t=mt(-1,-1,-1);
  bool ok=0;
  forinc(i,0,3) forinc(j,0,3) forinc(k,0,3){
    if(f[n][i][j][k]){
      t=mt(i,j,k);
      ok=1;
      break;
    }
  }
  if(!ok) return cout<<"No\n",0;
  vector<char> ans;
  int now=n,i,j,k; tie(i,j,k)=t;
  while(now){
    ans.pb(c[now][i][j][k]);
    int _i,_j,_k;
    tie(_i,_j,_k)=trace[now][i][j][k];
    i=_i, j=_j, k=_k;
    now--;
  }
  reverse(all(ans));
  cout<<"Yes\n";
  forv(v,ans) cout<<v<<'\n';
}


Measured memory_bytes: 113204
#include <bits/stdc++.h>
#define PI 3.14159265359
typedef long long int ll;
using namespace std;



// first end を含む
bool check(string s, ll first, ll end){
    while (first <= end)
    {
        if(s[first] != s[end]) return false;
        first++;
        end--;
    }
    return true;
    
}


int main()
{
    double l;
    cin >> l;
    double ans;
    ans = pow(l, 3) / 27;
    printf("%lf\n", ans);
}

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

int n, i, ans;
pair<int, int> a[200000];

int main () {
	ios_base::sync_with_stdio(0); cin.tie(NULL);

	cin >> n;
	for (i=1; i<=n; i++) {
		cin >> a[i].first;
		a[i].second=i;
	}
	sort (a+1, a+n+1);

	//for all odd places
	for (i=1; i<=n; i+=2) {
		if (i%2!=a[i].second%2) {
			ans++;
		}
	}
	cout << ans;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define y1 Gacho
#define N 20
using namespace std;

string s[N];
int h, w, X[N][N];
int grundy[N][N][N][N];

int dfs(int y1, int y2, int x1, int x2){
  
  if(y2-y1<0||x2-x1<0) return 0;
  
  int &g=grundy[y1][y2][x1][x2];
  
  if(g!=-1) return g;
    
  set<int> S;
  
  for(int i=y1;i<=y2;i++)
    for(int j=x1;j<=x2;j++){
      if(X[i][j]) continue;
      int a=dfs(y1,i-1,x1,j-1);
      int b=dfs(y1,i-1,j+1,x2);
      int c=dfs(i+1,y2,x1,j-1);
      int d=dfs(i+1,y2,j+1,x2);
      S.insert(a^b^c^d);
    }
  
  int cnt=0;
  
  while(S.count(cnt)) cnt++;
  
  return g=cnt;
}

void solve(){

  memset(grundy,-1,sizeof(grundy));
  
  cout<<(dfs(0, h-1, 0, w-1)?"First":"Second")<<endl;
  
}

int main(){

  cin>>h>>w;

  for(int i=0;i<h;i++){
    cin>>s[i];
    for(int j=0;j<w;j++)
      if(s[i][j]=='X') X[i][j]=1;
  }

  solve();
  
  return 0;
}

Measured memory_bytes: 3824
import sys
sys.setrecursionlimit(4100000)
import math
import fractions



'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

複数行2数値
x = []
y = []
for i in range(5):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

'''


S = input()


check = len(S)-1

while(check >= 0):

    if S[check] == "r":
        if S[check-2] == "m":
            remove = S[check-6: check+1]
            if remove == "dreamer":
                check -= 7
            else:
                print("NO")
                sys.exit()


        elif S[check-2] == "s":
            remove = S[check-5: check+1]
            
            if remove == "eraser":
                check -= 6
            else:
                print("NO")
                sys.exit()

        else:
            print("NO")
            sys.exit()

    elif S[check] == "e":
        remove = S[check-4: check+1]
            
        if remove == "erase":
            check -= 5
        else:
            print("NO")
            sys.exit()

    elif S[check] == "m":
        remove = S[check-4: check+1]
            
        if remove == "dream":
            check -= 5
        else:
            print("NO")
            sys.exit()

    else:
        print("NO")
        sys.exit()


print("YES")

Measured memory_bytes: 5332
n,k = map(int,input().split())
v = list(map(int,input().split()))
ma = 0
kaisu = min(n,k)
for a in range(kaisu+1):
    for b in range(kaisu-a+1):
        push = k-(a+b)
        li = v[:a]+v[n-b:]
        li.sort(reverse=True)
        for c in range(push):
            if li:
                if li[-1] < 0:
                    li.pop()
        ma = max(ma,sum(li))
print(ma)

Measured memory_bytes: 3064