akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

ll n,q;
ll a[201010],b[201010];
multiset<ll> ps,ms;
ll asum,psum;

int main(){
  cin>>n>>q;
  n*=2;
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  rep(i,n){
    asum+=a[i];
  }

  repl(i,1,n-1){
    if(b[i]-a[i]>=0){
      ps.insert(b[i]-a[i]);
      psum+=b[i]-a[i];
    }else ms.insert(b[i]-a[i]);
  }

  while(q--){
    ll p,x,y;
    cin>>p>>x>>y;
    p--;
    if(p==0||p==n-1){
      asum-=a[p];
      a[p]=x; b[p]=y;
      asum+=a[p];
    }else{
      if(b[p]-a[p]>=0){
        ps.erase(ps.lower_bound(b[p]-a[p]));
        psum-=b[p]-a[p];

        asum-=a[p];
        a[p]=x; b[p]=y;
        asum+=a[p];

        if(b[p]-a[p]>=0){
          ps.insert(b[p]-a[p]);
          psum+=b[p]-a[p];
        }else{
          ms.insert(b[p]-a[p]);
        }
      }else{
        ms.erase(ms.lower_bound(b[p]-a[p]));

        asum-=a[p];
        a[p]=x; b[p]=y;
        asum+=a[p];

        if(b[p]-a[p]>=0){
          ps.insert(b[p]-a[p]);
          psum+=b[p]-a[p];
        }else{
          ms.insert(b[p]-a[p]);
        }
      }
    }

    if(ps.size()%2==0)cout<<asum+psum<<endl;
    else{
      ll hoge=asum+psum+(*ms.rbegin());
      ll fuga=asum+psum-(*ps.begin());
      cout<<max(hoge,fuga)<<endl;
    }
  }

  return 0;
}


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

#define fi first
#define se second
#define lc (rt<<1)
#define rc (rt<<1|1)
#define mp make_pair
#define pb push_back
#define lowbit(a) (a&(-a))
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define mst(a,v) memset(a,v,sizeof(a))
#define debug(x) cout<<#x": "<<x<<'\n';
#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

const int N=1010;
const int mod=1e9+7;
const ld PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

template<class T> inline void gmax(T &A,T B)
{
    (A<B)&&(A=B);
}
template<class T> inline void gmin(T &A,T B)
{
    (A>B)&&(A=B);
}

template<class T> inline bool re(T &ret)
{
    char c;
    int sgn;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')? -1:1;
    ret=(c=='-')? 0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    ret*=sgn;
    return 1;
}

int n;
ll dp[407][407],sum[407];

int main()
{
#ifdef local
    //freopen("in.txt", "r", stdin);
#endif
    IOS;
    mst(dp,0x3f);
    cin>>n;
    for(int i=1,x; i<=n; i++)
    {
        cin>>x;
        sum[i]=sum[i-1]+x;
        dp[i][i]=0;
    }
    for(int len=2; len<=n; len++)
        for(int i=1; i+len-1<=n; i++)
        {
            int j=i+len-1;
            for(int k=i; k<j; k++)
                gmin(dp[i][j],dp[i][k]+dp[k+1][j]);
            dp[i][j]+=sum[j]-sum[i-1];
        }
    cout<<dp[1][n];
    return 0;
}


Measured memory_bytes: 1536
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string S=Console.ReadLine();
      int N=S.Length;
     int ans=0;
      for(int i=0;i<N;i++){
        int tmp=0;
        if(S.Substring(i,1)=="A"||S.Substring(i,1)=="T"||S.Substring(i,1)=="G"||S.Substring(i,1)=="C"){
          tmp++;
        for(int j=1;j<N-i;j++){
          if(S.Substring(i+j,1)=="A"||S.Substring(i+j,1)=="T"||S.Substring(i+j,1)=="G"||S.Substring(i+j,1)=="C"){
            tmp++;
          }else{
          break;
          }
        }if(tmp>ans){
          ans=tmp;
        }
        }
        
        
      }  
      Console.WriteLine(ans);
    }
    
  }

}


Measured memory_bytes: 25752
#include <iostream>
#include <cstring>

using namespace std;

int main() {
	int a, b, c, d, e, k;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cin >> e;
	cin >> k;
	if (a + k < e) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}
}

Measured memory_bytes: 256
from copy import deepcopy
from itertools import combinations, product

H, W, K = map(int, input().split())
board = []
for _ in range(H):
    row = input()
    row = [r == "#" for r in row]
    board.append(row)

all_h_comb = [()]
for r in range(1, H):
    comb_obj = combinations(range(H), r)
    all_h_comb += list(comb_obj)
all_w_comb = [()]
for c in range(1, W):
    comb_obj = combinations(range(W), c)
    all_w_comb += list(comb_obj)
all_comb = list(product(all_h_comb, all_w_comb))

res = 0
for comb in all_comb:
    r, c = comb
    tmp_board = deepcopy(board)
    for _r in r:
        tmp_board[_r] = [False] * W
    for _c in c:
        for b in tmp_board:
            b[_c] = False
    s = sum(sum(l) for l in tmp_board)
    if s == K:
        res += 1
print(res)

Measured memory_bytes: 9576
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int ar[n];
	for(int i=0;i<n;++i)
	{
		cin>>ar[i];
	}
	sort(ar,ar+n);
	int cnt=0;
	for(int i=0;i<n-2;++i)
	{
		for(int j=i+1;j<n-1;++j)
		{
			for(int k=j+1;k<n;++k)
			{
				if((ar[i]<(ar[j]+ar[k]))&&(ar[j]<(ar[i]+ar[k]))&&(ar[k]<(ar[i]+ar[j])))
					cnt++;

			}
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//
// https://atcoder.jp/contests/abc130/tasks/abc130_e

#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

static ll BASE = 1000000007;

ll good_mod(ll x) {
    return (x % BASE + BASE) % BASE;
}


int main(int argc, char* argv[]) {
    int N, M;
    cin >> N >> M;
    vector<int> Si;
    vector<int> Ti;
    for (int i = 0; i < N; i++) {
        int si;
        cin >> si;
        Si.push_back(si);
    }
    for (int i = 0; i < M; i++) {
        int ti;
        cin >> ti;
        Ti.push_back(ti);
    }
    vector<vector<ll>> dp(N+1, vector<ll>(M+1));
    for (int i = 0; i <= N; i++) {
        dp[i][0] = 1;
    }
    for (int i = 0; i <= M; i++) {
        dp[0][i] = 1;
    }
    for (int n = 1; n <= N; n++) {
        for (int m = 1; m <= M; m++) {
            dp[n][m] = good_mod(dp[n-1][m] + dp[n][m-1] - dp[n-1][m-1]);
            if (Si[n-1] == Ti[m-1]) {
                dp[n][m] = good_mod(dp[n][m] + dp[n-1][m-1]);
            }
        }
    }
    cout << dp[N][M] << endl;
}



Measured memory_bytes: 31616
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000009;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int main(){
	int d; cin >> d;
	cout << "Christmas";
	if (d == 22) {
		cout << " Eve Eve Eve" << endl;
	}
	else if (d == 23) {
		cout << " Eve Eve" << endl;
	}
	else if (d == 24) {
		cout << " Eve" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*
name:       Egyptian Tourist
PlatForm:   CodeForces/SPOJ...etc
LANG:       C++
DIV:        Training
TIME:       *
RATE:       *
*/

/*
Time Consumed:*
Problem Topics: *
*/

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

//-------------------------------------------------------//
#define rep(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define repr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define lp(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define lpr(i,n) for (int i = (n) - 1; ~i; i--)
#define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
//-------------------------------------------------------------------------------------//

#define clr(ar, val) memset(ar, val, sizeof(ar))
//----------------------------------------------//

#define inn freopen("in.in","r",stdin)
#define outt freopen("out.out","w",stdout)
#define PI 3.1415926535897932385
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define pob pop_back
#define bit(n) (1<<(n))
#define Last(i) ( (i) & (-i) )
#define all(v) ((v).begin()), ((v).end())
#define sq(x) ((x) * (x))
#define INF INT_MAX
#define Ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

//-------------------------------------------------------------//
#ifndef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1<<" | ";
    __f(comma+1, args...);
}
#else
#define debug(...)
#endif
#define _ist_ cout << "\nSTART OF INPUT DISPLAYING CHECK\n";
#define _iend_ cout << "\nEND OF INPUT DISPLAYING CHECK\n";
//------------------------------------------------------------//
#define mod (int)(1e9 + 7)
//#define N (int)2e5 + 5
#define N (int)1e5 + 5
//----------------------------------//
typedef pair<int, char> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
//---------------------------------//
template<class T, class T2>
T _f_pow(T a, T2 b)
{
    T res = 1LL;
    //a%=mod;
    while (b > 0)
    {
        if (b & 1)
            res = (res*a);//res = (res * a)%mod;
        a = (a * a);
        //a%=mod;
        b >>= 1;
    }
    return (res);
}
template<class T>
T gcd(T a, T b)
{
    while(a && b)
        if(a > b)
            (a%=b);
        else(b%=a);

    return a + b;
}
template<class T>
T lcm(T a, T b)
{
    return (a * b) / gcd(a, b);
}

int main()
{
    Ios;
    //inn;outt;
    //auto tt = clock();
    string arr[105];
    int n, l;
    cin >> n >> l;
    lp(i, n)
        cin >> arr[i];
    sort(arr, arr + n);
    string sol = "";
    lp(i, n)
        sol += arr[i];
    cout << sol << endl;
    //cout << (double(clock() - tt)/CLOCKS_PER_SEC * 1.00) << endl;
    //system("sleep 50");
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
ll n, x, mi;
vector<pair<P, P>> v;
bool check(ll s) {
    ll sum = mi;
    for (int i = 0; i < s / x; i++) {
        sum += v[i].first.first;
    }
    ll res = sum;
    if (s % x > 0 && s / x < n) {
        for (int i = 0; i < n; i++) {
            ll b = v[i].first.second, l = v[i].second.first,
               u = v[i].second.second;
            ll t;
            if (s % x <= b) {
                t = (s % x) * l;
            } else {
                t = b * l + (s % x - b) * u;
            }
            if (i < s / x) {
                chmax(res, sum - v[i].first.first + v[s / x].first.first + t);
            } else {
                chmax(res, sum + t);
            }
        }
    }
    return res >= 0;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> x;
    mi = 0;
    v.resize(n);
    for (int i = 0; i < n; i++) {
        ll b, l, u;
        cin >> b >> l >> u;
        mi -= b * l;
        v[i] = make_pair(P(l * b + u * (x - b), b), P(l, u));
    }
    sort(all(v));
    reverse(all(v));
    ll ng = -1LL, ok = n * x;
    while (ok - ng > 1LL) {
        ll mid = (ok + ng) / 2LL;
        if (check(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
}

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

//関数



    
//main関数
int main() {
    
    
    //入力
    long N,M;
    cin>>N>>M;
    
    
    
    //計算
    vector<long> A(100001);
    for(int i=0;i<M;i++){
        long a,b;
        cin>>a>>b;
        A.at(a)++;
        A.at(b)++;
    }
    
    bool pos=true;
    for(long i=0;i<100001;i++){
        if(A.at(i)%2!=0) pos=false;
    }
    
    
    
    
    //出力
    if(pos){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}



Measured memory_bytes: 1024
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int N;
int E[200001], n[200001], H[100001];
int kyori, kotae;
int dfs(int p, int mae, int d) {
	int kazu = 1;
	if (p == N) {
		kazu += 1 << 20;
		kyori = (d + 1) / 2;
	}
	for (int i = H[p]; i; i = n[i]) if (E[i] != mae) kazu += dfs(E[i], p, d + 1);
	if (kazu > (1 << 20) && d == kyori + 1) kotae = kazu - (1 << 20);
	return kazu;
}

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


	N = getint();
	int kari = 1;
	rep(i, N - 1) {
		int a = getint(), b = getint();
		E[kari] = b;
		n[kari] = H[a];
		H[a] = kari++;
		E[kari] = a;
		n[kari] = H[b];
		H[b] = kari++;
	}

	dfs(1, 0, 1);

	if (N - kotae > kotae) printf("Fennec");
	else printf("Snuke");

	Would you please return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int h,w;
  cin >> h >> w;
  double l,s;
  l=(h*30+w*0.5);
  s=w*6;
  
  double p=max(l-s,s-l);
  
  if(p!=180){
    if(p>180) p=360-p;
    p*=M_PI; 
    p/=180;
    double ans=a*a+b*b-2*a*b*cos(p);
    printf("%.25f\n",sqrt(ans));
  }
  
  else{
    cout << a+b << endl;
  }
}

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

int p[1000][1000]{};
int N;

bool check(int i, int j) {
    if (i >= N / 2) i = N - i - 1;
    if (j >= N / 2) j = N - j - 1;
    if (p[i][j] != p[N - i - 1][j]) return false;
    if (p[i][j] != p[i][N - j - 1]) return false;
    if (p[i][j] != p[N - i - 1][N - j - 1]) return false;
    return true;
}

int to_index(int r, int c) {
    if (r >= N / 2) r = N - r - 1;
    if (c >= N / 2) c = N - c - 1;
    return (N - 1) * r + c;
}

int main() {
    int C;
    cin >> C >> N;
    int D[C - 1];
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < N; j++) {
            p[i][j] = s[j] - '0';
        }
    }
    
    vector<pair<int, int>> q[C - 1];
    for (int i = 0; i < C - 1; i++) {
        cin >> D[i];
        for (int j = 0; j < D[i]; j++) {
            int r, c;
            cin >> r >> c;
            r--;
            c--;
            q[i].push_back(make_pair(r, c));
        }
    }
    int ans = 0;
    int c[N][N]{};
    set<int> s;
    for (int i = 0; i < N / 2; i++) {
        for (int j = 0; j < N / 2; j++) {
            if (!check(i, j)) s.insert(to_index(i, j));
        }
    }
    if (s.size() == 0) ans = 1;

    for (int i = 0; i < C - 1; i++) {
        for (int j = 0; j < D[i]; j++) {
            int r = q[i][j].first;
            int c = q[i][j].second;
            (p[r][c] == 1) ? p[r][c] = 0 : p[r][c] = 1;
            if (!check(r, c)) {
                s.insert(to_index(r, c));
            } else {
                if (s.count(to_index(r, c)) == 1) {
                    s.erase(to_index(r, c));
                }
            }
        }
        if (s.size() == 0) ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 25984
from itertools import combinations

while True:
    n,x =map(int,input().split())
    if n==x and n==0:
        break
    
    L = [i for i in range(1,n+1)]
    cnt = 0
    for i in list(combinations(L,3)):
        if  sum(list(i))==x:
            cnt+=1
    print(cnt)


Measured memory_bytes: 18432
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int F,G;
  if(C%B != 0){
    F = C/B;
    F++;
  }
  else{
    F = C/B;
  }
  if(A%D != 0){
    G = A/D;
    G++;
  }
  else{
    G = A/D;
  }
//  cout << F << " " << G << endl;
  if(F<=G){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

int main()
{
	int x , y ;
	for ( int i = 1;; i++ )
	{
		cin >> x >> y;
		if ( x > y )
		swap ( x , y );
	if ( x == 0 && y == 0 ) break;
	cout << x << " " << y << endl; 
	}
}

Measured memory_bytes: 1160
#include<cstdio>
#define maxn 100050
using namespace std;
struct enode{
	int y,nxt,z;
}e[maxn*2];
int tot=0;
int dis[maxn],first[maxn];
void adde(int x,int y,int z){
	e[tot].nxt=first[x];
	e[tot].y=y;
	e[tot].z=z;
	first[x]=tot++;
}
void dfs(int x,int fa){
	for (int i=first[x];i>=0;i=e[i].nxt){
		int y=e[i].y;
		if (y!=fa){
			dis[y]=(dis[x]+e[i].z)%2;
			dfs(y,x);
		}
	}
}
int main(){
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	first[i]=-1;
	for (int i=1;i<n;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		adde(x,y,z),adde(y,x,z);
	}
	dfs(1,0);
	for (int i=1;i<=n;i++)
	printf("%d\n",dis[i]);
	return 0;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
#define rep(i, x) for (ll i = 0; i < (x); i++)
#define chmax(x, a)  do { x = max(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main(void) {
  ll l, r, d, ans=0;
  cin >> l >> r >> d;
  for (ll i = l; i <= r ; i++)
    if ((i % d) == 0)
      ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define f(i,st,n) for(i=st;i<n;i++)
#define vec vector
#define mst(a,b) memset(a,b,sizeof(a))
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define sfl(x) scanf("%lld",&x)
#define pfl(x) printf("%lld\n",x)
#define pf(x) printf("%lld",x)
#define all(v) v.begin(),v.end()
#define mpr make_pair
#define fs first
#define se second
#define inf LLONG_MAX
#define nnf LLONG_MIN
 
 
 
ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }                     
    return gcd(b%a,a);
}
ll power(ll x,ll y){            
    ll res=1;
    while(y>0){
        if(y%2==1){
            res=((res%mod)*(x%mod))%mod;
        }
        x=((x%mod)*(x%mod))%mod;
        y=y/2;
    }
    return res;
}
 
 struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(pair<uint64_t,uint64_t> x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);
  }
};

void get_time(auto start,auto end){
    double time_taken =  
      chrono::duration_cast<chrono::nanoseconds>(end - start).count(); 
  
    time_taken *= 1e-9;
    cout<<"\n";
    cout<<"Time taken : "<<fixed<<time_taken<<setprecision(6);
}

const int block=1420;

ll c[500002],a[500002];

struct query{
 
    ll l,r,id;
    query(){}
 
    query(ll l,ll r,ll id){
      this->l=l;
      this->r=r;
      this->id=id;
    }
};
bool cmp(query x,query y){
  if(x.l/block!=y.l/block)return x.l/block<y.l/block;
 
  return (x.l/block&1)?x.r<y.r:x.r>y.r;
}


int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

  auto start = chrono::high_resolution_clock::now();

  
 

/* #ifndef ONLINE_JUDGE
    
   freopen("input.txt", "r", stdin);
   
   freopen("output.txt", "w", stdout);
   #endif
*/

   ll n,l,r,i,j,q;

   cin>>n>>q;

   f(i,0,n)cin>>a[i];



   query qr[q];

   
    f(i,0,q){
 
        cin>>l>>r;
        l--;
        r--;
        qr[i]=query(l,r,i);
        
    }

    sort(qr,qr+q,cmp);
   
    ll cl=0,cr=-1,d=0,ans[q];
 
    f(i,0,q){
 
      ll l=qr[i].l,r=qr[i].r;
 
      while(cl>l){
        cl--;
        c[a[cl]]++;
        if(c[a[cl]]==1)d++;
      }
      while(cr<r){
        cr++;
        c[a[cr]]++;
        if(c[a[cr]]==1)d++;
      }
      while(cl<l){
        c[a[cl]]--;
        if(c[a[cl]]==0)d--;
        cl++;
      }
      while(cr>r){
        c[a[cr]]--;
        if(c[a[cr]]==0)d--;
        cr--;
      }
      ans[qr[i].id]=d;
    }
    f(i,0,q)cout<<ans[i]<<"\n";


   



  auto end = chrono::high_resolution_clock::now();

 /* #ifndef ONLINE_JUDGE

   get_time(start,end); 

  #endif*/

    return 0;
 }

Measured memory_bytes: 27272
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <random>
#include <set>
 
using namespace std;

typedef long long ll;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()

mt19937 rnd(1337);

int main() {
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    multiset<int> s;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].f >> v[i].s;
    }
    sort(v.begin(), v.end());
    int i = 0;
    ll ans = 0;
    for (int day = 1; day <= m; ++day) {
        while (i < n && v[i].f <= day) {
            s.insert(v[i].s);
            i++;
        }
        if (!s.empty()) {
            auto it = s.end();
            --it;
            ans += (*it);
            s.erase(it);
        }
    }
    cout << ans;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

vector<string> ss;

void build_std(int n, int k, string s)
{
	if(sz(s) == n)
	{
		ss.push_back(s);
		return;
	}
	rep(i, k)
	{
		char c = char('a'+ i);
		string next = s;
		next.push_back(c);
		build_std(n, k, next);
	}
	string next = s;
	char c = char('a'+ k);
	next.push_back(c);
	build_std(n, k + 1, next);
	return;
}

void solve()
{
	int n; cin >> n;
	build_std(n,0,"");
	sort(all(ss));
	rep(i ,sz(ss))cout << ss[i] << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 7796
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
//ll n,m,k;/*"//......"means the first code:WA
int n,m;
int a[100010],b[100010];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	cin>>n>>m;
//	if(n&1) for(ll i=1;i<=m;i++){
//		k=(n/2)-i+1;
//		cout<<k<<' '<<n-k<<'\n';
//	}
//	else for(ll i=1;i<=m;i++){
//		k=(n/2)-i+1;
//		if(n-k+1-k==n/2){
//			m+=1;
//			continue;
//		}
//		cout<<k<<' '<<n-k+1<<'\n';
//	}
	cin>>n>>m;
	for(int i=0;i<m;i++)a[i]=i+1,b[i]=n-i;
	if((n&1)==0) for(int i=n/4;i<m;i++)b[i]--;
	for(int i=0;i<m;i++)cout<<a[i]<<' '<<b[i]<<'\n';
	return 0;
}


Measured memory_bytes: 4232
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

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

int main(){
    int n;
    cin >>n;
    str S;
    cin >> S;
    S.erase(unique(S.begin(),S.end()),S.end());
    cout << S.size() << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdbool.h>
int gcd(int a, int b){return b?gcd(b,a%b):a;}
int N, A, B[1<<20];
bool p[1<<20], flg = true;
int main(){
	scanf("%d%d", &N, &A);
	int t = A;
	B[A]++;
	for(int i=1; i<N; i++){
		scanf("%d", &A);
		t = gcd(t, A);
		B[A]++;
	}
	for(int i=2; i<(1<<20); i++)p[i] = true;
	for(int i=2; i<(1<<20); i++){
		if(p[i]){
			int cnt = B[i];
			for(int j=2*i; j<(1<<20); j+=i){
				p[j] = false;
				cnt += B[j];
			}
			if(cnt > 1)flg = false;
		}
	}
	if(flg){
		puts("pairwise coprime");
	}else if(t == 1){
		puts("setwise coprime");
	}else {
		puts("not coprime");
	}
	return 0;
}

Measured memory_bytes: 6580
#include<bits/stdc++.h>
using namespace std;
int black=0;
int main(){
  int H,W,K;
  cin>>H>>W>>K;
  vector<string>G(H);
  for(int i=0;i<H;i++){
    cin>>G[i];
  }

  vector<int>WD(W,0);
  vector<int>HD(H,0);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(G[i][j]=='#'){
        black++;
        WD[j]++;
        HD[i]++;
      }
    }
  }
  //cout<<black<<endl;
  //cout<<HD[0]<<endl;
  map<pair<int,int>,int>mp;
  int ans=0;
  int res=0;
  for(int bit=0;bit<(1<<H);bit++){
    for(int bit2=0;bit2<(1<<W);bit2++){
      int ans=black;
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          //cout<<"AA"<<endl;
          if((bit&(1<<i))||(bit2&(1<<j))){
            //int ans=black-HD[i]-WD[j];
            //if(G[i][j]=='#')ans++;
            
            if(G[i][j]=='#'){
              ans--;
              //cout<<i<<" "<<j<<endl;
            }
            
            // if(ans==K){
            //   mp[make_pair(bit,bit2)]++;
            //   res++;
             //cout<<bit<<" "<<bit2<<" "<<ans<<endl;
            // }
          }
        }
      }
      if(ans==K){
        mp[make_pair(bit,bit2)]++;
        res++;
      //cout<<bit<<" "<<bit2<<" "<<ans<<endl;
      }
    }
  }
  cout<<mp.size()<<endl;
  }
 

Measured memory_bytes: 3676
// Created by js0805
#include <bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
using ll = long long;
void solve() {
	int n;
	cin >> n;
	int p[n][3];
	for (int i = 0; i < n; i++) {
		cin >> p[i][0];
		cin >> p[i][1];
		cin >> p[i][2];
	}
	int dp[n][3];
	dp[0][0] = p[0][0];
	dp[0][1] = p[0][1];
	dp[0][2] = p[0][2];
	for (int i = 1; i < n; i++) {
		dp[i][0] = p[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = p[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = p[i][2] + max(dp[i - 1][1], dp[i - 1][0]);

	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));



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

Measured memory_bytes: 5932
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 4005;
const int MM = 998244353;

typedef bitset<MX> Integer;
void print(Integer P);

bool divide(Integer X, Integer Y, Integer &P, Integer &Q)
{
	Integer Z = X;
	P.reset();
	int high = MX-1;
	for(; high >= 0; high--) if(Y[high]) break;
	for(int i = MX-high-1; i >= 0; i--){
		if( X[i+high] ){
			X ^= Y<<i;
		}
		if( Z[i+high] ){
			Z[i+high] = 0;
			P[i] = 1;
		}
	}
	Q = X;
	print(Z);
	print(Q);
	for(int i = high-1; i >= 0; i--) if( Q[i] ) return Z[i];
	return true;
}

char buf[MX];

Integer gcd(Integer A, Integer B){
	Integer C, D;
	divide(A, B, C, D);
	if( D.none() ) return B;
	else return gcd(B, D);
}

Integer input(){
	Integer X; X.reset();
	scanf("%s", buf);
	int L = strlen(buf);
	for(int i = 0; buf[i]; i++) X[L-i-1] = buf[i]-'0';
	return X;
}

void print(Integer P){
//	for(int i = 0; i < 10; i++) printf("%d", !!P[i]); printf("\n");
}

int main()
{
	int N;
	Integer X, A[10];
	X.reset();
	scanf("%d", &N);
	X = input();
	for(int i = 1; i <= N; i++){
		A[i] = input();
		print(A[i]);
	}

	Integer G = A[1];
	for(int i = 2; i <= N; i++) G = gcd(G, A[i]);
	print(G);

	Integer tmp, t2;
	int ans = 0, flag = 0;
	flag = divide(X, G, tmp, t2);
	for(int i = MX-1; i >= 0; i--){
		ans = (ans * 2 + tmp[i]) % MM;
	}
	printf("%d\n", (ans+flag)%MM);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end() //使うときはsort(all())という感じで
using ll = long long;

int main(){
  int n;
  cin>>n;
  vector<int> b(n+1,0); //1~n-1
  vector<int> a(n,0); //0~n-1
  rep(i,n-1){
    cin>>b[i+1];
  }
  b[n]=b[n-1];
  ll ans=0;
  a[0]=b[1];
  rep(i,n-1){
    if(b[i+2]>=b[i+1]){
      a[i+1]=b[i+1];
    }
    else{
      a[i+1]=b[i+2];
    }
  }
  rep(i,n){
    ans+=a[i];
  }
  cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

int main() {
    FIO;
    ll n, d;
    cin >> n;
    string s = "";
    while(n > 0) {
        n--;
        s += ('a' + n % 26);
        n = n / 26;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;

}




Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
        int k;
		string n;
        cin>>k;
		cin>>n;
		if(n.size()<=k)cout<<n<<endl;
		else {
			for(int i=0;i<k;i++){
				cout<<n.at(i);
			}
			cout<<"..."<<endl;
		}
		return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  priority_queue<P> que, que2;
  priority_queue<P, vector<P>, greater<P>> que3;

  for(int i = 0; i < A; i++){
    int x;
    cin >> x;
    que.push(P(x, 1));
  }
  for(int i = 0; i < B; i++){
    int x;
    cin >> x;
    que.push(P(x, 2));
  }
  for(int i = 0; i < C; i++){
    int x;
    cin >> x;
    que2.push(P(x, 0));
  }

  ll ans = 0;
  while(X > 0 || Y > 0){
    int px, py;
    px = que.top().first;
    py = que.top().second;
    que.pop();

    if(py == 1){
      if(X > 0){
        ans += (ll)px;
        X--;
        que3.push(P(px, 1));
      }
    }
    if(py == 2){
      if(Y > 0){
        ans += (ll)px;
        Y--;
        que3.push(P(px, 1));
      }
    }
  }

  while(true){
    if(que2.empty()) break;
    int pxx = que2.top().first;
    int pyy = que2.top().second;
    int px, py;
    px = que3.top().first;
    py = que3.top().second;
    if(pxx > px){
      ans -= px;
      ans += pxx;
      que2.pop();
      que3.pop();
    }
    else break;
  }

  cout << ans << endl;

}


Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;
 
int a, b;
 
int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> a >> b;
	cout << b*2-a << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

int main(int argc, char const *argv[])
{
	int N;
	cin >> N;

	std::vector<ll> A(N);
	int mcount = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		if (A[i] < 0)
		{
			mcount += 1;
		}
	}

	ll ans = 0;
	ll sum = 0;
	for (int i = 0; i < N; i++)
	{
		sum += abs(A[i]);
	}

	ll min_ = 1e15;
	if (mcount % 2 == 0)
	{
		ans = sum;
	}
	else{
		for (int i = 0; i < N; i++)
		{
			min_ = min(min_,abs(A[i]));
		}
		ans = sum - 2*min_;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<long long, long long>;
const int INF = 1001001007;
const int mod = 1000000007;

int main(){
    ll n, m; cin >> n >> m;
    vector<int> ar(n);
    rep(i,n) cin >> ar[i];
    vector<int> le(n);
    vector<int> ri(n);
    repl(i,n){
        int a = 0;
        repl(j,i){
            if (ar[j] > ar[i]) a++;
        }
        int b = 0;
        reppl(j,n,i+1){
            if (ar[j] > ar[i]) b++;
        }
        le[i] = a; ri[i] = b;
    }
    ll sle = 0; ll sri = 0;
    rep(i,n){
        sle += le[i];
        sri += ri[i];
    }
    ll ale = (m * (m+1) / 2 % mod) * sle % mod;
    ll ari = (m * (m-1) / 2 % mod) * sri % mod;
    cout << (ale + ari) % mod << endl;
}

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

int main()
{
    int n; cin >> n;
    vector<int> h(n),dp(n);

    for (int i=0;i<n;i++) cin >> h[i];
    
    dp[0]=0;
    for (int i=1;i<n;i++)
    {
        dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        if (i>1 && dp[i] > dp[i-2]+abs(h[i-2]-h[i])) dp[i]=dp[i-2]+abs(h[i-2]-h[i]);
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
 
using namespace std;
 
#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238
 
typedef pair<int, int> P;
 

void solve(long long N, std::vector<P > A){
    sort(all(A));
    REP(i,N){
        if(i!=N-1) cout<<A[i].second<<" ";
    }
    cout<<A[N-1].second<<endl;
}
 
signed main(){
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
    long long N;
    scanf("%lld",&N);
    vector<P > A(N);
    for(int i = 0 ; i < N ; i++){
        cin>>A[i].first;
        A[i].second = i+1;
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
constexpr long INF = 1L << 62;
constexpr int MOD = 1e9 + 7;


int main() {
    ios::sync_with_stdio(false); cin.tie(0);
 
    long n, m; cin >> n >> m;
    vector<pair<long,long>> ab;
    REP(i,n) {
        long a, b;
        cin >> a >> b;
        ab.emplace_back(a, b);
    }
    sort(ab.begin(), ab.end());
 
    priority_queue<long> pq;
    long ans = 0, cnt = 0, idx = 0;
    for(int i = 1; i <= m; ++i) {
        while(ab[idx].first == i && idx < ab.size()) pq.push(ab[idx++].second);
        if(pq.size()) {
            ans += pq.top(); 
            pq.pop();
        }
    }
 
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3696
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int a,b,c;
	cin>>a>>b>>c;
	int Max=max(max(a,b),c);
	if (2*Max==a+b+c){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,x,y,z,m,n,t,a,b,c,l,r,q;
    cin>>n;
    string s;
    while(n)
    {
        n--;
        x=n%26;
        s+=x+'a';
        n/=26;
    }
    reverse(s.begin(),s.end());
    cout<<s<<'\n';
}








Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
typedef pair<ll, int> P;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
struct edge {int u, v; ll cost;};
int par[100005]; //親
int tree_rank[100005]; //木の深さ
int N, M;
ll T, A[100005];
edge es[200005];

void init_union_find(int n){
  rep(i, n){
    par[i] = i;
    tree_rank[i] = 0;
  }
}

bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}

// 木の根を求める
int find(int x){
  if (par[x] == x) return x;
  else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite(int x, int y){
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (tree_rank[x] < tree_rank[y]) par[x] = y;
  else{
    par[y] = x;
    if (tree_rank[x] == tree_rank[y]) tree_rank[x]++;
  }
}

// xとyが同じ要素に属するかどうか
bool same(int x, int y){
  return find(x) == find(y);
}

ll kruskal() {
  sort(es, es+2*N-2, comp);
  init_union_find(N);
  ll res = 0ll;
  rep(i, 2*N-2){
    edge e = es[i];
    if (!same(e.u, e.v)) {
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

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

  cin >> N;
  ll x, y;
  vector<P> X, Y;
  rep(i, N) {
    cin >> x >> y;
    P px = make_pair(x, i);
    P py = make_pair(y, i);
    X.push_back(px);
    Y.push_back(py);
  }
  sort(ALL(X));
  sort(ALL(Y));
  rep(i, N-1) {
    edge e = { X[i].second, X[i+1].second, X[i+1].first - X[i].first };
    es[i] = e;
  }
  rep(i, N-1) {
    edge e = { Y[i].second, Y[i+1].second, Y[i+1].first - Y[i].first };
    es[i+N-1] = e;
  }

  ll ans = kruskal();
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 8292
#include<stdio.h>

typedef struct{
  int n;
  int count;
}hoge;
hoge s[13];
int sn;
int main(){
  int seq[13],n,i,j,k,fix;
  do{
    scanf("%d",&n);
    if(n==0) break;
    for(i=0;i<n;i++) scanf("%d ",seq+i);
    for(i=0;;i++){
      for(j=0;j<n;j++)
      fix=1;
      for(j=0;j<n;j++){
	for(k=0;k<sn;k++){
	  if(s[k].n==seq[j]){
	    s[k].count++;
	    break;
	  }
	}
	if(k==sn){
	  s[sn].n=seq[j];
	  s[sn].count=1;
	  sn++;
	}
      }
      for(j=0;j<n;j++){
	for(k=0;k<sn;k++){
	  if(s[k].n==seq[j]){
	    if(seq[j]!=s[k].count) fix=0;
	    seq[j]=s[k].count;
	    break;
	  }
	}
      }
      sn=0;
      if(fix) break;
    }
    printf("%d\n",i);
    for(i=0;i<n-1;i++){
      s[i].n=s[i].count=-1;
      printf("%d ",seq[i]);
    }
    printf("%d\n",seq[i]);
  }while(1);
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
    std::ios::sync_with_stdio(false);
    int n,a,b;
    while (cin>>n>>a>>b) {
        if (n*a>b) {
            cout<<b<<endl;
        }
        else
            cout<<n*a<<endl;
    }
    
    
   
    
    return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define gcda(x,y) gcd(abs(x),abs(y))

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int main(){
    int n;
    cin >> n;
    map<int,int> count;
    REP(i,n){
        int a;
        cin >> a;
        count[a] ++;
    }
    ll sum = 0;
    for(auto iter = count.begin(); iter != count.end(); iter ++){
            int x = iter->first;
            int y = iter->second;
            sum += x*y;
    }
    
    int Q;
    cin >> Q;
    REP(geign,Q){
        int b,c;
        cin >> b >> c;
        count[c] += count[b];
        sum += count[b]*(c-b);
        count[b] = 0;

        cout << sum << endl;
    }
}


Measured memory_bytes: 7868
#include<stdio.h>
int main(void){
  int n, q, temp, i, j;
  int a[2001] = {1};
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &temp);
    for(j=2000-temp;j>=0;j--){
      if(a[j]) a[j + temp] = 1;
    }
  }
 
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d", &temp);
    if(a[temp]) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
        

Measured memory_bytes: 588
#include<bits/stdc++.h>
using namespace std;
//random range:1e5
int n,m,x,p[12];
bool f[1<<12],b[12][12];
char a[12][12];
int main(){
	random_device ra;
	mt19937 gen(ra());
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) p[i]=i;
	for(int i=0;i<n;i++) scanf("%s",a[i]);
	int y=CLOCKS_PER_SEC*15;
	for(int ite=1;ite<=100000;ite++){
		shuffle(p,p+n,gen);
		memset(b,1,sizeof(b));
		for(int i=0;i<m;i++) for(int j=i;j<m;j++) for(int k=0;k<n;k++)
			if(a[p[k]][i]!=a[p[n-k-1]][j])
				b[i][j]=0;
		memset(f,0,sizeof(f));
		f[0]=1;
		for(int k=0;k<(1<<m);k++) if(f[k])
			for(int i=0;i<m;i++) for(int j=i+1;j<m;j++)
				if(!(1<<i&k)&&!(1<<j&k)&&b[i][j])
					f[k|(1<<i)|(1<<j)]=1;
		bool chk=0;
		if(!(m&1))
			chk=f[(1<<m)-1];
		else for(int i=0;i<m;i++)
			chk|=f[(1<<m)-1-(1<<i)];
		if(chk) {
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll dp[101][100001];
int main(){
    int n,W,v[100],w[100];
    cin>>n>>W;
    rep(i,n) cin>>w[i]>>v[i];
    fill(dp[0],dp[0]+100001,1e9+1);
    dp[0][0]=0;
    rep(i,n)rep(j,100001){
        if(j>=v[i]) dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
        else dp[i+1][j]=dp[i][j];
    }
    int ans=0;
    rep(i,n)rep(j,100001) if(dp[i+1][j]<=W) ans=max(ans,j);
    cout<<ans;
}

Measured memory_bytes: 79104
#include <stdio.h>
#define MAX 100

int main(void){
  
  int len,key,i,j,f;
  int A[MAX];
  
  scanf("%d",&len);
  for(i=0;i<len;i++)
    scanf("%d",&A[i]);
  
  for(i=1;i<len;i++)
    printf("%d ",A[i-1]);
  printf("%d\n",A[i-1]);
  
  for(j=1;j<len;j++){
    key = A[j];
    i = j - 1;
    while(i >= 0 && A[i] > key){
      A[i+1] = A[i];
      i = i - 1;
      A[i+1] = key;
    }
    for(f=1;f<len;f++)
      printf("%d ",A[f-1]);
    printf("%d\n",A[f-1]);
  }
  return 0;
}

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

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

int n, m;
// graph[i][j] := 辺(i, j)が存在するか
// visit[k] := 頂点 k へ訪問済か
bool graph[55][55] = {};
bool visit[55] = {};

void dfs(int v) {
  if(visit[v]) return;
  else visit[v] = true;
  rep(i, n) {
    if(graph[v][i]) dfs(i);
  }
}

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

  cin >> n >> m;
  int u[55], v[55];
  rep(i, m) {
    cin >> u[i] >> v[i];
    u[i]--, v[i]--;
    // 無向グラフ
    graph[u[i]][v[i]] = graph[v[i]][u[i]] = true;
  }

  int ans = 0;
  rep(i, m) {
    // 辺を1本ずつ消して連結か確かめる
    graph[u[i]][v[i]] = graph[v[i]][u[i]] = false;
    rep(i, n) visit[i] = false;

    dfs(0);

    bool flag = false;
    rep(j, n) {
      if(!visit[j]) flag = true;
    }
    if(flag) ans++;

    graph[u[i]][v[i]] = graph[v[i]][u[i]] = true;
  }

  cout << ans << '\n';
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  int p; p = s.size();
  int c = 0;
  for (int i=0; i< p;i++){
    for (int j=0;j <p;j++){
      if (s[i] == s[j])c++;
    }
    if (c%2 == 1){
      cout << "No" << endl;
      return 0;
    }
    c=0;
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256