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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

// Problem Specific Parameter:

ll x[210], y[210];
const ll mod = 998244353LL;

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

	rep(i, n) cin >> x[i] >> y[i];

	if (n <= 2) {
		puts("0");
		return 0;
	}


	ll ans = 1LL;
	rep(loop, n) ans = 2LL * ans % mod;

	rep(j, n)rep(i, j) {
		vector<int> ary;
		rep(k, n) {
			ll det = (x[k] - x[i]) * (y[j] - y[i]) - (x[j] - x[i]) * (y[k] - y[i]);
			if (det == 0) ary.push_back(k);
		}

		sort(begin(ary), end(ary));
		if (ary[0] != i or ary[1] != j) continue;

		ll minus = 1LL;
		rep(loop, ary.size()) minus = 2LL * minus % mod;
		minus = (minus + mod - ary.size() - 1 ) % mod;
		ans = (ans + mod - minus) % mod;
	}

	ans = (ans + mod - n - 1) % mod;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define mp make_pair
using namespace std;
int n,k,cnt;
int a[200010];
pair<int,int> q[400010];
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	while (k--)
	{
		cnt=0;
		for (int i=1;i<=n;i++)
		{
			q[++cnt]=mp(max(i-a[i],1),1);
			q[++cnt]=mp(min(i+a[i]+1,n+1),-1);
		}
		sort(q+1,q+cnt+1);
		int last=1;
		int flag=1;
		int sum=0;
		for (int i=1;i<=n;i++)
		{
			while (last<=cnt&&q[last].first==i) sum+=q[last].second,last++;
			a[i]=sum;
			flag&=(a[i]==n);
		}
		if (flag) break;
	 } 
	 for (int i=1;i<=n;i++) printf("%d%c",a[i],i==n?'\n':' ');
}

Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,num,ctr;
	cin >> n;
	ctr = 0;
	for (int i = 1; i <= n; i++) {
		cin >> num;
		ctr += (i%2 && num%2);
	}
	cout << ctr;
	return 0;
}

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

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

    int a, b;
    for(int i = 0; i < k; i++){
        cin >> a >> b;
        int color = min(a, min(b, min(n-a+1, n-b+1))) % 3;
        if(color == 0)  color = 3;
        cout << color << endl;
    }   

    return 0;
}


Measured memory_bytes: 3104
N = int(input())
S = input()
blacks = [0 for i in range(N + 1)]
whites = [0 for i in range(N + 1)]
for i in range(N):
    blacks[i + 1] = blacks[i] + (S[i] == '#')
    whites[i + 1] = whites[i] + (S[i] == '.')
result = N
for i in range(N + 1):
    result = min(result, blacks[i] + (whites[N] - whites[i]))
print(result)

Measured memory_bytes: 19364
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;

int gcd(int a, int b){
    if(a < b){
        int tmp = a;
        a = b;
        b = tmp;
    }
    while(true){
        //printf("(%d, %d)\n", a, b);
        a = a % b;
        if(a == 0) break;
        int tmp = a;
        a = b;
        b = tmp;
    }

    return b;
}

int main(){
    int k;
    cin >> k;
    ll ans=0;
    rrep(a, k){
        rrep(b, k){
            int tmp = gcd(a, b);
            rrep(c, k){
                ans += gcd(tmp, c);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  int N; cin >> N;
  vector<ll> A(N),B(N);
  for (int i = 0; i < N; i++) cin >> A[i];
 
  int count = 0;
  for (int i = 0; i < N; i++) if (A[i] < 0) count++;
  
  for (int i = 0; i < N; i++) B[i] = abs(A[i]);
  
  sort(B.begin(),B.end());
  
  ll ans = 0;
  for (int i = 0; i < N; i++) ans += B[i];
  if (B[0] != 0 && count % 2 == 1) ans -= 2*B[0];
  
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;


int h, w, k;
vector<vector<char>> c;

vector<vector<bool>> TFcombination(int n){
    vector<vector<bool>> ans(pow(2, n), vector<bool>(n));
    for(int i = 0; i < (1 << n); i++){
        for(int j = 0; j < n; j++){
            ans[i][j] = i >> j & 1;
        }
    }
    return ans;
}

bool cnt(vector<bool> s1, vector<bool> s2){
    int blk = 0;
    bool ans = false;
    rep(i, h){
        rep(j, w){
            auto x = c[i][j];
            if(!s1[i] && !s2[j] && x == '#'){
                blk++;
            }
        }
    }
    if(blk == k){
        ans = true;
    }
    return ans;
}

int main(){
    cin >> h >> w >> k;
    rep(i, h){
        vector<char> tp;
        rep(i, w){
            char tmp;
            cin >> tmp;
            tp.push_back(tmp);
        }
        c.push_back(tp);
    }

    auto seth = TFcombination(h);
    auto setw = TFcombination(w);
    int ans = 0;

    for(auto s1 : seth){
        for(auto s2 : setw){
            if(cnt(s1, s2)){
                ans++;
            }
        }
    }

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

Measured memory_bytes: 4132
a,b=map(int,input().split())
a-=1
fa,fb=0,0
if a%2==0:
  c=a//2
  if c%2==0:
    fa=a
  else:
    fa=1^a
else:
  c=(a+1)//2
  if c%2==0:
    fa=0
  else:
    fa=1
if b%2==0:
  c=b//2
  if c%2==0:
    fb=b
  else:
    fb=1^b
else:
  c=(b+1)//2
  if c%2==0:
    fb=0
  else:
    fb=1
print(fa^fb)

Measured memory_bytes: 3064
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    char N[4];

    gets(N);

    if (strchr(N, '7')) {
        puts("Yes");
    } else {
        puts("No");
    }

    return 0;
}


Measured memory_bytes: 1912
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		 int hito  = in.nextInt();
		 int day  = in.nextInt();
		 int zan  = in.nextInt();
		 
		 int cnt = 0;
		 for(int i = 0; i < hito ; i++){
		     int nam = in.nextInt();
		     if(day%nam == 0){
		       cnt += day/nam;
		     }else{
		       cnt += day/nam+1;
		     }
		 }
        System.out.print(cnt+zan);
	}
}

Measured memory_bytes: 22868
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n; vector<int> a;
int main() {
	ios::sync_with_stdio(false);
	cin >> n; a.resize(n);
	for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
	int ret = 0;
	for (int i = 0; i < n; i++) {
		if (a[a[i]] == i) ret++;
	}
	cout << ret / 2 << endl;
	return 0;
}

Measured memory_bytes: 640
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	ll x, k, d; cin >> x >> k >> d;
	x = abs(x);
	if (k*d < 0 || x < k*d)
	{
		k -= x / d;
		x %= d;
		if (k % 2 == 0)cout << x << endl;
		else cout << d - x << endl;
	}
	else
	{
		cout << x - k * d << endl;
	}
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;
#define DBG(x) cerr << x << endl;

/*
	http://abc069.contest.atcoder.jp/tasks/arc080_b
*/
int h, w, n;
VI color;
void solve()
{
	VVI ans(h, VI(w));
	for(int i = 0, j = 0, c = 1, d = 0; i < h && c <= n;
	 i += (j == w || j < 0), d ^= (j == w || j < 0), c += (color[c] == 0))
	{
		if(j == w) j = w - 1;
		else if(j < 0) j = 0;

		if(d == 0) {
			for(; j < w && color[c] > 0; --color[c])
				ans[i][j++] = c;
		}
		else {
			for(; j >= 0 && color[c] > 0; --color[c])
				ans[i][j--] = c;
		}
	}

	REP(i, 0, h) {
		REP(j, 0, w)
			cout << ans[i][j] << " ";
		cout << endl;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> h >> w >> n;

	color.resize(n + 1);
	REPC(i, 1, n) cin >> color[i];

	solve();
	
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,m,x,a,ct=0; cin>>n>>m>>x;
	for (int i=0; i<m; i++) {
		cin>>a;
		if(a<x) ct++;
	}
	cout << min(ct,m-ct) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
bool insideNumber(int a, int b, int k)
{
    for(int i = a; i <= b; i++)
    {
        if(i % k == 0)
        {
            return true;
        }
    }
    return false;
}
int main()
{
    int k, a, b;
    cin >> k;
    cin >> a >> b;    
    if(insideNumber(a, b, k))
    {
        cout << "OK" << "\n";
    } else {
        cout << "NG" << "\n";
    }
        
}


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	
	int N;
	cin >> N;
	vector<int> A(N,0);
	int temp = 0;
	for(int i=0; i<N-1; i++){
			cin >> temp;
			A[temp-1]++;
	}

	rep(i,A.size()){
		cout << A[i] << endl;
	}

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 4764
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

signed main() {
	string s;
	cin >> s;
	if (s == "Sunny")cout << "Cloudy" << endl;
	elif(s == "Cloudy")cout << "Rainy" << endl;
	else cout << "Sunny" << endl;
}

Measured memory_bytes: 256
// if文による条件分岐　比較演算子
#include <stdio.h>
#include <stdlib.h>
int main(void){
    char buf[100];
    int a,b;
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf,"%d %d",&a,&b);
    int ans;
    if (b>=a) {
        ans=a;
    } else {
        ans=a-1;
    }
    printf("%d",ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s;
  R s;
  set<char> se;
  rep(i,s.size()) se.in(s[i]);
  rep(i,26) {
    char c=(char)(i+'a');
    if(!se.count(c)) {
      pr(c);
      return;
    }
  }
  pr("None");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
int const INF = 1001001001;


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

int S,W; cin >> S >> W;
if(S <= W) cout << "unsafe" << endl;
else cout << "safe" << endl;

return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
int main()
{
	int a,b,c,d;
	while(scanf("%d",&a)!=EOF)
	{
		d=a%10;
		c=(a/10)%10;
		b=(a/100)%10;
		a=a/1000;
		if(a+b+c+d==7)
		{
			printf("%d+%d+%d+%d=7\n",a,b,c,d);
		}
		else if(a-b+c+d==7)
		{
			printf("%d-%d+%d+%d=7\n",a,b,c,d);
		}
		else if(a+b-c+d==7)
		{
			printf("%d+%d-%d+%d=7\n",a,b,c,d);
		}
		else if(a+b+c-d==7)
		{
			printf("%d+%d+%d-%d=7\n",a,b,c,d);
		}
		else if(a-b-c+d==7)
		{
			printf("%d-%d-%d+%d=7\n",a,b,c,d);
		}
		else if(a-b+c-d==7)
		{
			printf("%d-%d+%d-%d=7\n",a,b,c,d);
		}
		else if(a+b-c-d==7)
		{
			printf("%d+%d-%d-%d=7\n",a,b,c,d);
		}
		else if(a-b-c-d==7)
		{
			printf("%d-%d-%d-%d=7\n",a,b,c,d);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long A;
  cin >> A;
  double B;
  cin >> B;
  int b = round(B * 100.0);
  ll ans = A * b;
  ans /= 100LL;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3760
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>


using namespace std;

int main() {
	string s;
	cin >> s;
	int m = (s[5] - '0') * 10 + (s[6] - '0');
	int d = (s[8] - '0') * 10 + (s[9] - '0');

	bool tmp = true;//Heisei/TBD
	if ((m > 4) || ((m == 4) && (d == 31))) tmp = false;

	string ans = tmp ? "Heisei" : "TBD";
	cout << ans << endl;

	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin >> n;

  vector<ll> a(n);
  REP(i, n)
    cin >> a[i];

  map<ll,ll> amap;
  ll ans = 0;
  REP(i, n){
    amap[a[i]]++;
    if(amap[a[i]] % 2 == 1)
      ans++;
    else
      ans--;
  }
  cout << ans << endl;
  
  
}


Measured memory_bytes: 7296
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

int main(){    
  string S;
  cin >> S;
  if(S.length()%2==1){
    cout << "No" << endl;
  }
  else{
    for(int i=0;i<S.length()/2;i++){
      if(S[2*i]!='h' || S[2*i+1]!='i'){
	cout << "No" <<endl;
	return 0;
      }
    }
  cout << "Yes" << endl;
  }
}


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

int main(){
	int n;
  	cin >> n;
  	
  	ll ans = 0;
  	for(int i = 1; i <= n; i++){
    	ans += (n-1) / i;
    }
  
  	cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
char x[10];
int main()
{
	cin>>x;
	if(x[0]=='Y'&&x[1]=='A'&&x[2]=='K'&&x[3]=='I')
	{
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

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

using namespace std;

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

  int n;
  cin >> n;

  vector<tuple<string, int, int>> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> get<0>(p[i]) >> get<1>(p[i]);
    get<1>(p[i]) *= -1;
    get<2>(p[i]) = i + 1;
  }
  sort(begin(p), end(p));

  for (int i = 0; i < n; ++i) {
    cout << get<2>(p[i]) << '\n';
  }

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>

int main() {
    int N, Y;
    std::cin >> N >> Y;

    int possible = false;
    for (int i = Y / 10000; i >= 0; i --) {
        for (int j = (Y - 10000 * i) / 5000; j >= 0; j --) {
            int k = N - i - j;
            if (10000 * i + 5000 * j + 1000 * k == Y) {
                std::cout << i << " " << j << " " << k << std::endl;
                possible = true;
                break;
            }
        }
        if (possible) break;
    }
    if (!possible) {
        std::cout << "-1 -1 -1" << std::endl;
    }
}


Measured memory_bytes: 256
using System;

class Program
{
	static void Main()
	{
		var input = Console.ReadLine().Split();
		var w = int.Parse(input[0]);
		var h = int.Parse(input[1]);
		var x = int.Parse(input[2]);
		var y = int.Parse(input[3]);
		var r = int.Parse(input[4]);

		if (x - r >= 0 && y - r >= 0 && x + r <= w && y + r <= h)
			Console.WriteLine("Yes");
		else
			Console.WriteLine("No");
	}
}

Measured memory_bytes: 8896
// B - Coins
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> n;
  repe(i, 0, a)
  {
    repe(j, 0, b)
    {
      w = (n - (i * 500 + j * 100)) / 50;
      if (w >= 0 && w <= c)
        count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    string A, B, C;
    cin >> A >> B >> C;

    char nxt = A[0];
    A.erase(0,1);
    while(1){
        if(nxt == 'a'){
            if(!A.empty()){
                nxt = A[0];
                A.erase(0,1);
            }else{
                cout << 'A' << endl;
                break;
            }
        }else if(nxt == 'b'){
            if(!B.empty()){
                nxt = B[0];
                B.erase(0,1);
            }else{
                cout << 'B' << endl;
                break;
            }
        }else{
            if(!C.empty()){
                nxt = C[0];
                C.erase(0,1);
            }else{
                cout << 'C' << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
n = int(input())
# n = 2 * 10**4
# a = [i for i in range(n)]
a = list(map(int, input().split(" ")))

wari = 10**9 + 7

ruiseki = [0]
for i, ai in enumerate(a):
    ruiseki.append(ruiseki[i] + ai)

ans = 0
for i in range(n):
    ans += a[i] * (ruiseki[n] - ruiseki[i+1])
    ans = ans % wari

print(ans)



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

using namespace std;

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

    long double rad;
    rad = 2.0 * M_PI *
          ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 -
           (long double)m / 60.0);

    long double rsq;
    rsq = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(rad);
    printf("%20.20Lf\n", sqrtl(rsq));
    // cout << sqrtl(rsq) << endl;

    return 0;
}

Measured memory_bytes: 4144
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{int p,l,r;};
struct Node T[MAX];
int n;

void Preorder(int u){
  if(u==NIL){
    return;
  }
  printf(" %d",u);
  Preorder(T[u].l);
  Preorder(T[u].r);
}

void Inorder(int u){
  if(u==NIL){
    return;
  }
  Inorder(T[u].l);
  printf(" %d",u);
  Inorder(T[u].r);
}

void Postorder(int u){
  if(u==NIL){
    return;
  }
  Postorder(T[u].l);
  Postorder(T[u].r);
  printf(" %d",u);
}

int main(){
  int i,v,l,r,root;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l!=NIL){
      T[l].p=v;
    }
    if(r!=NIL){
      T[r].p=v;
    }
  }
  
  for(i=0;i<n;i++){
    if(T[i].p==NIL){
      root=i;
    }
  }

  printf("Preorder\n");
  Preorder(root);
  printf("\n");
  printf("Inorder\n");
  Inorder(root);
  printf("\n");
  printf("Postorder\n");
  Postorder(root);
  printf("\n");

  return 0;
}



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

signed main() {
  int N;
  cin >> N;
  int a = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 3 == 0 || i % 5 == 0) {
    }else{
      a += i;
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clear(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	return x * flag;
}

int main() {
#ifdef Qrsikno
	freopen("AGC004_1.in", "r", stdin);
	freopen("AGC004_1.out", "w", stdout);
#endif
	int a = read(), b = read(), c = read();
	if(!((a & 1) * (b & 1) * (c & 1))) {
		puts("0");
		return 0;
	}else{
		LL ans = LLONG_MAX;
		ans = min((1ll * a * b) , min((1ll * b * c), (1ll * c * a)));
		printf("%lld\n", ans);
	}                                        
	return 0;
}


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

int main(){
  std::vector<int> v(4);
  for(int i =0;i<4;i++){
    std::cin >> v[i];
  }

  int t_life = v[0];
  int t_atack = v[1];
  int a_life = v[2];
  int a_atack = v[3];

  while(1){
    a_life -= t_atack;
    if (a_life <= 0){
      printf("Yes");
      return 0;
    }

    t_life -= a_atack;
    if(t_life <= 0){
      printf("No");
      return 0;
    }

  }

  return 0;
}

Measured memory_bytes: 3660
import java.io.InputStream;
import java.io.PrintStream;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int k = Integer.parseInt(sc.next());
    Queue<Long> lunlunQueue = new LinkedList<>();
    for (int i = 1; i < 10; i++) {
      lunlunQueue.add(Long.valueOf(i));
    }
    long ans = 0;
    for (int i = 0; i < k; i++) {
      ans = nextLunlunBfs(lunlunQueue);
    }
    pw.println(ans);
  }

  static Long nextLunlunBfs(Queue<Long> lunlunQueue) {
    Long next = lunlunQueue.poll();
    long digit1 = next % 10;
    if (digit1 > 0) {
      lunlunQueue.add(next * 10 + digit1 - 1);
    }
    lunlunQueue.add(next * 10 + digit1);
    if (digit1 < 9) {
      lunlunQueue.add(next * 10 + digit1 + 1);
    }
    return next;
  }
}


Measured memory_bytes: 40276
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

void main()
{
    auto abc = readln.split.to!(int[]);
    sort(abc);
    auto a = abc[0];
    auto b = abc[1];
    auto c = abc[2];

    writeln(c-b + (b-a+1)/2 + (b-a)%2);
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
bool comparator(P a, P b) {
	return a.first / a.second < b.first / b.second;
}

int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
}


Measured memory_bytes: 3192
# -*- coding: utf-8 -*-

import sys

def debt_interest(debt, weeks, rate=0.05, cut_up=1000):
    if weeks != 1:
        debt = debt_interest(debt, weeks-1, rate=rate, cut_up=cut_up)

    debt *= 1 + rate
    c = debt % cut_up
    if c != 0:
        debt += cut_up - c
    return debt

def main():
    debt = 100000.
    n = int(input())
    ret = debt_interest(debt, n)
    print(int(ret))

if __name__ == '__main__':
    main()

Measured memory_bytes: 7684
// 2020.6.28
// https://atcoder.jp/contests/intro-heuristics
import java.util.*;

public class Main {

	public static void main(String[] args) {

		// ----------
		// 入力
		// ----------

		Scanner sc = new Scanner(System.in);
		int span = Integer.parseInt(sc.next()); // 何日間のスケジューリングをするか
		int minus[] = new int[26]; // 26種類のコンテストの飽きやすさ
		for (int i = 0; i < 26; i++) {
			minus[i] = Integer.parseInt(sc.next());
		}
		int plus[][] = new int[span][26]; // 26種類のコンテストの満足感
		for (int d = 0; d < span; d++) {
			for (int i = 0; i < 26; i++) {
				plus[d][i] = Integer.parseInt(sc.next());
			}
		}
		int input[] = new int[span]; // 開催したコンテスト
		for (int d = 0; d < span; d++) {
			input[d] = Integer.parseInt(sc.next());
		}

		// ----------
		// 変数初期化
		// ----------

		// 各コンテストが最終開催日から何日経過しているか
		int last[] = new int[26];
		for (int i = 0; i < 26; i++) {
			last[i] = 0;
		}

		// ユーザ満足度
		int result = 0;

		// ----------
		// d日目のコンテスト終了時の満足度を計算して出力
		// ----------

		for (int d = 0; d < span; d++) {
			
			// lastの更新
			for (int i = 0; i < 26; i++) {
				if (i == input[d] - 1) {
					last[i] = 0;
				} else {
					last[i]++;
				}
				//System.out.println("last[" + i + "] = " + last[i]);
			}

			// 開催による満足度アップ
			result += plus[d][input[d] - 1];
			
			// 日数経過による満足度ダウン
			for (int i = 0; i < 26; i++) {
				result -= minus[i] * last[i];
				//System.out.println(minus[i] * last[i]);
			}
			System.out.println(result);
		}

	}
}


Measured memory_bytes: 42520
#pragma GCC optimize("O3")

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <numeric>
#include <bitset>
#include <cassert>
#include <random>
#include <unordered_set>
#include <unordered_map>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

int32_t main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int h1, m1;
	int h2, m2;
	int k;
	cin >> h1 >> m1;
	cin >> h2 >> m2;
	cin >> k;
	int len = (h2 * 60 + m2) - (h1 * 60 + m1);
	cout << max(0, len - k);
}


Measured memory_bytes: 3648
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let s = read_vec::<i32>();
    let (a,b) = (s[0],s[1]);
    if (a <= 8 && b <= 8){
        println!("Yay!");
    } else {
        println!(":(");
    }
}


Measured memory_bytes: 4352
a = int(input())
b = int(input())
c = int(input())
x = int(input())
counter = 0

for i in range(a+1):
    oturi = x-500*i
    if oturi < 0:
        break
    else:
        for j in range(b+1):
            oturi_2 = oturi-100*j
            if oturi_2 < 0:
                break
            else:
                if oturi_2 // 50 <= c:
                    counter += 1
print(counter)

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

template<size_t max_N, size_t prime_size>
struct Prime{
    bool sieve[max_N];
    int_fast64_t prime[prime_size];
    size_t counter = 0;
    constexpr Prime() : sieve(), prime() {
        for(int_fast64_t i = 0; i < max_N; ++i)
            sieve[i] = true;
        sieve[0] = sieve[1] = false;
        for(int_fast64_t i = 2; i < max_N; ++i){
            if(sieve[i]){
                prime[counter] = i;
                ++counter;
                if(counter >= prime_size)break;
            }
            for(int_fast64_t j = i * i; j < max_N; j += i)
                sieve[j] = false;
        }
    }
    constexpr int_fast64_t operator[](size_t i) const{
        return i < counter ? prime[i] : prime[counter - 1];
    }
};

constexpr Prime<8831, 1000> p = Prime<8831, 1000>();

constexpr int_fast64_t gcd(int_fast64_t a, int_fast64_t b){
    int_fast64_t t(0);
    while(b){
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

constexpr int_fast64_t lcm(int_fast64_t a, int_fast64_t b){
    return a / gcd(a, b) * b;
}

constexpr int_fast64_t lcm(int_fast64_t a, int_fast64_t b, int_fast64_t c, int_fast64_t d){
    return lcm(lcm(a, b), lcm(c, d));
}

struct Ans{
    int_fast64_t ans[502][502];
    constexpr size_t v(size_t i){
        return i & 1 ? i / 2 : 999 - i / 2;
    }
    constexpr Ans() : ans(){
        for(size_t i = 0; i < 501; ++i){
            ans[i][0] = 1;
            ans[501][i] = 1;
            ans[i + 1][501] = 1;
            ans[0][i + 1] = 1;
        }
        for(size_t i = 1; i <= 500; i += 2)
            for(size_t j = 1; j <= 500; j += 2){
                ans[i][j] = p[v((i + j - 2) / 2)] * p[v((1500 + i - j) / 2)];
                if(i < 500 && j < 500)ans[i + 1][j + 1] = p[v((i + j) / 2)] * p[v((1500 + i - j) / 2)];
            }
        for(size_t i = 1; i < 500; i += 2)
            for(size_t j = 1; j < 500; j += 2){
                ans[i + 1][j] = lcm(ans[i][j], ans[i + 2][j], ans[i + 1][j + 1], ans[i + 1][j - 1]) + 1;
                ans[i][j + 1] = lcm(ans[i][j], ans[i][j + 2], ans[i + 1][j + 1], ans[i - 1][j + 1]) + 1;
            }
    }
    constexpr int_fast64_t at(size_t i, size_t j)const{
        return ans[i + 1][j + 1];
    }
};

constexpr Ans a = Ans();
size_t N;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> N;
    for(size_t i = 0; i < N; ++i){
        for(size_t j = 0; j < N - 1; ++j)cout << a.at(i, j) << " ";
        cout << a.at(i, N - 1) << "\n";
    }
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
// #define int int64_t
#define double long double
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using reverse_queue = priority_queue<T, vector<T>, greater<T>>;
mt19937_64 rnd(time(0));
const int64_t FIXED_RANDOM = rnd();
template<typename T> struct custom_hash{T operator()(T x)const{return (T) x^FIXED_RANDOM;}}; // check hash in whether int64 or int32
template<typename T1, typename T2> using hash_map = gp_hash_table<T1, T2, custom_hash<T1>>;
// Tao luyện kỹ thuật trong 8 năm mày luyện kỹ thuật trong buồng tắm nam
const int MAXN = (int) 2e5 + 2;
const int INF = numeric_limits<int>::max() >> 1;
const int MOD = (int) 998244353;
struct disjoint_set_union{
  vector<int> p, val;
  void init(int _, vector<int> a){
    p.assign(_ + 1, -1);
    val = a;
  }
  int par(int u){
    return p[u] < 0 ? u : (p[u] = par(p[u]));
  }
  int get_low(int u){
    return val[par(u)];
  }
  int get_size(int u){
    u = par(u);
    return -p[u];
  }
  bool same(int u, int v){
    return par(u) == par(v);
  }
  void join(int u, int v){
    if((u = par(u)) == (v = par(v))) return;
    if(p[u] > p[v]) swap(u, v);
    int lower = min(val[u], val[v]);
    p[u] += p[v];
    p[v] = u;
    val[u] = lower;
  }
};
signed main(){
  ios_base::sync_with_stdio(0); 
  cin.tie(0);
  // freopen("FDT.txt", "r", stdin);
  int n;
  cin >> n;
  vector<tuple<int, int, int>> p(n);
  vector<int> temp(n);
  for(int i = 0; i < n; i ++){
    int x, y;
    cin >> x >> y;
    p[i] = make_tuple(x, y, i);
    temp[i] = y;
  }
  vector<int> res(n);
  // cout << "done sorting";
  sort(p.begin(), p.end());
  disjoint_set_union dsu;
  map<int, int> cz;
  dsu.init(n, temp);
  // for(int u: dsu.val) cout << u << " ";
  // cout << endl;
  for(auto point: p){
    int x, y, id;
    tie(x, y, id) = point;
    auto it = cz.upper_bound(y);
    for(auto itr = cz.begin(); itr != it; itr ++){
      pair<int, int> d = *itr;
      // merge
      dsu.join(d.se, id);
      // cout << "join " << d.se + 1 << " " << id + 1 << endl;
      cz[d.fi] = dsu.par(id);
      // cout
    }
    // cout << "!" << dsu.par(6) << " " << dsu.get_low(6) << endl;
    cz[dsu.get_low(id)] = dsu.par(id);
    // cout << "after " << id + 1 << ": ";
    // for(auto u: cz) cout << u.fi << "," << u.se + 1 << "|";
    // cout << endl;
  }
  for(int i = 0; i < n; i ++) cout << dsu.get_size(i) << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
constexpr int N_MAX=1e5+10;
vi imos(N_MAX);

int main(int argc, char** argv) {
  int N, M;
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    int L,R;
    cin >> L >> R; // 1-indexed

    imos[L] += 1;
    imos[R+1] -= 1;
  }

  for (int i=1; i<int(imos.size()); i++) {
    imos[i] += imos[i-1];
  }

  int ret = 0;
  for (auto x : imos) {
    if (x == M) {
      ret++;
    }
  }

  cout << ret << endl;


  return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, m;
int a[3000], b[3000];
int c[3000][3000];
int dp[3000][3000];
signed main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		c[i][0] = 1;
	}
	for (int i = 1; i <= m; i++) {
		cin >> b[i];
		c[0][i] = 1;
	}
	dp[0][0] = 1;
	c[0][0] = 1;
	//dp[i][j]=i番目、j番目の要素を最後に使って作れる共通部分列の総数
	//if(a[i]==b[j]) dp[i][j]=dp[i未満][j未満]の総和
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			c[i][j] = (c[i - 1][j] + c[i][j - 1] % Mod - c[i - 1][j - 1]) % Mod;
			if (a[i] == b[j]) {
				dp[i][j] = c[i - 1][j - 1];
				c[i][j] += dp[i][j];
				c[i][j] %= Mod;
			}
		}
	}
	cout << (c[n][m] + Mod) % Mod << endl;
}

Measured memory_bytes: 96128
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    res = 0
    n = 0
    for i in range(N):
        if a[i]<b[i]+n:
            res += a[i]
        else:
            res += b[i]+n
        if a[i]-n>0:
            c = a[i]-n
        else:
            c = 0
        if b[i]-c>0:
            n = b[i]-c
        else:
            n = 0
    res += min(n, a[-1])
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 19008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

int main(){
    int n,C;
    cin>>n>>C;
    int d[C][C];
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            cin>>d[i][j];
        }
    }
    int c[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>c[i][j];
            c[i][j]--;
        }
    }
    int dsum[3][C];
    memset(dsum,0,sizeof(dsum));
    for(int i=0;i<3;i++){
        for(int j=0;j<C;j++){
            for(int k=0;k<n;k++){
                for(int l=0;l<n;l++){
                    if((k+l)%3==i){
                        dsum[i][j]+=d[c[k][l]][j];
                    }
                }
            }
        }
    }
    int ans=INF;
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            for(int k=0;k<C;k++){
                if(i!=j&&j!=k&&k!=i){
                    ans=min(ans,dsum[0][i]+dsum[1][j]+dsum[2][k]);
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1280
def queenprint() :
    global x
    global col
    global row
    global k
    global maxx
    
    for i in range(maxx):
        for j in range(maxx):
            if x[i][j] and row[i] != j:
                return
       
    for i in range(maxx):
        for j in range(maxx):
            if row[i]==j: 
                print('Q',end='')
            else:
                print('.',end='')
        print()
        
def recursive(i):
    global x
    global col
    global row
    global k
    global maxx
    
    if (i == maxx) :
        queenprint()
        return
    
    for j in range(maxx):
        # 不适合放在这里
        if (col[j] or dpos[i + j] or dneg[i - j + maxx - 1]):
            continue
        # 尝试放下这里
        row[i] = j 
        col[j] = dpos[i + j] = dneg[i - j + maxx - 1] = 1;
        recursive(i + 1);
        # 恢复刚才的操作继续其他的操作
        row[i] = col[j] = dpos[i + j] = dneg[i - j + maxx - 1] = 0

maxx = 8    
k=int(input())
x=[[ 0 for i in range(maxx)] for j in range(maxx)]
col=[0 for i in range(maxx)]
row=[0 for i in range(maxx)]
dpos=[0 for i in range(maxx * 2 - 1)]
dneg=[0 for i in range(maxx * 2 - 1)]
      
for i in range(k):
    r,c=[int(x) for x in input().split()]
    x[r][c] = 1
   
recursive(0)   


Measured memory_bytes: 5616