akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;
	public static final long HUGE_NUM = 99999999999999999L;
	public static final double EPS = 0.000000001;



	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);

		long dp[][][] = new long[10][101][1001];

		for(int i = 0; i < 10; i++){
			for(int k = 0; k <= 100; k++){
				for(int p = 0; p <= 1000; p++){
					dp[i][k][p] = 0;
				}
			}
		}

		//最初の数字
		for(int first = 0; first <= 100; first++){

			dp[0][first][first] = 1;
		}

		for(int index = 1; index <= 9; index++){
			for(int pre_num = 0; pre_num <= 100; pre_num++){
				for(int pre_sum = 0; pre_sum <= 1000; pre_sum++){
					if(dp[index-1][pre_num][pre_sum] == 0)continue;

					for(int next_num = pre_num+1; next_num <= 100 && pre_sum+next_num <= 1000; next_num++){

						dp[index][next_num][pre_sum+next_num] += dp[index-1][pre_num][pre_sum];
					}
				}
			}
		}

		StringBuilder ans = new StringBuilder();

		while(true){

			int N = scanner.nextInt();
			int S = scanner.nextInt();

			if(N == 0 && S == 0)break;

			long tmp = 0;
			for(int i = 0; i <= 100; i++){

				tmp += dp[N-1][i][S];
			}
			ans.append(Long.toString(tmp)).append("\n");
		}

		System.out.print(ans.toString());
	}
}

class UTIL{

	//最大公約数
	public static long gcd(long x,long y){

		x = Math.abs(x);
		y = Math.abs(y);

		if(x < y){

			long tmp = y;
			y = x;
			x = tmp;
		}

		if(y == 0){

			return x;
		}else{

			return gcd(y,x%y);
		}
	}

	//最小公倍数
	public static long lcm(long x,long y){

		return (x*y)/gcd(x,y);
	}

	//String→intへ変換
    public static int getNUM(String tmp_str){

        return Integer.parseInt(tmp_str);
    }

    //文字が半角数字か判定する関数
    public static boolean isNumber(String tmp_str){

        if(tmp_str == null || tmp_str.length() == 0){

            return false;
        }

        Pattern pattern = Pattern.compile("\\A[0-9]+\\z");
        Matcher matcher = pattern.matcher(tmp_str);
        return matcher.matches();
    }
}


Measured memory_bytes: 36428
#include<cstdio>
#include<algorithm>
#define SZ 262144
using namespace std;
struct Tree {
	long long S, Mn, Mx;
	int C;
}IT[SZ+SZ];
void Ins(int a, int b) {
	a += SZ;
	IT[a].S = max(0, b);
	IT[a].Mn = -1e18, IT[a].Mx = 1e18;
	if (b >= 0) {
		IT[a].C = 1;
		IT[a].Mx = b;
	}
	else {
		IT[a].C = 0;
		IT[a].Mn = b;
	}
	while (a != 1) {
		a >>= 1;
		IT[a].Mx = min(IT[a * 2].Mx, IT[a * 2 + 1].Mx);
		IT[a].Mn = max(IT[a * 2].Mn, IT[a * 2 + 1].Mn);
		IT[a].S = IT[a * 2].S + IT[a * 2 + 1].S;
		IT[a].C = IT[a * 2].C + IT[a * 2 + 1].C;
	}
}
long long SA;
int n, A[201000], B[201000];
int main() {
	int i, Q, t, a, b;
	scanf("%d%d", &n,&Q);
	n *= 2;
	for (i = 1; i < SZ+SZ; i++) {
		IT[i].Mn = -1e18, IT[i].Mx = 1e18;
	}
	for (i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
		SA += A[i];
	}
	for (i = 1; i <= n; i++) {
		scanf("%d", &B[i]);
		if(i!=1 && i!=n) Ins(i, B[i] - A[i]);
	}
	while (Q--) {
		scanf("%d%d%d", &t, &a, &b);
		SA = SA - A[t] + a;
		A[t] = a, B[t] = b;
		if(t!=1 && t!=n)Ins(t, B[t] - A[t]);
		long long r = 0;
		if (IT[1].C % 2 == 0) r = SA + IT[1].S;
		else {
			r = max(SA + IT[1].S - IT[1].Mx, SA + IT[1].S + IT[1].Mn);
		}
		printf("%lld\n", r);
	}
}

Measured memory_bytes: 19584
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();
            int h = in.nextInt();
            int w = in.nextInt();
            out.println((H - h) * (W - w));
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            int n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

    }
}



Measured memory_bytes: 22996
//Robs Code
/***********HEADER***************/
#include<bits/stdc++.h>
/***********MACROS***************/
#define ll long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 10000007
#define mxval 1e9
#define grt [](auto x,auto y){return x>y;}
#define pii pair<ll,ll>
/*********VARIABLE****************/
using namespace std;
ll i,j,n,m,k,l,q,t,a,b,sum[3],tot[3],cnt[3];
/***********MAIN******************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll W,H,w,h;
    cin>>W>>H>>w>>h;
    cout<<((W-w)*(H-h));
	return 0;
}
//.........

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int H,W,D;
  cin >> H >> W >> D;
  vvi A(H,vi(W));
  map<int,P> mp;
  rep(i,H) {
    rep(j,W) {
      cin >> A[i][j];
      mp[A[i][j]] = P(i,j);
    }
  }
  vi sum(H*W+1,0);
  srep(x,1,H*W+1) {
    if(x > D) {
      sum[x] = sum[x-D] + abs(mp[x].first - mp[x-D].first) + abs(mp[x].second - mp[x-D].second);
    }
  }
  int q;
  cin >> q;
  vi L(q),R(q);
  rep(i,q) {
    cin >> L[i] >> R[i];
  }
  rep(i,q) {
    cout << sum[R[i]] - sum[L[i]] << endl;
  }
  return 0;
}

Measured memory_bytes: 8192
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define ROW_MAX 100
#define COL_MAX 100
#define NUM_MAX (ROW_MAX*COL_MAX)

int main(void) {
    int row, col;
    get_int2(&row, &col);
    int num = get_int();
    // 1-indexed
    static int arr[NUM_MAX];
    fget_array(&arr[1], num);
    int aidx = 1;

    int i, j;
    int norm[NUM_MAX];
    int rev[NUM_MAX];
    for(i = 0; i < col; i++) {
        norm[i] = i;
        rev[i] = col-i-1;
    }
    static int map[ROW_MAX][COL_MAX];
    for(i = 0; i < row; i++) {
        int *order = (i%2==0) ? norm : rev;
        for(j = 0; j < col; j++) {
            if(!arr[aidx]) aidx++;
            int jdx = order[j];
            map[i][jdx] = aidx;
            arr[aidx]--;
        }
    }

    // presentation
    for(i = 0; i < row; i++) {
        for(j = 0; j < col; j++) {
            printf("%d%c", map[i][j], j==(col-1) ? '\n' : ' ');
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    int N,M; cin >> N >> M;
    int a[60]; int b[60]; rep(i,N) cin >> a[i] >> b[i];
    int c[60]; int d[60]; rep(i,M) cin >> c[i] >> d[i];
    
    rep(i,N){
        int res = abs(a[i]-c[0]) + abs(b[i]-d[0]);
        int check_point = 1;
        rep(j,M){
            const int len = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if(res>len){
                res = len;
                check_point = j+1;
            }
        }
        pr(check_point);
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;


int c(int rate){
    if(rate < 400) return 0;
    if(rate < 800) return 1;
    if(rate < 1200) return 2;
    if(rate < 1600) return 3;
    if(rate < 2000) return 4;
    if(rate < 2400) return 5;
    if(rate < 2800) return 6;
    if(rate < 3200) return 7;
    return 8;
}
int main(){
    int N;
    cin >> N;
    int a[N];
    int colors[9];
    int cmax = 0;
    int cmin = 0;
    for(int i = 0; i < 9; i++){
        colors[i] = 0;
    }
    for(int i = 0; i < N; i++){
        cin >> a[i];
        colors[c(a[i])]++;
    }
    for(int i = 0; i < 8; i++){
        cmin += (colors[i] > 0);
    }
    if(colors[8] > 0){
        if(cmin == 0){
            cmin = 1;
            cmax--;
        }
    }
    cmax += cmin+colors[8];
    cout << cmin << " " << cmax << endl;
    return 0;
}

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

int main() {
    int n;cin>>n;
    int mn=1e9;
    int ans=0;
    for (int i=0;i<n;i++) {
        int a;cin>>a;
        if (a<=mn) {
            ans++;
            mn=a;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

ll kill (ll h)
{
  if (h == 1)
    return 1;
  
  ll temp = kill(h/2);
  
  return temp * 2 + 1;
}

int main()
{
  ll h;
  scanf("%lld", &h);
  
  printf("%lld\n", kill(h));
  
  return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,ll> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}
const ll INF = 1LL<<60;


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m, s;
	cin >>n >>m >>s;
	int MX = (n+4)*55;
	s = min(MX, s);
	vector<VI> z1(n, VI(n)), z2(n, VI(n));
	vector<VI> rr(n);
	rep(i, m){
		int u, v, az,b;
		cin >>u >>v >>az >>b;
		u--; v--;
		z1[u][v] = z1[v][u] = az;
		z2[u][v] = z2[v][u] = b;
		rr[u].emplace_back(v);
		rr[v].emplace_back(u);
		
	}
	VI w1(n), w2(n);
	rep(i, n){
		int g, d; cin >>g >>d;
		w1[i]=g; w2[i] = d;
	}
	
	VL ans(n, INF);
	typedef tuple<ll, ll, ll> TL;
	priority_queue< TL, vector<TL>, greater<TL> > que;
	vector<VL> dp(n, VL(MX+3, INF));
	dp[0][s] = 0; ans[0]=0;
	que.emplace(0, 0, s);
	while(!que.empty()){
		ll c0, v, c2;
		tie(c0, v, c2) = que.top(); que.pop();
		if(dp[v][c2] < c0) continue;
		for(auto q2 : rr[v]){
			if(c2 >= z1[v][q2]){
				ll ncst = dp[v][c2] + z2[v][q2];
				if( ncst < dp[q2][c2-z1[v][q2]]){
					dp[q2][c2-z1[v][q2]] = ncst;
					que.emplace(ncst, q2, c2-z1[v][q2]);
					ans[q2] = min(ans[q2], ncst);
				}
			}
			if(c2 < MX ){
				int zxc = min<ll>(MX, c2+w1[v]);
				ll ncst = dp[v][c2] + w2[v];
				if(dp[v][zxc]  > ncst){
					dp[v][zxc] = ncst;
					que.emplace(ncst, v, zxc);
				}
			}
			
		}
	}
	rep2(i,1, n) cout << ans[i] <<"\n";
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    int arr[n],ans[n];
    for(int i=0;i<n;i++){
        ans[i]=0;
        cin>>arr[i];
    }
    ans[0]=0;
    ans[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++){
        ans[i] = min( ans[i-1] + abs(arr[i]-arr[i-1]) , ans[i-2] + abs(arr[i]-arr[i-2]) );
        //cout<<ans[i]<<" ";
    }
    cout<<ans[n-1]<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n;
    cin >> n;

    VI p(101, 0);
    int in;
    FOR(i, 0, n) {
        cin >> in;
        p[in]++;
    }

    int ans = 0;
    rFOR(i, 0, 100)p[i] += p[i + 1];
    eFOR(i, 0, 100)if (p[i] >= i)chmax(ans, i);
    cout << ans << "\n";
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int H, W, m;
    cin >> H >> W >> m;
    int h[m], w[m];
    bool chk[H][W];
    int cnth[H] = {}, cntw[W] = {};
    map<pint, bool> mp;
    rep(i, 0, m) {
        cin >> h[i] >> w[i];
        --h[i], --w[i];
        cnth[h[i]]++, cntw[w[i]]++;
        mp[{h[i], w[i]}] = 1;
    }
    int mh = -1, mw = -1;
    vector<int> vh, vw;
    rep(i, 0, H) {
        if (cnth[i] > mh) {
            mh = cnth[i];
            vector<int> ch;
            swap(vh, ch);
            vh.push_back(i);
        } else if (cnth[i] == mh)
            vh.push_back(i);
    }
    rep(i, 0, W) {
        if (cntw[i] > mw) {
            mw = cntw[i];
            vector<int> ch;
            swap(vw, ch);
            vw.push_back(i);
        } else if (cntw[i] == mw)
            vw.push_back(i);
    }
    // cout << mh << " " << mw << "\n";
    int ans = -1;
    rep(i, 0, vh.size()) {
        rep(j, 0, vw.size()) {
            if (mp[{vh[i], vw[j]}]) {
                ans = max(ans, cnth[vh[i]] + cntw[vw[j]] - 1);
            } else {
                cout << mh + mw << "\n";
                return 0;
            }
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 39756
#include<stdio.h>
int main()
{
	int h,w,c1=0,c2=0,m,n;
	scanf("%d %d",&h,&w);
		while(1){
			c1=0;
			c2=0;
			if(h==0&&w==0)break;
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					m=c1%2;
					n=c2%2;
					if(m==0&&n==0){
						printf("#");
					}
					else if(m==1&&n==0){
						printf(".");
					}
					else if(m==0&&n==1){
						printf(".");
					}
					else
						printf("#");
					c1++;
				}
				c1=0;
				c2++;
				printf("\n");
			}
			printf("\n");
	scanf("%d %d",&h,&w);
	}
	return 0;
}

Measured memory_bytes: 1000
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int a, b, t;
    cin >> a >> b >> t;
    cout << (t / a) * b << endl;
    return 0;
}


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

int main(void){
    int n; cin >> n;
    vector<int> a(n);
    vector<int> box(n);
    int m = 0;
    
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    
    for(int i = n - 1; i > -1; i--){
        if((i + 1) > n / 2){
            box.at(i) = a.at(i);
            m += a.at(i);
        }else{
            box.at(i) += a.at(i);
            for(int j = 2*(i + 1) - 1 ; j < n; j += (i + 1)){
                box.at(i) += box.at(j);
            }
            box.at(i) = box.at(i) % 2;
            m += box.at(i);
        }
    }
    
    cout << m << endl;
    
    for(int i = 0; i < n; i++){
        if(box.at(i) == 1){
            cout << i + 1 << " ";
        }
    }
    cout << endl;
    
}

Measured memory_bytes: 2432
#include "bits/stdc++.h"
using namespace std;

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

	cin >> a >> b >> c >> d;

	while (true) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			break;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
int main(){
    int N;
    scanf("%d",&N);
    int h[N];
    for(int i=0;i<N;i++)
        scanf("%d",&h[i]);
    int dp[N];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<N;i++){
        dp[i]=std::min(dp[i-1]+abs(h[i]-h[i-1]),
                       dp[i-2]+abs(h[i]-h[i-2]));
    }
    printf("%d\n",dp[N-1]);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int a[3][3], n, b;
pair<int, int> pos[110];
bool mark[110];
bool vis[3][3];
int main() {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
			pos[a[i][j]] = make_pair(i, j);
			mark[a[i][j]] = 1;
		}
	}
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> b;
		if (!mark[b]) continue;
		pair<int, int> p = pos[b];
		vis[p.first][p.second] = 1;
	}
	for (int i = 0; i < 3; i++) {
		if (vis[i][0] && vis[i][1] && vis[i][2]) {
			puts("Yes");
			return 0;
		}
	}
	for (int i = 0; i < 3; i++) {
		if (vis[0][i] && vis[1][i] && vis[2][i]) {
			puts("Yes");
			return 0;
		}
	}
	if (vis[0][0] && vis[1][1] && vis[2][2]) {
		puts("Yes");
		return 0;
	}
	if (vis[0][2] && vis[1][1] && vis[2][0]) {
		puts("Yes");
		return 0;
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(a,b) memset(a,b,sizeof (a))
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll ksm(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

const int N=110;
int n,k;
int d[N];
int a[N][N];
int vis[N];
int main(){
	scanf("%d%d",&n,&k);
	
	rep(i,1,k){
		scanf("%d",&d[i]);
		rep(j,1,d[i]){
			scanf("%d",&a[i][j]);
			vis[a[i][j]]=true;
		}
	}
	int ans=0;
	rep(i,1,n){
		if(!vis[i]){
			ans++;
		}
	}
	printf("%d",ans);
    return 0;
}


Measured memory_bytes: 3868
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	int N, K; cin >> N >> K;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		int tmp; cin >> tmp;
		if (tmp >= K) cnt++;
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <stack>
#include <math.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
typedef pair<int, int> pii;
int main(){
long double a,b,x,i;
long double bu,ans;
cin>>a>>b>>x;
if(x>=a*a*b/2){
bu=x/(a*a); b-=bu;
ans=(long double)atan(b*2/a);
ans=ans*180/PI;

cout <<setprecision(9)<<fixed<<ans<<endl;

}else{
bu=x/(a*b);
//cout << b<<" "<<bu<<" "<<b/bu<<endl;
//ans=(long double)atan(b/bu);

ans = PI / 2 - atan(2*bu/b);
ans=ans*180/PI;
cout <<setprecision(9)<<fixed<<ans<<endl;

}







}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

vector<P> TV[40], TV2;
priority_queue<int, std::vector<int>, std::greater<int> > pq;

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

    int N, C;
    std::cin >> N >> C;

    for(int i=0;i<N;++i){
        int s, t, c;
        std::cin >> s >> t >> c;

        --c;
        TV[c].emplace_back(s, t);
    }

    for(int i=0;i<C;++i){
        sort(TV[i].begin(), TV[i].end());

        int l = TV[i].size();
        for(int j=0,k=0;j<l;j=k){
            while(k + 1 < l && snd(TV[i][k]) == fst(TV[i][k+1])){
                ++k;
            }

            TV2.emplace_back(fst(TV[i][j]), snd(TV[i][k]));
            ++k;
        }
    }

    // for(auto &p : TV2){
    //     std::cout << fst(p) << ", " << snd(p) << std::endl;
    // }

    sort(TV2.begin(), TV2.end());
    
    int cnt = 1;
    pq.emplace(snd(TV2[0]) + 1);

    for(int i=1;i<(int)TV2.size();++i){
        int t = pq.top();
        if(t <= fst(TV2[i])){
            pq.pop();
            pq.emplace(snd(TV2[i]) + 1);
        }else{
            pq.emplace(snd(TV2[i]) + 1);
            ++cnt;
        }
    }

    std::cout << cnt << std::endl;
}


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int ans = 0;
  for (int i = 0; i <= A; i++)
    for (int j = 0; j <= B; j++)
      for (int k = 0; k <= C; k++)
        if (500 * i + 100 * j + 50 * k == X) ans++;

  cout << ans << endl;
}


Measured memory_bytes: 256
s = input()
dp = [[0]*13 for _ in range(len(s)+1)]
dp[0][0] = 1
mul = 1

MOD = 10**9 + 7

for i in range(len(s)):
    x = s[-(i+1)]
    if x != '?':
        k = int(x)
        for j in range(13):
            dp[i+1][(mul*k+j)%13] += dp[i][j]
            dp[i+1][(mul*k+j)%13] %= MOD
    else:
        for k in range(10):
            for j in range(13):
                dp[i+1][(mul*k+j)%13] += dp[i][j]
                dp[i+1][(mul*k+j)%13] %= MOD
    mul *= 10
    mul %= 13
print(dp[-1][5])

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

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

  int N;
  string S;
  cin >> N >> S;

  int x = 0;
  int max_num = 0;
  for (int i = 0; i < N; ++i) {
    if (S.at(i) == 'I') x++;
    else if (S.at(i) == 'D') x--;
    max_num = max(max_num, x);
  }

  cout << max_num << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())

int main(){
  ll n;
  cin>>n;
  vp time(n);
  REP(i,n){
    cin>>time[i].second>>time[i].first;
  }
  sort(time.begin(),time.end());
  ll sum=0;
  bool ans=true;
  REP(i,n){
    sum+=time[i].second;
    if(sum>time[i].first){
      ans=false;
      cout<<"No"<<endl;
      break;
    }
  }
  if(ans){cout<<"Yes"<<endl;}
}


Measured memory_bytes: 3328
import itertools


sw_n,den_n = list(map(int,input().split()))
dens = []

for _ in range(den_n):
    dens.append(list(map(int,input().split()[1:])))
den_kyo = list(map(int,input().split()))

patt = list(itertools.product([0,1], repeat=sw_n))

res = 0

for pat in patt:
    kyoka = True
    for i,den in enumerate(dens):
        sums = 0
        for j in den:
            sums += pat[j-1]
        if sums%2 != den_kyo[i]:
            break
    else:
        res+=1


print(res)

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

const int maxn = 1000;

string s[maxn];
int n,l;

int main()
{
    scanf("%d %d",&n,&l);

    for(int i = 0;i < n;++i)
    {
        char buf[1000];
        scanf("%s",buf);
        s[i] = string(buf);
    }
    sort(s,s+n);
    string res = "";
    for(int i = 0;i < n;++i)
        res += s[i];
    printf("%s",res.c_str());

    return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 999999999999

using namespace std;

#define int long long

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

	int cnt_1=0;
	REP(i, n){
		int x;
		cin >> x;
		if(x%2) cnt_1++;
	}
	
	if(cnt_1%2){
		cout << "NO" << endl;
	}
	else{
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
	int data[1010];
	
	int n,m;
	while(cin>>n>>m && n &&m){
		for(int i=0;i<n;i++){
			cin>>data[i];
		}
		sort(data,data+n,greater<int>());
		int ans=0;
		
		for(int i=0;i<n;i++){
			if((i+1)%m!=0)ans+=data[i];
		}
		
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1180
o=->a,n{n<1?1:a**n[0]*o[a,n/2]**2%M}
eval'N,A,B='+`dd`.split*?,
a=o[A*=t=o[A+B,-2+M=10**9+7],N]
b=o[B*=t,N]
f=g=1,*(1...N).map{|i|g=g*i%M}
t*=g
N.times{|i|$.=($.+o[g*f[i],M-2]*(a+b)*100*t=t*(N+i)%M)%M
a=a*B%M
b=b*A%M}
p$.

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vs vector<string>
#define miv map<int, vi>

void show(auto a){
  int i = 0;
  while(i < a.size()){
    cout<<a[i]<<" ";
    i++;
  }
  cout<<endl;
}


void dfs(int a,  vector<int> table[], bool visited[], int dp[]){
	visited[a] = true;
	for(int i = 0; i<table[a].size(); i++){
		if(!visited[table[a][i]]) dfs(table[a][i], table, visited, dp);

		dp[a] = max(dp[table[a][i]] + 1, dp[a]);
	}

}

int main(){
  ios_base::sync_with_stdio(false);

  int n, m;
  cin>>n>>m;
  vector<int> table[n + 1]; 

  while(m--){
  	int a, b;
  	cin>>a>>b;
  	table[a].push_back(b);
  }

  bool visited[n+1];
  int dp[n+1];

  for(int i = 0; i <= n; i++){
  	visited[i] = false;
  	dp[i] = 0;
  }


  for(int i = 1; i<=n; i++){
  	if(!visited[i])dfs(i, table, visited, dp);
  }
  int ans = 0;
  for(int i = 0; i < n+1; i++){
  	ans = max(dp[i], ans);
  }

  cout<<ans<<endl;

}

Measured memory_bytes: 9600
s = list(input())
t = list(input())
ch_list = []
n = len(s)
flag = 0
ch_list = ["" for i in range(n)]
for i in range(n):
    for j in range(n):
        ch_list[(j+i)%n] = s[j]
    if ch_list == t:
        flag = 1
if flag == 1: print("Yes")
else: print("No")

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

int main() {
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());
    sort(c.begin(), c.end(), greater<ll>());
        
    vector<ll> abc;
    rep(ai, x) {
        rep(bi, y) {
            if (ai * bi > k) break;
            rep(ci, z) {
                if (ai * bi * ci > k) break;
                abc.push_back(a[ai] + b[bi] + c[ci]);
            }
        }
    }
    sort(abc.begin(), abc.end(), greater<ll>());
    rep(i, k) cout << abc[i] << endl; 
    return 0;
}

Measured memory_bytes: 36304
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define INF 1000000000
typedef long long ll;

#define MAXN 105
#define MAXL 1005
int N,M,L;
int dis[MAXN][MAXN];
pii mis[MAXL];

#define MAXV 2100
int V;//# of vertex 
vector<int> G[MAXV];
int match[MAXV];
int used[MAXV];
void add_edge(int u, int v)
{
    G[u].pb(v);
    G[v].pb(u);
}

bool dfs(int u)
{
    used[u]=true;
    for(int i = 0; i < G[u].size(); i++)
    {
        int v = G[u][i], w = match[v];
        if(w<0 || !used[w]&&dfs(w) )
        {
            match[u]=v;
            match[v]=u;
            return true;
        }
    }
    return false;
}

int bip_match()
{
    int res=0;
    memset(match,-1,sizeof(match));
    for(int v=0; v<V; v++)
    {
        if(match[v]<0)
        {
            memset(used,0,sizeof(used));
            if(dfs(v))res++;
        }
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while(cin>>N>>M>>L&&(N+M+L))
    {
        V=L*2;
        FOR(i,0,V-1)G[i].clear();
        FOR(i,0,N-1)FOR(j,0,N-1)dis[i][j]=(i==j)?0:INF;
        int a,b,c;
        FOR(i,1,M)
        {
            cin>>a>>b>>c;
            dis[a][b]=dis[b][a]=c;
        }
        FOR(k,0,N-1)FOR(i,0,N-1)FOR(j,0,N-1)
            if(dis[i][k]+dis[k][j]<dis[i][j])
                dis[i][j]=dis[i][k]+dis[k][j];
        //get missions
        FOR(i,0,L-1)cin>>mis[i].f>>mis[i].s;
        //build graph
        FOR(i,0,L-1)FOR(j,0,L-1)if(i!=j&&(mis[j].s-mis[i].s)>=dis[mis[i].f][mis[j].f])
            add_edge(i,L+j);
        cout<<L-bip_match()<<'\n';
    }

    return 0;
}




Measured memory_bytes: 11616
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
typedef struct book{
    string title,auth,date;
} bk;

vector<string> split(string s,char ch){
    vector<string> ret;
    string tmp ="";
    rep(i,s.size()){
        if(s[i]==ch){
            ret.pb(tmp);
            tmp = "";
        }else tmp+=s[i];
    }
    if(tmp.size())ret.pb(tmp);
    return ret;
}

//????????????0
//a?????\????????????????????????1???
//a?????\????????????????????????-1?????????
int ymdcompare(string a,string b){
    vector<string> A[2];
    A[0] = split(a,'/');
    A[1] = split(b,'/');
    int ymd[2][3];
    rep(i,2)rep(j,3)ymd[i][j]=stoi(A[i][j]);
    
    rep(i,3){
        if(ymd[0][i]>ymd[1][i])return -1;
        if(ymd[0][i]<ymd[1][i])return  1;
    }
    
    return 0;
}


bool is(bk data,string title,string auth,string from,string to){
    if(title!="*"   && data.title.find(title)==string::npos)return false;

    if(auth!="*"    && data.auth.find(auth)==string::npos)  return false;

    if(from!="*"    && ymdcompare(from,data.date)==-1)      return false;

    if(to!="*"      && ymdcompare(to,data.date)==1)         return false;

    return true;
}

int main(){
    
    int n;
    cin>>n;
    vector<bk> data;
    
    rep(i,n){
        string a,b,c;
        cin>>a>>b>>c;
        data.pb(bk{a,b,c});
    }
    
    int q;
    cin>>q;
    rep(i,q){
        string title,auth,from,to;
        cin>>title>>auth>>from>>to;
        
        vector<string> t;
        rep(j,n){
            if(is(data[j],title,auth,from,to))t.pb(data[j].title);
        }
        
        rep(i,t.size())cout<<t[i]<<endl;
        if(i!=q-1)cout<<endl;
    }
}

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

using namespace std;

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

const int N = 100005;
const int mod = 1e9 + 7;

string k;
int d;
int memo[N][2][105];

int dp(int pos, bool last, int modpro) {
	if (pos == k.size()) {
		return (modpro == 0);
	}
	int &ans = memo[pos][last][modpro];
	if (ans != -1) {
		return ans;
	}
	int till = (last ? k[pos] - '0' : 9);
	ans = 0;
	for (int i = 0; i <= till; i++) {
		ans += dp(pos + 1, last && (i == k[pos] - '0'), (modpro + i) % d);
		ans %= mod;
	}
	return ans % mod;
}

void solve() {
	int i, j, n, m, ans = 0, cnt = 0, sum = 0;
	cin >> k >> d;
	memset(memo, -1, sizeof(memo));
	cout << (dp(0, 1, 0) - 1 + mod) % mod;
	return ;
}

int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	// int t; cin >> t; while (t--)
	solve();
	return 0;
}

Measured memory_bytes: 165120
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

const int MAX=510000;
const int mod=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];

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

ll modinv(ll a){
  return modpow(a,mod-2);
}

void init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  rep(i,MAX){
    if(i>1){
      fac[i]=fac[i-1]*i%mod;
      inv[i]=mod-inv[mod%i]*(mod/i)%mod;
      finv[i]=finv[i-1]*inv[i]%mod;
    }
  }
}

ll 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;
}

int main(){
  int S;
  cin>>S;
  init();
  ll ans=0;
  rep(i,S/3){
    ll tmp=S-(i+1)*3;
    ans=(ans+com(tmp+i,i))%mod;
  }
  cout<<ans<<endl;
}


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

int main () {
  int N, ans;
  cin >> N;
  for (int i = 1; i < N/2+1; i++) {
    int j = i, k = N-i, a = 0, b = 0;
    while (j != 0) {
      a += j%10;
      j /= 10;
    }
    while (k != 0) {
      b += k%10;
      k /= 10;
    }
    if (i == 1) ans = a+b;
    else ans = min(ans, a+b);
  }
  cout << ans << endl;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define si set<int>
#define sl set<long long>
#define pq prioirty_queue
#define all(v) v.begin(),v.end()
#define left (2*idx)+1
#define right (2*idx)+2
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

const ll N = (ll)(1e5 + 7);
const ll MOD = (ll)(1e9 + 7);

int main()
{
    FIO;

    map<int, vector<long long>> mp;
    int n, m;
    cin >> n >> m;

    for(int i=0; i<n; i++)
    {
    	ll a, b;
    	cin >> a >> b;
    	mp[a].push_back(b);
    }

    priority_queue<long long> q;
    ll ans = 0;
    for(int i = m-1; i>=0; i--)
    {
    	int d = m-i;
    	for(auto ele : mp[d])
    	{
    		q.push(ele);
    	}
    	if(q.empty())
    		continue;
    	ans+=q.top();	q.pop();
    }

    cout << ans << "\n";

}


Measured memory_bytes: 10880
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int A,B,C,K;
    R(A,B,C,K);
    W(min(A,K)-max(K-A-B,0));
    return 0;
}


Measured memory_bytes: 3824
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    s=input()
    ans=0
    for d in range(1,n):
        count=0
        for i in range(n-d):
            if s[i]==s[i+d]: count+=1
            else: count=0
            ans=max(min(count,d),ans)
    print(ans)
resolve()

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

#define FASTIO1 ios_base::sync_with_stdio(false)
#define FASTIO2 cin.tie(NULL),cout.tie(NULL)
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
#define all(x) (x).begin(),(x).end()
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll power(ll x,ll y,ll p);
const ll inf=999999999;
const ll mod=1e9+7;
bool tc=false;
#define MAX 200005

vector <ll> adj[MAX];
vector <bool> visited(MAX,false);
ll number_of_node_visited;

void dfs(ll src)
{
    visited[src]=true;
    number_of_node_visited++;
    // cout<<src<<" ";
    for(ll node:adj[src])
        if(visited[node]==false)
            dfs(node);
    // return;
}

void solve()
{
    //scan edge and vertices
    ll n,m,u,v,ans=-inf; cin>>n>>m;
    for(ll i=0;i<m;i++)
    {
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for(ll i=1;i<=n;i++)
        if(visited[i]==false)
        {
            number_of_node_visited=0;
            dfs(i);
            ans=max(ans,number_of_node_visited);
        }
    cout<<ans;

}

int main() 
{
    FASTIO1;
    FASTIO2;
    clock_t start=clock();
    ll t=1; 
    if(tc) cin>>t;
    while(t--)
        solve();
    cerr<<fixed<<setprecision(6);
    cerr<<(double)(clock()-start)/CLOCKS_PER_SEC<<endl;
    return 0;
}

ll power(ll x,ll y,ll p)  
{  
    ll res=1; x=x%p;
    if(x==0) return 0;
    while(y>0)  
    {
        if(y&1) res=(res*x)%p;
        y=y>>1; x=(x*x)%p;  
    }
    return res;  
}  


Measured memory_bytes: 20920
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	cout << ((a[0]+a[1]==a[2])?"Yes":"No") << endl;
	return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

int a[111111],n,minV;
unordered_map <int,bool> cache;
void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

bool solve(int s)
{
	if(s < 0)
	{
		return false;
	}
	if(s == 0)
	{
		return false;
	}
	if(s < minV)
	{
		return false;
	}
	if(cache.find(s) != cache.end())
	{
		return cache[s];
	}
	
		int flag = 0;
		for(int i=0;i<n;i++)
		{
			if(s-a[i] < 0)
			{
				continue;
			}
			bool p = solve(s-a[i]);
			if(p == false)
			{
				flag = 1;
				break;
			}
		}
		if(flag == 1)
		{
			return cache[s] = true;
		}
		else
		{
			return cache[s] = false;
		}
}

int32_t main()
{
 // c_p_c();
  int x;
  cin >> n >> x;
  minV = INT_MAX;
  for(int i=0;i<n;i++)
  {
  	cin >> a[i];
  	minV = min(minV,a[i]);
  }
  // cout<<minV<<endl;
  bool res = solve(x);
  if(res == true)
  {
  	cout<<"First"<<endl;
  }
  else
  {
  	cout<<"Second"<<endl;
  }
  return 0;
}



Measured memory_bytes: 7460
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb emplace_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<int, pii>
#define puu pair<ULL, ULL>
#define pdd pair<long double, long double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

const int N = 1e5 + 40;
const int MOD = 1e9 + 7;
vector<int> g[N];
int n, k, u, v;
LL dp[N], f[N], invf[N];
LL q_pow(LL n, LL k) {
	LL ans = 1; 
	while(k) {
		if(k&1) ans = (ans * n) % MOD;
		n = (n * n) % MOD;
		k >>= 1;
	}
	return ans;
}
void init() {
	f[0] = 1;
	for (int i = 1; i < N; ++i) f[i] = f[i-1]*i%MOD;
	invf[N-1] = q_pow(f[N-1], MOD-2);
	for (int i = N-2; i >= 0; --i) invf[i] = invf[i+1]*(i+1)%MOD; 
}
LL C(int n, int m) {
	if(m > n) return 0;
	return f[n]*invf[m]%MOD*invf[n-m]%MOD;
}
void dfs(int u, int o) {
	dp[u] = 1;
	int t = 0;
	for (int v : g[u]) {
		if(v != o) {
			dfs(v, u);
			dp[u] = (dp[u] * dp[v]) % MOD;
			++t;
		}
	}
	if(u == 1) {
		if(t >= k) dp[u] *= 0;
		else dp[u] = (dp[u]*f[k-1]%MOD*invf[k-t-1])%MOD;
	}
	else {
		if(t >= k-1) dp[u] *= 0;
		else dp[u] = (dp[u]*f[k-2]%MOD*invf[k-1-t-1])%MOD;
	}
}
int main() {
	init();
	scanf("%d %d", &n, &k);
	for (int i = 1; i < n; ++i) scanf("%d %d", &u, &v), g[u].pb(v), g[v].pb(u); 
	dfs(1, 1);
	printf("%lld\n", dp[1]*k%MOD);
	return 0;
}

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

using namespace std;

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))


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

template <class T> inline T gcd(T a, T b) { while (b) { a = a%b; swap(a, b); } return a; }
template <class T> inline T bigmod(T p, T e, T m) {
	T ret = 1;
	for (; e > 0; e >>= 1) {
		if (e & 1) ret = (ret * p) % m; p = (p * p) % m;
	} return (T)ret;
}



int main()
{
	//cout.setf(ios::fixed); cout.precision(10);
	ios_base::sync_with_stdio(false);  cout.tie(nullptr); cin.tie(nullptr);
	int a, b, c;
	cin >> a >> b >> c;

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

	}

	return 0;
}

Measured memory_bytes: 256