akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


string s;
Int n, k;


class SuffixArray
{
private:
    string *text;
    int length;
    int *index;
    string *suffix;
public:
    SuffixArray(string text)
        {
            this->text = new string[text.length()]; 
            for (int i = 0; i < text.length(); i++)
            {
                this->text[i] = text.substr(i, 1);
            } 
            this->length = text.length();
            this->index = new int[length];
            for (int i = 0; i < length; i++)
            {
                index[i] = i;
            }	
            suffix = new string[length];
        }
 
    vector<int> createSuffixArray()
        {
            vector<int> v;
            for(int index = 0; index < length; index++)	
            {
                string text = "";
                for (int text_index = index; text_index < length; text_index++)
                {
                    text += this->text[text_index];
                } 
                suffix[index] = text;
            }
            int back;
            for (int iteration = 1; iteration < length; iteration++)
            {
                string key = suffix[iteration];
                int keyindex = index[iteration];
                for (back = iteration - 1; back >= 0; back--)
                {
                    if (suffix[back].compare(key) > 0)
                    {
                        suffix[back + 1] = suffix[back];
                        index[back + 1] = index[back];
                    }
                    else
                    {
                        break;
                    }
                }
                suffix[back + 1] = key;
                index[back + 1 ] = keyindex;
            }

            for (int iterate = 0; iterate < length; iterate++)
            {		
                v.push_back(index[iterate]);
            }
            return v;
        }
};

int main(){
    cin >> n >> k;
    cin >> s;
    for(int i= n-1;i >= 0;i--)s += s[i];
    SuffixArray suffixarray(s);
    auto v = suffixarray.createSuffixArray();
    int p = 0;
    while(v[p] >= n)p++;
    p = v[p];
    string hoge = "";
    for(int i = 0;i < n;i++)hoge += s[p+i];
    int start = 0;
    while(start < n && hoge[start] == hoge[0])start++;
    int start2 = start;
    for(int i = 0;i < k-1;i++){
        start *= 2;
        if(start > n){
            start = n;
            break;
        }
    }
    for(int i = 0;i < start;i++){
        cout << hoge[0];
    }
    for(int i = start;i < n;i++){
        cout << hoge[start2 + i - start];
    }cout << endl;
        
    return 0;
}

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

using namespace std;

int main(){

	int h, w;
	vector< vector<char> > board;

	cin>> h >> w;
	board.resize(h+2);

	for(int i=0;i<h+2;i++) board[i].resize(w+2);

	for(int i=0;i<h+2;i++){
		for(int j=0;j<w+2;j++){
			if(i==0 || j==0 || i==h+1 || j==w+1){
				board[i][j]='#';
			}else{
				cin>> board[i][j];
			}
		}
	}

	for(int i=0;i<h+2;i++){
		for(int j=0;j<w+2;j++){
			cout<< board[i][j];
		}
		cout<< endl;
	}

}

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

#define pb push_back
#define ll long long
#define mp make_pair

int main()
{	
	// #ifndef ONLINE__JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	std::ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	ll n, k;
	cin >> n >> k;
	vector <ll> a(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];

	vector <ll> dp(n, INT_MAX);
	dp[0] = 0;
	for(int i = 1; i <= k; i++)
		dp[i] = abs(a[i] - a[0]);

	for(int i = k + 1; i < n; i++)
	{
		ll min_ = INT_MAX;
		for(int j = i - k; j < i; j++)
		{
			ll temp = abs(a[j] - a[i]) + dp[j];
			dp[i] = min(temp, dp[i]);
		}
	}	cout << dp[n - 1];
}

Measured memory_bytes: 1792
import sys

def solve():
    x = int(input())

    t = 1

    while calc_sum(t) < x:
        t += 1

    print(t)

def calc_sum(t):
    return t * (t + 1) // 2

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    string ans;

    if(b <= a) {
        ans = "delicious";
    } 
    else if(b <= a+x) {
        ans = "safe";
    }
    else {
        ans = "dangerous";
    }

    cout << ans;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
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; }
const ll INF = 1LL << 60;
const ll mod = 1000000007;

ll N;
ll W, weight[110], value[110];

ll dp[110][100100]={0};

int main(){
	//乱数srand((unsigned)time(NULL));
	//入力
	cin>>N>>W;
	rep(i,N)cin>>weight[i]>>value[i];
	
	
	//dpテーブル埋め
	rep(i,N){
		rep(j,W+1){
			if(j-weight[i]>=0){
				chmax(dp[i+1][j],dp[i][j-weight[i]]+value[i]);
			}
			
			chmax(dp[i+1][j],dp[i][j]);
		}
	}
	
	cout<<dp[N][W]<<endl;
}

Measured memory_bytes: 79360
#include<bits/stdc++.h>
#define ld  double
#define ll long long 
#define pp push
#define pb push_back
#define pf push_front
#define mp make_pair
#define inf 1e9
#define f first
#define s second
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define mod 1000000007
using namespace std;
ll n;
ld p[3010];
int vis[3010][3010];
ld dp[3010][3010];
ld prob(ll nn,ll heads)
{
    if(heads < 0) return 0.0;

	if(nn == 0)
	{
	    if(heads==0)
	    return 1.0;
	    else return 0.0;
	}

    if(vis[nn][heads]==1)return dp[nn][heads];
    vis[nn][heads]=1;
    return dp[nn][heads]=prob(nn-1,heads)*(1.0-p[nn])+prob(nn-1,heads-1)*p[nn];
}
ld solve()
{
    ld ans=0.0;
    for(ll i=0;i<=n;i++)
    {
        ll tails=n-i;
        if(i>tails)ans+=prob(n,i);
    }
    return ans;
}
int main()
{
    cin>>n;
    for(ll i=1;i<=n;i++)cin>>p[i];
    printf("%.9lf\n",solve());
}

Measured memory_bytes: 106240
#pragma GCC optimize("Ofast")   //Comment optimisations for an interative problem/use endl
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;  
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss;  
typedef vector<pll> vpll; 
typedef vector<ll> vll; 
typedef vector<vll> vvll; 
typedef unordered_map<ll,ll> um;

#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define sqr(x) ((ll)(x) * (x)) 
#define reset(a, b) memset(a, b, sizeof(a)) 
#define f first 
#define s second 
#define mp make_pair 
#define pb push_back 
#define all(v) v.begin(), v.end() 
#define alla(arr, sz) arr, arr + sz 
#define showv(v) for(auto it: (v))cout<<it<<" ";newl;
#define newl cout<<"\n"

const ll MAXN=1e+2+7;
const ll MOD=1e+9+7, INF=0x7f7f7f7f7f7f7f7f;const int INFi=0x7f7f7f7f;
double EPS = 1e-9;  
double PI = acos(-1); 

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
ll t,n;
ll i,j;
 
//<<-----Implement Functions Here---->>//
 
 
//<<-----Start of Main--------------->>//

int main()
{

	

	cin >> n >> t;
	if(n==t)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

N = getN()

if N == 1:
    print("Hello World")

if N ==2:
    A = getN()
    B = getN()
    print(A+B)

Measured memory_bytes: 3060
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
long long int x[100001];
long long int v[100001];
long long int N,C;

int main()
{
  long long int m=-1,ind,lroad[100001],rroad[100001],left[100001],right[100001];
  cin >> N >> C;
  for(int i=0;i<N;i++)cin >> x[i] >> v[i];
  REP(i,N){
    if(i != 0)
      left[i] = left[i-1] + v[i] - abs(x[i] - x[i-1]);
    else
      left[i] = v[i] - x[i];
    m = max(left[i],m);
  }
  for(int i=N-1;i>=0;i--){
    if(i != N-1){
      right[i] = right[i+1] + v[i] - abs(x[i] - x[i+1]);
    }else{
      right[i] = v[i] - abs(C-x[i]);
    }
    m = max(right[i],m);
  }
  
  REP(i,N){ 
      lroad[i] = x[i];
      rroad[i] = (C - x[i]);
      
  }

  
  long long int dp[100001],dp2[100001],dp3[100001];
  if(N >= 2){
    dp[N-2] = right[N-1];
    dp2[N-2] = rroad[N-1];
    dp3[N-2] = dp[N-2] - dp2[N-2];
  }
  for(int i=N-3;i>=0;i--){
    dp[i] = max(right[i+1],dp[i+1]);
    if(dp[i] != dp[i+1])
      dp2[i] = rroad[i+1];
    else
      dp2[i] = dp2[i+1];
    dp3[i] = max(dp[i] - dp2[i],dp3[i+1]);
  }
  REP(i,N-1){
      m = max(left[i] - lroad[i] + dp[i],m);
      m = max(left[i] + dp3[i] ,m);
  }
  m = max(m,(long long int)0);
  cout << m << endl;
  return 0;
  
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long A, long long B, long long C, long long K) {
  if (K <= A) {
    cout << K << endl;
    return;
  }
  K -= A;
  if (K <= B) {
    cout << A << endl;
    return;
  }
  K -= B;
  cout << A - K << endl;
}

signed main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  long long K;
  scanf("%lld", &K);
  solve(A, B, C, K);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


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

static const int N=100;
static const int INFTY=(1<<21);

int n,m[N][N];
int d[N];

void dfs(int a){
  queue<int> q;
  q.push(a);
  for(int i=0;i<n;i++) d[i]=INFTY;
  d[a]=0;
  int b;
  while(!q.empty()){
    b=q.front();
    q.pop();
    for(int j=0;j<n;j++){
      if(m[b][j]==0) continue;
      if(d[j]!=INFTY) continue;
      d[j]=d[b]+1;
      q.push(j);
    }
  }
  for(int i=0;i<n;i++) cout << i+1 << " " << ((d[i]==INFTY) ? (-1) : d[i]) << endl;
}

int main(){
  int u,k,v;

  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) m[i][j]=0;
  }

  for(int i=0;i<n;i++){
    cin >> u >> k;
    u--;
    for(int j=0;j<k;j++){
      cin >> v;
      v--;
      m[u][v]=1;
    }
  }
  dfs(0);
  return 0;
}


Measured memory_bytes: 3104
Scanf.(Array.(scanf " %d" @@ fun n ->
  let a = make 9233 false in
  let col n = if n mod 2 = 0 then n/2 else 3*n+1 in
  let rec f i x = if a.(x) then i else
    (a.(x) <- true; f (i+1) (col x))
  in print_int @@ f 1 n))

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 105;
const int MOD = 1e9 + 7;
int n, h[N];
int qpow(int x, int k) {
    int r = 1;
    while(k) {
        if(k & 1) r = (ll)r * x % MOD;
        x = (ll)x * x % MOD;
        k >>= 1;
    }
    return r;
}
typedef pair<int, int> pii;
pii dfs(int l, int r) {
    int mn = 2e9, mc = 0;
    for(int i = l; i <= r; i++) {
        if(h[i]) {
            if(mn == h[i]) mc++;
            else if(mn > h[i]) mc = 1;
            mn = min(mn, h[i]);
        }
    }
    // printf("mc:%d mn:%d\n", mc, mn);
    vector<pii> res;
    int st = -1, t = 0;
    for(int i = l; i <= r; i++) {
        h[i] -= mn;
        if(h[i]) {
            if(st == -1) st = i, t = 1;
            else {
                t++;
            }
        } else {
            if(t) {
                res.push_back(dfs(st, st + t - 1));
                t = 0;
                st = -1;
            }
        }
    }
    if(t) {
        res.push_back(dfs(st, st + t - 1));
    }
    ll o1 = qpow(2, mc), o2 = qpow(2, mn);
    ll r1 = o1, r11 = o2 - 2, ret2 = o2;
    for(pii p : res) {
        ret2 = ret2 * p.second % MOD;
        r1 = r1 * (p.first + p.second) % MOD;
        r11 = r11 * p.second % MOD;
    }
    // printf("%d  %d  mn:%d  mc:%d  ret1:%d  ret2:%d\n", l, r, mn, mc, ret1, ret2);
    return pii((r1 + r11) % MOD, ret2);
}
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    pii res = dfs(0, n - 1);
    cout << res.first % MOD << endl;
    return 0;
}

Measured memory_bytes: 256
/*Arnab's Code
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define vii vector<int>
#define pll pair<ll,ll>
#define pii pair<int,int>/*Arnab's Code
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define vii vector<int>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define take(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define takes(a,n,st) for(ll i=st;i<n+st;i++)cin>>a[i]
ll sum(ll a[],ll n,ll s){ for(ll i=0;i<n;i++)s+=a[i]; return s;}
#define mod 1000000009
ll power(ll x, ll y, ll p)  {  
    ll res = 1;  
    x = x % p;   
    if (x == 0) return 0;  
    while (y > 0){  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll a[200017];
void solve(){
	ll n,curm,i,tot;
	tot=0;
	cin>>n;
	take(a,n);
	curm=a[0];
	for(i=1;i<n;i++){
		if(a[i]>=curm)
			curm=a[i];
		else{
			tot+=(curm-a[i]);
		}
	}
	cout<<tot;
	return;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ll t,T;
//	cin>>T;
	T=1;
	for(t=1;t<=T;t++){
//		cout<<"Case #"<<t<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 5220
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = str(n)
for i in range(3):
    if s[i] == '7':
        print('Yes')
        quit()
print('No')

Measured memory_bytes: 65316
#include <bits/stdc++.h>
#define ll long long int
#define mod_ceil(a, b) (a % b) ? a / b + 1 : a / b
using namespace std;

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

    ll n, d = 0, sum = 0, tmp;
    cin >> n;
    while (true)
    {
        tmp = powl(26, d + 1);
        sum += tmp;
        d++;
        if (n <= sum)
            break;
    }
    string s = "";
    sum = n;
    for (ll i = 0; i < d; i++)
    {
        sum--;
        s += char('a' + sum % 26);
        sum /= 26;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

int main() {
    int n ;
    cin >> n ;
    vector<double>  x (n) ;
    vector<double> y (n) ;
    vector<int> v (n) ;
    rep(i, n) {
        v[i] = i ; 
    }
    rep(i, n) {
        cin >> x[i] ; 
        cin >> y[i] ;
    }
    double tot = 0 ;
    do{
        rep(i, n){
            if(i == 0){
                continue ;
            }
            else {
                int e = v[i] ;
                int s = v[i - 1] ;
                tot += (sqrt(pow(x[e] - x[s], 2) + pow(y[e] - y[s], 2))) ;
            }
        }            
    }while(next_permutation(v.begin(),v.end())) ;
    double nn = n ;
    for(int i = 1; i < n ; i++){
        nn = nn * (n-i) ;
    }
    cout << fixed << setprecision(10) ;
    cout << tot / nn << endl ;
}

Measured memory_bytes: 3788
#include <array>
#include <iostream>
 
int main()
{
    std::array<int, 10000> a, b;
    long sum = 0;
    unsigned int n;
    std::cin >> n;
    for (unsigned int i = 0; i < n; i++) {
        std::cin >> a[i];
        sum -= a[i];
    }
    for (unsigned int i = 0; i < n; i++) {
        std::cin >> b[i];
        sum += b[i];
    }
 
 
    if (sum < 0) {
        std::cout << "No" << '\n';
    } else {
        long sum2 = 0;
        for (unsigned int i = 0; i < n; i++) {
            if (a[i] < b[i]) {
                sum2 += (b[i] - a[i] + 1) / 2;
            }
        }
        if (sum2 <= sum) {
            std::cout << "Yes" << '\n';
        } else {
            std::cout << "No" << '\n';
        }
    }
 
    return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
p = [1]*100000
p[0] = 0
p[1] = 0
p[2] = 1
for i in range(3,100000):
    if i%2==0:
        p[i]=0
    if p[i]==1:
        j = i + i
        while j < 100000:
            p[j] = 0
            j += i
a = [0]*100000
for i in range(2,100000):
    if i % 2 ==0:
        continue
    if p[i] and p[(i+1)//2]:
        a[i] = 1
s = [0]*100001
for i in range(2,100000):
    s[i+1]=s[i]+a[i]
#print(s)
Q = int(input())
for i in range(Q):
    l,r=map(int,input().split())
    print(s[r+1]-s[l])


Measured memory_bytes: 9940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,l,r) for(int i=l;i<r;i++)
const int inf=2e9+10;
const ll INF=9e18+10;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const ll MOD=1e9+7;

struct dis{
    vector<int> parent,rank;
    dis(int n){
        parent.resize(n);rank.resize(n);
        rep(i,n)parent[i]=i;
        rep(i,n)rank[i]=0;
    }
    bool is_same(int x,int y){
        return findg(x)==findg(y);
    }
    void unit(int x,int y){
        x=findg(x);y=findg(y);
        if(x==y)return;
        parent[x]=y;
    }
    int findg(int x){
        if(x==parent[x])return x;
        return parent[x]=findg(parent[x]);
    }
};

int main(){
    int n,m;cin>>n>>m;
    int x,y;
    dis t(n);
    int g=n;
    rep(i,m){
        cin>>x>>y;
        x--;y--;
        if(t.is_same(x,y));
        else {
            t.unit(x,y);
            g--;
        }
    }
    cout<<g-1<<endl;
    return 0;
}

Measured memory_bytes: 4052
N, M = map(int, input().split())
maxL = 1
minR = N

for i in range(M):
    L, R = map(int, input().split())
    if maxL < L:
        maxL = L
    if minR != None and R < minR:
        minR = R
    #print("\t\t\t", maxL, minR)

if maxL <= minR:
    print(minR - maxL + 1)
else:
    print(0)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec[i];
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int alice=0, bob= 0;
  for( int i = 0; i < vec.size(); i+=2){
    alice += vec[i];
     bob += vec[i+1];
  }
	cout << alice - bob << endl;
}
    

Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph2 {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	private int[] discover; //discover time stamp, -1 for undiscovered
	private int[] finish; //finish time stamp
	public Graph2() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1; //-1, index
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1; //-1, index
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	
	public int DFS(int v, int t0) {
		discover[v] = t0;
		LinkedList<Integer> nb = adjList.get(v);
		Iterator<Integer> it = nb.iterator();
		int t = t0;
		while(it.hasNext()) {
			int w = it.next();
			if(discover[w] == -1) {
				t ++; //one forward step
				t = DFS(w, t);
			}
		}
		finish[v] = t + 1; //+1 for backtrack step
		return t + 1;
	}
	
	public void timeStamp() {
		int v;
		discover = new int[totalVertex];
		finish = new int[totalVertex];
		for(v = 0; v < totalVertex; v ++) discover[v] = -1; //-1: not discovered
		int t = 0;
		for(v = 0; v < totalVertex; v ++) {
			if(discover[v] == -1) { //for disconnected graph, restart from an unvisited node
				t = DFS(v, t);
				t ++;
			}
		}
		//display the result
		for(v = 0; v < totalVertex; v ++) {
			System.out.println((v + 1) + " " + (discover[v] + 1) + " " + (finish[v] + 1));
			//+1, node 0 -> 1, 1 -> 2, etc
		}
	}
}

public class Main {
	public static void main(String argv[]) {
		Graph2 g = new Graph2();
		g.loadAdjList();
		g.timeStamp();
	}
}


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

int n, m;
int it[800005], lazy[800005];
pair<int, int> a[200005];

void down(int id)
{
	it[id*2]+=lazy[id];
	it[id*2+1]+=lazy[id];
	lazy[id*2]+=lazy[id];
	lazy[id*2+1]+=lazy[id];
	lazy[id]=0;
}

void update(int id, int l, int r, int u, int v)
{
	if(l>v||r<u) return;
	if(l>=u&&r<=v)
	{
		it[id]++;
		lazy[id]++;
		return;
	}
	down(id);
	int mid=(l+r)/2;
	update(id*2, l, mid, u, v);
	update(id*2+1, mid+1, r, u, v);
	it[id]=max(it[id*2], it[id*2+1]);
}

int get(int id, int l, int r, int u, int v)
{
	if(l>v||r<u) return -1e9;
	if(l>=u&&r<=v)
	{
		return it[id];
	}
	down(id);
	int mid=(l+r)/2;
	return max(get(id*2, l, mid, u, v), get(id*2+1, mid+1, r, u, v));
}

void build_tree(int id, int l, int r)
{
	if(l==r)
	{
		it[id]=-(m+1-l);
		return;
	}
	int mid=(l+r)/2;
	build_tree(id*2, l, mid);
	build_tree(id*2+1, mid+1, r);
	it[id]=max(it[id*2], it[id*2+1]);
}

signed main()
{
	cin>>n>>m;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i].first>>a[i].second;
	}
	sort(a+1, a+n+1);
	build_tree(1, 1, m+1);
	int ans=max(0ll, n-m);
	// cout<<get(1, 1, m+1, 3, m+1)<<endl;
	for(int i=1; i<=n; i++)
	{
		update(1, 1, m+1, 1, a[i].second);
		ans=max(ans, -a[i].first+get(1, 1, m+1, a[i].first+1, m+1));
		// cout<<get(1, 1, m+1, a[i].first+1, m+1)<<endl;
		// cout<<i<<" "<<ans<<endl;
	}
	cout<<ans;
}

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

using namespace std;

int main()
{
	int n,q;
	string s;
	cin>>n>>q>>s;
	vector<int> cnt(1e5+1);
	for(int i=0;i<(int)s.size()-1;i++)
	{
		if(s.substr(i,2)=="AC")
			cnt[i+1]++;
			cnt[i+1]+=cnt[i];
	}
	for(int i=0;i<q;i++)
	{
		int l,r;
		cin>>l>>r;
		cout<< cnt[r-1]-(l-1<0?0:cnt[l-1])<< endl;
	}

  return 0;
}


Measured memory_bytes: 1408
$m = {}
def r m, a, b, c
  if v = $m[[m, a, b, c]]
    return v
  elsif m < 0
    return
  elsif m == 0
    p = 0;
    k = a % 5; p += 380 * k + (380 * (a - k) * 0.80).to_i
    k = b % 4; p += 550 * k + (550 * (b - k) * 0.85).to_i
    k = c % 3; p += 850 * k + (850 * (c - k) * 0.88).to_i
    return $m[[m, a, b, c]] = p
  end
  s = []
  if m >= 200
    s.push r(m - 200, a + 1, b, c)
  end
  if m >= 300
    s.push r(m - 300, a, b + 1, c)
  end
  if m >= 500
    s.push r(m - 500, a, b, c + 1)
  end
  return $m[[m, a, b, c]] = s.select{|a|a}.min
end

while 0 < m = gets.to_i
  p r(m, 0, 0, 0)
end

Measured memory_bytes: 8116
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#define ll long long

using namespace std;


int main(void){
   string s;
   cin >> s;
   ll n;
   cin >> n;
   ll count = 0;
   string F, L;
   for(ll i = 0; i < n; i++){
      ll q; cin >> q;
      if(q==1){
         count++; continue;
      }
      else if(q==2){
         ll c; string a;
         cin >> c; cin >> a;
         if(c == 1 && count%2==0)
            F.insert(0, a);
         if(c == 1 && count%2!=0)
            L.push_back(a[0]);
         if(c == 2 && count%2==0)
            L.push_back(a[0]);
         if(c == 2 && count%2!=0)
            F.insert(0, a);
      }
   }
   string ans = F+s+L;
   if(count%2!=0)
      reverse(ans.begin(), ans.end());
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 1348
n, p = map(int, input().split())

if p == 2:
    s = input()
    ans = 0
    for i in range(n):
        if int(s[i]) % 2 == 0:
            ans += i + 1
    print(ans)

elif p == 5:
    s = input()
    ans = 0
    for i in range(n):
        if int(s[i]) % 5 == 0:
            ans += i + 1
    print(ans)

else:
    s = input()[::-1]
    mod = 0
    c = [0] * p
    c[0] = 1
    ten = 1
    for i in s:
        mod = (mod + ten * int(i)) % p
        ten = ten * 10 % p
        c[mod] += 1

    ans = 0
    for i in c:
        ans += i * (i - 1) // 2
    print(ans)

Measured memory_bytes: 41968
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(long long*)a > *(long long*)b){
        return -1;
    }else if (*(long long*)a == *(long long*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int ng, mid, ok;
    ng = -1, ok = n-1;
    while (abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if (key <= a[mid]){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    if (a[ok] >= key)return ok;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

/*
int struct_ascending_compare(const void *p, const void *q) {
return ((struct_name*)p)->member_name - ((struct_name*)q)->member_name;
}*/

/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]);
        }
    }
}*/
long long mod = 1000000007;

long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % mod;
        x = x * x % mod;
    }
    return res;
}


char s[105];
char ans[205];

int main(void){
    int n;
    int left_cnt = 0;
    int right_cnt = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf(" %c", &s[i]);
        if (s[i] == '(') left_cnt++;
        else if (left_cnt > 0) left_cnt--;
    }
    for (int i = n-1; i >= 0; i--){
        if (s[i] == ')') right_cnt++;
        else if (right_cnt > 0) right_cnt--;
    }
    int i = 0;
    int j;
    while (i < right_cnt){
        ans[i] = '(';
        i++;
    }
    for (j = i; j < n + i; j++){
        ans[j] = s[j-i];
    }
    for (i = j; i < left_cnt + j; i++){
        ans[i] = ')';
    }
    ans[i] = '\0';

    printf("%s", ans);

    return 0;
}

Measured memory_bytes: 128
#6974436 ponestrellaさんのコード

h,w=map(int,input().split())
a=[[j for j in input()] for i in range(h)]
b=[x for x in a if "#" in x]
c=zip(*[y for y in zip(*b) if "#" in y])
for d in c:print("".join(d))


Measured memory_bytes: 3188
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  

int main() {
    int N;
    cin >> N;
    vector<int> A;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A.push_back(a);
    }


    int cnt2 = 0;
    int cnt1 = 0;
    int cnt0 = 0;
    for (int i = 0; i < N; i++) {
        int cnt = 0;
        while(!(A[i] >> cnt & 1)) cnt++;
        //cout << cnt << endl;
        if (cnt >= 2) {
            cnt2++;
        } else if (cnt == 1) {
            cnt1++;
        } else {
            cnt0++;
        }
    }

    if (cnt2 > 0) {
        N -= 1 + 2 * cnt2;
    }
    if (cnt1 > 0) {
        if (cnt2 > 0) N++;
        N -= cnt1;
    }

    if (N <= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

vector<ll> enum_div(ll n) {
  vector<ll> ret;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) ret.push_back(i);
  }
  sort(ret.begin(), ret.end());
  return ret;
}

bool isprime(ll x) {
  ll i;
  if(x < 2) return 0;
  else if(x == 2) return 1;
  if(x%2 == 0) return 0;
  for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
  return 1;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> vec = enum_div(n);
  ll ans = LLONG_MAX;
  rep(i, vec.size()) {
    ll m = vec.at(i) + n/vec.at(i) - 2;
    ans = min(ans, m);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np
N=int(input())
A_np = np.zeros(N)
A=list(map(int, input().split()))
for Ai in A:
  A_np[Ai-1] = A_np[Ai-1] + 1
for i in range(N):
  print('{:.0f}'.format(A_np[i]))

Measured memory_bytes: 50940
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.X86;
using System.Text;
using System.Threading;

namespace AtCoder
{
	public class Program
	{
		static void Main()
		{
			string b = Console.ReadLine();
			char ans = b[0] switch
			{
				'A' => 'T',
				'G' => 'C',
				'C' => 'G',
				'T' => 'A',
			};

			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 25584
#include "bits/stdc++.h"
#include <cmath>

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<ll> B(N);
    for(int i = 0; i < N; i++){
        B[i] = A[i] - i - 1;
    }
    sort(all(B));
    int M = B.size();
    ll ans;
    if(M % 2 == 0){
        ans = (B[M / 2 - 1] + B[M / 2]) / 2;
    }else ans = B[M / 2];
    ll sum = 0;
    for(int i = 0; i < N; i++){
        sum += abs(B[i] - ans);
    }
    cout << sum << endl;
}

Measured memory_bytes: 3456
using System;
public class Eratosthenes
{
	public static void Main(string[] args)
	{
		int count = int.Parse(Console.ReadLine());
		int sum = 0;//?´???°???????¨?
		
		for (int i = 0; i < count; i++)
		{
			//?????????????±????????????????
			int target = int.Parse(Console.ReadLine());
			//????????????
			//2???????°??????£???????????§??????????????????if?????????????????\????????????
			if(target==2)
			{
				sum++;
			}
			if ((target >= 2) && ((target % 2) != 0)) 
			{
				
				int j = 3;
				do{
					
					
					if ( target == 3)
					{//?´???°??§??????
						sum ++;
						break;
					}
					
					if (target % j == 0)
					{//?´???°??§?????????
						break;
					}
					if ((j + 2) >( target / (j+2)))
					{
						//????????????????????§????????????break?????????????????´????????????????????\???
						sum ++;
						break;
					}
					
					j+=2;
				}while(j<=target/j);
			}
			
		}
		
		Console.WriteLine(sum);
	}
}

Measured memory_bytes: 9196
#include<iostream>
#include<string.h>
using namespace std;
 
int D[6];
void spin(char c)
{
  if(c=='E'){
    swap(D[0],D[3]);swap(D[3],D[5]);swap(D[5],D[2]);
  }
  else if(c=='W'){
    swap(D[0],D[2]);swap(D[2],D[5]);swap(D[5],D[3]);
  }
  else if(c=='S'){
    swap(D[0],D[1]);swap(D[0],D[4]);swap(D[4],D[5]);
  } 
  else if(c=='N'){
    swap(D[0],D[1]);swap(D[1],D[5]);swap(D[5],D[4]);
  }
}
int main()
{
  char M[101];
 
  for(int i=0;i<6;i++)cin>>D[i];
  cin>>M;
 
  for(int i=0;i<strlen(M);i++)spin(M[i]);
 
  cout<<D[0]<<endl;
 
  return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int dist[1010][1010];
int d[]={1,0,-1,0,1};
int a[22][22];
ll dp[1<<20][20];
int main(){
	int h,w,k;
	cin>>h>>w>>k;
	string s[h];
	rep(i,h)cin>>s[i];
	map<pair<int,int>,int> mp;
	int ap=0;
	rep(i,h)rep(j,w){
		if(s[i][j]=='a')mp[{i,j}]=ap++;
	}
	rep(i,h)rep(j,w){
		if(s[i][j]=='s')mp[{i,j}]=ap++;
	}
	rep(i,h)rep(j,w){
		if(s[i][j]=='e')mp[{i,j}]=ap++;
	}
	for(auto e:mp){
		int sx=e.first.first, sy=e.first.second;
		rep(i,h)rep(j,w)dist[i][j]=inf;
		dist[sx][sy]=0;
		queue<pair<int,int>> q;
		q.push(e.first);
		while(q.size()){
			auto p=q.front();q.pop();
			int cx=p.first, cy=p.second;
			rep(i,4){
				int nx=cx+d[i], ny=cy+d[i+1];
				if(nx<0||nx>=h||ny<0||ny>=w)continue;
				if(dist[nx][ny]!=inf)continue;
				if(s[nx][ny]=='#')continue;
				dist[nx][ny]=dist[cx][cy]+1;
				q.emplace(nx,ny);
			}
		}
		for(auto f:mp){
			a[e.second][f.second]=dist[f.first.first][f.first.second];
		}
	}
	int n=ap-2;
	rep(i,1<<n)rep(j,n)dp[i][j]=longinf;
	rep(i,n)dp[1<<i][i]=a[n][i];
	rep(i,1<<n){
		rep(j,n){
			if(((1<<j)&i)==0)continue;
			int pre = i^(1<<j);
			rep(k,n){
				if(((1<<k)&pre)==0)continue;
				dp[i][j]=min(dp[i][j],dp[pre][k]+a[k][j]);
			}
		}
	}
	ll ans = longinf;
	rep(i,1<<n){
		if(__builtin_popcount(i)<k)continue;
		rep(j,n)ans = min(ans,dp[i][j]+a[j][n+1]);
	}
	if(ans>=inf)cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 171864
#include <cstdio>
#include <iostream>
#include <algorithm>
const int N = 2e5 + 5;
inline int Get() {
	char ch;
	while ((ch = getchar()) < '0' || ch > '9');
	int Num = ch - '0';
	while ((ch = getchar()) >= '0' && ch <= '9')
		Num = (Num << 3) + (Num << 1) + ch - '0';
	return Num;
}
int n, m, l[N], r[N], id[N], ans;
int sum[N << 2], mx[N << 2];
void build(int k, int l, int r) {
	if (l == r) {
		sum[k] = mx[k] = -1;
		return;
	}
	
	int mid = l + r >> 1;
	build(k << 1, l, mid), build((k << 1) | 1, mid + 1, r);
	
	sum[k] = sum[k << 1] + sum[(k << 1) | 1];
	mx[k] = std :: max(mx[k << 1] + sum[(k << 1) | 1], mx[(k << 1) | 1]);
}
void modify(int k, int l, int r, int pos) {
	if (l == r) {
		++sum[k], ++mx[k];
		return;
	}
	
	int mid = l + r >> 1;
	if (pos <= mid) modify(k << 1, l, mid, pos);
	else modify((k << 1) | 1, mid + 1, r, pos);
	
	sum[k] = sum[k << 1] + sum[(k << 1) | 1];
	mx[k] = std :: max(mx[k << 1] + sum[(k << 1) | 1], mx[(k << 1) | 1]);
}
inline bool cmp(const int &x, const int &y) {
	return l[x] < l[y];
}
int main() {
	n = Get(), m = Get(), ans = n - m;
	for (int i = 1; i <= n; ++i) l[i] = Get(), r[i] = Get(), id[i] = i;
	
	build(1, 1, m + 1), modify(1, 1, m + 1, m + 1);
	
	std :: sort(id + 1, id + n + 1, cmp);
	for (int i = 1, k; k = id[i], i <= n; ++i) {
		modify(1, 1, m + 1, r[k]);
		if (i == n || l[id[i + 1]] != l[k]) ans = std :: max(ans, mx[1] - l[k]);
	}
	
	printf("%d\n", std :: max(ans, 0));
}

Measured memory_bytes: 8832
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<60)
#define mod 1000000007
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };


signed main(){

	int n;
	cin >> n;

	bool yes = false;
	int k;
	for (k = 1; k*(k-1)/2 <= n; k++){
		if (k*(k - 1) / 2 == n){
			yes = true;  break;
		}
	}
	if (!yes){
		cout << "No" << endl;
		return 0;
	}

	// a[k][k]
	int **a = new int*[k];
	for (int i = 0; i < k; i++)
		a[i] = new int[k];

	for (int i = 0; i < k; i++) for (int j = 0; j < k; j++) a[i][j] = 0;

	int c = 1;
	for (int i = 0; i < k; i++){
		for (int j = i+1; j < k; j++){
			a[i][j] = a[j][i] = c;
			c++;
		}
	}

	cout << "Yes" << endl;
	cout << k << endl;
	for (int i = 0; i < k; i++){
		cout << k - 1 << " ";
		for (int j = 0; j < k; j++){
			if (a[i][j] != 0) cout << a[i][j] << " ";
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 2944
N = int(input())
li = list(map(int, input().split()))
count = 0

while(True):
  if max(li) == 0:
    break

  i = 0
  while(i < N):
    if li[i] == 0:
      i += 1
      continue

    count += 1
    while(i < N and li[i] > 0):
      li[i] -= 1
      i += 1

print(count)

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

const ll MAXN = 200000;

ll N, M, ans=0, tmp=0;
//vector<pair<ll,ll>> job;
priority_queue<ll> job[100005];
priority_queue<pair<ll,ll>> PQ;
signed main(){
    cin >> N >> M;
    for(int i=0;i<N;i++) {
        ll a, b;
        cin >> a >> b;
        job[a].push(b);
    }
    for(int i=1;i<=M;i++) {
        //cout << "OK" << i << endl;
        if(!job[i].empty()) {
            PQ.push(make_pair(job[i].top(),i));
            job[i].pop();
        }
        //cout << "OK" << i << endl;
        pair<ll,ll> p;
        if(!PQ.empty()) {
            p = PQ.top();
            PQ.pop();
            ans += p.first;            
            if(!job[p.second].empty()) {
                PQ.push(make_pair(job[p.second].top(),p.second));
                job[p.second].pop();
            }
        }
        //cout << "OK" << i << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
#include<stack>
#include<cstdio>

#define	mp	make_pair
#define	Clr	first
#define	Num	second

using namespace std;

typedef	pair<int,int>	pii;

int main()
{
	for(int n;scanf("%d",&n),n;){
		stack<pii> st;
		for(int i=0;i<n;i++){
			int a;	scanf("%d",&a);
			if(i&1){
				if(st.top().Clr==a)	st.top().Num++;
				else{
					int num=st.top().Num;	st.pop();
					if(st.empty())	st.push(mp(a,num+1));
					else	st.top().Num+=num+1;
				}
			}
			else{
				if(st.empty() || st.top().Clr!=a)	st.push(mp(a,1));
				else	st.top().Num++;
			}
		}

		int wcnt=0;
		while(!st.empty()){
			if(st.top().Clr==0)	wcnt+=st.top().Num;
			st.pop();
		}
		printf("%d\n",wcnt);
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int H,W,x,y,flag;
char tile[100][101];

int main(){
	while(cin>>H>>W){
		if(H+W==0)return 0;
		for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>tile[i][j];
		x=0;y=0;flag=0;
		for(int i=0;i<10000;i++){
			if(tile[y][x]=='.'){
				cout<<x<<" "<<y<<endl;
				flag=1;
				break;
			}
			if(tile[y][x]=='>')x++;
			if(tile[y][x]=='<')x--;
			if(tile[y][x]=='^')y--;
			if(tile[y][x]=='v')y++;
		}
		if(flag==0)cout<<"LOOP"<<endl;
	}
}

Measured memory_bytes: 0
import java.util.*;


public class Main{    
    
    public static void main(String[] args){            
       
        Scanner sc = new Scanner(System.in);        
                      
        int N = sc.nextInt();

        long A = sc.nextInt();
        long B = sc.nextInt();
        
        int count = 0;
        
        int a[] = new int [N];
        
        for(int i = 0;i < N;i++){
            a[i]  = sc.nextInt();           
        }
        
        long sum = 0;
        for(int j = 0;j <= N-2;j++){
            sum += Math.min(A*(a[j+1] - a[j]),B);
        }
        
        System.out.println(sum);
                
                        
    }                                       
}

Measured memory_bytes: 52164
#include<bits/stdc++.h>
#define endl "\n" 
using namespace std; 

vector<int>v;
void primeGenerate()
{
    int n=10000000;
    for(int i=0; i<n; i++)
    v.push_back(1);
    v[0]=v[1]=0;
    for(int i=2; i<sqrt(n); i++)
    {
        if(v[i]==1)
        for(int j=2; j*i<=n; j++)
        {
            v[i*j]=0;
        }
    }
}
typedef long long int ll; 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
    #endif
    int n,cnt=0;
    cin>>n;
    while(n!=0)
    {
        if(n%10==7)
        {
            cnt=1;
            break;
        }
        n/=10;
    }
    if(cnt==0)
    cout<<"No"<<"\n";
    else
    cout<<"Yes"<<"\n";
        
    return 0;
}

Measured memory_bytes: 3656
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn sat_pow(b: usize, mut n: usize) -> usize {
    let mut res = 1usize;
    let mut mul = b;
    while n > 0 {
        if n & 1 == 1 {
            res = res.saturating_mul(mul);
        }
        mul = mul.saturating_mul(mul);
        n >>= 1;
    }
    res
}

macro_rules ! min { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ z : expr ) ,+ ) => { { std :: cmp :: min ( $ x , min ! ( $ ( $ z ) ,* ) ) } } }

fn main() {
    use core::cmp::Reverse;
    input! {
        t: usize,
    }
    for _ in 0..t {
        input! {
            n: usize,
            a: usize,
            b: usize,
            c: usize,
            d: usize,
        }

        let mut heap = BinaryHeap::new();
        heap.push((Reverse(0), n));
        let mut dist = BTreeMap::new();
        dist.insert(n, 0);
        let neighbors = vec![(2, a), (3, b), (5, c)];
        while let Some((Reverse(cost), val)) = heap.pop() {
            if val == 1 {
                println!("{}", cost + d);
                break;
            }
            for &(base, bcost) in &neighbors {
                if val % base == 0 {
                    let kd = dist.get(&(val / base)).cloned().unwrap_or(std::usize::MAX);
                    let nd = cost.saturating_add(min!(bcost, (val - val / base).saturating_mul(d)));
                    if kd > nd {
                        dist.insert(val / base, nd);
                        heap.push((Reverse(nd), val / base));
                    }
                } else {
                    let v1 = val / base * base;
                    let v2 = v1 + base;
                    let kd = dist.get(&(v1 / base)).cloned().unwrap_or(std::usize::MAX);
                    let nd = cost.saturating_add(
                        min!(bcost, (v1 - v1 / base).saturating_mul(d)) + (val - v1) * d,
                    );
                    if kd > nd {
                        dist.insert(v1 / base, nd);
                        heap.push((Reverse(nd), v1 / base));
                    }
                    let kd = dist.get(&(v2 / base)).cloned().unwrap_or(std::usize::MAX);
                    let nd = cost.saturating_add(
                        min!(bcost, (v2 - v2 / base).saturating_mul(d)) + (v2 - val) * d,
                    );
                    if kd > nd {
                        dist.insert(v2 / base, nd);
                        heap.push((Reverse(nd), v2 / base));
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 2560
# import platform
# ver = platform.python_version_tuple()
# if int(ver[1]) < 5:
#     from fractions import gcd
# else:
#     from math import gcd

# from itertools import accumulate, combinations, permutations, product
# from bisect import bisect, bisect_left
# from collections import Counter, defaultdict, deque
# from heapq import heappush, heappop

# from functools import lru_cache
# @lru_cache(maxsize=1024)

from sys import stdin, stdout
input = lambda: stdin.readline().rstrip()
write = stdout.write

def main():
    N, K = map(int, input().split())
    A = tuple(map(int, input().split()))

    ans = -(-(N - K) // (K - 1)) + 1
    print(ans)

main()


Measured memory_bytes: 14008
import Control.Applicative

main :: IO ()
main = solve <$> f >>= print
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> Int
solve [x, y]
  | x == 1 && y == 1 = 1000000
  | otherwise = f x + f y
  where
    f 1 = 300000
    f 2 = 200000
    f 3 = 100000
    f _ = 0


Measured memory_bytes: 508
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll h,w;cin>>h>>w;
  string s[h];
  rep(i,0,h)cin>>s[i];
  ll x=0;
  rep(i,0,h){
    ll count=0;
    rep(j,0,w){
      if(s[i][j]=='#'){
        if(count==0)if(x!=j){
          out("Impossible");
          return 0;
        }
        x=j;
        count++;
      }
    }
  }
  out("Possible");



  return 0;
}


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

int main(){
    
	long long n , ans = 10000000000000; cin >> n;
	for (long long i = 1; i <= sqrt(n); i++) {
		if (n % i == 0) {
			ans = min(ans, i + n / i);
		}
	}
	cout << ans - 2 << endl;

	return 0;
}

Measured memory_bytes: 256