akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define N 15
using namespace std;
void func(int,int);
int jump(int,int);
int X,Y,data[N][N],memo[N][N];
int main(){
  while(1){
    cin >> X >> Y;
    if(X==0&&Y==0) break;
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
	data[i][j]=0;
      }
    }
    for(int i=0;i<Y;i++)
      for(int j=0;j<X;j++) cin >> data[i][j],memo[i][j]=0;
    for(int i=0;i<X;i++)
      if(data[0][i]==0) func(0,i);
    int cnt=0;
    for(int i=0;i<X;i++) cnt+=memo[0][i];
    cout << cnt << endl;
  }
  return 0;
}
void func(int y,int x){
  if(y==Y-1){
    memo[Y-1][x]=1;
    return ;
  }
  if(0<=x-1&&data[y+1][x-1]==0){
    if(memo[y+1][x-1]==0) func(y+1,x-1);
    memo[y][x]+=memo[y+1][x-1];
  }
  if(x+1<X&&data[y+1][x+1]==0){
    if(memo[y+1][x+1]==0) func(y+1,x+1);
    memo[y][x]+=memo[y+1][x+1];
  }
  if(data[y+1][x]==0){
    if(memo[y+1][x]==0) func(y+1,x);
    memo[y][x]+=memo[y+1][x];
  }
  if(data[y+1][x]==2){
    int r=jump(y+1,x);
    if(r==-2) memo[y][x]+=1;
    else if(r!=-1){
      if(memo[r][x]==0) func(r,x);
      memo[y][x]+=memo[r][x];
    }
  }
  if(memo[y][x]==0) data[y][x]=1;
}
int jump(int y,int x){
  while(1){
    y+=2;
    if(data[y][x]==1) break;
    if(y>=Y-1) return -2;
    if(data[y][x]==0) return y;
  }
  return -1;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    string s; cin>>s;
    if (s.back() == 's') {
        cout << s + "es" << '\n';
    }
    else {
        cout << s+"s" << '\n';
    }
    return 0;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	vector<pair<int, int>>A(N);
	for (int i = 0; i < N; i++){
		int a;
		cin >> a;
		A[i] = make_pair(a, i+1);
	}
	sort(A.begin(), A.end());
	for (int i = 0; i < N; i++){
		cout << A[i].second << " ";
	}
	return 0;
}

Measured memory_bytes: 1664
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define ALL(a)					(a).begin(),(a).end()
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N, W;
	cin >> N >> W;
	vector<vector<int>> masu(N + 1, vector<int>(W + 1, 0));
	vector<vector<bool>> used(N + 1, vector<bool>(W + 1, false));
	REP(i, N) {
		REP(j, W) {
			cin >> masu[i][j];
		}
	}

	vector<int> a, b, c, d;
	REP(i, N) {
		REP(j, W) {
			if (IsOdd(masu[i][j])) {
				if (i == N - 1) {
					if (j != W - 1) {
						masu[i][j]--;
						masu[i][j + 1]++;
						a.emplace_back(i + 1);
						b.emplace_back(j + 1);
						c.emplace_back(i + 1);
						d.emplace_back(j + 2);
					}
				} else {
					masu[i][j]--;
					masu[i + 1][j]++;
					a.emplace_back(i + 1);
					b.emplace_back(j + 1);
					c.emplace_back(i + 2);
					d.emplace_back(j + 1);
				}
			}
		}
	}

	cout << a.size() << endl;
	REP(i, a.size()) {
		cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i]<< endl;
	}
	return 0;
}



Measured memory_bytes: 5220
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f 
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long int
#define pi 3.14159265358979
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef vector<int>   vi;
typedef vector<pii>   vpii;
typedef vector<vi>    vvi;

int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ll n;
    cin>>n;
    if(n>=30)
        cout<<"Yes";
    else
        cout<<"No";

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define SCANF(i) int i;scanf("%d",&i)
using namespace std;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int IINF=100000000;
const int MOD = (int)1e9 + 7;
typedef long long ll;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<int> dx={1,0,-1,0};vector<int> dy={0,-1,0,1};
int h,w;
vector<vector<int>> grid;
vector<vector<bool>> seen;
int xx[8] = {0,-1,-1,-1,0,1,1,1};
int yy[8] = {1,1,0,-1,-1,-1,0,1};
void dfs(int x,int y){
    seen[x][y] = true;
    for(int i=0;i<8;i++){
        int nx = x+xx[i];int ny = y+yy[i];
        if(nx<0||nx>h-1||ny<0||ny>w-1)continue;
        if(!seen[nx][ny] && grid[nx][ny]==1){
            dfs(nx,ny);
        }
    }
}
signed main () {
    while(cin >> w >> h){
        if(h+w==0)break;
        int cnt = 0;
        grid.assign(h,vector<int>(w));
        seen.assign(h,vector<bool>(w,false));
        REP(i,h)REP(j,w)cin >> grid[i][j];
        REP(i,h)REP(j,w){
            if(grid[i][j]==1 && !seen[i][j]){
                dfs(i,j);
                cnt++;
            }
        }
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3220
#include <iostream>
#include <algorithm> //min
typedef long long ll;

using namespace std;

int main() {

	ll L, R; //範囲がintを超える
	cin >> L >> R;

	//余りは最大でも2018
	int mod_min = 2018;

	//余りは2019周期でパターンが同じなのでRの範囲を縮める
	R = min(R, L + 2019);

	for (ll i = L; i < R; i++)
	{
		for (ll j = i + 1; j <= R; j++)
		{

			int mod = (i * j) % 2019;
			//cout << mod << "\n";

			mod_min = min(mod_min, mod);
			//if (mod < mod_min) {
			//	mod_min = mod;
			//}
		}
	}

	cout << mod_min << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1e9 + 7;
	//constexpr ll P = 998244353;

	ll n;
	cin >> n;
	vector<ll> l(n);
	for (ll i = 0; i < n; i++) cin >> l[i];
	ll ans = 0, a, b, c;
	for (ll i = 0; i < n - 2; i++) {
		a = l[i];
		for (ll j = i + 1; j < n - 1; j++) {
			b = l[j];
			if (a == b) continue;
			for (ll k = j + 1; k < n; k++) {
				c = l[k];
				if (a == c || b == c) continue;
				if (a + b > c && b + c > a && c + a > b) ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	LL N,A,B,C,D,E;
	cin>>N;
	cin>>A;
	cin>>B;
	cin>>C;
	cin>>D;
	cin>>E;
	LL minV=min(A,min(B,min(C,min(D,E))));
	LL t=5;
	N-=minV;
	t+=N/minV;
	LL n=N%minV;
	if (n>0){
		t++;
	}
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] t = new int[n];
		int[] x = new int[n];
		int[] y = new int[n];
		boolean flag = true;
		int rtime = 0;
		int nx = 0;
		int ny = 0;
		for(int i = 0; i < n; i++){
			t[i] = sc.nextInt();
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		for(int i = 0; i < n && flag; i++){
			int itime = t[i] - rtime;
			rtime = t[i];
			int wtime = Math.max(nx,x[i])-Math.min(nx,x[i])+Math.max(ny,y[i])-Math.min(ny,y[i]);
			if(itime < wtime){
				flag = false;
				break;
			}else if(itime > wtime){
				if((itime-wtime)%2==1){
					flag = false;
					break;
				}
			}
			ny = y[i];
			nx = x[i];
		}
		System.out.print(flag?"Yes":"No");
	}
}


Measured memory_bytes: 90796
#include<iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

int dp[301];
int to[1001];
vector<int> from[1001];

const int INF=1000000000;
int main(){
  int n,e,t;
  while(cin>>n>>e>>t&&(n|e|t)){
    for(int i=0;i<1001;i++)from[i].clear();
    for(int i=1;i<=n;i++){
      cin>>dp[i];
      if(dp[i]==0)dp[i]=INF;
    }
    for(int i=0;i<e;i++){
      int g,c;
      cin>>g>>c;
      to[i]=g;
      for(int j=0;j<c;j++){
	int s;
	cin>>s;
	from[i].push_back(s);
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<e;j++){
	int d[11];
	// cost of moving before
	for(int k=0;k<from[j].size();k++)
	  d[k]=dp[from[j][k]];
	// sort with ordering acending
	sort(d,d+(int)from[j].size(),greater<int>());
	int maxc=0;
	for(int k=0;k<from[j].size();k++)
	  maxc=max(maxc,k+d[k]);
	dp[to[j]]=min(dp[to[j]],maxc);	
      }
    }
    if(dp[t]==INF)cout<<-1<<endl;
    else cout<<dp[t]<<endl;
  }

  return 0;
}

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

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
typedef priority_queue<int, vector<int>, greater<int>> min_heap;

// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const double PI = 4*atan(1);
const ll INF = 1e18;
const int MX = 100001;

ll bin(ll a) {
    return (a * (a - 1)) / 2;
}

const int maxn = 2e5 + 5;
int cnt[maxn], a[maxn];
ll ans = 0;
int n;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        ans += bin(cnt[i]);
    }
    // cout << "ans:" << ans << "\n";
    for (int i = 1; i <= n; i++) {
        int c_elt = cnt[a[i]];
        ll ans2 = ans - bin(c_elt) + bin(c_elt - 1);
        cout << ans2 << "\n";
    }
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int dp[100005];
//int mx=INT_MIN;
int solve(int i){
    if(i==n-1)return 0;
    if(i>n-1)return INT_MAX;
    if(dp[i]!=-1)return dp[i];
    int l=abs(a[i]-a[i+1])+solve(i+1);
    int r=INT_MAX;
    if(i+2<n){
         r=abs(a[i]-a[i+2])+solve(i+2);
    }
    return dp[i]=min(l,r);
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<solve(0);
}

Measured memory_bytes: 4096
/*input
2
*/

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

// from atcoder live
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
 
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        return fact[n]*ifact[n-k];
    }
} c(1000005);

int main() {
    int s;
    cin >> s;
    mint ans = 0;
    for (int i = 1; i <= s/3; i++) {
        ans += c(s-2*i-1, i-1);
    }
    cout << ans << endl;
}

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

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


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

    rep(i, c-a) {
        cout << "R";
    }
    rep(i, d-b) {
        cout << "U";
    }
    rep(i, c-a) {
        cout << "L";
    }
    rep(i, d-b) {
        cout << "D";
    }

    cout << "D";

    rep(i, c-a+1) {
        cout << "R";
    }
    rep(i, d-b+1) {
        cout << "U";
    }

    cout << "LU";

    rep(i, c-a+1) {
        cout << "L";
    }
    rep(i, d-b+1) {
        cout << "D";
    }
    cout << "R" << endl;
    return 0;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

struct tree{
    int parent[NMAX];
    int p_color[NMAX];
    vector<int> to[NMAX];
    vector<int> num[NMAX];
    vector<int> color[NMAX];

    void init(int n){
        for(int i = 0; i < n; i++){
            parent[i] = -1;
            p_color[i] = -1;
        }
    }

    void addchild(int a, int b, int n){
        to[a].push_back(b);
        num[a].push_back(n);
        color[a].push_back(0);
        parent[b] = a;
    }

    void colorize(int a){
        int j = 1;
        if(p_color[a] == j) j++;
        for(int i = 0; i < to[a].size(); i++){
            color[a][i] = j;
            p_color[to[a][i]] = j;
            j++;
            if(p_color[a] == j) j++;
            colorize(to[a][i]);
        }
    }

    void print(int n){
        vector<int> ans(n-1);
        int k = 1;

        for(int i = 0; i < n-1; i++){
            for(int j = 0; j < num[i].size(); j++){
                ans[num[i][j]] = color[i][j];
                k = max(k, color[i][j]);
            }
        }
        cout << k << endl;
        for(int i = 0; i < n-1; i++){
            cout << ans[i] << endl;
        }
    }
};

int main(){
    int n;
    cin >> n;
    tree t;
    t.init(n);
    for(int i = 0; i < n-1; i++){
        int a,b;
        cin >> a >> b;
        a--, b--;
        t.addchild(a,b,i);
    }
    t.colorize(0);
    t.print(n);

    return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

typedef struct UnionFind{
	vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
	vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

	UnionFind(int N){/*最初はすべてが根であると初期化*/
		REP(i,0,N){
			par.push_back(i);
			size.push_back(1);
		}
	}

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

	void unite(lli x,lli y){/*xとyの併合*/
		lli rx = root(x);
		lli ry = root(y);
		if(rx == ry)return;
		par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
		lli resize = size[rx] + size[ry];
		size[rx] = resize;
		size[ry] = resize;
	}

	bool same(lli x,lli y){
		lli rx = root(x);
		lli ry = root(y);
		return rx == ry;
	}

	lli getSize(lli x){
		lli rx = root(x);
		return size[rx];
	}
};

signed main(){

	lli n,m,k;
	cin>>n>>m>>k;
	UnionFind uf(n);

	vector<lli> friends(n,0);

	REP(i,0,m){
		lli a,b;
		cin>>a>>b;
		a--,b--;
		friends[a]++,friends[b]++;
		uf.unite(a,b);
	}
	vector<lli> ans(n,0);
	REP(i,0,n)ans[i] = uf.getSize(i)-friends[i];

	REP(i,0,k){
		lli c,d;
		cin>>c>>d;
		c--,d--;
		if(uf.same(c,d)){
			ans[c]--,ans[d]--;
		}
	}
	REP(i,0,n)cout<<ans[i]-1<<" ";
	cout<<endl;

	return 0;
}

Measured memory_bytes: 4588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x1,y1,x2,y2;
  cin >>x1>>y1>>x2>>y2;
  cout << x2-(y2-y1) << " " << y2+(x2-x1)<< " " << x1-(y2-y1) << " " << y1+(x2-x1);
}


Measured memory_bytes: 256
import Data.List

main = interact $ unlines . map (show' . patrol . map words) . splitBy (== "0 0") . lines
 where show' p = if p then "OK" else "NG"

patrol = all (even.length) . group . sort . concat . (["1","2"]:)

splitBy p xs
 | null xs = []
 | p (head xs) = splitBy p (tail xs)
 | otherwise = (takeWhile (not.p) xs : splitBy p (dropWhile (not.p) xs))

Measured memory_bytes: 4104
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;

int main() {
    int n, m;
    cin >> n >> m;
    VI a(n), b(m);
    REP(i,n) a[i] = in();
    REP(i,m) b[i] = in();
    sort(ALL(a));
    reverse(ALL(a));
    sort(ALL(b));
    reverse(ALL(b));

    REP(i,n-1){
        if (a[i] == a[i+1]){
            cout << 0 << endl;
            return 0;
        }
    }
    REP(i,m-1){
        if (b[i] == b[i+1]){
            cout << 0 << endl;
            return 0;
        }
    }

    ll i = 0, j = 0;
    ll ans = 1;
    REP(p,n*m){
        int x = n * m - p;
        while (i < n && a[i] >= x) i++;
        while (j < m && b[j] >= x) j++;
        if (i == 0 || j == 0){
            cout << 0 << endl;
            return 0;
        }
        ll tmp = 0;
        if (a[i-1] == x && b[j-1] == x) tmp = 1;
        else if (a[i-1] == x) tmp = j;
        else if (b[j-1] == x) tmp = i;
        else tmp = i * j - p;
        if (tmp <= 0){
            cout << 0 << endl;
            return 0;
        }
        ans = (ans * tmp) % mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto ql = new BinaryHeap!(Array!int, "a < b"); // 大きい値から取り出す
    auto qr = new BinaryHeap!(Array!int, "a > b"); // 小さい値から取り出す
    long suml = 0;
    long sumr = 0;
    long sumb = 0;

    int Q = readint;
    while (Q--) {
        auto t = readints;
        if (t[0] == 1) { // 1 a b
            int a = t[1];
            int b = t[2];
            sumb += b;

            if (ql.length == 0 || a < ql.front) {
                suml += a;
                ql.insert(a);
                if (ql.length > qr.length + 1) { // qr に要素を移動
                    int x = ql.front;
                    suml -= x;
                    sumr += x;
                    qr.insert(x);
                    ql.popFront();
                }
            }
            else {
                sumr += a;
                qr.insert(a);
                if (ql.length < qr.length) { // ql に要素を移動
                    int x = qr.front;
                    suml += x;
                    sumr -= x;
                    ql.insert(x);
                    qr.popFront();
                }
            }
        }
        else {
            int m = ql.front; // 中央値
            long v = sumb + (m * ql.length - suml) + (-m * qr.length + sumr);
            writeln(m, " ", v);
        }
    }
}


Measured memory_bytes: 4420
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  LL N, T; std::cin >> N >> T;
  LL total = 0;
  LL last = -1;
  for (int n = 0; n < N; ++n) {
    LL t; std::cin >> t;

    LL next = t + T;
    total += std::min(T, next - last);

    last = next;
  }
  std::cout << total << std::endl;
}


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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  int x=0;
  for(int i=0;i<n;i++){
    x=max(x,a[i]);
  }
  int count=0;
  int y=0;
  int p=-1;
  for(int i=0;i<n;i++){
    if(a[i]==x){
      count++;
      p=i;
    }
    else{
      y=max(y,a[i]);
    }
  }
  if(count>1){
    for(int i=0;i<n;i++){
      cout << x << endl;
    }
  }
  else{
    for(int i=0;i<p;i++){
      cout << x << endl;
    }
    cout << y << endl;
    for(int i=p+1;i<n;i++){
      cout << x << endl;
    }
  }
}

Measured memory_bytes: 2432
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (a <= 0 && 0 <= b)
    {
        cout << "Zero\n";
    }
    else
    {
        if (b < 0)
        {
            if ((b - a + 1) % 2 == 0)
            {
                cout << "Positive\n";
            }
            else
            {
                cout << "Negative\n";
            }
        }
        else
        {
            cout << "Positive\n";
        }
    }
}


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

using namespace std;

int main() {
    long long n, k;
    cin >> n >> k;

    vector<pair<long long, long long>> ab(n, make_pair(0, 0));
    for (int i = 0; i < n; i++) {
        cin >> ab[i].first >> ab[i].second;
    }

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

    long long res = 0;
    for (long long i = 0, j = 0; i < n && j < k; i++, j += ab[i - 1].second) {
        res = ab[i].first;
    }

    cout << res << endl;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);
    long m, n;
    long INF = 1000000007;

    void run(){
	while(sc.hasNext()){
	    m = sc.nextLong();
	    n = sc.nextLong();
	    if(m!=0 && n!=0) 
		System.out.println(solve(m, n) % INF);
	}
    }
    
    long solve(long m, long n){
	if(n==(long)0)
	    return (long)1;
	
	long a = solve(m, n/(long)2);
        if(a>INF) a = a % INF;
	a = (a*a);
	if(a>INF) a = a % INF;
	if(n%(long)2!=(long)0){
	    a = (a*m) % INF;
	}
	return a;
    }
}

Measured memory_bytes: 17332
#include<iostream>
#define INF -2000000001
using namespace std;

int A[2000001],size;

void increase(int i,int key){
  int tmp;
  A[i]=key;
  while(i>1 && A[i/2]<A[i])tmp=A[i],A[i]=A[i/2],A[i/2]=tmp,i=i/2;
}

void insert(int key){
  size++,A[size]=INF;
  increase(size,key);
}

void maxHeapify(int i){
  int l,r,largest,tmp;
 l=i*2;
  r=i*2+1;
  if(l<=size && A[l]>A[i])largest=l;
  else largest=i;

  if(r<=size && A[r]>A[largest])largest=r;
  if(largest!=i){tmp=A[i],A[i]=A[largest],A[largest]=tmp; maxHeapify(largest);}
}

int extractMax(){
  int max;
  max=A[1],A[1]=A[size],size--,maxHeapify(1);
  return max;
}

int main(){
  string s;
  int a;
  while(1){
    cin>>s;
    if(s=="insert")cin>>a,insert(a);
    else if(s=="extract") cout<<extractMax()<<endl;
    else if(s=="end") break;
   }

  return 0;
}

Measured memory_bytes: 5296
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> P;
constexpr auto INF = INT_MAX/2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	vvi s(n, vi(n, 0));
	rep(i, n) {
		string e;
		cin >> e;
		rep(j, n) {
			s[i][j] = e[j] - '0';
			if (s[i][j] == 0 && i != j)s[i][j] = INF;
		}
	}

	rep(k, n)rep(i, n)rep(j, n)s[i][j] = min(s[i][j], s[i][k] + s[k][j]);

	int mxd = 0, r = 0;
	rep(i, n)rep(j, n)if (s[i][j] >= mxd) { r = i, mxd = s[i][j]; }

	vvi v(mxd + 1, vi(0));
	rep(i, n)v[s[i][r]].push_back(i);

	bool ok = true;
	rep(i, mxd + 1)rep(j, v[i].size())rep(k, v[i].size()) if (s[v[i][j]][v[i][k]] == 1)ok = false;
		
	if (ok)cout << mxd + 1 << endl;
	else cout << -1 << endl;

}

Measured memory_bytes: 384
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

struct UnionFind {
  par: Vec<usize>,
  size: Vec<usize>,
}
use std::cmp::Ordering;

impl UnionFind {
  fn new(n: usize) -> Self {
    let mut uf = UnionFind {par: vec![0; n], size: vec![1; n]};
    for (i, item) in uf.par.iter_mut().enumerate() {
      *item = i;
    }
    uf
  }
  fn find(&mut self, x: usize) -> usize {
    if self.par[x] == x {
      x
    } else {
      let px = self.par[x];
      self.par[x] = self.find(px);
      self.par[x]
    }
  }
  fn unite(&mut self, x: usize, y: usize) {
    let x = self.find(x);
    let y = self.find(y);
    if x == y {
      return;
    }
    match self.size[x].cmp(&self.size[y]) {
      Ordering::Less => {
        self.par[x] = y;
        self.size[y] += self.size[x];
      },
      _ => {
        self.par[y] = x;
        self.size[x] += self.size[y];
      }
    }
  }
  fn same(&mut self, x: usize, y: usize) -> bool {
    self.find(x) == self.find(y)
  }
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    m: usize,
    k: usize,
    fr: [(usize1, usize1); m],
    bl: [(usize1, usize1); k],
  }
  let mut uf = UnionFind::new(n);
  for &(a, b) in &fr {
    uf.unite(a, b);
  }
  let mut fr_a = vec![vec![]; n];
  let mut bl_a = vec![vec![]; n];
  for &(a, b) in &fr {
    fr_a[a].push(b);
    fr_a[b].push(a);
  }
  for &(c, d) in &bl {
    bl_a[c].push(d);
    bl_a[d].push(c);
  }
  for i in 0 .. n {
    let root = uf.find(i);
    let mut s = uf.size[root] - fr_a[i].len() - 1;
    for &b in &bl_a[i] {
      if uf.same(i, b) {
        s -= 1;
      }
    }
    puts!("{} ", s);
  }

  puts!("\n");
}


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

using namespace std;

#define ll long long
#define N 2e5


int main() {
//#ifndef ONLINE_JUGDE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif

	ios::sync_with_stdio(0);
    cin.tie(0);
    
    int mod;
    cin>>mod;
    ll val=7%mod;
    for(int i=1;i<1e7;i++){
    	if(val==0){
    		cout<<i;
    		return 0;
		}
    	val=(val*10+7)%mod;	
	}
    cout<<"-1";
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int A[210000];

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

    for (int i = 0; i < n; i++) cin >> A[i];

    sort(A, A+n);

    string ans = "YES";
    for (int i = 0; i < n; i++) {
        if (A[i] == A[i+1]) {
            ans = "NO";
            break;
        }
    }

    cout << ans << endl;



    return 0;

}

Measured memory_bytes: 1024
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;


int main() {
	int n;
	map<ll,ll> map;
	cin >> n;
	
	rep(i, n) {
		ll x;
		cin >> x;
		map[x]++;
	}

	vector<ll> ans;
	ll a = -1;
	for (auto x : map) {
		if (x.second >= 2) {
			ll tmp = x.first;
			ans.push_back(tmp);
		}
	}
	sort(ans.begin(), ans.end(), greater<int>());

	if (ans.size() == 0) {
		cout << 0 << endl;
		return 0;
	}
	if (map[ans[0]] >= 4) {
		cout << ans[0] * ans[0] << endl;
		return 0;
	}
	else cout << ans[0] * ans[1] << endl;
	return 0;
}


Measured memory_bytes: 6528
using System;
using System.Collections;
using System.Linq;
class Pogram{
    static void Main(){
        string[] s = Console.ReadLine().Split(' ');
        int a, b, c;
        a = int.Parse(s[0]);
        b = int.Parse(s[1]);
        c = int.Parse(s[2]);
        for (int i = 1; i <= b; i++){
            if ((a * i) % b == c){
                Console.WriteLine("YES");
                Environment.Exit(0);
            }
        }
        Console.WriteLine("NO");
    }
}

Measured memory_bytes: 13140
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

int main()
{
    int N, L;
    cin >> N >> L;

    vector<int> A(N),B(N);
    rep(i, N) A[i] = i + L;

    int s = 0;

    rep(i, N) s += A[i];

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

    if (A[N - 1] < 0) { s -= A[N-1]; goto xyz; }
    else if (A[0] > 0) { s -= A[0]; goto xyz; }

    for (int i = 0; i < N-1; ++i) {
        if (A[i] * A[i + 1] <= 0) {
            if (abs(A[i]) <= abs(A[i + 1])) {
                s -= A[i];
            }
            else {
                s -= A[i + 1];
            }
        }
    }

xyz:;

    cout << s << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  string S;
  cin >> S;
  map<char, int> mp{};
  REP(i, S.size()) { mp[S[i]]++; }
  for(int i = 'a'; i <= 'z'; i++) {
    if(mp[i]==0){
      char c = i;
      cout << c << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll N,K;
    Scll2(N,K);

    printf ("%lld\n", min(N%K,K-N%K));

    return 0;
}



Measured memory_bytes: 256
## main

n, t, s = gets.strip.split(' ').map{|s0| s0.to_i}

ms = (t + 1).times.map{0}

n.times do
  #p ms
  ms0 = ms
  ms = []

  ai, bi = gets.strip.split(' ').map{|s0| s0.to_i}

  for i in (0..t)
    if i < bi || (i - bi < s && s < i)
      ms[i] = ms0[i]
    else
      ms[i] = [ms0[i], ms0[i - bi] + ai].max
    end
  end
end
#p ms

puts ms.max

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);


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


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

    ll N;
    cin >> N;
    string X;
    cin >> X;

    ll bits = 0;
    for(char c : X){
        if(c=='1') ++bits;
    }

    auto smod = [](string m, ll n){
        if(n==0) return 0ll;
        while(m.length()>61){
            ll offset = m.length() - 61;
            string b0 = m.substr(0, 61);
            string b1 = m.substr(61);
            ll t = stoll(b0, nullptr, 2);
            t %= n;
            //t *= pow_mod(2, offset, n);
            //t %= n;
            if(t>0){
                stringstream ss;
                while(t>0){
                    ss << to_string(t&1);
                    t >>= 1;
                }
                string s = ss.str();
                reverse(all(s));
                m = s + b1;
            }
            else{
                m = b1;
            }
        }
        return stoll(m, nullptr, 2) % n;
    };

    ll t0 = smod(X, bits-1);
    ll t1 = smod(X, bits);
    ll t2 = smod(X, bits+1);

    rep(i, N){
        ll t = 0;
        ll count = 0;
        if(X[i]=='1'){
            t = t0;
            if(bits>1){
                count = 1;
                t = (t-pow_mod(2, N-i-1, bits-1)+(bits-1))%(bits-1);
            }
            else t = 0;
        }
        else{
            t = t2;
            t = (t+pow_mod(2, N-i-1, bits+1))%(bits+1);
            count = 1;
        }
        while(t>0){
            ll bits = bitset<64>(t).count();
            t %= bits;
            ++count;
        }
        cout << count << endl;
    }
}



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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define int long long

const int N = 1e5 + 10;

int n;
struct book {
    int h, p;
}t[N];

bool cmp(const book x, const book y)    {
    return (x.h + x.p) < (y.h + y.p);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n;
    FOR(i, 1, n)    {
        cin >> t[i].h >> t[i].p;
    }
    sort(t + 1, t + n + 1, cmp);
    priority_queue<int> pq;
    int sum = 0ll;
    FOR(i, 1, n)    {
        sum += t[i].p;
        pq.push(t[i].p);
        while(!pq.empty() && sum > t[i].h + t[i].p) {
            sum -= pq.top();
            pq.pop();
        }
    }
    cout << pq.size();
}


Measured memory_bytes: 512
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long a, b;

	cin >> a >> b;
  	long long x = a * b;
 
 	if(a<b){
    	long long tmp = a;
    	a = b;
    	b = tmp;
  	}
 
  	long long r = a % b;
  	while(r!=0){
    	a = b;
    	b = r;
    	r = a % b;
  	}

	cout << x / b << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	string s;cin>>s;
	int count1=0; int count2=0;
	for(int i=0;i<3;i++){
		if(s[i]=='A'){
			count1++;
		}
		else{
			count2++;
		}
	}
	if(count1>0 && count2>0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
main(){
  int i,j,n,code;
  char cm[7],op,dict[262145];
  for(i=0,scanf("%d",&n);i<n;i++){
    scanf("%s",cm);
    j=code=op=0;
    while(op!='\n'){
      scanf("%c",&op);
      if(op=='A') code+=1*pow(4,j++);
      else if(op=='C') code+=2*pow(4,j++);
      else if(op=='G') code+=3*pow(4,j++);
      else if(op=='T') code+=4*pow(4,j++);
    }
    if(cm[0]=='i') dict[code] = 1;
    if(cm[0]=='f') dict[code] ? printf("yes\n") : printf("no\n");
  }
  return 0;
}

Measured memory_bytes: 496
#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define forall(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define dforn(i, n) for(int i = ((int) n) - 1; i >= 0; i--)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int MAXN = 10005000;

struct frac{
    ll a, b;
};
bool operator<(frac a, frac b){
    return a.a*b.b < a.b*b.a;
}
bool operator<=(frac a, frac b){
    return a.a*b.b <= a.b*b.a;
}

ll DIEZ[19];
vector<ll> Ans;
set<ll> W, used;

ll sum(ll n){
    int ans = 0; while(n){ ans += n%10; n /= 10;}
    return ans;
}
bool tem(ll n, int i){
    n %= DIEZ[i+1];
    n /= DIEZ[i];
    return n;
}

void correme(){
    priority_queue<ll> Q;
    ll t = 1e15-1;
    Ans.pb(t); Q.push(t);
    frac mn = {1000*t, 1};
    while(Q.size()){
        ll X = Q.top(); Q.pop();
        frac F = {X, sum(X)};

        if(used.find(X) != used.end())continue; used.insert(X);
        if(F <= mn) {
            Ans.pb(X); mn = F;// db(X);
            forn(i, 18)if(tem(X, i))Q.push(X - DIEZ[i]);
        }
    }
}

int main(){
//	freopen("input.txt", "r", stdin);
//	forn(i, 1e6) J[i] = {i, sum(i)};
//	frac mn = {1e9, 1};
//	dforn(i, 1e7){
//        if(J[i] <= mn){
//            if(i < 1e6)Ans.pb(i);
//            mn = J[i];
//        }
//	}
    DIEZ[0] = 1; forr(i, 1, 19)DIEZ[i] = DIEZ[i-1]*10;
    correme();
	sort(Ans.begin(), Ans.end());
//	forn(i, 200)printf("%d: %d\n", i, Ans[i]);
	int n;
	while(scanf("%d", &n) >= 1){
        forr(i, 1, n+1)printf("%lld\n", Ans[i]);
    }
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>

using namespace std;

bool isPrime(int n) {
    if (n == 1)
        return false;
    for (int i = 2, l = sqrt(n); i <= l; ++i) {
        if (n % i == 0)
            return false;
    }
    return true;
}

int main() {
    int n, v, ans = 0;
    cin >> n;
    while (n--) {
        cin >> v;
        if (isPrime(v))
            ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3084
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
char S[200000+2];
int cnt[2019];
int main(){
  int i;
  int tmp = 0;
  int mul = 1;
  long long res = 0;
  N = rd(S);
  cnt[tmp]++;
  for(i=(N)-1;i>=(0);i--){
    tmp = (tmp + (S[i] - '0') * mul) % 2019;
    mul = (mul * 10) % 2019;
    res += (cnt[tmp]++);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200419-1

// --- original code ---
// int N;
// char S[2d5+2];
// int cnt[2019];
// {
//   int tmp = 0, mul = 1;
//   ll res = 0;
// 
//   rd(S@N);
// 
//   cnt[tmp]++;
//   rrep(i,N){
//     tmp = (tmp + (S[i] - '0') * mul) % 2019;
//     mul = (mul * 10) % 2019;
//     res += (cnt[tmp]++);
//   }
//   wt(res);
// }


Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d,e,f,i=0;
  cin>>a>>b>>c>>d;
  while(c>0&&a>0)
  {
  	i++;
  	if(i%2==1)
  	c=c-b;
  	else
  	a=a-d;
  }
  if(c<=0)
  cout<<"Yes";
  else
  cout<<"No";
}



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

int k, size;
// 0-9
int num[101];
// dp[ 決めた桁数 ][ 未満フラグ ][ 0以外(1-9)==K個 ] :[size][0-1][K] 総数
// 未満フラグ == 0 : ちょうどその数の時。今回は以下なので含む、未満の時は含まない。
int64_t dp[101][2][4];

void add(int i, bool smaller, int current_k, int x)
{
  int64_t now_digit = dp[i][smaller][current_k];

  if (x < num[i])
    smaller = true;

  if (x != 0)
    current_k++;

  // next digit
  i++;

  dp[i][smaller][current_k] += now_digit;
}

void loop(int i, bool smaller, int current_k)
{
  int64_t cnt = dp[i][smaller][current_k];
  if (cnt == 0)
    return;

  int max;

  if (current_k == k)
    max = 0;
  else if (smaller)
    max = 9;
  else
    max = num[i];

  rep(x, max + 1)
      add(i, smaller, current_k, x);
}

int main()
{
  string s;
  cin >> s >> k;
  size = s.size();

  rep(i, size)
      num[i] = s[i] - '0';

  dp[0][0][0] = 1;
  rep(i, size)
      rep(smaller, 2)
          rep(j, k + 1)
              loop(i, smaller, j);
  int64_t cnt = dp[size][0][k] + dp[size][1][k];
  cout << cnt << endl;
}

Measured memory_bytes: 256