akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>
#include <random>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int N, M;
VVI K;
VT<bool> visited;
VVI graph;

void dfs(int now) {
    visited[now] = true;
    FORE(e, graph[now]) {
        if (!visited[e]) {
            dfs(e);
        }
    }
    return;
}

int main(void) {
    scanf("%d%d", &N, &M);
    graph.resize(N + M);
    visited.resize(N + M, false);
    REP(i, N) {
        int K; scanf("%d", &K);
        REP(j, K) {
            int m; scanf("%d", &m);
            m--;
            graph[i].EB(N + m);
            graph[N + m].EB(i);
        }
    }
    dfs(0);
    //FORE(e, visited) cout << e << " ";cout << endl;
    REP(i, N) {
        if (!visited[i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 8440
#include "bits/stdc++.h" 
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rerep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
const ll INF = 10e9;
int main(){
    ll n,m,x;cin>>n>>m>>x;
    ll a[n][m];
    ll c[n];
    rep(i,0,n){
        cin>>c[i];
        rep(j,0,m)cin>>a[i][j];
    }
    ll ans=INF;
    rep(s,0,1<<n){
        ll cost=0;
        ll d[m];
        rep(i,0,m)d[i]=0;
        rep(i,0,n){
            if(s>>i&1){
                cost+=c[i];
                rep(j,0,m)d[j]+=a[i][j];
            }
        }
        bool flag=true;
        rep(i,0,m){
            if(d[i]<x)flag=false;
        }
        if(flag)ans=min(cost,ans);
    }
    if(ans==INF)cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int A = 0, B = 0 , pt;
  for(int i = 0 ; i < 4 ; i++ ) cin >> pt , A += pt;
  for(int j = 0 ; j < 4 ; j++ ) cin >> pt , B += pt;
  cout << max(A,B) << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

double s[1000];

int main()
{
	while (true)
	{
		int n;
		cin >> n;
		if (n == 0) break;

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

		double m = 0;
		for (int i = 0; i < n; i++) {
			m += s[i];
		}
		m /= (double)n;

		double sgm2 = 0;
		for (int i = 0; i < n; i++) {
			sgm2 += pow(s[i] - m, 2);
		}
		sgm2 /= (double)n;

		double sgm = sqrt(sgm2);

		printf("%.10lf\n", sgm);
	}
	
	return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

  bool COL[8];
  int ANS = 0;
  int ANY = 0;
  rep(i, 8) COL[i] = false;
  rep(i, N) {
    int a;
    cin >> a;
    int g = a / 400;
    if (g < 8) {
      if (COL[g] == false) ANS++;
      COL[g] = true;
    } else {
      ANY++;
    }
  }
  int minA = (ANS == 0) ? 1 : ANS;
  int maxA = ANS + ANY;
  cout << minA << " " << maxA << endl;
  return 0;
}


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

using namespace std;


void solve() {
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<int>> g(n);
    for (int _ = 1; _ < n; _++) {
        int x,y;
        cin >> x >> y;
        x--;y--;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }

    vector<int> dp(n), sd(n), sz(n);
    function<void(int,int)> dfs = [&](int u, int p){
        sz[u] = s[u]-'0';
        sd[u] = 0;
        int mx = 0, mi = 0;
        for (int v: g[u])if(v!=p){
            dfs(v, u);
            sz[u] += sz[v];
            sd[u] += (sd[v] += sz[v]);
            dp[v] += sz[v];
            if (mx < dp[v]) {
                mx = dp[v]; mi = sd[v];
            } else if (mx == dp[v]) {
                mi = min(mi, sd[v]);
            }
        }
        if (mx <= sd[u] - mi) dp[u] = sd[u]&1;
        else dp[u] = mx + mi - sd[u];
    };
    
    int res = 1<<28;
    for (int i = 0; i < n; i++) {
        dfs(i,-1);
        if (dp[i] == 0) {
            res = min(res, sd[i]/2);
        }
    }
    if (res == 1<<28) res = -1;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 640
N = int(input())
a = [0] * N
xy = [[]] * N
for i in range(N):
    a[i] = int(input())
    xy[i] = [list(map(int, input().split())) for _ in range(a[i])]
# print(xy)
ans = 0
for i in range(2 ** N):
    tf = [False] * N
    for j in range(N):
        if (i >> j) & 1:
            tf[j] = True
    flag = False
    for j in range(N):
        for k in xy[j]:
            # 正直者が嘘をついたことになれば矛盾している
            if tf[j] and k[1] != tf[k[0] - 1]:
                flag = True
                break
        if flag:
            break
    if flag:
        continue
    ans = max(ans, tf.count(True))
print(ans)


Measured memory_bytes: 9240
#include<iostream>
#include<cstring>
using namespace std;
int ans = 0, k, n, m;
char a[100][100];
bool vis[1000];
void dfs(int i, int flag, int sum) {
    if (i > n && flag) {i = 0, flag = 0;}
    if (i >= m  && !flag) {
        if (sum == k)  ans++;
        return;
    }
    if (sum < k) return;
    if (flag) {
        dfs(i+1, flag, sum);
        vis[i] = 1;
        int x = 0;
        for (int j = 0; j < m; j++) 
            if (a[i][j] == '#')  x++;
        dfs(i+1, flag, sum-x);
        vis[i] = 0;
    }
    else {
        dfs(i+1, flag, sum);
        int x = 0;
        for (int j = 1; j <= n; j++) {
            if (a[j][i] == '#' && !vis[j]) x++;
        }
        dfs(i+1, flag, sum-x);
    }
}
int main() {
    cin >> n >> m >> k;
    int sum = 0;;
    for (int i = 1; i <= n; i++) 
        cin >> a[i];
    for (int i = 1; i <= n; i++) 
        for (int j = 0; j < m; j++)
            if (a[i][j] == '#') sum++;
   // for (int i = 1; i <= n; i++) cout << a[i] << endl;   
    dfs(1, 1, sum);
    cout << ans <<'\n';
  //  system("pause");
}


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

int N, a[100000];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    int cnt[3] = {};
    for(int i = 0; i < N; i++){
        if(a[i] % 4 == 0){
            cnt[2]++;
        }else if(a[i] % 2 == 0){
            cnt[1]++;
        }else{
            cnt[0]++;
        }
    }
    int prev;
    if(cnt[0] > 0){
        prev = 0;
        cnt[0]--;
    }else{
        cout << "Yes" << endl;
        return 0;
    }
    for(int i = 1; i < N; i++){
        if(prev == 0){
            prev = 2;
        }else if(prev == 1){
            prev = 1;
        }else{
            prev = 0;
        }
        bool ok_flag = false;
        for(int j = prev; j <= 2; j++){
            if(cnt[j] > 0){
                cnt[j]--;
                prev = j;
                ok_flag = true;
                break;
            }
        }
        if(!ok_flag){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
flag = 0
# 計算
for i in range(1, 1001):
  if int(i * 0.08) == a and int(i * 0.1) == b: 
    flag = 1
    break

# 出力
if flag == 0:
  print(-1)
elif flag == 1:
  print(i)

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

int gcd(int m, int n){
    if(m<n){
        int temp = m;
        m = n;
        n = temp;
    }
    if(n==0) return m;
    return gcd(n,m%n);
}

int main(){
    int N,ans;
    cin >> N;
    vector<int> HP(N);
    for(int i=0; i<N; i++){
        cin >> HP[i];
    }
    ans=HP[0];
    for(int i=1;i<N; i++){
        ans = gcd(ans,HP[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

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

	if (n > m) {
		ll k = m;
		m = n;
		n = k;
	}

	if (n == 1 && m==1) {
		cout << 1 << endl;
		return 0;
	}

	if (n < 3) { 
		if (n == 1) {
			cout << m - 2 << endl;
			return 0;
		}

		if (n == 2) {
			cout << 0 << endl;
			return 0;
		}

	}

	cout << (n - 2 ) * (m - 2) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long ll;

int main() {
  ll inf = 1LL << 60;
  int N, K;
  cin >> N >> K;

  ll dp[100100];
  vector<ll> hs(100100, 0);
  ll h;
  for (int i = 0; i < N; ++i) {
    dp[i] = inf;
    cin >> h;
    hs[i] = h;
  }
  dp[0] = 0;
  for (int i = 0; i < N; ++i) {
    for (int y = 1; y <= K; ++y) {
      dp[i + y] = min(dp[i + y], dp[i] + abs(hs[i] - hs[i + y]));
    }
  }

  cout << dp[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 1792
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque

def sum_count(arr):
    mem = arr[:]
    while True:
        if len(mem) == 1:break
        tmp = []
        while True:
            if len(mem) == 1:
                tmp.append(mem[-1])
                mem = tmp[:]
                break
            if len(mem) == 0:
                mem = tmp[:]
                break
            x1, x2 = mem.pop(), mem.pop()
            tmp.append(int(x1) + int(x2))

    return int(mem[0])

def run():
    N = int(input())
    X = list(input())[::-1]
    lis_bf = []
    lis_af = []
    count1 = sum_count(X)
    sum_val_bf, sum_val_af = 0, 0
    if count1 <= 1:
        for i in range(N):
            tmp_af = 0
            if int(X[i]):
                tmp_af = pow(2, i, count1 + 1)
            lis_af.append(tmp_af)
            sum_val_af += tmp_af
            sum_val_af %= count1 + 1

        for i in list(range(N))[::-1]:
            ans = 0
            if X[i] == '1':
                print(0)
                continue
            else:
                next_val = (sum_val_af + pow(2, i, count1 + 1)) % (count1 + 1)
            # print(next_val)
            ans += 1
            # print(f'i : {i}, next_val : {next_val}')
            while True:
                if next_val == 0: break
                val = next_val
                count_n = sum_count(list(bin(val)[2:]))
                next_val = val % count_n
                ans += 1
                # print(f'next_val : {next_val}')
            print(ans)
        return None

    for i in range(N):
        tmp_bf, tmp_af = 0,0
        if int(X[i]):
            tmp_bf = pow(2, i , count1-1)
            tmp_af = pow(2, i, count1+1)
        lis_bf.append(tmp_bf)
        lis_af.append(tmp_af)
        sum_val_bf += tmp_bf
        sum_val_bf %= count1-1
        sum_val_af += tmp_af
        sum_val_af %= count1 + 1

    for i in list(range(N))[::-1]:
        ans = 0
        if X[i] == '1':
            next_val = (sum_val_bf - lis_bf[i]) % (count1-1)
        else:
            next_val = (sum_val_af + pow(2, i, count1+1)) % (count1+1)
        #print(next_val)
        ans += 1
        #print(f'i : {i}, next_val : {next_val}')
        while True:
            if next_val == 0:break
            val = next_val
            count_n = sum_count(list(bin(val)[2:]))
            next_val = val % count_n
            ans += 1
            #print(f'next_val : {next_val}')
        print(ans)


if __name__ == "__main__":
    run()


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int A,B; cin >> A>>B;
    cout << (A+B)%24 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define enter putchar('\n')
#define Mem(a, x) memset(a, x, sizeof(a))
using namespace std;

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

inline ll read() {
    ll x = 0;
    int f = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x = f ? -x : x;
}

inline void write(ll x) {
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[23];
    int l = 0;
    while (x != 0)s[l++] = x % 10 + 48, x /= 10;
    while (l)putchar(s[--l]);
}

template<class T, class U>
inline void checkMax(T &x, U y) { if (y > x) x = y; }

const int M = 1123456;// 2e5+5

int n;
vector<int> to[M];
int fa[M];
int inDg[M];
set<int> points;
int cnt = 0;

void dfs(int now) {
    cnt++;
    for (auto son:to[now]) {
        inDg[son]--;
        if (inDg[son] == 0) {
            dfs(son);
        }
    }
}

int dp[M];


int dfs2(int now) {
    if (dp[now] != -1)
        return dp[now];
    int tmp = 0;
    for (auto son:to[now]) {
        checkMax(tmp, dfs2(son) + 1);
    }
    return dp[now] = tmp;
}


void init() {
    Mem(dp, -1);
    n = read();
    for (int i = 1; i <= n; ++i) {
        int bf = 0;
        points.insert(0);
        for (int j = 1; j < n; ++j) {
            int tmp1 = read();
            int tmp2 = i;
            if (tmp1 > tmp2)swap(tmp1, tmp2);
            int tmp = tmp1 * 999+ tmp2;
            points.insert(tmp);
            fa[tmp] = bf;
            to[bf].emplace_back(tmp);
            inDg[tmp]++;
            bf = tmp;
        }
    }
    dfs(0);
    if (cnt < points.size()) {
        puts("-1");
        return;
    }
    write(dfs2(0)), enter;
}

int main() {

    init();
    return 0;
}

Measured memory_bytes: 78848
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())

li_w = [a1, b1, a2, b2, a3, b3]

result = [li_w.count(i) for i in range(1, 5)]
if result.count(2) == 2 and result.count(1) == 2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3060
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from itertools import combinations
N, K = map(int, input().split())
A = list(map(int, input().split()))
mn = 10**18
for B in combinations(range(1,N),K-1): # 一番左は固定
    mx = A[0] # 初期値は一番左の建物
    score = 0
    for n in range(1,N):
        if n in B: # 見えるようにすべき建物なら
            if A[n] <= mx: # 低ければ高くする
                mx += 1
                score += (mx - A[n])
            else: # 高さが十分なら何もしない。最大値を更新
                mx = A[n]
        else:
            mx = max(mx, A[n]) # 見えなくても良い建物なら、最大値を更新
    mn = min(mn, score)
print (mn)


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

typedef long long int ll;

int main()
{
    ll n, x, t;
    cin >> n >> x >> t;

    if(n % x == 0){
        cout  << (n / x) * t;
    }
    else{
        cout << (n / x + 1) * t;
    }

    return 0;
    
}


Measured memory_bytes: 3632
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 1e6 + 111;
        
using namespace std;          

int a, b, n;

void solve(){      
	cin >> n >> a >> b;

	int x = (n / (a + b));

	cout << x * a + min(n % (a + b), a);
}                              
      
main(){
    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
const double EPS = 1e-10;
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    string s,t; cin >> s >> t;
    int n = s.size();
    string k = t.substr(0,n);
    if(s == k) cout << "Yes" <<endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(void) {
   
   int N,M;
   
   scanf("%d%d",&N,&M);
   
   int *A = malloc(sizeof(int)*(M+1));
   
   int i;
   int *Check = malloc(sizeof(int)*(N+1));
   
   
   for (i = 1; i <= N; i++) {
      Check[i] = 0;
   }
   
   for (i = 1; i <= M; i++) {
      scanf("%d",&A[i]);
      Check[A[i]] = 1;
   }
  
   int *Ans = malloc(sizeof(int)*(N+1));
   
   if (Check[1] == 1) {
      Ans[1] = 0;
   }
   else {
      Ans[1] = 1;
   }
   
   if (Check[2] == 1) {
      Ans[2] = 0;
   }
   else {
      Ans[2] = Ans[1] + 1;
   }
   
   for (i = 3; i <= N; i++) {
      if (Check[i] == 1) {
         Ans[i] = 0;
      }
      else {
         Ans[i] = (Ans[i - 1] + Ans[i - 2])%1000000007;
      }
      
   }
   
   /*
   for (i = 1; i <= N; i++) {
      printf("%d-->%d\n",i,Ans[i]);
   }
    */
   
   printf("%d\n",Ans[N]);
   
   
   return 0;
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int n = 4;
	string s;
	rep(i, 0, n) {
		char x; cin >> x;
		s.pb(x);

	}
	sort(all(s));
	YES(s == "1479");

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0; i<n; ++i)
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> c(n), s(n), f(n), ans(n,0);
    
    rep(i,n-1){
        cin >> c[i] >> s[i] >> f[i];
        rep(j,i+1){
            ans[j] = max(ans[j], s[i]);
            if(ans[j] % f[i] != 0) ans[j] = (1 + ans[j] / f[i]) * f[i];
            ans[j] += c[i];
        }
    }
    rep(i,n) cout << ans[i] << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define o_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define int ll
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main(){
		ios_base::sync_with_stdio(0);cin.tie(0);
		int N;
		cin>>N;
		int tot=0;
		for(int i=2;i*i<=N;i++){
      int a=0;
      while(N%i==0){a++;N/=i;}
      for(int j=10;j>=0;j--){
        if(j*(j+1)/2<=a){
          tot+=j;
          break;
        }
      }
		}
		if(N>1)tot++;
		cout<<tot;
}

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

public class Main{

	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public String next(){
			try{
				while(st==null||!st.hasMoreElements()){
					st = new StringTokenizer(br.readLine());
				}
			}catch(Exception e){
				e.printStackTrace();
			}
			return st.nextToken();
	
		}
		public int nextInt(){
			return Integer.parseInt(next());
		}
		public long nextLong(){
			return Long.parseLong(next());
		}
		public double nextDouble(){
			return Double.parseDouble(next());
		}
		public String nextLine(){
			String s = "";
			try{
				s = br.readLine();
			}catch(Exception e){
				e.printStackTrace();
			}	
			return s;		
		}
	} 
	
	public static void main(String[] args){
		FastReader in = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int k = in.nextInt();
		int s = in.nextInt();
		int cnt=0;
		for(int i =0 ; i <=k ; i++){
			for(int j = 0; j <= k ;j++){
					if(s-i-j>=0&&s-i-j<=k)cnt++;
				
				
			}
		
		
		} 
		out.println(cnt);
		out.flush();
		out.close();  
	}

}






Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
const ll MOD=1000000007;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<int>A(N);
    bool flag=true;
    REP(i,N){
        cin>>A[i];
        if(A[i]>i){flag=false;}
    }
    if (flag==false){cout<<-1<<endl;exit(0);}
    ll sub=0;
    for(int i=N-1;i>=0;i--){
        if(i!=N-1){
            if(A[i+1]-A[i]==1){continue;}
            if(A[i+1]-A[i]>=2){cout<<-1<<endl;exit(0);}
        }
        sub+=A[i];
    }
    cout<<sub<<endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String w = scan.next();
		if (w.length() % 2 == 1) {
			System.out.println("No");
			return;
		}
		int a = 'a';
		int z = 'z';
		boolean flag = true;
		for (int i = a; i <= z; i++) {
			int count = 0;
			for (int j = 0; j < w.length(); j++) {
				if (w.charAt(j) == i) {
					count++;
				}
			}
			if (count % 2 == 1) {
				flag = false;
				break;
			}
		}
		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

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

int main() {
	int a,b,c,k,sum=0;
  	cin>>a>>b>>c>>k;
    if(k<=a)
    	sum+=k;
    else if(k>a && k<=a+b)
    	sum+=a;
    else sum+=a-(k-(a+b));
    cout<<sum;
	return 0;
}

Measured memory_bytes: 3548
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<pair<int, int>> vp;
	unordered_map<int, unordered_set<int>> um1;
	unordered_map<int, unordered_map<int, int>> um2;
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		vp.push_back(make_pair(a, b));
		um1[a].insert(b);
		um1[b].insert(a);
	}
	int m;
	cin >> m;
	unordered_map<int, unordered_map<int, unordered_set<int>>> um;
	for (int i = 1; i <= m; i++) {
		int a, b;
		cin >> a >> b;
		um2[a][b] = i;
		um2[b][a] = i;
		vector<int> v(n + 1, 0);
		v[a] = -1;
		vector<int> v1, v2;
		v1.push_back(a);
		while (v1.size() > 0) {
			v2.clear();
			for (auto node : v1) {
				if (node == b) {
					while (v[node] != -1) {
						um[v[node]][node].insert(i);
						um[node][v[node]].insert(i);
						node = v[node];
					}
					v2.clear();
					break;
				}
				else {
					for (auto next : um1[node]) {
						if (v[next] == 0) {
							v2.push_back(next);
							v[next] = node;
						}
					}
				}
			}
			v1 = v2;
		}
	}

	unordered_map<string, long long int> res1, res2;
	res1[string(m, '0')] = 1;
	for (int i = 0; i < n; i++) {
		// vp[i];
		res2 = res1;
		for (auto p : res1) {
			// <string, int>
			string s = p.first;
			for (auto index : um[vp[i].first][vp[i].second]) {
				s[index - 1] = max(s[index - 1], '1');
			}
			res2[s] += p.second;
		}
		res1 = res2;
	}
	cout << res1[string(m, '1')] / 2 << endl;
}









Measured memory_bytes: 180640
#include <bits/stdc++.h>
using namespace std;
#define ELEM(array)  (sizeof (array) / sizeof *(array))
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int main(){
    ll n,m,ans=0;
    cin>>n>>m;
    vector<pair<ll,ll>> dr(n);
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        dr[i]=make_pair(a,b);
    }
    sort(dr.begin(),dr.end());
    rep(i,n){
        if(m>dr[i].second){
            ans+=dr[i].first*dr[i].second;
            m-=dr[i].second;
        }
        else{
            ans+=dr[i].first*m;
            break;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = a[i];
        }
        HashMap<Integer, Integer> map = new HashMap<>();
        Arrays.sort(b);
        int cnt = 1;
        for (int i = 0; i < n; i++) {
            if(!map.containsKey(b[i])){
                map.put(b[i], cnt++);
            }
        }
        long ans = 0L;
        BIT bit = new BIT(n);
        for (int i = 0; i < n; i++) {
            ans += i - bit.sum(map.get(a[i]));
            bit.add(map.get(a[i]), 1);
        }
        System.out.println(ans);
        sc.close();

    }

}

class BIT {

    public int n;
    public long[] bit;

    public BIT(int n){
        this.n = n;
        bit = new long[n+1];
    }

    public long sum(int i){
        long s = 0L;
        while(0 < i){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    public void add(int i, int x){
        while(i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }

}



Measured memory_bytes: 103652
// this is a program which see the number of divisor of the variable c between a and b
#include <stdio.h>
int main()
{
    int a, b, c;
    int x = 0;
    scanf("%d %d %d", &a, &b, &c);
    for (int i = 1; i <= c; i++)
    {
        if (c % i == 0)
        {
            if (a <= i && i <= b)
            {
                x++;
            }
        }
    }
    printf("%d\n", x);
    return 0;
}


Measured memory_bytes: 2108
#include<iostream>
using namespace std;
int k,n,a[400000];
int main()
{
	cin>>k>>n;
	if(k%2==0)
	{
		cout<<k/2;
		for(int i=1;i<n;i++)cout<<' '<<k;
		cout<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)a[i]=(k+1)>>1;
	int len=n;
	for(int i=0;i<n/2;i++)
		if(a[len]==1)len--;
		else
		{
			a[len]--;
			while(len<n)a[++len]=k;
		}
	for(int i=1;i<=len;i++)cout<<a[i]<<' ';
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){
	

	int t = 1;
	// /cin >> t;
	while(t--){		
		int n;
		cin >> n;
		if(n >= 30){
			cout << "Yes\n";
		}
		else{
			cout << "No\n";
		}
	}
	return 0;
}

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

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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

mint choose(int n, int a)
{
    mint x = 1, y = 1;
    rep(i, a)
    {
        x *= n - i;
        y *= i + 1;
    }
    return x / y;
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    mint ans = mint(2).pow(n);
    ans -= 1;
    ans -= choose(n, a);
    ans -= choose(n, b);
    cout << ans.x << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    N = int(input())
    A = ["?"]*N
    pos = N//2
    left = 0
    right = N
    for i in range(20):
        pos = (left+right)//2
        if A[pos] == "?":
            print(pos)
            sys.stdout.flush()
            S = input()[0]
            if S == "V":
                return
            A[pos] = S
        if A[left] == "?":
            print(left)
            sys.stdout.flush()
            S = input()[0]
            if S == "V":
                return
            A[left] = S

        if (pos - left) % 2 == 0:
            if A[pos] == A[left]:
                left = pos
            else:
                right = pos
        else:
            if A[pos] != A[left]:
                left = pos
            else:
                right = pos


if __name__ == '__main__':
    main()


Measured memory_bytes: 4424
#include <iostream>
#include <set>
#include <cmath>
#include <tuple>
#include <vector>
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
	int a,b,c,d;
	std::cin >> a>>b>>c>>d;
	a = a > c ? a : c;
	b = b > d ? d : b;
	if(b-a<0) std::cout << 0 << std::endl;
	else std::cout << b-a << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <random>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
ll rand26() {
  random_device rnd;
  mt19937 mt(rnd());
  uniform_real_distribution<> rand(0, 25);
  return (ll)rand(mt);
}
int main()
{
  ll D; cin >> D;
  vector<ll> c(26);
  rep(i,26) cin >> c[i];
  vector<vector<ll>> s(D, vector<ll>(26));
  vector<ll> t(D);  
  rep(i,D) {
    ll smax = -1;
    rep(j,26) {
      cin >> s[i][j];
      if(smax <= s[i][j]) {
	smax = s[i][j];
	t[i] = j;
      }
    }
  }

  
  ll m = 26*365*120;
  vector<ll> d(m), q(m);
  rep(k,120) {
    rep(i,26) {
      rep(j,365) {
	d[k*26*365 + i*365 + j] = j;
	q[k*26*365 + i*365 + j] = i;
      }
    }
  }
  
  vector<set<ll>> st(26);
  rep(i,26) {
    st[i].insert(-1);
    st[i].insert(D);    
  }
  rep(i,D) {
    st[t[i]].insert(i);
  }

  ll res = 0;
  // ペナルティ
  vector<ll> pen(26, 0);
  rep(i,26) {
    auto it = st[i].begin();
    it++;
    while(it != st[i].end()) {
      auto it2 = it;
      it2--;
      ll x = *it - *it2 - 1;
      res -= x * (x + 1) / 2 * c[i];
      pen[i] += x * (x + 1) / 2 * c[i];
      it++;
    }
  }
  rep(i,D) {
    res += s[i][t[i]];
  }

  rep(i,m){
    ll oldres = res;
    ll old = t[d[i]];
    ll neww = q[i];
    set<ll> oldst1 = st[old];
    set<ll> oldst2 = st[neww];    
    ll oldpen1 = pen[old];
    ll oldpen2 = pen[neww];
    
    res += s[d[i]][neww] - s[d[i]][old];
    st[old].erase(d[i]);
    st[neww].insert(d[i]);    
    // old
    res += pen[old];
    pen[old] = 0;
    auto it = st[old].begin();
    it++;
    while(it != st[old].end()) {
      auto it2 = it;
      it2--;
      ll x = *it - *it2 - 1;
      res -= x * (x + 1) / 2 * c[old];
      pen[old] += x * (x + 1) / 2 * c[old];
      it++;
    }
    // new
    res += pen[neww];
    pen[neww] = 0;
    it = st[neww].begin();
    it++;
    while(it != st[neww].end()) {
      auto it2 = it;
      it2--;
      ll x = *it - *it2 - 1;
      res -= x * (x + 1) / 2 * c[neww];
      pen[neww] += x * (x + 1) / 2 * c[neww];
      it++;
    }

    if(oldres < res) {
      t[d[i]] = neww;
    }
    else {
      t[d[i]] = old;
      st[old] = oldst1;
      st[neww] = oldst2;
      pen[old] = oldpen1;
      pen[neww] = oldpen2;      
    }
  }

  rep(i,D) cout << t[i]+1 << "\n";
  
  return 0;
}


Measured memory_bytes: 21196
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	int n; cin>>n;
	string s; cin>>s;
	int siro=0,kuro=0;
	rep(i,0,n){
		if(s[i]=='.')siro++;
	}
	int ans=siro+kuro;
	rep(i,0,n){
		if(s[i]=='.')siro--;
		else kuro++;
		chmin(ans,kuro+siro);
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define MAX 10001
#define INF 2000000001
#define LGMAX 18
#define MOD 1000003
#define F first
#define S second
#define ll long long
#define pb push_back
using namespace std;

int main() {
    int n, r, g, b;
    cin >> r >> g >> b >> n;
    ll res = 0;
    for (int i = 0; i <= n / r + 1; ++i) {
        for (int j = 0; j <= n / g + 1; ++j) {
            if (i * r + j * g <= n && (n - i * r - j * g) % b == 0) res++;
        }
    }
    cout << res;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include<algorithm>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;i++)
using namespace std;
using ll = long long;
const ll inf = 1LL << 50;





int main()
{
	int N, W;
	cin >> N >> W;
	vector< vector<int> > data;

	rep(i, 0, N) {
		int v, w;
		cin >> v >> w;
		data.push_back({ v,w });
	}

	vector< vector<int> >dp(N+1,vector<int>(W+1,0));

	rep(i, 1, N + 1) {
		rep(j, 0, W + 1) {
			if (j - data[i - 1][1] >= 0) {
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - data[i - 1][1]] + data[i - 1][0]);
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	cout << dp[N][W] << endl;
	
	return 0;
}


Measured memory_bytes: 6832
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(e,array) for(const auto& e : array)
#define lower_index(v,a) (int)distance(v.begin(), lower_bound((v).begin(),(v).end(),a))
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
typedef long long ll;
const int inf = 1<<28;
const ll INF = 1LL<<57;
const ll MOD = 1e9+7;

int main(){ 
    ll N,W; cin >> N >> W;
    vector<ll> v(N), w(N);
    vector<vector<ll>> dp(N+1,vector<ll>(W+1,0));
    rep(i,N) cin >> v[i] >> w[i];
    rep(i,N)rep(j,W+1){
        chmax(dp[i+1][j],dp[i][j]);
        if (0<=j-w[i]) chmax(dp[i+1][j],dp[i][j-w[i]] + v[i]);
        if (0<j) chmax(dp[i+1][j],dp[i+1][j-1]);
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 10796
#include <iostream>
#include <cmath>
#include <map>

using namespace std;

int main() {
    unsigned long long n;
    cin >> n;

    double root_n = sqrt(n);
    map<int, int> factor;
    while (n % 2 == 0) {
        n /= 2;
        factor[2]++;
    }
    for (int i=3;i <= root_n; i++) {
        while (n % i == 0) {
            n /= i;
            factor[i]++;
        }
    }
    if (n > 1) {
        factor[n]++;
    }
    int cnt = 0;
    for (auto v: factor) {
        int k = v.second;
        for (int i=1;i<=k;i++) {
            if (k - i > i) {
                k -= i;
                cnt++;
                continue;
            } else {
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3724
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define int long long
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
const double EPS = 1e-6 ; 
signed main(){
    fastio
    int h , a ;
    cin >> h >> a ; 
    cout << (h + a - 1) / a << endl;
    return 0; 
}

Measured memory_bytes: 256
def get_first(even,even_max_ind,even_second_ind):
    even_max=0
    second=0
    for i in range(1,10**5+1):
        if(even[i]==0):
            continue
        if(even_max<even[i]):
            even_second_ind[0]=even_max_ind.pop()
            second=even[even_second_ind[0]]
            even_max_ind.clear()
            even_max_ind.append(i)
            even_max=even[i]
        elif(even_max==even[i]):
            even_max_ind.append(i)
        elif(second < even[i]):
            even_second_ind[0]=i
            second=even[even_second_ind[0]]


n=int(input())
e_max=0
o_max=0
even=[0]*(10**5+1)
odd=[0]*(10**5+1)
retu=list(map(int,input().split()))
for i in range(n):
    if(i%2==0):
        even[retu[i]]+=1
    else:
        odd[retu[i]]+=1

even_max_ind=[0]
even_second_ind=[0]
odd_max_ind=[0]
odd_second_ind=[0]

get_first(even,even_max_ind,even_second_ind)
get_first(odd,odd_max_ind,odd_second_ind)

if(len(even_max_ind)>=2 or len(odd_max_ind)>=2 or even_max_ind[0]!=odd_max_ind[0]):
    print(n-even[even_max_ind[0]] - odd[odd_max_ind[0]])
else:
    print(n-max([even[even_second_ind[0]] + odd[odd_max_ind[0]],even[even_max_ind[0]] + odd[odd_second_ind[0]]]))
    

Measured memory_bytes: 15520
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  int tt = 0;
  rep(i,n){
    cin >> a[i];
    tt ^= a[i];
  }
  for(int i = 0; i < n; i++){
    int o = a[i]^tt;
    cout << o << endl;
  }

  return 0;
}


Measured memory_bytes: 4028
use std::io::*;
use std::str::FromStr;
use std::cmp;
   
fn read<T: FromStr>() -> T {
	let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let a: u32 = read();
	let s: String = read();

	if a >= 3200 {
		println!("{}", s);
	} else {
		println!("red");
	}
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back

#define N 100010
#define MOD 1000000007

int n, m;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> m;
	int ans = n * m + n * (n - 1) / 2;
	// cout << ans << "\n";
	if(m >= 0)
	{
		ans -= (m);
	}
	else if(m < 0)
	{
		if(abs(m) > n - 1)
			ans -= (m + n - 1);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;

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

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))
#define POSITIVE_RANGE(n)	( n >= 0 ? n : 0)
//#define int long long int //dont forget to change int to signed

const int BIGINT = 1000000007;

int N;
int sa = 0, saa = 0;
int fz(int z) {
	return saa - 2 * sa * z + N * z * z;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		sa += a;
		saa += a*a;
	}

	int alpha = sa / N, beta = ROUNDUP(sa, N);
	int ans = fz(alpha);
	chmin<int>(ans, fz(beta));
	cout << ans << endl;
}


Measured memory_bytes: 256