akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int X, N;
set<int> p;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> X >> N;
	rep(i, 0, N) {
		int x; cin >> x;
		p.insert(x);
	}

	int ans = inf, diff = inf;
	rep(y, 0, 102) if (!p.count(y)) {
		int d = abs(y - X);
		if (d < diff) ans = y, diff = d;
	}
	cout << ans << endl;
}







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

int main() {
	int right_a = 0, right_b = 0, right_c = 0, right_d = 0;
	int left_a = 0, left_b = 0, left_c = 0, left_d = 0;
	double right_eye, left_eye;
	while (cin >> left_eye >> right_eye) {
		if (left_eye >= 1.1)left_a++;
		else if (left_eye >= 0.6&&left_eye < 1.1)left_b++;
		else if (left_eye >= 0.2&&left_eye < 0.6)left_c++;
		else if (left_eye < 0.2)left_d++;
		if (right_eye >= 1.1)right_a++;
		else if (right_eye >= 0.6&&right_eye < 1.1)right_b++;
		else if (right_eye >= 0.2&&right_eye < 0.6)right_c++;
		else if (right_eye < 0.2)right_d++;
	}
	cout << left_a << ' ' << right_a << endl;
	cout << left_b << ' ' << right_b << endl;
	cout << left_c << ' ' << right_c << endl;
	cout << left_d << ' ' << right_d << endl;
}

Measured memory_bytes: 3156
a,b, c = map(int, input().split())
turn_a =[x for x in range(1,a+1)]
turn_b=[y for y in range(1,b+1)]
ans=[x for x,y in zip(turn_a,turn_b) if a%x==0 and b%y==0]
ans.reverse()
print(ans[c-1])

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

int main(){
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2]) cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

namespace ABC_166c
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] count = new int[input[0]];
            long[] high = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            

            for(int i = 0; i < input[1]; i++)
            {
                string[] bridge = Console.ReadLine().Split(' ');
                
                if(high[int.Parse(bridge[0])-1] > high[int.Parse(bridge[1])-1])
                {
                    count[int.Parse(bridge[1])-1] -= 1;
                }
                else if(high[int.Parse(bridge[0])-1] < high[int.Parse(bridge[1])-1])
                {
                    count[int.Parse(bridge[0])-1] -= 1;
                }
                else
                {
                    count[int.Parse(bridge[0])-1] -= 1;
                    count[int.Parse(bridge[1])-1] -= 1;
                }
            }

            int res = 0;

            for (int j = 0; j < count.Length; j++)
            {
                if (count[j] == 0)
                {
                    res++;
                } 
            }

            Console.WriteLine(res);
            Console.Read();
        }
    }
}


Measured memory_bytes: 46700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int co[2][4];
double l, r;

int main(){
	while (cin >> l >> r){
		if (1.1 - l < EPS) co[0][0]++;
		else if (0.6 - l < EPS) co[0][1]++;
		else if (0.2 - l < EPS) co[0][2]++;
		else co[0][3]++;
		if (1.1 - r < EPS) co[1][0]++;
		else if (0.6 - r < EPS) co[1][1]++;
		else if (0.2 - r < EPS)	co[1][2]++;
		else co[1][3]++;
	}
	REP(j, 4){
		cout << co[0][j] << " " << co[1][j] << endl;
	}
}

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

int main() {
  int64_t n;
  int64_t ave;
  cin >> n >> ave;
  int64_t x[n+1];
  x[0]=0;
  for(int i=1; i<=n; i++) cin >> x[i];
  
  int64_t a=n; // x_a番目に書かれた数まで考慮
  int64_t b=n; // 何個取り出すか
  int64_t c=2500LL; // 和のMAX
  int64_t dp[a+1][b+1][c+1];
  
  memset(dp, 0LL, sizeof(dp)); // dp0に初期化
  dp[0][0][0]=1LL; // dp開始条件
  
  for(int i=0; i<=a; i++){
    for(int j=0; j<=b; j++){
      for(int k=0; k<=c; k++){
        if(i>0) dp[i][j][k]+=dp[i-1][j][k];
        if(i>0 && j>0 && k>=x[i]) dp[i][j][k]+=dp[i-1][j-1][k-x[i]];
      }
    }
  }
  
  int64_t ans=0LL;
  for(int i=1; i<=n; i++) ans += dp[n][i][ave*i];
  cout << ans << endl;
}

Measured memory_bytes: 51072
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define MM multimap
#define PB push_back
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
    vector<int> A(5);
    cin >> A[0] >> A[1] >> A[2] >> A[3] >> A[4];
    vector<int> P = {0, 1, 2, 3, 4};
    int final_answer = INF;
    do {
        int ans = 0;
        for (int i = 0; i < 5; ++i){ // 注文時刻の10の倍数まで1を追加していく
            while (ans % 10 != 0) ans += 1; // 注文時刻以外のとき
            ans += A[P[i]];
        }
        final_answer = min(final_answer, ans);
    } while (next_permutation(P.begin(), P.end()));
    cout << final_answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n, t; cin >> n >> t;
	vector<P> p(n);
	REP(i, n) cin >> p[i].first >> p[i].second;
	int dp[3010][3010][2] = { 0 };
	for (int i = 0; i < n; i++) {
		REP(j, t) {
			REP(k, 2) {
				if (j >= p[i].first)
					dp[i + 1][j][k] = max(dp[i][j - p[i].first][k] + p[i].second, dp[i][j][k]);
				else
					dp[i + 1][j][k] = dp[i][j][k];
			}
			dp[i + 1][j][1] = max(dp[i][j][0] + p[i].second, dp[i + 1][j][1]);
		}
	}
	cout << dp[n][t - 1][1];
}

Measured memory_bytes: 71040
# ABC126B - YYMM or MMYY
s = input()
x, y = int(s[:2]), int(s[2:])
if 1 <= x <= 12:
    if 1 <= y <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1 <= y <= 12:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;



int main(void){
    REP(i,5){
        int x;
        cin >> x;
        if(x==0)
            cout << i+1;
    }

    return 0;
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i, n){
        cin >> x[i];
        y[i] = x[i];
    }
    sort(x.begin(), x.end());

    int medl = x[n / 2 - 1];
    int medr = x[n / 2];
    rep(i, n){
        if(y[i] < medr) cout << medr << endl;
        else if(y[i] > medl) cout << medl << endl;
        else cout << medl << endl;
    }
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repin(Array,n) for(int i=0;i<n;i++){cin>>Array[i];}
using namespace std;

using ll = long long;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;

int main() {

	int N, K;
	cin >> N >> K;
	ll ans = 0;

	rep(i, N) {
		if (i == 0)
			ans += K;
		else
			ans *= K - 1;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;

#define N 20
int a[2][N];

vpii p[2], q;

int main(){
	int n; scanf("%d", &n);
	REP(j, 2) REP(i, n) scanf("%d", a[j]+i);
	int ans = INT_MAX;
	REP(b, (1<<n)){
		if(__builtin_popcount(b) != (n+1)/2) continue;
		REP(j, 2){
			p[j].clear();
			REP(i, n) if( (!(b & (1<<i))) == j) 
				p[j].EB(a[ (i + j) % 2 ][i], i);
			sort(ALL(p[j]));
		}
		REP(j, 2){
			DEBUG("j = %d\n", j);
			for(auto &pr : p[j]) DEBUG(" %d %d\n", pr.first, pr.second);
		}
		DEBUG("\n");

		q.clear();
		REP(i, n) q.EB( p[i%2][i/2] );

		bool ok = true;
		REP(i, n-1) if( q[i].first > q[i+1].first ) ok = false;
		if(!ok) continue;

		REP(i, n) DEBUG("%d (%d)\n", q[i].first, q[i].second);
		int tmp = 0;
		REP(i, n) {
			FOR(j, i+1, n){
				if(q[i].second > q[j].second){
					tmp++;
				}
			}
		}
		DEBUG("%d\n\n", tmp);
		SML(ans, tmp);
	}
	if(ans == INT_MAX) ans = -1;
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

long long modpow(long long a, long long n){
  long long r=1;
  while(n){
    if(n&1) r=r*a%MOD;
    a=a*a%MOD;
    n>>=1;
  }
  return r;
}

ll sum[101010];
ll X[101010];
int N;

int main(){
  cin>>N;
  rep(i,N) cin>>X[i];
  ll fac=1;
  for(int i=2;i<N;i++) (fac*=i)%=MOD;
  for(int i=1;i<N;i++){
    sum[i]=(sum[i-1]+fac*modpow(i,MOD-2))%MOD;
  }
  ll ans=0;
  for(int i=0;i<N-1;i++){
    ans=(ans+sum[i+1]*(X[i+1]-X[i]))%MOD;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5064
use proconio::input;
use proconio::marker::Usize1;

#[allow(non_snake_case)]
fn main() {
    use std::io::Write;

    let stdout = std::io::stdout();
    let mut stdout = std::io::BufWriter::new(stdout.lock());

    input! {
        N: usize,
    }

    let mut n_children = vec![0usize; N];

    for _ in 0..N - 1 {
        input! {
            A: Usize1,
        }
        n_children[A] += 1;
    }

    for i in 0..N {
        writeln!(stdout, "{}", n_children[i]).unwrap(); 
    }
    stdout.flush().unwrap();
}


Measured memory_bytes: 4704
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

vector<int> BuildTree(int start, int end, const string& s,
	unordered_map<int, unordered_map<int, vector<int>>>& tree) {
	vector<int> res (26, 0);
	if (start == end) {
		res[s[start] - 'a']++;
		tree[start][end] = res;
		return res;
	}
	int mid = (start + end) / 2;
	vector<int> res1 = BuildTree(start, mid, s, tree);
	vector<int> res2 = BuildTree(mid + 1, end, s, tree);
	for (int i = 0; i < 26; i++) {
		res[i] = res1[i] + res2[i];
	}
	tree[start][end] = res;
	return res;
}

void ModifyTree(int start, int end, int index, char before, char after,
	unordered_map<int, unordered_map<int, vector<int>>>& tree) {
	if (start > index || end < index) return;
	int mid = (start + end) / 2;
	tree[start][end][before - 'a']--;
	tree[start][end][after - 'a']++;
	if (start == end) return;
	ModifyTree(start, mid, index, before, after, tree);
	ModifyTree(mid + 1, end, index, before, after, tree);
}

vector<int> QueryTree(int l, int r, int start, int end, unordered_map<int, unordered_map<int, vector<int>>>& tree) {
	vector<int> res (26, 0);
	if (l > end || r < start) return res;
	int mid = (start + end) / 2;
	if (l <= start && end <= r) return tree[start][end];
	vector<int> res1 = QueryTree(l, r, start, mid, tree);
	vector<int> res2 = QueryTree(l, r, mid + 1, end, tree);
	for (int i = 0; i < 26; i++) {
		res[i] = res1[i] + res2[i];
	}
	return res;
}

int main(int argc, char *argv[]) {
	int n, q;
	cin >> n;
	string s;
	cin >> s;
	cin >> q;

	unordered_map<int, unordered_map<int, vector<int>>> tree;
	BuildTree(0, n - 1, s, tree);

	for (int i = 0; i < q; i++) {
		int type;
		cin >> type;
		if (type == 1) {
			int index;
			char c;
			cin >> index >> c;
			// 0 index base
			index--;
			char ordinary = s[index];
			s[index] = c;
			ModifyTree(0, n - 1, index, ordinary, c, tree);

		}
		else {
			int l, r;
			cin >> l >> r;
			l--, r--;
			vector<int> query_result = QueryTree(l, r, 0, n - 1, tree);
			int res = 0;
			for (auto num : query_result) {
				if (num > 0) 
					res++;
			}
			cout << res << endl;
		}
	}
}









Measured memory_bytes: 223084
#include <bits/stdc++.h>
using namespace std;
#define rep(src,dst)    for(int i=src; i<dst;  i++)
#define rep2(src,dst)   for(int j=src; j<dst;  j++)
#define INF 1000000000000 //1e+12
#define MOD 10000007 //1e9+7
#define PI  acos(-1)
#define ll long long
template<typename T> inline void ChMin(T* a, T* b) {if(*a>*b) *a=*b;}
template<typename T> inline void ChMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  DivUp(T a, T b)   {return ((a+b-1)/b);}

int main(){
    int n, ans=0; cin >> n;
    vector<int> d(n);
    rep(0,n) cin >> d[i];
    int p = (n*(n-1))/2;

    rep(0,n){
        rep2(i+1,n){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
    return 0;
}
/*

*/


Measured memory_bytes: 3624
#include <cstdio>
using namespace std;
  
int a[4];
int c[8];
int k;
  
int calc(){
    int op = c[k++];
    int ret = 0;
    if(op >= 0){
        ret = op;
    }
    else if(op >= -3){
        int x = calc();
        int y = calc();
        if(op == -1){
            ret = x + y;
        }
        else if(op == -2){
            ret = x - y;
        }
        else{
            ret = x * y;
        }
    }
    else{
        throw 0;
    }
    return ret;
}
  
void print(){
    int op = c[k++];
    if(op >= 0){
        printf("%d", op);
    }
    else{
        char ch;
        if(op == -1){ ch = '+'; }
        else if(op == -2){ ch = '-'; }
        else{ ch = '*'; }
  
        putchar('(');
        print();
        printf(" %c ", ch);
        print();
        putchar(')');
    }
}

const int bnum = 20;
  
void solve(int i, int S, int oprem, int numrem){
    if(i == 6){
        for(int j = 0; j < 4; ++j){
            if(S >> j & 1){
                c[6] = a[j];
            }
        }
        try{
            k = 0;
            if(calc() == 10 && k == 7){
                k = 0;
for(int j=0;j<bnum;++j)putchar('(');
                print();
for(int j=0;j<bnum;++j)putchar(')');
                puts("");
                throw "";
            }
        }catch(int){}
        return;
    }
  
    if(oprem > 0){
        for(int op = -1; op >= -3; --op){
            c[i] = op;
            solve(i + 1, S, oprem - 1, numrem + 1);
        }
    }
  
    if(numrem > 0){
        for(int j = 0; j < 4; ++j){
            if(S >> j & 1){
                c[i] = a[j];
                solve(i + 1, S ^ 1 << j, oprem, numrem - 1);
            }
        }
    }
}
  
int main(){
    while(1){
        for(int i = 0; i < 8; ++i){
            c[i] = -9;
        }
        for(int i = 0; i < 4; ++i){
            scanf("%d", &a[i]);
        }
        if(a[0] == 0){ break; }
        try{
            solve(0, 15, 3, 0);
            puts("0");
        }catch(...){}
    }
}

Measured memory_bytes: 1128
N = int(input())
first_line = list(map(int, input().split()))
second_line = list(map(int, input().split()))

r = 0
for n in range(1, N + 1):
    a = sum(first_line[0:n])
    b = sum(second_line[n - 1:])

    if r <= (a + b):
        r = (a + b)
print(r)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <random>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 998244353 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll n,k ;
	cin >> n >> k ;
	vll l(k),r(k) ;
	for(int i=0;i<k;i++) cin >> l[i] >> r[i] ;
	vll dp(n+2,0) ;
	dp[0] = 1 ;
	dp[1] = -1 ;
	ll sum = 0 ;
	for(int i=0;i<n;i++){
		sum += dp[i] ;
		dp[i] = sum ;
		for(int j=0;j<k;j++){
			if(l[j]+i>n) continue ;
			dp[i+l[j]] = (dp[i+l[j]]+sum)%mod ;
			if(i+r[j]>n) dp[n+1] = (dp[n+1]-sum+mod)%mod ;
			else dp[i+r[j]+1] = (dp[i+r[j]+1]-sum+mod)%mod ;
		}
	}
	cout << dp[n-1]%mod << endl ;
	// for(auto i:dp) cout << i << " " ; cout << endl ;
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N = 2e5+5;
lli now1[N], now2[N], ans[N], tot1, tot2, curtot;

lli binpow(lli a,lli b, lli M) 
{
    if (b == 0) return 1;
    lli res = binpow(a,b/2,M);
    res= (res*res)%M;
    
    if(b%2) return (res*a)%M;
    return res;
}
 
lli inv(lli a, lli M)
{
    return binpow(a,M-2,M);
}

lli add(lli a, lli b, lli M)
{
	lli res = a + b;
	if(res >= M)
		return res - M;
	return res;
}
 
lli mul(lli a, lli b, lli M)
{
	lli  res = a * b;
	if(res >= M)
		return res % M;
	return res;
}
 
lli sub(lli a, lli b, lli M)
{
	return (a%M -b%M +M) %M;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    string x;
    cin>>n>>x;
    lli i, on = 0, m1, m2;
    
    for(i=0;i<n;i++) if(x[i] == '1') on++;
    
    m1 = on - 1;
    m2 = on + 1;
    if(m1 == 0) m1 = 1;
    
    for(i=0;i<n;i++)
    {
        if(x[i] == '1')
        {
            if(m1 != -1) now1[i] = binpow(2, n - i - 1, m1), tot1 = add(tot1, now1[i], m1);
            if(m2 != -1) now2[i] = binpow(2, n - i - 1, m2), tot2 = add(tot2, now2[i], m2);
        }
    }
    
    for(i=1;i<=n;i++) ans[i] = ans[i%(__builtin_popcount(i))] + 1;
    
    
    for(i=0;i<n;i++)
    {
        if(x[i] == '0')
        {
            curtot = add(tot2, binpow(2, n - i - 1, m2), m2);
            cout<<ans[curtot] + 1<<endl;
        }
        else
        {
            if(on == 1)
            {
                cout<<0<<endl;
                continue;
            }
            
            curtot = sub(tot1, binpow(2, n - i - 1, m1), m1);
            cout<<ans[curtot] + 1<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 8416
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    int a,b,c,d;cin>>a>>b>>c;
    cout<<(a+b>=c?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
//Suplex
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
int A,B,f[105][105];

int main()
{
	scanf("%d%d",&A,&B);
	A--;B--;
	for(int i=1;i<=100;i++)
		for(int j=51;j<=100;j++) f[i][j]=1;
	for(int i=1;i<=100;i+=2)
		for(int j=1;j<=50;j+=2)
			if(B) f[i][j]=1,B--;
	for(int i=1;i<=100;i+=2)
		for(int j=52;j<=100;j+=2)
			if(A) f[i][j]=0,A--;
	printf("100 100\n");
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++) if(f[i][j]) putchar('#');else putchar('.');
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, K, X, Y := sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()
	if N <= K {
		fmt.Fprintln(wtr, N*X)
	} else {
		fmt.Fprintln(wtr, K*X+(N-K)*Y)
	}

	wtr.Flush()
}


Measured memory_bytes: 640
from typing import List


class DSU:
    def __init__(self, n: int) -> None:
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a <= self._n
        assert 0 <= b <= self._n
        x, y = self.leader(a), self.leader(b)
        if x == y:
            return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a <= self._n
        assert 0 <= b <= self._n
        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n
        stack = []
        while self.parent_or_size[a] >= 0:
            stack.append(a)
            a = self.parent_or_size[a]
        for i in stack:
            self.parent_or_size[i] = a
        return a

    def size(self, a: int) -> int:
        assert 0 <= a <= self._n
        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> List[List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]
        group_size = [0] * self._n
        for i in leader_buf:
            group_size[i] += 1
        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)
        result = [i for i in result if i]
        return result


n, q = map(int, input().split())
dsu = DSU(n)

for _ in range(q):
    t, u, v = map(int, input().split())
    if t == 0:
        dsu.merge(u, v)
    else:
        print(1 if dsu.same(u, v) else 0)


Measured memory_bytes: 79708
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 105;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
  int n,m;
  cin>>n>>m;
  int ret = n + m;
  ret = max(ret, n+n-1);
  ret = max(ret, m+m-1);
  cout<<ret<<endl;
  return 0;
}

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

char in[1<<21];
char const*o;

inline void init_in() { 
  o = in;
  in[fread(in,1,sizeof(in)-4,stdin)] = 0;
}

int readInt(){ 
  unsigned u = 0, s = 0;
  while(*o && *o <= 32){
    ++o;
  }
  if (*o == '-'){
    s = ~s, ++o;
  } else if (*o == '+'){
    ++o;
  }
   
  while(*o>='0' && *o<='9'){
    u = (u<<3) + (u << 1) + (*o++ - '0');
  }

  return static_cast<int>((u^s) + !!s) ;
}

int cnt[202020];
template<typename T> void fastout(T &n) {
  T N = n, rev, count = 0;
  rev = N;
  if (N == 0) {
    putchar_unlocked('0');
    putchar_unlocked('\n');
    return;
  }
  while ((rev % 10) == 0) { 
    ++count; rev /= 10;
  }
  rev = 0;
  while (N != 0) { 
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) { 
    putchar_unlocked(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar_unlocked('0');
  putchar_unlocked('\n');
}
int main(){
  init_in();
  int n = readInt(); int k = readInt();
  
  for (int i = 0; i < n; ++i) {
    int x = readInt();
    ++cnt[x];
  }
  
  sort(cnt, cnt + n + 1 , greater<int>());

  n -= accumulate(cnt, cnt + k, int());

  fastout(n);

  return 0;
}


Measured memory_bytes: 2304
#include<string>
#include<vector>
#include<iostream>

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

using namespace std;

const int INF=1<<29;

inline bool cmp(const string &a,const string &b){
	return a.length()!=b.length() ? a.length()<b.length() : a<b;
}

int main(){
	for(int n;cin>>n,n;){
		vector<string> s(n);
		rep(i,n) cin>>s[i];

		rep(i,s.size()){
			bool covered=false;
			rep(j,s.size()) if(i!=j && ~s[j].find(s[i])) covered=true;
			if(covered){
				s.erase(s.begin()+i);
				i--;
			}
		}

		n=s.size();
		int cost[10][10];
		rep(i,n) rep(j,n) {
			string a=s[i],b=s[j];
			int k;
			for(k=min(a.length(),b.length());k>0;k--){
				if(a.substr(a.length()-k,k)==b.substr(0,k)) break;
			}
			cost[i][j]=b.length()-k;
		}

		string dp[1<<10][10];
		rep(S,1<<n) rep(i,n) dp[S][i]=string(101,'*');
		rep(i,n) dp[1<<i][i]=s[i];
		rep(S,1<<n) rep(i,n) {
			rep(j,n) if(!(S&(1<<j))) {
				string &next=dp[S|(1<<j)][j];
				string tmp=dp[S][i]+s[j].substr(s[j].length()-cost[i][j],cost[i][j]);
				if(cmp(tmp,next)) next=tmp;
			}
		}

		int i_ans=0;
		rep(i,n) if(cmp(dp[(1<<n)-1][i],dp[(1<<n)-1][i_ans])) i_ans=i;
		cout<<dp[(1<<n)-1][i_ans]<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
def combination(k, r, MOD):
    """kCrを求める"""
    if k < r:
        return 0
    r = min(r, k - r)
    numer, denom = 1, 1
    for l in range(r):
        numer *= (k - l)
        numer %= MOD
        denom *= l + 1
        denom %= MOD
    return numer * pow(denom, MOD - 2, MOD) % MOD


t = int(input())
MOD = 10 ** 9 + 7


for i in range(t):
    n = int(input())
    n -= 5
    res = 0
    for odd_cnt in range(12):
        if n - odd_cnt < 0 or (n - odd_cnt) % 2 == 1:
            continue
        m = (n - odd_cnt) // 2
        res += combination(m + 15, 15, MOD) * combination(11, odd_cnt, MOD)
        res %= MOD
    print(res)

Measured memory_bytes: 75116
#include <stdio.h>
#include <stdlib.h>
int main(){
  int n = 0;
  int m;
  scanf("%d", &n);
  scanf("%d", &m);
  int *a;
  a = malloc(sizeof(int)*n);

  for(int i=0; i<n; i++){
    scanf("%d",&a[i]);
  }

  double s = 0;
  for(int i=0; i<n; i++){
    s += a[i];
  }
  s = s / (4*m);

  int count = 0;
  for(int i=0; i<n; i++){
    if(a[i]>=s){
      count++;
    }
  }
  if(count>=m){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
}


Measured memory_bytes: 1624
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>



using namespace std;




int main(){
	
	long long int a,b,x=0;;
	cin>>a>>b;
	int t=0;
	for(int i=0;i<a;i++){
		int r;
		cin>>r;
		if(r+t>b)x+=r+t-b,t=b-t;
		else t=r;

	}
	cout<<x<<endl;

	return 0;
	

}


	

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

int main()
{
    string s;
    cin>>s;
    ll rem,i,n=s.size(),k=2019,val,ans=0,val1=1,c;
    unordered_map<ll,ll> m;
    rem=0;
    
    for(i=n-1;i>=0;i--)
    {
        val=val1%k;
        c=s[i]-'0';
        rem=(rem+c*val)%k;
        m[rem]++;
        val1=(val1%k*10)%k;
    }

   

    for(auto x:m)
    {
        ans+=(x.second*(x.second-1))/2;
    }
    
    cout<<ans+m[0];
}

Measured memory_bytes: 3732
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VB vector<bool>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVL vector<VL>
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int pow(int x, int n){
    int t = 1;
    rep(i, n){
        t *= x;
    }
    return t;
}

int main(){
    int n, k;
    cin >> n >> k;
    cout << k * pow(k-1, n-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 10000000
#define int long long
#define double long double
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, m, a, b, c[100010];
vector<int> vec[100010], g(100010);
vector<P> change;
set<P> ans;
bool used[100010];
int depth[100010];
void bfs() {
	queue<P> que;
	que.push(make_pair(1, 0));
	while (!que.empty()) {
		P p = que.front();
		que.pop();
		for (int i : vec[p.first]) {
			if (!used[i]) {
				used[i] = true;
				depth[i] = p.second + 1;
				que.push(make_pair(i, depth[i]));
			}
		}
	}
}
signed main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> a >> b;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	used[1] = true;
	bfs();
	REP(i, n) {
		change.push_back(make_pair(depth[i], i));
	}
	sort(change.begin(), change.end(), greater<P>());
	rep(i, n)g[change[i].second] = i;
	rep(z, n) {
		int i = change[z].second;
		if (c[i] % 2) {
			rep(j, vec[i].size()) {
				if (g[i] < g[vec[i][j]]) {
					ans.insert(make_pair(i,vec[i][j]));
					break;
				}
			}
			bool f = false;
			rep(j, vec[i].size()) {
				if (g[i] < g[vec[i][j]]) {
					if (f) {
						ans.insert(make_pair(vec[i][j],i));
						c[vec[i][j]]++;
					}
					f = true;
				}
			}
		}
		else {
			rep(j, vec[i].size()) {
				if (g[i] < g[vec[i][j]]) {
					ans.insert(make_pair(vec[i][j],i));
					c[vec[i][j]]++;
				}
			}
		}
	}
	if (c[change[n - 1].second] % 2)cout << -1 << endl;
	else for (P p : ans)cout << p.first << " " << p.second << endl;
	return 0;
}

Measured memory_bytes: 17648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;


ll a[3][3];
ll b[3];

ll aa[3];
int main()
{
	int sum=0;
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin >> a[i][j];
			if(i==j)
				aa[i]=a[i][j];
		}
	}
	for(int i=0;i<=aa[0];i++)
		for(int j=0;j<=aa[1];j++)
			for(int k=0;k<=aa[2];k++)
			{

				b[0]=i;
				b[1]=j;
				b[2]=k;
				bool check=1;
				for(int ii=0;ii<3;ii++)
				{
					for(int jj=0;jj<3;jj++)
					{
						 if(a[ii][jj]!=b[ii]+aa[jj]-b[jj])
							check=0;
					}
				}
				if(check)
				{
					cout << "Yes";
					return 0;
				}
			}		
	cout << "No";
}

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

using namespace std;

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

    int a,b,c;
  	cin>>a>>b>>c;
  
  	if(b-a == c-b) cout<<"YES\n";
  	else cout<<"NO\n";


    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main(){
	int n;
	int c;
	cin>>n;
	while(1){
		if(n<2){
			break;
		}
		n/=2;
		c++;
	}
	int a=1;
	for(int i=0;i<c;i++){
		a*=2;
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
string s;
bool acgt(int  x){
  if(s[x]=='A'||s[x]=='C'||s[x]=='G'||s[x]=='T') return true;
  return false;
  
}

int main() {
  
  cin>>s;
  int n=s.size();
  //////
  int ans=0;
  int cnt=0;
  rep(i,n){
    if(acgt(i)){
      cnt++;
      if(i==n-1) ans=max(cnt,ans);
    }
    else{
      ans=max(ans,cnt);
      cnt=0;
      
    }
    
  }
       cout<<ans<<endl;
}




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {

	/* --------------------------------------------------------------------
	   main
	 * -------------------------------------------------------------------- */
	public static void main(String args[]) throws Exception {

		// ----- input -----
		Input input = new Input();
		final Data l = input.readLine();
		final int A = l.col[0];
		final int B = l.col[1];
		input.close();

		// ----- main -----
		System.out.println((A <= 8 && B <= 8)? "Yay!" : ":(");
	}

	/* --------------------------------------------------------------------
	 * inupt class
	 * -------------------------------------------------------------------- */
	static class Input {

		public BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		public void close() throws Exception {
			input.close();
		}

		public Data readLine() throws Exception {
			return new Data(input.readLine().split(" "));
		}

		public Queue<Data> getDataQueue(int num) throws Exception {

			Queue<Data> q;
			q = new ArrayDeque<>();
//			data = new PriorityQueue<>( (a,b) -> a.col[0] - b.col[0]);	// 降順


			for(int i=0; i < num; i++) {
				q.offer(readLine());
			}
			return q;
		}

		public Queue<Integer> getColQueue(Data data) {

			Queue<Integer> q;
			q = new ArrayDeque<>();
//			queue = new PriorityQueue<>( (a,b) -> a.col[0] - b.col[0]);	// 降順
			for(int i=0; i < data.col.length; i++) {
				q.offer(data.col[i]);
			}
			return q;
		}
	}
	/* --------------------------------------------------------------------
	 * data class
	 * -------------------------------------------------------------------- */
	static class Data{
		public int[] col;
		public Data(String[] values) {
			col = new int[values.length];
			for(int i=0; i < values.length; i++) {
				col[i] = Integer.parseInt(values[i]);
			}
		}
	}
}

Measured memory_bytes: 22228
#include "bits/stdc++.h"
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//adds two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set]
//(2)set.order_of_key(k)[count of elements strictly less than k]
#define ll long long
#define ld long double
#define vv vector
#define pp pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
typedef pair<ll, ll> pll;
typedef vv<bool> vbool;
typedef vv<ll> vll;
typedef vv<ld> vld;
typedef vv<pll> vpll;
#ifdef LOCAL
#include "prettyprint.hpp"
#define LG(args...)                           \
{                                             \
	string _s = #args;                        \
	replace(_s.begin(), _s.end(), ',', ' ');  \
	stringstream _ss(_s);                     \
	err(istream_iterator<string>(_ss), args); \
	cerr << endl;                             \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "(" << *it << ":" << a << ") ";
	err(++it, args...);
}
#define fastio
#else
#define LG(...)
#define fastio                    \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);
#define endl "\n"
#endif
//:::::::::::::::::::::::::::::::::::::::::::::
const ll INF = 9e18;
const ll MOD = 1e9 + 7;

bool check(ll i,ll j, ll k){
	if(i == j || j == k || i+j <=k)
		return 0;
	return 1;
}

int main(){
	fastio;
	ll n;
	cin>>n;
	vll v(n);
	for(ll i=0; i<n; i++){
		cin>>v[i];
	}
	sort(all(v));
	ll ans=0;
	for(ll i=0; i<n; i++){
		for(ll j=i+1; j<n; j++){
			for(ll k=j+1; k<n; k++){
				if(check(v[i], v[j], v[k]))
					ans++;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
struct UnionFind{
public:
    vector<int> par;
    vector<int> rank;
    vector<int> s;
    int cnt;
 
    UnionFind(int n){
        rep(i,n){
            par.push_back(i);
            rank.push_back(0);
            s.push_back(1);
        }
        cnt=n;
    }
 
    int find(int x){
        if(par[x]==x) return x;
        else return par[x]=find(par[x]);
    }
 
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){
            par[x]=y;
            s[y]+=s[x];
        }else{
            par[y]=x;
            s[x]+=s[y];
            if(rank[x]==rank[y]) rank[x]++;
        }
        cnt--;
    }

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

    int size(int x){
        return s[find(x)];
    }
};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        int x,y,z;
        cin>>x>>y>>z;
        x--,y--;
        uf.unite(x,y);
    }
    set<int> st;
    rep(i,n) st.insert(uf.find(i));
    cout<<st.size()<<endl;
}

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

int main(){
  int a, b;
  cin >> a >> b;

  int ans = a - 2*b;
  if(ans > 0) cout << ans << endl;
  else cout << 0 << endl;

  return 0;
}

Measured memory_bytes: 256
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var x = int.Parse(line[0]);
        var y = int.Parse(line[1]);
        var z = int.Parse(line[2]);
        var k = int.Parse(line[3]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, long.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var b = Array.ConvertAll(line, long.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var c = Array.ConvertAll(line, long.Parse);
        Array.Sort(a); Array.Sort(b); Array.Sort(c);
        Array.Reverse(a); Array.Reverse(b); Array.Reverse(c);
        var ab = getArray(a, b, Min(k, x * y));
        var ans = getArray(ab, c, k);
        Console.WriteLine(string.Join("\n", ans));
    }
    static long[] getArray(long[] a, long[] b, int k)
    {
        var ans = new long[k];
        var t = new long[a.Length * b.Length];
        var p = 0;
        for (int i = 0; i < a.Length; i++)
            for (int j = 0; j < b.Length; j++)
                t[p++] = a[i] + b[j];
        Array.Sort(t);
        Array.Reverse(t);
        for (int i = 0; i < k; i++) ans[i] = t[i];
        return ans;
    }
}

Measured memory_bytes: 44896
/*
god taekyu
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

char A[3005], B[3005];
int n,m;
int dp[3005][3005];
int via[3005][3005];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>(A+1)>>(B+1);
    n = strlen(A+1);
    m = strlen(B+1);

    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            int a = dp[i-1][j-1] + (A[i] == B[j]);
            int b = dp[i][j-1];
            int c = dp[i-1][j];
            if(a >= b && a >= c) {
                dp[i][j] = a;
                via[i][j] = 1;
            } else if(b >= c) {
                dp[i][j] = b;
                via[i][j] = 2;
            } else {
                dp[i][j] = c;
                via[i][j] = 3;
            }
        }
    }
    string ans;
    int x = n, y = m;
    while(x > 0 && y > 0) {
        if(via[x][y] == 1 && A[x] == B[y]) {
            ans += A[x];
        }
        if(via[x][y] == 1) x--, y--;
        else if(via[x][y] == 2) y--;
        else x--;
    }
    for(int i=ans.length()-1;i>=0;i--) cout<<ans[i];
    return 0;
}

/*
god taekyu
*/


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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<vector<int>> A(N,vector<int>(M));
  vector<int> MAX(M,0);
  vector<int> c(N);
  for (int i = 0; i < N; i++) {
    cin >> c[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }
  
  int ans = 2000000000;
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<13> s(tmp);
    if (s.test(N) && N < 12) break;
    int cost = 0;
    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        cost += c[i];
        for (int j = 0; j < M; j++) {
          MAX[j] += A[i][j];
        }
      } 
    }
    bool b = true;
    for (int i = 0; i < M; i++) {
      if (MAX[i] < X) b = false;
    }
    if (b) ans = min(ans,cost);
    MAX.assign(M,0);
  }
  
  cout << (ans == 2000000000 ? -1 : ans) << endl;
}

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

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

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

int64_t dfs(int64_t d, int64_t n, int64_t& k) {
  if (d == 1) {
    --k;
    if (k == 0) {
      return n * d;
    } else {
      return -1;
    }
  }

  for (auto i : irange(max(0L, n - 1), min(9L, n + 1) + 1L)) {
    int64_t ret = dfs(d / 10, i, k);

    if (k == 0) {
      return n * d + ret;
    }
  }

  return -1L;
}

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

  for (int64_t d = 1;; d *= 10) {
    for (auto i : irange(1L, 10L)) {
      auto ret = dfs(d, i, k);

      if (ret > 0) {
        cout << ret << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define int long long
signed main(signed argc, char* argv[]) {
	int n;
	cin >> n;
	vector<int> t(n + 1), a(n + 1);
	t[0] = 0;
	rep(i, n) cin >> t[i + 1];
	rep(i, n) cin >> a[i];
	a[n] = 0;
	int ans = 1;
	rep(i, n) {
		bool b1, b2;
		b1 = a[i] == a[i + 1];
		b2 = t[i] == t[i + 1];
		if (b1 && b2) {
			ans = ans*min(a[i], t[i+1])%1000000007;
		}
		else if (b1) {
		    if(a[i]<t[i+1])ans=0;
		}
		else if (b2) {
            if(a[i]>t[i+1])ans=0;
		}
		else {
		    if(a[i]!=t[i+1])ans=0;
		}
	}
	cout<<ans<<endl;
}

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

int main(){
  string s, t = "";
  cin >> s;
  for(int i=0; i<s.size(); i++){
    if(s[i]!='B'){
      t+=s[i];
    } else {
      t = t.substr(0, t.size()-1);
    }
  }
  cout << t << endl;
  return 0;
}

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

using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  string s = "ACL";
  int n ;
  cin >> n;
  rep(i,n)cout << s;
  cout << "\n";



  return 0;
}

Measured memory_bytes: 3456