akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, m, x; cin >> n >> m >> x;
  vll c(n);
  vvll a(n, vll(m));
  REP(i, n) {
    cin >> c[i];
    REP(j, m) {
      cin >> a[i][j];
    }
  }

  ll ans = LINF;
  REP(i, 1<<n) {
    vll now(m, 0);
    ll tmp = 0;
    REP(j, n) {
      if((i>>j)&1) {
        tmp += c[j];
        REP(k, m) {
          now[k] += a[j][k];
        }
      }
    }
    bool ok = true;
    REP(j, m) {
      ok &= now[j] >= x;
    }
    if(ok) chmin(ans, tmp);
  }
  cout << (ans == LINF ? -1 : ans) << endl;
}
























Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		for(int i = 0; i < N; i++) {
			A[sc.nextInt()-1] = i + 1;
		}
		for(int i = 0; i < N; i++) {
			System.out.println(A[i]);
		}
		sc.close();
	}

}


Measured memory_bytes: 59476
//e
#include <stdio.h>
int main ()
{
	long long int a, sum = 0;
	scanf ("%lld",&a);
	
	for (int i = 1; i <= a; i++)
	{
		if (i%3 == 0 || i%5 == 0)
		{
			continue;
		}
		else
		{
		sum+= i;
		}
	}	
	
	printf ("%lld\n", sum);
	
	return 0;
}

Measured memory_bytes: 1736
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
 
    if op == '?':
        break

    if op == '+':
        print(a + b)

    if op == '-':
        print(a - b)
    
    if op == '*':
        print(a * b)

    if op == '/':
        print(a // b)

Measured memory_bytes: 7568
#pragma GCC optimize("O3")
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200
int nn;
bool u[N];
long long uu;
long long um;
long long p2[N];
vector<int>e[N];
int aa[N];
map<long long, int>mp3;

int solve(int kk) {
	if (mp3[uu] != 0)return (mp3[uu]-1);
	int re, re2;
	long long uu2 = uu;
	long long uu3 = uu;
	long long x = um;
	uu2 >>= kk;
	for (int i = kk; i < nn; i++) {
		if (uu2 & 1 == 1) {
			if (i + 1 == nn) {
				mp3[uu] = aa[nn - 1] + 1;
				return aa[nn - 1];
			}
			uu ^= p2[i];
			re = solve(i + 1);
			f(j, e[i].size()) {
				x ^= p2[e[i][j]];
			}
			uu &= x;
			re2 = solve(i + 1);
			uu = uu3;
			mp3[uu] = max(re2 + aa[i], re) + 1;
			return max(re2 + aa[i], re);
		}
		uu2 >>= 1;
	}
	mp3[uu] = 1;
	return 0;
}


int main() {
	vector<char>c[100];
	char cc[20];
	map<vector<char>, int>mp;
	map<int, int>mp2;
	vector<vector<char> >ab[N];
	vector<char>abb;
	vector<int>ed[N];
	int uuuse[N];
	bool used[N];
	vector<int>use;
	queue<int>q;
	int a[N];
	f(i, N)a[i] = 0;
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	p2[0] = 1;
	f(i, 40)p2[i + 1] = p2[i] * 2;
	while (true) {
		mp.clear();
		scanf("%d", &n);
		if (n == 0)return 0;
		f(i, n) {
			f(j, 20)cc[j] = 0;
			scanf("%s", cc);
			x = strlen(cc);
			c[i].clear();
			f(j, x)c[i].push_back(cc[j]);
			mp[c[i]] = i;
			scanf("%d", &a[i]);
			if (i == 0)ans = a[i];
			scanf("%d", &k);
			ab[i].clear();
			f(ii, k) {
				f(j, 20)cc[j] = 0;
				scanf("%s", cc);
				x = strlen(cc);
				abb.clear();
				f(j, x)abb.push_back(cc[j]);
				ab[i].push_back(abb);
			}
		}
		f(i, n)uuuse[i] = 1000000;
		uuuse[0] = -1;
		for (int i = 1; i < n; i++) {
			f(j, ab[i].size()) {
				x = mp[ab[i][j]];
				if (x == 0)uuuse[i] = -1;
			}
		}
		x = 0;
		f(i, n) {
			if (uuuse[i] >= 0) {
				uuuse[i] = x;
				a[x] = a[i];
				x++;
			}
		}
		k = x;
		f(i, n) {
			if (uuuse[i] >= 0) {
				ed[uuuse[i]].clear();
				f(j, ab[i].size()) {
					x = mp[ab[i][j]];
					if (uuuse[x] >= 0) {
						ed[uuuse[i]].push_back(uuuse[x]);
					}
				}
			}
		}
		n = k;
		f(i, n)used[i] = false;
		f(i, n) {
			if (!used[i]) {
				use.clear();
				mp2.clear();
				x = 0;
				use.push_back(i);
				used[i] = true;
				while (x < use.size()) {
					mp2[use[x]] = x;
					aa[x] = a[use[x]];
					f(j, ed[use[x]].size()) {
						if (!used[ed[use[x]][j]]) {
							use.push_back(ed[use[x]][j]);
							used[ed[use[x]][j]] = true;
						}
					}
					x++;
				}
				f(ii, use.size()) {
					e[ii].clear();
					f(j, ed[use[ii]].size()) {
						if (ii < mp2[ed[use[ii]][j]])e[ii].push_back(mp2[ed[use[ii]][j]]);
					}
				}
				uu = 0;
				um = 0;
				nn = use.size();
				f(ii, N)u[ii] = false;
				f(ii, nn) {
					uu += p2[ii];
					um += p2[ii];
					u[ii] = true;
				}
				mp3.clear();
				x = solve(0);
				ans += x;

			}
		}
		printf("%d\n", ans);
	}


	return 0;
}



Measured memory_bytes: 3116
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
int main()
{
		int a, b, c, s;
		scanf("%d%d", &a, &b);
		s = a * b;
		c = (a + b) * 2;
		printf("%d %d\n", s, c);
	return 0;
}


Measured memory_bytes: 2580
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define PB push_back
#define MP make_pair
#define MOD 1000000007

int main(){
	int N,H[20];
	cin >> N;
	for(int i=0; i<N; i++) cin >> H[i];

	int ans = 0;
	for(int i=0; i<N; i++){
		bool flg = true;
		for(int j=0; j<i; j++){
			if(H[j] > H[i]) flg = false;
		}
		if(flg) ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

template <int mod>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const {
    return ModInt(*this) += p;
  }
  ModInt operator-(const ModInt &p) const {
    return ModInt(*this) -= p;
  }
  ModInt operator*(const ModInt &p) const {
    return ModInt(*this) *= p;
  }
  ModInt operator/(const ModInt &p) const {
    return ModInt(*this) /= p;
  }
  bool operator==(const ModInt &p) const {
    return x == p.x;
  }
  bool operator!=(const ModInt &p) const {
    return x != p.x;
  }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ans(1), mul(x);
    while(n) {
      if(n & 1) ans *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ans;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

LL N;
string S;

ModInt<mod> ans = 1;

void solve(){
	vector<ModInt<mod>> alpha(26,0);
	for(int i=0;i<N;i++){
		alpha[S[i]-'a'] = alpha[S[i]-'a'] + 1;
	}
	for(int i=0;i<26;i++){
		ans *= (alpha[i]+1);
	}
	ans = ans - 1;
}
 
int main(){
    cin >> N;
    cin >> S;
 
    solve();

    cout << ans << endl;
    return 0;
}

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

int main() {
  int n,k;cin>>n>>k;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  rep(i,n-k){
    if(a[i]<a[i+k])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 4656
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 3000000
ll MOD=998244353;

ll inv[N],prd[N],invprd[N];
void calc_inv(){
    inv[1]=1;
    rep2(i,2,N-1){
        inv[i]=((-(MOD/i)*inv[MOD%i])%MOD+MOD)%MOD;
    }
    return;
}
void calc_product(){
    prd[0]=prd[1]=1;
    invprd[0]=invprd[1]=1;
    rep2(i,2,N-1){
        prd[i]=i*prd[i-1]%MOD;
        invprd[i]=inv[i]*invprd[i-1]%MOD;
    }
    return ;
}
ll cmb(ll a,ll b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return prd[a]*invprd[b]%MOD*invprd[a-b]%MOD;
}
ll modpow(ll x,ll n){
    if(n==0) return 1;
    ll res=modpow(x*x%MOD,n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

main(){
    calc_inv();
    calc_product();
    ll n=lin(),m=lin();
    ll ans=0;
    ans=cmb(m*3ll+n-1ll,n-1ll);
    rep2(x,1,m){
        ans=(ans+MOD-n*cmb(m+n-x-2ll,n-2ll)%MOD)%MOD;
        if(cmb(m+n-x-2ll,n-2ll)<0)cout<<0000;
        if(n*cmb(m+n-x-2ll,n-2ll)<0)cout<<000;
        //cout<<ans<<endl;
    }
    ll t=-1;
    ll p=m,q=m;
    rep2(x,m+1,(ll)min(m*3,n)){
        
        if(x>n)break;
        //ans=(ans+MOD-t*cmb(n,x)*cmb(p-q-1,q-1)%MOD)%MOD;
        if(n==x){
            if(m*3==n)
            ans=(ans+MOD+t*cmb(p,q)%MOD)%MOD;
            //cout<<ans<<endl;
        }
        if((m*3-x)%2)continue;
        ans=(ans+MOD+t*cmb(n,x)%MOD*cmb((m*3-x)/2+n-1,n-1)%MOD)%MOD;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 70528
#include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v._size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v._size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,from,n) for(int i=from;i<n;i++)
    #define FOL(i,from,n) for(int i=from;i >= n;i--)

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;

        ll pow(ll base, ll q, ll mod){
            ll answer = 1;
            while(q > 0){
                if(q & 1LL)
                    answer = (answer * base) % mod;

                q = q >> 1LL;
                base = (base*base) % mod;
            }
            return answer % mod;
        }

        

        

        

        void solve1(){
            cin >> n;
            string s1,s2;
            cin >> s1 >> s2;
            if(s1 == s2){
                cout << "0\n";
                return;
            }
            int len1 = 0, len2 = 0;
            for(int i=0;i < n; i++){
                if(s1[i] == '1') len1++;
                if(s2[i] == '1') len2++;
            }
            if(len1 != len2) {cout << "-1\n"; return;}
        }


        void solve(){
            cin >> n;
            ll arr[n+1];
            ll sum = 0;
            map<ll,ll> mp;
            for(int i=1; i <= n; i++){
                cin >> arr[i];
                mp[arr[i]]++;
                sum += arr[i];
            }

            cin >> q;
            while(q--){
                cin >> a >> b;
                ll freq = mp[a];
                sum -= a*freq;
                mp[a] = 0;
                mp[b] += freq;
                sum += freq*b;
                cout << sum << endl;
            }
        }



       
    


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

        
            

            int cases = 1;
            //cin >> cases;

            while(cases--) solve();
            return 0;

        }

Measured memory_bytes: 10256
#include <bits/stdc++.h>
// #include <chrono>
// #include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846
 
ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}
 
int pow(int a,int b){
	if(b == 0)return 1;
	int res = pow(a,b/2);
	res = res*res;
	if(b&1)res *= a;
	return res;
}



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

// int t;
// cin >> t;
// while(t--){



// }


int n,k;
cin >> n >> k;
n = n%k;
cout << min(n,k-n) << endl;



return 0;
	
	}


Measured memory_bytes: 3660
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 100000
#define INF (NUM_MAX+1)

int main(void) {
    int num, size;
    get_int2(&num, &size);
    static int arr[NUM_MAX];
    fget_array(arr, num);
    num -= size;
    int cnt = 1;
    while(num>0) {
        num -= (size-1);
        cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    int arr[n];

    for (int i = 0; i < n; i++) {
        arr[i] = -1;
    }

    bool invalid = false;
    for (int i = 0; i < m; i++) {
        int s, c;
        cin >> s >> c;
        if (arr[s - 1] != -1 && arr[s - 1] != c) {
            invalid = true;
        } else {
            arr[s - 1] = c;
        }
    }

    if (invalid || (n > 1 && arr[0] == 0)) {
        cout << -1;
        return 0;
    }

    if (n == 1) {
        if (arr[0] == -1) {
            cout << 0;
        } else {
            cout << arr[0];
        }
        return 0;
    }

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

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    string  s;
    cin>>s;
    if(s=="A") cout<<"T"<<endl;
    else if(s=="T") cout<<"A"<<endl;
    else if(s=="C") cout<<"G"<<endl;
    else cout<<"C"<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
//const long long MOD = 1000000007LL;
const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll r,D,x; cin >> r >> D >> x;

    rep(_,10) {
        x = r*x - D;
        cout << x << endl;
    }
}


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

using namespace std;

int main()
{
	int a, b, c, d, e;

	cin >> a >> b >> c >> d >> e;
	vector<int> nums{a, b, c, d, e};

	int min = a;
	int min_digit = a % 10;

	for (int i = 0; i < nums.size(); i++)
	{
		if (nums[i] % 10 == 0) continue;
		if (nums[i] % 10 < min_digit)
		{
			min = nums[i];
			min_digit = nums[i] % 10;
		}
	}

	int result = 0;
	bool used = false;
	for (int i = 0; i < nums.size(); i++)
	{
		if (nums[i] == min && !used)
		{
			result += nums[i];
			used = true;
		}
		else
		{
			if (nums[i] % 10 == 0)
			{
				result += nums[i];
			}
			else
			{
				result += (floor(nums[i] / 10.0) + 1) * 10;
			}
		}
	}

	cout << result << endl;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

const ll mod = 1000000007;

struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) {  //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {  // xとyの木を併合
    int rx = root(x);         // xの根をrx
    int ry = root(y);         // yの根をry
    if (rx == ry) return;  // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry;  // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  ll n;
  cin >> n;
  vP xl(n);
  vP yl(n);
  vT eds;

  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    xl[i] = P(x, i);
    yl[i] = P(y, i);
  }
  Sort(xl);
  Sort(yl);

  rep(i, n - 1) {
    ll posi = xl[i].first;
    ll posip1 = xl[i + 1].first;
    ll wt = abs(posi - posip1);
    ll s = xl[i].second;
    ll t = xl[i + 1].second;
    eds.push_back(T(wt, s, t));
  }

  rep(i, n - 1) {
    ll posi = yl[i].first;
    ll posip1 = yl[i + 1].first;
    ll wt = abs(posi - posip1);
    ll s = yl[i].second;
    ll t = yl[i + 1].second;
    eds.push_back(T(wt, s, t));
  }

  // Kruscal's algorithm
  Sort(eds);  
  UnionFind uf(n);
  ll ans = 0;
  for (auto e : eds) {
    ll wt, s, t;
    tie(wt, s, t) = e;
    if(!uf.same(s, t)){
      ans += wt;
      uf.unite(s, t);
    }
  }

  cout << ans << endl;

  return 0;
}


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

class solver{
    string name;
    int am;
    int pm;
public:
    void put_name(string str){
        name = str;
    }
    string show_name(){
        return name;
    }
    void put_am(int n){
        am = n;
    }
    void put_pm(int n){
        pm = n;
    }
    int sum(){
        return am+pm;
    }
    int income(){
        return 200*am + 300*pm;
    }
    void print(){
        cout << name;
        cout << " ";
        printf("%d %d\n", sum(), income());
    }
};


int main(){
    vector<solver> a(9);
    string tmp;
    int n, m;

    for(int i=0; i<9; i++){
        cin >> tmp;
        a[i].put_name(tmp);
        cin >> n >> m;
        a[i].put_am(n);
        a[i].put_pm(m);
    }

    for(int i=0; i<9; i++){
        a[i].print();
    }

    return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

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

int main(){
    int N; cin >> N;
    string X; cin >> X;
    vector<ll> f(N);
    ll cnt=0;
    for(int i=0; i<N; i++){
        if(X[i] == '1') cnt++;
    }
    // choose 0 or 1
    ll r0=0, r1=0;
    for(ll i=0; i<N; i++){
        if(X[i] == '1'){
            r0=(r0+modpow(2, N-i-1, cnt+1))%(cnt+1);
            if(cnt > 1) r1=(r1+modpow(2, N-i-1, cnt-1))%(cnt-1);
        }
    }
    for(ll i=0; i<N; i++){
        if(X[i] == '0'){
            ll val=(r0+modpow(2, N-i-1, cnt+1))%(cnt+1);
            if(val < 0) val+=(cnt+1);
            int res=1;
            while(val != 0){
                val%=__builtin_popcountll(val);
                res++;
            }
            f[i]=res;
        }
        else{
            if(cnt == 1){
                f[i]=0;
                continue;
            }
            ll val=(r1-modpow(2, N-i-1, cnt-1))%(cnt-1);
            if(val < 0) val+=(cnt-1);
            int res=1;
            while(val != 0){
                val%=__builtin_popcountll(val);
                res++;
            }
            f[i]=res;
        }
    }
    for(int i=0; i<N; i++){
        cout << f[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5192
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int INF = 1e18 + 13, maxN = 2e5 + 13;;
int n, ans = INF, mxy, mxx, mnx = INF, mny = INF, x[maxN], y[maxN];
int arr[maxN];

bool cmp (int i, int j) {
    if (x[i] != x[j])
	return x[i] < x[j];
    if (y[i] != y[j])
	return y[i] < y[j];
    return i < j;
}

int32_t main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
	cin >> x[i] >> y[i];
	if (y[i] < x[i])
	    swap(x[i], y[i]);
	mnx = min(mnx, x[i]);
	mxx = max(mxx, x[i]);
	mny = min(mny, y[i]);
	mxy = max(mxy, y[i]);
    }
    iota(arr, arr + n, 0);
    sort(arr, arr + n, cmp);
    int mn = INF, mx = mxx;
    for (int i = 1; i < n; i++) {
	mx = max(mx, y[arr[i - 1]]), mn = min(mn, y[arr[i - 1]]);
	ans = min(ans, (mxy - mnx) * (mx - min(x[arr[i]], mn)));
    }
    cout << min(ans, (mxx - mnx) * (mxy - mny)) << endl;
    return 0;
}

Measured memory_bytes: 4992
from itertools import accumulate

N = int(input())
a = list(map(int, input().split())) 

b = list(accumulate(a))
ma = b[-1]
mi = 10**10
for sunuke in b[:N-1]:
    arai = ma - sunuke
    if abs(sunuke - arai) < mi:
        mi = abs(sunuke - arai)
print(mi)

Measured memory_bytes: 102516
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    int m, n, s;
    cin >> n >> m;
    int a[n][m], b[m];
    int ans[n];
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < m; j ++){
            cin >> s;
            a[i][j] = s;
        }
    }
    for(int i = 0; i < m; i ++){
        cin >> s;
        b[i] = s;
    }
    for(int i = 0; i < n; i ++){
        ans[i] = 0;
        for(int j = 0; j < m; j ++){
            ans[i] += a[i][j] * b[j];
        }
    }
    for(int i = 0; i < n; i ++){
        cout << ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3124
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n;i>0;i--)
#define  REP(i,a,b) for(int i=a;i<b;i++)
typedef long long int lld;
typedef vector<lld> vl;
typedef vector<int> vi;
typedef vector<string> vs;


//int arr[N]
////sort(arr,arr +N)
//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();


int map[100][100];
vi cl(1000);
vi ol(1000);


void print(int n);
void next(int locate);

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if((a<c && b>c) ||(c>b && c<a)){
		cout<<"Yes";
		return 0;
	}
	else{
		cout<<"No";
	}

}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define ll long long
#define re register
#define inf 0x3f3f3f3f
using namespace std;
bitset<4000007>f;
inline int read(){
   int x=0,w=0;char ch=getchar();
   while (!isdigit(ch))w|=ch=='-',ch=getchar();
   while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
   return w?-x:x;
}
int main(){
	int sum=0;
	int n=read();f[0]=1;
	for (int i=1;i<=n;++i){
		int x=read();
		f|=f<<x;
		sum+=x;
	}
	for (int i=(sum+1)/2;i<=sum;++i)
		if (f[i]){
			printf("%d",i);
			return 0;
		}
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

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

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

    // 素数である
    return num;
}

vector<ll> factorList(ll x) {
  vector<ll> res;
  while (x != 1) {
    res.push_back(f(x));
    x /= f(x);
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  map<int, int> M;
  if(n==1){
    cout << "1" << endl;
    return 0;
  }
  ll ans=1;
  while(n>1){
    vector<ll> fac=factorList(n);
    rep(i, fac.size()){
      M[fac[i]]++;
    }
    n--;
  }
  for(auto a: M){
    ans*=(a.second+1)%mod;
    ans%=mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int f=1,x=0;
    char ch;
    do{
        ch=getchar();
        if(ch=='-'){
            f=-1;
        }
    }while(ch<'0'||ch>'9');
    do{
        x=x*10+ch-48;
        ch=getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}
inline int cmp(int a,int b){
    if(a>b){
        return a;
    }
    else{
        return b;
    }
}
int main(){
    int a=read(),b=read(),c=read();
    if(a*b>c){
        cout<<c<<endl;
    }
    else{
        cout<<a*b<<endl;
    }
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string s;

int main() {
	cin >> s;
	
	int n = s.size();
	int g = 0, p = 0;
	inc(i, n) {
		(s[i] == 'g' ? g : p)++;
	}
	
	cout << (g - p) / 2 << endl;
	
	return 0;
}


Measured memory_bytes: 512
import numpy as np

s = int(input())
A = list(map(int, input().split()))

A = np.array(sorted(A))
ans = A[0]
np.delete(A, 0)

while True:
    B = A % ans
    C = B[B != 0]
    if len(C) == 0:
        break
    ans = min(C)
    B = C

print(ans)

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];
    sort(A.begin(), A.end());
    int ans = A[N - 1] - A[0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define q(x)(x<0x40?x^1:x)
char a[99];main(i,l,r){scanf("%s",a);l=strlen(a);for(r=i=0;i<l/2;i++)if(a[i]!=q(a[l-1-i]))r++;if((l%2)&&a[i]!='i'&&a[i]!='w')r++;printf("%d\n",r);exit(0);}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
vector<ll> C[404];
ll VV[404];
int R[404];
map<ll,int> B[5];

ll getkey(vector<ll> v) {
	ll r=1LL<<60;
	int i;
	FOR(i,4) {
		rotate(v.begin(),v.begin()+1,v.end());
		r=min(r,v[0]*1000000000+v[1]*1000000+v[2]*1000+v[3]);
	}
	return r;
}

ll dfs(int cur,int n1,int n2,int n4) {
	if(cur==0) return 1;
	ll ret=0;
	if(n1) ret += n1*dfs(cur-1,n1-1,n2,n4);
	if(n2) ret += 2*n2*dfs(cur-1,n1,n2-1,n4);
	if(n4) ret += 4*n4*dfs(cur-1,n1,n2,n4-1);
	return ret;
}

void solve() {
	int i,j,k,l,r,x,y,z; string s;
	
	cin>>N;
	FOR(i,N) {
		vector<ll> V(4,0);
		FOR(j,4) cin>>V[j];
		C[i]=V;
		VV[i]=getkey(C[i]);
		R[i]=1;
		if(C[i][0]==C[i][2]&&C[i][1]==C[i][3]) {
			R[i]=2;
			if(C[i][0]==C[i][1]) R[i]=4;
		}
		B[R[i]][VV[i]]++;
	}
	ll ret=0;
	FOR(x,N) {
		B[R[x]][VV[x]]--;
		for(y=x+1;y<N;y++) {
			B[R[y]][VV[y]]--;
			FOR(z,4) {
				
				map<ll,int> mp;
				mp[getkey({C[x][1],C[x][0],C[y][1],C[y][0]})]++;
				mp[getkey({C[x][2],C[x][1],C[y][0],C[y][3]})]++;
				mp[getkey({C[x][3],C[x][2],C[y][3],C[y][2]})]++;
				mp[getkey({C[x][0],C[x][3],C[y][2],C[y][1]})]++;
				
				ll tmp=1;
				FORR(r,mp) {
					tmp *= dfs(r.second,B[1][r.first],B[2][r.first],B[4][r.first]);
					if(tmp==0) break;
				}
				ret += tmp;
				
				rotate(C[y].begin(),C[y].begin()+1,C[y].end());
				
			}
			B[R[y]][VV[y]]++;
		}
		B[R[y]][VV[x]]++;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

ll N, M;
vector<ll> a, b;
vector<vector<int>> movesima;

int main() {
    cin >> N >> M;
    movesima.resize(N+1); a.resize(M); b.resize(M);
    for (int i = 0; i < M; i++) scanf("%Ld %Ld", &a[i], &b[i]);
    for (int i = 0; i < M; i++) {
        movesima[a[i]].push_back(b[i]);
        movesima[b[i]].push_back(a[i]);
    }
    int flag = 1;
    for (int i = 0; i < movesima[1].size() && flag; i++) {
        for (int j = 0; j < movesima[movesima[1][i]].size() && flag; j++) {
            if (movesima[movesima[1][i]][j] == N) flag = 0;
        }
    }
    string ans = flag ? "IMPOSSIBLE" : "POSSIBLE";
    cout << ans << endl;

}


Measured memory_bytes: 15088
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>
#include <vector>
#include <cstring>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <map>
#include <stack>
#include <iterator> 
#define LL long long 
using namespace std;

int main()
{
	int h,w,a,b;
	scanf("%d%d%d%d",&h,&w,&a,&b);
	if(a*2>w||b*2>h)
		cout<<-1;
	else
	{
		for(int i=1;i<=h;i++)
		{
			for(int j=1;j<=w;j++)
			{
				if((i<=b&&j<=a)||(i>b&&j>a))
					cout<<1;
				else
					cout<<0;
			}
			cout<<"\n";
		}
	}
}

Measured memory_bytes: 1280
// D - Integer Cards
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<pair<int, int> > t(m);
	for (int i = 0; i < m; i++) cin >> t[i].second >> t[i].first;
	sort(a.begin(), a.end());
	sort(t.begin(), t.end(), greater<pair<int, int> >());
	long long sum = 0;
	int k = 0;
	for (int i = 0; i < m; i++)
		for (int j = 0; j < t[i].second && k < n; j++)
			if (t[i].first > a[k]) {
				sum += t[i].first;
				k++;
			} else
				break;
	for ( ; k < n; k++) sum += a[k];
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#define MAX 100

int main(void){
  int A[MAX];
  int N;
  std::cin >> N;
  for(int i=0;i<N;i++){
    std::cin >> A[i]; 
  }
  for(int i=0;i<N;i++){
    // Even?
    if(A[i]%2 == 0){
      // 3 or 5で割り切れる　ということは　どちらでも割り切れないならダメ
      if(A[i]%3 != 0 && A[i]%5 != 0){
	std::cout << "DENIED" << std::endl;
	return 0;
      }
    }
  }
  // FINISH = APPROVE
  std::cout << "APPROVED" << std::endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys

# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# A,B = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
# A, B = [str(x) for x in stdin.readline().rstrip().split()]
N = int(input())
S = list(input())
r = []
g = []
b = []
for i in range(N):
    if S[i] == 'R':
        r.append(i+1)
    elif S[i] == 'G':
        g.append(i+1)
    else:
        b.append(i+1)
# print(r)
# print(g)
# print(b)
cnt = len(r)*len(g)*len(b)
for i in range(N):
    for j in range(i+1, N):
        k = 2*j-i
        if k < N and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            cnt -= 1
print(cnt)


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

int main() {
	int n;
	string s;
	cin >> n >> s;
	vector<int> w(n + 1);
	for (int i = 0; i < n; i++)
		if (s[i] == '#')
			w[i + 1] = w[i] + 1;
		else
			w[i + 1] = w[i];
	int ans = 2e5;
	for (int i = 0; i <= n; i++)
		ans = min(ans, w[i] + n - i - (w[n] - w[i]));
	cout << ans << endl;
}

Measured memory_bytes: 1412
# def chkzero(x,k,d):
#     if(x == 0):
#         if(k%2 ==1):
            
#             print(d)
#         else:
#             print(0)
#         k=0
#     return k
    

x, k, d = map(int, input().split())
#origin reach check
minans=abs(x)+d
while(k>0):
    if(x==0):
        if(k%2==1):
            minans=d
        else:
            minans=0
        break
    if(x<0):
        x=x*(-1)
    steps= x//d
    if(steps<=k):
        k=k-steps
        x=x-d*steps
        #minans=min(minans,x)
        if(k%2==1):
            minans=min(abs(x-d),minans)
        else:
            minans=min(x,abs(x-2*d),minans)
        break
    else:
        x=x-k*d
        k=0
        minans=min(x,minans)
        break
print(minans)

Measured memory_bytes: 9216
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI 3.14159265358979323846264338327950L

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

ll gcd(ll a, ll b){
    if(a % b == 0){
        return(b);
    }
    else{
        return(gcd(b, a % b));
    }
}

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

// ll N, M, K, Q, i, j, k, l, tmp, ans;

int main(){
    ll A, B;
    double b;

    cin >> A >> b;
    B = b * 100 + .5;
    printf("%llu\n", (ull)(A * B) / 100);

    return 0;
}

Measured memory_bytes: 3808
str = gets.to_s
q = gets.to_i
w = []

q.times do
    x, a, b, q = gets.split.map(&:to_s)
    a = a.to_i
    b = b.to_i

    case x
    when "reverse" then
        str[a..b] = str[a..b].reverse
    
    when "replace"
        str[a..b] = str[a..b].replace(q)
    
    when "print" then
        puts str[a..b]
    
    end
end

Measured memory_bytes: 8720
def check(x, y, z):
    return 10000*x + 5000*y + 1000*z

def main():
    N, Y = map(int, input().split())
    for x in range(2001):
        if 10000*x > Y:
            break
        for y in range(0, 2001):
            z = N - (x+y)
            if z < 0:
                break
            if check(x, y, z) == Y:
                ans = (x, y, z)
                print(*ans)
                return
            if check(x, y, z) > Y:
                break
    ans = [-1, -1, -1]
    print(*ans)

if __name__ == "__main__":
    main()


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

int main(){
    int n;
    cin >> n;
    ll sum = 0;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum ^= a[i];
    }
    for(int i = 0; i < n; i++){
        ll ans = sum ^ a[i];
        cout << ans << endl;
    }
}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {

  int N;
  cin >> N;

  map<int, int> m;

	for (int i = 2; i <= sqrt(N); i++) {
		while (N%i == 0) { // 素数で割り切れなくなるまで割っていく
			m[i]++; //割った個数を配列に足す
			N /= i;      
      if(N == 1){
        goto end;
      }
		}
	}
  if(N != 1){
    m[N]++;
  }

end:

  int tmp;
  int ans = 0;

  for(auto it = m.begin(); it != m.end(); it++){
    tmp = it->second;
    int i = 1;
    while(tmp >= i){
      tmp -= i;
      ans++;
      i++;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

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

  int n, m, k;
  cin >> n >> m >> k;
  
  n = max(n, m);
  cout << (k + n - 1) / n;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}
#define centering center=(right-left)/2+left

main(){
	int n,k,i,p,tmpI,flag,max,center,left,right;
	int *w;
	scanf("%d %d",&n,&k);
	mymalloc(w,n+1);
	w[0]=0;
	max=0;
	for(i=1;i<=n;i++){
		scanf(" %d",&w[i]);
		if(max<w[i]){max=w[i];}
		w[i]+=w[i-1];
	}
	if(w[n]/k>max){
		p=w[n]/k;
	}else{
		p=max;
	}
	
	while(1){
		tmpI=0;
		for(i=1;i<k;i++){
			left=tmpI;
			right=n;
			centering;
			flag=0;
			while(right-left>1){
				if(w[center]>p+w[tmpI]){
					right=center;
					centering;
				}else{
				if(w[center]<p+w[tmpI]){
					left=center;
					centering;
				}else{
					tmpI=center;
					flag=1;
					break;
				}}
			}
			if(flag!=1){
				tmpI=left;
			}
		}
		if(w[n]<=w[tmpI]+p){
			break;
		}
		p++;
	}
	printf("%d\n",p);
	free(w);
	return 0;
}
		

Measured memory_bytes: 888
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n;
  cin>>n;
  
  vector<int> A(n);
  rep(i,n) cin>>A[i];
  
  sort(ALL(A));
  reverse(ALL(A));
  
  int m=n-1;
  ll ans=0;
  for(int i=1;i<n;i++){
    ans+=A[i/2];
  }
  
  cout<<ans<<endl;

  return 0;
}

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

const int MAXN = 101;
int m, n;
map<string, int> lb, ub;
string e[MAXN];

int main() {
  while(cin >> m) {
    lb.clear(); ub.clear();
    for(int i = 0; i < m; ++i) {
      string name; cin >> name;
      cin >> lb[name] >> ub[name];
    }
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> e[i];
    try {
      stack<vector<int> > stk;
      for(int i = 0; i < n; ++i) {
        const string &s = e[i];
        if(isdigit(s[0])) {
          vector<int> v(256);
          v[atoi(s.c_str())] = 1;
          stk.push(v);
        } else if(isalpha(s[0])) {
          vector<int> v(256);
          for(int i = lb[s]; i <= ub[s]; ++i) v[i] = 1;
          stk.push(v);
        } else {
          vector<int> a, b, v(256);
          b = stk.top(); stk.pop();
          a = stk.top(); stk.pop();
          for(int i = 0; i < a.size(); ++i) {
            if(!a[i]) continue;
            for(int j = 0; j < b.size(); ++j) {
              if(!b[j]) continue;
              if(s[0] == '+') {
                v[(i+j)%256] = 1;
              } else if(s[0] == '-') {
                v[(i-j+256)%256] = 1;
              } else if(s[0] == '*') {
                v[i*j%256] = 1;
              } else if(s[0] == '/') {
                if(j == 0) throw 0;
                v[i/j] = 1;
              }
            }
          }
          stk.push(v);
        }
      }
      cout << "correct" << endl;
    } catch(...) {
      cout << "error" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1320
n, m = map(int, input().split())
sl = []
cl = []
ans = [-1] * n
a = ""
for _ in range(m):
    s, c = map(int, input().split())
    sl.append(s)
    cl.append(c)
    if ans[s - 1] == -1:
        ans[s - 1] = c
    elif ans[s - 1] == c:
        continue
    else:
        ans[s - 1] = -10
        break

if ans.count(-10) > 0:
    print(-1)
else:
    if n == 1:
        if ans[0] == -1:
            print(0)
        else:
            print(ans[0])
    else:
        for i in range(n):
            if i != n - 1 and ans[i] == 0:
                print(-1)
                exit()
            elif ans[i] == -1 and i == 0:
                ans[i] = 1
            elif ans[i] == -1 and i != 0:
                ans[i] = 0
        for i in ans:
            a += str(i)
        print(a)


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

vector<vector<ll>> G;
vector<pair<ll, ll>> V;
vector<bool> f;

void dfs(ll v, ll a, ll b)
{
	if (f[v]) return;

	f[v] = true;

	for (auto &nv : G[v])
	{
		if ((a == v && b == nv) || (b == v && a == nv)) continue;
		dfs(nv, a, b);
	}
}

int main(int argc, char **argv)
{
	ll N, M; cin >> N >> M;
	G.resize(N);
	V.resize(M);

	REP(m, M)
	{
		ll a, b; cin >> a >> b;
		--a, --b;
		V[m] = pair<ll, ll>(a, b);
		G[a].push_back(b);
		G[b].push_back(a);
	}

	ll res{0};
	REP(m, M)
	{
		f.assign(N, false);
		ll tmp{0};
		REP(n, N)
		{
			if (!f[n])
			{
				dfs(n, V[m].first, V[m].second);
				++tmp;
			}
		}

		if (tmp > 1)
			++res;
	}
	std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    string s;
    cin>>s;
    int i,cnt=s.size()-2;
    while (cnt>0)
    {
        int oc=0;
        for (i=0;i<cnt/2;i++)
        {
            if (s[i]!=s[cnt/2+i])
            {
                oc=1;
                break;
            }
        }
        if (!oc)
            break;
        cnt-=2;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using System;
class Program
{
    static void Main()
    {
        //a: 97, z: 122
        string line = Console.ReadLine();
        int length = line.Length;
        bool[] foundAlp = new bool[26];
        for (int i = 0; i < length; i++)
        {
            char dsg = line[i];
            int index = (int)dsg - 97;
            foundAlp[index] = true;
        }


        int num = -1;
        for (int i = 0; i < 26; i++)
        {
            if (foundAlp[i] == false)
            {
                num = i + 97;
                break;
            }
        }

        if(num == -1)
        {
            Console.WriteLine("None");
        }
        else
        {
            Console.WriteLine((char)num);
        }
    }
}

Measured memory_bytes: 11232