akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
int T,a,b,c,d;
int len,m,flag;
char Get(int p){
	if (flag)
		p=a+b-p+1;
	int res;
	if (p<=m)
		res=p%(len+1)?'A':'B';
	else
		res=(a+b-p+1)%(len+1)?'B':'A';
	if (flag)
		res=res=='A'?'B':'A';
	return res;
}
void Solve(){
	a=read(),b=read(),c=read(),d=read();
	if (a==b){
		For(i,c,d)
			putchar(i&1?'A':'B');
		puts("");
		return;
	}
	flag=0;
	if (a<b)
		swap(a,b),flag=1;
	len=(a+(b+1)-1)/(b+1);
	int rd=a/len,rem=b-a/len,rec=a%len;
	if (!rec)
		rec=len,rem++,rd--;
	if (rem<=(LL)rec*len)
		m=rd*(len+1)+rec-(rem-1)/len;
	else {
		//rem>rec*len
		rd--;
		rem-=rec*len;
		rem++;
		while (rem>(LL)len*len){
			int tmp=rem/(len*len);
			rem-=tmp*len*len;
			rem+=tmp;
			rd-=tmp;
		}
		m=rd*(len+1)+len-(rem-1)/len;
	}
//	outval(flag),outval(len),outval(m);
//	For(i,1,a+b)putchar(Get(i));puts("");
	For(i,c,d)
		putchar(Get(i));
	puts("");
}
int main(){
	T=read();
	while (T--)
		Solve();
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SIZE 100005

using namespace std;
typedef long long int ll;

int main()
{
    int n;
    cin >> n;
    map<string, ll> mp;
    for (int i=0; i<n; i++)
    {
        string str;
        cin >> str;
        sort(str.begin(), str.end());
        auto itr = mp.find(str);
        if (itr == mp.end()) mp.insert(make_pair(str, 1));
        else mp[str]++;
    }

    ll sum = 0;
    for (auto& e : mp)
    {
        if (e.second == 0) continue;
        sum += e.second * (e.second - 1) / 2;
    }
    cout << sum << endl;
    
    return 0;
}


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

typedef struct stringBlock
{
    int startIndex;
    int endIndex;
    int length;
    char moji;
} block;

void initialization(block *judgeBlock, int inputN)
{
    for (int count = 0; count < inputN; count++)
    {
        block tmp;
        tmp.length = 0;
        judgeBlock[count] = tmp;
    }
}

int main(void)
{
    int inputN, inputK, startIndex = 0, endIndex, answer = 0, emptyNum = 0, changeCount = 0;
    char *inputS;
    block *judgeBlock;
    
    scanf("%d%d", &inputN, &inputK);
    inputS = (char *)malloc(sizeof(char) * inputN + 1);
    judgeBlock = (block *)malloc(sizeof(block) * inputN);
    initialization(judgeBlock, inputN);
    scanf("%s", inputS);

    for (int count = 0; count < inputN; count++)
    {
        if (inputS[count] != inputS[count + 1])
        {
            endIndex = count;
            judgeBlock[emptyNum].startIndex = startIndex;
            judgeBlock[emptyNum].endIndex = endIndex;
            judgeBlock[emptyNum].length = endIndex - startIndex + 1;
            judgeBlock[emptyNum].moji = inputS[count];
            emptyNum++;
            startIndex = count + 1;
        }
    }
    for (int count = 0; count < emptyNum; count++)
    {
        if (count % 2 != 0)
        {
            if (judgeBlock[count].moji == 'R')
            {
                judgeBlock[count].moji = 'L';
            }
            else
            {
                judgeBlock[count].moji = 'R';
            }
            changeCount++;
        }
        if (changeCount == inputK)
        {
            break;
        }
    }
    for (int count = 0; count < emptyNum; count++)
    {
        for (int innercount = judgeBlock[count].startIndex; innercount <= judgeBlock[count].endIndex; innercount++)
        {
            inputS[innercount] = judgeBlock[count].moji;
        }
    }
    for (int count = 0; count < inputN; count++)
    {
        if (inputS[count] == inputS[count + 1])
        {
            answer++;
        }
    }
    printf("%d", answer);

    free(inputS);
    free(judgeBlock);

    return 0;
}

Measured memory_bytes: 1792
import collections as cc
n=int(input())
l=list(map(int,input().split()))
ff=cc.Counter(l)
ff=dict(ff)
ans=0
for i in ff:
    x=ff[i]
    ans+=(x*(x-1))//2
v={}
for i in set(l):
    vv=max(ff[i]-1,0)
    te=ans-(ff[i]*(ff[i]-1))//2+(vv*(vv-1))//2
    v[i]=te
for i in l:
    print(v[i])


Measured memory_bytes: 106700
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>

class Stack {
private:
    std::vector<int> stack;
public:
    void push(int x)
    {
        stack.push_back(x);
    }

    int pop()
    {
        int &x = stack.back();
        stack.pop_back();
        return x;
    }

    bool isEmpty()
    {
        return stack.empty();
    }
};

int main()
{
    Stack stack;
    char s[100];
    while(scanf("%s", s) != EOF)
    {
        if(s[0] == '+')
        {
            int a = stack.pop();
            int b = stack.pop();
            stack.push(a + b);
        }
        else if(s[0] == '-')
        {
            int a = stack.pop();
            int b = stack.pop();
            stack.push(b - a);
        }
        else if(s[0] == '*')
        {
            int a = stack.pop();
            int b = stack.pop();
            stack.push(a * b);
        }
        else
        {
            stack.push(std::atoi(s));
        }
    }

    std::cout << stack.pop() << std::endl;
}


Measured memory_bytes: 3248
import collections
n=int(input())
s=[]
for i in range(n):
  s.append(input())
c = collections.Counter(s)
s=[]
count=0
for i in c.most_common():
  if len(s)==0:
    count=i[1]
    s.append(i[0])
    continue
  if count!=i[1]:
    break
  else:
    s.append(i[0])

for i in sorted(s):
  print(i)

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

vector<vector<int>> T(MAX_N,vector<int>());
vector<ll> C(MAX_N);

void dfs(int x, int v, int bf){
	C[x] += v;
	for(int u: T[x]){
		if(u==bf)continue;
		dfs(u,C[x],x);
	}
	return;
}

int main(){
	int N,Q;
	cin >> N >> Q;
	rep(i,N-1){
		int a,b;
		cin >> a >> b;
		T[a].push_back(b);
		T[b].push_back(a);
	}
	rep(i,Q){
		int p,x;
		cin >> p >> x;
		C[p] += x;
	}
	dfs(1,0,0);

	rep(i,N){ if(i)cout<<" "; cout<< C[i+1];}cout<<endl;



}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/


int main(){
    int D;
    ll G;
    ll sp=0;
    cin >> D >> G;
    vector<int> p(D),c(D);
    rep(i,D){
        cin >> p[i] >> c[i];
        sp += p[i];
    }

    int l=0,r=sp;
    while(r-l>1){
        int m = (l+r)/2;

        bool ok = false;
        for(int mask=0;mask<(1<<D);mask++){
            int rem = m;
            ll po = 0;
            rep(i,D){
                if(mask&(1<<i)){
                    rem -= p[i];
                    po += p[i] * 100 * (i+1) + c[i];
                }
            }

            //if(m == 7 and mask==0b10){
            //    cout << "check " << rem << " " << po << endl;
            //}

            if(rem < 0) continue;

            for(int i=D-1;i>=0;i--){
                if(mask&(1<<i)) continue;
                else{
                    int tt = min(rem,p[i]-1);
                    rem -= tt;
                    po += tt * 100 *(i+1);
                }
            }


            if(po>=G){
                ok=true;
                break;
            }
        }

        //cout << m << "  " << ok << endl;

        if(ok){
            r = m;
        }else{
            l = m;
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 256
/*
Author : N_o_o_B
Created : June 14 2020 17:37:55 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

const int maxa = 1e6+4;
int m[maxa];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int n=2e5;
    cin >> n;
    vi a(n);
    fori(i,n){
        cin >> a[i];
    }   
    fori(i,n){
        m[a[i]]++;
    }
    int ans = 0;
    fori(i,n){
        int cnt = 0;
        for(int j=1;j*j<=a[i];j++){
            if(a[i]%j) continue;
            int d = j;
            cnt += m[d];
            if(d*d != a[i]) cnt += m[a[i]/d];
            if(cnt>1) break;
        }
        ans += (cnt == 1);
    }
    cout << ans << endl;
    
    time_taken();
    return 0;
}

Measured memory_bytes: 7832
#include <iostream>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0;
    int ans[n];
    int fl = 0;
    int check;
    s+='p';
    for(int i = 0;i<n;i++){
        if(s[i]=='R'&& s[i+1]=='L'){
            ans[i]=1+(i-cnt)/2;
            ans[i+1]=1+(i-cnt+1)/2;
            cnt=i+2;
            check= i;
            fl = 0;
            i++;
        }
        else{
            if(s[i]=='L'){
                ans[check+fl]++;
                fl=(fl+1)%2;  
                cnt=i+1;
            } 
            ans[i]=0;
        }
    }
    for(int i = 0;i<n;i++){
        cout << ans[i] << " "; 
    }
    cout << endl;
}

Measured memory_bytes: 1024
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

//#include <bits/stdc++.h>
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <random>
#include <assert.h>
#include <time.h>
#include <random>
#include <chrono>
#include <memory>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

#define plus dfghjk
#define minus tyughj
#define y1 tyjnm

using namespace std;

inline void setmin(int &x, int y) { if (y < x) x = y; }
inline void setmax(int &x, int y) { if (y > x) x = y; }
inline void setmin(ll &x, ll y) { if (y < x) x = y; }
inline void setmax(ll &x, ll y) { if (y > x) x = y; }

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = 998244353;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    string s;
    cin >> s;
    vector<int> st;
    rep(i, 0, sz(s)) {
        if (s[i] == '0') {
            if (sz(st) > 0 && st.back() == 1) {
                st.pop_back();
            } else {
                st.push_back(0);
            }
        } else {
            if (sz(st) > 0 && st.back() == 0) {
                st.pop_back();
            } else {
                st.push_back(1);
            }
        }
    }
    cout << sz(s) - sz(st) << "\n";
    return 0;
}

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

int main()
{
	//while(true)
	{
		int m,n;
		cin>>m>>n;
		map<int,int> was;
		map<int,int> acs;
		int sum = 0;
		for( int i=0; i<n; i++ )
		{
			int a;
			string b;
			cin>>a>>b;
			if( b == "WA") 
				was[a]++;
			else
			{
				if(!acs.count(a))
					sum += was[a];
				acs[a] = 1;
			}
		}
		cout << acs.size() << " " << sum << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 9600
type
  arr=array[0..200500]of longint;

var x:longint;
    a,b:arr;
    n,m:longint;
    i,j:longint;
procedure qs(var a:arr;l,r:longint);
var i,j:longint;
    m,t:longint;
begin
  i:=l;
  j:=r;
  m:=a[(l+r)>>1];
  repeat
    while a[i]<m do inc(i);
    while a[j]>m do dec(j);
    if i<=j then
    begin
      t:=a[i];a[i]:=a[j];a[j]:=t;
      inc(i);
      dec(j);
    end;
  until i>j;
  if l<j then qs(a,l,j);
  if i<r then qs(a,i,r);
end;
begin
  read(n);
  for i:=1 to n do
  read(a[i]);
  qs(a,1,n);
  read(m);
  for i:=1 to m do
  read(b[i]);
  qs(b,1,m);
  x:=1;
  for i:=1 to n do
  if a[i]=b[x] then inc(x);
  if x<=m then writeln('NO') else
  writeln('YES');
end.



Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 998244353
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	vector< pair<int,int> > vec;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		vec.pb( mp( x, i ) );
	}
	sort(vec.begin(), vec.end());
	for(int i=1;i<=n;i++){
		cout<<vec[i-1].second<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 2544
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int k,n;
    cin>>n;
    vector<ll> arr(n);
    for(auto &x:arr)cin>>x;
    sort(all(arr));
    cout<<(ll)(arr[n-1]-arr[0]);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string T;
    cin >> T;
    rep(i, 0, T.size()) {
        cout << (T[i] == '?' ? 'D' : T[i]);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3748
// 4_abc137_d
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> v(n);
    rep(i, n){
        int a, b;
        cin >> a >> b;
        v[i] = make_pair(a, b);
    }
    sort(v.begin(), v.end());
    priority_queue<int> q;
    int itr = 0;
    ll ans = 0;
    for(int i = 1; i <= m; i++){
        while(v[itr].first <= i){
            q.push(v[itr].second);
            itr++;
        }
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1660
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

n, m, q = map(int, input().split())
g = [[0 for _ in range(m)] for _ in range(n)]
for _ in range(q):
	r, c, v = list(map(int, input().split()))
	g[r-1][c-1] = v

pre = [0 for _ in range(m)]
dp = [[0 for _ in range(4)] for _ in range(m)]
dp[0][1] = g[0][0]
for i in range(n):
	for j in range(m):
		dp[j][0] = max(dp[j][0], pre[j])
		if j > 0:
			dp[j][0] = max(dp[j][0], dp[j-1][0])
			for k in range(1, 4):
				dp[j][k] = max(dp[j][k], dp[j-1][k])
				dp[j][k] = max(dp[j][k], dp[j-1][k-1] + g[i][j])
			if i > 0:
				dp[j][1] = max(dp[j][1], pre[j] + g[i][j])
		else:
			dp[0][1] = max(dp[0][1], pre[0] + g[i][j])
	pre = [max(dp[j]) for j in range(m)]
	dp = [[0 for _ in range(4)] for _ in range(m)]

print(pre[-1])

Measured memory_bytes: 224280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    long long a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k%2==0) cout<<a-b;
    else cout<<b-a;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	int n;
	cin>>n;
	vector<int> nums(n);
	for(int i=0;i<n;i++) cin>>nums[i];
	LL nil = 1e15+7;
	vector<vector<LL>> dp(n,vector<LL>(n,nil));
	vector<LL> sif(n+1,0ll);
	for(int i=0;i<n;i++){
		sif[i+1] = sif[i]+nums[i];
		dp[i][i] = 0;
	}

	for(int len=2;len<=n;len++){
		for(int i=0;i<(n-len+1);i++){
			int j = i+len-1;
			for(int k=i;k<j;k++){
				dp[i][j] = min(dp[i][k]+sif[j+1]-sif[i]+dp[k+1][j],dp[i][j]);
			}
		}
	}
	cout<<dp[0][n-1]<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 1536
import java.util.*;
import java.text.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str = sc.nextLine();
      System.out.println(str.toUpperCase());
   }//main
   
   
}//class

Measured memory_bytes: 26184
import numpy as np
N = int(input())
A = np.array(["0"] + input().split() + ["0"], dtype=np.int64)
B = np.abs(A[1:] - A[:-1])
C = np.abs(A[2:] - A[:-2])
total = B.sum()
for i in range(N):
    print(total - B[i:i + 2].sum() + C[i])

Measured memory_bytes: 21416
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 2005
#define INF 1000000005
#define INFLL (long long)1e18
#define PI 3.1415926535897
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    REP(i,n)cin>>a[i];
    vector<bool>check(MAX+1,true);
    sort(ALL(a));
    int ans=0;
    REP(i,n){
        if(check[a[i]]){
            if(i<n-1&&a[i]!=a[i+1])ans++;
            if(i==n-1)ans++;
            for(int j=1;a[i]*j<=MAX;j++){
                check[a[i]*j]=false;
            }
        }
    }
    OUT(ans);
    return 0;
}


Measured memory_bytes: 4024
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int X, Y; cin >> X >> Y;
	if (X % Y) {
		cout << X << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}

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

const int MAXN = 15;
const int MAXD = 15;

int point[MAXN][MAXD];

bool dist(int i, int j, const int& d){
	int ans = 0;
	for (int k=0; k<d; k++){
		ans += ((point[i][k] - point[j][k]) * (point[i][k] - point[j][k]));
	}
	return ((int)sqrt(ans) * (int)sqrt(ans) == ans);
}

int main()
{
	int n, d;
	scanf("%d %d", &n, &d);
	for (int i=0; i<n; i++){
		for (int j=0; j<d; j++)
			scanf("%d", &point[i][j]);
	}
	int ans = 0;
	for (int i=0; i<n; i++){
		for (int j=i+1; j<n; j++){
			if(dist(i, j, d)) ans++;
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,M,R = inputMap()
    r = inputList()
    A = [[float('inf') for _ in range(N)] for _ in range(N)]
    
    for _ in range(M):
        a,b,c = inputList()
        A[a-1][b-1] = c
        A[b-1][a-1] = c
    
    for i in range(N):
        A[i][i] = 0
        
    A = warshall_floyd(A, N)
        
    ans = -1
    visi = list(itertools.permutations(r))
    for sp in visi:
        tmp = 0
        for i, val in enumerate(sp):
            if i == 0:
                continue
            tmp += A[sp[i-1]-1][sp[i]-1]
            
        if ans == -1 or ans > tmp:
            ans = tmp
            
    print(ans)
        
def warshall_floyd(d, n):
	#d[i][j]: iからjへの最短距離
	for k in range(n):
		for i in range(n):
			for j in range(n):
				d[i][j] = min(d[i][j], d[i][k] + d[k][j])
	return d
		
            	
if __name__ == "__main__":
	main()


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if((a+b)>(c+d)){
    cout << "Left" << endl;
  }else if((a+b)==(c+d)){
    cout << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }
  return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
 
struct state{
  int bi,a,b;
  bool operator<(const state& s) const {
    if( bi == s.bi ){
      if( a == s.a ) return b < s.b;
      return a < s.a;
    }
    return bi < s.bi;
  }
};
 
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
 
 
map<state,int> dp;
char cie[55][55];
int fie[55][55];
int N,W,H;
bool check( int bi,int x,int y,int d,int &nst,int &nx,int &ny ){
  bool f = false;
  nst = bi;
  nx = x + dx[d];
  ny = y + dy[d]; 
  if( nx < 0 || nx >= W || ny < 0 || ny >= H ) return false;
  if( cie[nx][ny] == 'X' && !(nst & (1<<fie[nx][ny])) ){
    f = true;     
    nst |= (1<<fie[nx][ny]);
  }
 
  while( f ){
    nx = nx + dx[d];
    ny = ny + dy[d]; 
    if( ny > H-1 || ( ny == H-1 && 0 <= nx && nx < W ) ) return true;
    if( nx < 0 || nx >= W || ny < 0 ) return false;
    if( cie[nx][ny] == 'X' && !(nst & (1<<fie[nx][ny])) ){
      nst |= (1<<fie[nx][ny]);
    } else
      break;
  }
  return f;
}
 
int solve(int bi,int x,int y){
  if( dp.find((state){bi,x,y}) != dp.end() ) return dp[(state){bi,x,y}];
  // cout << bitset<20>(bi) << " "<< x << " "<< y << endl;
  if( y > H-1 || ( y == H-1 && 0 <= x && x < W ) ) return dp[(state){bi,x,y}] = 0;
  int ret = (1<<29);
  for(int i=0;i<8;i++){
    int nx,ny,nst;
    if( check(bi,x,y,i,nst,nx,ny) ){
      ret = min( ret, solve(nst,nx,ny)+1);
    }
  }
  return dp[(state){bi,x,y}] = ret;
}
 
int main(){
  N = 0;
  W=15;H=19;
  int x,y;
  for(int i=0;i<19;i++){
    for(int j=0;j<15;j++){
      cin >> cie[j][i];
      if( cie[j][i] == 'X')
    fie[j][i] = N++;
      if( cie[j][i] == 'O' ){
    x = j; y = i;
      }
    }
  }
  int res = solve(0,x,y);
  if( res == (1<<29) )
    cout << -1 << endl;
  else
    cout << res << endl;
}

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

#define ABS(X) ((X)<0?-(X):(X))
typedef pair<double, int> Subj;

int main(void){  
  int n;
  
  while (cin >> n){
    if (n==0) break;
    vector<Subj> v;
    for (int i=0; i<n; i++){
      int id;
      double h,w,bmi;
      cin >> id >> h >> w;
      h /= 100;
      bmi = w/(h*h);
      v.push_back(make_pair(ABS(bmi-22), id));
    }
    sort(v.begin(), v.end());
    cout << v[0].second << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3192
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

// key以上の要素の最小インデックス
func lowerBound(a []int, key int) int {
	l, r := 0, len(a)-1
	for l <= r {
		mid := (l + r) / 2
		if a[mid] < key {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return l
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	const mod = 1000000007

	n := nextInt()
	c := nextInts(n)
	m := max(c...)

	places := make([][]int, m+1)
	for i := 0; i <= m; i++ {
		places[i] = make([]int, 0)
	}
	for i := 0; i < n; i++ {
		places[c[i]] = append(places[c[i]], i)
	}

	dp := make([]int, n+1)
	dp[0] = 1
	for i := 1; i <= n; i++ {
		dp[i] += dp[i-1]

		color := c[i-1]
		idx := lowerBound(places[color], i-1)
		if idx > 0 {
			j := places[color][idx-1]
			if (i-1)-j > 1 {
				dp[i] += dp[j+1]
			}
		}

		dp[i] %= mod
	}

	puts(dp[n])
}


Measured memory_bytes: 13912
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = float('INF')
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
L = []
for i in range(n):
    s, t = LS()
    t = int(t)
    L += [[s, t]]


x = S()
ret = 0
for i in range(n - 1, -1, -1):
    s, t = L[i]
    if x == s:
        break
    ret += t



print(ret)




Measured memory_bytes: 40496
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
typedef long long ll;

int main() {
	ll N; cin >> N;
	cout << (N * (N - 1)) / 2 << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ちゃんとユニークな配列にする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int N, Y;
  cin >> N >> Y;
  repto(x, N) {
    repto(y, N) {
      int z = N - x - y;
      if(z >= 0 &&
        (x + y + z) == N && 
        ((x * 10000) + (y * 5000) + (z * 1000)) == Y) {
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
import math
import itertools
N = int(input())
Sum = 0
N_2 = math.factorial(N)
lis = []
for i in range(N):
  a,b = map(int,input().split())
  lis.append([a,b])
P = list(itertools.permutations(range(N)))
for j in range(N_2):
  for g in range(N-1):
    Sum += math.sqrt(((lis[P[j][g]][0]-lis[P[j][g+1]][0])**2) + ((lis[P[j][g]][1]-lis[P[j][g+1]][1])**2))
print(Sum/N_2)

Measured memory_bytes: 8052
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>

using namespace std;

void b_string_palindorme(void) {
	string s;
	cin >> s;
	int n = s.size();
	int n_1 = (n - 1) / 2;
	int n_3 = (n + 3) / 2 - 1;

	string s_upper = s.substr(0, n_1);
	string s_lower = s.substr(n_3, n-n_3);
	//cout << s_upper << " " << s_lower << endl;

	string judge = "Yes";
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - i - 1]) {
			judge = "No";
			break;
		}
	}

	for (int i = 0; i < s_upper.size(); i++) {
		if (s_upper[i] != s_upper[s_upper.size() - i - 1]) {
			judge = "No";
			break;
		}
	}

	for (int i = 0; i < s_lower.size(); i++) {
		if (s_lower[i] != s_lower[s_lower.size() - i - 1]) {
			judge = "No";
			break;
		}
	}

	cout << judge << endl;
}

int main()
{
    b_string_palindorme();

    return 0;
}


Measured memory_bytes: 3604
class DisjointSet
    def initialize(n)
        @parent = Array.new(n){-1}
    end
    def find(a)
        return a if @parent[a]<0
        @parent[a] = find(@parent[a])
    end
    def union(a, b)
        x = find(a)
        y = find(b)
        return x if x == y
        if size(x) < size(y)
            t = x
            x = y
            y = t
        end
        @parent[x] += @parent[y]
        @parent[y] = x
        x
    end
    def size(a)
        -@parent[find(a)]
    end
end 

N,Q=gets.split.map(&:to_i)
ds=DisjointSet.new(N)
Q.times{
	t,u,v=gets.split.map(&:to_i)
	case t
	when 0
		ds.union(u,v)
	when 1
		puts ds.find(u)==ds.find(v) ? 1 : 0
	end
}


Measured memory_bytes: 15664
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
map<long long, long long> b;
int a[100010];
int main(){
  long long n;
  while(cin>>n){
    b.clear();
    int tmp=0, lst=0, past=0;
    for(int i=0; i<n; ++i){
      scanf("%d",&a[i]);
      if(i==0){
        ++b[0];
      }
      else{
        ++b[max(past, (i-tmp)/2)];
        past=max(past, (i-tmp)/2);
      }
      tmp+=a[i]-lst-1;
      lst=a[i];
    }
    long long ans=b[0], sm=b[0];
    for(int i=1; i<n; ++i){
      sm+=b[i]-1;
      sm%=mod;
      ans*=sm;
      ans%=mod;
    }
    cout<<ans<<endl;
  }
  return 0;
}




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

template<typename T,T MOD = 1000000007>
struct Mint{
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}
  
  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  
  Mint operator+(Mint a){return Mint(v)+=a;};
  Mint operator-(Mint a){return Mint(v)-=a;};
  Mint operator*(Mint a){return Mint(v)*=a;};

  Mint operator-(){return v?MOD-v:v;}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}

};

//INSERT ABOVE HERE
using M = Mint<int, 10000>;
M dp[505][505][2][2][3][10];
bool used[505][505][2][2][3][10];
int m;
M dfs(string &a,int pos,int v,int tight,int lz,int inc,int curr){
  M &res=dp[pos][v][tight][lz][inc][curr];
  if(used[pos][v][tight][lz][inc][curr]) return res;
  used[pos][v][tight][lz][inc][curr]=1;
  int n=a.size();
  if(pos==n) return res=M(v==0);
  
  res=M(0);
  for(int k=0;k<10;k++){
    if(tight&&a[pos]-'0'<k) continue;
    int npos=pos+1;
    int nv=(v*10+k)%m;
    int ntight=tight&&(a[pos]-'0'==k);
    int nlz=lz&&(k==0);
    int ninc=0;
    int ncurr=k;
    
    if(!lz) ninc=curr<k?1:2;
    if(!lz&&(curr==k||inc==ninc)) continue;
    res+=dfs(a,npos,nv,ntight,nlz,ninc,ncurr);
  }
  return res;
}

int zigzag(string s){
  int n=s.size();
  for(int i=1;i<n;i++) if(s[i-1]==s[i]) return 0;
  for(int i=1;i+1<n;i++) if(s[i-1]<s[i]&&s[i]<s[i+1]) return 0;
  return 1;
}

signed main(){
  string a,b;
  cin>>a>>b>>m;  
  M ans;

  memset(used,0,sizeof(used));
  ans+=dfs(b,0,0,1,1,0,0);
  memset(used,0,sizeof(used));
  ans-=dfs(a,0,0,1,1,0,0);
  
  if(zigzag(a)) ans+=M(1);
  cout<<ans.v<<endl;
  return 0;
}



Measured memory_bytes: 152684
#include <cstdio>

int main()
{
  int x[5];
  int k;
  scanf("%d %d %d %d %d %d", x, x + 1, x + 2, x + 3, x + 4, &k);
  for (int i = 0; i < 4; ++i)
  {
    for (int j = i + 1; j < 5; ++j)
    {
      if (x[j] - x[i] > k)
      {
        puts(":(");
        return 0;
      }
    }
  }
  puts("Yay!");
  return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------
int c[13];
int a[13][13];
//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    int n,m,x;cin>>n>>m>>x;
    for(int i=0;i<n;i++){
        cin>>c[i];
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }

    }
    ll ans=INF;
    for(int bit=0;bit < (1<<n); bit++)
    {
        ll sum=0;
        ll tmp[13];
        memset(tmp,0,sizeof(tmp));
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                sum+=c[i];
                for(ll j=0;j<m;j++){
                    tmp[j]+=a[i][j];
                }
            }
        }
        bool abc=1;
        for(ll j=0;j<m;j++){
            if(tmp[j]<x){
                abc=0;
                break;
            }
        }
        if(abc==1){
            chmin(ans,sum);
        }
    }
    if(ans==INF)ans=-1;
    cout<<ans<<Endl;

    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































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

using namespace std;

int compute_gcd(int i, int j){
  	int divisor = i, dividend = j, remainder;
  	remainder = dividend % divisor;
  	while (remainder){
    	dividend = divisor;
      	divisor = remainder;
      	remainder = dividend%divisor;
    }
  	return divisor;
}

int main(){
  int n,i,j,k;
  long long int sum = 0;
  cin >> n;
  for (i=1;i<=n;i++){
    for (j=i+1;j<=n;j++){
      for (k=j+1;k<=n;k++){
          sum += 6*compute_gcd(compute_gcd(i,j),k);
      }
    }
  }
  sum += (n*(n+1)/2);
  for (i=1;i<=n;i++){
    for(j=i+1;j<=n;j++){
      sum += 6*compute_gcd(i,j);
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define printvector(v,n) for(int i=1;i<=n;i++) cout<<v[i]<<" "; cout<<ln;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for int64)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define RFOR(i,b,a) for(int i=b; i>=a; i--)
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define setPresent(x,s) (s.find(x)!=s.end())
#define sqr(x) x*x
#define siz(v) int(v.size())
const double pi = 3.14159265358979323846;
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef pair<char,int> pci;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef map<ll,ll> m64;
#pragma GCC optimize ("-O2")
template<class T> using min_heap = priority_queue<T, std::vector<T>, std::greater<T> >; 
const int LM=2e5;
ll n,d,a[LM+2],INF=1e18;
p64 sg1[4*LM+5],sg2[4*LM+5];
int sz[LM+2],p[LM+2],siz=1;
vector< pair<ll,p32> > edges;
vp64 v;
// in the segtree also store at what index the minimum
// occurs
int find(int x){
	while(p[x]!=x) x=p[x];
	return x;
}
void unite(int a,int b){
	a=find(a);b=find(b);
	if(sz[a]<sz[b]) swap(a,b);
	p[b]=a;sz[a]+=sz[b];
}
void init(p64 sg[]){
	while(siz<n) siz*=2;
	FOR(i,1,2*siz-1) sg[i]=mp(INF,1);
}
void update(int x,ll val,p64 sg[]){
	sg[x+siz-1]=mp(val,x); 
	x+=siz-1; x/=2;
	while(x!=0){
		sg[x]=min(sg[2*x],sg[2*x+1]);
		x/=2;
	}
}
p64 query(int l,int r,p64 sg[]){
	l+=siz-1;r+=siz-1;
	p64 ret=mp(INF,1);
	while(r>=l){
		if(l%2==1){
			ret=min(ret,sg[l++]);
		}
		if(r%2==0){
			ret=min(ret,sg[r--]);
		}
		l/=2;
		r/=2;
	}
	return ret;
}
int main()
{    
   ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
   cin>>n>>d;
   init(sg1); init(sg2);
   FOR(i,1,n){
   	cin>>a[i];
   	v.pb(mp(a[i],i));
   }
   sort(v.begin(),v.end());
   for(auto u:v){
   	auto t1=query(1,u.se-1,sg1);
   	auto t2=query(u.se+1,n,sg2);
   	int i1=t1.se,i2=t2.se;
   	ll w1=u.fi+d*u.se+t1.fi;
   	ll w2=u.fi-d*u.se+t2.fi;
   	edges.pb(mp(w1,mp(u.se,i1)));
   	edges.pb(mp(w2,mp(u.se,i2)));
   	update(u.se,u.fi-d*u.se,sg1);
   	update(u.se,u.fi+d*u.se,sg2);
   }
   ll ans=0;
   FOR(i,1,n) p[i]=i;
   FOR(i,1,n) sz[i]=1;
   sort(edges.begin(),edges.end());
   for(auto u:edges){
   	if(find(u.se.fi)==find(u.se.se)) continue;
   	else{
   		unite(u.se.fi,u.se.se);
   		ans+=u.fi;
   	}
   }
   cout<<ans<<endl; 
}

Measured memory_bytes: 37100
s=input()
t=input()
s_len=len(s)
t_len=len(t)
s=s[::-1]
t=t[::-1]
ans="UNRESTORABLE"
if s_len>=t_len:
    for i in range(s_len-t_len+1):
        count=0
        for j in range(t_len):
            if s[i+j]=="?" or s[i+j]==t[j]:
                count+=1
            else:
                break
        if count==t_len:
            s=s[:i]+t[:]+s[i+t_len:]
            s=s.replace("?", "a")
            s=s[::-1]
            ans=s
            break
print(ans)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
//        DecimalFormat df = new DecimalFormat("0.00000000");
        
        final int H = Integer.parseInt(sc.next());
        final int A = Integer.parseInt(sc.next());
        out.println(H%A == 0 ? H/A : H/A +1);
        
        out.flush();
    }
}

Measured memory_bytes: 23508
from heapq import heappop, heappush
N, M = map(int, input().split())
AB = []

for i in range(N):
  a, b = map(int, input().split())
  AB.append((a,b)) 

AB.sort()
queue = []
index = 0
ans = 0

for limit in range(1, M+1): # 残り limit日 で仕事を終わらせないといけない
  while index < N and AB[index][0] <= limit:
    a, b = AB[index]
    heappush(queue, -b)
    index += 1

  if queue:
    ans += -heappop(queue)

print(ans)

Measured memory_bytes: 20788
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <map>
#include <random>
#include <string>
#include<vector>
#include<stack>
#include <cstdlib>


using namespace std;
int main() {
	long long n, k, tmp;
	
	int cnt = 1;
	int move,begin=0;
	cin >> n >> k;
	vector<int> a(1,1);

	for (int i = 0; i < n; i++) {
		cin >> tmp;
		a.push_back(tmp);
	}

	vector<int> s;
	vector<int> ord(n+1,-1);

	{int now = 1;
	
		while (ord[now]==-1) {
			ord[now] = s.size();
			s.push_back(now);
			now = a[now];
		}
		begin = ord[now];
		cnt = s.size()-ord[now];
	}

	if (k < begin) {
		cout << s[k];
	}
	else {
		move = (k - begin) % cnt;
		cout << s[move+begin];
	}

	return 0;
}

Measured memory_bytes: 5900
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
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; }
int main()
{
    string s;
    cin >> s;
    int s_size = s.size();
    int a_index = INT_MAX;
    int z_index = INT_MIN;
    for (int i=0; i<s_size; i++) {
        if (s[i] == 'A' && i < a_index) {
            a_index = i;
        } else if (s[i] == 'Z' && i > z_index) {
            z_index = i;
        }
    }

    cout << z_index - a_index + 1 << endl;
    return 0;
}

Measured memory_bytes: 3732