akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set;

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define     int                 ll
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
	int n,m,k; cin >> n >> m >> k;
	char c;
	int mat[n][m];
	int tot = 0;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			cin>>c;
			if(c=='#'){
				mat[i][j] = 1;
				tot++;
			}
			else{
				mat[i][j] = 0;
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < pow(2,n); ++i){
		for(int j = 0; j < pow(2,m); ++j){
			int cnt = 0;
			vector<vector<int>> vis(n,vector<int>(m));
			for(int i0 = 0; i0 < 32; ++i0){
				if((i>>i0)&1){
					for(int j0 = 0; j0 < m; ++j0){
						if(mat[i0][j0]==1){
							cnt++;
							vis[i0][j0] = 1;
						}
					}
				}
			}
			for(int i0 = 0; i0 < 32; ++i0){
				if((j>>i0)&1){
					for(int j0 = 0; j0 < n; ++j0){
						if(mat[j0][i0]==1 && vis[j0][i0]==0){
							cnt++;
						}
					}
				}
			}
			if(tot-cnt==k){
				ans++;
			}
		}
	}
	cout<<ans<<'\n';
}

signed main() { 
    IO();
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0; 
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
typedef long long ll;

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

    int ans = 1;
    for(int i = 1; i < n; i++){
        bool flag = true;
        for(int j = i - 1; 0 <= j; j--){
            if(vec[i] < vec[j]){
                flag = false;
                break;
            }
        }
        if(flag) ans++;
    }
    OP(ans);
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPE(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void chmax(T& a, T b) { if(a > b) a = b; }
template<class T> void chmin(T& a, T b) { if(a < b) b = a; }
typedef long long ll;

int main() {
    int a, b, k; cin >> a >> b >> k;
    if(b - a + 1 >= k){
        for(int i = a; i < a + k; i++){
            cout << i << endl;
        }
        int m = 0;
        if(a + k > b - k) m = a + k;
        else m = b - k + 1;
        for(int i = m; i <= b; i++){
            cout << i << endl;
        }
    }else{
        for(int i = a; i <= b; i++){
            cout << i << endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
#define MODSIZE 1000000007
priority_queue<int, vector<int>, greater<int> > PQ; // 昇順PQ
// priority_queue<int> PQ;

int main(){
  ll a,b,v,w,t;

  scanf("%lld %lld", &a, &v);
  scanf("%lld %lld", &b, &w);
  scanf("%lld", &t);

  ll mxa = a + v*t;
  ll mna = a - v*t;
  ll mxb = b + w*t;
  ll mnb = b - w*t;

  if(mxa >= mxb && mna <= mnb) printf("YES\n");
  else printf("NO\n");
  return 0;
}


Measured memory_bytes: 3764
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 200005
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
#define pii pair<int, int>
#define ls (root<<1)
#define rs (root<<1|1)
#define mid ((l+r)>>1)
using namespace std;

int n, m;
LL t[MAXN*4], tag[MAXN*4];
vector<pii> vec[MAXN];

void up(int root)
{
    t[root]=max(t[ls], t[rs])+tag[root];
}

void update(int root, int l, int r, int x, int y, LL k)
{
    //printf("%d %d %d %d!!!\n", root, l, r, k);
    if(l>y || r<x) return;
    if(l>=x && r<=y)
    {
        t[root]+=k, tag[root]+=k;
        return ;
    }
    update(ls, l, mid, x, y, k);
    update(rs, mid+1, r, x, y, k);
    up(root);
}

int main()
{
    scanf("%d%d", &n, &m);
    for(rint i=1; i<=m; ++i)
    {
        int l, r, a;
        scanf("%d%d%d", &l, &r, &a);
        vec[r].push_back(make_pair(l, a));
    }
    for(rint i=1; i<=n; ++i)
    {
        update(1, 1, n, i, i, t[1]);
        for(rint j=0; j<vec[i].size(); ++j)
        {
            pii temp=vec[i][j];
            update(1, 1, n, temp.first, i, temp.second);
        }
    }
    printf("%lld\n", max(0LL, t[1]));
}


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

int main() {
	int n; cin >> n;
	vector<int> a(n); for (auto&& x : a)cin >> x;
	sort(a.begin(), a.end());
	cout << a[n - 1] - a[0] << endl;

	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
string c;
  cin >> c;
  int n;
  n = c.length();
  
  
  vector<char> vec(n);
  vector<char> vec2(n);
  rep (i, n) {
    vec.at(i) = c.at(i);
  }
    rep (i, n) {
    vec2.at(n - 1 - i) = c.at(i);
  }
  
  
  vector<char> vechalf((n - 1) / 2);
  vector<char> vechalf2((n - 1) / 2);
   rep (i, (n - 1) / 2) {
    vec.at(i) = c.at(i);
  }
    rep (i, (n - 1) / 2) {
    vec2.at((n - 3) / 2 - i) = c.at(i);
  }
  
  if (vec == vec2 && vechalf == vechalf2) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

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

typedef long long int   ll;
#define int             ll
#define PI              3.1415926535897932384626433832795

#define pb              push_back
#define rep0            for(int i=0;i<n;i++)
#define rep1            for(int i=1;i<=n;i++)
#define inputar0(ar)    for(int i=0;i<n;i++)cin>>ar[i]
#define inputar1(ar)    for(int i=1;i<=n;i++)cin>>ar[i]

#define hell            freopen("input.txt","r", stdin);freopen("output.txt", "w", stdout);freopen("error.txt", "w",stderr);
#define fastasF_boi()   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl            "\n"
//#define cerr            if(false)cerr

int mod=1000000007;
int maxn=200001;
int binpow(int a,int b,int mod){int res=1;while(b>0){if(b%2){res=(res*a)%mod;b--;}a=(a*a)%mod;b/=2;}return res%mod;}
int binpow(int a,int b){int res=1;while(b>0){if(b%2){res=(res*a);b--;}a=(a*a);b/=2;}return res;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}
int mulmod(int a,int b){return ((a%mod)*(b%mod))%mod;}
int addmod(int a,int b){return (((a%mod)+(b%mod))+mod)%mod;}

void solve(){
    double n,x;cin>>n>>x;
    int t;cin>>t;
    cout<<int(ceil(n/x))*t<<endl;
}

signed main(){
//    hell;

    fastasF_boi();
    int t=1;
//    cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
}



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

const long long inf = 1LL << 61;
struct Dinic {
    struct edge {int to, rev; long long flow, w; int id;};
	int n, s, t, mxid;
	vector<int> d, flow_through; vector<int> done;
	vector<vector<edge>> g;
	Dinic() {}
	Dinic(int _n) {
		n = _n + 10; mxid = 0;
		g.resize(n);
	}
	void add_edge(int u, int v, long long w, int id = -1) {
		edge a = {v, (int)g[v].size(), 0, w, id};
		edge b = {u, (int)g[u].size(), 0, 0, -2};//for bidirectional edges cap(b) = w
		g[u].emplace_back(a);
		g[v].emplace_back(b);
		mxid = max(mxid, id);
	}
	bool bfs() {
		d.assign(n, -1); d[s] = 0;
		queue<int> q; q.push(s);
		while (!q.empty()) {
			int u = q.front(); q.pop();
			for (auto &e: g[u]) {
				int v = e.to;
				if (d[v] == -1 && e.flow < e.w) d[v] = d[u] + 1, q.push(v);
			}
		}
		return d[t] != -1;
	}
	long long dfs(int u, long long flow) {
		if (u == t) return flow;
		for (int &i = done[u]; i < (int)g[u].size(); i++) {
			edge &e = g[u][i];
			if (e.w <= e.flow) continue;
			int v = e.to;
			if (d[v] == d[u] + 1) {
				long long nw = dfs(v, min(flow, e.w - e.flow));
				if (nw > 0) {
					e.flow += nw;
					g[v][e.rev].flow -= nw;
					return nw;
				}
			}
		}
		return 0;
	}
	long long max_flow(int _s, int _t) {
		s = _s; t = _t;
		long long flow = 0;
		while (bfs()) {
			done.assign(n, 0);
			while (long long nw = dfs(s, inf)) flow += nw;
		}
		flow_through.assign(mxid + 10, 0);
        for(int i = 0; i < n; i++) for(auto e: g[i]) if(e.id >= 0) flow_through[e.id] = e.flow;
		return flow;
	}
};
int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	long long ans = 0;
	for (int i = 1; i <= n; i++) ans += max(0, a[i]);
	Dinic F(n + 3);
	int s = n + 1, t = n + 2;
	for (int i = 1; i <= n; i++) {
		if (a[i] <= 0) F.add_edge(s, i, -a[i]);
		else F.add_edge(i, t, a[i]);
		for (int j = i + i; j <= n; j += i) {
			F.add_edge(i, j, inf);
		}
	}
	cout << ans - F.max_flow(s, t) << '\n';
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  deque<int> deq;
  rep(i, n){
    if(i % 2 == 0) deq.push_back(a.at(i));
    else deq.push_front(a.at(i));
  }

  while(!deq.empty()){
    if(deq.size() != n){
      cout << " ";
    }
    if(n % 2 == 0){
      cout << deq.front();
      deq.pop_front();
    }else{
      cout << deq.back();
      deq.pop_back();
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 4800
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

const ll mod = 1e9+7;
ll dp[101][10];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  memset(dp,0,sizeof(dp));
  dp[0][1]=1;
  int H,W,K;
  cin>>H>>W>>K;
  if(W==1) {
    cout << 1 << endl;
    return 0;
  }
  //cout << "1<<(W-1)=" << (1<<(W-1)) << endl;
  repeat(h,1,H+1) {
    rep(a,1<<(W-1)) {
            // cout << a << endl;
      rep(i,W-2) {
        if((a>>i)&1 && (a>>(i+1))&1) {
          goto NEXT;
        }
      }
      //cout << "a=" << a << endl;
      if((a>>0)&1) {
        dp[h][1] +=dp[h-1][2];
      } else {
        dp[h][1] += dp[h-1][1];
      }
      dp[h][1]%=mod;
      repeat(i,2,W) {
        //cout << "a&(a<<i)=" << (a&(1<<i)) << endl;
        if((a>>(i-2))&1) { // left
          dp[h][i] += dp[h-1][i-1];
        }else if((a>>(i-1))&1) { // right
          dp[h][i] += dp[h-1][i+1];
        } else {
          dp[h][i] += dp[h-1][i];
        }
        dp[h][i]%=mod;
      }
      if((a>>(W-2))&1) {
        dp[h][W] += dp[h-1][W-1];
      } else {
        dp[h][W]+=dp[h-1][W];
      }
      dp[h][W]%=mod;
      NEXT:;
    }
  }
  // rep(i,5) {
  //   rep(h,5) {
  //     cout << "dp[" << i << "]["<<h<< "]="<<dp[i][h] << endl;
  //   }
  // }
  cout << dp[H][K] << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <array>
#include <cstdio>

using namespace std;

int main()
{
    int N, C;
    if (scanf("%d%d", &N, &C) < 2) return 0;

    array<int, 100000> s, t, c;

    array<int, 100000> sm, tt;

    for (int i = 0; i < N; i++)
    {
        if (scanf("%d%d%d", &s[i], &t[i], &c[i]) < 3) return 0;
    }

    int idxmx = 0;
    sm.fill(0);
    for (int i = 1; i <= C; i++)
    {
        tt.fill(0);
        for (int j = 0; j < N; j++)
        {
            // 始点 + 1
            // 終点 - 1
            // 終点+1 に対して -1 とすると被る
            if (c[j] == i) tt[s[j]- 1]++, tt[t[j]]--;

            // 終点の最大値を取得 ブン回しせず
            if (idxmx < t[j]) idxmx = t[j];
        }

        for (int j = 1; j < idxmx; j++) tt[j] += tt[j - 1];

        for (int j = 0; j < idxmx; j++) if (tt[j] > 0) sm[j]++;
    }

    int mx = 0;
    for (int i = 0; i < idxmx; i++) if (mx < sm[i]) mx = sm[i];

    printf("%d\n", mx);
    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
using namespace std;
int main(){
	int x, b, cards[4][13];
	char P;
	cin >> x;
	for (int i = 0; i < 4; i++){
		for (int k = 0; k < 13; k++){
			cards[i][k] = 0;
		}
	}
	for (int h = 0; h < x; h++){
		cin >> P >> b;
		if (P == 'S'){
			cards[0][b - 1] = 1;
		}
		if (P == 'H'){
			cards[1][b - 1] = 1;
		}
		if (P == 'C'){
			cards[2][b - 1] = 1;
		}
		if (P == 'D'){
			cards[3][b - 1] = 1;
	}
}
for (int r = 0; r < 4; r++){
	for (int m = 0; m < 13; m++){
		if (cards[r][m] == 0){
			if (r == 0){
				cout << "S" << " " << m + 1 << endl;
			}
			if (r == 1){
				cout << "H" << " " << m + 1 << endl;
			}
			if (r == 2){
				cout << "C " << m + 1 << endl;
			}
			if (r == 3){
				cout << "D " << m + 1 << endl;
			}
		}
	}
	}
	
	return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    int N;
    std::cin >> N;
    std::vector<std::pair<int, int>> v(N);
    for (auto& e : v) std::cin >> e.first >> e.second;

    std::sort(v.begin(), v.end());
    for (auto e : v) std::cout << e.first << " " << e.second << std::endl;
}



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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, M, Q;
    cin >> N >> M >> Q;

    vector<Vl> vnum(N + 1, Vl(N + 1));
    for (ll i = 0; i < M; i++) {
        ll l, r;
        cin >> l >> r;
        --l, --r;
        ++vnum[0][r];
        --vnum[l + 1][r];
        --vnum[0][N];
        ++vnum[l + 1][N];
    }

    for (ll i = 0; i <= N; i++) {
        for (ll j = 0; j < N; j++) {
            vnum[i][j + 1] += vnum[i][j];
        }
    }

    for (ll j = 0; j <= N; j++) {
        for (ll i = 0; i < N; i++) {
            vnum[i + 1][j] += vnum[i][j];
        }
    }

    for (ll i = 0; i < Q; i++) {
        ll p, q;
        cin >> p >> q;
        --p, --q;
        cout << vnum[p][q] << "\n";
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 2944
#include<stdio.h>
int main(){
	int s[9000],n,m,t,f,i;
	while(scanf("%d%d",&n,&m),n)
		for(i=t=f=1;i<=n+m;i++){
			scanf("%d",&s[i]);
			if(i>n){t+=s[t+=s[i]];
				if(t>=n&f==1){
					printf("%d\n",i-n);
					f=0;
			}
		}}
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<map>

using namespace std;

struct Memo
{

  int count;
  bool flag;

  Memo()
  {
    count = 0;
    flag = false;
  }

};

Memo memo[31][4];

int ProgressNumberOfYears(int step_num, int step_kind)
{

  int kind_count = 0;

  if(step_num == 0) return 1;
  else if(memo[step_num][step_kind].count) return memo[step_num][step_kind].count;

  //for(int i = 1; i < 4; ++i) if(step_num - i >= 0) kind_count = kind_count + ProgressNumberOfYears(step_num - i,i);

  if(step_num - 3 >= 0)  kind_count = kind_count + ProgressNumberOfYears(step_num - 3,3);
  if(step_num - 2 >= 0)  kind_count = kind_count + ProgressNumberOfYears(step_num - 2,2);
  if(step_num - 1 >= 0)  kind_count = kind_count + ProgressNumberOfYears(step_num - 1,1);

  memo[step_num][step_kind].count = kind_count;

  return kind_count;

}

int main()
{

  int step_num;

  while(cin >> step_num && step_num != 0) cout << ProgressNumberOfYears(step_num,0)/10/365 + 1<< endl;

  return 0;

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll _gcd(ll x, ll y){
    while(1){
        if(x%y == 0)return y;
        else{
            ll z = x%y;
            x = y;
            y = z;
        }
    }
}
//ミョ(-ω- ?)
int main() {
    ll x,y;
    cin >> x >> y;
    cout << x + y - _gcd(x,y)+1 << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

template <class T>
struct Unionfindw {
  // tree number
  vector<int> par;
  // tree rank
  vector<int> treerank;
  // edge weight
  vector<T> weight;
  // constructor
  Unionfindw(int n = 1, T initialnum = 0) {
    stree(n + 1, initialnum);
  }
  // make and initialization
  void stree(int n = 1, T initialnum = 0) {
    par.resize(n);
    treerank.resize(n);
    weight.resize(n);
    for(int i = 0; i < n; ++i) {
      par[i] = i;
      treerank[i] = 0;
      weight[i] = initialnum;
    }
  }
  // search root
  int root(int x) {
    if(par[x] == x) return x;
    int rx = root(par[x]);
    weight[x] += weight[par[x]];
    return par[x] = rx;
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }
  // calculate weight
  T calcw(int x) {
    root(x);
    return weight[x];
  }
  // add
  // x+w = y
  // already added, return 0
  bool uni(int x, int y, T w = 0) {
    w += calcw(x);
    w -= calcw(y);
    x = root(x);
    y = root(y);
    if(x == y) return 0;
    if(treerank[x] < treerank[y]) {
      par[x] = y;
      weight[x] = -w;
    }
    else if(treerank[y] < treerank[x]) {
      par[y] = x;
      weight[y] = w;
    }
    else {
      par[y] = x;
      ++treerank[x];
      weight[y] = w;
    }
    return 1;
  }
  // calculate difference between x and y (y-x)
  // if not same tree, return 1
  T calcdiff(int x, int y) {
    if(!issame(x, y)) return -1;
    return calcw(y) - calcw(x);
  }
};

void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

long long n, m;
vector<pair<long long, long long>> edges[100005];
Unionfindw<long long> ufw;

bool solve();

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int l, r, d;
    cin >> l >> r >> d;
    --l, --r;
    edges[l].push_back(make_pair(d, r));
  }
  prians(solve());
  return 0;
}

bool solve() {
  ufw = Unionfindw<long long>(n + 1);
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < edges[i].size(); ++j) {
      long long r = edges[i][j].se, d = edges[i][j].fi;
      if(!ufw.issame(i, r))
        ufw.uni(i, r, d);
      else if(ufw.calcdiff(i, r) != d)
        return 0;
    }
  return 1;
}

Measured memory_bytes: 9216
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
using namespace std;

#define rep(i,n) for(i=0;i<n;i++)
int main(){
    int i;
    int n;
    cin>>n;
    int max=0;
    int ans=0;
    if(n==1){
        cout<<1;
        return 0;
    }
    rep(i,n+1){
        int cnt=0;
        int p=i;
        while(p%2==0 && p!=0){
            cnt++;
            p/=2;
        }
        if(cnt>max){
            max=cnt;
            ans=i;
        }
    }
    cout<<ans;
}


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

int main()
{
  int n;
  cin >> n;
  long long at = 0, aa = 0;
  
  for(int i = 0; i < n; ++i)
  {
    long long t, a;
    cin >> t >> a;
    if(i == 0)
      at = t, aa = a;
    else
    {
      long long b = (at - 1) / t + 1, c = (aa - 1) / a + 1;
      if(b > c)
        at = t * b, aa = a * b;
      else
        at = t * c, aa = a * c;
    }
  }
  cout << at + aa << endl;
}


Measured memory_bytes: 256
def run(n, a):
    cnt = 0
    for i in range(n):
        while a[i] % 2 == 0:
            a[i] /= 2
            cnt += 1
    return cnt


def read_line():
    n, = input().split()
    a = input().split()
    n = int(n)
    a = [int(a[i]) for i in range(n)]
    return (n, a)


def main():
    n, a = read_line()
    print(run(n, a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 42352
n = gets.to_i
a = gets.split.map(&:to_i)
m = a[0]
idx = 0
for i in 0..n-1
  if m.abs < a[i].abs
    m = a[i]
    idx = i
  end
end
puts 2*n-1
(1..n).each do |i|
  puts "#{idx+1} #{i}"
end
if m > 0
  for i in 1..n-1
    puts "#{i} #{i+1}"
  end
else
  n.downto(2) do |i|
    puts "#{i} #{i-1}"
  end
end

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

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };

const int MAX_X = 1000000;
bool values[MAX_X + 1];

const int MAX_N = MAX_X;
int prime[MAX_N];
bool is_prime[MAX_N + 1];
int eratos(int n)
{
	int p = 0;
	for (int i = 0; i <= n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; i++)
	{
		if(is_prime[i])
		{
			prime[p++] = i;
			for (int j = 2*i; j <= n; j += i) is_prime[j] = false; 
		}
	}
	return p;
}

int main(void)
{
	ios::sync_with_stdio(false);
	eratos(MAX_X);
	int n, x;
	while (cin >> n >> x && n)
	{
		memset(values, false, sizeof(values));
		values[0] = true;
		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			int v = getInt();
			for (int j = 0; j + v <= x; j++)
			{
				if(!values[j]) continue;
				values[j + v] = true;

				if(is_prime[j + v])
					ans = max(ans, j + v);
			}
		}

		cout << (ans ? toString(ans) : "NA") << endl;
	}
	return 0;
}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n >> q;
  std::vector<list<int> > v(n);
  while (q--) {
    int op;
    cin >> op;
    if (op == 0) {
      int t, x;
      cin >> t >> x;
      v[t].push_back(x);
    } else if (op == 1) {
      int t;
      cin >> t;
      for (list<int>::iterator i = v[t].begin(); i != v[t].end(); i++) {
        if (i != v[t].begin()) {
          cout << " ";
        }
        cout << *i;
      }
      cout << endl;
    } else {
      int s, t;
      cin >> s >> t;
      v[t].splice(v[t].end(), v[s]);
    }
  }
}


Measured memory_bytes: 18756
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int

typedef pair<int, int > P;

signed main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int ans = 0;
	vector<int> L(N + 1);
	vector<int> R(N + 1);
	rep(i, N) cin >> L[i] >> R[i];
	L[N] = 0;
	R[N] = 0;
	sort(L.begin(), L.end(), greater<int>());
	sort(R.begin(), R.end());
	rep(i, N + 1) {
		ans += 2 * max(0LL, (L[i] - R[i]));
	}



	cout << ans << endl;


	return 0;
}


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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long,long long>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back

const int MOD1=1000000007;
const int MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const int dx[]={0,1,0,-1,1,-1,1,-1};
const int dy[]={1,0,-1,0,1,1,-1,-1};

#define unless(a) if(!(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(n);i++)
#define bitrep(i,s,n) for(int i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}
long long cutup(long long a,long long b){return (a+b-1)/b;}
long long popcnt(long long a){return __builtin_popcountll(a);}
template<class T,class U> inline bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template<class T,class U> inline bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}

struct edge{long long to,cost;};
struct edge2{long long from,to,cost;};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,m;
    cin>>n>>m;
    string s,t;
    cin>>s>>t;
    ll res=lcm(n,m);
    rep(i,n){
        if((res/n*i)%(res/m)==0){
            ll a=res/n*i;
            a/=res/m;
            if(s[i]!=t[a]){
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3812
import java.util.*;

public class Main {
	
	/*
	 * default function
	 * */	
	int ni() {
		return cin.nextInt();
	}
	
	long nl() {
		return cin.nextLong();
	}
	
	String line() {
		return cin.nextLine();
	}
	
	void println(String str) {	
		System.out.println(str);
	}
	
	void print(String str) {
		System.out.print(str);
	}
	
	/*
	 * default variable
	 */
	
	static final int MOD = 1000000007;
	
	Scanner cin = new Scanner(System.in);	
	String  output;
	
	public static void main(String[] args) {			
		new Main().run();						
	}
	
	/* default above */		
	public void run() {
			
		
		/* 
		 * start
		 */	
		
		solve();
		
		/*
		 * finish
		 */
		
		
			
	}
	/* 
	 * define variable
	 */
	
	String S;
	String T;
	int N;
	
	void solve() {
		
		S = line();
		T = line();
		
		int[] sums = new int[S.length() + 1];
		int[] sumt = new int[T.length() + 1];
		
		sums[1] = S.charAt(0) - 'A' + 1;
		for (int i = 1; i < S.length(); i ++) {
			sums[i+1] = sums[i] + S.charAt(i) - 'A' + 1;
		}
		
		sumt[1] = T.charAt(0) - 'A' + 1;
		for (int i = 1; i < T.length(); i ++) {
			sumt[i+1] = sumt[i] + T.charAt(i) - 'A' + 1;
		}
				
		
		
		N = ni();
		
		for (int i = 0; i < N; i ++) {
			
			int a = ni();
			int b = ni();
			int c = ni();
			int d = ni();
			
			if ((sums[b] - sums[a-1]) % 3 == (sumt[d] - sumt[c-1]) % 3) {
				println("YES");
			} else {
				println("NO");
			}
			
		}
		
	}
	
	
	
}


Measured memory_bytes: 124536
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const int INF=1e9;

int main(){
    int n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    string s;cin>>s;
    int cb=0;
    for(int i=a-1;i<c;i++){
        if(s[i]=='#') cb++;
        else cb=0;
        if(cb>=2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cb=0;
    for(int i=b-1;i<d;i++){
        if(s[i]=='#') cb++;
        else cb=0;
        if(cb>=2){
            cout<<"No"<<endl;
            return 0;
        }
    } 
    if(c>d){
        int cm=0;
        for(int i=b-1;i<d;i++){
            if((i==b-1||i==d-1)&&(s[i-1]=='.'&&s[i+1]=='.')){
                cout<<"Yes"<<endl;
                return 0;
            }
            if(s[i]=='.') cm++;
            else cm=0;
            if(cm>=3){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 576
import java.util.*;

public class Main {

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

        int count = 0;
        for(;true;){
            boolean flag = false;

            for (int i = 0; i<N; i++) {
                if (h[i] > 0) {
                    flag = true;
                    h[i]--;
                }
                else if ((flag && h[i] == 0)) {
                    break;
                }
            }
          	
          if (flag){
            count++;
          }

            boolean check = true;
            for (int i = 0; i<N; i++) {
                if (h[i]>0) {
                    check = false;
                    break;
                }
            }
            if(check) {
                System.out.println(count);
                return;
            }
        }
    }

}

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

using namespace std;

void deeper(int, int&);

static const int A = 1e9 + 7;
static const int MAX_N = 1e5;
static const int MAX_K = 1e5;

struct node {
    vector<int> to;
    int from = 0;
};

unsigned int per[MAX_K - 2];
node vertices[MAX_N];
int n, k;
bool judge = false;

int main() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n - 1; i++) {
        int s, t;
        scanf("%d %d", &s, &t);
        vertices[s-1].to.push_back(t-1);
        vertices[t-1].to.push_back(s-1);
    }
    
    per[0] = k - 2;
    for (int i = 1; i < k - 2; i++) {
        per[i] = (k - i - 2L) * per[i-1] % A;
    }
    
    int res;
    switch (vertices[0].to.size() + 1) {
        case 1:
            res = k;
            break;
        case 2:
            res = static_cast<long>(k) * (k - 1) % A;
            deeper(0, res);
            break;
        default:
            res = static_cast<long>(k) * (k - 1) * per[vertices[0].to.size() - 2] % A;
            deeper(0, res);
            break;
    }
    if (judge == false) printf("%d\n", res);
    else printf("0\n");
    
    return 0;
}

void deeper(int num, int &ans) {
    if (k - 2 < vertices[num].to.size() - 1) judge = true;
    if (vertices[num].to.size() > 1 && num != 0)
        ans = static_cast<long>(per[vertices[num].to.size() - 2]) * ans % A;
    while (vertices[num].to.size() > 0 && judge == false) {
        if (vertices[num].to.back() != vertices[num].from) {
            vertices[vertices[num].to.back()].from = num;
            deeper(vertices[num].to.back(), ans);
        }
        vertices[num].to.pop_back();
    }
}


Measured memory_bytes: 9984
group1 = [1, 3, 5, 7, 8, 10, 12]
group2 = [4, 6, 9, 11]
group3 = [2]

x, y = map(int, input().split())

if (x in group1) and (y in group1):
    print("Yes")
elif (x in group2) and (y in group2):
    print("Yes")
elif (x in group3) and (y in group3):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        //int ans=0;
        String ans="even";

        int hi=sc.nextInt();
        int hy=sc.nextInt();
        int ki=sc.nextInt();
        int ky=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        int d=sc.nextInt();

        int hirosiP=(a*hi)+(b*hy)+(hi/10*c)+(hy/20*d);
        int kenjiroP=(a*ki)+(b*ky)+(ki/10*c)+(ky/20*d);

        if (hirosiP>kenjiroP) {ans="hiroshi";}
        else if (kenjiroP>hirosiP) {ans="kenjiro";}
        System.out.println(ans);
    }
}


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

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

    char u[2*n];
    for (int i = 0; i < 2*n; i++) {
        if ((i % 2) == 0) u[i] = s[i/2];
        else u[i] = t[i/2];
    }
    rep(i, 2*n) cout << u[i];
    cout << endl;
    
}

Measured memory_bytes: 256
class _Node {
  constructor(key, parent = null, left = null, right = null) {
    this.key = key;
    this.parent = parent;
    this.left = left;
    this.right = right;
  }

//   getChildrenNumber() {return (this.left && 1 || 0 ) + (this.right && 1 || 0 );}

  getChildrenNumber() {return Number(!!this.left) + Number(!!this.right);}


  isLeftChild() {
    if (this.parent === null) return null;
    return this.parent.left === this;
  }

  getLeftOrRight() {return this.isLeftChild() ? 'left' : 'right';}

  getSuccessor() {
    let n;
    if (this.right !== null) {
      n = this.right;
      while (n.left !== null) n = n.left;
    } else {
      n = this.parent;
      while (!n.isLeftChild && n.parent != null) n = n.parent;
    }
    return n;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    if (this.root === null) {
      this.root = new BinaryTree.Node(key);
      return;
    }
    let x = this.root, y;
    let newNode = new BinaryTree.Node(key);
    while (x !== null) {
      y = x;
      x = x[key < x.key ? 'left' : 'right'];
    }
    newNode.parent = y;
    y[key < y.key ? 'left' : 'right'] = newNode;
  }

  find(key, n = this.root) {
    if (n === null || n.key === key) return n;
    return this.find(key, n[key < n.key ? 'left' : 'right']);
  }

  delete(key) {
    const n = this.find(key);
    const leftOrRight = n.getLeftOrRight();
    switch (n.getChildrenNumber()) {
    case 0:
      n.parent[leftOrRight] = null;
      break;
    case 1:
      n.parent[leftOrRight] = n.left || n.right;
      n.parent[leftOrRight].parent = n.parent;
      break;
    default:
      const skey = n.getSuccessor().key;
      this.delete(skey);
      n.key = skey;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch (cmd.charAt(0)) {
    case 'i': tree.insert(Number(cmd.split(' ')[1])); break;
    case 'f': console.log(tree.find(Number(cmd.split(' ')[1])) ? 'yes' : 'no'); break;
    case 'd': tree.delete(Number(cmd.split(' ')[1])); break;
    default: tree.print();
    }
  });
})();



Measured memory_bytes: 204280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	int n=sc.nextInt();
	if(n%2==0){
		System.out.println((n-2)/2);
	}else{
		System.out.println((n-1)/2);
	}
	}}

Measured memory_bytes: 21844
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    REP(i, 0, N) cin >> A[i];
    REP(i, 0, N) cin >> B[i];
    REP(i, 0, N) cin >> C[i];
    sort(ALL(A));
    sort(ALL(B));
    sort(ALL(C));

    // 解答の方針はよかったが，TLEやREしないようにするにはupperboundのSTLを活用することが大事だった…

    // Cのとりうる範囲内で，ある数以上になっている数の個数をカウントしてvectorに収納
    // int C_max = C[N - 1];
    // vector<int> C_upper_cnt(C_max + 1);
    // REP(i, 0, N){
    //     chmax(C_upper_cnt[C[i]], N - i);
    // }
    // int Ctmp = 0;
    // for (int i = C_max; i >= 0; --i){  // 直接C内になかった値のインデックス部分は0になってるので右側の値で埋めてやる
    //     if (!chmax(Ctmp, C_upper_cnt[i])){
    //         C_upper_cnt[i] = Ctmp;
    //     }
    // }
    vector<ll> d(N);
    REP(i, 0, N){
        d[i] = (ll)(C.size() - (upper_bound(ALL(C), B[i]) - C.begin()));
    }

    // 各Bの値について，その数以上のBを選択したときのCの候補数の総和
    // int B_max = B[N - 1];
    // vector<ll> B_upper_cnt(B_max + 1);
    // ll C_cnt = 0;
    // for (int i = N - 1; i >= 0; --i){
    //     if (B[i] + 1 > C_max) continue;
    //     C_cnt += C_upper_cnt[B[i] + 1];  //「以上」から「より大きい」に注意
    //     B_upper_cnt[B[i]] = C_cnt;
    // }
    // ll Btmp = 0;
    // for (int i = B_max; i >= 0; --i){
    //     if (!chmax(Btmp, B_upper_cnt[i])){
    //         B_upper_cnt[i] = Btmp;
    //     }
    // }
    for(int i=N-2; i>=0; i--) d[i] += d[i+1];

    ll ans = 0;
    // REP(i, 0, N){
    //     if (A[i] + 1 > B_max) break;
    //     ans += B_upper_cnt[A[i] + 1];  //「以上」から「より大きい」に注意
    // }
    REP(i, 0, N){
        int t = upper_bound(ALL(B), A[i]) - B.begin();
        if(t<N) ans += (ll)d[t];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5068
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

def mine(s,i,j):
	
	ans = 0
	t = s[i-1][j-1]
	if t == '*' or t == '.':
		ans = ans + 0
	else:
		ans = ans + 1

	t = s[i-1][j]
	if t == '*' or t == '.':
		ans = ans + 0
	else:
		ans = ans + 1

	t = s[i-1][j+1]
	if t == '*' or t == '.':
		ans = ans + 0
	else:
		ans = ans + 1

	t = s[i][j-1]
	if t == '*' or t == '.':
		ans = ans + 0
	else:
		ans = ans + 1

	t = s[i][j+1]
	if t == '*' or t == '.':
		ans = ans + 0
	else:
		ans = ans + 1

	t = s[i+1][j-1]
	if t == '*' or t == '.':
		ans = ans + 0
	else:
		ans = ans + 1

	t = s[i+1][j]
	if t == '*' or t == '.':
		ans = ans + 0
	else:
		ans = ans + 1

	t = s[i+1][j+1]
	if t == '*' or t == '.':
		ans = ans + 0
	else:
		ans = ans + 1	

	return ans


h,w = map(int,input().split())
s = [str('*'+input())+'*' for i in range(h)]

test = ''
for i in range(w+2):
	test = test + '*' 

#リストsの頭にtestを追加
s.insert( 0,test)

#リストsの最後にtestを追加
s.insert(len(s),test)

#h行w列の2次元リストの初期化
s2 = [[0] * w for i in range(h)]
						
for i in range(1,h+1):
	for j in range(1,w+1):
		if s[i][j]=='*':
			pass
		elif s[i][j]=='#' :
			s2[i-1][j-1]='#'
		else:
			s2[i-1][j-1] = str(mine(s,i,j))

for i in range(h):
	print(''.join(s2[i]))


Measured memory_bytes: 3192
#include <iostream>
#include <string>

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++ )

int main()
{
  string a, b, c;
  cin >> a >> b >> c;
  if(a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0]) cout << "YES\n";
  else cout << "NO\n";
}


Measured memory_bytes: 256
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Comparator;

public class Main {
    private static final StringBuilder builder = new StringBuilder();
    public static void main(String[] args) {
        int n = readInt(), k = readInt();
        ArrayList<Integer> list = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            list.add(readInt());
        }

        list.sort(Comparator.naturalOrder());
        System.out.print(list.subList(0, k).stream().mapToInt(i -> i).sum());
    }

    private static void read() {
        builder.setLength(0);
        while (true) {
            try {
                int b = System.in.read();
                if (b == ' ' || b == '\n' || b == -1) {
                    break;
                } else {
                    builder.appendCodePoint(b);
                }
            } catch (IOException e) {
                break;
            }
        }
    }

    private static int readInt() {
        read();
        return Integer.parseInt(builder.toString());
    }

    private static int readInt(int radix) {
        read();
        return Integer.parseInt(builder.toString(), radix);
    }

    private static long readLong() {
        read();
        return Long.parseLong(builder.toString());
    }

    private static long readLong(int radix) {
        read();
        return Long.parseLong(builder.toString(), radix);
    }

    private static BigInteger readBigInteger() {
        read();
        return new BigInteger(builder.toString());
    }

    private static BigInteger readBigInteger(int radix) {
        read();
        return new BigInteger(builder.toString(), radix);
    }

    private static double readDouble() {
        read();
        return Double.parseDouble(builder.toString());
    }

    private static BigDecimal readBigDecimal() {
        read();
        return new BigDecimal(builder.toString());
    }

    private static float readFloat() {
        read();
        return Float.parseFloat(builder.toString());
    }

    private static void skipLine() {
        while (true) {
            try {
                int b = System.in.read();
                if (b == '\n' || b == -1) {
                    break;
                }
            } catch (IOException e) {
                break;
            }
        }
    }

    private static void skip() {
        while (true) {
            try {
                int b = System.in.read();
                if (b == ' ' || b == '\n' || b == -1) break;
            } catch (IOException e) {
                break;
            }
        }
    }

}


Measured memory_bytes: 33920
/*
TEMPLATE
by.YXH_XianYu
   2018.7.21
*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LLI long long
#define DBL double
#define CHR char
#define BOL bool
#define REG register
#define rep(i, j, k) for(int i = j, lim = k; i <= lim; i++)
#define req(i, j, k) for(int i = j, lim = k; i >= lim; i--)
#define MXN 100005

int n, m,
	a[MXN],
	b[MXN];

struct Query{
	int a,b;
	bool operator < (const Query &cp) const {
		if(a != cp.a)
			return a < cp.a;
		return b < cp.b;
	}
}w[MXN];

int main() {
	//freopen("TEMPLATE.in", "r", stdin);
	//freopen("TEMPLATE.out", "w", stdout);
	
	scanf("%d %d", &n, &m);
	rep(i, 1, m)
		scanf("%d %d", &w[i].a, &w[i].b);
	std::sort(w+1, w+m+1);
	int ans = 0,
		p = n + 1;
	rep(i, 1, m) {
		if(w[i].a >= p)
			p = n + 1,
			ans ++;
		if(w[i].b <= p)
			p = w[i].b;
	}
	printf("%d\n", ans + 1);

	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

#define N 2e5+5;

int32_t main()
{
    IOS;
    int t=1;
    // cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        int a[n];
        int l=1,r=0;
        for (int i = 0; i < n; ++i)
        {
            cin>>a[i];
            r=max(r,a[i]);
        }
        int ans=0;
        while(l<=r){
            int mid=(l+r)/2;
            int s=0;
            for(int i=0; i<n; i++){
                s+=(a[i]+mid-1)/mid;
                s-=1;
            }
            if(s<=k){
                ans=mid;
                r=mid-1;
            }
            else{
                l=mid+1;
            }
        }
        cout<<ans;
    }
    return 0;
}

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

int main() {
    int n, l;
    cin >> n >> l;
    int all = (l + (l + n - 1)) * n / 2;
    int min_abs = 1000;
    int min_abs_taste = 0;
    for(int i = l; i <= l + n - 1; ++i) {
        if(min_abs > abs(i)) {
            min_abs = abs(i);
            min_abs_taste = i;
        }
    }
    
    cout << all - min_abs_taste << endl;
}


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

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll; 

int h, n;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    int sum = 0;
    cin >> h >> n;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        sum += a;
    }

    if (sum >= h) cout << "Yes";
    else cout << "No";


    return 0;
}

Measured memory_bytes: 256