akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
int N,M,X,ind;
int C[15];
int a[15][15];
int fun(vector<int> V,int p)
{
    int i,j,x,flag;
    //cout<<endl;
    //for(i=0;i<V.size();i++)
      //  cout<<V[i]<<" ";
    //cout<<"---->";    
    int cost=INT_MAX;
    flag=0;
    //cout<<"aisa slection pr"<<endl;
    for(j=0;j<M;j++)
    {
        x=0;
        for(i=0;i<V.size();i++)
        {
            x+=a[V[i]][j];
        }
        //cout<<j<<" "<<x<<" __ ";
        if(x>=X)
        {
            flag=1;
        }
        else
        {
            flag=0;
            break;
        }
    }
    if(flag==1)
    {
        ind=1;
        cost=0;
        for(i=0;i<V.size();i++)
        {
            cost+=C[V[i]];
        }
    }
    int Z,Y;
    Z=INT_MAX;
    Y=INT_MAX;
    if(p<0)
    return min(cost,min(Z,Y));
    V.pb(p);
    Z=fun(V,p-1);
    V.pop_back();
    Y=fun(V,p-1);
    return min(cost,min(Z,Y));
}
int main()
{
    int i,j,Z,Y;
    cin>>N>>M>>X;
    for(i=0;i<N;i++)
    {
        cin>>C[i];
        for(j=0;j<M;j++)
        {
            cin>>a[i][j];
        }
    }
    //mini=999999999;
    ind=0;
    vector<int> V;
    Z=fun(V,N-1);
    if(ind==1)
    cout<<Z<<endl;
    else
    cout<<-1<<endl;
    return 0;
}

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

int N;
bool ng[15];
int v[15];
bool f[15];
char S[15][15];
int len[15];
inline int getnum(int x){
  int ret = 0;
  for(int i=0;i<len[x];i++,ret*=10)
    ret += v[S[x][i]];
  return ret;
}

inline bool check(){
  int ret = getnum(N-1);  
  for(int i=0;i<N-1;i++)
    if( (ret -= getnum(i)) < 0 ) return false;
  return ret==0;  
}

inline int solve(int c,int m){
  if( c == m )
    return check(); 
  int ret = 0;
  for(int i=0;i<10;i++){
    if( f[i] || (i==0&&ng[c]) ) continue;
    f[i] = 1;
    v[c]=i;
    ret += solve(c+1, m);
    f[i] = 0;
  }
  return ret;
}

int main(){
  while( cin >>N && N ){
    map<char,int> F;
    memset(ng,0,sizeof(ng));
    for(int i=0;i<N;i++){
      cin >> S[i];
      len[i] = strlen(S[i]);
      for(int j=0;j<len[i];j++){
        if( F.count(S[i][j]) == 0 ) F[S[i][j]] = F.size()-1;
        S[i][j] = F[S[i][j]];
        if( j==0 && len[i]>1) ng[S[i][j]]=true;
      }
    }

    int m = F.size();
    memset(f,0,sizeof(f));
    int res = solve(0, m );
    cout << res << endl;
  }
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstring>
#define MAXN 55
using namespace std;

int a[MAXN], b[MAXN];
bool g[MAXN][MAXN], vst[MAXN];
int cnt, n, m;

void dfs(int x) {
	for(int i = 1; i <= n; i++) 
		if(!vst[i] && g[x][i]) {
			vst[i] = 1;
			dfs(i);
		} 
}

int main() {
	bool flag;
	cin >> n >> m;
	for(int i = 1; i <= m; i++) {
		cin >> a[i] >> b[i];
		g[a[i]][b[i]] = g[b[i]][a[i]] = 1;
	}
	for(int i = 1; i <= m; i++) {
		g[a[i]][b[i]] = g[b[i]][a[i]] = 0;
		memset(vst, 0, sizeof vst);
		vst[1] = 1;
		dfs(1);
		flag = 0;
		for(int i = 1; i <= n; i++) 
			if(!vst[i]) flag = 1;
		if(flag) cnt ++;
		g[a[i]][b[i]] = g[b[i]][a[i]] = 1;
	}	
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2000000000
#define MOD 1000000007
#define N 200005
#define M 1000005
#define LOG 19
#define KOK 32000
#define EPS 0.000000001
using namespace std;

int p1[N],pm1[N],a[N];
ll pre[N],pmax[N],smax[N];

int g(int val) {

	if(val<0) return -1;
	if(val==0) return 0;

	return 1;

}

int main() {

	//freopen("input.txt","r",stdin);

	int n,k,x;

	scanf("%d %d",&n,&k);

	ll pos=0;

	for(int i=1;i<=n;i++) {

		scanf("%d",&x);

		a[i]=x;

		pos+=(x>0)*x;

		pre[i]=pre[i-1]+x;

		pmax[i]=pmax[i-1]+max(0,x);

		pm1[i]=pm1[i-1]+(g(x)==-1);
		p1[i]=p1[i-1]+(g(x)==1);

	}

	bool flag=0;

	for(int i=k;i<=n;i++) {

		if(pm1[i]-pm1[i-k]==0 || p1[i]-p1[i-k]==0) flag=1;

	}

	if(flag) {

		printf("%lld",pos);

		return 0;

	}

	for(int i=n;i>=1;i--) {

		smax[i]=smax[i+1]+max(0,a[i]);

	}


	ll ans=-1ll*inf*inf;

	for(int i=1;i<=n-k+1;i++) {

		umax(ans,pmax[i-1]+smax[i+k]+max(0ll,pre[i+k-1]-pre[i-1]));

	}

	printf("%lld",ans);

}



Measured memory_bytes: 6016
#include <iostream>
#include <cstdio>
using namespace std;
int num[200001];
int ans = 1;
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n;i++)
        cin >> num[i];
    if(n==1)
    {
        cout << ans;
        return 0;
    }
    int min;
    min = num[1];
    for (int i = 2; i <= n; i++)
        if(min<num[i])
            continue;
        else
        {
            ans++;
            min = num[i];
        }
            
    cout << ans;
    //system("pause");
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

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

const int inf=1e9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};	

int main(){
	int a,b;
  	cin>>a>>b;
  
  	int sum=0;
  	while(a/b){
      sum++;
      a/=b;
    }

  	cout<<sum+1<<endl;
  	
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}


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

	map<string,int>box;
	rep(i, n){
		cin >> s;
		box[s]++;
	}

	cout << "AC x " << box["AC"] << endl;
	cout << "WA x " << box["WA"] << endl;
	cout << "TLE x " << box["TLE"] << endl;
	cout << "RE x " << box["RE"] << endl;

	return 0;
}


Measured memory_bytes: 3584
# 2018  年 1 月某日、高木さんは書類を書いています。
# 書類には、その日の日付を yyyy/mm/dd という形式で書き込む欄があります。
# 例えば、2018 年 1 月 23 日は 2018/01/23 となります。
# 書類を書き終えたあと、高木さんは日付欄の先頭に誤って 2017 と書いてしまっていたことに気がつきました。
# 高木さんが日付欄に書いた文字列 S を入力すると、
# S の先頭の 4 文字を 2018 に修正して出力するプログラムを書いてください。

s = gets.chomp
s[3] = "8"
puts s

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


int main() {
    int K, S;
    cin >> K >> S;
    int ans = 0;

    for (int x = 0; x <= K; x++) {
        for (int y = 0; y <= K; y++) {
            int z = S - x - y;
            if (0 <= z && z <= K) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(void){
	using namespace std;
	int H, W, i, j;
	while(cin >> H >> W){
		if(H == 0 && W == 0)
			break;
	for(j = 0;j < W; j++){
		cout << "#";
	}
	cout << endl;
	
	for(i = 0; i < H - 2; i++){
		cout << "#";
		for(j = 0; j < W - 2; j++){
			cout << ".";
		}
		cout << "#" << endl;
	}
	
	
	for(j = 0;j < W; j++){
		cout << "#";
	}
	cout << endl << endl;
	}
	return 0;
}


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

#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
    fio;
    ll t, a, n, q, k, i, m, c, u, f, j, p, r, x, y, s, b, d;
    cin >> n;
    vector<int> H, v;
    v.resize(n + 1, 0);
    for (i = 1; i <= n; i++)
        cin >> v[i];
    H.resize(n + 1);
    H[1] =0;
    H[2] =abs( v[2] - v[1]);
    for (i = 3; i <= n; i++)
        H[i] = min(abs(v[i] - v[i - 1]) + H[i - 1], abs(v[i] - v[i - 2]) + H[i - 2]);
    cout << H[n];
    // for(auto h  : H)
    // cout<<h<<" ";
    return 0;
}


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

string S;

int main(void) {

	cin >> S;

	int ans = -1;

	int N = S.size();
	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			string str = S.substr(0, i) + S.substr(j, N - j);
			if (str == "keyence") { ans = 1; }
		}
	}

	if (ans == 1) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int a,b,c,d,k;
void input(){
    fast_io();
    cin >> a >>b >> c >> d >> k;
}

int solve(){
    int T = 60*c+d;
    int S = 60*a+b;
    cout << (T-S-k) << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();
        int ma = h[0];
        int ans = 1;
        for (int i = 1; i < n; i++) {
            if (h[i] >= ma) {
                ans += 1;
                ma = h[i];
            }
        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 21716
#include<cstdio>
#include<vector>


using ll=long long;

int calc(int n, int f, ll v)
{
	int ret=0;

	if(v>n) return 0;
	if(f==7) ret++;
	ret+=calc(n, f|1, v*10+7);
	ret+=calc(n, f|2, v*10+5);
	ret+=calc(n, f|4, v*10+3);
	return ret;
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		printf("%d\n", calc(n, 0, 0));
	}

	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

vector<int> getperm(){
    int w;
    cin>>w;
    vector<int> ret = vector<int>{0,1,2};
    
    rep(i,w){
        int p;
        cin>>p;
        if(p==0)swap(ret[0],ret[1]);
        else    swap(ret[1],ret[2]);
    }
    
    return ret;
}

vector<int> f(vector<int> origin, vector<int> comb){
    vector<int> ret(3);
    rep(i,3){
        ret[i] = origin[comb[i]];
    }
    
    return ret;
}

int main(){
    int n;
    cin>>n;
    vector<vector<int>> v;
    map<vector<int>,int> mp;
    rep(i,n){
        vector<int> t = getperm();
        if(mp[t]<2){
            if(mp[t]==0 or t==vector<int>{2,0,1} or t==vector<int>{1,2,0}){
                v.pb(t);
            }}
        mp[t]++;
    }
    
    
    assert(v.size()<=8);
    
    if(mp[vector<int>{2,0,1}]>=3 or
       mp[vector<int>{1,2,0}]>=3 or
       mp[vector<int>{2,1,0}]>=2 or
       mp[vector<int>{1,0,2}]>=2 or
       mp[vector<int>{0,1,2}]>=2 or
       mp[vector<int>{0,2,1}]>=2){
        cout<<"yes"<<endl;
        return 0;
    }
    
    sort(all(v));
    
    do{
        vector<int> t = v[0];
        if(t==vector<int>{0,1,2}){
            cout<<"yes"<<endl;
            return 0;
        }
        for(int i=1;i<v.size();i++){
            t = f(t,v[i]);
            if(t==vector<int>{0,1,2}){
                cout<<"yes"<<endl;
                return 0;
            }
        }
    }while(next_permutation(all(v)));
    
    cout<<"no"<<endl;
}


Measured memory_bytes: 3172
#include<stdio.h>
#include<stdlib.h>
#include<math.h>


int main(void) {
	int n, v[1000] = { 0 }, ex;
	int i, j;
	double max = 0, sum = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &v[i]);
	}
	for (i = 0; i < n; i++) {
		for (j = i; j < n; j++) {
			if (v[i] < v[j]) {
				ex = v[i];
				v[i] = v[j];
				v[j] = ex;
			}
		}
	}
	sum = (double)v[n-1]/(double)pow(2,n-1);
	for (i = 0; i < n-1; i++) {
		sum += (double)v[i] / (double)pow(2, i + 1);
	}
	printf("%lf", sum);
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

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

    while (in.hasNext()) {
      char[] S = in.next().toCharArray();
      int prevStart = 0;
      int prevEnd = 1;
      int currStart = 1;
      int currEnd = 2;
      int count = 1;
      
      while (currEnd < S.length) {
        if (isEqual (prevStart, prevEnd, currStart, currEnd, S) == false) {
          ++count;
          prevStart = currStart;
          prevEnd = currEnd;
          currStart = currEnd;
          currEnd = currStart + 1;
        } else {
          ++currEnd;
        }
      }
      
      if (currStart < S.length) {
        if (isEqual (prevStart, prevEnd, currStart, currEnd, S) == false) {
          ++count; 
        }
      }

      System.out.println(count);
    }
  }

  static boolean isEqual (int prevStart, int prevEnd, int currStart, int currEnd, char[] s) {
    if (prevEnd - prevStart != currEnd - currStart) {
      return false;
    } else {
      int len = prevEnd - prevStart;

      for (int i = 0; i < len; ++i) {
        if (s[prevStart + i] != s[currStart + i]) {
          return false;
        }
      }

      return true;
    }
  }
}

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

int main() {
    int n,i,max=0,count=0;
    vector<char> s(3);
    for(i=0;i<3;i++){
        cin >> s.at(i);
    }

    for(i=0;i<3;i++){
        if(s.at(i)=='R'){
            count++;
            if(max<count){
                max=count;
            }
        }else{
            count=0;
        }
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    ll val = 0;
    for (auto& a : A) {
        val ^= a;
    }
    for (auto& a : A) {
        cout << (val ^ a) << ' ';
    }
    cout << endl;
    return 0;
}

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

int main()
{
  int x;
  cin >> x;
  if (x == 1)
    cout << "0" << endl;
  else
    cout << "1" << endl;

  return 0;
}

Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int N, M, Q;
    cin >> N >> M >> Q;
    vector< vector<int> > city(N+2, vector<int>(N+2, 0));
    rep(i, M){
        int L, R;
        cin >> L >> R;
        city[R][L] += 1;
    }
    rep(i, N+1) rep(j, N+1) city[i][j+1] += city[i][j];

    rep(_, Q){
        int p, q, ans = 0;
        cin >> p >> q;
        FOR(i, p, q+1) ans += city[i][q] - city[i][p-1];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1920
#include<math.h>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define    ll   long long int
#define    py   printf("Yes\n")
#define    pn   printf("No\n")
#define    in   cin>>
using namespace std;

int main()
{
  int n;
  in n;
  string w[n];
  string check[n];
  bool flag=true;
  rep(i,n)in w[i];
  for(int i=0;i<n-1;i++)
  {
    if(w[i].back()!=w[i+1].front())flag=false;
  }
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      if(w[i]==w[j])flag=false;
    }
  }
  if(flag==true)py;
  else pn;
}


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

using namespace std;

const int kMaxN = 1e5+10;
const long long kInf = (1LL<<60);

vector<int> a, wh;
vector<bool> visited, attached;
vector<vector<int>> G, C;

void DFS(int x) {
	visited[x] = true;
	wh[x] = C.size() - 1;
	C.back().push_back(x);

	for (auto y : G[x]) {
		if (!visited[y]) {
			DFS(y);
		}
	}
}

void Solve() {
	int n, m;

	cin >> n >> m;

	a = wh = vector<int>(n + 1);
	visited = attached = vector<bool>(n + 1);
	G = vector<vector<int>>(n + 1);
	C = vector<vector<int>>();

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

	for (int i = 1; i <= m; ++i) {
		int x, y;
		cin >> x >> y;
		++x;
		++y;
		G[x].push_back(y);
		G[y].push_back(x);
	}

	for (int i = 1; i <= n; ++i) {
		if (!visited[i]) {
			C.push_back(vector<int>());
			DFS(i);
		}
	}

	vector<int> v(n + 1);

	for (int i = 1; i <= n; ++i) {
		v[i] = i;
	}

	sort(v.begin() + 1, v.end(), [&](int x, int y) {
		return a[x] < a[y];
	});

	if (C.size() == 1) {
		cout << 0 << "\n";
		return;
	}

	long long ans = 0;
	int extra = (int)C.size() - 2;

	// cerr << extra << "\n";

	for (int i = 1; i <= n; ++i) {
		int x = v[i];

		// cout << wh[x] << "\n";
		if (!attached[wh[x]]) {
			ans += a[x];
			attached[wh[x]] = true;
		} else if (extra > 0) {
			ans += a[x];
			--extra;
		}

		// cerr << ans << "\n";
	}

	if (extra > 0) {
		cout << "Impossible\n";
		return;
	}

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


int main() {
	int tests = 1;

	for (;tests; --tests) {
		Solve();
	}
}

Measured memory_bytes: 10548
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<tuple>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

int N, M;
int bit[1000001];

void update(int index, int value){
  for(int i=index; i <= M; i += i & -i){
	bit[i] += value;
  }
}

//sum bit[1]~bit[back_index]
int calc_sum(int back_index){
  int sum = 0;
  for(int i=back_index; i >= 1; i -= i & -i){
	sum += bit[i];
  }
  return sum;
}

signed main(){
	cin >> N >> M;
	fill(bit, bit+(M+1), 0);
	vector< tuple<int, int, int> > sourvenir;
	rep(N){
		int l, r;
		cin >> l >> r;
		sourvenir.push_back(make_tuple(r-l+1, l, r));
	}
	sort(all(sourvenir));
	
	vector<int> ans(M+1, 0);
	int i = 0;
	reppp(d, 1, M){
		while(get<0>(sourvenir[i]) <= d && i < N){
			update(get<1>(sourvenir[i]),  1);
			update(get<2>(sourvenir[i])+1, -1);
			i++;
		}
		ans[d-1] += N - i;
		for(int j=d;j<=M;j+=d){
			ans[d-1] += calc_sum(j);
		}
	}
	
	rep(M){
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 6896
import math
import sys
from operator import itemgetter
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':

def gcd(a, b):
	if a > b:
		return gcd(b, a)
	elif a == 0:
		return b
	else:
		return gcd(a, b % a)

N = int(input().rstrip())
As = list(map(int, input().rstrip().split()))

ans = As[0]
for i in As[1:]:
	ans = gcd(ans, i)
print(ans)

Measured memory_bytes: 14380
import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class Main {

    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int n = sc.nextInt();
        int i = 1;
        do {
            int x = i;
            if (x % 3 == 0) {
                System.out.print(" "+i);
                continue;
            }
            do{
                if(x%10==3){
                    System.out.print(" "+i);
                    break;
                }
                x/=10;
            }while(x!=0);
        }while(++i<=n);
        System.out.println();

    }

}

Measured memory_bytes: 28380
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

int main(void){
	string s; cin >> s;
	rep(i, s.length()) cout << "x";

	cout << endl;
	return 0;
}

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


vector<int> Eratosthenes(int N ){
    vector<bool> is_prime( N + 1 );
    for( int i = 0; i <= N; i++){
        is_prime[ i ] = true;
    }

    vector<int> P;
    for( int i = 2; i <= N; i++){
        if( is_prime[ i ] ){
            for( int j = 2 * i; j <= N; j += i ){
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}

vector<int> make_list(int N, int P,vector<int> &prime){
    vector<int> dic;
    int idx = 0;
    auto itr = upper_bound(prime.begin(),prime.end(),N);
    idx = distance(prime.begin(),itr);

    for(int i=idx; i<=(idx+P); i++){
        for(int j=i; j<=(idx+P); j++){
            dic.push_back(prime[i]+prime[j]);
        }
    }

    return dic;
}



int main(){
    vector<int> prime = Eratosthenes(10000000);
    vector<int> ans;

    while(1){
        int N,P;
        cin>>N>>P;

        if(N == -1 && P == -1) break;
        vector<int> M = make_list(N,P,prime);
        sort(M.begin(),M.end());
        ans.push_back(M[P-1]);
    }

    for(auto a : ans) cout<<a<<endl;
    return 0;
}



Measured memory_bytes: 7960
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define mod 1000000007 
#define check exit(0)
#define nl cout<<endl;
#define inp 200005
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define deb(v) for(int i=0;i<v.size();i++) {cout<<v[i]; (i==v.size()-1) ? cout<<"\n":cout<<" "; }
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace __gnu_pbds;
using namespace std;

// Pick yourself up, 'cause...

int main()
{
    jaldi

    int a,b;
    cin>>a>>b;
    cout<<a*b;

    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{string s;
 cin>>s;
 int n=s.size();
 if(s[n-1]!='s')
 {  s.push_back('s');
 cout<<s;
 }
 else{
   s.append("es");
   cout<<s;}
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a;
	cin >> a;

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

	int sa[200001];
	for (int k = 1; k <= a; k++) {
		sa[k] = array[k] - k;
	}
	
	sort(sa + 1, sa + a + 1);

	int marker;

	if (a % 2 == 1) {
		marker = sa[(a + 1) / 2];
	}
	else {
		marker = sa[a / 2];
	}
	
	for (int w = 1; w <= a; w++) {
		if (sa[w] > marker) {
			sa[w] = -marker + sa[w];
		}
		else {
			sa[w] = marker - sa[w];
		}


	}

	long long int sum = 0;

	for (int e = 1; e <= a; e++) {
		sum += sa[e];
	}

	cout << sum;

}

Measured memory_bytes: 1920
import collections
N, M = map(int, input().split())
As = list(map(int, input().split()))
b = [0]*N
b[0] = As[0]
ans = 0
for i in range(1,N):
    b[i] = b[i-1] + As[i]
bmod = [i % M for i in b]
for i in collections.Counter(bmod).values():
    if i >= 2:
        ans += i*(i-1) //2
for i in bmod:
    if i == 0:
        ans += 1
print(ans)

Measured memory_bytes: 18856
#include<stdio.h>
#include<stdlib.h>
long long int h, w, n;
int a[100005], b[100005];
long long int count[10];
int c[100005];
int asc(const void* x, const void* y)
{
	if (a[*(int*)x] > a[*(int*)y])return 1;
	if (a[*(int*)x] < a[*(int*)y])return -1;
	if (b[*(int*)x] > b[*(int*)y])return 1;
	if (b[*(int*)x] < b[*(int*)y])return -1;
	return 0;
}
int f(int x, int y)
{
	if (x <= 0 || y <= 0 || x > h || y > w)
		return -1;
	int min, mid, max;
	min = 0;
	max = n;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (a[c[mid]] > x)
			max = mid;
		else if (a[c[mid]] < x)
			min = mid;
		else if (b[c[mid]] > y)
			max = mid;
		else
			min = mid;
	}
	if (a[c[min]] == x && b[c[min]] == y)
		return 1;
	else
		return 0;
}
int fc(int s, int t,int x,int y)
{
	int res = 0;
	int i, j, k;
	for (i = x; i < x + 3; i++)
	{
		for (j = y; j < y + 3; j++)
		{
			k = f(s + i, t + j);
			if (k < 0)return -1;
			res += k;
		}
	}
	return res;
}
int main()
{
	scanf("%lld %lld %lld", &h, &w, &n);
	int i, j, k;
	for (i = 0; i < n; i++)
		scanf("%d %d", &a[i], &b[i]);
	for (i = 0; i < 10; i++)
		count[i] = 0;
	for (i = 0; i < n; i++)
		c[i] = i;
	qsort(c, n, sizeof(int), asc);
	for (i = 0; i < n; i++)
		for (j = -2; j <= 0; j++)
			for (k = -2; k <= 0; k++)
				if (fc(a[i], b[i], j, k) > 0)
					count[fc(a[i], b[i], j, k)]++;
	long long int p;
	for (p = 1; p < 10; p++)
		count[p] /= p;
	count[0] = (h - 2) * (w - 2);
	for (i = 1; i < 10; i++)
		count[0] -= count[i];
	for (i = 0; i < 10; i++)
		printf("%lld\n", count[i]);
	return 0;
}

Measured memory_bytes: 1788
# coding:utf-8                                                                  

from collections import defaultdict

N, K = map(int, raw_input().split())
As = map(int, raw_input().split())

dic = defaultdict(lambda: 0)

for a in As:
    dic[a] += 1

tar = len(dic) - K

count = 0
if tar <= 0:
    print count
else:
    for i, (k, v) in enumerate(sorted(dic.items(), key=lambda x: x[1])):
        count += v
        if i+1 == tar:
            print count
            break

Measured memory_bytes: 45200
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int F[110][15];
int p[110][15];

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

  int n;
  cin >> n;
  REP(i, n) for(int j=0; j<10;){
    cin >> F[i][j];
    j++;
    cin >> F[i][j];
    j++;
  }
  REP(i, n) REP(j, 11) cin >> p[i][j];

  int ans = -1e9;

  for(int bit=1; bit < (1<<10); bit++){
    int cc = 0;
    REP(i, n){
      int cnt = 0;
      REP(j, 10) if((bit&(1<<j)) && F[i][j]) cnt++;
      cc += p[i][cnt];
    }    
    ans = max(ans, cc);
  }

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


Measured memory_bytes: 256
z[4000],*a=z,*b=z+2000,m,i,j;main(n){for(;!scanf("%d",&n)|n;m=!printf("%d\n",m))for(i=++n;i--;j=a,a=b,b=j)for(j=n;j--;)m=fmax(m,b[j]=n+~i&&getchar()>45?1+fmin(fmin(b[j+1],a[j+1]),a[j]):0);}

Measured memory_bytes: 416
a,b,k = map(int,input().split())
data = range(a,b+1)
b_a = b-a
if b_a < k*2:
  for num in data:
    print(num)
else:
  min_k = data[:k]
  max_k = data[-k:]
  for num in min_k:
    print(num)
  for num in max_k:
    print(num)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int mxN=2001;
ll dp[mxN+1];
int main(){
	ll n,x=0;
	dp[0]=1;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(i>=3){
			x=(x+dp[i-3])%mod;
		}
		dp[i]=x;
	}
	cout<<dp[n];
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    vector<int64_t> t(n);
    for (auto&& tt : t) {
        cin >> tt;
    }

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

    int64_t next_arv = 0, next_dep = 0;
    int64_t ans = 0;
    while (next_dep < t.size()) {
        auto next_arv_time = (next_arv < t.size() ? t[next_arv] : numeric_limits<int64_t>::max());
        auto next_dep_time = t[next_dep] + k;

        while (next_arv_time <= next_dep_time) {
            ++next_arv;
            next_arv_time = (next_arv < t.size() ? t[next_arv] : numeric_limits<int64_t>::max());
        }

        ++ans;
        next_dep = min(next_dep + c, next_arv);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
N, X, Y = map(int, input().split())

ans = [0] * (N - 1)

for i in range(1, N + 1, 1):
    for j in range(i + 1, N + 1, 1):
        tmp = min(
            abs(j - i),
            abs(X - i) + 1 + abs(j - Y),
            abs(X - j) + 1 + abs(i - Y) # このパターンは
        )
        ans[tmp - 1] += 1

for a in ans:
    print(a)

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

int main()
{
    int n;
    cin >> n;
    int a;
    int ans = 0;
    int one = 0;
    int max = 0;
    int min = 1e9 + 7;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a % 2 != 0)
            ans++;
    }
    if (ans != 0)
        cout << "first" << endl;
    else
        cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ld long double
#define ll long long
#define eps 5e-10
#define MN 105
using namespace std;
inline ll in(){
    ll x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
struct vec{
	ll x,y;
	int id;
}a[MN];
struct lin{
	ll a,b,c;
}d[MN];
int q[MN<<1],n,tot;
bool vis[MN];
double res[MN];
ll c,g;
inline vec operator +(vec a,vec b){
	return (vec) {a.x+b.x,a.y+b.y};
}
inline vec operator -(vec a,vec b){
	return (vec) {a.x-b.x,a.y-b.y};
}
inline vec operator *(vec a,ll b){
	return (vec){a.x*b,a.y*b}; 
}
inline vec operator /(vec a,ll b){
	return (vec){a.x/b,a.y/b};
}
inline ll operator ^(vec a,vec b){
	return a.x*b.y-a.y*b.x;
}
inline bool cmp(vec a,vec b){
	return (a.x==b.x)?a.y<b.y:a.x<b.x;
}
inline ll gcd(ll x,ll y){
	return y?gcd(y,x%y):x; 
}
int main()
{
	n=in();if (n==1) {printf("1");return 0;}
	for (int i=0;i<n;++i){
		a[i].x=(in()<<1ll);a[i].y=(in()<<1ll);a[i].id=i;
	}sort(a,a+n,cmp);
	int hd=1,tl=0;
	for (int i=0;i<n;++i){
		while (tl>1&&((a[q[tl]]-a[q[tl-1]])^(a[i]-a[q[tl]]))<=0) --tl;
		q[++tl]=i;	
	}tot=tl;
	for (int i=n-2;i>=0;--i){
		while (tl>tot&&((a[q[tl]]-a[q[tl-1]])^(a[i]-a[q[tl]]))<=0) --tl;
		q[++tl]=i;
	}--tl;
	for (int i=1;i<=tl;++i) q[i-1]=q[i];q[tl]=0;
	for (int i=1;i<=tl;++i) vis[a[q[i]].id]=1;
	for (int i=1;i<=tl;++i){
		vec P=a[q[i%tl]],Q=a[q[i-1]];//printf("i=%d\n",i);
		vec mid=((P+Q)/(2ll)),dif=((P-Q));
		g=gcd(abs(dif.x),abs(dif.y));dif.x/=g;dif.y/=g;
	//	printf("diff:%lld %lld\n",dif.x,dif.y);
	//	if (dif.y<0) dif.x=(-dif.x),dif.y=(-dif.y);
		if (d[i%tl].a*d[i%tl].b>0) d[i%tl].a=dif.x,d[i%tl].b=-dif.y;
		else d[i%tl].a=-dif.x;d[i%tl].b=dif.y;
	//	printf("i:%lld %lld\n",d[i%tl].a,d[i%tl].b);
		//.c=-dif.x*mid.x-dif.y*mid.y;d[i%t\l].c=c;
	}
	
	for (int i=0;i<tl;++i){
		double aa=atan2(d[i].a,d[i].b),ab=atan2(d[(i+1)%tl].a,d[(i+1)%tl].b);//printf("%.10")
		if (aa<0) aa+=(2.0*acos(-1));if (ab<0) ab+=(2.0*acos(-1));
	//	printf("%.10lf %.10lf\n",aa,ab);
	//	printf("i:%lld %lld\n",d[i].a,d[i].b);
	//	printf("i+1:%lld %lld\n",d[(i+1)%n].a,d[(i+1)%n].b);
		res[a[q[i]].id]=ab-aa;if (res[a[q[i]].id]<=0) res[a[q[i]].id]+=2.0*acos(-1);   
	}
	for (int i=0;i<n;++i) if (!vis[i]) printf("%.10lf\n",0.0);
	else printf("%.10lf\n",res[i]/(2.0*acos(-1)));
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N, P;
	cin >> N >> P;

	string S;
	cin >> S;

	long long result = 0;
	if (P == 2 || P == 5)
	{
		for (int i = 0; i < N; i++)
		{
			if ((S[i] - '0') % P == 0)
			{
				result += (i + 1);
			}
		}
	}
	else
	{
		vector<int> base(N, 1);
		for (int i = N - 1; i >= 1; i--)
		{
			base[i - 1] = (base[i] * 10) % P;
		}

		vector<long long> mod_count(P, 0);
		mod_count[0] = 1;

		int mod = 0;
		for (int i = 0; i < N; i++)
		{
			mod = (mod + (S[i] - '0') * base[i]) % P;
			mod_count[mod]++;
		}

		for (long long val : mod_count)
		{
			result += (val * (val - 1)) / 2;
		}
	}

	cout << result;

	return 0;
}

Measured memory_bytes: 1428
n = int(input())
A = list(map(int,input().split()))
q = int(input())
M = list(map(int,input().split()))
dp = dict()

def solve(i,m):
  if m == 0:
    return True
  if i >= n :
    return False
  if m < 0:
    return False
  
  if (i,m) in dp:
    return dp[(i,m)]
  
  res = solve(i + 1 , m) or solve(i + 1 , m - A[i])
  dp[(i,m)] = res
  return res  

for i in M:
  if solve(0,i) :
    print("yes")
  else:
    print("no")



Measured memory_bytes: 9308
#!python3.4.3

n = int(input())
a_list = list(map(int, input().split(' ')))
result = []

c = 0
for i in range(1, n+1):
    for j in range(c, n):
        if i == a_list[j]:
            result.append(i)
            c = j
            break
    if len(result) != i:
        break

if len(result) == 0:
    print(-1)
else:
    print(n - len(result))
        
    


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    int64_t t1, t2;
    cin >> t1 >> t2;
    bitset<41> a, b, x;
    a = t1;
    b = t1 + t2;
    for (auto _ : irange(0L, n - 2)) {
        int64_t t;
        cin >> t;
        x ^= t;
    }

    if (n == 2 && t1 < t2) {
        cout << -1 << endl;
        return 0;
    }

    if ((t1 ^ t2 ^ x.to_ullong()) == 0) {
        cout << 0 << endl;
        return 0;
    }

    cerr << a << "," << b << "," << x << endl;

    array dp{-1L, -1L};
    int64_t s = 0;
    for (auto i : irange(0L, 41L) | reversed) {
        if (b[i]) {
            if (x[i]) {
                if (dp[0] >= 0) {
                    dp[0] += (1L << i);
                }
                dp[1] = -1;
            } else {
                if (dp[1] >= 0) {
                    dp[1] = max(dp[0], dp[1] + (1L << i));
                } else {
                    dp[1] = dp[0];
                }
                dp[0] = -1;
            }
        } else {
            if (x[i]) {
                dp[0] = -1;
                if (dp[1] >= 0) {
                    dp[1] = dp[1] + (1L << i);
                }
            } else {
                if (dp[1] >= 0) {
                    dp[0] = max(dp[0], dp[1] + (1L << i));
                }
                dp[1] = -1;
            }
        }

        int64_t t = t1 & ~((1L << (i + 1)) - 1);
        if (a[i]) {
            if (b[i]) {
                if (x[i]) {
                    if (s == 0) {
                        dp[0] = t;
                    }
                } else {
                    if (s == 0) {
                        dp[1] = t;
                    }
                }
            } else {
                if (x[i]) {
                    if (s == 1) {
                        dp[1] = t;
                    }
                } else {
                    if (s == 0) {
                        dp[0] = t;
                    }
                }
            }
        }

        if (((t1 >> i) ^ ((b.to_ullong() >> i) - (t1 >> i)) ^
             (x.to_ullong() >> i)) == 0) {
            s = 0;
        } else if (((t1 >> i) ^ ((b.to_ullong() >> i) - (t1 >> i) - 1) ^
                    (x.to_ullong() >> i)) == 0) {
            s = 1;
        } else {
            s = 2;
        }

        cerr << i << ":" << s << "," << dp[0] << "," << dp[1] << endl;
    }

    if (dp[0] <= 0) {
        cout << -1 << endl;
        // for (auto d : irange(1L, (int64_t)t1 + 1)) {
        //     assert((d ^ (t2 + (t1 - d))) != x.to_ullong());
        // }
    } else {
        cout << t1 - dp[0] << endl;

        assert((dp[0] ^ (t2 + (t1 - dp[0]))) == x.to_ullong());
        // assert(dp[0] < t1);
        // for (auto d : irange(dp[0] + 1, (int64_t)t1 + 1)) {
        //     assert((d ^ (t2 + (t1 - d))) != x.to_ullong());
        // }
    }

    return 0;
}

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

typedef long lint;
typedef long long llint;

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

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


int main(void) {
    int d, g;
    cin >> d >> g;

    vector<int> p(d);
    vector<int> c(d);
    for(int id=0;id<d;id++) {
        cin >> p.at(id) >> c.at(id);
    }

    int ans = 1e9;
    for(int ipow2d=0;ipow2d<(1<<d);ipow2d++) {
        int sum = 0, tmp = 0, dmax=-1;
        for(int id=0;id<d;id++) {
            if(ipow2d>>id&1) {
                sum += 100 * (id+1) * p.at(id) + c.at(id);
                tmp += p.at(id);
            }
            else dmax = id;
        }
        if(sum<g) {
            int sp = 100*(dmax+1);
            int add = (g - sum + sp - 1) / sp;
            if(add>=p.at(dmax)) continue;
            tmp += add;
        }
        ans = min(ans,tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        abcd: Chars
    };
    let a = abcd[0].to_digit(10).unwrap() as i8;
    let b = abcd[1].to_digit(10).unwrap() as i8;
    let c = abcd[2].to_digit(10).unwrap() as i8;
    let d = abcd[3].to_digit(10).unwrap() as i8;
    let bb = vec![b, -b];
    let cc = vec![c, -c];
    let dd = vec![d, -d];
    for ((b, c), d) in bb.iter().cartesian_product(cc).cartesian_product(dd) {
        if a + b + c + d == 7 {
            println!("{}{:+}{:+}{:+}=7", a, b, c, d);
            return;
        }
    }
}


Measured memory_bytes: 2136
#include<stdio.h>
int main(void){
int a,b,c,d=0;
scanf("%d %d %d",&a,&b,&c);
for(a;a<=b;a++){
  if(c%a!=0){
      continue;
           }
      d++;         
                }
    printf("%d\n",d);
return 0;
}

Measured memory_bytes: 596
use std::io;
use std::str::FromStr;

fn input_char_vec() -> Vec<char> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.chars().collect()
}

fn main() {
    let s = input_char_vec();
    let t = input_char_vec();
    if s[0] == t[2] && s[1] == t[1] && s[2] == t[0] {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

X = int(input())

s = 0
i = 1
while True:
    s += i
    if X <= s:
        print(i)
        break
    i += 1

Measured memory_bytes: 9692
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define MAX_LEN 1001
 
int dataset;
char str_X[MAX_LEN];
char str_Y[MAX_LEN];
 
void LCSLength(char *X, char *Y){
  int m,n;
  int **c;
  int i,j;
 
  m = strlen(X);
  c = malloc(sizeof(int*) * (m+1));
  n = strlen(Y);
  for(i=0; i<=m; i++){
    c[i] = malloc(sizeof(int) * (n+1));
  }
  for(i=1; i<=m; i++){
    c[i][0] = 0;
  }
  for(j=0; j<=n; j++){
    c[0][j] = 0;
  }
  for(i=1; i<=m; i++){
    for(j=1; j<=n; j++){
      if(X[i-1]==Y[j-1]){
        c[i][j] = c[i-1][j-1] + 1;
      }else if(c[i-1][j] >= c[i][j-1]){
        c[i][j] = c[i-1][j];
      }else{
        c[i][j] = c[i][j-1];
      }
    }
  }
  printf("%d\n",c[m][n]);
}
 
int main() {
  int i;
 
  scanf("%d",&dataset);
  for(i=0; i<dataset; i++){
    scanf("%s",str_X);
    scanf("%s",str_Y);
    LCSLength(str_X, str_Y);
  }
  return 0;
}



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

int main()
{
  int n,m;
  string u;
  map<string, bool> mp;

  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> u;
    mp[u] = true;
  }

  string t;
  bool isOpen = false;
  cin >> m;
  for(int j = 0 ; j < m ; j++){
    cin >> t;
    if(mp[t] == true){
      if(isOpen == true){
	cout << "Closed by " << t << '\n';
      }else{
	cout << "Opened by " << t << '\n';
      }
      isOpen = !isOpen; 
    }else{
      cout << "Unknown " << t << '\n';
    }
  }

  
  return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>
#include <string.h>
int main(void){
	char a[502]={0},c[201]={0},e[202]={0};
	int i,j,k,m,b,d,len;
	
	while(1){
		scanf("%s",a);
		if(strcmp(a,"-")==0)
			return 0;
		scanf("%d",&d);
		len = strlen(a);
		for(k=0;k<d;k++){
			scanf("%d",&b);
			for(i=0;i<b;i++)
				c[i] = a[i];
			strcat(a,c);
			for(i=0;i<=b;i++)
				c[i] = '\0';
			for(j=0;j<len;j++)
				e[j] = a[j+b];
			for(m=0;m<len;m++)
				a[m] = e[m];
			a[len] = '\0';
		}
		printf("%s\n",&a);
	}
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

int main()
{
  string S, T;
  cin >> S >> T;
  int n = S.size();
  bool succeeded = false;
  for (int i = 0; i < n; ++i) {
    bool happy = true;
    for (int j = 0; j < n; ++j) {
      if (S[(i + j) % n] != T[j]) {
	happy = false;
	break;
      }
    }
    if (happy) {
      succeeded = true;
      break;
    }
  }
  if (succeeded) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target ("avx,avx2")

using namespace std;

using ll = long long;
#define all(x) begin(x), end(x)

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,x,t; cin >> n >> x >> t;
	if(n%x==0) cout << n/x*t << "\n";
	else cout << (n/x+1)*t << "\n";

}


Measured memory_bytes: 3480
#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 <cmath>

using namespace std;

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

//10^9 + 7
const ll MOD = 1000000007;

int main() {
	ll K;
	string S;

	cin >> K;
	cin >> S;

	string ans = "";
	if (S.size() <= K) {
		ans = S;
	}
	else {
		ans = S.substr(0, K);
		ans += "...";
	}
	cout << ans << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>
int main(){
  int a,b,c,x;
  scanf("%d %d %d",&a,&b,&c);
  if(a > b){
    x=a;
    a=b;
    b=x; 
  }
  if(b > c){
    x=b;
    b=c;
    c=x;
  }
  if(a > b){
    x=a;
    a=b;
    b=x; 
  }
 printf("%d %d %d\n",a,b,c);
 

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
map<int,int>cnt;
int ans=0;
int32_t main()
{
  BOOST;
	int n;
	cin>>n;
	for (int i=1;i<=n;i++){
		int a;
		cin>>a;
		cnt[a]++;
	}
	for (auto it:cnt){
		int a=it.st;
		int b=it.nd;
		if (b>=a)ans+=b-a;
		else ans+=b;
	}
	cout<<ans;
  return 0;
}

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

int X, Y;

int f(int i) {
  if (i == 1) return 300000;
  if (i == 2) return 200000;
  if (i == 3) return 100000;
  return 0;
}

int main() {
  cin >> X >> Y;
  int ans = f(X) + f(Y);
  if (X == 1 && Y == 1) ans += 400000;

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


Measured memory_bytes: 256