akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

template<class T>
map<T, int> prime_factorization(T n) {
	map<T, int> ret;

	for (long long i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}

	if (n != 1)ret[n] = 1;
	return ret;
}


int main() {
	map<long long, int> mp;

	long long N;
	cin >> N;
	mp = prime_factorization(N);
	auto iter = mp.begin();
	int count = 0;
	for (; iter != mp.end(); iter++) {
		for (int i = 1; ; i++) {
			if (iter->second < i) {
				break;
			}
			iter->second -= i;
			++count;
		}
	}

	cout << count << endl;

	return 0;
}




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

#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define vec vector<int>
#define dead not_bad

#define left not_right
#define y1 what

using namespace std;

const int N = (int) 2e3 + 10;
const int M = (int) 3e6 + 10;
const ll LINF = (ll) 1e18;
const double PI = 3.14159265359;
const int INF = (int) 1e9 + 7;
const int mod = 1e9 + 7;
const double EPS = (double) 1e-9;

int n, z, w;
int a[N];
int dp[N][N];

int calc(int id, int turn, int x, int y) {
    if (id == n + 1)
        return abs(a[x] - a[y]);
    if (dp[id][turn] != -1) 
        return dp[id][turn];
    int ans = 0;
    if (turn == 0) {
        for (int i = id; i <= n; i++) {
            ans = max(ans, calc(i + 1, turn ^ 1, i, y));
        }
    } else {
        ans = INF;
        for (int i = id; i <= n; i++) {
            ans = min(ans, calc(i + 1, turn ^ 1, x, i));
        }
    }
    return dp[id][turn] = ans;
}

int main() {
    #define fn "billboard"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
    //    freopen(fn".in", "r", stdin);
    //    freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n >> z >> w;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    a[n + 1] = z;
    a[n + 2] = w;
    memset(dp, -1, sizeof(dp));
    cout << calc(1, 0, n + 1, n + 2);
    return 0;
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
#include <iostream>
// #define vi vector <int>
#define seti set<int>
#define mii map<int,int>
#define ull unsigned long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MAX 100100

using namespace std;


int main(){
	
	int n,k;
	cin >> n >> k;
	int ans  = 0;
	for(int i = 0; i < n; i++){
		int h;
		cin >> h;
		if(h >= k)
			ans++;		
	}
	cout << ans;
	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, m, mm;
vector<int> g[200000], gg[200000];
int c[200000], cc[200000];
vector<int> cm[200000], ccm[200000];

vector<int> *curg;
int *curc;
int curnum;

void dfs(int v) {
    curc[v] = curnum;
    for (int to : curg[v]) {
        if (curc[to] == -1) {
            dfs(to);
        }
    }
}

void solve(vector<int> *g, int *c) {
    curg = g;
    curc = c;
    memset(curc, -1, sizeof cc);
    curnum = 0;
    forn(i, n) {
        if (curc[i] == -1) {
            dfs(i);
            ++curnum;
        }
    }
}

vector<int> vv;
vector<int> res;

int ans[200000];

void dfs2(int v) {
    res.pb(v);
    ans[v] = 0;
    for (int x : vv) if (ans[x] == -1 && cc[v] == cc[x]) {
        dfs2(x);
    }
}

int par[200000], ra[200000];
int sz;
int inv[200000];

void dsuInit(int dsz) {
    sz = dsz;
    forn(i, sz) {
        par[i] = i;
        ra[i] = 1;
    }
}

int dsuParent(int v) {
    if (v == par[v]) {
        return v;
    }
    return par[v] = dsuParent(par[v]);
}

void dsuMerge(int u, int v) {
    u = dsuParent(u);
    v = dsuParent(v);
    if (u == v) {
        return;
    }
    if (ra[u] < ra[v]) {
        swap(u, v);
    }
    par[v] = u;
    ra[u] += ra[v];
}

int main() {
    //freopen("input.txt", "r", stdin);
    scanf("%d%d%d", &n, &m, &mm);
    forn(i, m) {
        int from, to;
        scanf("%d%d", &from, &to), --from, --to;
        g[from].pb(to);
        g[to].pb(from);
    }
    forn(i, mm) {
        int from, to;
        scanf("%d%d", &from, &to), --from, --to;
        gg[from].pb(to);
        gg[to].pb(from);
    }
    solve(g, c);
    solve(gg, cc);
    forn(i, n) cm[c[i]].pb(i);
    forn(i, n) ccm[cc[i]].pb(i);
    memset(ans, -1, sizeof ans);
    memset(inv, -1, sizeof inv);
    forn(i, n) {
        vv = cm[i];
        if (int(vv.size()) < 450) {
            for (int x : vv) {
                if (ans[x] == -1) {
                    res.clear();
                    dfs2(x);
                    for (int y : res) {
                        ans[y] = int(res.size());
                    }
                }
            }
        } else {
            int vsz = int(vv.size());
            forn(j, vsz) {
                inv[vv[j]] = j;
            }
            dsuInit(vsz);
            forn(j, n) {
                if (ccm[j].empty()) {
                    break;
                }
                int pre = -1;
                for (int x : ccm[j]) {
                    if (inv[x] == -1) {
                        continue;
                    }
                    if (pre != -1) {
                        dsuMerge(pre, inv[x]);
                    }
                    pre = inv[x];
                }
            }
            forn(j, vsz) {
                inv[vv[j]] = -1;
            }
            forn(j, vsz) {
                ans[vv[j]] = ra[dsuParent(j)];
            }
        }
    }
    forn(i, n) {
        printf("%d ", ans[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 37496
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
   ll a,b,x;cin >>a>>b>>x;
   if(a==0){
       cout <<b/x+1<<endl;
   }
   else {
       cout <<b/x-(a-1)/x<<endl;
   }
}


Measured memory_bytes: 3568
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;
using ll = long long;


int main() {
    int N; cin >> N;
    vector<int> supervisors(N);

    for (int i = 0; i < N-1; i++) {
        int a; cin >> a; --a;
        supervisors[a]++;
    }
    for (auto s : supervisors) {
        cout << s << endl;
    }
}

Measured memory_bytes: 3968
import java.util.Scanner;

public class Main {

     static Scanner scanner;

     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         int N=gi();
         int a=gi()-1;
         int b=gi()-1;
         int c=gi()-1;
         int d=gi()-1;
         String s=gs();

         boolean bs=false;
         String acs= s.substring(a,c+1);
         String bds= s.substring(b,d+1);
         if (acs.contains("##") || bds.contains("##")) {
        	 System.out.println("No");
        	 return;
         }

         if (c<d) {
        	 System.out.println("Yes");
        	 return;
         }

         String bds2= s.substring(b-1,d+2);

         if (bds2.contains("...")) {
        	 System.out.println("Yes");
        	 return;
         } else {
        	 System.out.println("No");
         }

     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 40500
#include <iostream>
#include <stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
int p[100005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&p[i]);
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(p[i]==i)
        {
            cnt++;
            swap(p[i],p[i+1]);
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=k;i<n;i++){
		if(a[i]>a[i-k])
		cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

Measured memory_bytes: 4052
#include <stdio.h>

int main(void)
{
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	if(a < b)
	{
		printf("a < b\n");
	}
	
	else if(a==b)
	{
		printf("a == b\n");
	}
	
	else if(a > b)
	{
		printf("a > b\n");
	}
	
	return 0;
}

Measured memory_bytes: 2680
import java.util.Scanner;

public class Main {
	static long modpow(long n, long y){
		if(y == 0){
			return 1;
		}else if(y == 1){
			return n % MOD;
		}else{
			if(y % 2 == 0){
				long r = modpow(n , y / 2);
				return (r * r) % MOD;
			}else{
				long r = modpow(n , y / 2);
				long r2 = (r * r) % MOD;
				return (r2 * n) % MOD;				
			}
		}
	}

	static final long MOD = 1000000007L;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long all = modpow(10, N);
		long a0 = modpow(9, N);
		long a1 = modpow(9, N);
		long a2 = modpow(8, N);
		long x = (a0 + a1 - a2 + MOD) % MOD;
		long r = (all - x + MOD) % MOD;
//		System.out.println(all+" "+x+" "+r);
		System.out.println(r);
	}
}


Measured memory_bytes: 35672
#include <bits/stdc++.h>
#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 MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n, m;
int u[200005], v[200005];
vector<int> G[1005];
int arr[1005][1005];

void dfs(int x, int y, int tp)
{
	arr[x][y] = arr[x][y] ? -1 : tp;
	rep(i, G[y].size()) {
		int cy = G[y][i];
		if(arr[x][cy] != -1 && arr[x][cy] != tp) dfs(x, cy, tp);
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	rep(i, m) {
		scanf("%d%d", &u[i], &v[i]);
		G[u[i]].push_back(v[i]);
	}
	
	rep1(i, n) arr[i][i] = -1;
	rep(i, m) dfs(u[i], v[i], v[i]);

	rep(i, m) {
		if((arr[u[i]][v[i]] != v[i]) != (arr[v[i]][u[i]] != 0)) printf("diff\n");
		else printf("same\n");
	}
	return 0;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
#define int long long  
#define mod 1000000007
#define am 998244353
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
int abs(int a,int b){ 
  int c=max(a,b)-min(a,b);
  return c;
}
int gcd(int a,int b){//最大公約数
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
}
int lcm(int a,int b){//最小公倍数
    return (a*b)/gcd(a,b);
}	    
signed main(){
// __builtin_ctz(N);      Nを２で何回割り切れるかを返す
//(n+1)*n/2;              １からNまでの総和を求める式
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a,b;
    int c=0;
    cin>>a>>b;
    if(a.size()==b.size()) c=1;
    for(int i=0;i<b.size();i++){
	cout<<a[i];
	cout<<b[i];
    }
    if(!c) cout<<a[a.size()-1];
    
    cout<<"\n";
}



Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, ti, ai int
	fmt.Scan(&n)

	t := 1
	a := 1

	for i := 0; i < n; i++ {
		fmt.Scan(&ti, &ai)
		k := max(1+(t-1)/ti, 1+(a-1)/ai)
		t = ti * k
		a = ai * k
	}
	fmt.Println(t + a)
}

func max(a, b int) int {
	if b > a {
		return b
	}
	return a
}


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

int main(){
  int N;
  cin>>N;
  int ans=1;
  vector<int> h(N);
  for(int i=0;i<N;i++) cin>>h.at(i);
  for(int i=0;i<N-1;i++){   
    if(h.at(i)+1<=h.at(i+1)) h.at(i+1)-=1;
    else if(h.at(i)==h.at(i+1)) continue;
    else{
      ans=0;
      break;
    }
  }
  
  if(ans==1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 640
H,W,K=map(int,input().split())

matrix=[]
for i in range(H):
    matrix.append(input())

ans=0

comb_b=[j for j in range(2**W)]

comb=[(i,comb_b) for i in range(2**H)]

for i in range(2**H):
    for j in range(2**W):
        count=0
        for k in range(H):
            for l in range(W):
                if ((0b1<<k) & comb[i][0]) or ((0b1<<l) & comb[i][1][j]):
                    pass
                else:
                    if matrix[k][l]=="#":
                        count+=1
        if count==K:
            ans+=1

print(ans)

Measured memory_bytes: 68628
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N,M;
int L[100010],R[100010];
int main(){
  cin>>N>>M;
  rep(i,M) cin>>L[i]>>R[i];
  int l=0,r=N+1;
  rep(i,M){
    l=std::max(l,L[i]);
    r=std::min(r,R[i]);
  }
  if(l>r) prin(0);
  else prin(r-l+1);
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define LL long long

using namespace std;

const int base = 1e9+7;
const int maxn = 2000100;

int x[6],y[6],fac[maxn],inv[maxn],ans;

int C(int x,int y) {
   //cout<<fac[x+y]<<" "<<inv[x]<<" "<<inv[y] <<endl;
   //cout<<fac[x+y]<<" "<<inv[x]<<" "<<inv[y] <<endl;
    return 1LL *fac[x+y] * inv[x] % base * inv[y] % base;
}

int W(int x1,int y1,int x2,int y2) {
    //cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
    x1 = abs(x1); y1=abs(y1); x2=abs(x2); y2=abs(y2);
    // cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
  //   cout<<"----------------"<<endl;
    return (1LL *C(x2+1,y2+1) - C(x2+1,y1) - C(x1,y2+1) + C(x1,y1)+base + base) % base;
}


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
   // freopen("in.txt","r",stdin);
    for (int i=1;i<=6;i++) cin>>x[i];
    for (int i=1;i<=6;i++) cin>>y[i];
   // for (int i=1;i<=6;i++) cout<<x[i]<<" "<<y[i]<<endl;
    fac[0]=fac[1]=1;
    for (int i=2;i<=maxn;i++) fac[i]=(1LL*fac[i-1]*i)%base;
    inv[0]=inv[1]=1;
	for(int i=2;i<=maxn;i++) inv[i] = 1LL * (base - base / i) * inv[base % i] % base;
	for(int i=2;i<=maxn;i++) inv[i] = 1LL * inv[i-1] * inv[i] % base;
    ans=0;
   for (int i=x[3];i<=x[4];i++) ans=(ans + 1LL*(base-i-y[3]) * W(i-x[2],y[3]-1-y[2],i-x[1],y[3]-1-y[1]) %base * W(i-x[5],y[3]-y[5],i-x[6],y[3]-y[6]))%base;
    for (int i=x[3];i<=x[4];i++) ans=(ans + 1LL*(i+y[4]+1) * W(i-x[2],y[4]-y[2],i-x[1],y[4]-y[1]) %base * W(i-x[5],y[4]-y[5]+1,i-x[6],y[4]-y[6]+1))%base;
    for (int i=y[3];i<=y[4];i++) ans=(ans + 1LL*(base-i-x[3]) * W(x[3]-1-x[2],i-y[2],x[3]-1-x[1],i-y[1]) %base * W(x[3]-x[5],i-y[5],x[3]-x[6],i-y[6]))%base;
    for (int i=y[3];i<=y[4];i++) ans=(ans + 1LL*(i+x[4]+1) * W(x[4]-x[2],i-y[2],x[4]-x[1],i-y[1]) %base * W(x[4]-x[5]+1,i-y[5],x[4]-x[6]+1,i-y[6]))%base;
    cout<<ans<<endl;

}



Measured memory_bytes: 15872
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t

int main()
{
	string a[3];
	cin >> a[0] >> a[1] >> a[2];
	vector<deque<char>> x(3);
	ff(i, 0, 3) {
		ff(j, 0, a[i].size()) {
			x.at(i).push_back(a[i][j]);
		}
	}
	char turn = 'A';
	while (1) {
		if (turn == 'A') {
			if (x.at(0).empty()) {
				cout << turn << endl;
				return 0;
			}
			turn = x.at(0).front();
			x.at(0).pop_front();
		}
		else if (turn == 'B') {
			if (x.at(1).empty()) {
				cout << turn << endl;
				return 0;
			}
			turn = x.at(1).front();
			x.at(1).pop_front();
		}
		else if (turn == 'C') {
			if (x.at(2).empty()) {
				cout << turn << endl;
				return 0;
			}
			turn = x.at(2).front();
			x.at(2).pop_front();
		}
		if (turn == 'a') {
			turn= 'A';
		}
		if (turn == 'b') {
			turn = 'B';
		}
		if (turn == 'c') {
			turn = 'C';
		}
	}
	return 0;
}

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


int main()
{
    long N;
    cin >> N;
    vector<long> A(N), B(N);

    rep(i, N) {
        cin >> A.at(i);
        B.at(A.at(i) - 1) = i + 1;
    }

    rep(i, N - 1) {
        cout << B.at(i) << " ";
    }
    cout << B.at(N-1) << endl;
    return 0;
}

Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int A = Integer.parseInt(scan.next());
		int B = Integer.parseInt(scan.next());
		int[] P = new int[N];
		for (int i = 0; i < N; i++) {
			P[i] = Integer.parseInt(scan.next());
		}
		int contestNum = 0;
		int maxNum = N / 3;
		boolean firstQ;
		boolean secondQ;
		boolean thirdQ;
		for (int j = 0; j < maxNum; j++) {
			firstQ = false;
			secondQ = false;
			thirdQ = false;
			for (int i = 0; i < N; i++) {
				if (firstQ == false && P[i] != -1 && P[i] <= A) {
					firstQ = true;
					P[i] = -1;
				}
				if (secondQ == false && P[i] > A && P[i] <= B) {
					secondQ = true;
					P[i] = -1;
				}
				if (thirdQ == false && P[i] > B) {
					thirdQ = true;
					P[i] = -1;
				}
			}
			if (firstQ && secondQ && thirdQ) {
				contestNum++;
			}
		}
		System.out.println(contestNum);
	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,dp[100009],dp2[100009];
pair <long long, long long> p[100009];
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>b;
	for(c=1; c<=a; c++){
		cin>>p[c].first>>p[c].second;
	}
	dp[p[1].first]=p[1].second;
	for(c=2; c<=a; c++){
		for(d=0; d<=b; d++){
			if(dp2[d]<dp[d]) dp2[d]=dp[d];
			if(d+p[c].first<=b){
				if(dp2[d+p[c].first]<p[c].second+dp[d]) dp2[d+p[c].first]=p[c].second+dp[d];
			}
		}
		for(d=0; d<=b; d++){
			dp[d]=dp2[d];
			dp2[d]=0;
		}
	}
	for(c=0; c<=b; c++){
		if(e<dp[c]) e=dp[c];
	}
	cout<<e;
	return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var nm = br.readLine().split(" ");
      final var n = Integer.parseInt(nm[0]);
      final var m = Integer.parseInt(nm[1]);
      final var s = new String[m];
      for (int i = 0; i < s.length; i++) {
        final var stringBuilder = new StringBuilder();
        stringBuilder.append("0".repeat(n));
        Arrays.stream(br.readLine().split(" "))
          .skip(1)
          .forEach((idx) -> stringBuilder
            .replace(Integer.parseInt(idx) - 1, Integer.parseInt(idx), "1"));

        s[i] = stringBuilder.toString();
      }

      final var p = Arrays.stream(br.readLine().split(" "))
        .mapToInt(Integer::parseInt)
        .toArray();

      var size = 0;
      for (int i = 0; i < Math.pow(2, n); i++) {
        var ok = true;
        for (int j = 0; j < m; j++) {
          final var bin = Integer.toBinaryString(Integer.parseInt(s[j], 2) & i)
            .toCharArray();

          var countOne = 0;
          for (char c : bin) {
            if (c == '1') {
              countOne++;
            }
          }

          ok &= countOne % 2 == p[j];
        }

        if (ok) {
          size++;
        }
      }

      System.out.println(size);
    }
  }
}


Measured memory_bytes: 36928
#include<bits/stdc++.h>
#define ll long long
#define N 300009
#define M 10000009
using namespace std;

int n,cnt,tp,c[N][2],fa[N],len[N],lf[N],rg[N],sz[N]; ll p[N],q[N],np[N],nq[N],a[M],b[M];
bool dfs(int x,ll lim){
	int y=c[x][0],z=c[x][1];
	if (!y){
		sz[x]=1; lf[x]=rg[x]=++cnt;
		a[cnt]=b[cnt]=len[x];
		return 1;
	}
	if (dfs(y,lim) && dfs(z,lim)){
		if (sz[y]>sz[z]) swap(y,z);
		int i,j,k;
		tp=0;
		for (i=lf[y],j=lf[z]; i<=rg[y]; i++){
			for (; j<=rg[z] && b[i]+a[j]<=lim; j++);
			if (j>lf[z]){
				p[++tp]=a[i]; q[tp]=b[j-1];
			}
		}
		if (!tp) return 0;
		for (i=1; i<=tp; i++){
			p[(tp<<1|1)-i]=q[i]; q[(tp<<1|1)-i]=p[i];
		}
		for (i=k=1,j=tp+1; k<=(tp<<1); k++)
			if (j>(tp<<1) || i<=tp && p[i]<=p[j]){
				np[k]=p[i]; nq[k]=q[i++];
			} else{
				np[k]=p[j]; nq[k]=q[j++];
			}
		lf[x]=cnt+1;
		for (i=1; i<=(tp<<1); i++)
			if (i==1 || np[i]>a[cnt] && nq[i]<b[cnt]){
				a[++cnt]=np[i]; b[cnt]=nq[i];
			} else if (np[i]==np[i-1]) b[cnt]=min(b[cnt],nq[i]);
		rg[x]=cnt; sz[x]=rg[x]-lf[x]+1;
		for (i=lf[x]; i<=rg[x]; i++){
			a[i]+=len[x]; b[i]+=len[x];
		}
	} else return 0;
	return 1;
}
bool ok(ll lim){
	cnt=0; return dfs(1,lim);
}
int main(){
	scanf("%d",&n);
	int i;
	for (i=2; i<=n; i++){
		scanf("%d%d",&fa[i],&len[i]);
		c[fa[i]][c[fa[i]][0]>0]=i;
	}
	ll l=0,r=1ll<<36,mid;
	while (l<r){
		mid=l+r>>1;
		if (ok(mid)) r=mid; else l=mid+1;
	}
	printf("%lld\n",l);
	return 0;
}


Measured memory_bytes: 37632
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline void goodbye(const T& val) { cout << val << endl; exit(0); }

const int MAXN  = (int)1007;
const int NDIRS = 4;

pii Q[MAXN * MAXN];
int dist[MAXN][MAXN], head = 0;
int H, W;

int di[] = {0, 0, -1, 1};
int dj[] = {-1, 1, 0, 0};

int valid(int i, int j) {
	return (i >= 0 && j >= 0 && i < H && j < W);
}

void solve() {
	cin >> H >> W;

	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W; ++j) {
			dist[i][j] = INT_INF;
		}
	}

	for(int i = 0; i < H; ++i) {
		string line;
		cin >> line;

		for(int j = 0; j < W; ++j) {
			if(line[j] == '#') {
				Q[head++] = make_pair(i, j);
				dist[i][j] = 0;
			}
		}
	}

	for(int j = 0; j < head; ++j) {
		pii v = Q[j];

		for(int dir = 0; dir < NDIRS; ++dir) {
			pii u = make_pair(v.first + di[dir], v.second + dj[dir]);

			if(valid(u.first, u.second) && dist[u.first][u.second] > dist[v.first][v.second] + 1) {
				dist[u.first][u.second] = dist[v.first][v.second] + 1;
				Q[head++] = u;
			}
		}
	}

	int answ = 0;

	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W; ++j) {
			answ = max(answ, dist[i][j]);
		}
	}

	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 12032
import java.util.*;
import java.io.*;

public class Main {

	void solve() {
		int n = in.nextInt();
		int[] a=  new int[n];
		Map<Integer, Integer> count = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
			if (!count.containsKey(a[i])) {
				count.put(a[i], 0);
			}
			count.put(a[i], count.get(a[i]) + 1);
		}
		
		List<Integer> b = new ArrayList<>();
		for (int i : count.keySet()) {
			for (int j = 0; j < count.get(i) / 2; j++) {
				b.add(i);
			}
		}
		Collections.sort(b);
		if (b.size() < 2) {
			out.println(0);
		} else {
			out.println(1L * b.get(b.size() - 2) * b.get(b.size() - 1));
		}
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 43808
nab=input().split(" ")
N,A,B=int(nab[0]),int(nab[1]),int(nab[2])
if abs(A-B)%2==0:
  print(abs(A-B)//2)
else:
  ans=0
  A,B=min(A,B),max(A,B)
  #まず端に近い選手を端に寄せる手数
  #Aと端の距離はA-1 Bと端の距離はN-B
  ans+=min(A-1,N-B)
  ans+=1 #端で1試合留まる
  print(ans+(abs(A-B)-1)//2)
  
    

Measured memory_bytes: 3060
s=list(input())


l=0
r=len(s)-1

count=0
while True:
    #print(s,l,r)
    if s[l]!=s[r]:
        if s[l]=="x":
            #s.insert(r+1,"x")
            l+=1
        elif s[r]=="x":
            #s.insert(l,"x")
            r-=1
            #l+=1
        else:
            res=-1
            break

        #print(s,l,r)


        count+=1
    else:
        r-=1
        l+=1

    if l>=r:
        res=count
        break


print(res)


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,K;
string S;
cin>>N>>K>>S;
for(int i=0;i<N;i++){
    if(i==K-1)
       S[i] =tolower(S[i]);
cout<<S[i];
}

	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
 
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}
 

ll mod_pow(ll x, ll n, ll mod) {
    if (n == 1) return x;
    ll ret = 1;
    if (n % 2 == 1) {
        ret *= x;
        ret %= mod;
    }
    ll p = mod_pow(x, n / 2, mod);
    ret *= p; ret %= mod;
    ret *= p; ret %= mod;
    return ret;
}

void solve() {
    ll N, K;
    cin >> N >> K;
    const int mod = 1e9 + 7;
    
    vector<ll> dp(K + 1, 0);
    
    for(ll i = K; i >= 1; i--) {
        dp[i] = mod_pow(K / i, N, mod);
        for(ll j = i * 2; j <= K; j += i) {
            dp[i] += (mod - dp[j]) % mod;
        }
    }
    
    ll ans = 0;
    for(ll i = 1; i <= K; i++) {
        ans += i * dp[i];
        ans %= mod;
    }
    cout << ans << endl;
    
}
 
int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 3976
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
    int i, j, max, a1, a2, a3, b1, b2, b3;
    int c[3][3];
    int flag = 0;
    
    max = 0;
    for(i = 0; i < 3; i++){
        for(j = 0; j < 3; j++){
            scanf("%d", &c[i][j]);
            if(max < c[i][j]){
                max = c[i][j];
            }
        }
    }
    
    for(a1 = 0; a1 <= max; a1++){
        for(a2 = 0; a2 <= max; a2++){
            for(a3 = 0; a3 <= max; a3++){
                b1 = c[0][0] - a1;
                b2 = c[0][1] - a1;
                b3 = c[0][2] - a1;
                
                if(a1+b1==c[0][0] && a1+b2==c[0][1] && a1+b3==c[0][2] && 
                   a2+b1==c[1][0] && a2+b2==c[1][1] && a2+b3==c[1][2] &&
                   a3+b1==c[2][0] && a3+b2==c[2][1] && a3+b3==c[2][2]){
                   
                   flag = 1;
                   }
            
            }
        }
    }
    
    if(flag == 1){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N,K;
ll A[1010];
vector<ll> V;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N) {
		cin>>A[i];
		ll v=A[i];
		V.push_back(v);
		for(j=i-1;j>=0;j--) {
			v+=A[j];
			V.push_back(v);
		}
	}
	
	ll cur=0;
	for(i=59;i>=0;i--) {
		vector<ll> V2;
		FORR(v,V) if(v&(1LL<<i)) V2.push_back(v);
		if(V2.size()>=K) {
			cur|=1LL<<i;
			V=V2;
		}
		else {
			FORR(v,V) if(v&(1LL<<i)) v^=1<<i;
		}
	}
	cout<<cur<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
int my_max(int a,int b)
{
	return a>b ?a:b;
}
int main()
{
	int a[3];
	for(int i=0;i<3;i++)
		scanf("%d",&a[i]);
	int sum=0;
	int max=0;
	for(int i=0;i<3;i++)
		for(int k=i+1;k<3;k++)
		{
			sum+=abs(a[i]-a[k]);
			max=my_max(max,abs(a[i]-a[k]));
		}
	printf("%d\n",sum-max);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
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;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(c,b/a)<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_5_A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int[] target = ReadIntAr();
            int m = ReadInt();
            int[] searchKeys = ReadIntAr();

            for (int i = 0 ; i < m ; i++)
            {
                Console.WriteLine(IsCreateMAfterI(0, searchKeys[i], n, target) ? "yes":"no");
            }

        }

        public static bool IsCreateMAfterI(int i ,int m, int n, int[] a)
        {
            if (m == 0) return true;
            if (i >= n) return false;
            bool res = IsCreateMAfterI(i + 1, m, n, a) || IsCreateMAfterI(i + 1, m - a[i], n, a);
            return res;
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 15924
// itne me hi thakk gaye?
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
#define ll long long 
#define ull unsigned long long
using ld = long double;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll rk = 256;
const ld PI = 3.141592653589793;
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define print(a) for(auto j:a) {cout<<j<<",";} cout << "\n";
#define endl '\n'
#define whatis(x) cout << "> "<<#x << " ==> " << x << endl;
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
// // Printing pair
ostream & operator << (ostream & os, pair <ll, ll> const& x) {
    os << x.first << "," << x.second;
    return os;
}
 
// printing vector
template <class T>
ostream & operator << (ostream & os, vector <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
// printing set
template <class T>
ostream & operator << (ostream & os, set <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
const int mxn = 1e5+5;

int32_t main(){
    int n; cin >> n;
    vc <ll> dp(3, 0);
    for(int day=0; day<n; day++) {
        vc <ll> cost(3);
        vc <ll> new_dp(3, -1);
        for(int i=0; i<3; i++) cin >> cost[i];
        for(int i=0; i<3; i++) {
            for(int j=0; j<3; j++) {
                if (i!=j) {
                    new_dp[j] = max(new_dp[j], dp[i] + cost[j]);
                }
            }
        }
        dp = new_dp;
    }
    cout << *max_element(all(dp)) << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
b = gets.split(' ').map(&:to_i)

a = []
a << b[0]
a << b[0]

b.each_cons(2) do |i, j|
  if i <= j
    a << j
  else
    a.delete_at(a.length-1)
    a << j
    a << j
  end
end

print "#{a.inject(:+)}"

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int A[2]; cin >> A[0] >> A[1];
	sort(A, A + 2);
	if (A[0] == A[1]) cout << 2 * A[1];
	else cout << 2 * A[1] - 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <functional>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
#define fi first
#define se second
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

  ll N; cin>>N;

  ll res = 0;
  reps(i,1, N+1) {
    if(i%3==0 || i%5==0)continue;
    else res+=i;
  }
  cout<<res<<endl;

  return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    VI a(n), cnt(n);
    REP(i,n){
        scanf("%d", &a[i]);
        a[i]--;
        cnt[a[i]]++;
    }

    VI p(n);
    REP(i,n){
        REP(j,cnt[i]){
            if (i - j >= 0) p[i - j]++;
        }
    }

    int ans = 0;
    REP(i,n) ans += (p[i] == 0);

    while (m--){
        int i, y;
        scanf("%d %d", &i, &y);
        y--;
        int x = a[i-1];
        a[i-1] = y;
        // cout << x << " " << y << endl;
        cnt[x]--;
        if (x - cnt[x] >= 0){
            p[x - cnt[x]]--;
            if (p[x - cnt[x]] == 0) ans++;
        }
        if (y - cnt[y] >= 0){
            p[y - cnt[y]]++;
            if (p[y - cnt[y]] == 1) ans--;
        }
        // cnt[x]--;
        cnt[y]++;
        // cout << endl;
        // REP(i,n) cout << p[i] << " ";
        // cout << endl;
        printf("%d\n", ans);
    }

    return 0;
}


Measured memory_bytes: 3840
_,*a=$<.map{|e|e=~/^[MARCH]/ ? e : "*"}
a=a.group_by{|e|e[0]}.map{|k, v| k==?* ? 0 : v.size}
res=0
for i in 0...a.size
    for j in i+1...a.size
        for k in j+1...a.size
            res+=a[i]*a[j]*a[k]
        end
    end
end
p res


Measured memory_bytes: 12492
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1E-11;

map <pair<pll, bool>, ll> Mx;
int getdigit(ll x) {
	int rv = 0;
	while (x) {
		rv++;
		x /= 10;
	}
	return rv;
}

ll po10[20];
ll aa(int d, ll v, bool c) {
	if (d == 0) {
		if (v == 0) return 1;
		return 0;
	}
	if (d == 1) {
		if (v == 0) {
			if (c) return 9;
			return 10;
		}
		return 0;
	}
	if (Mx.count(mp(pll(d, v), c))) return Mx[mp(pll(d, v), c)];

	if (po10[d] <= abs(v)) return 0;
	int i, j;

	ll rv = 0;
	for (i = 0; i <= 9; i++) {
		for (j = 0; j <= 9; j++) {
			if (c && (i == 0)) continue;

			ll t = po10[d - 1] * (j - i) + i - j;
			if ((v - t) % 10) continue;
			rv += aa(d - 2, (v - t) / 10, false);
		}
	}
	return Mx[mp(pll(d, v), c)] = rv;
}
int main() {
	ll D;
	scanf("%lld", &D);

	bool c = true;
	ll ans = 1;
	while (D % 10 == 0) {
		if (ans == 1) ans = 9;
		else ans *= 10;
		D /= 10;
		c = false;
	}

	po10[0] = 1;
	for (int i = 1; i <= 18; i++) po10[i] = po10[i - 1] * 10;

	ll ans2 = 0;
	for (int i = 1; i <= 18; i++) ans2 += aa(i, D, c);
	return !printf("%lld\n", ans * ans2);
}

Measured memory_bytes: 256
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
cnt=0
for i in range(N):
    cnt+=min(A[i],B[i])
    if A[i]>=B[i]:
        continue
    else:
        cnt+=min(B[i]-A[i],A[i+1])
        A[i+1]=max(0,A[i+1]-B[i]+A[i])
print(cnt)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n,m,s,t;
ll d[100010][3];
vector<ll> g[100010];

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

  cin>>n>>m;
  rep(i,m){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
  }
  cin>>s>>t;
  s--;t--;
  rep(i,n)rep(j,3)d[i][j]=INF;
  queue<P> que;
  d[s][0]=0;
  que.push(P(s,0));
  while(que.size()){
    P p=que.front(); que.pop();
    ll np=(p.se+1)%3;
    for(ll nv : g[p.fi]){
      if(d[nv][np]!=INF)continue;
      d[nv][np]=d[p.fi][p.se]+1;
      que.push(P(nv,np));
    }
  }
  ll res=d[t][0];

  if(res==INF)cout<<-1<<endl;
  else{
    cout<<res/3<<endl;
  }

  return 0;
}


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

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

int main() {
    while (true)
    {
        int w, h;
        cin >> w >> h;
        if (w == 0 && h == 0) break;

        int grid[100][100];
        rep(i, w) rep(j, h) grid[i][j] = 0;

        int sx, sy, gx, gy;
        cin >> sx >> sy >> gx >> gy;
        sx--; sy--; gx--; gy--;

        int n;
        cin >> n;

        rep(i, n) {
            int c, d, x, y;
            cin >> c >> d >> x >> y;
            if (d == 0) {
                rep(j, 4) rep(k, 2) grid[j+x-1][k+y-1] = c;
            } else {
                rep(j, 2) rep(k, 4) grid[j+x-1][k+y-1] = c;
            }
        }

        bool ok[100][100];
        rep(i, w) rep(j, h) ok[i][j] = true;

        bool flag = false;
        int sc = grid[sx][sy];
        queue<P> que;
        que.push(P(sx, sy));
        while (que.size()) {
            P p = que.front();
            que.pop();
            if (p.first == gx && p.second == gy) {
                flag = true;
                break;
            }

            rep(i, 4) {
                int nx = p.first+dx[i], ny = p.second+dy[i];
                if (0 <= nx && nx < w && 0 <= ny && ny < h && grid[nx][ny] == sc && ok[nx][ny] == true) {
                    que.push(P(nx, ny));
                    ok[nx][ny] = false;
                }
            }
        }

        if (flag && sc > 0) cout << "OK" << endl;
        else cout << "NG" << endl;
    }


    return 0;
}


Measured memory_bytes: 3108
#include <stdio.h>
int main(){
	int l, r, d;
	scanf("%d %d %d", &l, &r, &d);
	int temp=d;
	int sum=0;
	while(temp<=r){
		if(temp>=l){
			sum++;
		}
		temp+=d;
	}
	printf("%d", sum);
	return 0;
}


Measured memory_bytes: 1708
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        boolean flag = false;
        int result = 0;
        for(int i = 1; i <= 5; i++){
            flag = flag || (n == Math.pow(10,i));
        }
        if(flag){
            result = 10;
        } else {
            while(n != 0){
                result = result + n % 10;
                n = n / 10;
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 21076
N = int(input())
cnt = 0
OK = False
for i in range(N):
    D1,D2 = map(int, input().split())
    if D1 == D2:
        cnt+=1
    else:
        cnt=0
    if cnt>=3:
        OK = True

if OK :
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62336
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int n,m;
int h[2001],w[2001];
int hsum[2001],wsum[2001];
int hcnt[2000001],wcnt[2000001];

void init(){
	memset(hsum,0,sizeof(hsum));
	memset(wsum,0,sizeof(wsum));
	memset(h,0,sizeof(h));
	memset(w,0,sizeof(w));
	memset(hcnt,0,sizeof(hcnt));
	memset(wcnt,0,sizeof(wcnt));
	return;
}

int main(void){
	while(1){
		scanf("%d%d",&n,&m);
		if(n+m==0)break;
		for(int i=0;i<n;i++)scanf("%d",&h[i]);
		for(int i=0;i<n;i++)hsum[i+1]=hsum[i]+h[i];
		for(int i=0;i<m;i++)scanf("%d",&w[i]);
		for(int i=0;i<m;i++)wsum[i+1]=wsum[i]+w[i];
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n+1;j++){
				hcnt[hsum[j]-hsum[i]]++;
			}
		}
		for(int i=0;i<m;i++){
			for(int j=i+1;j<m+1;j++){
				wcnt[wsum[j]-wsum[i]]++;
			}
		}
		int cnt=0;
		for(int i=0;i<2000000;i++)cnt+=hcnt[i]*wcnt[i];
		printf("%d\n",cnt);
		init();
	}
	return 0;
}

Measured memory_bytes: 16852