akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <set>
using namespace std;
#define MAX_V 205
#define INF 1<<30
int N, M;
int cost[MAX_V][MAX_V];
int H[MAX_V];

int mincost[MAX_V];
bool used[MAX_V];
bool Vused[MAX_V][MAX_V];
int prevV[MAX_V];

int prim(int t){
	for(int i=0;i<N;i++){
		mincost[i]=INF;
		used[i] = false;
		prevV[i] = N;
	}
	for(int u=0;u<N;u++){
		if(H[u]>t){
			mincost[u]=0;
			break;
		}
	}
	
	int res = 0;

	while(true){
		int v = -1;
		for(int u=0;u<N;u++){
			if(H[u]>t && !used[u] && (v==-1 || mincost[u] < mincost[v])) v=u;
		}
		if(v == -1) break;
		used[v] = true;
		Vused[v][prevV[v]] = Vused[prevV[v]][v] = true;
		if(mincost[v] >= INF) return INF;
		res += mincost[v];
		for(int u=0;u<N;u++){
			if(H[u] <= t) continue;
			if(Vused[v][u] || Vused[u][v]){
				mincost[u] = 0;
				prevV[u] = v;
			}
			if(mincost[u] > cost[v][u]){
				mincost[u] = cost[v][u];
				prevV[u] = v;
			}
		}
	}
	return res;
}

main(){
	int i,j,k,a,b,c;
	while(cin >> N >> M, N){
		vector<int> broken;
		for(i=0;i<N;i++){
			for(j=0;j<N;j++){
				cost[i][j] = INF;
				Vused[i][j] = false;
			}
		}
		broken.push_back(0);
		for(i=0;i<N;i++){
			cin >> H[i];
			broken.push_back(H[i]);
		}

		sort(broken.begin(), broken.end());
		broken.erase(unique(broken.begin(), broken.end()), broken.end());
		
		for(i=0;i<M;i++){
			cin >> a >> b >> c;
			cost[a-1][b-1] = cost[b-1][a-1] = c;
		}

		int co = 0;
		for(i=broken.size()-1;i>=0;i--){
			int ret = prim(broken[i]);
			if(ret >= INF){
				co = 0;
				for(k=0;k<N;k++){
					for(j=0;j<N;j++){
						Vused[k][j] = false;
					}
				}
			}else co += ret;
		}
		cout << co << endl;
	}
	return 0;
}

Measured memory_bytes: 1428
//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 100009
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
    	ll n,x,y,i,t,j,k,c,b,m,r;
    	cin>>n;
    	if(n%1000==0)
            cout<<0<<endl;
        else{
            r=(n/1000)+1;
            m=r*1000-n;
            cout<<m<<endl;
        }

}












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

#define forn(i, n) for (int i = 0; i < n; i++)
#define re return
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define point pair <int, int>
#define re return
#define se second
#define fi first
#define mp(a, b) make_pair(a, b)
#define mp1(a, b, c, d) make_pair(mp(a, b), mp(c, d))
using namespace std;
typedef long long ll;
const int mod =  998244353;
const int ma = 2 * 128 * 1024;
const int k1 = 8, k2 = 8;
using namespace std;

ll n, k, a, b, fc[int(1e6) + 1], ofc[int(1e6) + 1];

ll pow2(ll a, ll c) {
    ll ans = 1;
    forn (i, 30) {
        if (c & (1 << i)) ans = (ans * a) % mod;
        a = (a * a) % mod;
    }
    return ans;
}

ll get_c(ll n, ll k) {
    if (k > n || k < 0) return 0;
    return ((fc[n] * ofc[k])%mod) * ofc[n - k] % mod;
}
int main() {
    iostream::sync_with_stdio(0);
    cin >> n >> a >> b >> k;
    fc[0] = 1;
    forn (i, n)
        fc[i + 1] = (fc[i] * ll(i + 1)) % mod;
    ofc[n] = pow2(fc[n], mod - 2);
    for (int i = n - 1; i >= 0; i--) ofc[i] = (ofc[i + 1] * ll(i + 1)) % mod;
    //forn (i, n + 1) cout << fc[i] << " " << ofc[i] << "\n";
    ll gc = __gcd(a, b);
    if (k % gc) {
        cout << "0\n";
        return 0;
    }
    k /= gc;
    a /= gc;
    b /= gc;
    ll ans = 0;
    for (int cnt1 = 0; cnt1 <= n; cnt1++) {
        ll ka = cnt1, kb = (k - a * ka) / b;
        //cout << ka << " " << kb << "\n";
        if ((k - a * ka) % b || k - a * ka < 0) continue;
        //cout << get_c(n, ka) << " koh " << get_c(n, kb) << "\n";
        ans += get_c(n, ka) * get_c(n, kb);
        ans %= mod;
    }
    cout << ans << "\n";
} 

Measured memory_bytes: 8448
#include<cstdio>
#include<iostream>
#include<string>
#include<stack>

using namespace std;

int main(){

	int N;
	int pi;
	int gi;
	int cnt[101];
	char in;
	string s[100];
	int gl[100];
	string tmp;
	stack<int> p;
	

	cin>>N;

	getchar();
	/*1...label 2...goto*/
	for(int i=0;i<N;i++){
		tmp="";
		while(1){
			in=getchar();
			if(in=='\n') break;
			tmp+=in;
		}
		s[i]="";
		if(tmp.size()>=7&&tmp[0]=='g'&&tmp[1]=='o'&&tmp[2]=='t'&&tmp[3]=='o'&&tmp[4]==' '){
			gl[i]=2;
			for(int j=5;j<tmp.size()-1;j++){
				s[i]+=tmp[j];
			}
		}
		else{
			gl[i]=1;
			for(int j=0;j<tmp.size()-1;j++){
				s[i]+=tmp[j];
			}
		}
	}

	for(int i=0;i<=N;i++){
		cnt[i]=100000;
	}

	p.push(0);
	cnt[0]=0;
	while(!p.empty()){
		pi=p.top();
		p.pop();
		if(gl[pi]==1){
			if(cnt[pi]<cnt[pi+1]){
				cnt[pi+1]=cnt[pi];
				if(pi!=N) p.push(pi+1);
			}
		}
		else if(gl[pi]==2){
			for(int i=0;i<N;i++){
				if(gl[i]==1&&s[i]==s[pi]){
					gi=i;
					break;
				}
			}
			if(cnt[pi]+1<cnt[pi+1]){
				cnt[pi+1]=cnt[pi]+1;
				if(pi!=N) p.push(pi+1);
			}
			if(cnt[pi]<cnt[gi]){
				cnt[gi]=cnt[pi];
				p.push(gi);
			}
		}
	}

	cout<<cnt[N]<<endl;

	return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>
int main(){
  int H,W,i,j;
  while(1){
    scanf("%d %d",&H,&W);
    if(H==0&&W==0)break;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

int N, M;
int a[(int)1e5];
int const mod = 1e9 + 7;

int main() {
    cin >> N >> M;
    rep(i, M) cin >> a[i];

    vector<int> broken(N + 1);
    int dp[N + 2] = {0};

    rep(i, M) {
        broken[a[i]] = 1;
    }

    dp[N] = 1;
    // cout << dp[0] << endl;
    for (int i = N - 1; i >= 0; i--) {
        if (broken[i] == 1) {
            dp[i] = 0;
            continue;
        }

        dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
        // printf("dp[i + 1] %d dp[i + 2] %d\n", dp[i + 1], dp[i + 2]);
    }

    cout << dp[0] << endl;
}

Measured memory_bytes: 1408
#include <iostream>

int main() {
  std::uint64_t n,a,b;

  std::cin >> n >> a >> b;

  auto sum = a + b;

  auto total = (n / sum) * a;

  auto rest = (n % sum);
  if (rest > a) {
    total += a;
  } else {
    total += rest;
  }

  std::cout << total << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if(r<=x&&x<=W-r&&r<=y&&y<=H-r)
	puts("Yes");
	else
	puts("No");
	
	return 0;
}



Measured memory_bytes: 2040
#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<set>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;

int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

    string n;
  	bool flag = true;
    cin>>n;
    for(int i = 0; i < n.size(); i++){
        if(n[i] - '0' == 7){
          	flag = false;
          	break;
        }
    }
  if(flag){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define N 100010
#define M 25

int tot;
long long poww[M];
int head[N];
struct edge{
    int u,v,w,next;
}e[2*N];
int ver[2*N],R[2*N],first[N];long long dir[N];
int dp[2*N][30];
bool vis[N];

inline void add(int u , int v ,int w ,int &k)
{
    e[k].u = u; e[k].v = v; e[k].w = w;
    e[k].next = head[u]; head[u] = k++;
    u = u^v; v = u^v; u = u^v;
    e[k].u = u; e[k].v = v; e[k].w = w;
    e[k].next = head[u]; head[u] = k++;
}

void dfs(int u ,int dep)
{
    vis[u] = true; first[u] = ++tot; ver[tot] = u; R[tot] = dep;
    for(int k=head[u]; k!=-1; k=e[k].next)
        if( !vis[e[k].v] )
        {
            int v = e[k].v , w = e[k].w;
            dir[v] = dir[u] + w;
            dfs(v,dep+1);
            ver[++tot] = u; R[tot] = dep;
        }
}
void ST(int len)
{
    int K = (int)(log((double)(len)) / log(2.0));
    for(int i=1; i<=len; i++) dp[i][0] = i;
    for(int j=1; j<=K; j++)
        for(int i=1; i+poww[j]-1 <= len; i++)
        {
            int a = dp[i][j-1] , b = dp[i+poww[j-1]][j-1];
            if(R[a] < R[b]) dp[i][j] = a;
            else            dp[i][j] = b;
        }
}

int RMQ(int x ,int y)
{
    int K = (int)(log((double)(y-x+1)) / log(2.0));
    int a = dp[x][K] , b = dp[y-poww[K]+1][K];
    if(R[a] < R[b]) return a;
    else            return b;
}

int LCA(int u ,int v)
{
    int x = first[u] , y = first[v];
    if(x > y) swap(x,y);
    int index = RMQ(x,y);
    return ver[index];
}

int main()
{
    for(int i=0; i<M; i++) poww[i] = (1<<i);
    int n,m,k;
    scanf("%d",&n);
        k = 0;
        memset(head,-1,sizeof(head));
        memset(vis,false,sizeof(vis));
        for(int i=1;i<n;i++)
        {
            int u,v,w;
            scanf("%d%d%d",&u,&v,&w);
            add(u,v,w,k);
        }
        int q,kk;
        scanf("%d%d",&q,&kk);
        tot = dir[k] = 0;
        dfs(kk,1);
        ST(tot);
        while(q--)
        {
            int u,v,lca;
            scanf("%d%d",&u,&v);
            lca = LCA(u,v);
            if(lca==k)
                printf("%lld\n",dir[u] + dir[v] - 2*dir[lca]);
            else
            {
                printf("%lld\n",dir[u] + dir[v]);
            }
        }
    return 0;
}


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

#define ll long long
const int MOD = 1e9+7;
ll mod(ll x) {
	return (x%MOD + MOD) %MOD;
}
ll mul(ll a,ll b) {
	return mod(mod(a) * mod(b));
}

ll bs(vector<ll> &v,ll l,ll r,ll key) {
	//cout << low << " " << high << endl;
	while (r - l > 1) { 
	       int m = (l + r)/ 2; 
	       if (v[m] >= key) 
	           r = m; 
	       else
	           l = m; 
	   } 
	 
	return (v[r] > key)?l:r; 
}
int main() {
	int n,m,k;
	cin >> n >> m >> k;
	vector<ll> a(n+1);
	vector<ll> b(m+1);
	ll sum = 0;
	for(int i = 1;i <= n;i++) {
		cin >> a[i];
		a[i] += sum;
		sum = a[i];
	}
	sum = 0;
	for(int i = 1;i<=m;i++) {
		cin >> b[i];
		b[i] += sum;
		sum = b[i];
	}
	ll j = m;
	ll result = 0;
	for(int i = 0; i <=n && a[i] <= k ;i++)
	{
		j = bs(b,0,j,(k-a[i]));
		if(j == -1) break;
		result = max(result,i+j);
	}
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 6404
#include<cstdio>
using namespace std;

int main() {
  int X; scanf("%d", &X);
  int A = X / 1000,
      B = (X / 100) % 10,
      C = (X / 10) % 10,
      D = X % 10;
  char *fmt;
  if (A+B+C+D==7) fmt = "%d+%d+%d+%d";
  else if (A+B+C-D==7) fmt = "%d+%d+%d-%d";
  else if (A+B-C+D==7) fmt = "%d+%d-%d+%d";
  else if (A+B-C-D==7) fmt = "%d+%d-%d-%d";
  else if (A-B+C+D==7) fmt = "%d-%d+%d+%d";
  else if (A-B+C-D==7) fmt = "%d-%d+%d-%d";
  else if (A-B-C+D==7) fmt = "%d-%d-%d+%d";
  else if (A-B-C-D==7) fmt = "%d-%d-%d-%d";
  printf(fmt, A, B, C, D);
  printf("=7\n");
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	char s[30];
	while(~scanf("%s",s))
	{
		for(int i=0;s[i]!='\0';i++)
		{
			if(s[i]!=',')
			printf("%c",s[i]);
			else 
			printf(" ");
			
		}
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sca=new Scanner(System.in);
		int a=sca.nextInt();
		int b=sca.nextInt();
		int y=sca.nextInt();
		int x=sca.nextInt();
		int v=a*b-y*b-(a-y)*x;
		System.out.print(v);
	}

}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

#define MAX_N 1000
#define MAX_M 100

const long long INF = 1LL << 60;

//境界値に注意！！！

// DP テーブル
ll dp[100010];

int main() {
    ll n;
    cin >> n;
    string a;
    cin >> a;
    if (n>=3200){
        cout << a << endl;
    }else{
        cout << "red" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<memory.h>
using namespace std;


int main(){

   int n , res = 0;
   vector < int > arr;
   map < int , int > mp;
   map < int , int > :: iterator it;

   scanf ("%d" , &n);
   arr.resize(n);

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


	   for ( int i = 0 ; i < n ; ++i){
	       if (arr[i] == i + 1 && i + 1 < n)
	       {
	    	   int tmp = arr[i];
	    	   arr[i] = arr[i + 1];
	    	   arr[ i + 1] = tmp;
	    	   res++;
	       }
	       else if ( arr[i] == i + 1 && i + 1 == n){
	    	        int tmp = arr[i];
	    	   	     arr[i] = arr[i - 1];
	    	   	      arr[ i - 1] = tmp;
	    	   	    res++;
	       }
	   }
   printf ("%d\n" , res);
	return 0;
}


Measured memory_bytes: 640
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let it = stdin.lock().bytes().map(|c| c.unwrap() as char);
    let (fs, ft) = (|c: &char| c.is_whitespace(), |c: &char| !c.is_whitespace());
    let token = it.skip_while(fs).take_while(ft).collect::<String>();
    token.parse().ok().unwrap()
}
#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    f(std::io::BufWriter::new(out.lock()));
}
#[allow(unused_macros)]
macro_rules! debug {
    ($($var:expr),*) => { #[cfg(debug_assertions)] {
        $({ match &$var { v => eprint!("{}={:?} ", stringify!($var), v) } })*
        eprintln!();
    }};
}

fn main() {
    let n: usize = input();
    let s: Vec<char> = input::<String>().chars().collect();

    let mut esum = vec![0; n + 1];
    let mut wsum = vec![0; n + 1];
    for i in 0..n {
        esum[i + 1] = esum[i];
        wsum[i + 1] = wsum[i];
        if s[i] == 'E' {
            esum[i + 1] += 1;
        } else {
            wsum[i + 1] += 1;
        }
    }

    let mut ans = n;
    for i in 0..n {
        ans = std::cmp::min(ans, wsum[i] + esum[n] - esum[i + 1]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 14588
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N;
    vec x(N);
    rep(i,N) cin>>x[i];
    cin>>L>>Q;
    mat dbl(20,vec(N+1));

    x.push_back(x[N-1] + L);
    rep(i,N + 1){
        dbl[0][i] = --upper_bound(ALL(x), x[i] + L) - x.begin();
    }
    reps(k,1,20) rep(i,N + 1) dbl[k][i] = dbl[k-1][dbl[k-1][i]];
    rep(i,Q){
        cin>>A>>B;
        --A; --B;
        if(A > B) swap(A, B);
        ll res = 0;
        Rrep(j,20){
            if(dbl[j][A] < B){
                A = dbl[j][A];
                res += (1LL<<j);
                //cout<<i<<' '<<j<<' '<<A<<endl;
            }
        }
        cout<<res + 1<<endl;
    }
    /*rep(j,20){
        rep(i,N+1) cout<<dbl[j][i]<<' ';
        cout<<endl;
    }*/
}

Measured memory_bytes: 17536
from sys import stdin
input = stdin.readline

r,c = map(int, input().split())
sumrow = [0 for _ in range(c+1)]
for rowidx in range(r):
    row = list(map(int, input().split()))
    row.append(sum(row))
    print(*row)
    
    for colmunidx in range(c+1):
        sumrow[colmunidx] += row[colmunidx]
print(*sumrow)
    


Measured memory_bytes: 6112
#include <iostream>
#include <vector>

using namespace std;

int n, m;
vector<int> g[100005];

int dp[100005];

int solve(int s) {
	if (dp[s] != -1) return dp[s];
	dp[s] = 0;

	for (int a : g[s]) {
		dp[s] = max(dp[s], 1+solve(a));
	}
	return dp[s];
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
	}
	for (int i = 1; i <= n; ++i) {
		dp[i] = -1;
	}
	int res = 0;
	for (int i = 1; i <= n; ++i) {
		res = max(res, solve(i));
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 7552
// D - equeue
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	int ans = 0;
	for (int i = 1; i <= min(n, k); i++) {
		for (int j = 0; j <= i; j++) {
			multiset<int> s;
			for (int ii = 0; ii < i; ii++)
				s.insert(a[(j - 1 - ii + n) % n]);
			int sum = 0, c = 0;
			for (multiset<int>::iterator it = s.begin(); it != s.end(); ++it) {
				if (*it < 0) {
					if (c >= k - i) sum += *it;
					c++;
				} else {
					sum += *it;
				}
			}
			ans = max(ans, sum);
		}
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

using ll = long long;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n+1,0);
  for(int i=0;i<n;++i)cin >> a[i];
  ll ans = 0;
  for(int i=0;i<n;++i){
    ans += a[i] / 2;
    a[i] %= 2;
    if(a[i] and a[i+1]){
      ++ans;
      --a[i];
      --a[i+1];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
int MOD= 1e9+7;
int main(){
    long n,k,a=0,b=0;
    cin >> n >> k;
    long c[n];
    for(int i=0;i<n;i++) cin >> c[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(c[j]<c[i]&&j<i) a++;
            if(c[j]<c[i]&&i<j) b++;
        }
    }
    cout << ((((((k-k%2)/2)*(k-(k-1)%2))%MOD)*a)%MOD+(((((k+1-(k+1)%2)/2)*(k+1-k%2))%MOD)*b)%MOD)%MOD << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int h,w,a,b;cin>>h>>w>>a>>b;
    cout<<h*w-(a*w+b*h)+a*b;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
a, b, c, d = [], [], [], []
for _ in range(N):
    i, j = map(int, input().split())
    a.append(i)
    b.append(j)
for _ in range(M):
    i, j = map(int, input().split())
    c.append(i)
    d.append(j)

for i in range(N):
    point = 1
    min_dst = 1e20
    for j in range(M):
        dst = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if dst < min_dst:
            min_dst = dst
            point = j+1
    print(point)


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

namespace Util {
#ifdef LOCAL
#define dbg(a) cerr << __LINE__ << " \"" << #a << "\": " << a << '\n'
#else
#define dbg(a)
#endif
#define all(v) (v).begin(), (v).end()
}
using namespace Util;

int constexpr MOD = int(1e9) + 7;

void norm(int &a) {
    if (a >= MOD) a -= MOD;
    if (a < 0) a += MOD;
}

int getbit(int a, int i) {
    return (a >> i) & 1;
}

// dp[mask] : 1...popcount(mask) are matched to mask
signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (auto &v : a) for (auto &i : v) cin >> i;
    vector<int> dp(1 << n);
    dp[0] = 1;
    for (int mask = 0; mask < (1 << n) - 1; ++mask) {
        for (int i = 0; i < n; ++i) {
            if (!getbit(mask, i) && a[__builtin_popcountll(mask)][i]) {
                norm(dp[mask ^ (1 << i)] += dp[mask]);
            }
        }
    }
    cout << dp[(1 << n) - 1];
    return 0;
}



Measured memory_bytes: 19548
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

int main() {
	UL x[5];
	rep(i, 5) cin >> x[i];
	rep(i, 5) {
		if (x[i] == 0) cout << (i + 1) << endl;
	}

	return 0;
}


Measured memory_bytes: 3520
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#define ll long long 
#define MOD 10000007

int main(void){
int N;
int a[100];
scanf("%d",&N);
int i;
int color[8]={0};
int X=0;
for(i=0;i<N;i++){
scanf("%d",&a[i]);
if(a[i]/400<8){
 color[a[i]/400]=1;
}else{
 X++;
}
}
int min=0,max=0;
for(i=0;i<8;i++){
 if(color[i]==1) {
 min++;
 max++;
 } 
}
max+=X;
if(X==N) min++;
printf("%d %d\n",min,max);
return 0;
}

Measured memory_bytes: 128
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = [1]*n
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1]>h[b-1]:
        ans[b-1] = 0
    elif h[b-1]>h[a-1]:
        ans[a-1] = 0
    else:
        #print("a")
        ans[a-1] = 0
        ans[b-1] = 0
print(ans.count(1))                

Measured memory_bytes: 20060
n = gets.chomp.to_i

h = { 'AC' => 0, 'WA' => 0, 'TLE' => 0, 'RE' => 0 }
n.times do
  s = gets.chomp
  h[s] += 1
end

puts "AC x #{h['AC']}"
puts "WA x #{h['WA']}"
puts "TLE x #{h['TLE']}"
puts "RE x #{h['RE']}"


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N, K;
ll A[202020];
ll B[202020];
ll mk[202020];
ll i, j, k;

int main(){
    scanf("%lld%lld", &N, &K);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    fornum(i,0,K){
        fornum(j,0,N){
            B[j] = A[j];
            A[j] = 0;
            mk[j] = 0;
        }
        fornum(j,0,N){
            ++mk[max(0ll, j - B[j])];
            --mk[min(N, j + B[j] + 1)];
        }
        ll a = 0,b=0;
        
        fornum(j,0,N){
            a += mk[j];
            A[j] = a;
            if(a==N){
                ++b;
            }
        }
        if(b==N)
            break;
        //printf(":%lld\n",i);
    }
    fornum(i,0,N){
        printf("%lld ", A[i]);
    }
    printf("\n");

    return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

typedef complex<double> P;
typedef vector<P> G;
#define here(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define prev(g, i) g[(i - 1 + g.size()) % g.size()]
const double EPS = 1e-10;
const double INF = 1e12;

struct L {
    P a, b, v;
    L(){}
    // L(P _a, P _b) {a = _a, b = _b, v = b - a;}
    L(P _a, P _b) : a(_a), b(_b), v(b - a) {}
    L(double _ax, double _ay, double _bx, double _by)
        : a(_ax, _ay), b(P(_bx, _by)), v(b - a) {}
};

double cross(P a, P b) {
    return imag(conj(a) * b);
}

double dot(P a, P b) {
    return real(conj(a) * b);
}

// 2: parallel
// 1: orthogonal
// 0: otherwise
int relationLL(L l1, L l2) {
    if (cross(l1.v, l2.v) == 0) return 2;
    if (dot(l1.v, l2.v) == 0) return 1;
    return 0;
}

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

    int q;
    cin >> q;
    while (q--) {
        double v[4][2];
        rep(i, 4) rep(j, 2) cin >> v[i][j];
        L l1(v[0][0], v[0][1], v[1][0], v[1][1]);
        L l2(v[2][0], v[2][1], v[3][0], v[3][1]);
        cout << relationLL(l1, l2) << endl;
    }

}

Measured memory_bytes: 3300
import numpy as np
N, M, C = map(int,input().split())
B = np.array([i for i in map(int,input().split())])
A = []
for n in range(N):
    A.append(np.array([i for i in map(int,input().split())]))

ans = 0

for a in A:
    if (a*B).sum() + C > 0:
        ans += 1
print(ans)


Measured memory_bytes: 12448
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

pair<int, int> XI[200000];
int ans[200000];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	
	for (int i = 0; i < N; i++) {
		cin >> XI[i].first;
		XI[i].second = i;
	}
	
	sort(XI, XI + N);
	
	for (int i = 0; i < N; i++) {
		if (i < N / 2) ans[XI[i].second] = XI[N / 2].first;
		else ans[XI[i].second] = XI[N / 2 - 1].first;
	}
	
	for (int i = 0; i < N; i++) {
		cout << ans[i] << '\n';
	}
	
	return 0;
}

Measured memory_bytes: 4608
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

tower = [[[0] * 10 for i in range(3)] for j in range(4)]

N = int(readline())
for _ in range(N):
    b, f, r, v = map(int, readline().split())
    tower[b - 1][f - 1][r - 1] += v

for i, h in enumerate(tower):
    if i:
        print("#" * 20)
    for r in h:
        print("", *r)



Measured memory_bytes: 5636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] prime = new int[123456*2];
		int end=(int)Math.sqrt((double)123456*2);
		for(int i=4;i<123456*2;i+=2) {
			prime[i-1]=-1;
		}
		for(int i=3;i<=end;i+=2) {
			if(prime[i-1]==0) {
				for(int j=i+i;j<=123456*2;j+=i) {
					prime[j-1]=-1;
				}
			}
		}
		while(true) {
			int n = sc.nextInt();
			if(n==0) break;
			int count=0;
			for(int i=n+1;i<=2*n;++i) {
				if(prime[i-1]==0) count++;
			}
			System.out.println(count);
		}
	}
}



Measured memory_bytes: 28848
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, l;
	cin >> n >> l;
	ll a[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int start;
	for (start = 1; start < n; start++)
	{
		if (a[start] + a[start - 1] >= l)
		{
			break;
		}
	}
	if (start == n)
	{
		cout << "Impossible" << endl;
		return 0;
	}
	cout << "Possible" << endl;
	for (int i = n - 1; i > start; i--)
	{
		cout << i << endl;
	}
	for (int i = 1; i <= start; i++)
	{
		cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
string a,b;
int memo[3001][3001];
vector<string>vec;
int solve(int x,int y){
    if(x==a.length() || y==b.length()) {
        return 0;
    }
    int &cur=memo[x][y];
    if(cur!=-1)
        return cur;
    cur=0;
    if(a[x]==b[y]) {
        cur = max(cur, 1 + solve(x + 1, y + 1));
    }
    else {
        cur = max(cur, solve(x + 1, y));
        cur = max(cur, solve(x, y + 1));
    }
    return cur;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    memset(memo,-1,sizeof(memo));
    cin>>a>>b;
    solve(0,0);
    int s=0,r=0;
    string ans="";
    while(s<a.length() && r<b.length()){
        if(a[s]==b[r]){
            ans+=a[s];
            s++;
            r++;
        }
        else{
            if(memo[s][r+1]>memo[s+1][r]){
                r++;
            }
            else{
                s++;
            }
        }
    }
    cout<<ans;
}

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

const int INF = 1 << 30;
int dp[100010];

int main() {
  for (int i = 0; i < 100010; i++) dp[i] = INF;
  dp[0] = 0;
  for (int n = 1; n <= 100000; n++) {
    int power = 1;
    while (power <= n) {
      dp[n] = min(dp[n], dp[n-power] + 1);
      power *= 6;
    }
    power = 1;
    while (power <= n) {
      dp[n] = min(dp[n], dp[n-power] + 1);
      power *= 9;
    }
  }
  int N; cin >> N;
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M; cin >> N >> M;
    set<ll> a;
    REP(i, M){
        ll k; cin >> k; a.insert(k);
    }
    
    const ll mod = 1e9+7;
    vl dp(N+10, 0); dp[0] = 1;
    REP(i, N+1){
        if(a.count(i+1) == 0){
            dp[i+1] = (dp[i+1] + dp[i]) % mod;
        }
        if(a.count(i+2) == 0){
            dp[i+2] = (dp[i+2] + dp[i]) % mod;
        }
    }
    cout << dp[N]%mod << endstr;
    return 0;
}


Measured memory_bytes: 5760
/*  /$$                                     /$$
      | $$                                    | $$
  /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$
 /$$__  $$ /$$__  $$ /$$_____/ /$$__  $$ /$$__  $$ /$$__  $$ /$$__  $$
| $$  | $$| $$$$$$$$| $$      | $$  \ $$| $$  | $$| $$$$$$$$| $$  \__/
| $$  | $$| $$_____/| $$      | $$  | $$| $$  | $$| $$_____/| $$
|  $$$$$$$|  $$$$$$$|  $$$$$$$|  $$$$$$/|  $$$$$$$|  $$$$$$$| $$
 \_______/ \_______/ \_______/ \______/  \_______/ \_______/|__//$$$$$$ /$$$$$$
                                                               |______/|______/

*/
#include <bits/stdc++.h>
#define fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ln            cout << endl;
#define vi            vector<int>
#define vll           vector<long long>
#define sortl(vec)    sort(vec.begin(), vec.end());
#define sortr(vec)    sort(vec.rbegin(), vec.rend());
#define forn(i, x, n) for(long long i = x; i < n; i++)
#define revn(i, n, x) for(long long i = n; i >= x; i--)
#define in(vec)       for(auto &it : vec) cin >> it;
#define loop(vec)     for(auto &it : vec)
#define	out(vec)      for(auto &it : vec) cout << it << " "; ln
#define ll            long long
#define mod           1000000007
#define debug(x)      cout << x << endl;
#define pb            emplace_back
#define mp            make_pair
#define um            unordered_map
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define f             first
#define s             second
#define pi            3.14159265359
#define CLOCK         cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
using namespace std;

ll bS(ll l, ll r, ll x, vll arr) {
	while (l <= r) {
		ll m = l + (r - l) / 2;

		if (arr[m] == x)
			return m;

		if (arr[m] < x)
			l = m + 1;

		else
			r = m - 1;
	}

	return -1;
}

void primeFactors(ll n) {
	while (n % 2 == 0) {
		//cout << 2 << " ";
		n = n / 2;
	}

	for (ll i = 3; i <= sqrt(n); i += 2) {
		while (n % i == 0) {
			//cout << i << " ";
			n = n / i;
		}
	}

	if (n > 2)
		cout << n << " ";
}

ll power(ll x, ll y, ll p) {
	ll res = 1;
	x = x % p;

	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll modulo(ll a, ll b) {
	ll c = a % b;
	return (c < 0) ? c + b : c;
}

int main() {
// in(vec) works for size-defined type vectors

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	fastio
	ll t = 1;
	while (t--) {
		ll n;
		cin >> n;
		vll vec(n + 1);
		for (ll i = 1; i <= n; i++)
			cin >> vec[i];

		um<ll, ll>hash;
		hash[1 + vec[1]] = 1;
		ll count = 0;

		forn(i, 2, n + 1) {
			hash[i + vec[i]]++;

			if (hash.find(i - vec[i]) != hash.end()) {
				count += hash[i - vec[i]];
			}

		}

		cout << count << endl;

	}
	CLOCK
	return 0;
}



Measured memory_bytes: 12760
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m=MI()
stu=[]
che=[]
for i in range(n):
    stu.append(LI())
for j in range(m):
    che.append(LI())
for i in range(n):
    mini=inf
    num=0
    for j in range(m):
        l=abs(che[j][0]-stu[i][0])+abs(che[j][1]-stu[i][1])
        #print(l,end=" ")
        if l<mini:
            mini=l
            num=j+1
    print(num)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
#define INF 1010101010
#define MOD 1000000007
#define LL long long

int main() {
    string s;
    cin >> s;
    s.erase(unique(s.begin(), s.end()), s.end());
    cout << s.size()-1 << endl;
}

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

int main(){
  string S;
  cin >> S;
  vector<bool> inc(26);
  for(int i=0;i<26;i=i+1){
    inc.at(i) = false;
  }
  for(int i=0;i<S.size();i=i+1){
    inc.at(S.at(i)-'a') = true;
  }
  int count=0;
  for(int i=0;i<26;i=i+1){
    if(!inc.at(i)){
      count=count+1;
      cout << (char)(i+'a') << endl;
      break;
    }
  }
  if(count == 0){
    cout << "None" << endl;
  }
}

  

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int n,m;
  ll s;
  cin >> n>> m;
  vector<int> d;
  for(int i = 0;i<n;i++)
  {
      int a;
      cin >> a;
      s += a;
      d.push_back(a);
  }
  int f = 0;
  sort(d.begin(),d.end());
  for(int i = 0; i<m;i++)
  {
      int a;
      a = d.back();
      d.pop_back();
      if((double)a < (double)s/(4*m))
      {
          f = 1;
          break;
      }
  }
  if(f == 0) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010;
const double eps = 1e-6;

LL n;
LL x = 1e18;

int main()
{
    cin >> n;
    for(int i = 1; i <= 5; i++)
    {
        LL t;
        cin >> t;
        x = min(x, t);
    }

    cout << 4LL + (n + x - 1LL) / x << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int A, B;
		A = reader.nextInt();
		B = reader.nextInt();
		int i=1;
		if(B==1) {
			System.out.println(0);
		}
		else {
			while((A*i)-(i-1) < B) {
				++i;
			}
			System.out.println(i);
		}
		
		

	}

}


Measured memory_bytes: 21460
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n,m,a,b;
    cin >> n>>m;
    vector<int> V(n);
    for(int i = 0;i<m;i++){
        cin >> a >> b;
        V[a-1] += 1;
        V[b-1] += 1;
    }
    for(int i=0;i<V.size();i++){
        cout<<V[i]<<endl;
    }
}

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

int main() {
  const int64_t mod = 1000000007;
  int n;
  string s;
  cin >> n >> s;
  vector<vector<int64_t>> dp(n, vector<int64_t>(n));
  dp.at(0).at(0) = 1;
  for (int i = 0; i < n - 1; i++) {
    if (s.at(i) == '<') {
      for (int j = 0; j <= i; j++) {
        (dp.at(i + 1).at(j + 1) += dp.at(i).at(j) + dp.at(i + 1).at(j)) %= mod;
      }
    } else {
      for (int j = i; j >= 0; j--) {
        (dp.at(i + 1).at(j) += dp.at(i).at(j) + dp.at(i + 1).at(j + 1)) %= mod;
      }
    }
  }
  cout << accumulate(dp.at(n - 1).begin(), dp.at(n - 1).end(), 0l) % mod << endl;
}


Measured memory_bytes: 70656
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,W;
    cin>>n>>W;
    vi v(n),w(n);
    rep(i,n)cin>>v[i]>>w[i];
    int dp[W+1]={};
    rep(i,n){
        REP(j,w[i],W){
            dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
        }
    }
    cout<<dp[W]<<endl;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
char str[1010000];
int main(){
	scanf("%s",str+1);
	int n=strlen(str+1);
	int w;
	scanf("%d",&w);
	for(int i=1;i<=n;i+=w)
		printf("%c",str[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  double a,b,p,q,r;
  cin >> a >> b >> p >> q >> r;
  cout << fixed << setprecision(10) << (p*b-q*(b-a))/(r+q)+b << endl;
}


Measured memory_bytes: 3308
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
#include<iomanip>
using namespace std;
double memo[2000]={};

int main(){
    int p;
    int64_t x;
    cin>>x>>p;
    double res=0.0;
    if(p==100){
        int64_t res=0;
        if(x%2==1){
            res=x/2+1;
        }else{
            res=x/2;
        }
        cout<<res<<endl;
    }else{
        if(x%2==1){
            x=(x+1)/2;
            res=100.0*x/(1.0*p);
        }else{
            x=x/2;
            res=100.0*x/(1.0*p);
        }
        cout<<setprecision(13)<<res<<endl;
    }
    
    
    
    return 0;
}


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

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

int MOD = 1e9 + 7;
ll INF = 1e18;

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

int gcd(int x, int y){
	if (y == 0) return x;
	else return gcd(y, x % y);
}

int main(){
    int n, x; cin>>n>>x;
    vector<int> city(n+1);
    for(int i=0; i<n; i++) {
        cin>>city[i];
    }
    city[n]=x;

    if(n == 1){
        cout << abs(city[0] - city[1]) << endl;
        return 0;
    }

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

    vector<int> dis(n, 0);
    for(int i=0; i<n; i++) dis[i] = city[i+1] - city[i];

    int nxt_dis=gcd(dis[0], dis[1]);
    for(int i=2; i<n; i++){
        nxt_dis=gcd(nxt_dis, dis[i]);
    }
    cout << nxt_dis << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
int x,sam=0;
cin>>x;

while(x>0)
{int c=0;
int y=x;
    while(y>0)
    {
     c++;
     y/=10;
    }

if(c%2!=0)
    sam++;
x--;
}
cout<<sam;
return 0;}


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

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

int main() {
  long N, L, a = 0, ajimin = 100, tmp = 0, ans = 0;
  cin >> N >> L;
  
  for (int i = 1; i <= N; i++) {
    a += L + i - 1;
    tmp = L + i - 1;
    if (abs(ajimin) > abs(tmp)) ajimin = tmp;
  }
  ans = a - ajimin;
  
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1000000007;
 
int main() {
  int A=0,B=0,C=0;
  for(int i=0; i<3; i++){
    char s;
    cin >> s;
    if(s=='a')A++;
    if(s=='b')B++;
    if(s=='c')C++;
  }
  if(A==1 && B==1 && C==1) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

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

int main() {
  int N;
  double ans =0.0, A;
  cin >> N;
  
  for(int i=0; i<N; i++) {
    cin >> A;
    ans += 1.0 / A;
  }
 cout << 1.0 / ans << endl;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main (){
    int n;
    cin >> n;
    vector<int>x(n);
    vector<int>y(n);
    rep(i,n){
        int a;
        cin >> a;
        x[i]=a;
        y[i]=a;
    }
    sort(y.begin(),y.end());
    int ans_left=y[n/2-1];
    int ans_right=y[n/2];
    rep(i,n){
        int rid=x[i];
        if(rid>=ans_right) cout << ans_left <<endl;
        else cout << ans_right <<endl;
    }
    return 0;
}



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


using namespace std;

int main() {

	int n;
	cin >> n;

	int s[4][14] = {};
	char cc;
	int nn;

	for (int i = 0; i < n; i++) {
		cin >> cc >> nn;
		if (cc == 'S') { s[0][nn]++; }
		if (cc == 'H') { s[1][nn]++; }
		if (cc == 'C') { s[2][nn]++; }
		if (cc == 'D') { s[3][nn]++; }
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 1; j <= 13; j++) {
			if (s[i][j] == 0) {
				switch (i){
				case 0:
					cout << "S ";
					break;
				case 1:
					cout << "H ";
					break;
				case 2:
					cout << "C ";
					break;
				case 3:
					cout << "D ";
					break;
				}
				cout << j << endl;
			}
		}
	}

}


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

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

using namespace std;

class disjoint_set {
private:
    std::vector<size_t> parents;
    std::vector<size_t> ranks;
    std::vector<size_t> component_sizes;
public:
    const size_t n_vertices;
    size_t n_components;

    disjoint_set(size_t n_vertices) : n_vertices(n_vertices), parents(n_vertices), ranks(n_vertices, 0), n_components(n_vertices), component_sizes(n_vertices, 1) {
        for (size_t i = 0; i < n_vertices; ++i) {
            parents[i] = i;
        }
    }

    size_t root(size_t x) {
        if (parents[x] == x) {
            return x;
        } else {
            return parents[x] = root(parents[x]);
        }
    }

    void merge(size_t x, size_t y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (ranks[x] < ranks[y]) {
            parents[x] = y;
            component_sizes[y] += component_sizes[x];
        } else {
            parents[y] = x;
            component_sizes[x] += component_sizes[y];
            if (ranks[x] == ranks[y]) {
                ++ranks[x];
            }
        }
        --n_components;
    }

    bool is_same(size_t x, size_t y) {
        return root(x) == root(y);
    }

    size_t component_size(size_t x) {
        return component_sizes[root(x)];
    }
};

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

    int N, M, K;
    cin >> N >> M >> K;
    vector<int> n_friends(N);
    vector<vector<int>> blocks(N);
    disjoint_set ds(N);
    REP(i, M) {
        int A, B;
        cin >> A >> B;
        --A; --B;
        ++n_friends[A];
        ++n_friends[B];
        ds.merge(A, B);
    }
    REP(i, K) {
        int C, D;
        cin >> C >> D;
        --C; --D;
        blocks[C].push_back(D);
        blocks[D].push_back(C);
    }

    REP(i, N) {
        int result = ds.component_size(i) - 1 - n_friends[i];
        for (int j: blocks[i]) {
            if (ds.is_same(i, j)) {
                --result;
            }
        }
        cout << result << ' ';
    }
    cout << endl;


    return 0;
}


Measured memory_bytes: 8704