akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 39999999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

struct edge{int to; ll cost;};
/*
edge es[MAX]; //辺

unsigned ll d[MAX]; //最短距離
int V, E; //Vは頂点数、Eは辺の数

//s番目の頂点から各頂点への最短距離を求める
void shortest_path(int s){
    rep(i, V)d[i] = INF;
    d[s] = 0;
    while(true){
        bool update = false;
        rep(i, E){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if(!update) break;
    }
}*/

vector<edge> G[MAX];
ll d[MAX]; //最短距離
int V, E; //Vは頂点数、Eは辺の数

void dfs(int now, int before, ll dd){
    d[now] = dd;
    for(auto i: G[now]){
        if(i.to != before) dfs(i.to, now, dd + i.cost);
    }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    V = n;
    int jj = 0;
    rep(i, n - 1){
        int a, b; ll c;
        cin >> a >> b >> c;
        a --;
        b --;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }
    E = 2 * n - 2;
    int q, k;
    cin >> q >> k;
    k --;
    dfs(k, -1, 0);
    rep(i, q){
        int x, y;
        cin >> x >> y;
        x --; y --;
        //cout << d[x] << endl;
        //cout << d[y] << endl;
        cout << d[x] + d[y] << endl;
    }
}

Measured memory_bytes: 25856
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define ul unsigned long long
#define si short int
#define P pair<si,si>
using namespace std;
const int N=2000;
int n,m,x,y,fa[N],ans;
vector<int>e[N];
struct bit{
	ul a[32];
	inline void filp(int x){a[x>>6]^=(ul)1<<(x&63);}
	inline void operator|=(const bit &b){fo(i,0,31)a[i]|=b.a[i];}
	inline void operator&=(const bit &b){fo(i,0,31)a[i]&=b.a[i];}
}e2[N][N],ex[N],nex[N],b;
P d[2000*1000];
void ins(int x,int y){
	d[ans++]=P(x,y);
	ex[x].filp(y);ex[y].filp(x);
	nex[x].filp(y);nex[y].filp(x);
}
void dfs(int x,int st){
	b.filp(x);
	int is=0;
	for(int i:e[x])if(i!=fa[x]){
		is=1;fa[i]=x;dfs(i,st);
		e2[st][x]|=e2[st][i];
	}
	if(!is)e2[st][x]=b;
	b.filp(x);
}
int main(){
	cin>>n>>m;
	fo(i,2,n)cin>>x>>y,--x,--y,e[x].push_back(y),e[y].push_back(x);
	fo(i,0,n-1)fo(j,0,n-1)nex[i].filp(j);
	fo(i,1,m)cin>>x>>y,--x,--y,ins(x,y);
	fo(i,0,n-1)
		for(int j:e[i])
			fa[j]=i,dfs(j,i);
	fo(i,0,n-1)fo(j,i+1,n-1)
		e2[i][j]|=e2[j][i],e2[i][j].filp(i),e2[i][j].filp(j);
	for(int j=0;j<ans;++j){
		int x=d[j].first,y=d[j].second;
		if(x>y)swap(x,y);
		b=e2[x][y];b&=ex[x];b&=nex[y];
		fo(i,0,31)if(b.a[i]){
			ul s=b.a[i];
			for(int j;s;s-=(ul)1<<j)
				j=__builtin_ctzll(s),ins(y,i<<6^j);
		}
		b=e2[x][y];b&=nex[x];b&=ex[y];
		fo(i,0,31)if(b.a[i]){
			ul s=b.a[i];
			for(int j;s;s-=(ul)1<<j)
				j=__builtin_ctzll(s),ins(x,i<<6^j);
		}
	}
	cout<<ans;
}

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

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

  int zero_count = 0;
  int one_count = 0;
  for (int i = 0; i < S.length(); i++) {
    if (S.at(i) == '0') {
      zero_count++;
    } else {
      one_count++;
    }
  }

  if (one_count == 0 || zero_count == 0) {
    printf("%d", 0);
  } else {
    printf("%d", 2 * min(zero_count, one_count));
  }
  return 0;
}


Measured memory_bytes: 512
import math


def comb(n, r):
    mf = math.factorial
    return mf(n) // (mf(n - r) * mf(r))


n, k = map(int, input().split())

ans = 0
for i in range(k, n + 2):
    l = (n + (n - 1 * (i - 1))) * i // 2
    a = (0 + (0 + 1 * (i - 1))) * i // 2 - 1
    ans += l - a

print(ans % (10**9 + 7))

Measured memory_bytes: 9208
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define re register
using namespace std;

inline 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=100000+10;

int n,L,Q;
int x[N],f[18][N];

int main() {
    n=read();
    for (re int i=1;i<=n;++i) x[i]=read();
    L=read();
    for (re int i=1;i<=n;++i) f[0][i]=upper_bound(x+1,x+n+1,x[i]+L)-x-1;
    for (re int i=1;i<=17;++i)
        for (re int j=1;j<=n;++j)
            f[i][j]=f[i-1][f[i-1][j]];
    Q=read();
    while (Q--) {
        int x=read(),y=read(),ans=0;
        if (x>y) swap(x,y);
        for (re int i=17;~i;--i)
            if (f[i][x]<y) ans|=(1<<i),x=f[i][x];
        printf("%d\n",ans+1);
    }
    return 0;
}


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

using namespace std;

double dp[301][301][301];

int main()
{
    int n;
    cin >> n;
    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        if (a == 1) cnt1++;
        if (a == 2) cnt2++;
        if (a == 3) cnt3++;
    }
    for (int i = 0; i <= n; i++){
        for (int j = 0; j + i <= n; j++){
            for (int k = 0; i + j + k <= n; k++){
                if (i == 0 && j == 0 && k == 0) continue;
                dp[k][j][i] = double(n) / double(i + j + k);
                double p1 = double(k) / double(i + j + k);
                double p2 = double(j) / double(i + j + k);
                double p3 = double(i) / double(i + j + k);
                if (k > 0) dp[k][j][i] += p1 * dp[k - 1][j][i];
                if (j > 0) dp[k][j][i] += p2 * dp[k + 1][j - 1][i];
                if (i > 0) dp[k][j][i] += p3 * dp[k][j + 1][i - 1];
            }
        }
    }
    cout << setprecision(10) << fixed << dp[cnt1][cnt2][cnt3];
    return 0;
}


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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)1e5 + 7;

int n;
struct node {
    int x,y;
}a[N],b[N];
int u[N];
int cnt,mt[N];
vector <int> g[N];

bool kuhn (int v) {
    if (u[v]) return false;
    u[v] = 1;

    for (auto to : g[v]) {
        if (mt[to] == -1 || kuhn(mt[to])) {
            mt[to] = v;
            return true;
        }
    }
    return false;
}
main () {
    cin >> n;

    for (int i = 1; i <= n; i ++)
        cin >> a[i].x >> a[i].y;

    for (int j = 1; j <= n; j ++)
        cin >> b[j].x >> b[j].y;

    for (int i = 1; i <= n; i ++) {
        for (int j = 1; j <= n; j ++) {
            if (a[i].x <= b[j].x && a[i].y <= b[j].y)
                g[i].pb(j);
        }
    }

    for (int i = 1; i <= n; i ++)
        mt[i] = -1;

    for (int i = 1; i <= n; i ++) {
        for (int j = 1; j <= n; j ++)
            u[j] = 0;
        kuhn(i);
    }
    for (int i = 1; i <= n; i ++)
        if (mt[i] != -1) {
            cnt ++;
        }
    cout << cnt << endl;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
bool is_prime(long long x){
    for(long long i=2;i*i<=x;i++){
        if(x%i==0)return false;
    }
    return true;
}
int main(){
    long long N;cin>>N;
    long long res=0;
    if(N==2) res=2;
    if(N%2==0) N+=1;
    
    while (res==0){
        if(is_prime(N)) res=N;
        N+=2;
    }
    cout<<res<<endl;
}

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

void solve(){
  int C, A, N, T = 0;

  cin >> C >> A >> N;

  for(; C > 0 && N > 0 && A > 0; T++ ){
    C--; N--; A--;
  }

  for(; C >= 2 && A > 0; T++ ){
    C-=2; A--;
  }

  for(; C >= 3; T++ ){
    C-=3;
  }

  cout << T << endl;
}

main(){
  int q;
  cin >> q;
  for ( int i = 0; i < q; i++ ) solve();
}

Measured memory_bytes: 1164
import numpy as np
from math import sqrt
from itertools import accumulate

L = [0 for _ in range(10**5)]
check = [1 for _ in range(10**5)]
check[0],check[1] = 0,0
for i in range(2,10**5):
  if check[i]:
    for j in range(i**2,10**5,i):
      check[j] = 0

for i in range(3,10**5,2):
  if check[i] == 1 and check[((i+1)//2)] == 1:
    L[i] = 1

Q = int(input())
lr = [list(map(int,input().split())) for _ in range(Q)]
ans = list(accumulate(L))
for l,r in lr:
  print(ans[r]-ans[l-1]) 

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

int main() {
  int n; cin >> n;
  vector<ll> v(100050);

  rep(i,n){
    int p; cin >>p;
    v[p]++;
  }

  /*rep(i,n+1){
    cout << i << " " << v[i] << endl;
  }*/

  int q; cin >> q;
  int b, c;
  ll ans=0;
  int diff;

  rep(i,100010){
    ans += v[i]*i;
  }

  //cout << ans << endl;

  rep(i,q){
    cin >> b >> c;
    diff = c-b;
    ans += v[b]*diff;
    v[c] += v[b];
    v[b] = 0;
    cout << ans << endl;
  }
}


Measured memory_bytes: 3968
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a==5 && b==7 && c==5){
    printf("YES\n");
  }else if(a==5 && b==5 && c==7){
    printf("YES\n");
  }else if(a==7 && b==5 && c==5){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>

#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define ALL(X)      (X).begin(),(X).end()
typedef long long LL;

using namespace std;

int main(void){
    int N;vector<int> A;
    cin>>N;
    REP(i,N){int a;cin>>a;A.pb(a);}
    int no=0;
    REP(i,N){no+=(A[i]%2);}
    // cout<<no<<endl;
    if(no%2==0){cout<<"YES"<<endl;}
    else{ cout<<"NO"<<endl;}

     return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long int lint;
int main(){
	int a,b;
	cin>>a>>b;
	a=a-b*2;
	a=(a<0)?0:a;
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int min = 10000000;
        for (int i = -100; i <= 100 ;i++ ) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                sum += Math.pow(a[j]-i, 2);
            }
            min = Math.min(min, sum);
        }
        System.out.println(min);

    }

}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

main() {
    int H,W,D; cin >> H >> W >> D;
    int score[100000];
    vector<pair<int,int>> p(100000);
    rep(i,H) rep(j,W) {
        int a; cin >> a;
        a--;
        p[a].first=i; p[a].second=j;
    }
    rep(i,D){
        for(int j=i;j<=H*W;j+=D){
            if(j==i) score[j]=0;
            else{
            score[j]=score[j-D]+abs(p[j].first-p[j-D].first)
            +abs(p[j].second-p[j-D].second);
            }
        }
    }
    int Q; cin >> Q;
    rep(i,Q){
        int L,R; cin >> L >> R;
        L--; R--;
        cout << score[R]-score[L] << endl;
    }
}


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

signed main(){
    int N,K,Q; cin>>N>>K>>Q;
    vector<int> cnt(N);
    for(int i=0;i<Q;i++){
        int a; cin>>a; a--;
        cnt[a]++;
    }
    for(int i=0;i<N;i++){
        if(K-(Q-cnt[i])<=0){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1408
/****************************************

	LostMartian

****************************************/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <numeric>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;
typedef long long ll;
#define rep(i,m,n) for(ll i=m; i<n; i++)
#define repr(i,m,n) for(ll i=m; i>=n; i--)
#define vll vector<ll >
#define vvl vector<vector<ll > >
#define pi pair<ll, ll >
#define pb push_back
#define mk make_pair
#define sz size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define d(x) cout<<"Value of "#x" = "<<x<<"\n";
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define LOCAL #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
long long a [100010];
int main()
{
	clock_t z = clock();
	FAST
	//LOCAL
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	int zero = 0;
	for (int i = 0; i < n; i++)if (a[i] == 0) zero ++;
	if (zero > 0) {
// a[i] contains 0
		printf("0\n");
		return 0;
	}
	long long prod = 1;
	for (int i = 0; i < n; i++) {
		if (a[i ] <= 1000000000000000000 / prod ) {
// This condition is equivalent to prod*a[i] <=10ˆ18
			prod *= a[i];
		} else {
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", prod );


	debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 4604
use std::collections::BinaryHeap;
use std::cmp;
use num::abs;
use proconio::input;

fn main() {
    input! {
        n : usize,
        a : [i64; n]
    };
    let mut qu = BinaryHeap::new();
    for i in 0..n {
        qu.push((a[i], i));
    }
    let mut dp = vec!(vec!(0; n+1); n+1);
    for i in 0..n {
        let (v, b) = qu.pop().unwrap();
        for j in 0..n {
            if j + n - i > n {
                break;
            }
            dp[j][j+n-i-1] = cmp::max(dp[j][j+n-i-1], dp[j][j+n-i] + v * abs((j+n-i-1) as i64 - b as i64));
            dp[j+1][j+n-i] = cmp::max(dp[j+1][j+n-i], dp[j][j+n-i] + v * abs(j as i64 - b as i64));
        }
    }
    let mut res = 0;
    for i in 0..=n {
        res = cmp::max(res, dp[i][i]);
    }
    println!("{}", res);
}


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

using namespace std;
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define ld long double
#define endl "\n"

ll gcd(ll x,ll y)
{
	if(y>x)
		swap(x,y);
	while(y!=0)
	{
		ll tmp=x;
		x=y;
		y=tmp%y;
	}
	return x;
}

int main()
{
	IOS;
	ll a,b;
	cin >>a>>b;
	ll c=a*b;
	ll d=gcd(a,b);
	// cout <<d<<' ';
	cout << (c/d) <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

vector<double> intersect(double x, double y, double r1, double r2){
	vector<double> res(4,inf);
	double a = x*x + y*y;
	double b = (a + r1*r1 - r2*r2) / 2.0;
	double c = a * r1*r1 - b*b;
	if(c < 0) return res;
	res[0] = (b*x + y*sqrt(c)) / a;
	res[1] = (b*y - x*sqrt(c)) / a;
	res[2] = (b*x - y*sqrt(c)) / a;
	res[3] = (b*y + x*sqrt(c)) / a;
	return res;
}

double dist(double x, double y){
	return sqrt(x*x + y*y);
}

int main(){
	int n,k; cin >> n >> k;
	vd x(n), y(n), c(n);
	rep(i,n) cin >> x[i] >> y[i] >> c[i];
	double ok = 1e6, ng = 0.0;
	rep(t,100){
		double mid = (ok+ng) / 2.0;
		vd r(n);
		rep(i,n) r[i] = mid / c[i];
		vector<pair<double,double>> p;
		rep(i,n){
			REP(j,i+1,n){
				vd ret = intersect(x[j]-x[i],y[j]-y[i],r[i],r[j]);
				if(ret[0] >= 1e9) continue;
				p.emplace_back(ret[0] + x[i], ret[1] + y[i]);
				p.emplace_back(ret[2] + x[i], ret[3] + y[i]);
			}
			p.emplace_back(x[i],y[i]);
		}
		bool f = false;
		for(auto v : p){
			int cnt = 0;
			rep(i,n){
				if(dist(x[i]-v.first, y[i]-v.second) <= r[i] + eps) cnt++;
			}
			if(cnt >= k) f = true;
		}
		if(f) ok = mid;
		else ng = mid;
	}
	printf("%.10f\n",ok);
}

Measured memory_bytes: 3920
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;
int main(void) {
  string s;
  char op[2]={'-', '+'};
  int a, b, c, d;
  int x, y, z;
  cin>>s;
  a=s[0]-'0';
  b=s[1]-'0';
  c=s[2]-'0';
  d=s[3]-'0';
  for(int i=0; i<2; i++) {
    for(int j=0; j<2; j++) {
      for(int k=0; k<2; k++) {
	if(i==0) x=-1*b;
	else x=b;
	if(j==0) y=-1*c;
	else y=c;
	if(k==0) z=-1*d;
	else z=d;
	if(a+x+y+z==7) {
	  cout<<s[0]<<op[i]<<s[1]<<op[j]<<s[2]<<op[k]<<s[3]<<"=7"<<endl;
	  return 0;
	}
      }
    }
  }
  return 0;
}


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

int main(){

  int N;
  int a;

  int cnt4=0,cnt2=0;

  cin>>N;
  
  for(int i=0;i<N;i++){
    cin>>a;

    if(a%4==0){
      cnt4++;
    }
    else if(a%2==0){
      cnt2++;
    }

  }

  //2の倍数*2の倍数＝4の倍数
  //4の倍数*「　」 ＝4の倍数

  
  if((cnt2/2)+cnt4>=N/2){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }   
  return 0;

}


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

long long rec(int n, long long x) {
    if (n == 0) return 1;
    long long len = (1LL<<(n+1)) - 3;
    long long num = (1LL<<n) - 1;
    if (x == 1) return 0;
    else if (x <= len + 1) return rec(n-1, x-1);
    else if (x == len + 2) return num + 1;
    else if (x <= (len + 1) * 2) return num + 1 + rec(n-1, x-len-2);
    else return num * 2 + 1;
}

int main() {
    int N; long long X;
    cin >> N >> X;
    cout << rec(N, X) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    int a=0,b=0,c=0;
    string s;
    cin>>s;
    for(auto x:s){
        if(x=='a') a++;
        if(x=='b') b++;
        if(x=='c') c++;
    }
    int m=min({a,b,c});
    a-=m;b-=m;c-=m;
    if(a<2&&b<2&&c<2){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}


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

int main(){
  int a,res;
  
  cin >> a;
  
  res = a + pow(a, 2.0) + pow(a, 3.0);

  
  cout << res << endl;
  

}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

ll n;
V<P<char, ll>> a(100000);
V<P<char, ll>> b(100000);

void merge(ll l, ll m, ll r) {
  ll n1 = m - l;
  ll n2 = r - m;
  V<P<char, ll>> lv(n1+1, P<char, ll>(' ', HIGHINF)), rv(n2+1, P<char, ll>(' ', HIGHINF));
  REP(i, n1) lv.at(i) = b.at(l + i);
  REP(i, n2) rv.at(i) = b.at(m + i);
  ll i = 0;
  ll j = 0;
  rep(k, l, r) {
    if (lv.at(i).second <= rv.at(j).second) b.at(k) = lv.at(i++);
    else b.at(k) = rv.at(j++);
  }
}

void mergeSort(ll l, ll r) {
  if (l+1 < r) {
    ll mid = (l + r) / 2;
    mergeSort(l, mid);
    mergeSort(mid, r);
    merge(l, mid, r);
  }
}

ll partition(ll l, ll r) {
  P<char, ll> x = a.at(r-1);
  ll i = l-1;
  rep(j, l, r-1) {
    if (a.at(j).second <= x.second) {
      i++;
      P<char, ll> tmp = a.at(i);
      a.at(i) = a.at(j);
      a.at(j) = tmp;
    }
  }
  P<char, ll> tmp = a.at(i+1);
  a.at(i+1) = a.at(r-1);
  a.at(r-1) = tmp;
  return i+1;
}

void quickSort(ll l, ll r) {
  if (l < r) {
    ll q = partition(l, r);
    quickSort(l, q);
    quickSort(q+1, r);
  }
}

int main() {
  cin >> n;
  REP(i, n) {
    cin >> a.at(i).first >> a.at(i).second;
    b.at(i) = a.at(i);
  }
  quickSort(0, n);
  mergeSort(0, n);
  bool is_stable = true;
  REP(i, n) {
    if (a.at(i) != b.at(i)) {
      is_stable = false;
      break;
    }
  }
  if (is_stable) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  REP(i, n) {
    cout << a.at(i).first << ' ' << a.at(i).second << endl;
  }
  return 0;
}



Measured memory_bytes: 7428
#include <stdio.h>

#define N_MAX 100000

int main(void)
{
	int i, j;
	int Max = 0;
	int N = 0;
	scanf("%d", &N);	

	int list[N_MAX] = {0};
	int save[N_MAX] = {0};
	
	for (j = 0; j < N_MAX; j++){
		list[j] = 2147483647;
		save[j] = 2147483647;
	}
	
	for (i = 0; i < N; i++){
		scanf("%d", &list[i]);
		save[i] = list[i];
	}
	
	for (i = 0; i < N; i++){
		if (list[i] > Max){
			Max = list[i];
		}
	}
	
	int Left = 0;
	int Right = Max;
	int Mid = 0;
	
	for (i = 0; i < N; i++){
		if (list[i] <= Max / 2){
			if (list[i] > Left){
				Left = list[i];
			}
		}else{
			if (list[i] < Right){
				Right = list[i];
			}
		}	
	}

	if (Max/2 - Left < Right - Max/2){
		Mid = Left;
	}else if (Max/2 - Left > Right - Max/2){
		Mid = Right;
	}else if (Max % 2 == 0){
		Mid = Left;
	}else{
		Mid = Right;
	}
	
	printf("%d %d\n", Max, Mid);
	
	return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
	    System.out.printf("%d %d %.10f\n", a / b, a % b,  (double)a / (double)b);
		sc.close();
	}
}


Measured memory_bytes: 26596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
ll mod = 1000000007;
ll INF = 1000000099;



signed main(){
    int n;
    cin>>n;
    cout << (n-2)*180 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
	string s;
	cin >> s;
	int count0 = 0;
	int count1 = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			count0++;
		}
		else {
			count1++;
		}
	}
	cout << min(count0, count1) * 2 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
const int N = 0;
 
typedef long long int ll;
 
using namespace std;


 
int main(){

    ll n;cin>>n;
    queue<ll> numbers;

    for(int i=1;i<10;i++){
        numbers.push(i);
    }

    ll steps = 0;
    ll ans = 0;

    while(steps<n){
        ans = numbers.front();numbers.pop();
        if(ans%10 != 0)numbers.push(ans*10+(ans%10)-1);
        numbers.push(ans*10+(ans%10));
        if(ans%10 != 9)numbers.push(ans*10+(ans%10)+1);
        steps++;
    }
    cout<<ans;

    return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#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 ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	int n;
	cin >> n;
	list<int> b;
	FOR(i, 1, n) {
		int B;
		cin >> B;
		b.PB(B);
	}
	vector<int> res(n + 1);
	int cnt2 = n;
	while (1) {
		int cnt = 1;
		bool isfind = false;
		auto itr2 = b.begin();
		for (auto itr = b.begin(); itr != b.end(); itr++) {
			if (*itr == cnt) {
				itr2 = itr;
				isfind = true;
			}
			cnt++;
		}
		if (!isfind) {
			ps(-1);
			return 0;
		}
		res[cnt2] = *itr2;
		b.erase(itr2);
		cnt2--;
		if (cnt2 == 0)break;
	}
	FOR(i, 1, n) {
		pv(res[i]);
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

def solve():
    N = int(input())
    hq = []
    for i in range(N):
        A, B = map(int, input().split())
        heappush(hq, (B,A))

    time = 0
    cost = 0
    while hq:
        l, c = heappop(hq)
        if time == l:
            cost += c
        else:
            time = l
            cost += c
        if cost > time:
            return 'No'
    return 'Yes'
if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 28756
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main(){
  ll n,ans=0;
  cin>>n;
  vector<int> a(n),b(n),c(n);
  rep(i,n){
    int x;
    cin>>x;
    a.at(i)=x;
  }
  rep(i,n){
    int x;
    cin>>x;
    b.at(i)=x;
  }
  rep(i,n){
    int x;
    cin>>x;
    c.at(i)=x;
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  int start=0,end=n-1,center,x,y;
  rep(i,n){
    ans+=(lower_bound(a.begin(),a.end(),b.at(i))-a.begin())*(c.end()-upper_bound(c.begin(),c.end(),b.at(i)));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define FOR(i, a) for(int i = 0; i < (int) a; i++)
#define all(v) v.begin(), v.end()
#define f first
#define s second

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



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

	ll n; cin >> n;

	ll cnt = 1, ans = 0;
	while(n > 0){
		n/=2;
		ans += cnt;
		cnt*=2;
	}

	cout << ans << '\n';	

	return 0;
}


Measured memory_bytes: 256
def prime_factorization(n):
    table = []
    for x in range(2, int(n ** 0.5) + 1):
        while n % x == 0:
            table.append(x)
            n //= x
    if n > 1:
        table.append(n)
    return table


N = int(input())
MOD = 10**9+7

mp = [0]*1000
for i in range(2, N+1):
    pf = prime_factorization(i)
    for p in pf:
        mp[p] += 1

ans = 1
for p in mp:
    if p == 0:
        continue

    ans = ans*(p+1)

print(ans % MOD)


Measured memory_bytes: 9292
#include <iostream>
using namespace std;
int main(void){
    
     for (int i = 1; i > 0; i ++)
            {
                int x, y, tmp;
                cin >> x >> y;
                if (x == 0 && y == 0) {
                    break;
                }else if(x > y){
                    tmp = x;
                    x = y;
                    y = tmp;
                    cout << x << " " <<  y << endl;
                }else{
                    cout << x << " " <<  y << endl;
                }
            }

}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ios std::ios::sync_with_stdio(false)
#define maxn 100005
#define int long long
using namespace std;
int n;
int x, k, d;
int a[105];
int ans;
signed main()
{
	ios;
	cin >> x >> k >> d;
	x = abs(x);
	if (x / d > k) {
		cout << x - d * k << "\n";
	}
	else {
		k = k - x / d;
		if (k & 1) {
			cout << d - x % d << "\n";
		}
		else {
			cout << x % d << "\n";
		}
	}
}
	/*if (K * D <= X)
		ans = X - K * D;
	else
	{
		K -= X / D;
		int A = X % D;

		if (K % 2 == 0)
			ans = A;
		else
			ans = D - A;
	}
	cout << ans<<endl;*/
//}
/*#include <iostream>
#include <vector>
#include <map> 
#include <algorithm>
#include <cstring>
 
#define ll long long
using namespace std; 
 
void solve(){
  ll x,k,d; 
  cin >>x>> k>> d; 
  x = abs(x);
  d = abs(d);  
  
 
}
 
int main(){
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
 return 0;
}*/

Measured memory_bytes: 3636
#include <iostream>

using namespace std;
typedef long long ll;
const ll inf = 1LL << 60;

int n, W;
ll dp[110][101000];

//dp[i][sum_v]:i番目の品物までで、総価値sum_v以上になる最小の重さw
// => dp[n][sum_v] <= W であるようなsum_vのmax
int main(){
    cin >> n >> W;
    int w[n], v[n];
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
    }

    for(int i = 0; i < 110; i++){
        for(int j = 0; j < 101000; j++){
            dp[i][j] = inf;
        }
    }

    dp[0][0] = 0;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < 101000; j++){
            if(j >= v[i]) dp[i+1][j] = min(dp[i+1][j],dp[i][j - v[i]] + w[i]);

            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        }
    }

    ll res = 0;
    for(int j = 0; j < 101000; j++){
        if(dp[n][j] <= W) res = j;
    }
    cout << res << endl;
    return 0;
}

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

lli n;

int main(void){
	cin >> n;
	vector<lli> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end(), greater<lli>());
	lli m1, m2;
	m1 = m2 = 0;
	rep(i, n-1){
		if(a[i] == a[i+1]){
			if(m1 == 0) m1 = a[i];
			else if(m2 == 0) m2 = a[i];
			i+=1;
		}
	}
	cout << m1*m2 << endl;
	return 0;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;
 
void testCase() {
    ll n, k;
    cin >> n >> k;
    ll ans = n;
    if (n >= k) {
        ll al = (n/k);
        al--;
        ans = min (ans, n-al*k);
        ll vv = (n-al*k);
        vv = abs(vv - k);
        ans = min (ans, vv);
    }
    ll al = (n+k-1)/k;
    al--;
    ans = min (ans, n-al*k);
    ll val = (n-al*k);
    val = abs(val-k);
    ans = min (ans, val);
    cout << ans << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys



def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, m = LI()
num = LI()


ans = 0
D = defaultdict(int)
ret = 0
for i in range(n):
    ret = (ret + num[i]) % m
    D[ret] += 1



D[0] += 1


for i in D.values():
    ans += i * (i - 1) // 2



print(ans)


Measured memory_bytes: 59120
using System;

class E
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static void Main()
	{
		var z = Read();
		var h = z[0];
		var ms = Array.ConvertAll(new int[z[1]], _ => Read());

		var dp = Array.ConvertAll(new int[h + 1], _ => 1 << 30);
		dp[0] = 0;
		for (int j, i = 1; i <= h; i++)
			foreach (var m in ms)
				dp[i] = Math.Min(dp[i], dp[(j = i - m[0]) < 0 ? 0 : j] + m[1]);
		Console.WriteLine(dp[h]);
	}
}


Measured memory_bytes: 13308
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    char s[100005];
    ll n,k;
    scanf("%s%lld",s,&k);
    // ll [n];
    n=strlen(s);
    rep(i,0,n){
        if(s[i]=='a') continue;
        else{
            if(k<123-(char)s[i]){
                continue;
            }else{
                k-=123-(char)s[i];
                s[i]='a';
            }
        }
    }
    if(k>0){
        k%=26;
        ll a=(ll)s[n-1];
        if(a+k<=122){
            s[n-1]=(char)(a+k);
        }else{
            s[n-1]=(char)(95+a+k-123);
        }
    }
    rep(i,0,n){
        printf("%c",s[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int l,r;
    int max_l = -1;
    int max_r = 99999999;
    for(int i=0;i<m;i++){
        cin >> l >> r;
        if(l >= max_l) max_l = l;
        if(r <= max_r) max_r = r; 
    }
    if(max_r-max_l >-1){
        cout << max_r - max_l + 1<< endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n;
  ll a , b;
  cin >> n;
  a = b = (n / 2);
  if(n % 2 == 1) b++;
  cout << a * b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(){
  int n;
  std::cin >> n;
  std::vector<int> v(n);
  rep(i,n){
    int temp;
    std::cin >> temp;
    v[i]=temp-1;
  }

  int mi=1001001001;
  for (int i = 0; i < 100; i++) {
    int now=0;

    for (int no : v) {
      now+=(i-no)*(i-no);
    }
    mi=min(mi,now);
  }
  std::cout << mi << '\n';


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)
 
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
 
#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
 
typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
 
int main()
{
    int W, H;
    cin >> W >> H;
    priority_queue<int, vector<int>, greater<int>> P, Q;
    rep(i, W) {
        int p; cin >> p;
        P.push(p);
    }
    rep(i, H) {
        int q; cin >> q;
        Q.push(q);
    }
 
    ll ans = 0LL;
 
    int useW = 0, useH = 0;
    while (P.size() || Q.size()) {
        int topP = (P.size() ? P.top() : INF);
        int topQ = (Q.size() ? Q.top() : INF);
 
        if (topP < topQ) {
            // use p
            ans += (ll)P.top() * (H - useH + 1);
            useW++;
            P.pop();
        } else {
            // use q
            ans += (ll)Q.top() * (W - useW + 1);
            useH++;
            Q.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define ll long long

using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	ll int a[100001][4];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i][1]>>a[i][2]>>a[i][3];
	}

	ll int dp[n+1][4];

	dp[1][1]=a[1][1];
	dp[1][2]=a[1][2];
	dp[1][3]=a[1][3];

	/*int maxpts=std::max({a[1][1],a[1][2],a[1][3]});

	happts=maxpts;

	for(int i=2;i<=n;i++)
	{
		if(maxpts==a[i-1][1])
			maxpts=max(a[i][2],a[i][3]);

		else if(maxpts==a[i-1][2])
			maxpts=max(a[i][1],a[i][3]);

		else
			maxpts=max(a[i][1],a[i][2]);

		happts+=maxpts;

	}

	cout<<happts<<endl;*/


	for(int i=2;i<=n;i++)
	{
		dp[i][1]=max(dp[i-1][2]+a[i][1],dp[i-1][3]+a[i][1]);

		dp[i][2]=max(dp[i-1][1]+a[i][2],dp[i-1][3]+a[i][2]);

		dp[i][3]=max(dp[i-1][2]+a[i][3],dp[i-1][1]+a[i][3]);

	}

	ll int happts=std::max({dp[n][1],dp[n][2],dp[n][3]});

	cout<<happts<<endl;

	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
int n,m,js;char ch[10];
int main()
{
	scanf("%d%d",&n,&m);
	for(RI i=1;i<=n;++i) {
		scanf("%s",ch+1);
		for(RI j=1;j<=m;++j) js+=(ch[j]=='#');
	}
	if(js==n+m-1) puts("Possible");
	else puts("Impossible");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
using namespace std;
int main(void){
    // Your code here!
  int n,k;
  cin>>n>>k;
  int arr[n];
  
  
  for(int i=0;i<n;i++){
      cin>>arr[i];
  }
  std::sort(arr, arr+n);
  
  long long sum=0;
  for(int i=0;i<k;i++){
      sum+=arr[i];
  }
  cout<<sum;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define REP(n) for(int i = 0; i < n; i++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
template<class X=int>inline X min(X a,X b,X c){return min(min(a,b),c);}
template<class X=int>inline X min(X a,X b,X c,X d){return min(min(a,b,c),d);}
template<class X=int> inline X max(X a,X b,X c){return max(max(a,b),c);}
template<class X=int> inline X max(X a,X b,X c,X d){return max(max(a,b,c),d);}
template<class X=int> inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int> inline X len(X s,X e){return (e-s+1);}
const int MOD = 1e9 + 7;
const int INF = 987654321;
const bool TESTCASES = 0;
const bool CODEJAM = 0;

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> A = vector<int>(n);
	REP(n) cin >> A[i];
	vector<int> dp = vector<int>(n);
	dp[0] = 0;
	for(int i = 1; i < n; i++) {
		int temp = INT_MAX;
		for(int j = i - 1; j >= max(0, i - k); j--) {
			temp = min(temp, dp[j] + abs(A[j] - A[i]));
		}
		dp[i] = temp;
	}
	cout << dp[n - 1] << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int T = 1;
	if(TESTCASES) cin >> T;
	for(int t = 1; t <= T; t++) {
		if(CODEJAM) cout << "Case #" << t << ": ";
		solve();
	}
	return 0;
}


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

int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    string ans;
    while(1){
        c-=b;
        if (c<=0) {
            cout<<"Yes"<<endl;
            return 0;
        }
        a-=d;
        if (a<=0) {
            cout<<"No"<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;

const int MAX_N = 2000;
const int64_t MOD = 1e9 + 7;


i64 DP[MAX_N + 10][MAX_N + 10];

vector<int> S, T;
vector<set<int>> K;

int main() {
    int N, M;
    cin >> N >> M;
    S = vector<int>(N), T = vector<int>(M);
    // S[i] = T[j] となる j
    K = vector<set<int>>(N + 1, set<int>());
    for(int i = 0; i < N; i++) {
        cin >> S[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> T[i];
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (S[i] == T[j]) {
                K[i].insert(j);
            }
        }
    }
    for (int i = N; i >= 0; i--) {
        auto itor = K[i].end();
        if (K[i].size()) itor--;
        i64 sum = 0;
        for(int j = M; j >= 0; j--) {
            if(i == N) {
                DP[i][j] = 1;
            } else {
                if (K[i].size() && (*itor) == j) {
                    sum += DP[i + 1][j + 1];
                    sum %= MOD;
                    if(itor != K[i].begin()) itor--;
                }
                DP[i][j] = sum + DP[i + 1][j];
                DP[i][j] %= MOD;
            }
        }
    }
    cout << DP[0][0] << endl;
    return 0;
}

Measured memory_bytes: 212992
#include <stdio.h>
#include <string.h>

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }

    return flag;
}

int main(){
    char s[100010];
    int dp[100010] = {0};
    char t[4][8]={"dream","dreamer","erase","eraser"};

    scanf("%s", s);

    dp[0] = 1;
    for(int i = 0; i < strlen(s); ++i){
        if(dp[i] == 0) continue;
        for(int j = 0; j < 4; ++j){
            if(is_substr(s, t[j], i) == 1) dp[i + strlen(t[j])] = 1;
        }
    }

    puts(dp[strlen(s)] ? "YES" : "NO");

    return 0;
}

Measured memory_bytes: 2148
def main():
    S = list(input())
    count = 0
    counts = []
    for i in S:
        if i in ['A', 'T', 'C', 'G']:
            count += 1
        else:
            counts.append(count)
            count = 0
    counts.append(count)
    print(max(counts))
main()


Measured memory_bytes: 2940
n = gets.to_i

road = Array.new(n+1){[]}
pre = Array.new(n+1, 0)
ans = Array.new(n+1, 0)

(n-1).times do
    u, v, w = gets.split.map(&:to_i)
    road[u] << [v, w]
    road[v] << [u, w]
end

que = [[1, 0]]
while now = que.shift
    i, w = now
    ans[i] = ans[pre[i]] ^ (w % 2)

    road[i].each do |ni, nw|
        next if ni == pre[i]
        pre[ni] = i
        que << [ni, nw]
    end
end

puts ans[1..-1]

Measured memory_bytes: 28284
people, foods = map(int, input().split(' '))
ls = []
for p in range(0, people):
    ls.append(set(x for i, x in enumerate(list(map(int, input().split(' ')))) if i > 0))

populer = ls[0]
for l in ls:
    populer = populer & l

print(len(populer))

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

import sys
from math import sqrt
from collections import deque

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,K=MAP()
A=LIST()

sm=sum(A)

def divisor_set(N: int) -> set:
    """ 約数の列挙・個数 """
    # 1とその数はデフォで入れとく
    s = {1, N}
    # 終点はルート切り捨て
    for i in range(2, int(sqrt(N))+1):
        # 割り切れるなら、iとN/iを追加
        if N % i == 0:
            s.add(i)
            s.add(N // i)
    return s

divs=sorted(divisor_set(sm), reverse=True)

for div in divs:
    B=[]
    for i in range(N):
        if A[i]%div!=0:
            B.append(A[i]%div)
    # mod取ったものをソート、これを前後からdivの約数に合わせていく
    B.sort()
    B=deque(B)
    cnt=0
    while len(B):
        # 先頭を引いていってdivの約数になるまでの距離
        dista=B[0]%div
        # 末尾を足していってdivの約数になるまでの距離
        distb=div-B[-1]%div
        # どちらが近いかに応じてリストBを操作する
        if dista>distb:
            B[0]-=distb
            B.pop()
            cnt+=distb
        elif dista<distb:
            B[-1]+=dista
            B.popleft()
            cnt+=dista
        elif dista==distb:
            B.pop()
            B.popleft()
            cnt+=dista
    # 操作回数がK回以内ならOK
    if cnt<=K:
        print(div)
        exit()


Measured memory_bytes: 3552