akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int MAX_V = 210;

int N, M, V, match[MAX_V], used[MAX_V];
int tx[MAX_V], ty[MAX_V], tv[MAX_V], bx[MAX_V], by[MAX_V];
vector<int> G[MAX_V];

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

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

double solve(){
  double l = 0.0, h = 1e9;
  REP(t, 100){
    double m = (l + h) / 2.0;
    REP(i, MAX_V) G[i] = vector<int>();
    REP(i, N){
      REP(j, M){
        double d = sqrt((tx[i] - bx[j]) * (tx[i] - bx[j]) + (ty[i] - by[j]) * (ty[i] - by[j])) / tv[i];
        if(d <= m){
          G[i].push_back(j + N);
          G[j + N].push_back(i);
        }
      }
    }
    if(bipartite_matching() >= M) h = m;
    else l = m;
  }
  return h;
}

int main() {
  while(cin >>N >>M && N){
    V = N + M;
    REP(i, N) cin >>tx[i] >>ty[i] >>tv[i];
    REP(i, M) cin >>bx[i] >>by[i];
    printf("%.8lf\n", solve());
  }
  return 0;
}

Measured memory_bytes: 1380
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<set>
#include<queue>
#include<algorithm>
#include<climits>
#include<map>
#include<unordered_map>
#define ll long long

bool isPrime(ll n){
    if(n%2==0 || n%3==0) return false;
    if(n<=1)  return false;
    if(n<=3)  return true;
    for(ll i=5;i*i<=n;i=i+6)
        if(n%i==0||n%(i+2)==0)
           return false;
    return true;
}

#define w(t) ll t,tt=1;	cin>>t;		while(t--)
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

#define vi vector<int>
#define vll vector<ll>
#define mii map<ll,ll>
#define umii unordered_map<ll,ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>

#define mod 1e9+7
#define inf 1e18

#define lln ll n; cin>>n
#define intn int n; cin>>n
#define YES cout<<"YES"
#define NO cout<<"NO"
#define strr    string str; cin>>str;
#define strn   n=str.length()
#define fr(a,n) for(ll i=a;i<n;i++)
#define loop for(ll i=0;i<n;i++)

using namespace std;

bool possible(int mid,int k,int arr[],int n){
    if(mid==0)  return false;
    int curr=0;
    loop{
        if(arr[i]>mid)   curr+=(arr[i]/mid);
    }
    return curr<=k;
}

void solve (){
    intn;
    int k;
    cin>>k;
    int arr[n];
    loop cin>>arr[i];
    int mid,low=1,high=1e9;
    while(low<high){
        mid=(low+high)/2;
        if(possible(mid,k,arr,n)) high=mid;
        else                low=mid+1;
    }
    cout<<low;
}

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


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

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)

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

int main() {
  ll a, b;
  cin >> a >> b;
  cout << (abs(a - b) <= 1 ? "Brown" : "Alice") << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
int n,m,ans,sum[10],a[10][10];
void dfs(int xx,int yy)
{
    int v=0;
    int x,y;
    for (int i=1;i<=n;i++)
    if (sum[i]>(n-1)/2) return;
    for (int i=xx;i<=n;i++)
    {
      for (int j=1;j<=i-1;j++)
      if (a[i][j]==-1)
      {
         x=i; y=j;
         v=1;
         break;
      }
      if (v==1) break;
    }
    if (v==0)
    {
        int vv=0;
        for (int i=1;i<=n;i++)
        {
            if (i>=2&&sum[i]!=sum[i-1])
            {
                vv=1; break;
            }
        }
        if (vv==0) ans++;
        return;
    }
    a[x][y]=1;
    a[y][x]=0;
    sum[x]+=1;
    dfs(x,y);
    a[x][y]=-1;
    a[y][x]=-1;
    sum[x]-=1;
    a[x][y]=0;
    a[y][x]=1;
    sum[y]+=1;
    dfs(x,y);
    a[x][y]=-1;
    a[y][x]=-1;
    sum[y]-=1;
}

int main()
{
while (1)
{
    scanf("%d",&n);
    if (n==0) break;
    scanf("%d",&m);
    memset(a,-1,sizeof(a));
    int x,y;
    memset(sum,0,sizeof(sum));
    for (int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        a[x][y]=1;
        a[y][x]=0;
        sum[x]+=1;
    }
    ans=0;
    dfs(1,1);
    printf("%d\n",ans);
}

    return(0);
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull N, M;
typedef pair<ull, ull> P;
vector<P> v;

int main() {
  cin >> N >> M;
  ull s, t;
  for (ull i = 0; i < N; i++) {
    cin >> s >> t;
    v.push_back(P(s, t));
  }
  sort(v.begin(), v.end());

  ull ans = 0;
  ull drink = 0;
  ull i = 0;

  while (M > drink) {
    if (M - drink >= v[i].second) {
      ans += v[i].first * v[i].second;
      drink += v[i].second;
    } else {
      ans += (M-drink) * v[i].first;
      drink += M-drink;
    }
    i++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2420
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

int n, mx, c, h[N];
int main()
{
	int i;
	cin >> n;
	for (i = 0; i < n; i++) scanf("%d", &h[i]);
	for (i = n - 2; i >= 0; i--) {
		if (h[i] >= h[i + 1]) c++, mx = max(mx, c);
		else c = 0;
	}
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main() {
	
	int X=0; int A=0;
	scanf("%d %d", &X, &A);
	if(0<=X&A<=9){
	if(X<A){
	printf("0\n", X<A);
}
	if(X>=A){
	printf("10\n", X>A);
}
}
	return 0;
}

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

int main() {
	string s;
	int n,i,j,k;
	cin >> n;
	char c;
	vector<int> a(26),b(26);
	for(i=0; i<26; i++){
		b[i]=50;
	}
	for(i=0; i<n; i++){
		cin >> s;
		for(j=0; j<s.size(); j++){
			k=s[j]-'a';
			a[k]++;
		}
		for(j=0; j<26; j++){
			b[j]=min(a[j],b[j]);
			a[j]=0;
		}
	}
	for(i=0; i<26; i++){
		c='a'+i;
		for(j=0; j<b[i]; j++){
			cout << c;
		}
	}
	
}

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()

for i in range(4):
	if S[i:i+2] == 'AC':
		print('Yes')
		sys.exit()

print('No')

Measured memory_bytes: 4212
#include<iostream>
#include <cstdio>
#include<cstring>
#include<string>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define LEN 100005
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) {if (x % y == 0) return y;else return LGCD(y, x % y);}
ll LLCM(ll x, ll y) {return x * y / LGCD(x, y);}

int GCD(int x, int y) {if (x % y == 0) return y;else return GCD(y, x % y);}
int LCM(int x, int y) {return x * y / GCD(x, y);}
ll dpc[10000][10000];
ll combination(ll n, ll r) {
         if (n == r){dpc[n][n] = 1;}
	else if (r == 0) {return dpc[n][0] = 1;}
	else if (r == 1) {return dpc[n][1]=n;}
	else {dpc[n][r]=dpc[n - 1][r - 1] % 1000000007 + dpc[n - 1][r] % 1000000007;
	return dpc[n][r]=combination(n - 1, r - 1) % 1000000007 + combination(n - 1, r) % 1000000007;}
}
ll Combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else {
		//dpc[n][r] = dpc[n - 1][r - 1] % 1000000007 + dpc[n - 1][r] % 1000000007;
		return dpc[n][r] = combination(n - 1, r - 1) % 1000000007 + combination(n - 1, r) % 1000000007;
	}
}

bool chsK(string s) {
	int n = s.length();
	if (n % 2 == 0) {
		for (int i = 0;i <= n / 2;i++) {
			if (s[i] != s[n - i-1])return false;
		}
	}
	else {
		for (int i = 0;i <= n / 2;i++) {
			if (s[i] != s[n - i-1])return false;
		}
	}
	return true;
}

int main() {
	double L;
	cin >> L;
	L = pow(L / 3, 3);
	cout<<fixed <<setprecision(8)<< L << endl;
	return 0;
}

Measured memory_bytes: 256
/* Manish Pant - insider_pants, hello_my_friend */
    
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define endl "\n"
#define pb push_back

typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; } 

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int n, k;
vector<set<int>> v(1000);

int main()
{
    fast();
    cin >> n >> k;
    int ans = 0;
    set<int> done;
    for(int i = 1; i <= k; i++)
    {
        int n; cin >> n;
        for(int j = 0; j < n; j++)
        {
            int a; cin >> a;
            v[a].insert(i);
        }
    }
    for(int i = 1; i <= n; i++)
    {
        if(v[i].empty()) ans++;
    }
    cout << ans << endl;
}

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

int main(void){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((abs(a-c)<=d) or (abs(a-b)<=d and abs(b-c)<=d))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=998244353;
const int MX=0x3f3f3f3f;

int main(){
	IOS;
	int h,w,i,j,k;
	cin>>h>>w>>k;
	char ch[h][w];
	REP(i,0,h-1)
		REP(j,0,w-1) cin>>ch[i][j];
	char temp[h][w];
	int p,r,cnt;
	ll ans=0;
	REP(i,0,llround(pow(2,h))-1){
		REP(j,0,llround(pow(2,w))-1){
		memcpy(temp,ch,sizeof(ch));
		cnt=0;
		dbg(i);
		REP(p,0,h-1){
			if(i>>p&1){
				REP(r,0,w-1) temp[p][r]='r';
			}
		}
			REP(p,0,w-1){
				if(j>>p&1){
					REP(r,0,h-1) temp[r][p]='r';
				}
			}
		REP(p,0,h-1)
			REP(r,0,w-1)
				if(temp[p][r]=='#') cnt++;
		if(cnt==k) ans++;
		dbg(cnt);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4080
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int d,n,m;
	for(;scanf("%d%d%d",&d,&n,&m)>2;){
		vector<int>v(n*3);
		v[1]=d,v[2]=d*2;
		for(int i=1;i<n;i++){
			scanf("%d",&v[i*3]);
			v[i*3+1]=v[i*3]+d,v[i*3+2]=v[i*3+1]+d;
		}
		sort(v.begin(),v.end());
		int r=0;
		for(int i=0;i<m;i++){
			int t;
			scanf("%d",&t);
			t+=d;
			vector<int>::iterator it=lower_bound(v.begin(),v.end(),t);
			for(;*it>=t;--it);
			int idx=distance(v.begin(),it);
			r+=min(t-v[idx],v[idx+1]-t);
		}
		printf("%d\n",r);
	}
}

Measured memory_bytes: 2060
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#define fi(p) for(int i=0;i<(p);i++)
using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int a, b;
	cin >> a >> b;

	bool res = false;

	for (int i = 1; i < 4; i++) {
		int temp = a * b * i;
		if (temp % 2 == 1) {
			res = true;
		}
	}
	if (res == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace std;
using namespace __gnu_pbds;
 
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define rev(a) a.rbegin(),a.rend()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
 
void solve(){
	ll m = 0, n = 0, i = 0, j = 0, k = 0, ma = -1e9, mi = 1e9, ans = 0, cnt = 0;
	cin>>n>>k;
    vl v(n), temp(n, 0);
    for(auto &i : v) cin>>i;
    f(i, 1, n){
        temp[i] = 1e9;
        for(j = i - 1; j >= max(i - k, 0LL); --j){
            temp[i] = min(temp[i], abs(v[i] - v[j]) + temp[j]);
        }
    }
    cout<<temp[n - 1]<<"\n";
}
 
int main(){
 
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
 
/* 	ll t;
	cin>>t;
	while(t--){ */
		solve();
/* 	} */
 
}

Measured memory_bytes: 4760
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main() {
    double x1, x2, y1, y2, D;
    cin >> x1 >> y1 >> x2 >> y2;
    D = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
    printf("%.5lf\n",sqrt(D));
    return 0;
}


Measured memory_bytes: 3276
N = int(input())
P = list(map(float, input().split()))

dp = [[0.0] * (N+1) for _ in range(N+1)]
dp[-1][0] = 1
for i, p in enumerate(P):
  for j in range(N):
    dp[i][j+1] += dp[i-1][j] * p
    dp[i][j] += dp[i-1][j] * (1-p)


print(sum(dp[-2][-(-(N+1)//2):]))
    

Measured memory_bytes: 111836
#include <stdio.h>

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#define N 200010
#define MAX 1000000000000000000
#define MOD 1000000007

#include <stdio.h>

int main (void) {
    char s[100], s1[50] = {0}, s2[50] = {0};
    int i;

    scanf("%s", s);

    strncpy(s1, s, strlen(s) / 2);
    strncpy(s2, s + (strlen(s) / 2  + 1), strlen(s) / 2);

    if (strcmp(s1, s2)) {
        puts("No");
        return 0;
    }

    for (i = 0; i < strlen(s1) / 2; i++) {
        if (s1[i] != s1[strlen(s1) - 1 - i]) {
            puts("No");
            return 0;
        }
    }

    puts("Yes");

    return 0;
}



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

using namespace std;

long long n,a[210000],x,an,hoge;

int main(){
    cin >> n;

    for (x=0 ; x<n ; x++) {
        cin >> a[x];
        a[x] -= x+1;
    }

    sort (a,a+n);

    hoge = a[n/2];

    for (x=0 ; x<n ; x++){
        if (a[x]-hoge < 0) an += (a[x]-hoge)*-1;
        else  an += a[x]-hoge;
    }


    cout << an << "\n";


}


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

int main() {
  string s, t;
  cin >> s;
  cin >> t;

  vector<map<char, int>> next(s.size());
  next[s.size() - 1] = map<char, int>();
  next[s.size() - 1][s[s.size() - 1]] = s.size() - 1;

  for (int i = s.size() - 2; i >= 0; i--) {
    next[i] = next[i + 1];
    next[i][s[i]] = i;
  }

  for (int i = 0; i < t.size(); i++) {
    if (next[0].count(t[i]) == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  int cur = 0;
  ll ans = 0;
  for (int i = 0; i < t.size(); i++) {
    if (next[cur].count(t[i]) == 0) {
      ans += s.size() - cur;
      cur = 0;
    }
    ll nextcur = next[cur][t[i]];
    ans += nextcur - cur + 1;
    cur = (nextcur + 1) % s.size();
  }

  cout << ans << endl;
}

Measured memory_bytes: 126976
#include <bits/stdc++.h>
using namespace std;
 
#define fastio() ios_base::sync_with_stdio(false);\
cin.tie(NULL);
 
#define md 1000000007
 
 
#define lli long long int
#define pb push_back
#define mp make_pair
#define vvi(r,c) vector<vector<lli>> v(r,vector<lli>(c));
#define fi first
#define se second
#define mem(arr,x) memset(arr,x,sizeof(arr))
 
lli power(lli a,lli b){
  if(b==0)
    return 1;
  if(b%2)
    return ((a%md)*(power(a,b-1)))%md;
  else
  {
    lli x=power(a,b/2);
    return (x*x)%md;
  }
}
 
void solve(){
  int n,W;
  cin>>n>>W;
  vector<int> w(n),v(n);
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>w[i]>>v[i];
    sum+=v[i];
  }
 // cout<<sum<<endl;
  vector<int> dp(sum+1,md);
  dp[0]=0;
  for(int j=0;j<n;j++){
  for(int i=sum;i>0;i--){
      if(i-v[j]>=0){
        dp[i]=min(dp[i],w[j]+dp[i-v[j]]);
      }  
  }
  }
  int i;
  for(i=sum;i>0;i--){
  //  cout<<dp[i]<<endl;
      if(dp[i]<=W){
        // cout<<dp[i]<<" ";
        break;
      }
  }
  cout<<i<<endl;
 
}
 
 
int main()
{  
    fastio();
  int t;
  
  t=1;
  while(t--){
    solve();
  }
 
  return 0;
}

Measured memory_bytes: 3708
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>

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

int main() {
  ll N, T, ans = 0;
  cin >> N >> T;
  ll a[N];
  rep(i, N){
    cin >> a[i];
  }

  ll tmp = a[0] + T;
  ans += T;
  for(int i = 1; i < N; i++){
    ans += T;
    if(tmp > a[i]){ // 時間が被っているとき
      ans -= tmp - a[i]; // 被った分をひく
    } 
    tmp = a[i] + T;
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 1792
import java.util.*;
import static java.lang.System.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        long ans=1;
        for (int i = 0; i < n; i++) {
            long t = sc.nextLong();
            long g = gcd(ans, t);
            ans=t/g*ans;
        }
        out.println(ans);
    }
    static long gcd (long a, long b) {
        long temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        int N = cin.Nextint;
        var A = cin.Scanlong;
        Array.Sort(A);
        Array.Reverse(A);
        long ans = 0;
        int cnt = 0;
        for (int i = 1; i < 3 * N; i += 2)
        {
            ans += A[i];
            cnt++;
            if (cnt == N) break;
        }
        WriteLine(ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 43976
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            var eatCount = int.Parse(Console.ReadLine());
            var payment = eatCount * 800;
            var discountSum = eatCount / 15 * 200;
            Console.WriteLine(payment - discountSum);
        }
    }
}


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

const int mxn = 1e5+7;
const int M = 1e9 + 7;

int main() {
	int n, m;
	cin >> n >> m;
	
	vector<string> mat(n);
	for(int i = 0; i < n; i++) {
		cin >> mat[i];
	}
	
	vector<vector<int>> dp(n+1, vector<int> (m+1, 0));
	
	dp[0][0] = 1;
	for(int i = 0; i < m; i++) {
		if(mat[0][i] == '.') {
			dp[0][i] = 1;
		}
		else break;
	}
	for(int i = 0; i < n; i++) {
		if(mat[i][0] == '.') {
			dp[i][0] = 1;
		}
		else break;
	}
	
	for(int i = 1; i < n; i++) {
		for(int j = 1; j < m; j++) {
			if(mat[i][j] == '.') {
				dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % M;
			}
			else {
				dp[i][j] = 0;
			}
		}
	}
	cout << dp[n-1][m-1] << "\n";
}


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

int main(){
  int N, X, bd=1, L, wh=0;
  cin >> N >> X;
  for(int i=0; i<N; i++){
    cin >> L;
    wh += L;
    if (wh <= X) bd++;
    else break;
  }
  cout << bd;
}


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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  if(A>K) cout << K << endl;
  if(A<=K && K<=A+B) cout << A << endl;
  if(A+B<K && K<=A+B+C) cout << A-(K-A-B) << endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
typedef long long ll;
const int N=100005;
int n,m,a[N],b[N],id[N];ll ans;
bool cmp(const int&x,const int&y){return a[x]<a[y];} 
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d%d",a+i,b+i),id[i]=i;std::sort(id+1,id+1+n,cmp);
	for(int j=1;j<=n;++j){
		int i=id[j];
		if(m>b[i])m-=b[i],ans+=1ll*a[i]*b[i];
		else{
			ans+=1ll*m*a[i];
			break;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N;
  cin>>N;
  cout<<N*N*N<<endl;
}


Measured memory_bytes: 256
PROGRAM-ID.                      ABC_099_C.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 N       PIC 9(6).
    01 ans     PIC X(6).

    01 ZS      PIC Z(7).
    01 DUMMY   PIC X(1).

    01 i       PIC 9(6) BINARY.

    01 r       PIC 9(1).

    01 sumr    PIC 9(6).
    01 t       PIC 9(6).

    01 res     PIC 9(6).

PROCEDURE                        DIVISION.
    ACCEPT N.

    MOVE N TO res.

    PERFORM VARYING i FROM 0 BY 1 UNTIL N < i

        MOVE i TO t
        MOVE ZERO TO sumr

        PERFORM UNTIL t <= ZERO
            DIVIDE 6 INTO t GIVING t REMAINDER r
            ADD r TO sumr
        END-PERFORM

        SUBTRACT i FROM N GIVING t

        PERFORM UNTIL t <= ZERO
            DIVIDE 9 INTO t GIVING t REMAINDER r
            ADD r TO sumr
        END-PERFORM

        COMPUTE res = FUNCTION MIN(res, sumr)

    END-PERFORM.

    MOVE res TO zs.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	bool ok = true;
	for(int i =0;i<n;i++)
	{
		int a;
		cin>>a;
		if(a % 2 == 0)
		{
			if(a % 3 == 0 || a % 5 == 0)
				continue;
			else
				ok = false;
		}
		else
			continue;
	}
	if(ok)
		puts("APPROVED");
	else
		puts("DENIED");
		
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    int N;
    cin >> N;
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        long long a; cin >> a;
        res += a-1;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll h,w; cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w));
    rep(i,h){
        rep(j,w) cin >> a[i][j];
    }
    ll dp[h+1][w+1] = {};
    dp[1][1] = 1;
    rep(i,h){
        rep(j,w){
            if(a[i][j] == '#') continue;
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j+1] + dp[i+1][j]);
            dp[i+1][j+1] %= MOD;
        }
    }
    cout << dp[h][w] << endl;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h> 
#define ll long long int  
using namespace std;
int main() {
    ll x,y; 
    cin >> x >> y;  
    ll c=0; 
    while(x<=y)
    {
       c++ ; 
       x*=2;
    } 
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3552
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		
		while(stdIn.hasNext()){
			String str = stdIn.nextLine();
			int[] number = new int[5];
			int[] count = new int[14];
			int j = 0;
			for(int i=0;i<str.length();i++){
				if('0'<=str.charAt(i) && str.charAt(i)<='9'){
					number[j]=number[j]*10;
					number[j]+=(int)str.charAt(i)-(int)'0';
				}
				else{
					j++;
				}
			}
			
			Arrays.sort(number);
			j=0;
			int k=0;
			int count_x =0;
			while(k<number.length){
				if(number[k]==j){
					count[j]++;
					if(0<k){
						if(number[k]-number[k-1]==1){
							count_x++;
						}
						else{
							count_x=0;
						}
					}
					k++;
				}
				else{
					j++;
				}
			}
			int count_3 = 0;
			int count_2 = 0;
			for(int i=0;i<14;i++){
				if(count[i]==4){
					System.out.println("four card");
					break;
				}
				else if(count[i]==3){
					count_3++;
				}
				else if(count[i]==2){
					count_2++;
				}
				if(count_3==1&&count_2==1){
					System.out.println("full house");
					break;
				}
				if(i==13){
					if(count_x == 4 || (count_x == 3 && number[0]==1 && number[1]==10)){
						System.out.println("straight");
						break;
					}
					else if(count_3==1){
						System.out.println("three card");
						break;
					}
					else if(count_2==2){
						System.out.println("two pair");
						break;
					}
					else if(count_2==1){
						System.out.println("one pair");
						break;
					}
					else{
						System.out.println("null");
						break;
					}
				}
			}
				
			
			
			
		}
	}
}

Measured memory_bytes: 17356
n, m = list(map(int, input().split()))

list = [list(map(int, input().split())) for x in range(m)]

ans = [1]*n

s = 0
m = n

for i in list:
    if i[0] > s:
        s = i[0]
    if i[1] < m:
        m = i[1]
if m>=s:
    print(m-s+1)
else:
    print(0)

Measured memory_bytes: 27960
#include<iostream>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <map>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){

ll n,m;
cin >> n >> m;

if(n == 2 || m == 2) {cout << 0 << endl; return 0;}
if(n == 1 &&  m == 1) {cout << 1 << endl; return 0;}
if(n == 1 ||  m == 1) {cout << max(m,n)-2 << endl; return 0;}

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

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define pq          priority_queue
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define vll         vector<pll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

const int N=1e5+5;
ll n,tmp;
pll a[N];

bool comp(pll a, pll b)
{
    return (a.F+a.S)<(b.F+b.S);
}

void solve()
{
    cin>>n;
    rep(i,1,n+1){
        cin>>a[i].F>>a[i].S;
        tmp-=a[i].S;
    }
    sort(a+1, a+1+n, comp);
    for(ll i=n; i>0; i-=2) tmp+=a[i].F+a[i].S;
    cout<<tmp;
}

int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
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() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;

  ll n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll q;
  cin >> q;
  ll total = accumulate(all(a), 0LL);
  map<ll, ll> Counter;
  rep(i, n) {
    Counter[a[i]]++;
  }
  vector<ll> ans(q);
  rep(i, q) {
    ll b, c;
    cin >> b >> c;
    total -= b*Counter[b];
    total += c*Counter[b];
    Counter[c] += Counter[b];
    Counter[b] = 0; 
    ans[i] = total;
  }
  for (ll i : ans) {
    cout << i << endl;
  }
}


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

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  int sum = 0;
  for (int i = N-1; i >= 0; i--) {
    sum += A.at(i);
    if (H <= sum) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

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

  int N; cin >> N;
  vector<int> A(N, 0);
  vector<vector<int>> X(N, vector<int>(N, 0));
  vector<vector<int>> Y(N, vector<int>(N, 0));
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    for (int j = 0; j < A[i]; j++) {
      int x, y;
      cin >> x >> y;
      X[i][j] = x - 1;
      Y[i][j] = y;
    }
  }

  int T = 1 << N;
  int ans = 0;
  for (int i = 0; i < T; i++) {
    vector<int> temp(N, 0);
    int ti = i;
    int tempAns = 0;
    for (int j = 0; j < N; j++) {
      temp[j] = ti % 2;
      tempAns += temp[j];
      ti /= 2;
    }

    bool ok = true;
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < A[j]; k++) {
        int x = X[j][k], y = Y[j][k];
        if (temp[j] == 1 && temp[x] != y) ok = false;
        if (!ok) break;
      }
      if (!ok) break;
    }
    if (!ok) continue;
    ans = max(ans, tempAns);
  }
  cout << ans << '\n';
  return 0;
}

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

int main(){
  bitset<4>b;
  vector<int>a(4);
  int tmp;
  cin >>tmp;
  for(int i=0;i<4;i++){
    a.at(3-i)=tmp%10;
    tmp/=10;
  }
  for(int i=0;i<(1<<4);i++){
    string s=to_string(a.at(0));
    tmp=a.at(0);
    b=i;
    for(int j=1;j<4;j++){
      if(b[j]==0){
        tmp+=a.at(j);
        s=s+"+"+to_string(a.at(j));
      }                   
      else{
        tmp-=a.at(j);
        s+=("-"+to_string(a.at(j)));
      }
    }
    if (tmp==7){
      cout <<s+"=7"<<endl;
      return 0;
    }
            }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef SIR
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define err(...) 42
#endif

typedef long long ll;

using namespace std;

void solve() {
    int n; cin >> n;
    int a, b; cin >> a >> b;
    cout << min(a, b) << " " << max(0, a - (n - b)) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef SIR
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200000)

def dfs(v):
    global node_chk
    global edge_chk
    global B
    global connect
    global value

    node_chk[v] = 1
    connect[v] = value
    for x in B[v]:
        if(node_chk[x] == 0):
                dfs(x)



n,m = map(int,input().split())
B = [[]for i in range(n)] # 隣接リスト
edge_chk = [[]for i in range(n)]
node_chk = [0 for i in range(n)]
connect = [0 for i in range(n)]
value = 0

for i in range(m):
    A = list(map(int,input().split()))
    B[A[0]].append(A[1])
    B[A[1]].append(A[0])
    edge_chk[A[0]].append(0)
    edge_chk[A[1]].append(0)

for i in range(n):
    if(node_chk[i] == 1):
        continue
    dfs(i)
    value += 1


q = int(input())
for i in range(q):
    start,target = map(int,input().split())
    if(connect[start] == connect[target]):
        print("yes")
    else:
        print("no")


Measured memory_bytes: 132540
#include <stdio.h>
#include <stdlib.h>

int compareInt(const void* a, const void* b)
{
	
	int aNum = *(int*)a; 
	int bNum = *(int*)b;
	return bNum - aNum;
}

int main(void) 
{
	int n;
	int array[100];
	int count = 1;

	
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &array[i]);
	}

	qsort(array, n, sizeof(int), compareInt);

	for (int i = 0; i < n-1; i++)
	{
		if (array[i] > array[i+1])
		{
			count++;
		}
	}

	printf("%d", count);

	return 0;
}

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

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

    int n;
    cin >> n;

    vector<vector<int>> a(n, vector<int>(n)), dist(n, vector<int>(n));
    rep(i, n) rep(j, n){
        cin >> a[i][j];
        dist[i][j] = a[i][j];
    }

    rep(k, n) rep(i, n) rep(j, n){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }

    rep(i, n) rep(j, n){
        if(dist[i][j] != a[i][j]){
            cout << -1 << endl;
            return 0;   
        }
    }

    const int no_conn = -1;
    rep(k, n) rep(i, n) rep(j, n){
        if(k==i || k==j) continue;

        if(a[i][j] == a[i][k] + a[k][j]) dist[i][j] = no_conn;
    }

    ll res = 0;
    rep(i, n) rep(j, n){
        if(i <= j || dist[i][j] == no_conn) continue;
        res += dist[i][j];
    }

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 1024
import sys
import heapq
from collections import defaultdict

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n, m = LI()
    c = defaultdict(list)
    for i in range(n):
        a, b = LI()
        c[a].append(b)
    # s_d = dict(sorted(d.items, key=lambda x: x[1]))
    s = []
    ans = 0
    for i in range(1, m+1):
        for j in c[i]:
            heapq.heappush(s, -j)
        if len(s) > 0:
            ans -= heapq.heappop(s)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 33016
#include<iostream>
#include<algorithm>
#define inf 1000000001
using namespace std;
int ans;
void merge(int A[],int left,int mid,int right){
int n1=mid-left;
int n2=right-mid;
	int L[n1+1],R[n2+1];
	int i,k,j;
	for(i=0;i<n1;i++)
	L[i]=A[left+i];
	for(i=0;i<n2;i++)
	R[i]=A[mid+i];
	L[n1]=inf;
	R[n2]=inf;
	i=0;j=0;
	for(k=left;k<right;k++){
		ans++;
		if(L[i]<=R[j]){
		A[k]=L[i];
			i++;
		}
		else{
		A[k]=R[j];
			j++;
		}
		
		
	}
	
}
void Msort(int A[],int left,int right){
	int mid;
	if(left+1<right){
		mid=(left+right)/2;
		Msort(A,left,mid);
		Msort(A,mid,right);
		merge(A,left,mid,right);
	}
}
void print(int n,int a[]){
int i;
for(i=0;i<n-1;i++)
printf("%d ",a[i]);
printf("%d\n",a[n-1]);
}
main(){
	int a[500000],n,i;
	ans=0;
	cin>>n;
	for(i=0;i<n;i++)
	cin>>a[i];
	Msort(a,0,n);
	print(n,a);
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 7108
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i=0,j;
    char s[100];
    cin>>s;
    while(s[i]!='\0')
    {
        if(s[i]>='a' && s[i]<='z')
        {
            cout<<'x';
        }
        i++;
    }
}


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

int main() {
  string s;
  cin>>s;
  int ans1=0;
  int a[100005];
  for (int i=0; i<s.size(); i++) {
    if (s[i]=='0') a[i]=0;
    else a[i]=1;
  }
  for (int i=0; i<s.size(); i++) {
    if (a[i]==i%2) ans1++;
  }
  int ans2=0;
  for (int i=1; i<=s.size(); i++) {
    if (a[i-1]==i%2) ans2++;
  }

  cout<<min(ans1,ans2)<<endl;
  return 0;
}



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

int main(){

string S;
int K;

cin>>K>>S;

//cout<<S.length();

if(int(S.length())>K){
    for(int i=0;i<K+3;i++){

        if(i<K){
        cout<<S[i];
        }else{
            cout<<".";
        }

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

    return 0;
}

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

#define LL 					long long
#define ULL 				unsigned long long
#define pii 				pair<int,int>
#define fi 					first
#define se 					second
#define mp 					make_pair
#define vi 					vector<int>
#define psb 				push_back
#define ppb 				pop_back
#define all(x)			 	(x).begin(),(x).end()
#define sz(x)				(int)(x).size()
#define endln 				printf("\n")
#define gc					getchar_unlocked
#define setmin(x)			memset((x), -1, sizeof((x)))
#define setnul(x)			memset((x), 0, sizeof((x)))
#ifndef getchar_unlocked
#define getchar_unlocked 	getchar
#endif
const int inf = (1<<30)-1+(1<<30);
const int mod = 1e9 + 7;

template <typename T>
void gi(T &ret) {
	ret = 0; char inp=gc(); int kl=1;
	while (inp<'0' || inp>'9') {if (inp=='-') kl=-1; inp=gc();}
	while ('0'<=inp && inp<='9') ret=(ret<<3)+(ret<<1)+(inp-'0'), inp=gc();
	if (kl<1) ret=-ret;
}

int tg, lb, n;
vector< pii > all;

bool penting(int y, int x) {
	if (y==0 || y==tg) return 1;
	if (x==0 || x==lb) return 1;
	return 0;
}

int conv (int y, int x) {
	if (x==0) return y;
	if (y==tg) return tg+x;
	if (x==lb) return tg+lb+(tg-y);
	return tg+lb+tg+(lb-x);
}

bool solve() {
	priority_queue < int, vi, greater<int> > pq;
	for (auto xx : all) {
		while (!pq.empty() && pq.top()<xx.fi) pq.pop();
		if (!pq.empty() && xx.se>pq.top()) return 0;
		pq.push(xx.se);
	}
	return 1;
}

int main() {
	gi(tg); gi(lb); gi(n);
	for (int i=1; i<=n; i++) {
		int ya, xa, yb, xb;
		gi(ya); gi(xa); gi(yb); gi(xb);
		if (!penting(ya,xa) || !penting(yb,xb)) continue;
		int a = conv(ya,xa), b = conv(yb,xb);
		if (a>b) swap(a,b);
		all.psb({a,b});
	}
	sort(all(all));
	if (solve()) puts("YES");
	else puts("NO");
	return 0;
}



Measured memory_bytes: 1524
using System;

namespace abc126B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string A = Console.ReadLine();
            int B = int.Parse(A.Substring(0, 2));
            int C = int.Parse(A.Substring(2));
            if ((B == 0 || B > 12 ) && (C == 0 || C > 12))
                Console.WriteLine("NA");
            else if ((B <= 12 && B != 0) && (C <= 12 && C != 0))
                Console.WriteLine("AMBIGUOUS");
            else if (B <= 12 && (C > 12 || C == 0))
                Console.WriteLine("MMYY");
            else if ((B > 12 || B == 0) && C <= 12)
                Console.WriteLine("YYMM");
            else
                Console.WriteLine("NA");
        }
    }
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  ll a,b,k; cin >> a >> b >> k;

  if(a>=k) a-=k;
  else{
    b-=k-a;
    a=0;
  }

  if(b<0) b=0;
  
  cout << a << " " << b << endl;
  
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>

using namespace std;
using ll = long long;

int main(){
    ll W, H, N;
    cin >> W >> H >> N;
    ll a[N], b[N], c[N];
    for(int i=0; i<N; ++i){
        cin >> a[i] >> b[i] >> c[i];
    }
    ll xmin, xmax, ymin, ymax;
    xmin = 0; ymin = 0;
    xmax = W; ymax = H;
    for(int i=0; i<N; ++i){
        if(c[i] == 1){
            if(xmin <= a[i]) xmin = a[i];
        }
        if(c[i] == 2){
            if(xmax >= a[i]) xmax = a[i];
        }
        if(c[i] == 3){
            if(ymin <= b[i]) ymin = b[i];
        }
        if(c[i] == 4){
            if(ymax >= b[i]) ymax = b[i];
        }
    }
    ll w, h;
    w = xmax - xmin;
    h = ymax - ymin;
    if(xmax < xmin) w = 0;
    if(ymax < ymin) h = 0;
    cout << w * h << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] temp = Console.ReadLine().Split();
        int M1 = int.Parse(temp[0]);
        temp = Console.ReadLine().Split();
        int M2 = int.Parse(temp[0]);
        if (M1 == M2) { Console.WriteLine("0"); }
        else { Console.WriteLine("1"); }
    }
}

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

using namespace std;

int main() {
	int n;
	while (cin >> n && n) {
		vector<int> s(n);
		int sum = 0;
		for (int i = 0; i < n; ++i) {
			cin >> s[i];
			sum += s[i];
		}
		auto m = 1.0*sum / n;
		auto sum2 = 0.0;
		for (auto si: s) {
			sum2 += (si-m)*(si-m);
		}
		auto var = sum2 / n;
		cout << fixed << setprecision(17) << sqrt(var) << '\n';
	}
}


Measured memory_bytes: 3220
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 300010;
int N;
string S;
int W[MAX_N];
int E[MAX_N];


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

  for (int i = 1; i <= N; ++i) {
    if (S[i-1] == 'W') W[i] += W[i-1]+1;
    else W[i] = W[i-1];
  }

  for (int i = N; i >= 1; --i) {
    if (S[i-1] == 'E') E[i] += E[i+1]+1;
    else E[i] = E[i+1];
  }


  int ans = 1e9;
  for (int i = 1; i <= N; ++i) {
    ans = min(ans, W[i-1] + E[i+1]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3076