akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc088/tasks/abc088_d

from collections import deque

if __name__ == "__main__":
    H, W = list(map(int, input().split()))
    A = []
    A.append('#' * (W + 2))
    for i in range(H):
        A.append('#' + input() + '#')
    A.append('#' * (W + 2))

    # for row in A:
    #     print(row)

    queue = deque()
    queue.appendleft((1, 1, 1))
    checked = set()
    goal = (H, W)

    dist = -1
    while queue:
        i, j, d = queue.pop()
        if (i, j) in checked:
            continue
        checked.add((i, j))

        if (i, j) == goal:
            dist = d

        for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            ii = i + dx
            jj = j + dy
            if A[ii][jj] == '.':
                queue.appendleft((ii, jj, d+1))

    if dist == -1:
        result = -1
    else:
        white = sum([row.count('.') for row in A])
        result = white - dist
    print(result)


Measured memory_bytes: 40944
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("[debug: %s] ", __func__); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

int find(vector<int> arr, int val) {
    for(int i = 0; i < arr.size(); i++) {
        if(arr[i] == val) {
            return i;
        }
    }
    return -1;
}

int main(void) {
    string str;
    cin >> str;
    int len = str.length();
    bool flag = 0;
    vector<int> map(3);
    if(len == 1) {
        flag = 1;
        goto finish;
    }
    for(int i = 0; i < str.length(); i++) {
        map[str[i]-'a']++;
    }


    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            // "aa"
            if(i == j) continue;
            int pprev = i;
            int prev = j;
            vector<int> abc_map(3);
            vector<int> mmap(map);
            if(!mmap[i] || !mmap[j]) continue;
            abc_map[pprev]++;
            abc_map[prev]++;
            mmap[pprev]--;
            mmap[prev]--;
            bool is_ok = 1;
            for(int k = 2; k < len; k++) {
                int cur = find(abc_map, 0);
                if(!mmap[cur]) { is_ok = 0; break; }
                // update
                abc_map[pprev]--;
                abc_map[cur]++;
                mmap[cur]--;
                pprev = prev;
                prev = cur;
            }
            debug("%c%c -> %d\n", i+'a', j+'a', is_ok);
            if(is_ok) {
                flag = 1;
                goto finish;
            }
        }
    }

finish:
    cout << (flag ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd(a,b) __gcd(a,b)
#define INF INT_MAX
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

string s;
int diff=0;
int main(){
  cin>>s;
  int i=0,j=s.size()-1;
  while(i<j){
    if(s[i]!=s[j]){
      s[i]=s[j];
      ++diff;
    }
    ++i;
    --j;    
  }
  cout<<diff<<endl;    
  return 0;
}

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

bool isSame(string a, string b) {
	for (int i = 0; i < a.size(); ++i) {
		if (a[i] != b[i] and a[i] != '?') {
			return false;
		}
	}
	return true;
}

string repl(string a, string b, int n) {
	for (int i = 0; i < b.size(); ++i) {
		a[n + i] = b[i];
	}
	return a;
}


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

	int N = s.size() - t.size();

	for (int i = N; i >= 0; --i) {
		if (isSame(s.substr(i, t.size()), t)) {
			string ans = repl(s, t, i);
			replace(ans.begin(), ans.end(), '?', 'a');
			cout << ans << endl;
			return 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
isExist = [False]*2001 
n = int( raw_input() )
A = [ int( val ) for val in raw_input().rstrip().split( ' ' ) ]
for i in A:
	for j in range( 2000-i, 0, -1 ):
		if isExist[j]:
			isExist[ i+j ] = True
	isExist[i] = True

q = int( raw_input() )
M = [ int( val ) for val in raw_input().rstrip().split( ' ' ) ]
for i in range( 0, q ):
	if isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Measured memory_bytes: 4292
#include <bits/stdc++.h>
#define MAX 100005
#define MOD 1e9
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define endl '\n'
using namespace std;
/* ----------------------------------------------------------------------------------- */

#define fastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define scan(a) scanf("%d", &a)
#define scanll(a) scanf("%lld", &a)
#define scanD(a) scanf("%lf", &a)
#define print(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printD(a) printf("%lf\n", a)
#define printTwo(a) printf("%.2lf\n", a);
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, a, n) for (int i = a; i <= n; i++)
#define inputArray(a,n) rep(i, 0, n) cin >> a[i];
#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
#define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;

/* ----------------------------------------------------------------------------------- */

#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)
#define showTime cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';

#define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, n){cout<<A[i][j]<<" ";}cout<<"\n";}cout<<"\n";}
#define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
#define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}

/* ----------------------------------------------------------------------------------- */

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

struct debugger {
	typedef string::iterator si;
	static void call(si it, si ed) {}
	template<typename T, typename ... aT>
	static void call(si it, si ed, T a, aT... rest) {
		string b;
		for(; *it!=','; ++it)
			if(*it!=' ')
				b+=*it;
		cout << b << "=" << a << " ";
		call(++it, ed, rest...);
	}
};

/* ----------------------------------------------------------------------------------- */

vi a;
vi Count;

void solve() {
	int n;
	cin >> n;
	a.resize(n + 2);
	Count.resize(n + 2);

	REP(i, 2, n) {
		cin >> a[i];
		Count[a[i]]++;
	}

	REP(i, 1, n) {
		print(Count[i]);
	}
}


int main() {
#ifdef Niloy
	read("input.txt");
	write("output.txt");
#endif

	solve();

	// __test {
	// 	solve();
	// }

	showTime;
	return 0;
}




Measured memory_bytes: 4680
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#define mp make_pair
#define pb push_back
using namespace std;

namespace Header_Template {
  typedef long long li;
  template<class T>inline void read(T &x) {
    x = 0;
    T tmp = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') tmp = -1, c = getchar();
    while (c >= '0' && c <= '9')
      x = (x << 1) + (x << 3) + c - '0', c = getchar();
    x *= tmp;
  }
  template<class T>inline void Max(T &x, T y) {
    if (y > x) x = y;
  }
  template<class T>inline void Min(T &x, T y) {
    if (y < x) x = y;
  }
}
using namespace Header_Template;

const int N = 2e5 + 10, M = 21;
int n, a[N], f[N];

int main(void) {
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]);
  int pos = 0, g = 0;
  for (int i = 1; i <= n; ++i) {
    while (pos < n && (g & a[pos + 1]) == 0)
      ++pos, g |= a[pos];
    f[i] = pos;
    g ^= a[i];
  }
  li ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += f[i] - i + 1;
  printf("%lld\n", ans);

  return 0;
}


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

int main(){
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int genjiten;
    int count=0;
    for(int i=0;i<a+1;i++){
        for(int j=0;j<b+1;j++){
            for(int h=0;h<c+1;h++){
                genjiten=500*i+100*j+h*50;
                if(genjiten==x){
                    count+=1;

                }
                else{
                    int unko=0;
                }
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll fac[100001];
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
ll nCrModPFermat(ll n, ll r, ll p) 
{ 
   if(n<r){
   	return 0;
   }
   if(r<0){
   	return 0;
   }
   // Base case 
   if (r==0) 
      return 1; 
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 
int main(){
	ll n,k;
	cin>>n>>k;
	vector<ll>a(n);
	fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%MOD; 
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	ll ans=0;
	for(int i=0;i<n;i++){
		// cout<<nCrModPFermat(i,k-1,MOD)<<" "<<nCrModPFermat(n-i,k-1,MOD)<<endl;
		ans+=((nCrModPFermat(i,k-1,MOD)*a[i])-(nCrModPFermat(n-i-1,k-1,MOD)*a[i])+MOD)%MOD;
		// cout<<ans<<endl;
		ans=ans%MOD;
		// cout<<ans<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, (int)n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}

int main() {
  int n, k; cin >> n >> k;
  vector<int> d(k);
  REP(i, k) cin >> d[i];

  for(int i = n; ; i++){
    string s = to_string(i);
    bool f = true;
    REP(i, k) f &= s.find(to_string(d[i])) == string::npos;
    if(f){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    char s[15], t[15];

    scanf("%s", s);
    scanf("%s", t);

    //printf("%lu\n", sizeof(s));
    int flag = 0;
    int i = 0;
    while(s[i] != '\0'){
        //printf("%c\n", s[i]);
        //printf("%c\n", t[i]);
        if(s[i] != t[i]) flag = 1;
        //printf("%d\n", i);
        i++;
    }

    if(flag) puts("No");
    else puts("Yes");

    return 0;
}

Measured memory_bytes: 1636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const int INF = 1000000000; // 10^9
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int A[3][3];
    rep(i, 3){
        rep(j, 3){
            cin >> A[i][j];
        }
    }

    int N;
    cin >> N;

    string ans = "No";
    for (int m = 0; m < N; m++){
        int tmp;
        cin >> tmp;
        for(int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++){
                if(tmp == A[i][j]){
                    A[i][j] = 0;
                }
            }
        }
    }

    for(int i = 0; i < 3; i++) {
        int y = 0;
        int x = 0;
        for(int j = 0; j < 3; j++) {
            x += A[i][j];
            y += A[j][i];
        }
        if(x == 0 || y == 0) {
            ans = "Yes";
            break;
        }
    }

    if(A[0][0] + A[1][1] + A[2][2] == 0){
        ans = "Yes";
    }

    if(A[0][2] + A[1][1] + A[2][0] == 0){
        ans = "Yes";
    }


    cout << ans << endl;
}


Measured memory_bytes: 256
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define F first
    #define S second
    #define pb push_back
    #define mkp make_pair
    #define int long long
    #define ld long double

    #define all(x) x.begin(),x.end() 
    #define rall(x) x.rbegin(),x.rend()
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
    
    #define XOX 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int INF = 1e15;
    const int MAX = 2e6 + 7;
    const int MOD =  1000000007;
    const long double PI  =3.141592653589793238463;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ D $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define deb(x) cout<<#x<<" "<<x<<endl;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    string s;
    int cnt;
    void solve()
    {
        cin>>s;
        n=s.size();
        fo(i,0,n)
        {
            if(s[i]=='?')s[i]='D';
        }
        // fo(i,0,n)
        // {
        //     if(s[i]=='D')cnt++;
        //     if(s[i]=='P' && s[i+1]=='D')cnt++;
        // }
        // cout<<cnt<<endl;
        cout<<s<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          THE GAME STARTS HERE                             //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        cout.tie(NULL);
        
        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<ll>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 117117117

int main()
{
    int n;
    ll d;
    ll x,y;
    cin >> n >> d;
    int count=0;
    rep(i,n){
        cin >> x >> y;
        ll ans=x*x+y*y;
        if(ans<=d*d){
            count++;
        }
    }
    cout << count << endl;

}


Measured memory_bytes: 3672
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int N,K;
int main() {
	cin>>N>>K;

	int A=1;
	for(int i=0;i<N;i++){
		if((2*A)<(A+K))A=2*A;
		else A=A+K;
	}

	cout<<A<<endl;

	return 0;
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
aa = np.array(input().split(), dtype='int')
ma = np.max(aa)
# cnt = np.zeros(max(aa)+1, dtype='int')
cnt = [0] * (ma+1)

for a in aa:
    cnt[a] += 1

if np.gcd.reduce(aa) != 1:
    print('not coprime')
elif np.all([sum(cnt[i::i]) <= 1 for i in range(2, ma)]):
    print('pairwise coprime')
else:
    print('setwise coprime')

Measured memory_bytes: 150436
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int X, Y;
	cin >> X >> Y;
	for(int c = 0; c <= X; c++){
		if(c*2+(X-c)*4 == Y){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    long long ans[n+1], sum[n+1];
    ans[0] = 1, sum[0] = 1;
    ans[1] = n, sum[1] = n + 1;
    const int M = 1000000007;
    for (int i = 2; i <= n; i++) {
        ans[i] = ans[i-1];      // 1, 1
        if (i >= 3) ans[i] += sum[i-3]; // k, 1; k < i
        if (i >= 2) ans[i] += (long long)(i - 2) * (n - 1); // k, l; k < i, l > 1
        ans[i] += (long long)(n - i + 1) * n; // k, l; k >= i
        ans[i] %= M;
        sum[i] = (sum[i-1] + ans[i]) % M;
    }
    cout << ans[n] << endl;
}


Measured memory_bytes: 15872
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
# local only
# if not __debug__:
#     fin = open('in_1.txt', 'r')
#     sys.stdin = fin
# local only
# input = sys.stdin.readline
# def ii(): return int(input())
# def mi(): return map(int, input().rstrip().split())
# def lmi(): return list(map(int, input().rstrip().split()))
# def fi(): return float(input())
# def mfi(): return map(float, input().rstrip().split())
# def lmfi(): return list(map(float, input().rstrip().split()))
# def li(): return list(input().rstrip())
# def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
# def exit(*arg): print(*arg); sys.exit()
# template


def main():
    a = ["Sunny", "Cloudy", "Rainy"]
    S = input()
    if S == a[0]:
        print(a[1])
    elif S == a[1]:
        print(a[2])
    else:
        print(a[0])
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


struct edge{
    int u, v, cost;
    edge(int u, int v, int cost): u(u), v(v), cost(cost){}
    bool operator>(const edge &e) const {
        return cost > e.cost;
    }
};


// Union Find
const int N_MAX = 100010;
int par[N_MAX];

void init_par(){
    REP(i, N_MAX) par[i] = i;
}

int root(int x){
    if(par[x] == x) return x;
    else return par[x] = root(par[x]);
}

bool same(int x, int y){
    return root(x) == root(y);
}

void unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x == y) return; // rank有りの場合ならこのifはあったほうがいい
    par[x] = y;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<P> xv, yv;
    REP(i, n){
        int x, y;
        cin >> x >> y;
        xv.push_back(make_pair(x, i));
        yv.push_back(make_pair(y, i));
    }
    sort(xv.begin(), xv.end());
    sort(yv.begin(), yv.end());

    priority_queue<edge, vector<edge>, greater<edge>> costpq;
    REP(i, n - 1){
        int cost = xv[i + 1].first - xv[i].first;
        costpq.push({xv[i + 1].second, xv[i].second, cost});
        cost = yv[i + 1].first - yv[i].first;
        costpq.push({yv[i + 1].second, yv[i].second, cost});
    }

    int ans = 0;
    init_par();
    while(!costpq.empty()){
        edge e = costpq.top();
        costpq.pop();
        if(!same(e.u, e.v)){
            unite(e.u, e.v);
            ans += e.cost;
        }
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 7144
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = stdin.Read()
	}

	c := NewCounter()
	for _, v := range s {
		c.Increment(v)
	}

	d := map[int]map[string]bool{}
	for _, key := range c.Keys() {
		count := c.Get(key)
		word, _ := key.(string)
		if _, ok := d[count]; !ok {
			d[count] = map[string]bool{}
		}

		words := d[count]
		words[word] = true
	}

	tuples := []Tuple{}
	for count, words := range d {
		tuple := Tuple{
			Count: count,
			Words: []string{},
		}
		for word := range words {
			tuple.Words = append(tuple.Words, word)
		}
		tuples = append(tuples, tuple)
	}
	sort.Sort(Tuples(tuples))

	sort.Strings(tuples[0].Words)
	for _, word := range tuples[0].Words {
		stdout.Println(word)
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

type Counter map[interface{}]int

func NewCounter() *Counter {
	return &Counter{}
}

func (c *Counter) Increment(key interface{}) {
	d := map[interface{}]int(*c)
	d[key] = c.Get(key) + 1
}

func (c *Counter) Get(key interface{}) int {
	d := map[interface{}]int(*c)
	if v, ok := d[key]; ok {
		return v
	} else {
		return 0
	}
}

func (c *Counter) Keys() []interface{} {
	d := map[interface{}]int(*c)
	keys := []interface{}{}
	for key := range d {
		keys = append(keys, key)
	}
	return keys
}

type Tuple struct {
	Count int
	Words []string
}

type Tuples []Tuple

func (ts Tuples) Len() int           { return len(ts) }
func (ts Tuples) Less(i, j int) bool { return ts[i].Count > ts[j].Count }
func (ts Tuples) Swap(i, j int)      { ts[i], ts[j] = ts[j], ts[i] }


Measured memory_bytes: 51456
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


int main() {
	int N; cin >> N;
	vector<int> a(N,0);
	int n = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (n < a[i]) {
			n = a[i];
		}
	}
	sort(a.begin(), a.end());
	
	int r = n;
	int min_d = n;
	for (int i = 0; i < N-1; i++) {
		double dt = abs(((double)a[i] - (double)n / 2));
		//cout << dt << " = " << "abs(" << a[i] << " - " << (double)n/2 << ")" << endl;
		if (min_d > dt) {
			min_d = dt;
			r = a[i];
		}
	}
	cout << n << " " << r << endl;
	return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;
const int MM = 3333;
vector<pair<int,int>> g[MM];
int D[3200], N, M;
void addedge(int from, int to, int wt = 1) { //0 based , directed x to y
    g[from].push_back({to, wt});
    swap(to, from);
    g[from].push_back({to, wt});
}
void dijkstra(int x) {
    for(int i = 0; i < N; i++) {
        D[i] = 1e4;
    }
    D[x] = 0;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
    q.push({0,x});
    
    while(!q.empty()) {
        pair<int,int> p = q.top();
        q.pop();
        
        int u = p.second, dist = p.first;
        if(dist > D[u]) {
            continue;
        }
    
        for(pair<int,int> pr : g[u]) {
            int v = pr.first;
            int next_dist = dist + pr.second;
            if(next_dist < D[v]) {
                D[v] = next_dist;
                q.push({next_dist,v});
            }
        }
    }
}

int main() {fio;
	int X, Y;
	cin >> N >> X >> Y;
	X--; Y--;
	for(int i = 0; i < N - 1; i++) {
		addedge(i, i + 1);
	}
	addedge(X, Y);
	vector <int> ans(N + 1, 0);
	for(int i = 0; i < N; i++) {
		dijkstra(i);
		for(int j = 0; j < N; j++) {
			// cout << i << ' ' << j << ' ' << D[j] << endl;
			ans[D[j]]++;
		}
	}
	for(int i = 1; i < N; i++) {
		cout << ans[i] / 2 << '\n';
	}


	return 0;	
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int area = a*b;
    int length = a+a+b+b;
    System.out.println(area+" "+length);
    sc.close();
  }
}



Measured memory_bytes: 26084
for i in xrange(input()):
    head1,head2=0,0
    frag=True
    for a in map(int,raw_input().split()):
        if head1>a and head2>a:
            frag=False
            break
        if head1<a and head1 > head2 or head2>a:
            head1=a
        else:
            head2=a
    if frag:print "YES"
    else:print "NO"

Measured memory_bytes: 5736
N,*X=map(int,open(0).read().split());M,g,r,h,i=10**9+7,1,0,[1],N
while i:i-=1;h+=[h[-1]*i%M]
while i<N:r,g=(r+g*h[N-2-i]*(X[-1]-X[i]))%M,g*-~i%M;i+=1
print(r)

Measured memory_bytes: 69672
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;

int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    priority_queue<ll> pq;
    ll A;
    for(ll i=0;i<N;i++){
        cin>>A;
        pq.emplace(A);
    ;}
    for(ll i=0;i<M;i++){
        ll T=pq.top();
        pq.pop();
        T>>=1;
        pq.emplace(T);
    ;}
    ll sum=0;
    while(pq.size()){
        ll T=pq.top();
        pq.pop();
        sum+=T;
    ;}
    cout<<sum<<endl;
return 0;
}  



Measured memory_bytes: 1400
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as B
import           Data.Char             (isSpace)
import qualified Data.Vector.Unboxed   as V

main :: IO ()
main = do
  n <- readLn
  hs <- V.unfoldrN n parseInt <$> B.getLine
  print $ solve n hs

solve :: Int -> V.Vector Int -> Int
solve _ hs = solve' hs

solve' :: V.Vector Int -> Int
solve' hs
  | V.length hs == 0 = 0
  | otherwise  = h + solve' (V.take i hs') + solve' (V.drop (i + 1) hs')
  where
    i = V.minIndex hs
    h = hs V.! i
    hs' = V.map (subtract h) hs

parseInt :: B.ByteString -> Maybe (Int, B.ByteString)
parseInt = B.readInt . B.dropWhile isSpace


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

const int INF = 10000000;

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    string s[12];
    for(int i = 0; i < h; i++) cin >> s[i];
    int ans = INF;
    for(int b = 0; b < (1 << (h - 1)); b++){
        bool f = true;
        int c[12]{0};
        int t[12]{0};
        int p = h - 1;
        for(int i = 0; i < h - 1; i++) if((b >> i) & 1) p--;
        for(int j = 0; j < w; j++){
            for(int i = 0; i < h; i++){
                if(s[i][j] == '1') t[i]++;
                if(i < h - 1 && ((b >> i) & 1)){
                    t[i + 1] += t[i];
                    t[i] = 0;
                }
            }
            bool g = false;
            for(int i = 0; i < h; i++){
                if(t[i] > k) f = false;
                if(t[i] + c[i] > k) g = true;
            }
            if(g){
                p++;
                for(int i = 0; i < h; i++) c[i] = 0;
            }
            for(int i = 0; i < h; i++){
                c[i] += t[i];
                t[i] = 0;
            }
        }
        if(f) ans = min(ans, p);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;
  for(int i=0;i<n;i++)if(a[i]==0) zero ++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}

Measured memory_bytes: 2932
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    string s;
    cin >> s;
    int ans = 0;
    for(char c: s) {
        ans += c-'0';
    }
    cout << ans << endl;
    return 0;
}




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

int main() {
    int n, k;
    cin >> n >> k;
    
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    
    sort(p.begin(), p.end());
    
    int answer = 0;
    for (int i = 0; i < k; i++) {
        answer += p[i];
    }
    
    cout << answer << endl;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

ll mod = 1e9 + 7;
const ld error = 1e-8;
const ld PI = acosl(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise - "<<__LINE__<<"\n"
#define tham getchar()
mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count()); //mt199937_64 for ll

inline ll MOD(ll x, ll m = mod)
{
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e9;
const ll infl = 1e18+1;
const int nmax = 2e6;
///===========================================  template  =======================================================

char arr[nmax];
int v[nmax];

int main(){
    FASTIO;
    cin>>arr;

    for(int i = 0; arr[i]; i++)
        v[i] = arr[i]-'0';

    int n = strlen(arr);
    reverse(v, v+n);
    int ans = 0;
    for(int i = 0; i<nmax; i++){
        if(v[i] >= 10){
            v[i] -= 10;
            v[i+1] += 1;
        }
        assert(v[i] < 10);

        if(v[i] < 5 || (v[i] == 5 && v[i+1] < 5)){
            ans += v[i];
        }
        else if(v[i] > 5 || (v[i] == 5 && v[i+1] >= 5)){
            v[i+1] += 1;
            ans += 10-v[i];
        }
    }
    cout<<ans;

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> av;
  ll sum = 0;
  rep(i,n) {
    int a;
    cin >> a;
    av.push_back(a);
    sum += a;
  }
  int cnt = 0;
  double d = (double) sum / (double) (4*m);
  rep(i,n) {
    if ((double)av[i] >= d) cnt++;
  }
  if(cnt >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
class HashTable:

    @staticmethod
    def h1(key):
        return key % 1046527

    @staticmethod
    def h2(key):
        return 1 + (key % (1046527 - 1))
    
    def __init__(self, size):
        self.size = size
        self.values = [None for _ in range(size)]
        self.tables = str.maketrans({
            'A':'1', 'C':'2', 'G':'3', 'T':'4',
        })

    def translate_key(self, value):
        return int(value.translate(self.tables))

    def find(self, value):
        count = 0
        key = self.translate_key(value)

        while True:
            h = (HashTable.h1(key) + count * HashTable.h2(key)) % 1046527
            if self.values[h] == value:
                return True
            elif self.values[h] is None:
                return False
            count += 1
        return False

    def insert(self, value):
        count = 0
        key = self.translate_key(value)
        
        while True:
            h = (HashTable.h1(key) + count * HashTable.h2(key)) % 1046527
            if self.values[h] is None:
                self.values[h] = value
                break
            count += 1


num = int(input())

dictionary = HashTable(1046527)
for _ in range(num):
    command, value = input().split()
    if command == "insert":
        dictionary.insert(value)
    elif command == "find":
        is_find = dictionary.find(value)
        print("yes" if is_find else "no")


Measured memory_bytes: 48220
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}
int main(){
    ll N;
    cin>>N;
    vector<string> W(N);
    rep(i,0,N)cin>>W[i];
    map<string,ll> m;
    char e = W[0][W[0].size()-1];
    m[W[0]]++ ;
    bool ans =true;
    rep(i,1,N){
        if(m[W[i]] >= 1) ans = false;
        if(e != W[i][0]) ans = false;
        m[W[i]]++;
        e = W[i][W[i].size()-1];
    }

    YN(ans);
    return 0;
}

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

using namespace std;

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

    int r;
    cin>>r;

    if(r%2==0)
        cout<<r/2;
    else
        cout<<(r+1)/2;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int a[55],b[55],c[55],d[55];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
    for(int i=1;i<=m;i++)cin>>c[i]>>d[i];
    for(int i=1;i<=n;i++)
    {
        int ans=1e9,k;
        for(int j=1;j<=m;j++)
        {
            int t=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(t<ans)
            {
                ans=t;
                k=j;
            }
        }
        cout<<k<<endl;
    }
    return 0;
} 

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N; cin >> N;

    auto ai = [](i64 i) {
        return (i * (i + 1)) / 2;
    };

    i64 len = -1;
    REP(i, N + 1) {
        i64 ok = ai(i);
        if (N == ok) len = i;
    }
    if (len == -1) {
        cout << "No" << endl;
        return 0;
    }

    i64 sz = (2 * N) / len;

    vector<vector<i64>> ans(len, vector<i64>(sz));
    REP(i, len) {
        i64 a = ai(i + 1);
        for (i64 j = 1; i - j >= 0; j++) {
            ans[i][i - j] = a - j;
        }
        ans[i][i] = a;
        ans[i][i + 1] = a;

        for (i64 j = i + 2; j < sz; j++) {
            ans[i][j] = ans[i][j - 1] + j - 1;
        }
    }

    cout << "Yes" << endl;
    cout << sz << endl;
    REP(i, sz) {
        cout << len << " ";
        REP(j, len) cout << ans[j][i] << " ";
        cout << endl;
    }

    return 0;
}


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

using namespace std;

int main() {

	long long n,k;

	cin >> n >> k;

	long long total;
	total = 0;

	long long minn, maxx;
	for (long long i = k; i <= n+1; i++) {
		minn = i * (i - 1) / 2;
		maxx = n * (n + 1) / 2 - (n - i)*(n - i + 1) / 2;
		total = (total + maxx - minn + 1)%(1000000007);
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 3636
/* Coached by rainboy */
#include <stdio.h>
#include <string.h>

#define H 200
#define W 200

int min(int a, int b) {
	return a < b ? a : b;
}

int main() {
	static int cc[10][10], dd[10];
	int h, w, i, j, k, ans;

	scanf("%d%d", &h, &w);
	for (i = 0; i < 10; i++)
		for (j = 0; j < 10; j++)
			scanf("%d", &cc[j][i]);
	memset(dd, 0x3f, sizeof dd);
	dd[1] = 0;
	for (k = 1; k <= 10; k++)
		for (i = 0; i < 10; i++)
			for (j = 0; j < 10; j++)
				dd[j] = min(dd[j], dd[i] + cc[i][j]);
	ans = 0;
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++) {
			int a;

			scanf("%d", &a);
			if (a != -1)
				ans += dd[a];
		}
	printf("%d\n", ans);
	return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll a, b, n;
char S[101010];
ll qq[2];
ll i, j, k;

int main(){
    scanf("%s", S);
    for (i = 0; S[i] != '\0';i++){
        ll qa = (S[i] - '0');
        if(qq[!qa]==0){
            qq[qa]++;
        }else{
            qq[!qa]--;
        }
    }
    printf("%lld", i - qq[0] - qq[1]);

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <limits.h>
#define N 500000

void marge(int*, int, int, int);
void mergeSort(int*, int, int);
int count=0,L[N/2+2],R[N/2+2];

int main(){

  int i,A[N],n;
  
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  mergeSort(A,  0, n);
  for(i=0;i<n-1;i++) printf("%d ",A[i]);
  printf("%d\n",A[n-1]);
  printf("%d\n",count);

  return 0;
}

void merge(int *A,int left,int mid,int right){
  int n1,n2,i,j,k;

  n1 = mid - left;
  n2 = right - mid;
 
  for (i = 0;i<n1;i++) L[i] = A[left + i];
  for (i = 0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = INT_MAX;
  R[n2] = INT_MAX;
  i = 0;
  j = 0;
  for (k = left;k<right;k++){
    count++;
    if (L[i] <= R[j]){
      A[k] = L[i++];
    }
    else{ 
      A[k] = R[j++];
    }
  }
}

void mergeSort(int *A,int left,int right){
  int mid;
  if (left+1 < right){
    mid = (left + right)/2;
  mergeSort(A, left, mid);
  mergeSort(A, mid, right);
  merge(A, left, mid, right);
  }
}

	



Measured memory_bytes: 5608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>
#include <cstdint>
#include <cstring>

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int main()
{
	int A, B;

	cin >> A >> B;

	int PLS = A + B;
	int MNS = A - B;
	int MLT = A * B;

	int MAX = 0;

	if (PLS > MNS){
		MAX = PLS;
	}
	else{
		MAX = MNS;
	}

	if (MLT > MAX){
		MAX = MLT;
	}

	cout << MAX << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cctype>
using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int n,a,b,ans=0;
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++){
        int digit=floor(log10(i)+1),tmp=i,sum=0;
        for(int j=0;j<digit;j++){
            sum+=tmp%10;
            tmp/=10;
        }
        if(sum>=a && sum<=b){
            ans+=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void){
    char S;

    cin>>S;
    if(isupper(S)){
        cout<<"A"<<endl;
    }else{
        cout<<"a"<<endl;
    }


    return 0;
}



Measured memory_bytes: 3596
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
// #define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);++i)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()

int main(){
	int N; cin>>N;
	vector<pair<int,int>> A;
	for(int no=1; no<=N; ++no){
		int nin; cin>>nin;
		A.emplace_back(nin,no);
	}

	sort(all(A));

	for(auto e:A){
		int nin,no; tie(nin,no) = e;
		printf("%d ", no);
	}

}


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

int  main()
    {
        int k;
        string s;
        cin>>k>>s;
        if(k>=s.length()){
            cout<<s<<endl;
            return 0;
        }
        string temp="";
        for(int i=0;i<k;i++)
        {
            temp+=s[i];
        }
        temp+="...";
        cout<<temp<<endl;
    }

Measured memory_bytes: 3616
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	lli n, x, a, b, c, l;
	cin >> n >> x;
	
	l=n; a=x; b=n-x;
	while(1){
		if(a>b) swap(a, b);
		if(b%a == 0) {l += b*2-a; break;}
		l += (b/a) * 2 * a;
		b = b%a;
	}
	
	cout << l <<endl;
	return 0;
}

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

class UnionFind
{
public:
		vector<int> data;
		UnionFind(int size):data(size, -1){}

		bool unionSet(int x, int y)
		{
			x = root(x); y=root(y);
			if(x != y)
			{
				if(data[y] < data[x]) swap(x, y);
				data[x] += data[y]; data[y] = x;
			}
			return x != y;
		}

		bool findSet(int x, int y)
		{
			return root(x) == root(y);
		}

		int root(int x)
		{
			return data[x] < 0 ? x:data[x]=root(data[x]);
		}
};

#define EPS 1e-8

typedef complex<double> P;
typedef vector<P> G;

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

double dot(const P& a, const P& b)
{
	return real(conj(a)*b);
}
double cross(const P& a, const P& b)
{
	return imag(conj(a)*b);
}

int ccw(P a, P b, P c)
{
	b -= a; c -= a;
	if (cross(b, c) > +EPS) return +1;
	if (cross(b, c) < -EPS) return -1;
	if (dot(b, c)   < -EPS) return +2;
	if (norm(b) < norm(c))  return -2;
	return 0;
}

bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

bool isIntoG(const G& g, const P& p)
{
	for(int i=0; i<g.size(); i++)
	{
		if(ccw(p, g[i], g[(i+1)%g.size()]) != +1) return false;
	}
	return true;
}

bool isInto(const G& l, const G& r)
{
	for(int i=0; i<r.size(); i++)
		if(isIntoG(l, r[i])) return true;
	return false;
}


bool intersect(const G l, const G r)
{
	for(int i=0; i<l.size(); i++)
	for(int j=0; j<r.size(); j++)
	{
		if(intersectSS(L(l[i], l[(i+1)%l.size()]), L(r[j], r[(j+1)%r.size()]))) return true;
		if(abs(l[i]-r[j]) < EPS) return true;
		if(intersectSP(L(l[i], l[(i+1)%l.size()]), r[j])) return true;
		if(intersectSP(L(r[j], r[(j+1)%r.size()]), l[i])) return true;
	}
	return false;
}

bool isConnect(const G l, G r)
{
	return (intersect(l,r)||isInto(l,r)||isInto(r,l));
}

int main()
{
	int N,M;
	while(cin >> N, N)
	{
		while(N--)
		{
			cin >> M;
			vector<G> rect;
			while(M--)
			{
				G t;
				for(int i=0; i<4; i++)
				{
					int x,y;
					cin >> x >> y;
					t.push_back(P(x,y));
				}
				reverse(t.begin(), t.end());
				rect.push_back(t);
			}
			
			UnionFind uf(rect.size());
			for(int i=0; i<rect.size(); i++)
			for(int j=i+1; j<rect.size(); j++)
				if(isConnect(rect[i], rect[j])) uf.unionSet(i,j);
				
			int ret=0;
			bool checked[100]={0};
			for(int i=0; i<rect.size(); i++)
			{
				if(checked[i]) continue;
				checked[i]=1;
				ret++;
				for(int j=0; j<rect.size(); j++)
					if(uf.findSet(i,j)) checked[j]=1;
			}
			
			cout << ret << endl;
		}
	}
}

Measured memory_bytes: 940
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>

typedef long long LL;

using namespace std;

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}


int main(void) {
	int h, w;
	cin >> h >> w;
	vector<string>a(h);
	for (int i = 0; i < h; i++)cin >> a[i];
	vector<bool>hf(w, false), wf(h, false);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				hf[j] = true;
				wf[i] = true;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		if (wf[i]) {
			for (int j = 0; j < w; j++) {
				if (hf[j]) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}
	return 0;
}

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

using namespace std;

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

    vector<int> v(n);
    int all = 0;
    for(int i=0;i<n;i++){
        cin >>v[i];
        all ^= v[i];
    }

    for(int i=0;i<n;i++)
        cout << (all ^ v[i])<<" ";
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M ;
  
  int i;
  int sum=0;
  for(i=0; i<M; i++){
    int A;
    cin >> A;
    sum += A;
  }
  
  if(N-sum >= 0){
    cout << N-sum <<endl;
  }
  
  else{
    cout << -1 <<endl;
  }
}
    
    


Measured memory_bytes: 3632