akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=605,Mod=1e9+7;
int n,k,s[N],f[N][N],g[N],t[N],ans;
#define mul(x,y) (1ll*(x)*(y)%Mod)
inline int add(int x, int y)
{	return (x+y>=Mod?x+y-Mod:x+y);
}
inline int sub(int x, int y)
{	return (x-y<0?x-y+Mod:x-y);
}
bool check(int l, int r)
{
	for(int i=l;i<=r;++i)
		if(t[i]&&(t[i]<l||t[i]>r)) return false;
	return true;
}
int main()
{
	scanf("%d%d",&n,&k),n<<=1;
	for(int i=1,a,b;i<=k;++i)
	{
		scanf("%d%d",&a,&b);
		t[a]=b,t[b]=a,--s[a],--s[b];
	}
	for(int i=1;i<=n;++i) s[i]+=s[i-1]+1;
	g[0]=1; for(int i=2;i<=n;++i) g[i]=mul(i-1,g[i-2]);
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;j+=2)
		{
			if(!g[s[j]-s[i-1]]||!check(i,j)) continue;
			f[i][j]=g[s[j]-s[i-1]];
			for(int k=i;k<j;++k) f[i][j]=sub(f[i][j],mul(f[i][k],g[s[j]-s[k]]));
			ans=add(ans,mul(f[i][j],g[s[n]-(s[j]-s[i-1])]));
		}
	printf("%d\n",ans);
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
const int M=1e9+7;// M=1e9+7;//M=300000;//
const int N=2e5+5;
typedef long long int ll;
using namespace std;
 
ll cnt(0),sum(0),n,m,x,y,t,i,j,temp,k,ans(1),mn(M),mx(-9e9);
vector<ll> v;
ll mark[N];
ll a[100][100];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	for(i=1;i<=5;i++)
	{
		cin>>x;
		if(x==0)
		{
			ans=i;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3560
/*input
3
28 27 24
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=4e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    REP(i,n){
        int x;
        cin>>x;
        if(x%2){

        }
        else{
            if(!(x%3==0 or x%5==0)){
                cout<<"DENIED\n";
                return 0;
            }
        }
    }
    cout<<"APPROVED";
}

Measured memory_bytes: 256
n = int(input())
d = [0]*4
for _ in range(n):
    s = input()
    if s == 'AC':
        d[0] += 1
    elif s == 'WA':
        d[1] += 1
    elif s == 'TLE':
        d[2] += 1
    else:
        d[3] += 1
print(f"AC x {d[0]}")
print(f"WA x {d[1]}")
print(f"TLE x {d[2]}")
print(f"RE x {d[3]}")

Measured memory_bytes: 9200
import bisect
N=int(input())
A=list(map(int,input().split()))
B=[A[0]]
for i in range(1,N):
    B.append(A[i]+B[i-1])
#print(B)

ans=10**20
for x in range(2,N-1):
    #print(x)
    Q=[]
    q1=B[bisect.bisect_left(B,B[x-1]/2)]
    q2=B[x-1]-q1
    q3=B[bisect.bisect_left(B,B[x-1]/2)-1]
    q4=B[x-1]-q3
    if abs(q1-q2)<abs(q3-q4):
        Q.append(q1)
        Q.append(q2)
    else:
        Q.append(q3)
        Q.append(q4)
    q5=B[bisect.bisect_left(B,(B[N-1]+B[x-1])/2)]-B[x-1]
    q6=B[N-1]-q5-B[x-1]
    q7=B[bisect.bisect_left(B,(B[N-1]+B[x-1])/2)-1]-B[x-1]
    q8=B[N-1]-q7-B[x-1]
    
    if abs(q5-q6)<abs(q7-q8):
        Q.append(q5)
        Q.append(q6)
    else:
        Q.append(q7)
        Q.append(q8)
    if (max(Q)-min(Q))<ans:
        ans=(max(Q)-min(Q))
    #print(Q)
print(ans)

Measured memory_bytes: 90616
h,i,j,x,y;char m[110][110];main(w){while(1){scanf("%d%d",&w,&h);if(!w)exit(0);for(i=0;i<w;)scanf("%s",m[i++]);x=-1;k(0,0,w*h);(x<0)?puts("LOOP"):printf("%d %d\n",x,y);}}k(a,b,c){if(c)(m[a][b]==46)?x=b,y=a:(m[a][b]-62)||k(a,b+1,c-1),(m[a][b]-60)||k(a,b-1,c-1),(m[a][b]-118)||k(a+1,b,c-1),(m[a][b]-94)||k(a-1,b,c-1);}

Measured memory_bytes: 0
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 100005
#define MOD 1000000007
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

struct point {int x, id; bool special;};
bool cmpX(const point &a, const point &b) {return (a.x < b.x);}

struct line {int x, y, id;};
bool cmpXLine(const line &a, const line &b) {return (a.x < b.x);}

bool onBound(int r, int c, int x, int y) {
    return (x == 0 || x == r || y == 0 || y == c);
}

bool Solve(const int &n, vector<point> &up) {
    sort(up.begin(), up.end(), cmpX);

    stack<int> s;
    bool appeared[n];
    memset(appeared, false, sizeof(appeared));

    for(point p: up) {
        if (p.special) {
            if (!s.empty()) return false;
        } else if (!appeared[p.id]) {
            appeared[p.id] = true;
            s.push(p.id);
        } else {
            if (s.top() != p.id) return false;
            else s.pop();
        }
    }

    return true;
}

bool SolveLine(vector<line> &l) {
    sort(l.begin(), l.end(), cmpXLine);
//    fto(i, 0, sz(l)-1) {
//        printf("%d %d %d\n", l[i].x, l[i].y, l[i].id);
//    }

    fto(i, 1, sz(l)-1) {
        if (l[i].y < l[i-1].y) return false;
    }
    return true;
}


int main () {
    int r, c, n; scanf("%d%d%d", &r, &c, &n);
    vector<point> up, down;
    vector<line> l;
    fto(i, 0, n-1) {
        int x1, y1, x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        if (onBound(r, c, x1, y1) && onBound(r, c, x2, y2)) {
            bool up1 = (x1 == 0 || y1 == c), up2 = (x2 == 0 || y2 == c);
            bool isSpecial = (up1^up2);
            if (isSpecial) {
                if (up1) l.pb({x1+y1, x2+y2, i});
                else l.pb({x2+y2, x1+y1, i});
            }
            if (up1) up.pb({x1+y1, i, isSpecial});
            else down.pb({x1+y1, i, isSpecial});
            if (up2) up.pb({x2+y2, i, isSpecial});
            else down.pb({x2+y2, i, isSpecial});
        }
    }

    puts((Solve(n, up) && Solve(n, down) && SolveLine(l)) ? "YES" : "NO");

    return 0;
}


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	ll a=n/100, b=n%100;
	if(1<=a and a<=12){
		if(1<=b and b<=12)puta("AMBIGUOUS");
		else puta("MMYY");
	}else{
		if(1<=b and b<=12)puta("YYMM");
		else puta("NA");
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
#define INF 1000000000000000007ll
using namespace __gnu_pbds;
using namespace std;

int n,dp[2020][2010];
pair<int,int> a[2010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].first;
		a[i].second=i;
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dp[i][j]=-INF;
	dp[0][0]=0;
	int ans=-INF; 
	for(int i=1;i<=n;i++){
		for(int j=0;j<=n;j++){
			int num1=j,num2=i-j;
			if(num1>0){
				int pos=num1;
				int cur=a[i].first*(a[i].second-pos);
				dp[num1][num2]=max(dp[num1][num2],dp[num1-1][num2]+cur);
			}
			if(num2>0){
				int pos=n-num2+1;
				int cur=a[i].first*(pos-a[i].second);
				dp[num1][num2]=max(dp[num1][num2],dp[num1][num2-1]+cur);
			}
			if(i==n) ans=max(ans,dp[num1][num2]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    string a;
    cin >> a;
    if (a[0] ==a[1] or a[1]==a[2] or a[2]==a[3] or a[3] ==a[4] ){
    cout << "Bad" << endl;
    }else {
        cout <<"Good"<< endl;
    }

return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(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 main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    int n;
    cin>>n;
    int x;
    string p="";
    string q="";
    REP(i,n)
    {
        cin>>x;
        p+=to_string(x);
    }
    REP(i,n)
    {
        cin>>x;
        q+=to_string(x);
    }
    string s="";
    FOR(i,1,n)
    {
        s+=to_string(i);
    }
    int a=0,b=0;
    int i=1;
    while(a==0 || b==0)
    {
        if(p==s)
        a=i;
        if(q==s)
        b=i;
        i++;
        next_permutation(s.begin(),s.end());
    }
    cout<<abs(a-b);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

ll dp[110][10010];

int main() {
	int N,W;
	cin >> N >> W;
	vector<int> v(N), w(N);
	rep(i,N) cin >> v[i] >> w[i];

	rep(i,N+1) rep(j,W) dp[i][j] = -1e9;
	dp[0][0] = 0;

	rep(i,N) {
		rep(j,W+1) {
			if(j < w[i]) dp[i+1][j] = dp[i][j];
			else chmax(dp[i+1][j], max(dp[i][j], dp[i][j-w[i]] + v[i]));
		}
	}
	ll maxi = 0;
	rep(j,W+1) chmax(maxi, dp[N][j]);
	/*
	rep(i,N+1) {
		rep(j,W+1) {
			if(dp[i][j] < 0) cout << setw(3) << -1;
			else cout << setw(3) << dp[i][j];
		}
		cout << endl;
	}
	*/
	cout << maxi << endl;

  return 0;
}


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

typedef long long ll;

int main(){
    ll n,i,j,k,l,r;
    cin>>k>>n;
    ll a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    vector<ll>p;
    for(i=0;i<n-1;i++)
    {
        p.push_back(a[i+1]-a[i]);
    }
    l=a[0];
    l+=k-a[n-1];
    p.push_back(l);
    sort(p.begin(),p.end());
    ll sum=0;
    for(i=0;i<p.size()-1;i++)
    sum+=p[i];
    cout<<sum;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
map<pair<int,int>,bool> M;
long long int H,W;
vector<int> A={-1,-1,-1,0,0,0,1,1,1},B={-1,0,1,-1,0,1,-1,0,1};

int cnt(pair<int,int> p){
    if(p.first>=2&&p.first<=H-1&&p.second>=2&&p.second<=W-1){
        int sum=0;
        for(int i=0;i<9;i++){
        if(M[make_pair(p.first+A[i],p.second+B[i])]==1) sum++;
    }
    return sum;
    }
    else return 0;
}

int main(){
    
    int N;cin>>H>>W>>N;
    vector<pair<int,int>> S(N);
    for(int i=0;i<N;i++){
        cin>>S[i].first>>S[i].second;
    }
    sort(S.begin(),S.end());
    vector<long long int> T(10);
    for(int i=0;i<N;i++){
        M[make_pair(S[i].first,S[i].second)]=1;
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<9;j++){
            T[cnt(make_pair(S[i].first+A[j],S[i].second+B[j]))]++;
        }
    }
    long long int V=0;
    for(int i=1;i<=9;i++){
        T[i]/=i;
        V+=T[i];
    }
    T[0]=(H-2)*(W-2)-V;
    for(int i=0;i<10;i++){
        cout<<T[i]<<endl;
    }
}


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

typedef long long ll;
const int maxn=1e5+10;
int n,m,fa[maxn],vis[maxn],size[3],cnt;
ll ans;
vector<int> g[maxn],gg[maxn];
bool flag;

void dfs(int pos,int c){
	if(~vis[pos]){
		if(vis[pos]!=c)
			flag=true;
		return;
	}
	vis[pos]=c;
	++size[c];
	cnt+=g[pos].size();
	for(int i=0;i<g[pos].size();++i)
		dfs(g[pos][i],(c+1)%3);
	for(int i=0;i<gg[pos].size();++i)
		dfs(gg[pos][i],(c+2)%3);
}

int main(){
	cin>>n>>m;
	for(int i=1,u,v;i<=m;++i){
		cin>>u>>v;
		g[u].push_back(v);
		gg[v].push_back(u);
	}
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=n;++i)
		if(vis[i]==-1){
			flag=false;
			size[0]=size[1]=size[2]=0;
			cnt=0;
			dfs(i,0);
			if(flag)
				ans+=(ll)(size[0]+size[1]+size[2])*(size[0]+size[1]+size[2]);
			else if(size[1]&&size[2])
				ans+=(ll)size[0]*size[1]+(ll)size[1]*size[2]+(ll)size[2]*size[0];
			else
				ans+=cnt;
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 17792
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      String S = sc.next();
      
      
      String S1 = "AAA";
      String S2 = "BBB";
      
      if(S.equals(S1)){
      System.out.println("No");
      }
      else if(S.equals(S2)){
      System.out.println("No");
      }
      else{
        System.out.println("Yes");
      }
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

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

  for(int i=0; i<s.size(); i++){
    int next;
    next= (s[i] - 'A' + n) %26;
    s[i]= next + 'A';
  }
  cout << s << endl;
}


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

using namespace std;

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

    if(a<=5)
        cout<<"0"<<endl;
    else if(a>=6 && a<=12)
        cout<<b/2<<endl;
    else if(a>=13)
        cout<<b<<endl;
        return 0;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int i = S.size();
  char c = T.at(i);
  
  if(S + c == T){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,w;
    cin>>n>>w;
    ll wt[n],val[n],val_sum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];
        val_sum+=val[i];
    }
    ll dp[val_sum+1][n+1],ans=0;
    memset(dp,0,sizeof(dp));
    for(ll i=0;i<=val_sum;i++)
    {
        for(ll j=n;j>=0;j--)
        {
            if(i==0)
                dp[i][j]=0;
            else if(j==n)
                dp[i][j]=w+1;
            else if(i>=val[j])
                dp[i][j]=min(dp[i][j+1],wt[j]+ dp[i-val[j]][j+1]);
            else
                dp[i][j]=dp[i][j+1];
        }
        if(dp[i][0]<=w)
            ans=i;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long n, a, b; cin>>n>>a>>b;
  long long diff = b-a;
  if (diff & 1) {
    long long d1 = a;
    long long final_b = b - d1;
    long long d2 = n - b + 1;
    long long final_a = a + d2;
    long long ans1 = d1 + ((final_b - 1) >> 1);
    long long ans2 = d2 + ((n - final_a) >> 1);
    cout << min(ans1, ans2) << endl;
    return 0;
  }
  cout << (diff>>1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cmath>
#include <chrono>

#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int> ())
#define FOR(k, n) for(int k=0; k<n; k++)



using namespace std;
using namespace std::chrono;

char nums[10] = { '0','1','2','3','4','5','6','7','8','9' };
char alphsl[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
const int MOD = 1000000007;
char alphs[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };


bool checkpal(string s, int a, int b){
    int n=b-a+1;
    for(int i=a; i<=b; i++){
        if(s[i]!=s[a+n-i-1]){
            
            return false;
        }
    }
    return true;
}

void solve() {

    string s;
    cin>>s;
    int n=s.length();
    if(checkpal(s, 0, ((n-1)/2)-1)&&checkpal(s, (n+1)/2, n-1)&&checkpal(s, 0, n-1)){
        cout<<"Yes"<<endl;
        return;
    }
    cout<<"No"<<endl;
}


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    
        solve();


    return 0;
}

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



int main() {
	string s;
	cin >> s;
	int ans = 0;
	char priv = s.at(0);
	for (char c : s) {
		if (c==priv) {
			continue;
		}
		priv = c;
		ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<pair<int, int> > VPII;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	string s;
	cin >> s;
	// size_t型(同士の計算)は符号なし整数なのでマイナスにならない
	// int型にキャストする
	if (s.find('C')!=string::npos && (int)s.rfind('F') - (int)s.find('C') > 0) {
		O("Yes");
	}
	else {
		O("No");
	}


	return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())

    ans = 0
    t = -1
    p = 1 << 30
    for h in map(int, input().split()):
        if p >= h:
            t += 1
            if ans < t:
                ans = t
        else:
            t = 0
        p = h

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  lb a,b,c,d;cin>>a>>b>>c>>d;
  out(fixed<<setprecision(10)<<sqrt((a-c)*(a-c)+(b-d)*(b-d)));

  return 0;
}



Measured memory_bytes: 3292
#include<bits/stdc++.h>
#define ll long long
const int N = 5010;
ll a[N],ans,der[N],b[N][N>>3];
int n,m;
struct sta{
	int top,s[N];
}sta[N>>3];
int main(){
	scanf("%d %d",&n,&m);
	for(int i=2;i<=n;++i)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j)
			scanf("%lld",&b[i][j]);
	}
	for(int i=n;i;--i){
		ll now=0;
		for(int j=1;j<=m;++j){
			while(sta[j].top&&b[i][j]>=b[sta[j].s[sta[j].top]][j]){
				if(sta[j].top>1)
					der[sta[j].s[sta[j].top-1]]-=b[sta[j].s[sta[j].top-1]][j]-b[sta[j].s[sta[j].top]][j];
				sta[j].top--;
			}
			if(sta[j].top>=1)
				der[sta[j].s[sta[j].top]]+=b[sta[j].s[sta[j].top]][j]-b[i][j];
			sta[j].s[++sta[j].top]=i;
			now+=b[i][j];
		}
		//int now=0;
		ans=std::max(now,ans); 
		for(int j=i+1;j<=n;++j){
			now+=der[j];
			now-=a[j];
			ans=std::max(now,ans);
		}
	}
	printf("%lld",ans);
	return 0;
} 

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

int main() {

	ll n, m; cin >> n >> m;

	vector<pair<ll, ll>> pa(n);
	for (ll i = 0; i < n; i++) {
		cin >> pa[i].first >> pa[i].second;
	}

	sort(pa.begin(), pa.end());
	
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		if (pa[i].second < m) {
			ans += pa[i].first * pa[i].second;
			m -= pa[i].second;
		}
		else{ // m <= pa[i].second
			ans += pa[i].first * m;
			break;
		}
	}

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              (double)3.14159265358979323844
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll s,w;
    cin>>s>>w;
    if (w>=s){
    	cout<<"unsafe"<<endl;
    	return;
    }
    cout<<"safe"<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
using namespace std;
long long mod=1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t=1;//cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        int cnt=0;
        int a[3]={0};
        for(int i=0;i<3;i++)
        {
            if(s[i]=='R') cnt++;
            else cnt=0;
            a[i]=cnt;
        }
        int ans=0;
        for(int i=0;i<3;i++)
        ans=max(ans,a[i]);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <iomanip>

#define rep(i,a,b) for(long long i=a;i<b;i++)

using namespace std;
int combination(int n, int r)
{
	if (r == 0 || r == n)
		return (1);
	else if (r == 1)
		return (n);
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

int main(void) {

	long long N=0,A=0,B=0,X=0,Y=0;
	long long big = 0,big2=0;
	long long c = 0;

	cin >> A >> B;
	
	
	if (A < 9 && B < 9) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
	

	return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>

using namespace std;

int main()
{
  int n, k; cin >> n >> k;
  int p[200000]; for (int i = 0; i < n; ++i) cin >> p[i];
  
  int sum = 0;
  for (int i = 0; i < k; ++i) sum += p[i];
  int mx = sum;
  for (int i = k; i < n; ++i) {
    sum += p[i] - p[i-k]; mx = max(mx, sum);
  }
  
  double ans = (mx+k)/2.0;
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define int long long

constexpr int N = 330;

int dist[N][N];
int ness[N][N];

signed main() {
    int n;
    cin >> n;
    rep(i, n) rep(j, n) cin >> dist[i][j];

    bool flag = false;
    rep(i, N) rep(j, N) ness[i][j] = 1;
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int length = dist[i][k] + dist[k][j];
                if (length < dist[i][j]) {
                    flag = true;
                    break;
                } else if (length == dist[i][j] && i != k && j != k) ness[i][j] = 0;
            }
        }
    }

    if (flag) {
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(ness[i][j] == 1) ans += dist[i][j];
        }
    }

    cout << ans / 2 << endl;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dl;
const int iNF = 1e9 + 100;
const ll INF = 1e18 + 100;
typedef pair<int, int> pii;

int main() {
   int n;
   cin >> n;
   n = n % 10;
   if(n == 2 or n == 4 or n == 5 or n == 7 or n == 9){
      cout << "hon" << endl;
   }else if( n == 3){
      cout << "bon" << endl;
   }else{
      cout << "pon" << endl;
   }
   return 0;
}

Measured memory_bytes: 3620
#pragma GCC diagnostic error "-std=c++14"
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cctype>
using namespace std;
template <class code>inline code read(const code &a)
{
    code x=0;short w=0;char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return w?-x:x;
}
void print(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)print(x/10);
	putchar(x%10+48);
}
int main()
{
	int n=read(n);
	while(n!=0){
		if(n%10==7){
			puts("Yes");
			return 0;
		}
		n/=10;
	}
	puts("No");
	return 0;
}



Measured memory_bytes: 1492
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define F first
#define S second
using namespace std;
#define mod 1000000007

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1;
    while(t--){
        int n,k; cin>>n; ll arr[n+1];
        for(int i=1;i<=n;i++) cin>> arr[i];
        ll profit=(1000%arr[1]);
        ll st=(ll)1000/arr[1];
        for(int i=2;i<=n;i++){
            if(arr[i]>arr[i-1]){
                profit+=((ll)st*arr[i]);
                st=profit/arr[i];
                profit=profit%arr[i];
            }else{
                profit+=(ll)st*arr[i-1];
                st=profit/arr[i];
                profit=profit%arr[i];
            }
        }
        profit+=(ll)st*arr[n];
        cout<< profit<<endl;

    }

}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

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

Measured memory_bytes: 3712
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;
  cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 384
'use strict';
(function(stdin) { 
  var inputs = stdin.toString();
  (function(x) {
    //????????????????????????
    console.log(Math.pow(x,3));
  }(parseInt(inputs.trim(),10))); //????°??????????????¶?????????°?????????
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7644
n = int(input())
a = list(map(int, input().split()))

def calc_half(n):
    return int(n / 2)

all_even = True
count = 0
while all_even:
    for value in a:
        if value % 2 == 1:
            all_even = False
            break
    if all_even:
        a = list(map(calc_half, a))
        count +=1
print(count)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){

    int n,m;
    int i,j,k;
    int reslut[128]={0};

    scanf("%d %d",&n,&m);
    int two_array[n][m];

    for(i = 0; i<n; i++){
        for(j = 0; j<m; j++){
            scanf("%d",&two_array[i][j]);
        }
    }

    int one_array[m];

    for(k = 0; k<m; k++){
        scanf("%d",&one_array[k]);
    }

    for(i=0; i<n;i++){
        for(j=0; j<m; j++){
            reslut[i] += two_array[i][j] * one_array[j];
            
        }
        printf("%d\n",reslut[i]);
    }
    
    

}


Measured memory_bytes: 2112
ABCD = list(input())

def Calc(a,b,op):
    if op == "+":
        return int(a) + int(b)
    else:
        return int(a) - int(b)

ops = [["+","+","+"], ["+","+","-"], ["+","-","+"], ["-","+","+"],
       ["-","-","+"], ["-","+","-"], ["+","-","-"], ["-","-","-"]]

for op1, op2, op3 in ops:
    AB = Calc(ABCD[0],ABCD[1],op1)
    ABC = Calc(AB, ABCD[2], op2)
    ans = Calc(ABC, ABCD[3], op3)

    if ans == 7:
        print(ABCD[0]+op1+ABCD[1]+op2+ABCD[2]+op3+ABCD[3] + "=7")
        break



Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N = keyboard.nextInt();
		int A = keyboard.nextInt();
		int[] in = new int[N];
		for(int i=0; i < N; i++) {
			in[i] = keyboard.nextInt();
		}
		
		for (int i = 0; i < N; i++) {
			in[i] -= A;
		}
		
		long[][] masu = new long[51][5001];
		
		masu[0][2500] = 1;
		
		for(int j = 1; j < N+1; j++) {
			for(int k = 0; k < 5001; k++) {
				if(k-in[j-1] >= 0 && k-in[j-1] <= 5000) {
				masu[j][k] += masu[j-1][k-in[j-1]];
				masu[j][k] += masu[j-1][k];
				}
			}
		}
			
		System.out.println(masu[N][2500]-1);
		keyboard.close();
	}
}

Measured memory_bytes: 25172
/*
   Username : moondancer
   Name : Moon Dancer
*/


#include <bits/stdc++.h>
using namespace std;

#define int long long

vector<int> v[100001];
bool v2[100001];

void dfs(int x){
    v2[x]=1;
    for(int i:v[x]){
        if(!v2[i])
            dfs(i);
    }
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    while( m-- ) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int ans = -1;
    for (int i = 1; i <= n; ++i) {
        if(!v2[i]){
            ans++;
            dfs(i);
        }
    }
    cout<<ans;
    return 0;
}

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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  lint n, k;
  cin >> n >> k;
  lint ans = 0;
  for (lint b=k+1; b<=n; ++b) {
    // a%b >= k
    ans += n/b*(b-k);
    ans += max((lint)0, n%b-max(k-1, (lint)0));
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int n, s, num, count=0;
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    cin >> s;
    for (int j=0; j<s; j++) {
        cin >> num;
        for (int i=0; i<n; i++) {
            if(a[i] == num) {
                count++;
                break;
            }
        }
    }
    
    cout << count << endl;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cassert>
#include <vector>
#define REP(i,l,n) for(int i=l;i<n;++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
int n;
vector<int> head;
void dissolve(int target);
int main() {
  while(1){
    cin >> n;
    if(n==0) return 0;
    dissolve(n);
  }
  return 0;
}

void dissolve(int target){
  int start;
  if(head.empty()||target<=head.back()){
    start = target-1;
    rep(i,head.size()) cout << head[i] << " ";
    cout << target << endl;
  }else{
    start = head.back();
  }
  for(int i = start;i>0;i--){
    head.push_back(i);
    dissolve(target-i);
    head.pop_back();
  }
}

Measured memory_bytes: 1216
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner cin = new Scanner(System.in);
		int N = cin.nextInt();
		
		int A[] = new int[200200];
		
		int B[] = new int[200200];
		
		for(int i = 2;i<N+1;i++) A[i] = cin.nextInt();
		
		for(int i = 2;i<N+1;i++) B[A[i]]++;
		
		
		//社員番号1~Nのそれぞれの社員について、直属の部下が何人いるか出力
		for(int i = 1;i<N+1;i++) System.out.println(B[i]);

	}

}

Measured memory_bytes: 61560
import java.util.Scanner;

public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);

			//受け取り
			//連結
			long takahashi = sc.nextLong();
			long aoki = sc.nextLong();
			long count = sc.nextLong();


			if( count >= takahashi + aoki) {
				takahashi = 0;
				aoki = 0;
			}else if( count > takahashi) {
				long tmp = count - takahashi;
				takahashi = 0;
				aoki = aoki - tmp;
			}else{
				takahashi = takahashi -count;
			}

			System.out.print(takahashi +" " + aoki);


		}
}



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

using namespace std;

//#define FILE_IO

const int mod = 1e9 + 7;

const int VMAX = 4000000;

int N, K;
int fct[VMAX + 5], ifct[VMAX + 5];

int dp[2005][2005];

int power(int x, int y)
{
    int p = x, r = 1;
    while(y)
    {
        if(y & 1)   r = (1LL * r * p) % mod;
        p = (1LL * p * p) % mod;
        y >>= 1;
    }
    return r;
}

int C(int N, int K)
{
    int ans = fct[N];
    ans = (1LL * ans * ifct[K]) % mod;
    ans = (1LL * ans * ifct[N - K]) % mod;
    return ans;
}

void precalc()
{
    fct[0] = 1;
    for(int i = 1; i <= VMAX; i++)
        fct[i] = (1LL * fct[i - 1] * i) % mod;
    ifct[VMAX] = power(fct[VMAX], mod - 2);
    for(int i = VMAX - 1; i >= 1; i--)
        ifct[i] = (1LL * ifct[i + 1] * (i + 1)) % mod;
    ifct[0] = 1;
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    precalc();

    scanf("%d%d", &N, &K);

    if(N == 1 || K == 1)
    {
        printf("1\n");
        return 0;
    }

    /// DP[i][j] - i-th white ball, j-th colors
    dp[N + 1][N + 1] = 1;
    for(int i = N + 1; i >= 1; i--)
        for(int j = i == N + 1 ? N : i; j >= 1; j--)
        {
            int white = dp[i + 1][j];
            int color = ( 1LL * dp[i][j + 1] * C( (N - i + 1) + (N - j + 1) * (K - 1) - 1 , K - 2 ) ) % mod;
            dp[i][j] = (white + color) % mod;
        }

    int ans = (1LL * dp[1][1] * fct[N]) % mod;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 46336
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n, A, B, H[MAXN], mark[MAXN], H2[MAXN];
vector<ll> adj[MAXN];

void DFS(ll v, ll p) {
    H[v] = H[p] + 1;
    for (ll u : adj[v]) {
        if (u == p) continue;
        DFS(u, v);
    }
}

void DFS2(ll v, ll p = -1) {
    mark[v] = 1;
    for (ll u : adj[v]) {
        if (mark[u]) continue;
        if (H2[v] + 1 < H[u]) {
            H2[u] = H2[v] + 1;
            DFS2(u, v);
        }
    }
}

int main() {
    fast_io;

    cin >> n >> A >> B;
    for (ll i = 1; i < n; i++) {
        ll v, u;
        cin >> v >> u;
        adj[v].push_back(u);
        adj[u].push_back(v);
    }
    H[0] = -1;
    DFS(B, 0);
    DFS2(A);

    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        if (mark[i]) {
            ans = max(ans, H[i] - (H[i] != H2[i]));
        }
    }

    cout << ans << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 36096
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys
#from heapq import heapify, heappush, heappop
#from heapq import nlargest, nsmallest

iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
readline = sys.stdin.readline
# puorquoi le sys.stdin.buffer.readline() fonctionne plus sur atcoder?
#sys.setrecursionlimit(10 ** 7)
#INF = 1 << 30 # 大体 1e9


def debug(*x):
    print(*x, file=sys.stderr)


# s == self
class atcoder():
    def __init__(s):
        s.A, s.B, s.C, s.D = map(int, sys.stdin.readline().split()) 
        

    def çözmek(s):
        
        res = []
        res.append(s.関数(s.A, s.B, s.C, s.D))
        print(*res)	
    
    def 関数(self, a, b, c, d):
        ac = a * c
        ad = a * d
        bc = b * c
        bd = b * d
        res = max(ac, ad, bc, bd)
        return res 

if __name__ == "__main__":
    ima = atcoder()
    ima.çözmek()



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

int main(void){
    int n, m;
    cin>>n>>m;
    int a=pow(2, m);
    int b=1900*m+(n-m)*100;
    int ans=a*b;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String args[]) throws IOException{
   int n,m;
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String line = br.readLine(); 
   String[] token = line.split(" ");
   n = Integer.parseInt(token[0]);
   m = Integer.parseInt(token[1]);
   int[][] matrixA = new int[n][m];
   int[] matrixB = new int[m];
   int[] matrixanswer = new int[n]; 

   for(int i = 0; i < n ;i++){
     String line2 = br.readLine(); 
     String[] token2 = line2.split(" ");
     for(int j = 0; j < m ;j++){
        matrixA[i][j] = Integer.parseInt(token2[j]);
        
     }//for  
   }//for

   for(int i = 0; i < m ;i++){
      matrixB[i] = Integer.parseInt(br.readLine());
   }

   for(int i = 0; i < n ;i++){
      matrixanswer[i] = 0;
   }   

  for(int i = 0; i < n ;i++){
      for(int j = 0; j < m ;j++){
        matrixanswer[i] += matrixA[i][j]*matrixB[j];
      }
   }

    for(int j = 0; j < n ;j++){
       System.out.println(matrixanswer[j]);
    }


  }
}

Measured memory_bytes: 27600
class Program
{
    static void Main()
    {
        const int MAX = 9;
        for (var i = 1; i <= MAX; ++i)
        {
            for (var j = 1; j <= MAX; ++j)
            {
                var result = i * j;
                System.Console.WriteLine(i + "x" + j + "=" + result);
            }
        }
    }
}

Measured memory_bytes: 5572
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

vector<int> P(1e5+1,1),sumP(1e5+1,0);
set<int> Prime;

int main(){
    int Q; cin>>Q;
    vector<pair<int,int>> LR;
    rep(q,0,Q){
        int l,r; cin>>l>>r;
        LR.emplace_back(l,r);
    }

    for(int i=2;i<P.size();i++){
        if(P.at(i)){
            Prime.insert(i);
            int k=2;
            while(i*k<P.size()){
                P.at(i*k)=0;
                k++;
            }
        }
    }

    rep(i,2,sumP.size()){
        if(i%2){
            if(Prime.count(i) && Prime.count((i+1)/2)) sumP.at(i)=sumP.at(i-1)+1;
            else sumP.at(i)=sumP.at(i-1);
        }else sumP.at(i)=sumP.at(i-1);
    }

    for(auto lr:LR){
        int ans=sumP.at(lr.second)-sumP.at(lr.first-1);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 2676