akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 1e5+10;
 ll mod = 1e9+7;

vector<bool> b_sta(1e5+10,false);

int main(){
  int n,cnt=0;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  for(int i=1;i<n-1;i++){
    if(p[i-1] < p[i]){
      if(p[i] < p[i+1]) cnt++;
    }else if(p[i+1] < p[i]){
      if(p[i] < p[i-1]) cnt++;      
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K;
  cin >> K;
  

  vector<int> vec(32);
  vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << vec.at(K - 1) <<endl;
}
  

  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long int n, m, y, counter = 0;
    cin >> n;

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

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

 	for (int i = 0; i < n; i++)
 	{
 		m = a[i] - b[i];
 		if (m > 0)
 		{
 			counter = counter + b[i];
 			b[i] = 0;
 		}
 		else
 		{
 			counter = counter + a[i];
 			b[i] = b[i] - a[i];
 			a[i] = 0;
 		}

 		if (b[i] > 0)
 		{
 			y = a[i+1] - b[i];
 			if(y > 0)
 			{
 				counter = counter + b[i];
 				a[i+1] = a[i+1] - b[i]; 
 			}
 			else
 			{
 				counter = counter + a[i+1];
 				a[i+1] = 0;
 			}
 		}

 	}

 	// for (int i = 0; i < n+1; i++)
 	// {
 	// 	cout << a[i];
 	// }

 	cout << counter;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <deque>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdlib>
#include <cassert>

#define el_cucuy ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long
#define pb push_back
#define bpc __builtin_popcount
#define pii pair <int, int>
#define f first
#define s second

const llong mxn = 4 * 1e5 + 3;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

llong n, a[21][21], k, dp[22][1 << 21], sum[mxn];
bool ok = 0;

int main (){
    cin >> n;
    for (int i = 0; i < n; i ++){
        for (int j = 0; j < n; j ++){
            cin >> a[i][j];
        }
    }dp[0][0] = 1;
    for (int M = 0; M < n; M ++){
        for (int mask = 0; mask < (1 << n); mask ++){
            llong x = bpc(mask);
            if(x != M) continue;
            for(int W = 0; W < n; W ++){
                if(a[M][W] == 1 && !(mask & (1 << W))){
                    dp[M + 1][mask | (1 << W)] += dp[M][mask];
                    dp[M][mask] %= mod;
                }
            }
            //cout << i << ' ' << mask << ' ' << dp[i][mask] << endl;
        }
    }cout << dp[n][(1 << n) - 1] % mod;
    return 0;
}




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

using namespace std;


int op(int a, int b){
  return max(a, b);
}
int e(){
  return 0;
}

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

  int ans = 0;
  atcoder::segtree <int, op, e> st(300030);

  for(int i = 0; i < n; ++i){
    int x; 
    cin >> x;
    int l = max(0, x-k);
    int r = min(x+k, 300000);
    int y = st.prod(l, r+1)+1;
    ans = max(ans, y);
    st.set(x, y);
  }
  cout << ans << '\n';

  return 0;
}


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

int main(){
    int N;
    int black[200002] = {};
    int n_black = 0;
    string S;
    cin >> N >> S;

    for(int i=1;i<=N;i++){
        black[i] = black[i-1];
        if(S[i-1] == '#') black[i]++;
    }
    n_black = black[N];

    int ans = 2e5 + 1;
    for(int i=0;i<=N;i++){
        ans = min(ans, black[i] + (N-i) - (n_black - black[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
#include <iostream>
#define CSIZE (128)
using namespace std;

bool is_prefix(string& pat, int& plen, int pos) {
	int len = plen-pos;
	for(int i = 0; i < len; i++)
		if(pat[i] != pat[pos+i]) return false;
	return true;
}

int get_suffix_len(string& pat, int& plen, int pos) {
	for(int i = 0; i <= pos; i++)
		if(pat[pos-i] != pat[plen-1-i]) return i;
	return 0;
}

void make_bm_table(string& pat, int& plen, int shift[][CSIZE]) {
	int len = 0;
	for(int i = plen-1; i > 0; i--) {
		if(is_prefix(pat,plen,i)) len = plen-i;
		for(int j = 0; j < CSIZE; j++)
			shift[i-1][j] = plen-len;
	}
	for(int i = 0; i < plen; i++) {
		len = get_suffix_len(pat,plen,i);
		if(len > 0)
			shift[plen-len-1][pat[i-len]] = plen-i-1;
	}
	for(int j = 0; j < CSIZE; j++)
		shift[plen-1][j] = plen;
	for(int i = 0; i < plen-1; i++)
		shift[plen-1][pat[i]] = plen-i-1;
}

int main() {
	string txt; cin >> txt; int tlen = txt.length();
	string pat; cin >> pat; int plen = pat.length();
	int shift[plen][CSIZE];
	make_bm_table(pat,plen,shift);
	int i,j;
	int ppos = plen-1;
	int sp = -1;
	int ep = 0;
	while(ppos < tlen) {
		i = ppos;
		j = plen-1;
		while(i > sp) {
			if(txt[i] != pat[j]) break;
			i--;
			j--;
		}
		if(i == sp) {
			if(ppos-ep+1 < plen) {
				i = ep-1;
				j -= sp-ep+1;
				while(j >= 0) {
					if(txt[i] != pat[j]) break;
					i--;
					j--;
				}
			} else {
				i = ppos-plen;
				j = -1;
			}
		}
		if(j < 0) {
			cout << ++i << endl;
			j = 0;
		}
		sp = ppos;
		ep = i;
		ppos += shift[j][txt[i]];
	}
	return 0;
}



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

int main(){
    int n,k;
    cin >> n >> k;
    vector<char> s(n);
    for(int i=0;i<n;i++){
        cin >> s.at(i);
    }
    if(s.at(k-1) =='A'){ s.at(k-1) = 'a';}
    else if(s.at(k-1) =='B'){ s.at(k-1) = 'b';}
    else {s.at(k-1) = 'c';}
    for(int i=0;i<n;i++){
        cout << s.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
d = Counter(list(map(int, input().split())))
ans = -1

for k in sorted(d.keys())[::-1]:
    if ans == -1 and d[k] >= 4:
        print(k*k)
        exit()
    elif ans == -1 and d[k] >= 2:
        ans = k
    elif ans != -1 and d[k] >= 2:
        print(ans*k)
        exit()

print(0)

Measured memory_bytes: 18600
s = input()
g = 0
p = 0
ans = 0
for i in range(len(s)):
    if s[i] == 'g':
        if p < g:
            p += 1
            ans += 1
        else:
            g += 1
    elif s[i] == "p":
        if p < g:
            p += 1
        else:
            g += 1
            ans -= 1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(998244353)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main() {
	int x,y; cin>>x>>y;
	bool flg=false;
	rep(i,x+1){
		if(i*2+(x-i)*4==y) flg=true;
	}
	if(flg) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;
int min(int a,int b){
	return (a<b)?a:b;
}
int max(int a,int b){
	return (a>b)?a:b;
}
int fp(int a,int b){
	if(b==0) return 1;
	int x=fp(a,b/2);
	x=(x*x)%mod;
	if(b&1) x=(x*a)%mod;
	return x;
}


signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 int n,m,k;
 cin>>n>>m>>k;
 int a[n+1][m+1];
 memset(a,0,sizeof(a));
 string s;
 for(int i=0;i<n;i++)
 {
 	cin>>s;
 	for(int j=0;j<s.size();j++)
 		a[i][j]=(s[j]=='#'?1:0);
 }
 int ans=0;
 for(int r=0;r<(1ll<<n);r++)
 {
 	for(int c=0;c<(1ll<<m);c++)
 	{
 		int x=0;
 		for(int i=0;i<n;i++)
 		{
 			for(int j=0;j<m;j++)
 			{
 				if(((r>>i)&1)||(c>>j&1))
 					continue;
 				x+=a[i][j];
 			}
 		}
 		if(x==k)
 			ans++;
 	}
 }
 cout<<ans;
  
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
char a[7][6];
char b[6][6];
int n,m,k;
void copy_matrix()
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			b[i][j]=a[i][j];
		}
	}
}
void color(int x,int y)
{
	for(int i=0;i<n;i++)
	{
		if(x&(1<<i))
		{
			for(int j=0;j<m;j++)
			{
				b[i][j]='$';
			}
		}
	}
	for(int i=0;i<m;i++)
	{
		if(y&(1<<i))
		{
			for(int j=0;j<n;j++)
			{
				b[j][i]='$';
			}
		}
	}
}
bool check()
{
	ll count=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(b[i][j]=='#')
			{
				count++;
			}
		}
	}
	if(count==k)
	{
		return true;
	}
	return false;
	
}
int main()
{
	
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>a[i][j];
		}
	}
	ll res=0;
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=0;j<(1<<m);j++)
		{
			copy_matrix();
			color(i,j);
			if(check())
			{
				res++;
			}
		}
	}
	cout<<res;
}

Measured memory_bytes: 3588
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    H, W, K = map(int, rl().split())
    sy, sx, gy, gx = map(lambda n: int(n) - 1, rl().split())
    c = [rl().rstrip() for _ in range(H)]
    
    INF = 10 ** 10
    cost = [[INF] * W for _ in range(H)]
    cost[sy][sx] = 0
    que = deque([(sy, sx)])
    while que:
        cy, cx = que.popleft()
        for dy, dx in ((-1, 0), (0, 1), (1, 0), (0, -1)):
            for k in range(1, K + 1):
                ny, nx = cy + k * dy, cx + k * dx
                if 0 <= ny < H and 0 <= nx < W:
                    if c[ny][nx] == '@':
                        break
                    if cost[ny][nx] <= cost[cy][cx]:
                        break
                    ncost = cost[cy][cx] + 1
                    if ncost < cost[ny][nx]:
                        cost[ny][nx] = ncost
                        que.append((ny, nx))
    print(cost[gy][gx] if cost[gy][gx] != INF else -1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 97464
A=int(input())
B=int(input())
C=int(input())
X=int(input())
S=0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if i*500+j*100+k*50==X:
        S=S+1
print(S)

Measured memory_bytes: 3060
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
unsigned long long int a = 0, b = 0, c = 0,d=0,e=0, ans = 0, x = 0, y = 0, z = 0, n = 0, m = 0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <char> vec{}, vecsec{}, vecth{};
long long int iremono[100001], sec[100001];
long long int iremono2[100001], check[100001];
std::vector<std::string>kinds{}, kaku{};
char maze[1000][1000];
int sx, sy;
int gx, gy;

int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
std::string output, output2, input, input2;
char rev[100001];
int starta, startb, enda, endb,ab;


unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

int H, W;//はんい
 long double syoki=1.0000000000000,pl,w= 1.0000000000000;
int main()
{
	cin >> a >> b;
	for (int i = 1; i <= a; i++) {
		long double syoki = i*1.0000000000000;
		w = 1.0000000000000;
		while(b>syoki){
			
			syoki *= 2;
			w /= 2;
		}
		
		pl += w/a;
	}
	cout << setprecision(100) << pl << endl;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);
	int N = 5;
	vector<int>v(N); rep(i, 0, N) { cin >> v[i]; }
	int K; cin >> K;
	if (v.back() - v[0] > K) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}

	return 0;
}


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

def main():

    import sys

    def input(): return sys.stdin.readline().strip()
    def list2d(a, b, c): return [[c] * b for i in range(a)]
    def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
    def ceil(x, y=1): return int(-(-x // y))
    def INT(): return int(input())
    def MAP(): return map(int, input().split())
    def LIST(): return list(map(int, input().split()))
    def Yes(): print('Yes')
    def No(): print('No')
    def YES(): print('YES')
    def NO(): print('NO')
    sys.setrecursionlimit(10 ** 9)
    INF = float('inf')
    MOD = 10 ** 9 + 7

    N,M=MAP()
    S=LIST()
    T=LIST()

    # dp1[i][j], dp2[i][j] := Sをi文字目、Tをj文字目まで考えた時、dp1はi方向、dp2はj方向に遷移させる
    dp1=list2d(N+2, M+2, 0)
    dp2=list2d(N+2, M+2, 0)
    dp1[0][0]=1
    for i in range(N+1):
        for j in range(M+1):
            dp1[i][j]%=MOD
            # 数え上げをi方向とj方向で重複がないように遷移させる
            dp1[i+1][j]+=dp1[i][j]
            dp2[i][j]+=dp1[i][j]
            dp2[i][j+1]+=dp2[i][j]
            # 今回増やす数値が一致するなら
            if i<N and j<M and S[i]==T[j]:
                # 斜めに遷移させる(1→0)
                dp1[i+1][j+1]+=dp2[i][j]
    print((dp2[N][M])%MOD)

if __name__ == '__main__':
    main()


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

int main(void) {
  int N;
  cin >> N;
  vector<int> P(N);
  rep(i, N) { cin >> P[i]; }

  int answer = 0;
  int current = P[0];
  for (int i = 0; i < N; ++i) {
    if (current == (i + 1)) {
      answer++;
    } else if (i < N - 1) {
      current = P[i + 1];
    }
  }

  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 640
from collections import Counter
from collections import deque
from functools import reduce
from operator import mul
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def COMBINATION(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    o = reduce(mul, range(n, n - r, -1))
    u = reduce(mul, range(1, r + 1))
    return o // u
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n = II()
a = LI()
b = LI()
cnt = 0
for i in range(len(b)):
    if a[n-i] >= b[n-1-i]:
        cnt += b[n-1-i]
        continue
    else:
        cnt += a[n-i]
        b[n-1-i] -= a[n-i]
        if a[n-1-i] >= b[n-1-i]:
            cnt += b[n-1-i]
            a[n-1-i] -= b[n-1-i]
        else:
            cnt += a[n-1-i]
            a[n-1-i] = 0
print(cnt)



Measured memory_bytes: 105960
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int r,g,b;
  cin>>r>>g>>b;
  if((g*10+b)%4 ==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}






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



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000000000009
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 0;i <= n;i++){
    if(i % 3 != 0 && i % 5 != 0) ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(ll (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string s,t;
    cin >> s >> t;
    int slen = s.length();
    int tlen = t.length();

    int ans = slen;
    rep(i,slen-tlen+1){
        //cout << s[i] <<  endl;
        int cnt = 0;
        rep(j,tlen){
            if(s[i+j] == t[j]){
                cnt++;
            }
        }
        
        ans = min(ans,tlen-cnt);
    }

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


Measured memory_bytes: 3624
#include <stdio.h>
int main ()
{
	int n ,q, a,a1[10000],a2[100000],k=0;
	scanf("%d",&n);
	for(int i = 0;i<n;i++)
	{
		scanf("%d",&a1[i]);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++)
	{
		scanf("%d",&a2[i]);
		for(int j=0;j<n;j++)
		{
			if(a1[j]==a2[i])
			 {
			 k++;
			 break;
			 }
		}
	}
	printf("%d\n",k);
	return 0;
}



Measured memory_bytes: 2108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int[] N=cin.ArrayInt(3,0);
        int ans=N[0]-N[1];
        ans=N[2]-ans;
      if(ans<0)ans=0;
      Console.WriteLine(ans);
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public static void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }//Answer.IntArrayAns(x);
    public static void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}










Measured memory_bytes: 13140
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)

N,M=map(int,input().split())

to = [[]*(N+1) for _ in range(N+1)]
for i in range(M):
    x,y=map(int,input().split())
    to[x].append(y)

dp = [-1]*(N+1)

def saiki(v):
    if dp[v]!=-1: return dp[v]
    res = 0
    for u in to[v]:
        res=max(res,saiki(u)+1)
    dp[v]=res
    return res

ans=0
for i in range(1,N+1):
    ans = max(ans,saiki(i))
print(max(dp))


Measured memory_bytes: 149340
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt(), t;
        if (n == 0) {
            System.out.println(0);
        } else {
            StringBuilder builder = new StringBuilder();
            while (n != 0) {
                builder.insert(0, t = Math.abs(n % 2));
                n = (n - t) / -2;
            }
            System.out.println(builder);
        }
    }
}

Measured memory_bytes: 23764
from collections import Counter
from itertools import groupby

s = input()
rlc = [len(list(itr)) for _, itr in groupby(s)]
for i in range(s[0] == '>', len(rlc) - 1, 2):
    rlc[i + (rlc[i] > rlc[i + 1])] -= 1
print(sum(l * (l + 1) * c // 2 for l, c in Counter(rlc).items()))


Measured memory_bytes: 8608
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  int H, W, h, w; cin >> H >> W >> h >> w;
  int p = H/h;
  int q = W/w;
  int x = H%h;
  int y = W%w;

  if (x == 0 && y == 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;

  int a = p*q+1;
  int b = (h*w-1)*a + 1;

  rep(i, H) {
    rep(j, W) {
      if (i%h == h-1 && j%w == w-1) cout << -b;
      else cout << a;
      cout << " ";
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 2048
#pragma GCC optimize ("O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
const lld inf = 1e18+5;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,w;
	cin >> n >> w;
	vector <int> we(n),va(n);
	lld sum=0;
	for(int i=0;i<n;i++)
	{
		cin >> we[i] >> va[i];
		sum+=va[i];
	}
	// vector <vector<lld> > dp(n+1,vector <lld> (sum+1,inf));
	vector <lld> dp(sum+1,inf);
	// for(int i=0;i<=sum;i++)
	// {
	// 	dp[0][i]=inf;
	// }
	// for(int i=0;i<=n;i++)
	// {
	// 	dp[i][0]=0;
	// }
	dp[0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=sum;j>=0;j--)
		{
			if(j-va[i-1]>=0)
			{
				dp[j] = min(dp[j],dp[j-va[i-1]]+we[i-1]);
			}

		}
	}
	lld ans = 0;
	for(int i=0;i<=sum;i++)
	{
		if(dp[i]<=w)
		{
			ans = max(ans,(lld)i);
		}
	}	
	cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 2005;

string s[maxn];
int l[maxn][maxn],r[maxn][maxn];
int u[maxn][maxn],d[maxn][maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
  int n,m;
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>s[i];
  for(int i=0;i<n;i++){
    int pos = -1;
    for(int j=0;j<m;j++){
      if(s[i][j]=='#')pos=j;
      l[i][j]=pos;
    }
    pos = m;
    for(int j=m-1;j>=0;j--){
      if(s[i][j]=='#')pos=j;
      r[i][j]=pos;
    }
  }
  for(int j=0;j<m;j++){
    int pos = -1;
    for(int i=0;i<n;i++){
      if(s[i][j]=='#')pos=i;
      u[i][j]=pos;
    }
    pos = n;
    for(int i=n-1;i>=0;i--){
      if(s[i][j]=='#')pos=i;
      d[i][j]=pos;
    }
  }
  int ret = 0;
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++){
      if(s[i][j]=='#')continue;
      int tt = r[i][j]-l[i][j]-2 + d[i][j]-u[i][j]-2 + 1;
      ret=max(ret,tt);
    }
  cout<<ret<<endl;
  return 0;
}

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

int main()
{
  ll a, b;
  cin>>a>>b;
  if( a <=0 && b>=0 )
  {
      cout<<"Zero";
  }
  else if( a> 0 && b> 0 )
  {
      cout<<"Positive";
  }
  else if( a<0 && b<0)
  {
      if( (b-a+1) %2==0 )
          cout<<"Positive";
      else cout<<"Negative";
  }
}

Measured memory_bytes: 3624
#define s(p)!strstr(a,"th"#p)&&
char*c;main(i,a){for(;~scanf("%[^\n] ",a);puts(a))for(;s(is)s(at)s(e)1;)for(c=a;*c;c++)*c=*c<97?*c:(*c+8)%26+97;c=0;}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;

import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			String[] line = input.readLine().split(" ");
			String lb = System.getProperty("line.separator");
			int a = Integer.parseInt(line[0]);
			int b = Integer.parseInt(line[1]);
			double c = toRadians(Integer.parseInt(line[2]));
			
			double area = (a * b * sin(c)) / 2;
			double perimeter = a + b + pow(a*a + b*b - 2*a*b*cos(c), 0.5);
			double height = b * sin(c);
			
			System.out.println(new StringBuilder().append(String.valueOf(area)).append(lb).append(String.valueOf(perimeter)).append(lb).append(String.valueOf(height)).toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16940
#include<bits/stdc++.h>
#define maxn 120
#define maxw 120000
using namespace std;
typedef long long LL;
LL w[maxn], v[maxn];
LL f[maxn][maxw];
int main(){
	ios::sync_with_stdio(false);
	int N, W;
	cin >> N >> W;
	for(int i = 1; i <= N; i += 1) cin >> w[i] >> v[i];
	for(int i = 1; i <= N; i += 1)
		for(int j = 1; j <= W; j += 1)
				f[i][j] = j >= w[i] ? max(f[i - 1][j], f[i - 1][j - w[i]] + v[i]) : f[i - 1][j];
	cout << *max_element(f[N], f[N] + W + 1);
} 

Measured memory_bytes: 95488
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		String s = scn.next();
      	int max = 0;
        for (int i=1;i<n; ++i){
            String str1 = s.substring(0,i);
            String str2 = s.substring(i);
            int count = 0;
            boolean[] az1 = new boolean[26];
            boolean[] az2 = new boolean[26];
          
            for (int j=0;j<str1.length();j++){
                az1[str1.charAt(j)-'a']=true;
            }
            for (int j=0;j<str2.length();j++){
                az2[str2.charAt(j)-'a']=true;
            }
            for (int j=0;j<26;j++){
                if (az1[j] && az2[j]){
                  count = count + 1;
                }
            }
            max = Math.max(max,count);
        }
        System.out.println(max);
	}
}


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

int main() {
  string s;
  cin >> s;
  long long i;
  long long wc = 0;
  long long count = 0;
  for(i = 0; i < s.length(); i++)
  {
    if(s[i] == 'W') count += wc;
    if(s[i] == 'B') wc++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
struct UnionFind {
	vector<int> par, s;
	UnionFind(int N) : par(N), s(N, 1) { rep(i, 0, N)par[i] = i; }
	int root(int x) { return par[x] == x ? x : par[x] = root(par[x]); }
	void unite(int x, int y) { x = root(x), y = root(y); if (x == y)return; if (s[x] < s[y])swap(x, y); s[x] += s[y]; par[y] = x; }
	bool same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return s[root(x)]; }
	map<int, int> cnt() { map<int, int> cnt; rep2(v, par)cnt[root(v)]++; return cnt; }
};
int main(void) {
	int n, m;
	cin >> n >> m;
	UnionFind tree(n);
	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		a--, b--; tree.unite(a, b);
	}
	int M = 0;
	rep(i, 0, n) {
		M = max(M, tree.size(i));
	}
	printf("%d\n", M);
	return 0;
}


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

int main(){
    int n,t;
    cin>>n>>t;
    vector<pair<int,int>> p(n);
    for(int i=0;i<n;i++){
        int c,t;
        cin>>c>>t;
        p[i]=make_pair(c,t);
    }

    int ans=1e9;
    for(int i=0;i<n;i++){
        if(p[i].second<=t){
            ans=min(ans,p[i].first);
        }
    }
    if(ans==1e9) cout<<"TLE"<<endl;
    else cout<<ans<<endl;
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  ll lim = ll(1e5);
  vector<ll> C(lim + 1);
  for (ll i = 0; i < N; i++) {
    ll a, b; cin >> a >> b;
    C[a] += b;
  }
  ll m = 0;
  for (ll i = 0; i <= lim; i++) {
    m += C[i];
    if (m >= K) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}



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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A.at(i);
  sort(A.begin(),A.end());
  long long ans=1;
  if(N%2==0){
    int cnt=1;
    for(int i=0; i<N; i+=2){
      if(A.at(i)!=cnt || A.at(i+1)!=cnt){
        ans=0;
        break;
      }
      cnt+=2;
      ans=ans*2 % 1000000007;
    }
  }
  else{
    int cnt=2;
    for(int i=1; i<N; i+=2){
      if(A.at(i)!=cnt || A.at(i+1)!=cnt){
        ans=0;
        break;
      }
      cnt+=2;
      ans=ans * 2 % 1000000007;
    }
    if(A.at(0)!=0) ans=0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  int prime[101];
  for (int i = 0; i < 101; i++) {
    prime[i] = 0;
  } 
  for (int i = 2; i <= N; i++) {
    int num = i;
    for (int j = 2; j <= i; j++) {
      while (num % j == 0) {
        num /= j;
        prime[j]++;
      }
    }
  }
  int _74 = 0;
  int _24 = 0;
  int _4 = 0;
  int _14 = 0;
  int _2 = 0;
  for (int i = 0; i < 101; i++) {
    if (prime[i] >= 74) {
      _74++;
    }
    if (prime[i] >= 4) {
      _4++;
    }
    if (prime[i] >= 2) {
      _2++;
    }
    if (prime[i] >= 14) {
      _14++;
    }
    if (prime[i] >= 24) {
      _24++;
    }
  }
  int ans = 0;
  ans += _74;
  ans += _24 * (_2 - 1);
  ans += _14 * (_4 - 1);
  ans += (_4 * (_4 - 1) / 2) * (_2 - 2);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long stair[31];
    stair[0]=1;stair[1]=1;stair[2]=2;stair[3]=4;
    for(int i=4;i<31;i++)
    {
        stair[i]=stair[i-1]+stair[i-2]+stair[i-3];
    }
    int n;
    int ans=0;
    while(true)
    {
        scanf("%d",&n);
        if(n==0)
        break;
        ans=(stair[n]+3649)/3650;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int n ;
  cin >> n;
  vector<int> vn;
  for( int i = 0; i < n; ++i){
    int a;
    cin >> a;
    vn.push_back(a);
  }
  vector<int> vc;
  for(int i = 0; i < n ; ++i){
    int a;
    cin >> a;
    vc.push_back(a);
  }

  vector<int> va;

  for(int i = 0;i < n; ++i){
    va.push_back(vn[i] - vc[i]);
  }

  sort(va.begin(),va.end(),greater<int>());
  int a = 0,i = 0;
  while (i < n && va[i] >= 0) {
    a += va[i];
    i++;
  }

  cout << a << endl;
}


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

#define st first
#define nd second
#define mp make_pair
#define space << " " <<
#define END << endl
#define pb push_back
#define fo(i,n) for(int i = 0; i<n; ++i)
#define ff(i,n) for(int i = 1; i<n; ++i)

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pi;
typedef long long ll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> pl;
typedef vector<pil>vil;

const int N = 4002;

short board[N][N] , U[N][N] , L[N][N] , R[N][N] , D[N][N];
int bit[N][2];
ll ans = 0; int h,w,p,l;

void update(int u,int id,int val) {
    while(u < N) { bit[u][id] += val; u += (u & (-u)); }
}
int get(int u,int id) {
    int ans = 0; while(u > 0) { ans += bit[u][id]; u -= (u & (-u)); } return ans;
}
void up(int id , int le , int ri) {
    if(le > ri) return;
    update(le,id,1); update(ri+1,id,-1);
}

void work(int x,int y)
{
    vector< pair<int,pii> > a; fo(i,N) fo(j,3) bit[i][j] = 0;
    while(x <= h && y <= w ) {
        a.push_back(mp(min(L[x][y],U[x][y]),mp(1,x)));
        a.push_back(mp(min(R[x][y],D[x][y]),mp(0,x)));
        x++; y++;
    } sort(a.begin(),a.end());
    fo(i,a.size()) {
        pair<int,pii> u = a[i];
        if(u.nd.st == 1)
        {
            ans += 1LL * get(u.nd.nd , 1);
            up(0,u.nd.nd - u.st + 1 , u.nd.nd - l + 1);
        }
        else
        {
            ans += 1LL * get(u.nd.nd , 0);
            up(1,u.nd.nd + l - 1 , u.nd.nd + u.st - 1);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> h >> w >> l >> p;
    fo(i,p) { int u,v; cin >> u >> v; board[u][v] = 1; }
    ff(i,h+1) ff(j,w+1) { if(board[i][j]) { L[i][j] = U[i][j] = 0; } else { L[i][j] = L[i][j-1] + 1; U[i][j] = U[i-1][j] + 1; } }
    for(int i=h; i >= 1; --i) for(int j=w; j>= 1; --j) {
        if(board[i][j]) { R[i][j] = D[i][j] = 0; } else { R[i][j] = R[i][j+1] + 1; D[i][j] = D[i+1][j] + 1; }
    }
    ff(i,h+1) work(i,1); for(int j=2; j<=w; ++j) work(1,j); cout << ans << endl;
}

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

const int maxLen = 1e5 +5;
vector<int> edges[maxLen];
int dist[maxLen];
int in_degree[maxLen];
bool is_visited[maxLen];

void dfs(int a) {
    is_visited[a] = true;
    for(int b: edges[a]) {
        in_degree[b]--;
        dist[b] = max(dist[b] , dist[a] + 1);
        if(!is_visited[b] && in_degree[b] == 0)
            dfs(b);
    }
}

int main() {

    int N, M;
    cin >> N >> M;
    for(int i=1; i<=M; i++) {
        int a, b;
        cin >> a >> b;
        edges[a].push_back(b);
        in_degree[b]++;
    }
    for(int i=1; i<=N; i++) {
        if(!is_visited[i] && in_degree[i] == 0) {
            dfs(i);
        }
    }
    int answer;
    for(int i=1; i<=N; i++) {
        answer = max(answer, dist[i]);
    }
    cout << answer;

    return 0;
}


Measured memory_bytes: 9728
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}



int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/


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

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string N;
	cin >> N;
	if (N.at(0) == '9' || N.at(1) == '9')
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
	return 0;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const string abc = "ABC";
void replace(string &s, char c) {
  for (auto pos = s.find(abc); pos != string::npos; pos = s.find(abc, pos + 2)) {
    s[pos] = c;
    s[pos + 1] = s[pos + 2] = '?';
  }
  s.erase(remove(s.begin(), s.end(), '?'), s.end());
}
bool solve(string s) {
  string r;
  string t = s;
  while (s != abc && s.find(abc) != string::npos) {
    if (s.substr(0, 3) == abc) {
      replace(s, 'A');
      r += 'A';
    } else if (s.substr((int) s.size() - 3, 3) == abc) {
      replace(s, 'C');
      r += 'C';
    } else {
      replace(s, 'B');
      r += 'B';
    }
  }
  if (s != abc) return false;
  reverse(r.begin(), r.end());
  for (char c : r) {
    for (int i = 0; i < (int) s.size(); i++) {
      if (c == s[i]) {
        s.erase(s.begin() + i);
        s.insert(s.begin() + i, abc.begin(), abc.end());
        i += 2;
      }
    }
  }
  return s == t;
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  cout << (solve(s) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3264
class UnionFind():
    def __init__(self, n):
        self.parents = [-1]*n
        self.rank = [0]*n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.find(self.parents[x])

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

N,M=list(map(int,input().split()))
S=set()
for _ in range(M):
    a,b=list(map(int,input().split()))
    a-=1
    b-=1
    S.add((a,b))

ct=0
for i in S:
    T=S-{i}
    uf=UnionFind(N)
    for (j,k) in T:
        uf.union(j,k)
    a=uf.find(0)
    for l in range(1,N):
        if a!=uf.find(l):
            ct+=1
            break
print(ct)

Measured memory_bytes: 74028
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

template<typename T> void cinpb(vector<T>& x) { T n; cin >> n; x.push_back(n); }
ull gcd(ull a, ull b) { return b ? gcd(b, a%b) : a; }
ull lcm(ull m, ull n) {	return ((0 == m) || (0 == n)) ? 0 : ((m / gcd(m, n)) * n); }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

void yesno(bool f) { cout << (f ? "Yes" : "No") << endl; }

//


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

	int a, b, c;

	for (int n = N; n <= 999; n++ )
	{
		c = n % 10;
		b = (n % 100 - c) / 10;
		a = (n % 1000 - c - b) / 100;
		if ( a == b && b == c )
		{
			cout << a << b << c << endl;
			break;
		}
	}



	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  std::cin >> S;

  i64 answer = 0;
  for (const char& c : S) {
    switch (c) {
    case '0':
      --answer;
      break;
    case '1':
      ++answer;
      break;
    }
  }

  std::cout << S.size() - std::abs(answer) << std::endl;
  return 0;
}

Measured memory_bytes: 512