akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


#define MOD (1000000007LL)


ll mod_pow(ll x, ll n, ll m)
{
	ll ret = 1LL;
	for(;n>0;n>>=1)
	{
		if(n&1) ret=(ret*x)%m;
		x=(x*x)%m;
	}
	return ret;
}


ll mod_inv(ll x, ll m)
{
	return mod_pow(x, m-2, m)%m;
}


ll nCr(int n, int r, ll m)
{
	ll bunbo=1LL;
	ll bunsi=1LL;

	if(r*2>n) r=n-r;

	for(int i=0;i<r;i++)
	{
		bunbo=bunbo*(n-i)%m;
		bunsi=bunsi*(i+1)%m;
	}
	return bunbo*mod_inv(bunsi, m);
}


int gcd(int a, int b)
{
	int c;

	while((c=a%b))
	{
		a=b;
		b=c;
	}
	return b;
}


void fuga(ll&ans, int n, int k, int t)
{
	if(n==0)
	{
		ans=(ans+t)%MOD;
		return;
	}
	for(int i=1;i<=k;i++)
	{
		fuga(ans, n-1, k, gcd(t, i));
	}
}


void hoge(ll&ans, int n, int k)
{
	for(int i=1;i<=k;i++)
	{
		fuga(ans, n-1, k, i);
	}
}


ll xhoge(int n, int k)
{
	vll r(k+1, 1);

	for(;n>1;n--)
	{
		vll y(k+1, 0);

		for(int i=1;i<=k;i++)
		{
			for(int j=1;j<=k;j++)
			{
				ll&x=y[gcd(i, j)];

				x+=r[j];
				x%=MOD;
			}
		}
		r.swap(y);
	}

for(ll mt:r) printf("%lld ", mt); printf("\n");

	ll ret=0;
	for(int i=0;i<=k;i++)
	{
		ret+=(i*r[i])%MOD;
	}
	return ret%MOD;
}


ll yhoge(int n, int k)
{
	vll t(k+1, 1);
	vll r(k+1, 0);

	for(;n>0;n/=2)
	{
		if(n&1)
		{
			if(r[1]>0)
			{
				vll y(k+1);

				for(int i=1;i<=k;i++)
				{
					for(int j=1;j<=k;j++)
					{
						ll&x=y[gcd(i, j)];

						x+=(r[i]*t[j])%MOD;
						x%=MOD;
					}
				}
				r.swap(y);
			}
			else
			{
				r=t;
			}
		}

		vll y(k+1, 0);

		for(int i=1;i<=k;i++)
		{
			for(int j=1;j<=k;j++)
			{
				ll&x=y[gcd(i, j)];

				x+=(t[i]*t[j])%MOD;
				x%=MOD;
			}
		}
		t.swap(y);
printf("debug n=%d\n", n);
	}

	ll ret=0;
	for(int i=0;i<=k;i++)
	{
		ret+=(i*r[i])%MOD;
	}
	return ret%MOD;
}


ll zhoge(int n, int k)
{
	ll ret=0;
	vll r(k+1);

	for(int x=k;x>=1;x--)
	{
		int t=k/x;
		ll prob=mod_pow(t, n, MOD);

		for(int i=x*2;i<=k;i+=x)
		{
			prob=(prob+MOD-r[i])%MOD;
		}
		r[x]=prob;
	}
	for(int i=1;i<=k;i++)
	{
		ret+=(r[i]*i)%MOD;
		ret%=MOD;
	}

	return ret;
}


int main(void)
{
	int n, k;

	while(scanf("%d%d", &n, &k)==2)
	{
		ll ans=0;

if(0)
{
		for(int i=1;i<=k;i++)
		{
			int m=k/i-1;

			if(m==0)
			{
				ans+=i;
				continue;
			}
			for(int j=1;j<=n;j++)
			{
				ll t=mod_pow(m, n-j, MOD)*nCr(n, j, MOD)%MOD;
				ans+=t*i;
				ans%=MOD;
//				printf("i=%d j=%d <t*i>=%lld\n", i, j, t*i);
			}
		}
}
else if(0)
{
	hoge(ans, n, k);
} else if(0)
{
		ans=yhoge(n, k);
}
else
{
	ans=zhoge(n, k);
}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 3568
#include<iostream>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=50000005;
int s,len[N],p[N];
ll qpow(ll a,ll n)
//CODE
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int main()
{
    p[0]=1;
    scanf("%d",&s);
    ll ans=0;
    int sum=0;
    for(int l=1,r=0;l<10000000;l++)
    {
        while(sum<s)
        {
            r++;
            p[r]=p[r-1];
            len[r]=len[r-1];
            if(r/p[r]!=0) p[r]*=10,len[r]++;
            sum+=len[r];
        }
        if(sum==s) ans++;
        sum-=len[l];
    }
    for(int t=1;t<=s/8;t++)
    {
        if(s%t) ans=(ans+1)%mod;
        else ans=(ans+(qpow(10,s/t)-qpow(10,s/t-1)-t+1))%mod;
    }
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}

Measured memory_bytes: 178432
#atcoder_RedAndBlueBalls

import numpy as np 

MAX = pow(10,9)+7

def fact(n):
    ls = [1] 
    for i in range(1,n+1):
        ls.append(ls[i-1]*i) 
    return(ls) 

n,k = input().split()
n,k = int(n),int(k) 

ls = fact(2000)

def C(n,m):
    return ((ls[n]//(ls[m]*ls[n-m])) % MAX)

for i in range(k):
    ans = ( C(n-k+1,i+1) * C(k-1,i) ) % MAX 
    print (ans)



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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i =  0; i < n; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    int Amax = A[n - 1];
    vector<int> dp(Amax + 1, 0);
    for (auto t : A) {
        for (int i = 1; i * t <= Amax; i++) {
            dp[i * t]++;
        }
    }
    int cnt = 0;
    for (auto t : A) {
        if (dp[t] == 1) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 7948
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b = map(int, readline().split())
    grid = []
    for _ in range(50):
        grid.append(["#"] * 100)

    for _ in range(50):
        grid.append(["."] * 100)

    w_row, w_col = 0, 0
    b_row, b_col = 51, 0

    for white in range(a - 1):
        grid[w_row][w_col] = "."
        w_row += 2
        if w_row == 50:
            w_row = 0
            w_col += 2

    for black in range(b - 1):
        grid[b_row][b_col] = "#"
        b_row += 2
        if b_row == 101:
            b_row = 51
            b_col += 2

    print(100, 100)
    for row_state in grid:
        print("".join(row_state))


if __name__ == '__main__':
    main()


Measured memory_bytes: 40400
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
typedef long long ll;
typedef unsigned long long ull;

struct edge{
	int to,cost,dis;
};

bool operator < (const edge &a,const edge &b){
    return a.cost > b.cost;
}

int main(){
	int c,n,m,s,g;
	while(scanf("%d%d%d%d%d",&c,&n,&m,&s,&g),n){
		int ans = 0;
		s--,g--;
		vector<edge> G[128];
		int d[128][32]={{}};
		rep(i,m){
			int a,b,cst;
			scanf("%d%d%d",&a,&b,&cst);
			a--,b--;
			edge in;
			in = {b,cst,-1};
			G[a].push_back(in);
			in = {a,cst,-1};
			G[b].push_back(in);
		}
		priority_queue<edge> PQ;
		edge start = {s,0,c};
		PQ.push(start);
		while(!PQ.empty()){
			edge pq = PQ.top();
			PQ.pop();
			if(d[pq.to][pq.dis]){
				d[pq.to][pq.dis]++;
				continue;
			}
			d[pq.to][pq.dis] = true;
			if(pq.to == g){
				printf("%d\n",pq.cost);
				break;
			}
			rep(u,G[pq.to].size()){
				edge next = {G[pq.to][u].to,pq.cost+G[pq.to][u].cost,pq.dis};
				PQ.push(next);
				if(pq.dis){
					next = {G[pq.to][u].to,pq.cost+G[pq.to][u].cost/2,pq.dis-1};
					PQ.push(next);
				}
			}
		}
	}
	return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n, k;
string s;

int num[MAX_N];

int ans;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &k);

  cin >> s;

  for (int i = 0; i < n; ++i) {
    if (s[i] == '0') {
      if (i == 0 || s[i - 1] == '1') {
        num[i] = 1;
      }
    }
  }

  for (int i = 1; i < n; ++i) {
    num[i] += num[i - 1];
  }

  num[n] = num[n - 1] + 1;

  int cnt = num[n - 1];

  if (k >= cnt) {
    printf("%d\n", n);
    return 0;
  }

  ans = -1;

  for (int i = 0; i < n; ++i) {
    int add = (s[i] == '0') ? k - 1 : k;  // already using 0 part

    auto itr = upper_bound(num + i, num + n + 1, num[i] + add);

    int ind = (itr - num) - 1;

    if (num[ind] - num[i] != add) continue;

    int score = ind - i + 1;

    ans = max(ans, score);
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define IL inline
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define repd(i,j,k) for(int i=j;i>=k;--i)
#define pb push_back
#define db double
#define mp make_pair
#define mp3(a,b,c) mp(mp(a,b),c)
#define pii pair<int,int>
#define piii pair<pii,int>
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pbc(x) __builtin_popcount(x)
#define clr(x) memset(x,0,sizeof x)
#define SIZE(x) (int)(x.size())
const int mod=1e9+7;
IL int pls(int x,int y){x+=y;return x>=mod?x-mod:x;}
IL int dec(int x,int y){x-=y;return x<0?x+mod:x;}
IL int mul(int x,int y){return 1ll*x*y%mod;}
IL int mul(int x,int y,int z){return mul(mul(x,y),z);}
IL int mul(int x,int y,int z,int p){return mul(mul(x,y),mul(z,p));}
IL void add(int &x,int y){x+=y;x=(x>=mod)?x-mod:x;}
IL int fpw(int x,int y,int r=1){for(;y;y>>=1,x=mul(x,x))if(y&1)r=mul(r,x);return r;}
IL int inv(int x){return fpw(x,mod-2);}
IL int gi(){int x;int _w=scanf("%d",&x);return x;}
IL void gi(int &x){int _w=scanf("%d",&x);}
IL void write(int x){printf("%d\n",x);}
void chkmax(int &x,int y){x=(x>y)?x:y;}
void chkmin(int &x,int y){x=(x<y)?x:y;}
const int INF=0x3f3f3f3f;
template<typename T>IL void debug(T x){cerr<<x;return;}
/* --------------------------------------------------------------------------------------------------------- */
const int maxn=2e5+10;
const int base=2000;
int n;
int a[maxn],b[maxn],f[4005][4005],fac[maxn],ifac[maxn];
int C(int x,int y){
	if(x<y)return 0;
	return mul(fac[x],ifac[y],ifac[x-y]);
}
int main(){
#ifdef LOCAL
	freopen("/home/noilinux/Desktop/input.txt","r",stdin);
#endif
	n=gi();
	rep(i,1,n)a[i]=gi(),b[i]=gi(),f[base-a[i]][base-b[i]]++;
	fac[0]=ifac[0]=1;
	rep(i,1,8000)fac[i]=mul(fac[i-1],i);
	ifac[8000]=inv(fac[8000]);
	repd(i,7999,1)ifac[i]=mul(ifac[i+1],i+1);
	rep(i,0,4000)rep(j,0,4000){
		if(i!=0)f[i][j]=pls(f[i][j],f[i-1][j]);
		if(j!=0)f[i][j]=pls(f[i][j],f[i][j-1]);
	}
	int ans=0;
	rep(i,1,n)ans=pls(ans,f[a[i]+base][b[i]+base]);
	rep(i,1,n)ans=dec(ans,C(a[i]+a[i]+b[i]+b[i],a[i]+a[i]));
	printf("%d\n",mul(ans,(mod+1)/2));
	return 0;
}

Measured memory_bytes: 64512
#include <stdio.h>
int main(void)
{
  int n, a, b, c;
  scanf("%d%d%d%d", &n, &a, &b, &c);
  int r = 0;
  
  for(int i=1;i<=n;++i){
      int sum=0, j=i;
      for(;j;j/=10){
          sum+=j%10;
      }
    if(a<=sum&&sum<=b)r+=i;
  }
  
  printf("%d\n", r);
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    int a, b;
    char op;
    while (cin >> a >> op >> b) {
        int ans = 0;
        switch (op) {
        case '+':
            ans = a + b;
            break;
        case '-':
            ans = a - b;
            break;
        case '*':
            ans = a * b;
            break;
        case '/':
            ans = a / b;
            break;
        default:
            return 0;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}

int a[305][305];
int pos[305][305];

signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
            pos[a[i][j]][i]=j;
        }
    }    
    
    int l=1,r=n;
    int mn=1e10;
    while (l<=r)
    {
        int mid=l+(r-l)/2;
        int ind[305]={};
        int mm[305]={};
        int lol[305]={};
        int cnt[305]={};
        bool flag=true;
        while (flag)
        {
            for(int i=1;i<=n;i++)
            {
                if(lol[i]==0)
                {
                    ind[i]++;
                    
                    while (mm[a[i][ind[i]]]==1)
                    {
                        ind[i]++;
                        if(ind[i]>=m+1)
                            break;
                    }        
                    if(ind[i]>m)
                    {
                        flag=false;
                        break;
                    }
                    cnt[a[i][ind[i]]]++;
                    lol[i]=1;
                }
            }
            
            for(int i=1;i<=m;i++)
            {
                if(cnt[i]>mid)
                    mm[i]=1;
            }
            bool ok=true;
            for(int i=1;i<=n;i++)
            {
                if(mm[a[i][ind[i]]])
                {
                    ok=false;
                    lol[i]=0;
                }
            }
            if(ok)
                break;
        }

        if(flag)
        {
            mn=min(mn,mid);
            r=mid-1;
        }        
        else
        {
            l=mid+1;
        }        
    }
    cout<<mn;
    
} 
    


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

using namespace std;

typedef long long ll;

const int N = 1 << 17;
ll seg[2 * N];
ll A, B, P;

void init(){ memset(seg, 0, sizeof(seg)); }
void update(int x, ll v){
  x += N - 1;
  seg[x] = v % P;
  while (x > 0){
    x = (x - 1) >> 1;
    seg[x] = seg[x + x + 1] + seg[x + x + 2];
    seg[x] %= P;
  }
}
ll sum(int a, int b, int x=0, int l=0, int r=N){
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b) return seg[x];
  ll lr = sum(a, b, x + x + 1, l, (l + r) >> 1);
  ll rr = sum(a, b, x + x + 2, (l + r) >> 1, r);
  return (lr + rr) % P;
}

ll rten(ll x){
  ll r = 1;
  while (r * 10 <= x) r *= 10;
  return r;
}

int main()
{
  while (cin >> A >> B >> P, A){
    init();
    update(0, 1);
    for (ll x = A + 1; x <= B; x++){
      ll s = sum(max(rten(x) - A, 0ll), x - A) + 1;
      for (ll y = x / 10; y >= A; y /= 10){
        s += sum(max(rten(y) - A, 0ll), y - A + 1);
        s %= P;
      }
      update(x - A, s);
    }
    cout << sum(0, N) << endl;
  }

  return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
	using namespace std;
	int main() { 
	    
	    int a,b;

	    cin >> a >> b;

	    while(a!= 0 || b!=0){
	    	int count =0;
	    	for(int i=1;i<=a;i++){
	    		for(int j=i+1; j<=a;j++){
	    			for(int k=j+1; k<=a;k++){
	    				if( (i+j+k) == b) count++;
	    			}
	    		}
	    	}
	    	cout << count << endl;

	    	cin >> a >> b;
	    }
	    

	    return 0;
	}


Measured memory_bytes: 3024
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,s,a[200040],b[200040],c[200040],d[200040];
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout<<fixed<<setprecision(12);
	cin>>n;
	for(;i<n;i++)
	{
		cin>>a[i]>>b[i];
		c[i]=a[i];
		d[i]=b[i];
	}
	sort(c,c+n);
	sort(d,d+n);
	if(n%2)
	{
		cout<<d[n/2]-c[n/2]+1;
	}
	else
	{
		cout<<d[n/2-1]+d[n/2]-c[n/2-1]-c[n/2]+1;
	}
}

Measured memory_bytes: 9812
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int n,m;
		cin>>n>>m;
		ll x[n],y[m],l=0,b=0;
		cin>>x[0];
		FOR(i,1,n)
		{
			cin>>x[i];
			l=(l+(i*(((n-i)*(x[i]-x[i-1]))%mod)))%mod;
		}
		cin>>y[0];
		FOR(i,1,m)
		{
			cin>>y[i];
			b=(b+(i*(((m-i)*(y[i]-y[i-1]))%mod)))%mod;
		}
		cout<<(l*b)%mod;
	}
	return 0;
}


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

int main(void){
    std::string s;
    std::cin >> s;
    std::string ans="Yes";
    int strlen = s.length();
    if(strlen%2 != 0) ans = "No";
    
    for(int i =0; i<strlen; i++){
        if(i%2 == 0 && s[i] != 'h'){
            //std::cout << s[i];
            ans ="No";
            break;
        }else if(i%2 == 1 && s[i] != 'i'){
            //std::cout << s[i];
            
            ans = "No";
            break;
        }else if(s[i] == ' '){
            ans = "No";
            break;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef enum {
    WHITE,
    BLACK,
    RED
} S_COLOR;

int main(void) {
    int H, W, K;
    cin >> H >> W >> K;

    vector<pair<int, int>> crd_org;

    string str;
    REP (i, H) {
        cin >> str;
        REP (j, W) {
            if (str[j] == '#') {
                crd_org.emplace_back(i, j);
            }
        }
    }

    int ans = 0;

    REP (bit_row, 1 << H) {
        REP (bit_col, 1 << W) {
            vector<pair<int, int>> crd(crd_org.size());
            copy(crd_org.begin(), crd_org.end(), crd.begin());

            REP (row, H) {
                if ((bit_row >> row) & 0x1) {
                    auto itr = remove_if(crd.begin(), crd.end(), [&](pair<int, int> v) {
                        return v.first == row;
                    });
                    if (itr != crd.end()) {
                        crd.erase(itr, crd.end());
                    }
                }
            }

            REP (col, W) {
                if ((bit_col >> col) & 0x1) {
                    auto itr = remove_if(crd.begin(), crd.end(), [&](pair<int, int> v) {
                        return v.second == col;
                    });
                    if (itr != crd.end()) {
                        crd.erase(itr, crd.end());
                    }
                }
            }

            if (crd.size() == K) {
                ans++;
            }
        }
    }

    
    cout << ans << endl;

    return 0;
}

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

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

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

	int a = 1;
	rep(i, n - 1)  if (s[i] != s[i + 1])  a++;
	rep(i, k) {
		if (a > 2) {
			a -= 2;
		}
		else {
			a--;
		}
	}
	int ans = n - max(1, a);
	cout << ans << endl;
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    int a,b,c,d,e,n;

    scanf("%d%d%d",&a,&b,&n);

    if(n<a)
    {
        c=0;
    }
  else
    c=(n/a);

   printf("%d\n",c*b);
    return 0;
}


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

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


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

int main() {
  int W,H,N;
  cin >> W >> H >> N;
  vector<int> x(N);
  vector<int> y(N);
  vector<int> a(N);
  int xl=0;
  int xr=W;
  int yt=H;
  int yb=0;
  for(int i=0;i<N;i++){
    cin >> x.at(i) >> y.at(i) >> a.at(i);
  }
  for(int i=0;i<N;i++){
    if(a.at(i) == 1){
      if(x.at(i) >= xl){
        xl = x.at(i);
      }
    }
    if(a.at(i) == 2){
      if(x.at(i) <= xr){
        xr = x.at(i);
      }
    }
    if(a.at(i) == 3){
      if(y.at(i) >= yb){
        yb = y.at(i);
      }
    }
    if(a.at(i) == 4){
      if(y.at(i) <= yt){
        yt = y.at(i);
      }
    }
  }
  if(xl >= xr || yb >= yt){
    cout << 0 << endl;
  }
  else if(xl < xr && yb < yt){
    cout << (xr-xl)*(yt-yb) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y,z;
  cin >> x >> y >> z;
  for(int i=x/y;i>0;i--){
    if(i*(y+z)+z<=x){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 3e5 + 9, M = 4e5 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int main(){
    init();

    string s;   cin >> s;
    cout << (s.find('A') != string::npos && s.find('B') != string::npos ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

vector<int> vis;
vector<vector<pair<int,int> > > g;     // to, edgeid

vector<int> c;    // vertexに0or1（偶奇）
vector<int> d;    // edgeに0or1  (反転なし/あり)

bool dfs( int edgeid, int curr, int& bad )
{
    bad = c[curr];
    if(vis[curr]) {
        return true;
    }
    vis[curr]=1;
    int siz=(int)g[curr].size();
    int i;
    for(i=0; i<siz; i++) {
        int next=g[curr][i].first;
        if(vis[next]) continue;

        int bad0=0;
        bool bOk = dfs(g[curr][i].second, next, bad0 );
        if(!bOk) {
            return false;
        }
        bad += bad0;
    }
    bad = bad % 2;
    if(bad) {
        if(edgeid>=0) {
            d[edgeid]=(d[edgeid]+1)%2;
        }
        else return false;
    }

    return true;
}

int main(int argc, char* argv[])
{
    int n,m;
    scanf("%d%d", &n, &m);
    g.resize(n);
    vis.resize(n);
    c.resize(n);
    d.resize(m);

    vector<int> a(m), b(m);
    int i;
    for(i=0; i<m; i++) {
        scanf("%d%d", &a[i], &b[i]);
        a[i]--; b[i]--;
        g[a[i]].push_back(make_pair(b[i],i));
        g[b[i]].push_back(make_pair(a[i],i));
        c[a[i]]=(c[a[i]]+1)%2;
    }

    for(i=0; i<n; i++) {
        int bad=0;
        bool bOk = dfs( -1, i, bad );
        if(!bOk) {
            printf("-1\n"); return 0;
        }
    }

    for(i=0; i<m; i++) {
        if(d[i]) {
            printf("%d %d\n", b[i]+1, a[i]+1);
        }
        else {
            printf("%d %d\n", a[i]+1, b[i]+1);
        }
    }

    return 0;
}



Measured memory_bytes: 15104
import Data.Char(isSpace)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C

main = do
    n <- readLn
    as <- U.unfoldrN n (C.readInt . C.dropWhile isSpace) <$> C.getLine
    let negCnt = U.length $ U.filter (<0) as
    let absLst = U.map abs as
    let absSum = U.sum absLst
    let absMin = U.minimum absLst
    print $ if even negCnt then absSum else absSum - 2*absMin

Measured memory_bytes: 5756
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
cnt = 1
for i in range(n):
    if i == 0:
        tmp = s[i]
    else:
        if s[i] == tmp:
            continue
        cnt += 1
        tmp = s[i]
if s[i] != tmp:
    cnt += 1
print(cnt-1)


Measured memory_bytes: 40428
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int x,y;
    x = 1;
    y = 1;
    while (x!=0){
        scanf("%d",&x);
        if(x!=0){
            printf("Case %d: %d\n",y,x);
            y = y +1;
        }else{
        }
    }
    return 0;
}



Measured memory_bytes: 2040
//#define _XCODE_DEBUG

#include <iostream>

#ifdef _XCODE_DEBUG
    #include <fstream>
#endif

int main() {
    #ifdef _XCODE_DEBUG
        std::ifstream in("input.txt");
        std::cin.rdbuf(in.rdbuf());
    #endif
    
    int N, Y;
    std::cin >> N >> Y;
    Y/=1000;
    for (int i=0; i<=N; ++i) {
        for (int j=0; j<=N-i; ++j) {
            if ((10*i+5*j+(N-i-j))==Y) {
                std::cout << i << " " << j << " " << N-i-j << "\n";
                return 0;
            }
        }
    }
    
    std::cout << "-1 -1 -1" << "\n";
    return 0;
}


Measured memory_bytes: 256
import queue

def bfs(h, w, maps):
    distance = [[float("inf")] * w for _ in range(h)]
    dx, dy = [0, 1, 0, -1], [1, 0, -1, 0]

    distance[0][0] = 0
    pri_queue = queue.Queue()
    pri_queue.put((0, 0))
    while True:
        if pri_queue.empty():
            break
        p = pri_queue.get()
        if p[0] == h - 1 and p[1] == w - 1:
            break

        for i in range(4):
            nx, ny = p[0] + dx[i], p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and maps[nx][ny] != "#" and distance[nx][ny] == float("inf"):
                pri_queue.put((nx, ny))
                distance[nx][ny] = distance[p[0]][p[1]] + 1

    if distance[h - 1][w - 1] != float('inf'):
        return distance[h - 1][w - 1]

    else:
        return -1

h, w = map(int, input().split())
maps = [list(input()) for _ in range(h)]
wall = 0

for i in maps:
    for j in range(w):
        if i[j] == "#":
            wall += 1

min_dis = bfs(h, w, maps)

print(-1 if min_dis == -1 else h * w - (wall + min_dis + 1))


Measured memory_bytes: 4080
/*
Wai u read my code xD
*/
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    int h, a; cin >> h >> a;
    if (h%a==0) nout(h/a);
    else nout((h/a)+1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define M 200005
using namespace std;
int i,j,k,l,s,n,m,last[N],to[M],Next[M],a[N],b[N],bb,fa[N],vis[N],Ans[N],ans,ans1,x,y;
int q[N],tot,X,Y;
inline void add(int x,int y) {
	Next[++tot]=last[x]; last[x]=tot; to[tot]=y;
}
inline void dfs(int x) {
	vis[x]=1;
	s++;
	if (s>ans) ans=s,ans1=x;
	for (int i=last[x];i;i=Next[i]) if (!vis[to[i]]) dfs(to[i]);
	vis[x]=0,s--;
}
inline void build(int x) {
	int l=0,r=1; q[1]=x;
	while (l<r) {
		int k=q[++l];
		for (int i=last[k];i;i=Next[i]) if (fa[k]!=to[i]) fa[q[++r]=to[i]]=k;
	}
}
int main() {
	scanf("%d",&n);
	for (i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	dfs(1);
	ans=0;
	X=ans1;
	dfs(ans1);
	Y=ans1;
	build(X);
	for (i=Y;i;i=fa[i]) vis[i]=1;
	for (i=1;i<=n;i++) if (!vis[i]&&!vis[fa[i]]) return puts("-1"),0;
	tot=0;
	for (i=Y;i;i=fa[i]) {
		tot++;
		for (j=last[i];j;j=Next[j]) {
			if (to[j]==fa[i]) continue;
			if (!vis[to[j]]) a[tot]++;
		}
	}
	for (i=1;i<=tot;i++) b[tot-i+1]=a[i];
	bb=0;
	for (i=1;i<=tot;i++) if (b[i]<a[i]) {
		bb=1; break;
	}
	else if (b[i]>a[i]) break; 
	s=0;
	if (!bb) {
		for (i=1;i<=tot;i++) {
			Ans[s+a[i]+1]=s+1;
			for (j=1;j<=a[i];j++) Ans[s+j]=s+j+1;
			s=s+a[i]+1;
		}
	}
	else {
		for (i=1;i<=tot;i++) {
			Ans[s+b[i]+1]=s+1;
			for (j=1;j<=b[i];j++) Ans[s+j]=s+j+1;
			s=s+b[i]+1;
		}
	}
	for (i=1;i<=n;i++) printf("%d ",Ans[i]);
}

Measured memory_bytes: 6784
/*
 * ALDS1_7_A.cpp
 *
 *  Created on: Apr 30, 2018
 *      Author: 13743
 */

#include<cstdio>

struct Node {
	int pa;
	int lc;
	int rs;
};

Node tree[100000];

int depth(int u) {
	int de = 0;
	while(tree[u].pa != -1) {
		de++;
		u = tree[u].pa;
	}
	return de;
}

int main() {
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++) {
		tree[i].pa = -1;
		tree[i].lc = -1;
		tree[i].rs = -1;
	}
	for(int i=0; i<n; i++) {
		int id, d;
		scanf("%d%d", &id, &d);
		for(int j=0; j<d; j++) {
			int ch0;
			int ch;
			scanf("%d", &ch);
			tree[ch].pa = id;
			if(j == 0) {
				tree[id].lc = ch;
			}
			else {
				tree[ch0].rs = ch;
			}
			ch0 = ch;
		}
	}

	for(int i=0; i<n; i++) {
		printf("node %d: ", i);
		printf("parent = %d, ", tree[i].pa);
		printf("depth = %d, ", depth(i));
		if(tree[i].pa == -1) {
			printf("root, ");
		}
		else if(tree[i].lc == -1) {
			printf("leaf, ");
		}
		else {
			printf("internal node, ");
		}
		printf("[");
		int sib = -1;
		if(tree[i].lc != -1) {
			printf("%d", tree[i].lc);
			sib =  tree[tree[i].lc].rs;
		}
		while(sib != -1) {
			printf(", %d", sib);
			sib = tree[sib].rs;
		}
		printf("]\n");
	}
}





Measured memory_bytes: 3732
using System;
class Program
{
  static void Main (string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int A = int.Parse(input[0]);
    int B = int.Parse(input[1]);
    int T = int.Parse(input[2]);
    
    int count = 0;
    for (int time = 1; time <= T; time++)
    {
      if (time % A == 0)
      {
        count += B;
      }
    }
    Console.WriteLine(count);
  }
}


Measured memory_bytes: 13140
/** author: __nishad__ **/
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(ll i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    int n;
    vector<pair<int, int>> v;

    cin>>n;

    loop(i, 1, n){
        int j = i, count = 0;
        while(j%2 ==0){
            j = j / 2;
            count++;
        }
        v.pb(mp(count, i));
    }

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

    cout<<v[n-1].second;



}





























Measured memory_bytes: 3644
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort()


mod = 10 ** 9 + 7
f_list = [1]
for i in range(1,n+1):
    f_list.append((f_list[-1] * i) % mod)
def comb(n,r):
    return f_list[n] * (pow(f_list[r], mod-2, mod) * pow(f_list[n-r], mod-2, mod) % mod) % mod


max_val = 0
min_val = 0
for i in range(n - k + 1):
    val = comb(n - i - 1, k - 1)
    max_val = (max_val + (((a_list[-(i + 1)]) * val))) % (10 ** 9 + 7)
    min_val = (min_val + ((a_list[i]) * val)) % (10 ** 9 + 7)

print(int((max_val - min_val) % (10 ** 9 + 7)))

Measured memory_bytes: 14040
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
 
using namespace std;


	
int main()
{ 
	string s;
	string t;
	cin>>s>>t;
	int slnth=s.length();
	int tlnth=t.length();
	bool ok=true;
	int ind=-1;
//	cout<<s<<endl<<t<<endl<<slnth<<endl<<tlnth<<endl;
	for(int i=slnth-tlnth+1;i>=0&&ok;i--){
		if(s[i]==t[0]||s[i]=='?'){
			for(int j=i+1;j<i+tlnth;j++){
				if(s[j]!=t[j-i]&&s[j]!='?'){
					ok=false;
					break;
				}
			}
			if(ok){ok=false;ind=i;/*cout<<ind<<endl;*/}
			else ok=true;
		}
	}
	if(ok){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	for(int i=ind;i<ind+tlnth;i++){
		s[i]=t[i-ind];
	}
	for(int i=0;i<slnth;i++){
		if(s[i]=='?')s[i]='a';
	}
	cout<<s<<endl;
//	cout<<ind<<endl;
	return 0;
}
	
	


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,z,w;
  cin >> n >> z >> w;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  if(n == 1) cout << abs(a[0]-w) << "\n";
  else cout << max(abs(a[n-1]-w),abs(a[n-2]-a[n-1])) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) cerr << #OBJ << ": "; CERR(OBJ); cerr << "\n"
template <typename T, typename ...Ts> void CERR(const T &FIRST, const Ts &...REST) { CERR(FIRST); cerr << ", "; CERR(REST...); }
#define dbs(...) cerr << "(" << #__VA_ARGS__ << "): ("; CERR(__VA_ARGS__); cerr << ")\n"
#include <atcoder/all>
using namespace atcoder;

int main() {
	string S; cin >> S;
	ll l = S.size(), ans = (l + 1) * l / 2;
	for (int x : lcp_array(S, suffix_array(S))) ans -= x;
	cout << ans << endl;
}

Measured memory_bytes: 15600
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<stdbool.h>
using namespace std;
typedef long long ll;
#define N (1000000000+7)

int main(void) {
	int n;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
using namespace std;
int f[3][105];
int a[3][105],n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
		scanf("%d",&a[i][j]);
	f[1][1]=a[1][1];
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
		f[i][j]=max(f[i-1][j],f[i][j-1])+a[i][j];
	printf("%d",f[2][n]);
}


Measured memory_bytes: 256
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define vz(x) x.size()
using ll = long long;
using ii = pair <ll , ll>;
void in(ll &x);
// const ll N = ;
const ll INF = 1e9 + 50;
const ll MOD = 1e9 + 7;
ll n, x, m;

ll mul(ll a , ll b) {
  return ((a % m) * (b % m)) % m;
}

ll rsum(int l , int r , vector <ll> &ps) {
  if (l > r) return 0;
  return ps[r] - ps[l - 1];
}

int main() {
  in(n); in(x); in(m);
  ll lst = x;
  vector <ll> ps;
  map <ll , ll> pos;
  pos[x] = 1;
  ps.pb(0); ps.pb(x);
  ll ans = x;
  for (ll i = 2 ; i <= n ; i++) {
    ll cur = mul(lst , lst);
    if (pos.count(cur)) {
      // printf(" hoho %lld -> %lld\n" , pos[cur] , i);
      ps.pb(ps.back() + cur);
      ll len = i - pos[cur];
      ll left = n - i;
      ll whole = rsum(pos[cur] + 1 , i , ps);
      ll rem = rsum(pos[cur] + 1 , pos[cur] + (left % len) , ps);
      // printf(" :: %lld %lld\n" , left , len);
      // printf(" >> %lld %lld\n" , pos[cur] + 1 , i);
      // printf(" >> %lld %lld\n" , pos[cur] + 1 , pos[cur] + (left % len));
      ans += whole * (left / len) + rem + cur;
      break;
    } else {
      pos[cur] = i;
    }
    ans += cur;
    ps.pb(ps.back() + cur);
    // printf("%d -> %lld\n" , i , ps[i]);
    lst = cur;
  }
  printf("%lld\n" , ans);
  return 0;
}

void in(ll &x){
	bool neg = false;
	register ll c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 6716
#include<stdio.h>  

int main(void){
  long int N,X,D,a,i;
  scanf("%ld%ld%ld",&N,&X,&D);
  
  if(D==0){
    if(X!=0){
      a=N+1;
      printf("%ld",a);
    }else{
      printf("1");
    }
    return 0;
  }
  
  if(D<0){
    X=X+(N-1)*D;
    D=-D;
  }
  if(X==0){
    a=N*(N-1)/2+1;
    printf("%ld",a);
    return 0;
  }
  a=(N+1)*(N*N-N+6)/6;
  long int b,c,k,j,l,r;
  b=0;
  k=1;
  while((k*X)%D!=0&&k!=N){
    k++;
  }
  if(k==N){
    printf("%ld",a);
    return 0;
  }else{
    c=k*X/D;
    if(X>0){
      for(i=0;i<=N-k;i++){
        j=i+k;
        if(i*(2*N-i-1)/2-j*(j-1)/2-c+1>0){
          b=b+i*(2*N-i-1)/2-j*(j-1)/2-c+1;
        }
      }
    }else{
      for(i=0;i<=N-k;i++){
        j=i+k;
        if(j*(j-1)/2+c>i*(i-1)/2){
          l=j*(j-1)/2+c;
        }else{
          l=i*(i-1)/2;
        }
        if(j*(2*N-j-1)/2+c>i*(2*N-i-1)/2){
          r=i*(2*N-i-1)/2;
        }else{
          r=j*(2*N-j-1)/2+c;
        }
        if(r-l+1>0){
          b=b+r-l+1;
        }
      }
    }
  }
  
  a=a-b;
  
  printf("%ld",a);
  
  return 0;
}

Measured memory_bytes: 128
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, m, q = map(int, input().split())
l = []
for _ in range(q):
    l.append(list(map(int, input().split())))

def check(n, m, l, a):
    if len(a) == n:
        point = 0
        for i in range(len(l)):
            if a[l[i][1]-1]-a[l[i][0]-1] == l[i][2]:
                point += l[i][3]
        return point
    point = 0
    if len(a) == 0:
        start = 1
    else:
        start = a[-1]
    for i in range(start, m+1):
        point = max(point, check(n, m, l, a+[i]))
    return point

print(check(n, m, l, []))

Measured memory_bytes: 73516
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
using ll = long long;


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

    if (A > 9) {
        cout << -1 << endl;
        return 0;
    }

    if (B > 9) {
        cout << -1 << endl;
        return 0;
    }

    cout << A * B << endl;
}


Measured memory_bytes: 256
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<sstream>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define vcin(v) for (int i = 0; i < (v).size(); i++) { cin >> (v)[i]; }
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define v vector
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
//printf("%02d:%02d:%02d\n", h, m, s);・・・2文字は埋める・h、m、ｓ
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

//for A以上B未満でI探索 for (int I = A; i <= B; i++)

//string s = to_string(i);

//char→小文字のほうが大きい数値　　&&　その差は32

//大文字→小文字 文字列のn文字目を大文字で出力→ (char)toupper(a[0])

int a = 0, b = 0, c = 0, x = 0, y = 0, z = 0, n = 0, sum = 0, i = 0;
string s = ""; asas; cncn;

int main(void) {
	string a, b, c;
	cin >>a >> b >> c;
	cout << (char)toupper(a[0]) << (char)toupper(b[0]) << (char)toupper(c[0]) << rt;
	please AC;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[2010], b[2010];
ll dp[2010], dp1[2010];
int main(){
    int n, m;
    while(cin>>n>>m){
        ll ans=1;
        for(int i=0; i<n; ++i){
            scanf("%d",a+i);
        }
        for(int i=0; i<m; ++i){
            scanf("%d",b+i);
        }
        ll mod=1e9+7, tmp;
        for(int i=0; i<n; ++i){
            ll tmp=1;
            for(int j=0; j<m; ++j){
                if(b[j]==a[i]){
                    ans+=tmp;
                    dp1[j]=tmp;
                    while(ans>=mod)
                        ans-=mod;
                }
                tmp+=dp[j];
                while(tmp>=mod)
                    tmp-=mod;
            }
            for(int j=0; j<m; ++j){
                dp[j]+=dp1[j];
                dp1[j]=0;
            }
        }
        cout<<ans<<endl;
    }
  return 0;
}




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

int main() {
    int n, d;
    cin >> n >> d;
    int ans = 0;
    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        if (sqrt(x * x + y * y) <= d)
            ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

ll inf=(ll)2e18;
const int mod=1000000007;
//const int mod=998244353;

int n,m;
const int N=2e5+1;
int dp[N];

ll pow(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int q,t,k,u,v;
    ll x,a,b,c,d,y,l,p;
    cin >> n;
    for(int i=1; i<=n; i++){
        dp[i]=dp[i%__builtin_popcount(i)]+1;
    }
    string s;
    cin >> s;
    u=(int)count(all(s),'1');
    if(u==0){
        for(int i=0; i<n; i++){
            cout << 1 << el;
        }
        return 0;
    }
    if(u==1){
        for(int i=0; i<n; i++){
            if(s[i]=='1'){
                cout << 0 << el;
            }
            else{
                if(i!=n-1&&s[n-1]=='0'){
                    cout << 1 << el;
                }
                else{
                    cout << 2 << el;
                }
            }
        }
        return 0;
    }
    reverse(all(s));
    a=0;b=0;c=0;
    for(int i=0; i<n; i++){
        if(s[i]=='1'){
            a+=pow(2,i,u-1);
            c+=pow(2,i,u+1);
        }
    }
    a%=u-1;
    c%=u+1;
    vi ans;
    for(int i=0; i<n; i++){
        if(s[i]=='1'){
            a-=pow(2,i,u-1);
            a=a<0?a+u-1:a;
            ans.pb(1+dp[a]);
            a+=pow(2,i,u-1);
            a%=u-1;
        }
        else{
            c+=pow(2,i,u+1);
            c%=u+1;
            ans.pb(1+dp[c]);
            c-=pow(2,i,u+1);
            c=c<0?c+u+1:c;
            
        }
    }
    while(!ans.empty()){
        cout << ans.back() << el;
        ans.pop_back();
    }
    return 0;
}



Measured memory_bytes: 5212
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;i++)cin>>A[i];
    Map M;
    for(ll i=0;i<N;i++){
        if(A[i]%4==0)M[4]++;
        else if(A[i]%2==0)M[2]++;
    }
    ll t=2*M[4];
    ll s=M[2];
    if(s==0)s++;
    if(s+t>=N)print("Yes")
    else print("No")
    return 0;
}


Measured memory_bytes: 1024
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,a[100111];
bool f[100111];
int go(int x)
{
	for(int i=30;i>=0;i--)if((x>>i)&1)return 1<<i;
}
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)geti(a[i]);
	int it=1,ans=0;
	while(it<=n)
	{
		while(it<=n&&a[it]==1&&!f[it])it++;
		if(it>n)break;
		ans++;
		if(f[it])f[it]=0;else a[it]-=a[it]>>1;
		for(int i=it+1;i<=n;i++)
		{
			if(a[i]==1&&!f[i])break;
			if(a[i]&1)
			{
				f[i]=1;
				if(a[i]>1)a[i]=go(a[i]);
			}
			if(a[i]==1&&f[i])
			{
				f[i]=0;
				break;
			}
			a[i]>>=1;
		}
//		for(int i=1;i<=n;i++)cerr<<a[i]<<" ";cerr<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768