akhauriyash/Code-Regression huggingface dataset:
const config = {
    input: '/dev/stdin',
    newline: '\n'
};

const line = require('fs').readFileSync(config.input, 'utf-8').split(config.newline);

const bs = (arr, n, start, end) => {
    start = start || 0;
    end = end || arr.length;

    if (arr.length === 0 || start > end) return false;
    const mid = Math.floor((start + end) / 2);
    if (n === arr[mid]) return true;
    if (n < arr[mid]) {
        return bs(arr, n, start, mid-1);
    } else {
        return bs(arr, n, mid+1, end);
    }
};

const solve = (arr1, arr2) => arr2.filter(x => bs(arr1, x)).length;

const data1 = line[1].split(' ').map(Number);
const data2 = line[3].split(' ').map(Number);

console.log(solve(data1, data2));



Measured memory_bytes: 33968
A,B=map(int,input().split())
N = 0
res = 0
def checkPali(n):
  # n = 100*a + 10*b +c
  c = n%10
  a = n//10000
  b = (n - 10000*a)//1000
  d = (n - c)/10
  e = d%10
  if a == c and b == e:
    return True
  else:
    return False
for i in range(B-A+1):
  N = A + i
  if checkPali(N):
    res+=1
print(res)

Measured memory_bytes: 9224
#include <iostream>
#include <vector>
#include <map>

using namespace std;

map<vector<int>, int> dp;
vector<vector<int>> data;

int rec(vector<int> win, int id) {
    if (win.size() == 1 && win[0] == 0) return 1;
    if (dp.count(win)) return dp[win];

    int n = win.size(), h = win.front();
    dp[win] = 0;

    for (int pat = 0; pat < (1 << (n - 1)); ++pat) {
        if (__builtin_popcount(pat) != h) continue;

        bool judge = true;
        for (int i = 0; i < n - 1; ++i) {
            int opp = id + i + 1;
            if (data[id][opp] >= 0 && ((pat >> i) & 1) != data[id][opp]) {
                judge = false;
            }
        }

        auto nwin = win;
        for (int i = 0; i < n - 1; ++i) {
            int opp = i + 1;
            nwin[opp] -= 1 - ((pat >> i) & 1);
            if (nwin[opp] < 0) judge = false;
        }

        nwin.erase(nwin.begin());
        if (judge) dp[win] += rec(nwin, id + 1);
    }

    return dp[win];
}

bool solve() {
    dp.clear();
    int N;
    cin >> N;
    if (N == 0) return false;
    data.assign(N, vector<int>(N, -1));

    int M;
    cin >> M;
    for (int i = 0; i < M; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        data[x][y] = 1;
        data[y][x] = 0;
    }


    vector<int> win(N, N / 2);
    cout << rec(win, 0) << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}



Measured memory_bytes: 3316
def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


def solve():
    A, B, K = get_next_ints()
    if K > B - A:
        for i in range(A, B + 1):
            print(i)
    else:
        ans = list(range(A, A + K))

        ans_b = list(range(B - K + 1, B + 1))
        for i in ans:
            print(i)
        for j in ans_b:
            if not j in (ans):
                print(j)
solve()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;

int main() {
	int n,k;
    cin >> n >> k;
    vector<long>list(n);
    for(int i=0; i<n; i++){
        cin >> list[i];
    }
    if (n <= k){
        cout << "0" << endl;
        return 0;
    } else {
        sort(list.begin(), list.end(), greater<int>());
        cout << accumulate(list.begin() + k, list.end(), 0L) << endl;
    }
}

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

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif

void solve() {
	rd1(string, t);
	for(int i = 0; i < t.size(); i++) {
	    if(t[i] == '?') {
	        t[i] = 'D';
	    }
	}
	
	cout << t << endl;
}

int main() {
	
	fastio;

// 	rd1(ll, t);
	ll t = 1;

    while(t--) {
        solve();
    }
    
	return 0;
}

Measured memory_bytes: 3784
//#define DEBUG 3

#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <regex>
#include <fstream>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
using namespace std;

void run() {
	string s; cin >> s;

	int a = -1, z = -1;
	REP(i, s.size()) {
		if (a == -1 && s[i] == 'A') a = i;
		else if (s[i] == 'Z') z = i;
	}

	cout << z - a + 1<< endl;
	
}

int main() {
#ifdef DEBUG
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
	for(int i = 0; i < DEBUG; i++) {
		cout << "cnt:" << i << " ------------" << endl;
		run();
	}
#else
	run();
#endif
	return 0;
}


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

const int MAX_N = 200005;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(MAX_N);

vector<int> to[MAX_N];

struct DP {
  mint dp;
  int t;
  DP(mint dp=1, int t=0):dp(dp),t(t) {}
  DP& operator+=(const DP& a) {
    dp *= a.dp;
    dp *= comb(t+a.t, t);
    t += a.t;
    return *this;
  }
  DP operator-(const DP& a) const {
    DP res(*this);
    res.t -= a.t;
    res.dp /= comb(res.t+a.t, res.t);
    res.dp /= a.dp;
    return res;
  }
  DP addRoot() const {
    DP res(*this);
    res.t++;
    return res;
  }
};

DP dp[MAX_N];

void dfs(int v, int p=-1) {
  for (int u : to[v]) {
    if (u == p) continue;
    dfs(u,v);
    dp[v] += dp[u].addRoot();
  }
}
void bfs(int v, int p=-1) {
  for (int u : to[v]) {
    if (u == p) continue;
    DP d = dp[v] - dp[u].addRoot();
    dp[u] += d.addRoot();
    bfs(u,v);
  }
}

int main() {
  int n;
  cin >> n;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  bfs(0);
  rep(i,n) {
    cout << dp[i].addRoot().dp << endl;
  }
  return 0;
}

Measured memory_bytes: 20224
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[30],b[28];
	for(int i=1;i<=30;i++){
		a[i-1]=i;
	}
	for(int i=0;i<28;i++){
		cin>>b[i];
	}
	sort(b,b+28);
	int c[2]={0},j=-1,k=-1;
	for(int i=0;i<28;i++){
		j++;
		if(a[i]!=b[j]){
			k++;
			c[k]=a[i];
			j--;
		}
		if(j==27){
			break;
		}
	}
	if(c[0]==0){
		c[0]=29;
	}
	if(c[1]==0){
		c[1]=30;
	}
	cout<<c[0]<<endl<<c[1]<<endl;
	return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


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


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}

int main() {
	int a[7]={1,3,5,7,8,10,12};
	int b[4]={4,6,9,11};
	int x,y;
	cin>>x>>y;
	int X,Y;
	REP(i,7){
		if(a[i]==x)X=1;
		if(a[i]==y)Y=1;
	};
	REP(i,4){
		if(b[i]==x)X=2;
		if(b[i]==y)Y=2;
	}
	if(x==2)X=3;
	if(y==2)Y=3;
	if(X==Y)cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 256
import sys
import heapq
import bisect

mod = 10**9+7
dd = ((-1,0),(1,0),(0,-1),(0,1))

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return((list(sys.stdin.readline()))[:-1])

def GCD(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def LCM(a,b):
    return a * b // GCD(a,b)

def main():
    s = input()
    if s == "Sunny":
        return "Cloudy"
    if s == "Cloudy":
        return "Rainy"
    if s == "Rainy":
        return "Sunny"

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 38384
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	string s;
	char c[52];
	rep(i,26)c[i]=(char)(i+'a');
	loop(i,26,52)c[i]=(char)(i-26+'A');
	while(cin>>n,n){
		int key[n];
		rep(i,n)cin>>key[i];
		cin>>s;
		rep(i,s.size()){
			rep(j,52){
				if(s[i]==c[j]){
					s[i]=c[(j-key[i%n]+52)%52];
					break;
				}
			}
		}
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
n = int(input())
imin = n // 4
flag = False
for i in range(imin, 3501):
    num = i * n
    den = 4 * i - n
    if den <= 0:
        continue
    jmin = num // den
    for j in range(jmin, 3501):
        num = i * j * n
        den = 4 * i * j - i * n - j * n
        if den > 0 and num % den == 0:
            k = num // den
            print("{} {} {}".format(i, j, k))
            flag = True
            break
    if flag:
        break


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

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> h(n);

    for(int i = n-1; i >= 0; i--){
        cin >> h[i];
    }

    int count = 0,max = 0;
    for(int i = 0; i < n-1; i++){
        if(h[i] > h[i+1])count = 0;
        else count++;
        if(max < count) max = count;
    }
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
   int p[25],o=0,n;
   scanf("%d",&n);
   for(int i=0;i<=n-1;i++){
       scanf("%d",&p[i]);
   }
   for(int i=1;i<=n-2;i++){
       if(p[i-1]-p[i]<=0 && p[i]-p[i+1]<=0){
           o++;
       }else if(p[i-1]-p[i]>=0 && p[i]-p[i+1]>=0){
           o++;
       }
       if(p[i-1]==p[i]&&p[i]==p[i+1]){
           o--;
       }
   }
   
   printf("%d",o);
}


Measured memory_bytes: 128
import fractions
N = int(input())
A = list(map(int, input().split()))

L = [0]
R = [0]

for i in range(N):
    L.append(fractions.gcd(L[i], A[i]))
    R.append(fractions.gcd(R[i], A[N - i - 1]))

ans = 0
for i in range(N):
    t = fractions.gcd(L[i], R[N - i - 1])
    ans = max(t, ans)

print(ans)

Measured memory_bytes: 16136
#include<iostream>
using namespace std;
void swap(int *x,int *y)
{
  int t=*x;
  *x=*y;
  *y=t;
}
int main()
{
  int a,b;
  cin>>a>>b;
  if(a>b)
    swap(&a,&b);
  string s="";
  for(int i=0;i<b;i++)
    s+=(a+'0');
  cout<<s;
  return 0;
}

Measured memory_bytes: 256
import numpy as np
import sys

input=sys.stdin.readline

n,m,q = list(map(int, input().split()))

lrs = [list(map(int, input().split())) for _ in range(m)]
pqs = [list(map(int, input().split())) for _ in range(q)]

train_array = np.zeros((n+1,n+1),dtype=int)

for lr in lrs:
    train_array[lr[0]][lr[1]] +=1


#print(train_array)

train_array_ruisekiwa = np.zeros((n+1,n+1), dtype = int)

for i in range(1, n+1):
    for j in range(1, n+1):
        train_array_ruisekiwa[i][j] = train_array[i][j] + train_array_ruisekiwa[i][j-1] + train_array_ruisekiwa[i-1][j] - train_array_ruisekiwa[i-1][j-1]

#print(train_array_ruisekiwa)

for pq in pqs:
    print(train_array_ruisekiwa[pq[1]][pq[1]] - train_array_ruisekiwa[pq[1]][pq[0]-1] - train_array_ruisekiwa[pq[0]-1][pq[1]] + train_array_ruisekiwa[pq[0]-1][pq[0]-1])



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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;

using namespace std;

int solve() {
	int y, m, d; cin >> y >> m >> d;
	int res = 0;
	auto f = [&]() {
		int D;
		if (y % 3 == 0 || m % 2 == 1) D = 20;
		else D = 19;
		if (d == D) {
			if (m == 10) y++, m = 1, d = 1;
			else m++, d = 1;
		} else {
			d++;
		}
		res++;
	};
	for (; y != 1000; f());
	return res;
}

signed main() {
	int n; cin >> n;
	while (n--) cout << solve() << endl;
}




Measured memory_bytes: 3064
public class Main{
 	public static void main(String args[]){
     int num = new java.util.Scanner(System.in).nextInt();
     String str = "NO";
     
     if(num == 3 || num == 5 || num == 7){
       str = "YES";
     }
      
     System.out.println(str);
      
    }
}

Measured memory_bytes: 23124
#include <algorithm>
#include <bitset>
#include <climits>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

int main() {
  ll S, W;
  cin >> S >> W;

  if (W >= S) {
    printf("unsafe");
  } else {
    printf("safe");
  }
}

Measured memory_bytes: 3712
/* 
chirag11032000
Chirag Thakur
*/

#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;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << (H - h) * (W - w) << "\n";
}

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

int H, W, K;

std::string grid[7];

int main() {
  std::cin >> H >> W >> K;
  for (int i = 0; i < H; ++i)
    std::cin >> grid[i];

  int ans = 0;
  for (int mask = 0; mask < (1 << (H+W)); ++mask) {
    int cnt = 0;
    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
        if ((1 << i) & mask)  continue;
        if ((1 << (j + H)) & mask)  continue;
        if (grid[i][j] == '#')
          cnt++;
      }
    }
    if (cnt == K)
      ans++;
  }

  std::cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;typedef string S;long long n,r,i,j;S s;map<pair<S,S>,long long> a;main(){cin>>n>>s;for(;i<1<<n;++i){S x,y;for(j=0;j<n;++j)(i>>j&1?x:y)+=s[j];a[{x,y}]++;}while(i--){S x,y;for(j=n-1;j>=0;--j)(i>>j&1?y:x)+=s[n+j];r+=a[{x,y}];}cout<<r;}

Measured memory_bytes: 91904
N = int(input())
S = input()
count = 0

# s = set()
# for i in range(N - 2):
#     for j in range(i + 1, N - 1):
#         for k in range(j + 1, N):
#             s.add(S[i] + S[j] + S[k])

# print(len(s))

def get_idx(array, val, tmp):
    for i in range(tmp + 1, len(array)):
        if val == array[i]:
            return i
    return -1

V = []
for i in range(1000):
    if i < 10: V.append("00" + str(i))
    elif i < 100: V.append("0" + str(i))
    else: V.append(str(i))

for v in V:
    tmp = -1
    flag = True
    for i in range(3):
        if v[i] in S:
            idx = get_idx(S, v[i], tmp)
            if idx != -1:
                tmp = idx
            else:
                flag = False
                break
        else:
            flag = False
            break
    if flag:
        count += 1

print(count)

Measured memory_bytes: 41964
#include <cstdio>
using namespace std;
int main(void){
    // Here your code !
    int a;
    int b;
    int c;
    scanf("%d %d %d", &a, &b, &c);
    if (a < b && b < c){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector < ll >
#define vvll vector < vll >
#define vld vector < ld >
#define pll pair < ll,ll >
#define ppll pair < ll, pll > 
#define pld pair < ld,ld > 
#define vpll vector < pll >
#define vpld vector < pld >
#define all(X) X.begin(),X.end()
#define rall(X) X.rbegin(),X.rend()
#define endl "\n"
#define sz(x) ((ll)((x).size()))
vll emptyVector;
const ll MAX = 2e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884197169399375105;

ll binaryExpo(ll x, ll n)
{
	if(n == 0)
		return 1;
	if(n % 2 == 0)
		return binaryExpo((x*x) % MOD, n/2);
	return (x*binaryExpo((x*x) % MOD, n/2)) % MOD;
}

ll gcd(ll a, ll b)
{
	if(b == 0)
		return a;
	return gcd(b, a % b);
}
/*-------------------------------------------		CODE STARTS FROM HERE		------------------------------------------*/

ll fun(ll z)
{
	return (z*(z + 1))/2;
}

void solve(void)
{
	string s;
	cin >> s;
	for(int i = 0; i < s.length(); i++)
	{
		if(s[i] == '?')
			cout << "D";
		else
			cout << s[i];
	}
	cout << endl;



}

int main(void)
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);


	// int t;
	// cin >> t;
	// while(t--)
	{
		solve();
	}


	return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int H, W, D; cin >> H >> W >> D;

    vector<pair<ll, ll>> fi(H*W+5);
    for(ll i=1; i<=H; i++){
        for(ll j=1; j<=W; j++){
            int a; cin >> a;
            fi[a] = {i, j};
        }
    }

    ll cum[H*W+5];
    for(int i=1; i<=D; i++) cum[i] = 0;
    for(int i=D+1; i<=H*W; i++) cum[i] = cum[i-D] + abs(fi[i].first - fi[i-D].first) + abs(fi[i].second - fi[i-D].second);

    int Q; cin >> Q;
    vector<ll> ans(Q);
    for(int i=0; i<Q; i++){
        int l, r; cin >> l >> r;
        ans[i] = cum[r]-cum[l];
    }

    for(int i=0; i<Q; i++) cout << ans[i] << endl;
    
}

Measured memory_bytes: 3968
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;

int main(void)
{
    int n;
    cin >> n;

    map<int, int> mp;
    for (int i = 0; i < n; ++i)
    {
        int d;
        cin >> d;
        mp[d]++;
    }

    int m;
    cin >> m;

    vector<int> t(m);
    for (int i = 0; i < m; ++i)
    {
        cin >> t[i];
    }

    bool yes = true;
    for (int i = 0; i < m; ++i)
    {
        if (mp[t[i]] == 0)
        {
            yes = false;
            break;
        }

        mp[t[i]]--;
    }

    if (yes)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

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

using namespace std;

const int N = 1e5 + 2;

string s[N], type = " MARCH";
int pref[6][N], suff[6][N], n;
long long ans;

int main(){
      cin >> n;

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

      for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= 5; j ++){
                  if(type[j] == s[i][0])
                        pref[j][i] ++;
                  pref[j][i] += pref[j][i - 1];
            }
      }

      for(int i = n; i >= 1; i --){
            for(int j = 1; j <= 5; j ++){
                  if(type[j] == s[i][0]){
                        suff[j][i] ++;
                  }
                  suff[j][i] += suff[j][i + 1];
            }
      }

      for(int t = 1; t <= n; t ++){
            for(int i = 1; i <= 5; i ++){
                  if(s[t][0] == type[i]){
                        for(int j = 1; j <= 5; j ++){
                              for(int k = 1; k <= 5; k ++){
                                    if(i != j && i != k && j != k){
                                          ans += pref[j][t] * 1ll * suff[k][t];
                                    }
                              }
                        }
                  }
            }
      }

      cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

const int N = 200010;

int n, k; ll a[N];

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", a + i);
  }
  for (int i = 1, j = k; j < n; ++i, ++j) {
    puts(a[i] < a[j + 1] ? "Yes" : "No"); 
  }
  return 0;
}



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

#define ll long long 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int h,n;
	cin >> h >> n;
	int a[n];
	int s=0;
	for (int i=0; i<n; ++i) {
		cin >> a[i];
		s+=a[i];
	}
	cout << (s>=h?"Yes":"No");

}


Measured memory_bytes: 640
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29

def main():
    a,b = map(int,input().split())
    ans = []
    x = int(min(a//0.08,b//0.1))
    y = int(max((a+1)//0.08,(b+1)//0.1))
    for i in range(x,y+1):
        if int(i*0.08)==a and int(i*0.1)==b:
            ans.append(i)
    if len(ans):
        print(min(ans))
    else:
        print(-1)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38384
import sys
sys.setrecursionlimit(10**7)

N = int(input())
h = list(map(int, input().split()))

dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト
dp[N-1] = 0

def rec_memo(i):
    if dp[i] >= 0:
        return dp[i]
    
    if i == N-2:
        dp[i] = rec_memo(i+1) + abs(h[i+1] - h[i])
        return dp[i]
    else:
        dp[i] = min(rec_memo(i+1) + abs(h[i+1] - h[i]), rec_memo(i+2) + abs(h[i+2] - h[i]))
        return dp[i]

print(rec_memo(0))

Measured memory_bytes: 95492
let last_i = ref 0

let parent i = int_of_float (floor (float_of_int i) /. 2.)

let left i = 2*i

let right i = 2*i + 1

let swap i j t = let tmp = t.(i) in t.(i) <- t.(j); t.(j) <- tmp

let extract (t : int array) =
  let ret = t.(1) in
  t.(1) <- t.(!last_i);
  decr last_i;
  let rec max_heapify i =
    let l = left i in
    let r = right i in
    let m = if l <= !last_i && t.(l) > t.(i) then l else i in
    let m = if r <= !last_i && t.(r) > t.(m) then r else m in
    if i = m then ()
    else begin
      swap i m t;
      max_heapify m
    end in
  max_heapify 1;
  ret

let insert x (t : int array) =
  incr last_i;
  t.(!last_i) <- x;
  let rec doit i =
    if i <= 1 || t.(parent i) >= t.(i) then ()
    else begin
      swap i (parent i) t;
      doit (parent i)
    end in
  doit !last_i

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let t = Array.make 2000001 0 in
  while true do
    match read_line () |> split_on_char ' ' with
    | ["extract"] -> extract t |> Printf.printf "%d\n"
    | ["insert"; n] -> insert (int_of_string n) t
    | _ -> exit 0
  done

Measured memory_bytes: 20340
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  long long n, m, ans = 0; cin >> n >> m;
  if(2 * n <= m){
    ans = n + (m - 2 * n) / 4;
  }
  else{
    ans = m / 2;
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created 2017/06/01.
 */
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    int h = n / 3600;
    int m = (n % 3600) / 60;
    int s = n % 60;

    System.out.println(h + ":" + m + ":" + s);
  }
}

Measured memory_bytes: 26276
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const int MOD = 1e9 + 7;

vector<int> c[26], ansv;

signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.length(); i++) {
        c[s[i]-'a'].pb(i);
    }
    int prev = -1;
    for (int i = 0; i < t.length(); i++) {
        int ch = t[i] - 'a';
        int pos = upper_bound(c[ch].begin(), c[ch].end(), prev) - c[ch].begin();
        if (pos == c[ch].size()) {
            pos = upper_bound(c[ch].begin(), c[ch].end(), -1) - c[ch].begin();
        }
        if (pos == c[ch].size()) {
            cout << -1;
            return 0;
        }
        pos = c[ch][pos];
        ansv.pb(pos + 1);
        prev = pos;
    }
    int ans = ansv[0];
    for (int i = 1; i < ansv.size(); i++) {
        if (ansv[i] > ansv[i-1]) {
            ans += ansv[i] - ansv[i-1];
        }
        else {
            ans += s.length() - ansv[i-1] + ansv[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2884
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;

int main(){
    ll x, y; cin >> x >> y;

    int ans = 1;

    for(ll i = x; i <= y; ++i){
        int len = 1;

        ll pre = i;
        while(true){
            pre *= 2; 
            if(pre > y) break;
            len++;
        }

        if(ans >= len) break;
        ans = max(ans, len);
    }

    cout << ans << endl;
    return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

vll divisor(ll n) {
    vll ans;
    for (ll i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ans.push_back(i);
            if (i*i != n) ans.push_back(n/i);
        }
    }
    sort(all(ans));
    return ans;
}

bool c(ll n, ll k) {
    while(n >= k) {
        if (n%k==0) n /= k;
        else n %= k;
    }
    if (n==1) return true;
    return false;
}

int main() {
    ll n;
    cin >> n;

    ll ans = 0;
    vll d1 = divisor(n);
    vll d2 = divisor(n-1);
    set<ll> st;
    for (ll d : d1) st.insert(d);
    for (ll d : d2) st.insert(d);

    for (ll d : st) {
        if (d == 1) continue;
        if (c(n, d)) ans++;
    }

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

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int top=1,bottom=6,front=2,back=5,rig=3,lef=4;

void North(){
	int alt=top;
	top=front;
	front=bottom;
	bottom=back;
	back=alt;
}

void East(){
	int alt=top;
	top=lef;
	lef=bottom;
	bottom=rig;
	rig=alt;
}

void West(){
	int alt=top;
	top=rig;
	rig=bottom;
	bottom=lef;
	lef=alt;
}

void South(){
	int alt=top;
	top=back;
	back=bottom;
	bottom=front;
	front=alt;
}

void Right(){
	int alt=front;
	front=rig;
	rig=back;
	back=lef;
	lef=alt;
}
void Left(){
	int alt=front;
	front=lef;
	lef=back;
	back=rig;
	rig=alt;
}

int main(){
	int n;
	while(1){
		cin>>n;
		if(!n)break;
		top=1;
		bottom=6;
		front=2;
		back=5;
		rig=3;
		lef=4;
		int sum=1;
		rep(i,n){
			string s;
			cin>>s;
			if(s=="North")North();
			else if(s=="South")South();
			else if(s=="East")East();
			else if(s=="West")West();
			else if(s=="Right")Right();
			else Left();
			sum+=top;			
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

int main()
{
	LL a, b, c, d;
	cin >> a >> b >> c >> d;
	LL num1 = a * c;
	LL num2 = a * d;
	LL num3 = b * c;
	LL num4 = b * d;
	LL ans = max(num4, max(num3, max(num1, num2)));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
int main(){
	int n;
	cin>>n;
	map<string,int> mp;
	rep(i,n){
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		mp[s]++;
	}
	ll ans=0;
	for(auto& p:mp){
		int s=p.second;
		ans+=(ll)s*(s-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}	

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

int main() {
  int n, a_score = 0, b_score = 0;
  cin >> n;
  vector<int> a(n);
  rep(i, n)
    cin >> a.at(i);
  sort(a.begin(), a.end(), greater<int>());
  rep(i, n) {
    if (i % 2 == 0)
      a_score += a.at(i);
    else
      b_score += a.at(i);
  }
  cout << a_score - b_score << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int t;
   float x1,x2,x3,x4,y1,y2,y3,y4;
  cin >> t;
  while(t--){
cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
    if( (y2-y1)/(x2-x1) == (y4-y3)/(x4-x3) ) 
      cout<<"YES\n";
    else
      cout<<"NO\n";
  }
  
  return 0;
}



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

int main(){
  string S, T;
  cin >> S >> T;

  string tmp;
  char c;
  for (int i = 0; i < S.size(); i++)
  {
    if (S == T){
      cout << "Yes" << endl;
      return 0;
    }
    c = {S.at(S.size() - 1)};
    tmp = {c};
    S = tmp + S;
    S = S.substr(0, S.size() - 1);
  }

  cout << "No" << endl;
}

Measured memory_bytes: 3556
#include <stdio.h>

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


Measured memory_bytes: 2136
use std::io::*;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let a: i64 = itr.next().unwrap().parse().unwrap();
    let b: i64 = itr.next().unwrap().parse().unwrap();

    println!(
        "{}",
        if a <= 0 && 0 <= b {
            "Zero"
        } else if b < 0 && (b - a + 1) % 2 == 1 {
            "Negative"
        } else {
            "Positive"
        }
    );
}


Measured memory_bytes: 4352
#include<cstdio>

int main(){
	int a,b,c,x=0,y=0;
	while( scanf("%d,%d,%d",&a,&b,&c) != EOF ){
		if(a==b)x++;
		if(a*a+b*b==c*c)y++;
	}
		printf("%d\n%d\n",y,x);
	return 0;
}

Measured memory_bytes: 2712
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
int main(void)
{
    string str;
    cin>>str;
    str.resize(str.length() - 8);
    cout << str << '\n';
    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,w = map(int,readline().split())
WV = []
for i in range(n):
	WV.append(list(map(int,readline().split())))

dp = [[0]*(w+1) for _ in range(n+1)]

for i in range(n):
	for j in range(w+1):
		if WV[i][0]-j > 0:
			dp[i+1][j] = dp[i][j]
			continue
		dp[i+1][j] = max(dp[i][j],dp[i][j-WV[i][0]]+WV[i][1])

print(dp[-1][-1]) 


Measured memory_bytes: 120556
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int r2[1111111];
void init()
{
	r2[0] = 0;
	for (int t = 2; t < 1010101; t *= 2)
	{
		for (int j = t; j < 1010101; j += t)
		{
			r2[j]++;
		}
	}
	for (int i = 1; i < 1010101; i++)r2[i] += r2[i - 1];
}
int main()
{
	int num;
	string s;
	cin >> num >> s;
	for (int i = 0; i < num; i++)s[i]--;
	int s1 = 0, s2 = 0;
	int f = 0;
	init();
	//for (int i = 0; i < 10; i++)printf("%d ", r2[i]); printf("\n");
	for (int i = 0; i < num; i++)
	{
		int z = s[i] - '0';
		if (z == 1)f = 1;
		int t = r2[num - 1] - r2[i] - r2[num - 1 - i];
		//printf("%d %d\n", i, t);
		if (t == 0)
		{
			if (z == 1)s1 ^= 1;
			if (z == 2)s2 ^= 1;
		}
	}
	if (f)printf("%d\n", s1);
	else printf("%d\n", s2 * 2);
}

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

int gcd(int a,int b){
    if(a<b){
        int now=a;
        a=b;
        b=a;
    }

    int r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }

    return b;
}



/* 値を入れ替える関数 */
void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}




/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int n;
  scanf("%d",&n);
  int ans=100;
  int i;
  for(i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    int count=0;//aが2でなんかい割れるか

    while(a%2==0){
      a/=2;
      count++;
    }

    if(count<ans){
      ans=count;
    }
  }

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

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

int main() {
  int64_t N;
  string S;
  cin>>N>>S;
  vector<int> r={};
  vector<int> g={};
  for(int i=0;i<N;i++){
    if(S.at(i)=='R'){
      r.push_back(i);
    }
    else if(S.at(i)=='G'){
      g.push_back(i);
    }
  }
  int64_t A=r.size();
  int64_t B=g.size();
  int64_t Z=A*B*(N-A-B);
  for(int i=0;i<A;i++){
    for(int j=0;j<B;j++){
      int x=r.at(i),y=g.at(j);
      if((x+y)%2==0&&S.at((x+y)/2)=='B'){
        Z--;
      }
      if(2*x-y>=0&&2*x-y<N){
        if(S.at(2*x-y)=='B'){
          Z--;
        }
      }
      if(2*y-x>=0&&2*y-x<N){
        if(S.at(2*y-x)=='B'){
          Z--;
        }
      }
    }
  }
  cout<<Z<<endl;
}

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

using namespace std;

#define int long long int
#define REDBULL ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define endl "\n"

// bool isPerfectSquare(long double x) 
// {   
  
//   long double sr = sqrt(x);
//   return ((sr - floor(sr)) == 0); 
// } 
// bool isPrime(int n) 
// { 
//     // Corner case 
//     if (n <= 1) 
//         return false; 
  
//     // Check from 2 to n-1 
//     for (int i = 2; i < n; i++) 
//         if (n % i == 0) 
//             return false; 
  
//     return true; 
// } 
  
int32_t main()
{
	REDBULL
	int a,b;
	cin>>a>>b;
	if(a>9||b>9)
	{
		cout<<-1<<endl;
	}
	else
	{
		cout<<a*b<<endl;
	}

	
    return 0;
}

Measured memory_bytes: 256
import heapq
n = int(input())
p = list(map(int,input().split()))


ans = 1

l = [p[0]]

heapq.heapify(l)

for i in range(1,n):
    tmp = heapq.heappop(l)
    heapq.heappush(l,tmp)




    if p[i] < tmp:
        ans +=1

    heapq.heappush(l,p[i])

print(ans)


Measured memory_bytes: 24872
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N,d[123];

int main() {

	scanf("%d", &N);
	rep(i, N) scanf("%d", &d[i]);

	ll ans = 0;
	rep(i, N) {
		for (int j = i + 1; j < N; ++j) {
			ans += d[i] * d[j];
		}
	}


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

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

template<class T>
struct BellmanFord {
    const T INF = numeric_limits<T>::max() / 2 - 1;
    vector<vector<pair<int, T>>> edges;
    int vertex_number;
    bool iinc = false;
    vector<vector<bool>> reachable;
    
    BellmanFord(int n) : edges(n) {
        vertex_number = n;
    }
    
    void add_edge(int from, int to, T cost) {
        edges[from].emplace_back(to, cost);
    }
    
    vector<T> get_distance(int from, int to = -1) {
        vector<T> dist(vertex_number, INF);
        dist[from] = 0;
        for (int i = 0; i < vertex_number; i++) {
            for (int ii = 0, e = edges.size(); ii < e; ii++) {
                if ((to != -1) && (!is_reachable(from, ii))) continue;
                for (int iii = 0, ee = edges[ii].size(); iii < ee; iii++) {
                    if ((to != -1) && (!is_reachable(edges[ii][iii].first, to))) continue;
                    if ((dist[ii] + edges[ii][iii].second) < dist[edges[ii][iii].first]) {
                        if (i != (vertex_number - 1)) {
                            dist[edges[ii][iii].first] = dist[ii] + edges[ii][iii].second;
                        }
                        else {
                            iinc = true;
                            break;
                        }
                    }
                }
            }
        }
        return dist;
    }
    
    bool is_include_negative_circle() {
        return iinc;
    }
    
    void get_reachable_dfs(int from, int to) {
        if (reachable[from][to]) return;
        reachable[from][to] = true;
        for (pair<int, T> e : edges[to]) {
            get_reachable_dfs(from, e.first);
        }
    }
    
    void get_reachable() {
        for (int i = 0; i < reachable.size(); i++) {
            get_reachable_dfs(i, i);
        }
    }
    
    bool is_reachable(int from, int to) {
        if (reachable.size() == 0) {
            reachable.resize(vertex_number, vector<bool>(vertex_number, false));
            get_reachable();
        }
        return reachable[from][to];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m, p;
    cin >> n >> m >> p;
    BellmanFord<int> bf(n);
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--; c -= p;
        c = -1 * c;
        bf.add_edge(a, b, c);
    }
    vector<int> dist = bf.get_distance(0, n - 1);
    if (bf.is_include_negative_circle()) {
        cout << -1 << endl;
        return 0;
    }
    cout << max(-1 * dist[n - 1], 0) << endl;
    return 0;
}

Measured memory_bytes: 1408