akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")


//最大公約数
long long gcd(long long a, long long b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

unordered_map<int, vector<ll>> fmp;

void fact(int n, unordered_map<int,int>& dst, unordered_map<int,int>& gdst) {
	for (int i = 2; i * i <= n; ++i) {
		int c = 0;
		while (n % i == 0) {
			++c;
			n /= i;
		}
		if (c > 0) {
			dst[i] = c;
			if (gdst.count(i) == 0) gdst.insert(pair<int, int>(i, c));
			else gdst[i] = max(c, gdst[i]);
		}
	}
	if (n > 1) {
		dst[n] = 1;
		if (gdst.count(n) == 0) gdst.insert(pair<int, int>(n, 1));
	}
}
ll mod = 1000000007;

ll po(ll x, ll n) {
	ll ans = 1;
	for (int i = 0; i < n; ++i)ans = ans * x % mod;
	return ans;
}

ll modpow(ll x, ll n) {
	ll ans = 1;
	ll tmp = x;
	ll f = n;
	while (f > 0) {
		if ((f&1) == 1) ans = ans * tmp % mod;
		tmp = tmp * tmp % mod;
		f >>= 1;
	}
	return ans;
}

ll calcB(unordered_map<int, int>& a, unordered_map<int, int>& g) {
	ll ans = 1;
	for (auto itr = g.begin(); itr != g.end(); ++itr) {
		ll x = itr->first;
		int n = itr->second;
		
		ans = ans * fmp[x][n - (a.count(x)==0 ? 0 : a[x])] % mod;
	}
	return ans;
}


//拡張ユークリッドの互除法。戻り値は最大公約数、x,yはax+by=gcd(a,b)を満たす組の一つ
long long gcdext(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long g = gcdext(b, a % b, y, x);
	y -= a / b * x;
	return g;
}

//モジュラ逆数
long long modinv(long long a, long long mod) {
	long long x, y;
	gcdext(a, mod, x, y);
	x = ((x % mod) + mod) % mod;
	return x;
}
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<unordered_map<int, int>> dst(N);
	unordered_map<int, int> gdst;
	REP(i, 0, N) {
		cin >> A[i];
		fact(A[i], dst[i], gdst);
	}
	ll lcm = 1;
	for (auto itr = gdst.begin(); itr != gdst.end(); ++itr) {
		for (int i = 0; i < itr->second; ++i) lcm = lcm * itr->first % mod;
	}
	ll ret = 0;
	REP(i, 0, N) ret = (ret + lcm * modinv(A[i], mod)) % mod;
	PRI(ret);
	return 0;
}




Measured memory_bytes: 5804
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s=sc.next();
        for(int i=0;i<s.length()-1;i++){
            if(s.charAt(i)==s.charAt(i+1)){
                System.out.println((i+1)+" "+(i+2));
                return;
            }
        }
        for(int i=0;i<s.length()-2;i++){
            if(s.charAt(i)==s.charAt(i+2)){
                System.out.println((i+1)+" "+(i+3));
                return;
            }
        }
        System.out.println("-1 -1");
    }
    
 
}

Measured memory_bytes: 24916
a, b, m = list(map(int, input().split()))
refs = list(map(int, input().split()))
mcws = list(map(int, input().split()))
coupons = [list(map(int, input().split())) for _ in range(m)]

ans = min(refs) + min(mcws)

for i in range(m):
	ans = min(ans, refs[coupons[i][0] - 1] + mcws[coupons[i][1] - 1] - coupons[i][2])

print(ans)

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

using namespace std;

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

  string judge;  
  if (a < b && b < c) {
    judge = "Yes";
  } else {
    judge = "No";
  }
  cout << judge << endl;

  return 0;
}



Measured memory_bytes: 3192
// C.

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<int> t(n);
	for (int i = 0; i < n - 1; ++i) {
		int c, s, f;
		cin >> c >> s >> f;
		for (int j = 0; j <= i; ++j) {
			int k = max(t[j], s);
			k += f - 1;
			k -= k % f;
			k += c;
			t[j] = k;
		}
	}
	for (int i = 0; i < n; ++i) {
		cout << t[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int a,b;
int main(){
	cin >> a >> b;
	if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;
	}else {
		cout << "Impossible" << endl;
	}
	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 < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

  if (a == c) cout << "0" << endl;
  else cout << "1" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <cstdlib>
using namespace std;
using ll = long long int;
int INF = 1e9+7;

int main() {
    int N,M;
    cin >> N >> M;
    int X[M];
    for (int i = 0; i < M; i++) {
        cin >> X[i];
    }

    if (M == 1 || N > M) {cout << 0 << endl; return 0;}
    sort(X,X+M);

    int LL[M-1];
    for (int i = 0; i < M-1; i++) {
        LL[i] = X[i+1]-X[i];
    }
    sort(LL,LL+M-1);
    reverse(LL,LL+M-1);
    int sum = X[M-1] - X[0];
    for (int i = 0; i < N-1; i++) {
        sum -= LL[i];
    }
    cout << sum << endl;
}


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

int main(){
    ll A,B,C,X;
    ll count = 0;
    cin >> A >> B >> C >> X;
    for(ll a=0;a<=A;a++){
        for(ll b=0;b<=B;b++){
            for(ll c=0;c<=C;c++){
                if((a*500+b*100+c*50) == X){
                    count++;
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second 
#define ll long long 
#define _for(i,j,k) for(int i=j;i<k;i++)
#define endl  '\n'
#define inf 1<<29-1 
const int mod=1e9+7;
const int MAX=1e5+5;
int a[MAX],b[MAX];
int main() 
{
 	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	int a,b,c;
 	cin>>a>>b>>c;
 	swap(a,b);
 	swap(a,c);
 	cout<<a<<" "<<b<<" "<<c;
	 
 	
 	
}

Measured memory_bytes: 256
from collections import deque
def runrun():
    count = 0
    while count <= k:
        run = quee.popleft()
        count += 1
        if count == k:
            print(run)
        last_digit = run%10
        if 0 < last_digit < 9:
            quee.extend([run * 10 + last_digit-1 , run * 10 + last_digit, run*10 + last_digit + 1])
        elif last_digit == 0:
            quee.extend([run * 10, run * 10 + 1])
        elif last_digit ==9:
            quee.extend([run*10 + 8, run*10 + 9])


k = int(input())
quee = deque([1,2,3,4,5,6,7,8,9])
runrun()


Measured memory_bytes: 11976
// 10000*a+5000*b+1000*(N-a-b) == Y となるかどうか.
#include<iostream>
using namespace std;
int main(){
  int N,Y; cin >> N >> Y;
  for(int i=0;i<=N;i++){
    for(int j=0;j<=N;j++){
      if(i+j > N) continue;
      if(10000*i+5000*j+1000*(N-i-j) == Y){
        cout << i << " " << j  << " " << N-i-j << endl;
        return 0;
      }
    }
  }
  
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
IDENTIFICATION  DIVISION.
PROGRAM-ID.     HELLO.

 
DATA DIVISION.
	WORKING-STORAGE SECTION.
        01 X PIC S99.
      
PROCEDURE       DIVISION.
    ACCEPT X.
    
    IF X < 30 THEN 
      DISPLAY 'No'
    ELSE
      DISPLAY 'Yes'
    END-IF.
    
    STOP RUN.

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define CLR(a) memset(a, 0, sizeof(a))
#define DBG(x) cout<<(#x)<<"="<<x<<endl
#define FOR(i, a, b)  for(int i=(a); i<(b); i++)
#define REP(i, a, b)  for(int i=(a); i<=(b); i++)
#define DOWN(i, a, b) for(int i=(a); i>=(b); i--)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000009;
const int N= 3e5 +10;

int n;
char c;
int a[N];
int sum[N], sum2[N];
int ans;

int main() {
	cin>>n;
	REP(i, 1, n) {
		cin>>c;
		if (c=='W') a[i]=1;
		else a[i]=0;
	}
	REP(i, 1, n) {
		sum[i]=sum[i-1]+1-a[i];
	}
	DOWN(i, n, 1) {
		sum2[i]=sum2[i+1]+a[i];
	}
	REP(i, 1, n) {
		ans=max(ans, sum[i-1]+sum2[i+1]);
	}
	cout<<n-1-ans<<endl;
	//cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";
	return 0;
}

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

int cnt1,cnt2,cnt3;
int a[200000];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int flag=0;
    for(int i=1;i<=n;i++){
        if(a[i]%2==0&&a[i]%4!=0)
            flag=1;
        if(a[i]%4==0)
            cnt1++;
        if(a[i]%2==1)
            cnt2++;
    }
    if(cnt2+flag>cnt1+1)
        puts("No");
    else
        puts("Yes");
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

class DisjoinSet {
    public:
        vector<int> rank, p;
        DisjoinSet(){}
        DisjoinSet(int size){
            rank.resize(size,0);
            p.resize(size,0);
            for (int i=0;i<size;i++) makeSet(i);
        }
        
        void makeSet(int x){
            p[x]=x;
            rank[x]=0;
        }
        
        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        
        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }
        
        void link(int x, int y){
            if (rank[x] > rank[y]){
                p[y]=x;
            }else{
                p[x]=y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        
        int findSet(int x){
            if(x!=p[x]){
                p[x]=findSet(p[x]);
            }
            return p[x];
        }
};

int main(){
    int n, a, b, q;
    int t;
    
    cin >> n >> q;
    DisjoinSet ds= DisjoinSet(n);
    
    rep(i,q){
        cin >> t >> a >> b;
        if(t==0) ds.unite(a,b);
        else if(t==1){
            if(ds.same(a,b)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
    
    return 0;

}

Measured memory_bytes: 1276
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int N;
    long long l0,l1,l2;
    l0 = 2;
    l1 = 1;
    cin >> N;
    if(N == 1){
        cout << 1 << endl;
    }
    else{
        for(int i = 0; i < N-1; i++){
            l2 = l0+ l1;
            l0 = l1;
            l1 = l2;
        }
        cout << l2 << endl;
    }
}

Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 2000;
struct edge{
	int to;
	edge *nxt;
}edges[MAXN*2 + 5], *adj[MAXN + 5], *ecnt = &edges[0];
void addedge(int u, int v) {
	edge *p = (++ecnt);
	p->to = v, p->nxt = adj[u], adj[u] = p;
	p = (++ecnt);
	p->to = u, p->nxt = adj[v], adj[v] = p;
}
queue<int>que;
int dis[MAXN + 5], vis[MAXN + 5], N, K;
int solve() {
	int ret = 0;
	while( !que.empty() ) {
		int f = que.front(); que.pop();
		if( dis[f] > K/2 ) ret++;
		for(edge *p=adj[f];p!=NULL;p=p->nxt) {
			if( !vis[p->to] ) {
				vis[p->to] = true;
				dis[p->to] = dis[f] + 1;
				que.push(p->to);
			}
		}
	}
	return ret;
}
int main() {
	scanf("%d%d", &N, &K);
	for(int i=1;i<N;i++) {
		int A, B;
		scanf("%d%d", &A, &B);
		addedge(A, B);
	}
	int ans = MAXN + 5;
	if( K % 2 == 0 ) {
		for(int i=1;i<=N;i++) {
			for(int j=1;j<=N;j++) {
				vis[j] = false;
				dis[j] = 0;
			}
			vis[i] = true; que.push(i);
			ans = min(ans, solve());
		}
	}
	else {
		for(int i=1;i<=N;i++) {
			for(edge *p=adj[i];p!=NULL;p=p->nxt) {
				if( i > p->to ) continue;
				for(int j=1;j<=N;j++) {
					vis[j] = false;
					dis[j] = 0;
				}
				vis[i] = true; que.push(i);
				vis[p->to] = true; que.push(p->to);
				ans = min(ans, solve());
			}
		}
	}
	printf("%d\n", ans);
}

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

int bubbleSort(int a[], int n) {
  int flag = 1;
  int counter = 0;
  while (flag) {
    flag = 0;
    for (int j = n-1; j > 0; j--) {
      if (a[j] < a[j-1]) {
        int tmp = a[j];
        a[j] = a[j-1];
        a[j-1] = tmp;
        counter++;
        flag = 1;
      }
    }
  }
  return counter;
}


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

  int counter = bubbleSort(a, n);
  for (int i = 0; i < n; i++) {
    if (0 < i) cout << " ";
    cout << a[i];
  }
  cout << endl;
  cout << counter << endl;
}



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

llong N;
llong cnt;

void rec(llong num, int use) {
	if (num > N) return;
	if (use == 0b111) cnt++;

	rec(num * 10 + 3, use | 0b001);
	rec(num * 10 + 5, use | 0b010);
	rec(num * 10 + 7, use | 0b100);
	return;
}

int main(void) {
	cin >> N;
	rec(0, 0);
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {
    const lines = input.split('\n')
    const [H, W] = lines[0].split(' ').map(Number)
    const C = lines[1].split(' ').map(Number)
    const D = lines[2].split(' ').map(Number)

    const map = []
    for (let i = 0; i < H; i++) {
        map[i] = lines[i + 3].split('')
    }

    const wall = '#'

    const f = (h, w, score) => {
        let p = null
        if (map[h] && map[h][w]) {
            p = map[h][w]
        }
        if (p && p !== wall && dp[h][w] > score) {
            dp[h][w] = score
            return true
        } else {
            return false
        }
    }

    const dp = Array(H).fill().map(_ => Array(W).fill(Infinity))
    const stack = []
    let score = 0
    dp[C[0] - 1][C[1] - 1] = score
    let i = [C[0] - 1, C[1] - 1]
    stack.push(i)
do {
    let stamp = []
    while (i = stack.shift()) {
        stamp.push(i)
        score = dp[i[0]][i[1]]
        const walk = [
            [i[0] + 1, i[1]],
            [i[0] - 1, i[1]],
            [i[0], i[1] + 1],
            [i[0], i[1] - 1]
        ]
        let n =null
        while (n = walk.pop()) {
            if (f(n[0], n[1], score)) {
                stack.push([n[0], n[1]])
            }
        }
    }
    score++
    while (i = stamp.pop()) {
        const warp = [
            [i[0] + 2, i[1] + 2],
            [i[0] + 2, i[1] + 1],
            [i[0] + 2, i[1]],
            [i[0] + 2, i[1] - 1],
            [i[0] + 2, i[1] - 2],
            [i[0] + 1, i[1] + 2],
            [i[0] + 1, i[1] + 1],
            [i[0] + 1, i[1] - 1],
            [i[0] + 1, i[1] - 2],
            [i[0], i[1] + 2],
            [i[0], i[1] - 2],
            [i[0] - 1, i[1] + 2],
            [i[0] - 1, i[1] + 1],
            [i[0] - 1, i[1] - 1],
            [i[0] - 1, i[1] - 2],
            [i[0] - 2, i[1] + 2],
            [i[0] - 2, i[1] + 1],
            [i[0] - 2, i[1]],
            [i[0] - 2, i[1] - 1],
            [i[0] - 2, i[1] - 2]
        ]
        let n = null
        while (n = warp.pop()) {
            if (f(n[0], n[1], score)) {
                stack.push([n[0], n[1]])
            }
        }
    }
} while (stack.length)

    const ans = dp[D[0] - 1][D[1] - 1]
    console.log(ans === Infinity ? -1 : ans)

})(input)


Measured memory_bytes: 89332
import sys
def input():
    return sys.stdin.readline()[:-1]

n=int(input())
s=input()
tmp=["SS","WW","SW","WS"]
for j in range(4):
    ans=tmp[j]
    for i in range(n-1):
        if ans[i+1]=="S":
            if s[i+1]=="o":
                if ans[i]=="S":
                    ans+="S"
                else:
                    ans+="W"
            else:
                if ans[i]=="S":
                    ans+="W"
                else:
                    ans+="S"
        else:
            if s[i+1]=="o":
                if ans[i]=="S":
                    ans+="W"
                else:
                    ans+="S"
            else:
                if ans[i]=="S":
                    ans+="S"
                else:
                    ans+="W"
    if ans[0]==ans[-1]:
        if s[0]=="o":
            if ans[0]=="S" and ans[1]==ans[-2]:
                print(ans[:-1])
                quit()
            if ans[0]=="W" and ans[1]!=ans[-2]:
                print(ans[:-1])
                quit()
        else:
            if ans[0]=="S" and ans[1]!=ans[-2]:
                print(ans[:-1])
                quit()
            if ans[0]=="W" and ans[1]==ans[-2]:
                print(ans[:-1])
                quit()
print(-1)

Measured memory_bytes: 3572
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let T = read!(i64, i64; N);

    let mut U = T
        .iter()
        .cloned()
        .enumerate()
        .map(|(i, (a, b))| (a + b, a, b, i))
        .collect::<Vec<_>>();
    U.sort();
    U.reverse();

    let mut V = T
        .iter()
        .cloned()
        .enumerate()
        .map(|(i, (a, b))| (a + b, b, a, i))
        .collect::<Vec<_>>();
    V.sort();
    V.reverse();

    let mut done = vec![false; N];
    let mut ti = 0;
    let mut ai = 0;
    let mut turn = true;
    let mut score = 0_i64;
    while ti < N || ai < N {
        if turn {
            // takahashi
            while ti < N {
                let (_, a, b, i) = U[ti];
                ti += 1;
                if done[i] {
                    continue;
                }
                score += a;
                done[i] = true;
                debug!(("takahashi", i, a, score));
                break;
            }
        } else {
            // aoki
            while ai < N {
                let (_, b, a, i) = V[ai];
                ai += 1;
                if done[i] {
                    continue;
                }
                score -= b;
                done[i] = true;
                debug!(("aoki", i, b, score));
                break;
            }
        }
        turn = !turn;
    }

    println!("{}", score)
}


Measured memory_bytes: 18684
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=200000+10;
const int inf=0x3f3f3f40;

int n,a[N],w[N],cnt[N]; char s[N];

#define ls (o<<1)
#define rs (o<<1|1)
struct sgt {
	int maxv[N<<2];
	void pushup(int o) { maxv[o]=max(maxv[ls],maxv[rs]); }
	void modify(int o,int l,int r,int p,int w) {
		if (l==r) { maxv[o]=w; return; }
		int mid=(l+r)>>1;
		if (p<=mid) modify(ls,l,mid,p,w);
		else modify(rs,mid+1,r,p,w);
		pushup(o);
	}
	int query(int o,int l,int r,int ql,int qr) {
		if (ql<=l&&r<=qr) return maxv[o];
		int mid=(l+r)>>1,res=-inf;
		if (ql<=mid) res=max(res,query(ls,l,mid,ql,qr));
		if (qr>mid) res=max(res,query(rs,mid+1,r,ql,qr));
		return res;
	}
} odd,even;
#undef ls
#undef rs

bool check(int p,int w) {
	if (w<0) return 0;
	if (w&1) return odd.query(1,1,n,p,n)>=w;
	else return even.query(1,1,n,p,n)>=w;
}

int main() {
	n=read();
	for (int i=1;i<=n;++i) a[i]=read();
	for (int i=1,mx=0;i<=n;++i) {
		if (a[i]>mx) w[i]=2,mx=a[i];
		else w[i]=1;
	}
	memset(odd.maxv,0xc0,sizeof(odd.maxv));
	for (int i=n;i;--i) {
		int mxo=odd.query(1,1,n,a[i],n),mxe=even.query(1,1,n,a[i],n);
		if (w[i]&1) odd.modify(1,1,n,a[i],mxe+w[i]),even.modify(1,1,n,a[i],mxo+w[i]);
		else odd.modify(1,1,n,a[i],mxo+w[i]),even.modify(1,1,n,a[i],mxe+w[i]);
	}
	for (int i=n;i;--i) cnt[i]=cnt[i+1]+w[i]-1;
	int cx=0,cy=0,mxx=0,mxy=0;
	for (int i=1;i<=n;++i) {
		odd.modify(1,1,n,a[i],-inf),even.modify(1,1,n,a[i],0);
		if (check(mxy,cx+(a[i]>mxx)+cnt[i+1]-cy)
		  ||check(max(mxx,a[i]),cy+cnt[i+1]-cx-(a[i]>mxx)))
			s[i]='0',cx+=(a[i]>mxx),mxx=max(mxx,a[i]);
		else s[i]='1',cy+=(a[i]>mxy),mxy=max(mxy,a[i]);
	}
	if (cx!=cy) puts("-1");
	else for (int i=1;i<=n;++i) putchar(s[i]);
	return 0;
}

Measured memory_bytes: 11348
n,m=map(int,input().split(' '))
war=[tuple(map(int,input().split(' '))) for _ in range(m)]
war.sort(key=lambda x:x[1])
bridge=[0]*n
flag=0
for w in war:
    if not w[0]<=flag<w[1]:
        flag=w[1]-1
        bridge[flag]=1
print(sum(bridge))

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

#define EVEN "Even"
#define ODD "Odd"

int main()
{
	// 整数の入力
	int a,b;
	cin >> a >> b;

	if ( (a*b)%2 == 0 )
	{
		cout << EVEN << endl;
	}
	else
	{
		cout << ODD << endl;
	}

	return 0;
}

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

int main()
{
    int N;
    scanf("%d", &N);
    std::vector<int> A(3*N);
    for(int i = 0; i < 3*N; i++) {
	scanf("%d", &A[i]);
    }
    std::sort(A.begin(), A.end());
    std::reverse(A.begin(), A.end());
    long sum = 0;
    for(int i = 0; i < N; i++) {
	sum += A[2*i + 1];
    }
    std::cout << sum << std::endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define bug(x) do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define bugv(x) do{cerr<#x<<': "';\
for(auto&e: x)cerr<<e<<" ";cerr<<"\n";}while(0)

using namespace std;
using ll=long long;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
  int n,k; cin>>n>>k;
  vector<ll> T(n+1, 0);
  vector<ll> M(n+1, 1);
  ll MM = n * (1LL<<20);

  rep(i, 1, min(k-1,n)) {
    ll need = (k+(i-1)) / i;
    ll f = 1; while(f < need) f = f << 1;
    M[i] = n * f; T[i] = 1;
    while(M[i] != MM) { M[i]*=2; T[i]*=2;}
  }
  rep(i, k, n) T[i] = (1LL<<20);
  ll tt = 0; rep(i, 1, n) tt+= T[i];
  cout << setprecision(28) << (long double)(tt) / MM << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define re(n) for (int i = 0; i < (n); ++i)
#define rej(n) for (int j = 0; j < (n); ++j)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <pair <int, int>> vii;

const ld PI = acos((ld)-1);

int main() {
    #ifndef LOCALDEBUG
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #endif  // LOCALDEBUG
    int n, k;
    cin >> n >> k;
    vi h(n);
    re(n) cin >> h[i];
    int ans = 0;
    re(n) {
        if (h[i] >=k) ++ans;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
s = input()[::-1]

l5 = ["dream"[::-1], "erase"[::-1]]
l6 = ["eraser"[::-1]]
l7 = ["dreamer"[::-1]]

ans = "YES"

while len(s) > 4:
    if s[:5] in l5:
        s = s[5:]
    elif s[:6] in l6:
        s = s[6:]
    elif s[:7] in l7:
        s = s[7:]
    else:
        ans = "NO"
        break

print(ans)

Measured memory_bytes: 3188
#include <stdio.h>

int main (void)
{
	int w , h , x , y , r;
	scanf("%d %d %d %d %d" , &w , &h , &x , &y , &r);
	if(x + r <= w && x - r >= 0)
	{
		if(y + r <= h && y - r >= 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");	
		}
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2072
/*
* Welcome to my code!
*---------------------------------------------*
* author : lynmisakura(twitter : @andoreiji11)
*/

#include<bits/stdc++.h>

using namespace std;

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

///////////////////////////////////////////////////////////////////////
using TYPE = long long; // edit here!

TYPE minvalue = 0; // edit here!
const int MAX_N = 200020; // edit here!

int size_of_data;
TYPE dat[2 * MAX_N - 1];

void init(int n_,TYPE minvalue_ = 1LL << 55){
	
  size_of_data = 1;
  minvalue = minvalue_;
  
	while(size_of_data < n_) size_of_data *= 2;
	for(int i = 0;i < 2 * size_of_data - 1;i++) dat[i] = minvalue;
}

TYPE get_func(TYPE a,TYPE b){ // edit here!
	return a + b;
}

void update(int k,TYPE a){ // edit here!
	k += size_of_data - 1;
	dat[k] += a;
	while(k > 0){
		k = (k - 1) / 2;
		dat[k] = get_func(dat[2 * k + 1],dat[2 * k + 2]);
	}
}

// [a,b) , call as query(a,b,0,0,n) 
TYPE query(int a,int b,int k,int l,int r){
	if(r <= a || b <= l){
    return minvalue;
  }
  if(a <= l && r <= b){
    return dat[k];
  }
  else{
		TYPE vl = query(a,b,k * 2 + 1,l,(l + r)/2);
		TYPE vr = query(a,b,k * 2 + 2,(l + r)/2,r);
		return get_func(vl,vr);
	}
}
///////////////////////////////////////////////////////////////////////

int main(void){
  int n,q;cin>> n >> q;
  
  init(n , 0);
  
  rep(i,q){
    
    int com,x,y;cin >> com >> x >> y;
    if(com == 0){
      x--;
      update(x,y);  
    }else{
      x--,y--;
      cout << query(x,y + 1,0,0,size_of_data) << '\n';
    }
  }
  
  return 0;
}


Measured memory_bytes: 5140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ABC087a
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, a, b, c;

            // キーボードから数値を読み込む
            x = int.Parse(Console.ReadLine());
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());

            // 出力値を計算
            c = (x - a) % b;

            // 結果を表示
            Console.WriteLine(c);

            //Console.ReadKey();
        }
    }
}

Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {

    public static void main(final String... args) {
        final String mode = "c";

        if (mode.equals("a")) {
            A.solve();
        } else if (mode.equals("b")) {
            B.solve();
        } else if (mode.contentEquals("c")) {
            C.solve();
        }
    }
}

class C {

    static void solve() {
        final Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int k = sc.nextInt();
        final int q = sc.nextInt();
        final int[] a = new int[q];
        for (int i = 0; i < q; i++) {
            a[i] = sc.nextInt();
        }
        final int[] res = calc(n, k, q, a);
        for (final int p : res) {
            if (q - p < k) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }

    static int[] calc(final int n, final int k, final int q, final int[] correctors) {
        final int[] points = new int[n];
        for (final int col : correctors) {
            points[col - 1]++;
        }
        return points;
     }
}

class B {
    static void solve() {
    }
}

class A {
    static void solve() {
        final Scanner sc = new Scanner(System.in);
        final int r = sc.nextInt();
        final int res = calc(r);
        System.out.println(res);
    }

    static int calc(final int r) {
        return 3 * r * r;
    }
}

Measured memory_bytes: 58520
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;

template <class T> using V = vector<T>;

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

const long long INF = 1LL << 60;

using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;



#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define pb(a) push_back(a);



ll Sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}



const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


#define comuse Comuse()

ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll perm(int n,int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] % MOD) % MOD;
}


ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}


vll div(ll n){
  vll ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  SORT(ret);
  return (ret);
}

ll modpow(ll a,ll n,ll mod){
  ll ans=1;
  while(n>0){
    if(n&1){
      ans=ans*a%mod;
    }

    a=a*a%mod;
    
    n>>=1;
  }

  return ans;
}

void Solve();


const int MAX_N = 131072;
//segment tree 
int NN;
int seg[MAX_N*2-1];
void seguse(){
  for(int i=0;i<2*NN-1;i++){
    seg[i]=INT_MAX;
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
//segtreeの葉の先頭の添え字はn-1
void Solve(){
  //vll segtree(524287);
  //ll N=262144;
  st s;
    cin>>s;
  st t=s;
  REV(t);
  ll n=s.sz;
  ll ans=0;
  FOR(i,0,n){
    if(s[i]!=t[i]){
      ans++;
    }
  }
  cout<<ans/2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    int res=0;
    cin>>n;
    int d[n];
    for(int i=0;i<n;i++)cin>>d[i];
    sort(d,d+n,greater<int>());
    if(n>1){
        for(int i=0;i<n-1;i++){
        if(d[i]==d[i+1])res++;
    }
    }
    cout<<n-res<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <map>
#include <numeric>

using namespace std;

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

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

using ll = long long;
using ld = long double;
using ull = unsigned long long;

int N;
vector<vector<pair<int, int>>> A;
vector<int> T;

int check()  {
  int count = 0;
  rep(i, N) {
    if (T[i] == 0) continue;
    count++;
    for (auto p : A[i]) {
      int x = p.first;
      int y = p.second;
      if (T[x] != y) return 0;
    }
  }
  return count;
}

int solve(int n) {
  if (n == N) return check();

  int maxi = 0;
  T[n] = 1;
  maxi = max(maxi, solve(n + 1));
  T[n] = 0;
  maxi = max(maxi, solve(n + 1));
  return maxi;
}

int main(void) {
  cin >> N;
  A.resize(N);
  T.assign(N, 0);
  rep(i, N) {
    int a; cin >> a;
    rep(j, a) {
      int x, y; cin >> x >> y;
      x--;
      A[i].push_back(pair<int, int>(x, y));
    }
  }
  cout << solve(0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
typedef long long int lli;
void merge (long long int arr[], long long int l, long long int m, long long int r)
{
        long long int i, j, k, n1 = m - l + 1, n2 =  r - m, L[n1], R[n2];
        for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr[m + 1+ j];
        i = 0;j = 0;k = l;
        while (i < n1 && j < n2)
        {if (L[i] <= R[j]) arr[k++] = L[i++]; else arr[k++] = R[j++];}
        while (i < n1) arr[k++] = L[i++]; while (j < n2) arr[k++] = R[j++];
}
void mergesort (long long int arr[], long long int l, long long int r)
{
        if (l < r)
        {
                long long int m = l+(r-l)/2;
                mergesort(arr, l, m);
                mergesort(arr, m+1, r);
                merge(arr, l, m, r);
        }
}
int cmp (const void *a, const void *b)
{
        return *(long long int *)a - *(long long int *)b;
}

//qsort(arr,n,sizeof(long long int),cmp);
//mergesort(arr, 0, arr_size - 1);

int main ()
{
        char str[210000] ;
        scanf("%s", str);
	lli n,t=0;

	n=strlen(str);

	lli count=0;

	for (int i=0;i<n;i++)
	{
		if (str[i]=='A')
			t++;
		
		else if (str[i]=='B' && str[i+1]=='C')
		{
			count=count+t;
			i++;
		}

		else
			t=0;
	}
	
	printf("%lld\n",count);

        return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
 
 
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll n,k,c,i,j;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    vector<ll> l(k+1),r(k+1);
    ll pos = 1;
    for(i=0;i<n;i++)
    {
        if(s[i]=='o') {l[pos] = i;i+=c;pos++;}
        if(pos==k+1) break;
    }
    pos = k;
    for(i=n-1;i>=0;i--)
    {
        if(s[i]=='o') {r[pos] = i;i-=c;pos--;}
        if(pos == 0) break;
    }
    for(i=1;i<=k;i++) 
    {
        if(l[i]==r[i]) cout<<l[i]+1<<"\n";
    }
}

Measured memory_bytes: 5012
A = [list(map(int, input().split())) for _ in range(3)]
N=int(input())
b=[int(input()) for i in range(N)]


for i in range(N):
    for j in range(3):
        for k in range(3):
            if b[i]==A[j][k]:
                A[j][k]=0

if (A[0][0]==A[0][1]==A[0][2]) or (A[1][0]==A[1][1]==A[1][2]) or (A[2][0]==
   A[2][1]==A[2][2]) or (A[0][0]==A[1][0]==A[2][0]) or (A[0][1]==A[1][1]==
    A[2][1]) or (A[0][2]==A[1][2]==A[2][2]) or (A[0][0]==A[1][1]==A[2][2]
    ) or (A[0][2]==A[1][1]==A[2][0]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
//引用:http://drken1215.hatenablog.com/entry/2018/06/08/210000
#include <iostream>
using namespace std;

const int MAX = 2510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long f(int r, int c) {
    return COM(r + c, c);
}

signed main() {
    // 前処理
    COMinit();

    // 計算例
    //cout << COM(100000, 50000) << endl;
    
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    
    long long ans = 0;
    for (int c = c1 + 1; c <= c2 + 1; c++) {
        ans += f(r2, c);
        ans %= MOD;
    }
    
    for (int c = c1 + 1; c <= c2 + 1; c++) {
        ans += MOD - f(r1 - 1, c);
        ans %= MOD;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 59136
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int a[55556];
    fill(a, a + 55556, 0);

    for(int i = 2; i <= 55555; i++){
        if(a[i] == 0){
            a[i] = 1;
            for(int j = 2; i * j <= 55555; j++){
                a[i*j] = -1;
            }
        }
    }
    // for(int i = 0; i < 100; i++){
    //     if (a[i] == 1){
    //         printf("%d %d\n", a[i], i);
    //     }
    // }
    int count = 0;
    for(int i = 2; count < n; i++){
        if(a[i] == 1 && i % 5 == 1){
            printf("%d ", i);
            count++;
        }

    }
    puts("");
    
    
    
}

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

int main(){
	int cards[4][13]={0};
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
	char a;
	int b;
	cin>>a>>b;
	if(a=='S')cards[0][b-1]++;
	else if(a=='H')cards[1][b-1]++;
	else if(a=='C')cards[2][b-1]++;
	else if(a=='D')cards[3][b-1]++;
	}
	for(int i=0;i<4;i++){
		for(int j=0;j<13;j++){
			if(cards[i][j]==0){
				if(i==0)cout<<"S "<<j+1<<endl;
				if(i==1)cout<<"H "<<j+1<<endl;
				if(i==2)cout<<"C "<<j+1<<endl;
				if(i==3)cout<<"D "<<j+1<<endl;
				
				}
			
			}
		
		}
	
	
	
}


Measured memory_bytes: 3092
n,w=map(int,input().split())
w_sub,v_sub=map(int,input().split())
w0=w_sub
inf=10000000000
x=[[inf,v_sub],[inf],[inf],[inf]]
for i in range(n-1):
    w_sub,v_sub=map(int,input().split())
    z=w_sub-w0
    x[z].append(v_sub)
for i in range(4):
    x[i].sort(key=lambda x:-x)
    x[i][0]=0
    l_sub=len(x[i])
    for j in range(1,l_sub):
        x[i][j]+=x[i][j-1]

ma=0
l3=len(x[3])
l2=len(x[2])
l1=len(x[1])
l0=len(x[0])
for i in range(l3):
    for j in range(l2):
        d=w-i*(w0+3)-j*(w0+2)
        if d>=0:
            for k in range(l1):
                d=w-i*(w0+3)-j*(w0+2)-k*(w0+1)
                if d>=0:
                    ma=max(ma,x[3][i]+x[2][j]+x[1][k]+x[0][min(d//w0,l0-1)])
                else:
                    break
        else:
            break

print(ma)


Measured memory_bytes: 3192
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main()
{
    int N, X;
    cin >> N >> X;
    int m[N];
    REP(i, N) cin >> m[i];
    sort(m, m + N);
    int sum = accumulate(m, m + N, 0);
    cout << N + (X - sum) / m[0] << endl;
    return 0;
}

Measured memory_bytes: 256
//----->|try=0; while(!success) try++;|<------
//----->|Belief Yourself,Respect Yourself|<----
//----->|Be Proud Of Yourself,You're Doing Your best|<-----
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a)|(b))
#define XOR(a,b) ((a) ^ (b))
#define mp make_pair
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
template<typename T> T POW(T b,T p)          //Pow calculation
 {
    T r=1;
    while(p) {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
{
    T r=1;
    while(p) {
        if(p&1)r=(r*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return r;
}

//||--------------------------->||Main_Code_Start_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    LL a,b,c,arr[4];
    bool flag=false;
     for(int i=0;i<3;i++)
     {
         cin>>arr[i];
         if(!(arr[i]%2))
         flag=true;
     }
     sort(arr,arr+3);
     if(flag) cout<<"0"<<endl;
     else
     {

         LL mid=arr[0]*arr[1];
         LL ans=((arr[2]/2)+1)*mid-((arr[2]/2)*mid);
         cout<<ans<<endl;
     }

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,s,cnt;
int main() {
	
	cin>>N;
	
	for (int i = 1; i<=N; i++){
		cin>>s;
		
		if((s % 2 == 1) && (i % 2 == 1)){
			cnt++;
		}
	}
	
	cout<<cnt<<endl;
	return 0;
}

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

int main(){
    int count=0;
  	long i=100;
    long X;
  	cin >> X;
	
  	while(X>i){
    	i = i + i*0.01;
      	count++;
    }	
  
  	cout << count;
    
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(){

  int n,a[100000],m,b,result=0,i;

  cin>>n;
  for(i=0;i<n;i++) cin>>a[i];
  cin>>m;
  for(i=0;i<m;i++){
    cin>>b;
    if(b<a[0]||a[n-1]<b) continue;
    int l=0,r=n,m;
    while(r-l){
      m=(r+l)/2;
      if(b==a[m]){
	result++;
	break;
      } else if(b>a[m]) l=m+1;
      else r=m;
    }
  }
  cout<<result<<endl;
  return 0;
}



Measured memory_bytes: 3464
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S;
	int K;
	cin>>K>>S;
	if(S.size()<=K){
		
		cout<<S<<endl;
		
	}else{

		for(int i = 0; i < K; i++){
			cout<<S[i];
		}
		cout<<"..."<<endl;
	}
	
	
	
	
	
	
	
	
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std ;
typedef pair<int, int> P ;

int board[60][60] ;
int d[60][60] ;
queue<P> que ;
int pre = 0 ;
int H , W ;
const int INF = 100000000 ;
int dx[4] = {-1,1,0,0} , dy[4]= {0,0,-1,1} ;

int bfs() {
  int sx = 0 , sy = 0 ;
  int gx = H - 1 , gy = W - 1 ;
  que.push(P(sx,sy)) ;
  d[sx][sy] = 0 ;
  
  while(que.size()){
    P p = que.front() ; que.pop() ;
    if(p.first == gx && p.second == gy ) break ;
    
    for(int i = 0 ; i < 4 ; i++ ){
      int nx = p.first + dx[i] , ny = p.second + dy[i] ;
      if(nx >= 0 && ny >= 0 && nx < H && ny < W && d[nx][ny] == INF && board[nx][ny] == 0 ){
        d[nx][ny] = d[p.first][p.second] + 1 ;
        que.push(P(nx,ny)) ;
      }
    }
  }
  return d[gx][gy] ;
}

int main () {
  //入力
  cin >> H >> W ;
  for(int i = 0 ; i < H ; i++ ){
    for(int j = 0 ; j < W ; j++ ){
      char ch ;
      cin >> ch ;
      if(ch == '#') board[i][j] = 1 ;
      else {
        board[i][j] = 0 ;
        pre ++ ;
      }
    }
  }
  
  //演算
  for(int i = 0 ; i < H ; i++ )
    for(int j = 0 ; j < W ; j++ )
      d[i][j] = INF ;
  int ans = bfs() ;
  if(ans != INF )cout << pre - ( ans + 1 ) << endl ;
  else cout << -1 << endl ;
}


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

#define int long long
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 1e3+5;
		
signed main()
{
    flash
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n,m;
		cin>>n>>m;
		int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		--x1,--y1,--x2,--y2;
		char arr[1005][1005];
		int dist[n][m]; 
		for(int i=0;i<n;++i)
		{
			for(int j=0;j<m;++j)
			{
				cin>>arr[i][j];
				dist[i][j] = inf;
			}
		}
		int dx[] = {1,-1,0,0};
		int dy[] = {0,0,1,-1};
		deque<int> dqx,dqy;
		dqx.push_back(x1);
		dqy.push_back(y1);
		dist[x1][y1] = 0;
		//cout<<arr[2][2]<<"\n";
		auto check = [&](int ii,int jj)
		{
			if(ii<0 or jj<0 or ii>=n or jj>=m or arr[ii][jj]=='#')
			return false;
			return true;
		};
		while(!dqx.empty())
		{
			int x = dqx.front() , y = dqy.front();
			dqx.pop_front();
			dqy.pop_front();
			for(int i=0;i<4;++i)
			{
				int xx = x+dx[i] , yy = y+dy[i];
				if(!check(xx,yy))
				continue;
				if(dist[xx][yy]>dist[x][y])
				{
					dist[xx][yy] = dist[x][y];
					dqx.push_front(xx);
					dqy.push_front(yy);
				}
			}
			for(int i=x-2;i<=x+2;++i)
			{
				for(int j=y-2;j<=y+2;++j)
				{
					if(!check(i,j))
					continue;
					if(dist[i][j]>dist[x][y]+1)
					{
						dist[i][j] = dist[x][y]+1;
						dqx.push_back(i);
						dqy.push_back(j);
					}
				}
			}
		}
		if(dist[x2][y2]>1e9)
		cout<<-1;
		else
		cout<<dist[x2][y2];
					
    }
    return 0;
}


Measured memory_bytes: 12540
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<int> maxL(N), maxR(N);
  rep(i, N-1)
    maxL[i+1] = max(maxL[i], A[i]);
  maxR[N-1] = A[N-1];
  rep(i, N-1)
    maxR[N-2-i] = max(maxR[N-1-i], A[N-2-i]);
  rep(i, N)
    cout << max(maxL[i], maxR[i+1]) << endl;
  return 0;
}


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

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

#define PB push_back
#define pb push_back

#define MP make_pair
#define mp make_pair
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>

#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define in scanf
#define out printf
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())

#define in_i(vi, c) string s;stringstream ss;for(getline(cin, s), ss = stringstream(s); getline(ss, s, (c)); (vi).push_back(stoi(s)))
#define in_s(vs, c) string s;stringstream ss;for(getline(cin, s), ss = stringstream(s); getline(ss, s, (c)); (vs).push_back(s))

using namespace std;

int main() {
    int N;
    string r;
    getline(cin, r);
    N = stoi(r);

    VI vv;
    in_i(vv, ' ');


    double ave = (double)accumulate(vv.begin(), vv.end(), 0) / vv.size();

    int total0 = 0;
    int total1 = 0;
    int X = ceil(ave);
    int Y = floor(ave);
    for(int value : vv){
        total0 += (X - value) * (X - value);
        total1 += (Y - value) * (Y - value);
    }
    cout << min(total0, total1) << endl;
}


Measured memory_bytes: 384