akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) {
        cin >> a[i];
    }
    ll sum1 = 0, res1 = 0;
    REP(i, n) {
        ll tmp = sum1 + a[i];
        if (i % 2 == 1 && tmp <= 0) {
            res1 += abs(1 - tmp);
            sum1 = 1;
        } else if (i % 2 == 0 && tmp >= 0) {
            res1 += abs(-1 - tmp);
            sum1 = -1;
        } else {
            sum1 += a[i];
        }
    }
    ll sum2 = 0, res2 = 0;
    REP(i, n) {
        ll tmp = sum2 + a[i];
        if (i % 2 == 1 && tmp >= 0) {
            res2 += abs(-1 - tmp);
            sum2 = -1;
        } else if (i % 2 == 0 && tmp <= 0) {
            res2 += abs(1 - tmp);
            sum2 = 1;
        } else {
            sum2 += a[i];
        }
    }
    cout << min(res1, res2) << "\n";
    return 0;
}


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

const int MAXN = 105;
int n, m, a[MAXN], f;
bool cmp(int a, int b) {
	return a % 2 < b % 2;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		cin >> a[i], f += a[i] % 2;
	sort(a, a + m, cmp);
	if ((n % 2 == 0 && f == 0) || (n % 2 == 1 && f == 1)) {
		for (int i = 0; i < m; i++)
			cout << a[i] << ' ';
		cout << '\n' << m + 1 - (a[m - 1] == 1) << '\n';
		cout << 1 << ' ';
		for (int i = 0; i < m - (a[m - 1] == 1); i++)
			cout << a[i] - (i == m - 1) << ' ';
		return 0;
	}
	if (n % 2 == 0 && f == 2) {
		for (int i = m - 2; i >= 0; i--)
			swap(a[i], a[i + 1]);
		for (int i = 0; i < m; i++)
			cout << a[i] << ' ';
		cout << '\n' << m - (a[m - 1] == 1) << '\n';
		cout << a[0] + 1 << ' ';
		for (int i = 1; i < m - (a[m - 1] == 1); i++)
			cout << a[i] - (i == m - 1) << ' ';
		return 0;
	}
	cout << "Impossible";
}

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

using namespace std;

long long INF=1e15;

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

    int a,b;
    cin>>a>>b;
    a--;b--;

    cout<<"100 100"<<endl;

    for(int j=0;j<100;j++){
    if(j%2==0){for(int i=0;i<50;i++){
        if(i%2==0){
            if(b>0){
                cout<<"#";
                b--;
            }
            else cout<<".";
        }
        else cout<<".";
    }
    for(int i=0;i<50;i++){
        if(i%2==1){
            if(a>0){
                cout<<".";
                a--;
            }
            else cout<<"#";
        }
        else cout<<"#";
    }}
    else{
        for(int i=0;i<50;i++)cout<<".";
        for(int i=0;i<50;i++)cout<<"#";
    }
    cout<<endl;
    }
}

Measured memory_bytes: 256
<?php
  
$n = trim(fgets(STDIN));
$a = explode(' ', trim(fgets(STDIN)));
 
$e = $o = [];
for($i=0; $i<$n; $i++){
  if ($i%2 ==0) array_push($e, $a[$i]);
  if ($i%2 ==1) array_push($o, $a[$i]);
}
 
$ec = array_count_values($e);
$oc = array_count_values($o);
 
$ek = array_keys($ec, max($ec));
$ok = array_keys($oc, max($oc));
 
$au = array_unique($a);
if (count($au) == 1){
  echo $n/2;
} else if ($ek !== $ok){
  echo $n - max($ec) - max($oc);
} else {
  rsort($ec);
  rsort($oc);
  echo $n - max($ec[0] + $oc[1], $oc[0] + $ec[1]);
}
 
 
?>

Measured memory_bytes: 33140
package main

import "fmt"

func main() {
        var a, b, c int
        fmt.Scan(&a, &b, &c)
        modulos := map[int]struct{}{}
        i := 1
        for true {
                mod := i * a % b
                if mod == c {
                        fmt.Println("YES")
                        return
                }
                if _, visited := modulos[mod]; visited {
                        break
                }
                modulos[mod] = struct{}{}
                i++
        }
        fmt.Println("NO")
        return
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    int a, b, c;
    cin >> a >> b >> c;

    cout << ((21 < a+b+c) ? "bust" : "win") << endl;

    return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T1> bool chmax(T1 &a, const T1 &b) { if (a < b) { a = b; return true; } return false; }
template<class T1> bool chmin(T1 &a, const T1 &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int T1,T2;
	int A1,A2;
	int B1,B2;
	cin>>T1>>T2>>A1>>A2>>B1>>B2;
	int P=(A1-B1)*T1,Q=(A2-B2)*T2;
	if(P>0)P=-P,Q=-Q;
	A1*=T1,A2*=T2,B1*=T1,B2*=T2;

	if(P+Q==0)
	{
		cout<<"infinity"<<endl;
		return 0;
	}
	if(A1+A2<B1+B2)
	{
		swap(A1,B1);
		swap(A2,B2);
	}
	if(P+Q<0)cout<<"0"<<endl;
	else
	{
		/*int T=(-P)/(P+Q);
		T*=2;
		if((-P)%(P+Q)!=0)T++;
		cout<<T<<endl;*/
		int D=A1+A2-B1-B2;
		int T=(B1-A1)/D+1;
		T*=2;
		T--;
		if((B1-A1)%D==0)T--;
		cout<<T<<endl;
	}
	

	return 0;
}


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


void solve(long long a, long long b, long long x){
    if(x > a * a * b / 2) {
        long long xx = a * a * b - x;
        double res = atan2(2 * xx, a * a * a) * 180.0f / 3.1415926535898f;
        printf("%f", res);
    } else {
        double res = atan2(a * b * b, 2 * x) * 180.0f / 3.1415926535898f;
        printf("%f", res);
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long x;
    scanf("%lld",&x);
    solve(a, b, x);
    return 0;
}


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

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

	int b = 0;
	int ans = 0;
	rep(i, n-1) {
		if(a[i] >= a[i+1]) {
			b++;
			ans = max(ans, b);
		}
		else {
			b = 0;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

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

const int INF = 1 << 24;

int main(void){
    int res = 0, n;
    rep(i, 10) cin >> n, res += n;
    cout << res << endl;
 
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
  int N;
  cin >> N;
  int ans=0;
  int cnt=0;
  int temp=0;
  for(int j=1;j<=N;j+=2){
    vector<int> v;
    for(int i=1;i*i<=j;i++){
      if(j%i==0){
        v.push_back(i);
        if(i!=(j/i)) v.push_back(j/i);
      }
    }
    if(v.size()==8){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char x , y;
	int n , m;
	scanf("%c %c",&x,&y);
	n = x - 'A' + 10;
	m = y - 'A' + 10;
	//printf("%d%d\n",n,m);
	if(n>m)
		printf(">");
		if(n<m)
			printf("<");
			if(n==m)
				printf("=");
	return 0;
	}

Measured memory_bytes: 128
// https://atcoder.jp/contests/abc177/tasks/abc177_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    string S, T;
    cin >> S >> T;
    // 最小の差分を記録
    int minv = 1e12;
    REP(i, S.length() - T.length() + 1) {
        int diff = 0;
        REP(j, T.length()) {
            if (S[i + j] != T[j]) {
                diff++;
            }
        }
        minv = min(minv, diff);
    }
    cout << minv << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3644
#include <stdio.h>

class Dice4{
public:
	int number[6];

	void roll(char dst){
		switch(dst){
		case 'E':
			setNumber(number[3],number[1],number[0],number[5],number[4],number[2]);
			break;
		case 'N':
			setNumber(number[1],number[5],number[2],number[3],number[0],number[4]);
			break;
		case 'S':
			setNumber(number[4],number[0],number[2],number[3],number[5],number[1]);
			break;
		case 'W':
			setNumber(number[2],number[1],number[5],number[0],number[4],number[3]);
			break;
		}
	};

	bool isSameDice(int inputed[]){
		char order[25] = "NNNNWNNNWNNNENNNENNNWNNN";
		for(int i = 0; i < 24; i++){
			roll(order[i]);
			for(int j = 0; j < 6; j++){
				if(inputed[j] != number[j])
					break;
				if(j == 5)
					return true;
			}
		}
		return false;
	}

private:
	void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
		number[0] = n0;
		number[1] = n1;
		number[2] = n2;
		number[3] = n3;
		number[4] = n4;
		number[5] = n5;
	}

};

int main(){
	int n,k,j;
	scanf("%d",&n);
	Dice4 array[n];
	for(int i = 0; i < n; i++){
		scanf("%d %d %d %d %d %d",&array[i].number[0],&array[i].number[1],&array[i].number[2],
				&array[i].number[3],&array[i].number[4],&array[i].number[5]);
	}
	for(k = 0; k < n-1; k++){
		for(j = k+1; j < n; j++){
			if(array[k].isSameDice(array[j].number))
				break;
		}
		if(j < n) break;
	}
	if(k == n-1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}


Measured memory_bytes: 2620
import sys

N,K=map(int,input().split())
S=list(input())
MIN=min(S)

def minimum(S):
    T=S+S[::-1]

    ANS=[]

    for i in range(N+1):
        ANS.append(T[i:i+N])

    return min(ANS)

def next(S):
    T=S+S[::-1]
    LIST=[]
    CL=[0]*2*N
    count=0

    for i in range(2*N):
        if T[i]==MIN:
            count+=1

        else:
            count=0

        CL[i]=count

    MAX=max(CL)
    LIST=[]

    for i in range(N-1,2*N):
        if CL[i]==MAX:
            LIST.append(T[i+1-N:i+1])

    return LIST,MAX

def next2(S,x):
    return [MIN]*x+S[x:][::-1]

if K==1:
    print("".join(minimum(S)))

else:
    CAN,MAX=next(S)

    if (MAX<<(K-1))>=N:
        print(MIN*N)
        sys.exit()

    ANS=[]

    for c in CAN:

        ANS.append(next2(c,MAX*((1<<(K-1))-1)))

    print("".join(min(ANS)))

Measured memory_bytes: 192116
def intersection_ll(S0, S1, T0, T1):
    x0, y0 = S0; x1, y1 = S1
    X0, X1 = T0; X1, Y1 = T1
    p = (x1-x0)*(y0-Y0) - (y1-y0)*(x0-X0) # -cross(S0, S1, T0)
    q = (x1-x0)*(Y1-Y0) - (y1-y0)*(X1-X0) # cross(0, S1-S0, T1-T0)
    return (X0 + p*(X1-X0)/float(q), Y0 + p*(Y1-Y0)/float(q))# T0 + p/q*(T1-T0)

n = int(input())
for i in range(n):
    x0, y0, x1, y1, X0, Y0, X1, Y1 = map(int, input().split())
    print("%.08f %.08f" % intersection_ll((x0, y0), (x1, y1), (X0, Y0), (X1, Y1)))

Measured memory_bytes: 7780
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main() {
    ll n,ans=0;
    cin >> n;
    for (ll i=1;i<=n;i*=2){
        ans=i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def partition(ary, p, r):
    x = ary[r]
    i = p - 1
    for j in range(p, r):
        if ary[j] <= x:
            i += 1
            ary[i], ary[j] = ary[j], ary[i]

    ary[i + 1], ary[r] = ary[r], ary[i + 1]

    return i + 1


n = int(input())
ary = [int(_) for _ in input().split()]
q = partition(ary, 0, n - 1)
print(*ary[:q], '[{}]'.format(ary[q]), *ary[q + 1:])



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

const int N = 200000;

vector<int> vc[N+5];

struct SegmentTree{
    long long sumv[N*4+5], addv[N*4+5];
    void upd_add(int L, int R, int K, int o, int l, int r){
        if (L <= l && r <= R){
            addv[o] += K;
            sumv[o] += (long long)K * (r-l+1);
        }
        else {
            int lc = o<<1, rc = o<<1|1, m = (l+r)>>1;
            if (L <= m) upd_add(L, R, K, lc, l, m);
            if (R > m) upd_add(L, R, K, rc, m+1, r);
            sumv[o] = sumv[lc] + sumv[rc] + addv[o] * (r-l+1);
        }
    }
    long long q_sum(int L, int R, int o, int l, int r, long long add){
        if (L <= l && r <= R){
            return sumv[o] + add * (r-l+1);
        }
        else {
            int lc = o<<1, rc = o<<1|1, m = (l+r)>>1;
            long long res = 0;
            if (L <= m) res += q_sum(L, R, lc, l, m, add + addv[o]);
            if (R > m) res += q_sum(L, R, rc, m+1, r, add + addv[o]);
            return res;
        }
    }
} segt;

int main(){
    int n, u, v;
    scanf("%d\n", &n);
    for (int i = 1; i <= n-1; ++i){
        scanf("%d %d", &u, &v);
        if (u > v) swap(u, v);
        vc[v].push_back(u);
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i){
        sort(vc[i].begin(), vc[i].end());
        vc[i].push_back(i);
        for (int j = 0, k = 2 - vc[i].size(); j < vc[i].size(); ++j, ++k){
            if (j == 0) segt.upd_add(1, vc[i][j], k, 1, 1, n);
            else segt.upd_add(vc[i][j-1] + 1, vc[i][j], k, 1, 1, n);
        }
        ans += segt.q_sum(1, i, 1, 1, n, 0);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 23240
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = res * a;
      a = a * a;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  freopen("out.txt","w",stdout);
  #endif
}

int dx[4]={0,-1,1,0};
int dy[4]={1,0,0,-1};
int vis[101][101];
int tm;

int main() 
{ 
    fast_io
    go();
    intt n;cin>>n;
    intt sum=0;
    vector<intt> v(n);
    map<intt,intt> mp;
    for0(i,n)
    {
      cin>>v[i];
      sum+=v[i];
      mp[v[i]]++;
    }
    intt k;cin>>k;
    for0(i,k)
    {
      int a,b;cin>>a>>b;
      auto it=mp.find(a);
      if(it!=mp.end())
      {
        sum-=(a*mp[a]);
        mp[b]+=mp[a];
        sum+=(mp[a]*b);
        mp[a]=0;
        mp.erase(a);
      }
      cout << sum <<"\n";
    }
} 

/*!
    You are under no obligation to be the same person you were a minute ago,
    You have the right to grow !
*/




















Measured memory_bytes: 7940
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   vector<int> a(n);
   set<int> s;
   int ans = 0;;
   f(i,0,n){
      cin >> a[i];
      s.insert(a[i]);
      auto k = s.begin();
      if(*k == a[i]) ans++;
   }
   cout << ans << '\n';
   return 0;
}

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

const int MOD = (int)1e9+7;

int main(){
	int N,M;
	cin >> N >> M;
	vector<bool> a(N+1,true);
	for(int i=0;i<M;i++){
		int x;
		cin >> x;
		a.at(x)=false;
	}

	vector<int> dp(N+1,0);
	dp.at(0)=1;
	for(int i=0;i<N;i++){
		if(i+1<a.size() && a.at(i+1)==true){
			dp.at(i+1)+=dp.at(i);
			dp.at(i+1)%=MOD;
		}
		if(i+2<a.size() && a.at(i+2)==true){
			dp.at(i+2)+=dp.at(i);
			dp.at(i+2)%=MOD;
		}
	}
	cout << dp.at(N) << endl;

	return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    if(n<=999) cout << "ABC" << endl;
    else cout << "ABD" << endl;
    return 0;
}


Measured memory_bytes: 256
import itertools

def check(arr,t):
    for i in arr:
        if i < t:
            return False
    return True

N,M,X = list(map(int,input().split()))
l = []
for _ in range(N):
    l.append(list(map(int,input().split())))
buy_bit = list(itertools.product([0,1], repeat=N))

mi = 990000000
for pattern in buy_bit:
    learned = [0 for _ in range(M)]
    total = 0
    for idx,bit in enumerate(pattern):
        if bit == 1:
            total += l[idx][0]
            for learned_id in range(M):
                learned[learned_id] += l[idx][learned_id+1]
    if total < mi and check(learned,X):
        mi = total
if mi == 990000000:
    print(-1)
else:
    print(mi)

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int k, x;
	cin >> k >> x;
	int n = k - 1;
	vector<int> ans;
	for (int i = x; i <= x + n; i++) {
		ans.push_back(i);
	}
	for (int i = x - n; i < x; i++) {
		ans.push_back(i);
	}
	sort(ans.begin(), ans.end());
	if (k == 1) cout << x << "\n";
	else {
		for (int i = 0; i < ans.size(); i++) {
			cout << ans[i] << " ";
		}
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.io.*;

class Main
{
 public static void main(String[] args) throws IOException
 {
	 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     String str = br.readLine();
     String[] abc = str.split(" ", 0);
     int a = Integer.parseInt(abc[0]);
     int b = Integer.parseInt(abc[1]);
     int c = Integer.parseInt(abc[2]);

     if(a < b){
    	 if (b<c){   	 
         System.out.println(a+" "+b+" "+c);}
    	 else if(a<c){
    		 System.out.println(a+" "+c+" "+b);}
    	 else{
    		 System.out.println(c+" "+a+" "+b);}
    	 }    	 
     else {
    	 if (a<c){   	 
             System.out.println(b+" "+a+" "+c);}
    	 else if(b<c){
    		 System.out.println(b+" "+c+" "+a);}
    	 else{
    		 System.out.println(c+" "+b+" "+a);}
 }
}
}

Measured memory_bytes: 24352
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

MAX = 10 ** 18

# 累積和
accA, accB = [0] * (n + 1), [0] * (m + 1)
accA[1], accB[1] = A[0], B[0]
for i in range(2, n + 1):
    accA[i] = accA[i - 1] + A[i - 1]
for i in range(2, m + 1):
    accB[i] = accB[i - 1] + B[i - 1]
accA.append(MAX)
accB.append(MAX)

from bisect import bisect_left, bisect_right

res = 0
for i in range(n + 1):
    tmp = accA[i]
    idx = bisect_right(accB, k - tmp) - 1
    if tmp + accB[idx] <= k:
        res = max(res, i + idx)
print(res)

Measured memory_bytes: 111300
a,b=map(int,input().split())
h,w=100,100
c=[["."]*w if int(i)<50 else ["#"]*w for i in range(h)]

a-=1
b-=1
plus=True
h1,w1=0,0
while b:
  c[h1][w1]="#"
  b-=1
  if w1!=48:
    w1+=2
  else:
    if h1==48:break
    w1=0
    h1+=2
h2,w2=51,0
while a:
  c[h2][w2]="."
  a-=1
  if w2!=48:
    w2+=2
  else:
    if h2==99:break
    w2=0
    h2+=2
print(h,w)
for ci in c:
  ans=""
  for cc in ci:
    ans+=cc
  print(ans)



Measured memory_bytes: 3188
n, m = gets.chop.split.map(&:to_i)
s = gets.chop.split('')
t = gets.chop.split('')

if s[0] == t[0]

  l = n.lcm(m)

  s_diff = l / n
  t_diff = l / m

  s_arr = []
  t_arr = []

  n.times do |i|
    s_arr << i * s_diff + 1
  end

  m.times do |i|
    t_arr << i * t_diff + 1
  end

  s_is = [0]
  t_is = [0]
  i = 1
  loop do
    next_num = i * t_diff
    if next_num >= n
      break
    else
      s_is << next_num
    end
    i += 1
  end
  i = 1
  loop do
    next_num = i * s_diff
    if next_num >= m
      break
    else
      t_is << next_num
    end
    i += 1
  end

  # p s_is, t_is

  flag = true
  # s_is.each do |s_i|
  #   break unless flag
  #   t_is.each do |t_i|
  #     if s[s_i] != t[t_i]
  #       flag = false
  #       break
  #     end
  #   end
  # end

  s_is.length.times do |i|
    break unless flag
    if s[s_is[i]] != t[t_is[i]]
      flag = false
      break
    end
  end

  if flag
    puts l
  else
    puts '-1'
  end

else
  puts '-1'
end


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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n;
int a[125252];
int b[125252];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",a+i);
  REP(i,n)scanf("%d",b+i);
  ll suma = accumulate(a,a+n,0ll);
  ll sumb = accumulate(b,b+n,0ll);
  if(suma < sumb){
    puts("-1"); return 0;
  }
  vector<ll> src;
  ll snksum = 0;
  int ans = 0;
  REP(i,n){
    ll v = a[i] - b[i];
    if(v==0)continue;
    if(v>0)src.push_back(v);
    if(v<0)snksum += -v, ans++;
  }
  sort(ALL(src));
  while(snksum > 0){
    snksum -= src.back(); src.pop_back(); ans++;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 1660
///
// File:  a.go
// Author: ymiyamoto
//
// Created on Sun Jun  3 21:07:03 2018
//
package main

import (
	"fmt"
	"strconv"
)

var N int

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	fmt.Scan(&N)

	v := 1 << 30
	for i := 1; i < N; i++ {
		var val int
		s := strconv.Itoa(i)
		for j := range s {
			val += int(s[j] - '0')
		}
		s = strconv.Itoa(N - i)
		for j := range s {
			val += int(s[j] - '0')
		}
		v = min(v, val)
	}

	fmt.Println(v)
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


long long floor_sum(long long n, long long m, long long a, long long b) {
    long long ans = 0;
    if (a >= m) {
        ans += (n - 1) * n * (a / m) / 2;
        a %= m;
    }
    if (b >= m) {
        ans += n * (b / m);
        b %= m;
    }

    long long y_max = (a * n + b) / m, x_max = (y_max * m - b);
    if (y_max == 0) return ans;
    ans += (n - (x_max + a - 1) / a) * y_max;
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
    return ans;
}




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

  int t;
  cin>>t;

  rep(i,t){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout << floor_sum(a,b,c,d) << endl;
  }

}


Measured memory_bytes: 3620
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

K=gets.to_i
A,B=get_i
ans=false
A.upto(B) do|x|
    if (x%K).zero?
        ans=true
        break
    end 
end
puts yn_judge(ans,"OK","NG")

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

using namespace std;

bool check()
{
	string s;
	cin >> s;
	if (s[0] != 'A') return false;
	bool f = false;
	for (int i = 2; i + 1 < s.length(); i++) {
		if (s[i] == 'C') {
			f = true;
			s[i] = 'c';
			break;
		}
	}
	if (!f) return false;
	for (int i = 1; i < s.length(); i++) {
		if ('A' <= s[i] && s[i] <= 'Z') return false;
	}
	return true;
}

int main()
{
	if (check()) cout << "AC" << endl;
	else cout << "WA" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main() {
    int n,m;cin>>n>>m;
    int A[n],B[m];
    rep(i,n)cin>>A[i];
    rep(i,m)cin>>B[i];
    vector<int>V1(n-1),V2(m-1);
    rep(i,n-1)V1[i]=A[i+1]-A[i];
    rep(i,m)V2[i]=B[i+1]-B[i];
    int sum1=0,sum2=0;
    rep(i,n-1){
        sum1+=V1[i]%mod*(i+1)%mod*(n-1-i)%mod;
        sum1%=mod;
    }
    rep(i,m-1){
        sum2+=V2[i]%mod*(i+1)%mod*(m-1-i)%mod;
        sum2%=mod;
    }
    cout<<sum1*sum2%mod<<endl;
    
}
        

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


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

//Ctrl+Aを使わない

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import collections

def solve(N: int, K: int, A: "List[int]"):
    a_counter = collections.Counter(A)
    if len(a_counter) <= K:
        print(0)
        return 

    values = sorted(list(a_counter.values()))
    answer = 0
    for i in range(len(a_counter)-K):
        answer += values[i]
    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 43744
using System;
using System.Linq;

class prog{
  static void Main(){
    
    string N = Console.ReadLine();
    int sum = 0;
    foreach(var s in N){
      sum += int.Parse(s.ToString());
    }
    
    int n = int.Parse(N);
    Console.WriteLine(n % sum == 0 ? "Yes" : "No");
    
  }
}

Measured memory_bytes: 11092
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 
int dp[100][4003];
void solve(){
  int n;
  dp[0][0] = 1;
  for(int i = 1; i < 5; i++){
	for(int j = 0; j < 4000; j++){
	  for(int k = 0; k <= 1000; k++){
		  dp[i][j + k] += dp[i - 1][j];  
		}	
	  }  
	}
  while(cin >> n){
	  cout << dp[4][n] << endl;  
	}
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3352
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1000000000;
const ll inf=LONG_LONG_MAX;
const ll ms=(1e5)+5;


int main()
{
    idfc;

    ll ans=0;
    int p=0;
    int v=0;
    string s;
    cin>>s;int pp;
    for(char e:s)
    {
        if(e=='<')
        {
            v++;
            ans+=v;
            pp=v;
            p=0;
        }
        else
        {
            p++;
            v=0;
            ans+=(p-1);
            if(p>pp)ans++;
        }
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n,k, ans = 0; cin>>n>>k;
	vector<int> price(n);
	for(int i=0;i<n;i++) cin>>price[i];
	sort(price.begin(), price.end());
	for(int i=0;i<k;i++) ans += price[i];
	cout<<ans;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int M, K; std::cin >> M >> K;
  if(M == 0) {
    if(K > 0) fin(-1);
    fin("0 0");
  }
  if(M == 1) {
    if(K > 0) fin(-1);
    fin("0 0 1 1");
  }
  if(K >= (1<<M)) fin(-1);
  char sp = ' ';
  if(K == 0) {
    int i = 0;
    for(; i < (1<<M)-1; ++i) std::cout << i << sp << i << sp;
    std::cout << i << sp;
    fin(i);
  }
  std::vector<int> ans;
  std::vector<bool> used(1<<M+1, false);
  for(int i = 0; i < (1<<M); ++i) if(!used[i]){
    ans.push_back(i);
    int j = i^K;
    used[i] = used[j] = true;
  }
  for(int i = 0; i < ans.size(); i += 2) {
    int a = ans[i], b = ans[i+1], c = a^K, d = b^K;
    std::cout << a << sp << c << sp << b << sp << d << sp
              << c << sp << a << sp << d << sp << b;
    if(i+2 == ans.size()) sp = '\n';
    std::cout << sp;
  }
  return 0;
}


Measured memory_bytes: 2300
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>

using namespace std;
//#define int long
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main() 
{
	int N;
	string S;
	cin >> N >> S;
	for (auto i : S)
	{
		char replace = i + N;
		if (replace > 'Z')replace += 'A' - 1 - 'Z';
		cout << replace;
	}
}

Measured memory_bytes: 256
#include <iomanip>
#include <map>
#include <iostream>
using namespace std;
int main() {
    int n, k; cin >> n >> k;
    map<int, int> s;
    for (int i = 1; i <= n; i++) {
        int m = 0;
        int tmp = i;
        while (tmp < k) m++, tmp *= 2;
        s[m]++;
    }
    double ans = 0;
    for (auto x : s) ans += 1.0 / (1<<x.first) * x.second;
    cout << setprecision(12) << ans/n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 3000 + 5;
ld dp[N][N];
ld arr[N];
bool vis[N][N];
int n;

ld solve(int idx, int cnt) {
    if (idx == n)
        if (cnt > idx - cnt)
            return 1;
        else
            return 0;
    if (vis[idx][cnt])
        return dp[idx][cnt];
    vis[idx][cnt] = true;
    return dp[idx][cnt] = arr[idx] * solve(idx + 1, cnt + 1) + (1.0 - arr[idx]) * solve(idx + 1, cnt);
}


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    cout << fixed << setprecision(10) << solve(0, 0);
    return 0;
}


Measured memory_bytes: 150144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DIVERTA2019B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
            var output = 0;

            for (int i = 0; i < input[3] / input[0] + 1; i++)
            {
                for (int j = 0; j < input[3] / input[1] + 1; j++)
                {
                    var sum1 = input[0] * i + input[1] * j;

                    if (sum1 > input[3])
                    {
                        break;
                    }
                    else if (((input[3] - sum1) % input[2]) == 0)
                    {
                        // きっちり数があう
                        output++;
                    }
                }
            }

            Console.WriteLine(output);
        }
    }
}


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

int solve(int m, int x);

int solve(int m, int x) {
    int half = m / 2;
    int a;
    for (int i = 0; i < half; i++) {
        cin >> a;
        if (x < a) {
            return i;
        }
    }
    for (int i = half; i < m; i++) {
        cin >> a;
        if (x < a) {
            return m - i;
        }
    }
    return 0;
}


int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int a[m];
    cout << solve(m, x) << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
x=[]
y=[]
h=[]
for i in range(n):
    xx,yy,hh = map(int,input().split())
    x.append(xx)
    y.append(yy)
    h.append(hh)
max_h = h.index(max(h))
for cx in range(0,101):
    for cy in range(0,101):
        flag = True
        high = h[max_h] + abs(x[max_h]-cx) + abs(y[max_h]-cy)
        for i in range(n):
            if h[i]==0:
                if high-abs(x[i]-cx)-abs(y[i]-cy)>0:
                    flag=False
            else:
                if high != abs(x[i]-cx)+abs(y[i]-cy)+h[i]:
                    flag=False
        if flag:
            print(cx,cy,high)
            exit()


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

using lint = long long;
using ldouble = long double;

void solve() {
    int n, k, s;
    std::cin >> n >> k >> s;

    n -= k;
    while (k--) {
        std::cout << s << " ";
    }

    int x = 1000000000;
    if (s == x) x = 1;

    while (n--) {
        std::cout << x << " ";
    }

    std::cout << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
#include<vector>
int n;
std::vector<int> data;
void proc(){
  auto end=data.rend();
  for(auto it=data.rbegin();it!=end;){
    printf("%d",*it);
    if(++it!=end)printf(" ");
  }
  printf("\n");
}

void input(){
  int x;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&x);
    data.push_back(x);
  }
}

int main(){
  input();
  proc();
}

Measured memory_bytes: 1040
class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.components = n  # 連結成分の数

    def root(self, x):
        if self.p[x] != x:
            stack = [x]
            while True:
                top = stack[-1]
                if self.p[top] == top:
                    break
                else:
                    stack.append(self.p[top])
            for v in stack:
                self.p[v] = top
        return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
    
    def same(self, x,y):
        return (self.root(x) == self.root(y))

N = int(input())
X, Y = [], []
for i in range(N):
    x, y = map(int,input().split())
    X.append([x, i])
    Y.append([y, i])

X.sort()
Y.sort()

edges = []
for i in range(N-1):
    edges.append([X[i+1][0]-X[i][0], X[i][1], X[i+1][1]])
    edges.append([Y[i+1][0]-Y[i][0], Y[i][1], Y[i+1][1]])
edges.sort()

UF = UnionFind(N)
ans = 0
for cost, s, t in edges:
    if UF.same(s,t): continue

    UF.unite(s,t)
    ans += cost
print(ans)

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

int main() {
  int N,i,A,B;
  int64_t t=0;
  cin >> N;
  vector<pair<int,int>> T(N);

  for(i=0; i<N; i++) {
    cin >> A >> B;
    T.at(i) = make_pair(B,A);
  }

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

  for(i=0; i<N; i++) {
    t+=T.at(i).second;
    if(t>T.at(i).first)
      break;
  }

  if(i==N)
    cout << "Yes";
  else
    cout << "No";
  cout << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
using namespace std;

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

using Graph = vector<vector<int>>;

int main(){
    int N, M;
    cin >> N >> M;
    Graph G(N);
    rep(i, M){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> dist(N, -1);
    vector<int> pre(N, -1);
    queue<int> q;
    dist[0] = 0;
    q.push(0);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(int nv : G[v]){
            if(dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            pre[nv] = v; //preには、自分よりも始点からのステップ数が少ない頂点の頂点番号を記録
            q.push(nv);
        }
    }
    cout << "Yes" << endl;
    rep(i, N){
        if(i == 0) continue;
        int ans = pre[i];
        ans++;
        cout << ans << endl;
    }
    return 0;
}

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

int main(void){

    char s[100001];
    long int K,i;
    int s_len;

    scanf("%s",s);
    scanf("%ld",&K);

    s_len = strlen(s);

    for(i = 0;i < s_len;i++){
        if(K == 0) break;
        int t = (int)('a' - s[i]);
        if(t < 0) t += 26;
        if(t <= K){
            s[i] += (char)t;
            K -= (long int)t;
            if(s[i] > 'z'){
                s[i] -= 26;
            }
        }
    }

    K %= 26;
    s[s_len-1] += K;
    if(s[s_len] > 'z'){
        s[i] -= 26;
    }

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


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, M;
    cin >> N >> M;
    Graph graph(N);
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    ll ans = 0;
    queue<vector<ll>> queue;
    queue.push(vector<ll>(1, 0));
    while (!queue.empty()) {
        vector<ll> route = queue.front();
        queue.pop();
        if (route.size() == N) {
            ans++;
        } else {
            ll v = route.back();
            for (ll u : graph[v]) {
                if (find(route.begin(), route.end(), u) == route.end()) {
                    vector<ll> target = route;
                    target.push_back(u);
                    queue.push(target);
                }
            }
        }
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 768
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(X, Y, A, B, C, Ps, Qs, Rs):
    inf = 10 ** 9 + 1
    Ps.sort(reverse=True)
    Qs.sort(reverse=True)
    Rs.sort(reverse=True)
    a = X - 1
    b = Y - 1
    c = 0
    while True:
        m = min(Ps[a] if a >= 0 else inf,
                Qs[b] if b >= 0 else inf,
                Rs[c])
        if m == Rs[c]:
            break
        elif m == Ps[a]:
            c += 1
            a -= 1
        elif m == Qs[b]:
            c += 1
            b -= 1
        if c == C:
            break

    ans = 0
    if a >= 0:
        ans += sum(Ps[:a + 1])
    if b >= 0:
        ans += sum(Qs[:b + 1])
    if c > 0:
        ans += sum(Rs[:c])

    print(ans)


if __name__ == '__main__':
    X, Y, A, B, C = map(int, input().split())
    Ps = [int(i) for i in input().split()]
    Qs = [int(i) for i in input().split()]
    Rs = [int(i) for i in input().split()]
    solve(X, Y, A, B, C, Ps, Qs, Rs)


Measured memory_bytes: 23640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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

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

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

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

void PrimeFact(ll x) { // 素因数分解 出力部を適切に書き換え
	int i=2;
	while(x%2&&i*i<=x) {
		cout<<2<<endl;
		x/=2;
	}
	i++;
	while(i*i<=x) {
		if(x%i) {
			i+=2;
			continue;
		}
		cout<<i<<endl;
		x/=i;
	}
}

bool Palind(string s) {
	return s == string(s.rbegin(), s.rend());
}

int main() {
	int N,M; cin>>N>>M;
	string A[N],B[M];
	for(int i=0; i<N; i++) cin>>A[i];
	for(int i=0; i<M; i++) cin>>B[i];

	for(int i=0; i<=N-M; i++) {
		for(int j=0; j<=N-M; j++) {
			bool equal=true;
			for(int k=0; k<M; k++) {
				if(A[i+k].substr(j,M)!=B[k]) {
                    equal=false;
					break;
				}
			}
			if(equal) {
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}

	cout<<"No"<<endl;
}


Measured memory_bytes: 256