akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
#define N 100010
int par[N];
int rnk[N];

void init(int n){
    for(int i=0;i<n;i++){
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

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

bool same(int x,int y){
    return find(x) == find(y);
}
priority_queue<int,vector<int>,greater<int>> tree[100010];
signed main(){
    int n,m;
    cin >> n >> m;
    init(n);
    int a[100010];
    rep(i,n) cin >> a[i];
    rep(i,m){
        int x,y;
        cin >> x >> y;
        unite(x,y);
    }
    rep(i,n){
        tree[find(i)].push(a[i]);
    }
    int ans = 0;
    int X = 0;
    rep(i,n){
        if(tree[i].size() != 0){
            X++;
            int p = tree[i].top();
            ans += p;
            tree[i].pop();
        }
    }
    if(X == 1){
        cout << 0 << endl;
        return 0;
    }
    vector<int> b;
    rep(i,n){
        while(tree[i].size() != 0){
            b.pb(tree[i].top());
            tree[i].pop();
        }
    }
    if((int)(b.size()) < X - 2){
        cout << "Impossible" << endl;
    }else{
        SORT(b);
        rep(i,X-2){
            ans += b[i];
        }
        cout << ans << endl;
    }

    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_d
// rm -r -f test;oj dl http://apc001.contest.atcoder.jp/tasks/apc001_d

Measured memory_bytes: 8832
#include<iostream>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)

int main(){
  ll n, k;
  ll a[100001];
  cin>>n>>k;
  rep(i,n){
    cin>>a[i];
  }
  /*最終的に全部一になる
   * 1から始めて、広げて行く*/
  rep(i,n){
    if((k-1)*(i-1)+k >= n) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  int n;
  cin>>n;
  V<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(all(a));
  int mi=a.front(),ma=a.back();
  if(mi==ma){
      if(ma==n-1||ma*2<=n)cout<<"Yes"<<"\n";
      else cout<<"No"<<"\n";
  }else{
      int x=0,y=0;
      for(int i=0;i<n;i++){
          if(ma==a[i])y++;
          else if(mi==a[i])x++;
      }
      if(x+y!=n||ma<=x||y<2*(ma-x)||ma!=mi+1)cout<<"No"<<"\n";
      else cout<<"Yes"<<"\n";
  }
}


Measured memory_bytes: 3688
// youngjinp20
// 2020 03

#include <bits/stdc++.h>
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; }
#define byr(x) [](const auto& a, const auto& b) { return a.x > b.x; }
#define smax(a, b) ((a) < (b) ? ((a)=(b), true) : false)
#define smin(a, b) ((a) > (b) ? ((a)=(b), true) : false)
using namespace std;

typedef long long ll;

int N;
int ct[4];
const int MAX = 301;
double prob[MAX][MAX][MAX];
double dp[MAX][MAX][MAX];

double get_prob(int a, int b, int c) {
	/* cout << "prob: " << a << " " << b << " " << c << endl; */
	if (a < 0) return 0;
	if (b < 0) return 0;
	if (c < 0) return 0;
	if (prob[a][b][c] != -1) return prob[a][b][c];
	if (a+b+c > N) return 0;
	double x=0, y=0, z=0;
	x = get_prob(a+1, b, c)   * (double) (a+1)/(a+b+c+1);
	if (a+b+c) {
		y = get_prob(a-1, b+1, c) * (double) (b+1)/(a+b+c);
		z = get_prob(a, b-1, c+1) * (double) (c+1)/(a+b+c);
	}
	return prob[a][b][c] = x+y+z;
}

double solve(int a, int b, int c) {
	if (a < 0) return 0;
	if (b < 0) return 0;
	if (c < 0) return 0;
	if (dp[a][b][c] != -1) return dp[a][b][c];
	if (a+b+c > N) return 0;
	double total = get_prob(a,b,c);
	double x=0, y=0, z=0;
	x = (solve(a+1,b,c)     + (double) N/(a+b+c+1)) * get_prob(a+1,b,c) * (a+1)/(a+b+c+1);
	if (a+b+c) {
		y = (solve(a-1,b+1,c) + (double) N/(a+b+c))   * get_prob(a-1,b+1,c) * (b+1)/(a+b+c);
		z = (solve(a,b-1,c+1) + (double) N/(a+b+c))   * get_prob(a,b-1,c+1) * (c+1)/(a+b+c);
	}
	if (total == 0) return dp[a][b][c] = 0;
	return dp[a][b][c] = (x+y+z)/total;
}

int main() {
	cin >> N;
	for (int i=0; i<N; i++) {
		int tmp;
		cin >> tmp;
		ct[tmp] ++;
	}

	for (int i=0; i<MAX; i++) {
		for (int j=0; j<MAX; j++) {
			for (int k=0; k<MAX; k++) {
				dp[i][j][k] = -1;
				prob[i][j][k] = -1;
			}
		}
	}

	prob[ct[1]][ct[2]][ct[3]] = 1;
	dp[ct[1]][ct[2]][ct[3]] = 0;

	printf("%.9lf", solve(0,0,0));

	return 0;
}


Measured memory_bytes: 426496
from bisect import bisect_right
N, H = map( int, input().split())
A,B = [], []
for i in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)

maxA = max(A)
sortB = sorted(B)
RsortB = sortB[::-1]
L = N - bisect_right(sortB,maxA)
ans = 0
damage_sum = 0
Flag = True
for i in range(L):
    damage_sum = damage_sum + RsortB[i]
    if damage_sum < H:
        ans += 1
        pass
    else:
        ans += 1
        Flag = False
        break
if Flag:
    ans += (H - damage_sum + maxA - 1)//maxA
print(ans)

Measured memory_bytes: 12640
n = gets.to_i
names = Hash.new(0)
n.times do
  names[gets[0]] += 1
end
ans = 0
names.to_a.select { |k, v| ['M', 'A', 'R', 'C', 'H'].include?(k) }.map { |s| s[1] }.combination(3).each do |s|
  ans += s.inject(:*)
end
puts ans

Measured memory_bytes: 2044
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	L := make([]int, N)
	sum := 0
	max := 0
	for i := 0; i < N; i++ {
		fmt.Scan(&L[i])
		l := L[i]
		sum += l
		if max < l {
			max = l
		}
	}

	if max < sum-max {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll a;
  cin >> a;
  print(a+a*a+a*a*a);
}


Measured memory_bytes: 3648
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<int>>
constexpr auto mod = 1000000007;


//2のn乗を求めるよ！！！
int ni(int n) {
	if (n == 0)return 1;
	int x = ni(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
}

//フィボナッチ数列のx番目を求めるよ！
int f(int x, vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1, s) + f(x - 2, s);
	return s[x];
}

//aとｂの最大公約数を求めるよ！
llint gcd(llint a, llint b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//m進数のn桁を全列挙やで
void dfs(int m, int n) {

	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			cout << now << endl;
		}
		else {
			for (int i = m - 1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}

int main() {
	int n;
	int ans = 0;
	cin >> n;
	hei(int) s(n+1,0);
	rep(i, 0, n)cin >> s[i];
	rep(i, 0, n+1) {
		if (s[i] > 0) {
			for (int j = i;; j++) {
				if (s[j] == 0)break;
				s[j]--;
			}
			ans++;
			i = -1;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
main = do
       a<-getLine
       let (x0:y0:x1:y1:[])=(map read . words) a::[Int]
       putStrLn $ show (y0 - y1 + x1)++" "++show (y1 - x0 + x1)++" "++show (y0 - y1 + x0)++" "++show(x1 - x0 + y0) 
       

Measured memory_bytes: 508
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;

#define MAX_SIZE 1000+10

int map[MAX_SIZE][MAX_SIZE];
int m_cnt[MAX_SIZE][MAX_SIZE];

int my[8] = { 1,1,1,0,-1,-1,-1,0 };
int mx[8] = { 1,0,-1,-1,-1,0,1,1 };

struct ST
{
	int cnt;
	int y, x;
};

int main(void)
{
	queue<ST> QU;
	ST now, tp;

	int h, w;
	char tmp;

	int c_max=0;

	int i, j,k;

	cin >> h >> w;

	for (i = 1; i <= h; i++)
	{
		scanf("%c", &tmp);
		for (j = 1; j <= w; j++)
		{
			scanf("%c", &tmp);
			if (tmp == '.')
			{
				map[i][j] = -1;
			}
			else
			{
				map[i][j] = tmp - 48;
			}
		}
	}

	for (i = 2; i < h; i++)
	{
		for (j = 2; j < w; j++)
		{
			for (k = 0; k < 8; k++)
			{
				if (map[i + my[k]][j + mx[k]] == -1)
				{
					m_cnt[i][j]++;
				}
			}

			if (map[i][j] <= m_cnt[i][j] && map[i][j]!=-1)
			{
				now.cnt = 1;
				now.y = i;
				now.x = j;
				QU.push(now);
			}
		}
	}

	while (!QU.empty())
	{
		now = QU.front();
		QU.pop();

		if (map[now.y][now.x] == -1)
		{
			continue;
		}
		map[now.y][now.x] = -1;

		c_max = max(c_max, now.cnt);

		for (i = 0; i < 8; i++)
		{
			m_cnt[now.y + my[i]][now.x + mx[i]]++;

			if (map[now.y + my[i]][now.x + mx[i]] <= m_cnt[now.y + my[i]][now.x + mx[i]] && map[now.y + my[i]][now.x + mx[i]] != -1)
			{
				tp.cnt = now.cnt+1;
				tp.y = now.y + my[i];
				tp.x = now.x + mx[i];
				QU.push(tp);
			}
		}


	}

	cout << c_max << endl;

	return 0;
}


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

int main() {
    ll a,b,c;
    string s;
    cin >> a >> s;
    b=(s[0]-'0')*100+(s[2]-'0')*10+s[3]-'0';
    c=a*b;
    c/=100;
    cout << c;
}


Measured memory_bytes: 3592
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	ll cur = 1LL;
	vector<ll> a(n);
	int f = 0;
	rep(i, n) cin >> a[i], f |= !a[i];
	if(f){
		cout << 0 << endl;
		return 0;
	}
	rep(i, n){
		ll x = a[i];
		if(((ll)1e18 / cur) < x){
			cout << -1 << endl;
			return 0;
		}
		cur *= x;
	}
	cout << cur << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3932
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

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

    int any = 0;
    set<int> colors;
    REP(i, 0, N) {
        int a; cin >> a;
        if (a < 400) {
            colors.insert(0);
        } else if (a < 800) {
            colors.insert(1);
        } else if (a < 1200) {
            colors.insert(2);
        } else if (a < 1600) {
            colors.insert(3);
        } else if (a < 2000) {
            colors.insert(4);
        } else if (a < 2400) {
            colors.insert(5);
        } else if (a < 2800) {
            colors.insert(6);
        } else if (a < 3200) {
            colors.insert(7);
        } else {
            any++;
        }
    }

    cout << max((int)colors.size(), 1) << " " << (int)colors.size() + any << endl;
    return 0;
}

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
#define int long long
const int INF = 1e9;

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);

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

    vector<int> used(n, 0);
    vector<int> cur;

    int v = 0;
    int t = 1;

    while (!used[v]){
      cur.eb(v);
      used[v] = t;
      t++;
      v = a[v];
    }

    int N = (int)cur.size();

    if (k < N){
      cout << cur[k] + 1 << '\n';
      return 0;

    }

    k -= (used[v] - 1);
    N -= (used[v] - 1);


    cout << cur[used[v] - 1 + k % N] + 1 << '\n';

    return 0;
}


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




int main(){

  ll mod=1e9+7;
  ll n,m,t,ans=0,a,b,c;
  cin>>n;
  rep(i,n){
      cin>>a>>b;
      if(a==b){
          ans++;
      }else{
          ans=0;
      }
      if(ans==3){
          cout<<"Yes";
          break;
      }

  }
   if(ans!=3)cout<<"No";   

}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main() {
	int a, b;
	char  k[505][505];
	cin >> a >> b;
	for (int i = 0; i < a; ++i) {
		for (int j = 0; j < b; ++j) {
			cin >> k[i][j];
		}
	}

	//red
	for (int i = 0; i < a; ++i) {
		for (int j = 0; j < b; ++j) {
			if (i % 2 == 1&&j!=b-1) cout << "#";
			else if (j == 0) cout << "#";
			else if (k[i][j] == '#') cout << "#";
			else cout << ".";
		}
		cout << endl;
	}
	cout << endl;
	//blue
	for (int i = 0; i < a; ++i) {
		for (int j = 0; j < b; ++j) {
			if (i % 2 == 0&&j!=0) cout << "#";
			else if (j == b - 1) cout << "#";
			else if (k[i][j] == '#') cout << "#";
			else cout << ".";
		}
		cout << endl;
	}
}

Measured memory_bytes: 1024
import sys,math
from collections import deque,defaultdict
import operator as op
from functools import reduce

sys.setrecursionlimit(10**6) 

I=sys.stdin.readline

 #s="abcdefghijklmnopqrstuvwxyz"

"""
x_move=[-1,0,1,0,-1,1,1,-1]
y_move=[0,1,0,-1,1,1,-1,-1]
"""
def ii():
	return int(I().strip())
def li():
	return list(map(int,I().strip().split()))
def mi():
	return map(int,I().strip().split())

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
def divi(n):
	if n==1:
		return 1
	cnt=2
	for i in range(2,int(n**.5)+1):
		if n%i==0:
			if i==n//i:
				cnt+=1
			else:
				cnt+=2
	return cnt

arr=[2]*(10**6+1)
arr[1]=1
for i in range(2,10**6+1):
	for j in range(i*i,10**6+1,i):
		if j//i==i:
			arr[j]+=1
		else:
			arr[j]+=2
def main():
	n=ii()
	ans=0
	for i in range(1,n):
		ans+=arr[n-i]

	print(ans)
	

























	
	
	





if __name__ == '__main__':
	main()

Measured memory_bytes: 17076
#include<bits/stdc++.h>
using namespace std;
const long INF=1L<<60;
long A[200000]={0};long dp[200000][5];
long cost(int a,int b){
    if(b==0||b==4){
        return A[a];
    }else if(b==1||b==3){
        if(A[a]==0){
            return 2;
        }else{
            return A[a]%2;
        }
    }else{
        return (A[a]+1)%2;
    }
}
int main(){
    int L;cin>>L;
    for(int i=0;i<L;i++){ cin>>A[i]; }
    for(int i=0;i<200000;i++){
       for(int j=0;j<5;j++){
           dp[i][j]=INF;
       }
    }for(int j=0;j<5;j++){
        dp[0][j]=cost(0,j);
    }for(int i=0;i<=L-2;i++){
        for(int j=0;j<5;j++){
            for(int k=0;k<=j;k++){
                dp[i+1][j]=min(dp[i+1][j],dp[i][k]+cost(i+1,j));
            }
        }  
    }long result=INF;
    /*for(int i=0;i<L;i++){
        for(int j=0;j<5;j++){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    for(int i=0;i<5;i++){
        result=min(result,dp[L-1][i]);
    }cout<<result<<endl;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,K,C;
    cin>>N>>K>>C;
    string S; cin>>S;
    vector<ll> A(N,0);
    vector<ll> B(N,0);
    vector<ll> ans;
    ll ct=0;
    rep(i,N){
        if(S[i]=='o'){
            ++ct;
            A[i]=ct;
            /*
            reps(j,i,min(N,i+C+1)){
                A[i]=ct;
            }
            */
            i=i+C;
        }
    }
    if(ct!=K){
        cout<<"\n"; return;
    }
    repr(i,N-1,0){
        if(S[i]=='o'){
            repr(j,i,max(0LL,i-C)){
                B[j]=ct;
            }
            --ct;
            i=i-C;
        }
    }
    /*
    sum[0]=A[0];
    reps(i,1,N){
        sum[i]=sum[i-1]+A[i];
    }
    */
    rep(i,N){
        if(S[i]=='o'){
            bool ok=true;
            reps(j,i+1,min(N,i+C+1)){
                if(S[j]=='o' and B[j]!=A[i]+1) ok=false; 
            }
            if(ok) ans.emplace_back(i+1);
            i=i+C;
        }
    }
    SORT(ans);
    for(auto x: ans){
        cout<< x <<"\n";
    }

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

int main() 
{
    ll w, h, x, y;
    cin >> w >> h >> x >> y;

    double S = w*h /2.0;
    int ans = 0;
    if ( 2*x == w && 2*y == h) ans = 1;
    printf("%.8f %d\n", S, ans);
    return 0;
}


Measured memory_bytes: 256
//Shivam gupta (Codeforces handle : shivam_1999)

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define ll long long
#define ld long double
typedef vector<long long> vi;
typedef vector<vi> vvi;
typedef pair<long long, long long> pii;
typedef vector<pair<long long, long long>> vpii;
typedef map<long long, long long> mii;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define sorta(x) sort(x.begin(),x.end())
#define sortd(v) sort(all(v), greater<ll>())
#define el cout << endl;
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define cpresent(container, element) (find(all(container), element) != container.end())
#define deb(x) cout << #x << x << endl;
#define fl(i,n) for(ll i=0;i<n;i++)
#define fls(i,x,n) for(ll i=x;i<n;i++)
#define flr(i,n)  for(ll i=n-1;i>=0;i--)
#define fla(i,v)  for(auto i:v)    
#define in(v) for(auto &i:v){cin>>i;}
#define INF 1e9+1
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define tt    \
    int T;    \
    cin >> T; \
    while (T--)

int main()
{   fast
    ll n,w;
    cin >> n >> w;
    ll wg[n], v[n], sum = 0;
    fl(i,n){
        cin >> wg[i] >> v[i];
        sum += v[i];
    }
    ll dp[n][sum + 1];

    fl(i,n){
        fl(j,sum+1){
            if(j == 0) {
				dp[i][j] = 0;
				continue;
			}
 
			if(i == 0) {
				dp[i][j] = j == v[i] ? wg[i] : INF;
				continue;
			}

            dp[i][j] = INF;
            if(j < v[i]) {
				dp[i][j] = dp[i - 1][j];
			} else {
				dp[i][j] = min(dp[i - 1][j - v[i]] + wg[i], dp[i - 1][j]);
			}
        }
    }
    ll result;
	for(int i = sum; i >= 0; i--) {
		if(dp[n - 1][i] <= w) {
			result = i;
			break;
		}
	}
    cout << result << endl;
}


Measured memory_bytes: 81776
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    ll n,k ; cin >> n >> k;
    ll ans = 0;
    while(n!=0){
        n /= k;
        ans++;
    }
    cout << ans << endl;
}


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


bool solve(){
    int n, h, w;
    cin >> n >> h >> w;
    vector<int> hr(h, 0), wr(w, 0);
    for(int i = 0; i < n; ++i){
        int x, y, k;
        cin >> x >> y >> k;
        ++hr[max(x - k, 0)];
        if(x + k < h)
            --hr[x + k];
        ++wr[max(y - k, 0)];
        if(y + k < w)
            --wr[y + k];
    }
    for(int i = 0; i < h - 1; ++i)
        hr[i + 1] += hr[i];
    for(int i = 0; i < w - 1; ++i)
        wr[i + 1] += wr[i];

    cout << (max(*min_element(hr.begin(), hr.end()), *min_element(wr.begin(), wr.end())) > 0 ? "Yes" : "No") << endl;
    return false;
}

signed main(){
    while(solve());
}



Measured memory_bytes: 3640
#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {

	int n, l, apple[101], check = 1, ans = 0;

	cin >> n >> l;

	for (int i = 1;i <= n;i++) {
		apple[i] = l + i - 1;
	}

	for (int i = 1;i <= n;i++) {
		if(abs(apple[check])>abs(apple[i])){
			check = i;
		}
	}

	apple[check] = 0;

	for (int i = 1;i <= n;i++) {
		ans += apple[i];
	}

	cout << ans << endl;

	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    
    multiset<int> s;
    REP(i, N){
        auto itr = s.lower_bound(A[i]);
        // cout << *itr << " " << boolalpha << (itr == s.begin()) << endl;
        if(itr != s.begin()) s.erase(--itr);
        s.insert(A[i]);
    }
    cout << s.size() << endl;
    
    return 0;
}

Measured memory_bytes: 5376
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll mod = 1000000007;

using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> a= {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k-1] << "\n";
}


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

int s[1001];

int main(){
	int n, sum;
	double m, sd;
	while (scanf("%d",&n) && n != 0) {
		sum = 0;
		sd = 0;
		for (int i = 0; i < n; i++) {
			scanf("%d",&s[i]);
			sum += s[i];
		}
		m = 1.0*sum / n;
		for (int i = 0; i < n; i++) {
			sd += pow(s[i] - m, 2);
		}
		printf("%.6lf\n", sqrt(sd / n));
	}

	return 0;
}

Measured memory_bytes: 2684
import java.util.*;
 
class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int N = sc.nextInt();
		int K = sc.nextInt();
        int[] d = new int[K];
        int[] h = new int[N];
        
        for(int i=0; i<K; i++){
          d[i] = sc.nextInt();     //i番目のお菓子を持っている人数
          int[] A = new int[d[i]];
          for(int j=0; j<d[i]; j++){
            A[j] = sc.nextInt();
            h[A[j]-1]++;
          }
        }
      
        int count = 0;
        for(int i=0; i<N; i++){
          if(h[i]==0){
            count++;
          }
        }
        System.out.println(count);
	}
}

Measured memory_bytes: 46056
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]

sum = 0
for i in range(len(a)-1):
    sum += abs(a[i+1] - a[i])

for i in range(1, len(a)-1):
    if (a[i] - a[i-1]) * (a[i+1] - a[i]) > 0:
        print(sum)
    else:
        save = 2 * min(abs(a[i] - a[i-1]), abs(a[i+1] - a[i]))
        print(sum - save)

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

#define pb push_back
#define ss second
#define ff first
#define N 100005
#define ll long long
#define mid(a,b) (a+b)/2
#define pii pair<ll,ll>

using namespace std;

ll mod = 1e9+7;
ll n,k;
ll fc[N],inv[N],a[N],sum;

int read(){
	char c=getchar();ll ans=0,b = 0;
	while(c < '0' or c > '9'){
		if(c == '-') b = 1;
		c=getchar();
	}
	while (c>='0'&&c<='9') ans=ans*10+c-'0',c=getchar();
	if(b) ans *= -1;
	return ans;
}

ll big(ll a,ll b){
	if(b == 0) return 1;
	ll x = big(a,b / 2);
	if(b % 2) return (((x * x) % mod) * a) % mod;
	return (x * x) % mod;
}

ll norm(ll x){
	if(x < 0) x += mod;
	else if(x >= mod) x -= mod;
	
	return x;
}

ll C(ll n,ll k){
	return (((fc[n] * inv[n - k]) % mod) * inv[k]) % mod;
}

int main()
{
	n = read(),k = read();
	fc[0] = 1;
	for(int i = 1;i <= n;i++)
		fc[i] = (fc[i - 1] * i) % mod;
	inv[n] = big(fc[n],mod - 2);
	for(int i = n - 1;i >= 0;i--)
		inv[i] = (inv[i + 1] * (i + 1)) % mod;
	for(int i = 1;i <= n;i++) a[i] = read();
	sort(a + 1,a + n + 1);
	
	for(int i = n;i >= k;i--){
		sum += ((a[i] * C(i - 1,k - 1)) % mod);
		sum %= mod;
	}
	for(int i = 1;i <= n - k + 1;i++){
		sum -= ((a[i] * C(n - i,k - 1)) % mod);
		sum = norm(sum);
	}
	printf("%lld",sum);
}

Measured memory_bytes: 2560
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

divisors = make_divisors(N)
l = len(divisors)

a = divisors[(l-1)//2]
b = N // a

print(a+b-2)

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

int main() {
  int h, w;
  int c;
  int dp[50][50];
  char ch;

  cin >> h >> w;
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      cin >> ch;
      c = ch - '0';
      if(i == 0 && j == 0) {
	dp[i][j] = c;
      } else {
	if(i == 0) dp[i][j] = dp[i][j-1] + c;
	else if(j == 0) dp[i][j] = dp[i-1][j] + c;
	else {
	  dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + c;
	}
      }
    }
  }
  cout << dp[h-1][w-1] << endl;

  return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <string>

using namespace std;

int H, W;
int ansx, ansy;
int tile[100][100];

void move(int x, int y) {
	int here = tile[y][x];
	tile[y][x] = -1;

	if (here) {
		if (here == -1) {
			ansx = -1;
			ansy = -1;
		}
		else if (here == 1)		move(x+1, y);
		else if (here == 2)	move(x-1, y);
		else if (here == 3) move(x, y-1);
		else				move(x, y+1);
	}
	else {
		ansx = x, ansy = y;
	}

	return;
}

int main() {
	string str;

	while (cin >> H >> W) {
		if (H == 0 && W == 0) break;

		for (int i = 0; i < H; i++) {
			cin >> str;
			
			for (int j = 0; j < W; j++) {
				tile[i][j] = (str[j] == '.') ? 0 : (str[j] == '>') ? 1 : (str[j] == '<') ? 2 : (str[j] == '^') ? 3 : 4;
			}
		}

		move(0, 0);

		if (ansx == -1 && ansy == -1)
			cout << "LOOP" << endl;
		else
			cout << ansx << ' ' << ansy << endl;
	}

	return 0;
}

Measured memory_bytes: 1252
from collections import defaultdict
N, M, *L = map(int, open(0).read().split())
dic = defaultdict(list)
rdic = defaultdict(list)
nin = [0]*N
Els = []
for a,b,c in zip(*[iter(L)]*3):
  dic[a-1] += [b-1]
  rdic[b-1] += [a-1]
  nin[b-1] += 1
  Els += [(a-1,b-1,c)]

To = [False]*N
From = [False]*N
q = [0]
To[0] = True
while q:
  p = q.pop()
  for e in dic[p]:
    if To[e]==False:
      To[e] = True
      q += [e]
q = [N-1]
From[N-1] = True
while q:
  p = q.pop()
  for e in rdic[p]:
    if From[e]==False:
      From[e] = True
      q += [e]

ok = [False]*N
for i  in range(N):
  ok[i] = To[i]&From[i]

cnt = 0
dist = [-float('inf')]*N
dist[0] = 0
cnt = 0
flag = False
while True:
  update = True
  for a,b,c in Els:
    if not(ok[a] and ok[b]):
      continue
    if dist[a]!=-float('inf') and dist[b]<dist[a]+c:
      dist[b] = dist[a]+c
      update = False
  if update:
    break
  cnt += 1
  if cnt>N:
    flag = True
    break

if flag:
  print('inf')
else:
  print(dist[N-1])

Measured memory_bytes: 44780
N = int(input())
H = input().split()
H = [int(h) for h in H]

count = 0
for i in range(N-1):#(0~N-2)
    num = N-i-1
    if(H[num-1]-1==H[num]):
        H[num-1] -= 1
    elif(H[num-1]-1>H[num]):
        count += 1
        break
        
if(count == 0):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println(String.valueOf(a + b).length());
		}

	}

}

Measured memory_bytes: 20604
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    sort(all(a));
    if (a[0] > 0) {
        vector<int> x(n - 1), y(n - 1);
        int now = a[0];
        rep(i, n - 2) {
            x[i] = now;
            y[i] = a[i + 1];
            now -= a[i + 1];
        }
        x[n - 2] = a[n - 1];
        y[n - 2] = now;
        cout << x[n - 2] - y[n - 2] << "\n";
        rep(i, n - 1) cout << x[i] << " " << y[i] << "\n";
        return;
    }
    if (a[n - 1] <= 0) {
        reverse(all(a));
        vector<int> x(n - 1), y(n - 1);
        int now = a[0];
        rep(i, n - 1) {
            x[i] = now;
            y[i] = a[i + 1];
            now -= a[i + 1];
        }
        cout << x[n - 2] - y[n - 2] << "\n";
        rep(i, n - 1) cout << x[i] << " " << y[i] << "\n";
        return;
    }
    
    int cnt = 0;
    rep(i, n) {
        if (a[i] <= 0) ++cnt;
    }
    vector<int> x(n - 1), y(n - 1);
    int now = a[0];
    rep(i, n - cnt - 1) {
        x[i] = now;
        y[i] = a[cnt + i];
        now -= y[i];
    }
    x[n - cnt - 1] = a[n - 1];
    y[n - cnt - 1] = now;
    now = x[n - cnt - 1] - y[n - cnt - 1];
    rep(i, cnt - 1) {
        x[n - cnt + i] = now;
        y[n - cnt + i] = a[i + 1];
        now -= a[i + 1];
    }
    cout << x[n - 2] - y[n - 2] << "\n";
    rep(i, n - 1) cout << x[i] << " " << y[i] << "\n";
    return;
}



Measured memory_bytes: 4516
#include <iostream>

using namespace std;

int main (void)
{
    int h, w;
    char origin[100][100], doubled[200][100];

    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        cin >> origin[i];
    }

    for (int i = 0; i < 2 * h; i++) {
        for (int j = 0; j < w; j++) {
            doubled[i][j] = origin[i/2][j];
        }
    }

    for (int i = 0; i < 2 * h; i++) {
        for (int j = 0; j < w; j++) {
            cout << doubled[i][j];
        }
        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int to,costa,costb;};


signed main() {
int n,x,d;
cin>>n>>x>>d;
if(d==0){
    if(x==0)cout<<1;
    else cout <<n+1;
    return 0;
}
if(d<0){
    x*=-1;
    d*=-1;
}
priority_queue<int,vector<int>,greater<int>> s,e;
for(int i=0;i<=n;i++){
    s.push(i*x+i*(i-1)*d/2 -d);
    e.push(i*x+i*(2*n-i-1)*d/2 );
}
//cerr<<e.top()<<' '<<s.top()<<endl;
map<int,int> mp,s0;int ans=0;
while(!s.empty()){
    if(s.top()<=e.top()){
        if(mp[(d +s.top()%d)%d]==0)s0[(d +s.top()%d)%d]=s.top();
        mp[(d +s.top()%d)%d]++;
        s.pop();
    }else{
        mp[(d +e.top()%d)%d]--;
        if( mp[(d +e.top()%d)%d]==0){
            ans+=(e.top()- s0[(d +e.top()%d)%d])/d;
           // cerr<< mp[(d +e.top()%d)%d]<<' '<<e.top()<<endl;
        }
        e.pop();
    }
}
while(!e.empty()){
    mp[(d +e.top()%d)%d]--;
        if( mp[(d +e.top()%d)%d]==0){
            ans+=(e.top()- s0[(d +e.top()%d)%d])/d;
           // cerr<< mp[(d +e.top()%d)%d]<<' '<<e.top()<<endl;
        }
        e.pop();
}
cout<<ans;



return 0;
}


Measured memory_bytes: 28388
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T = int > T in() {
  T x;
  cin >> x;
  return (x);
}
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vec< pair< int, int > > a(N);
  FORA(e, a) {
    cin >> e.snd >> e.fst;
    e.snd--;
    e.fst *= -1;
  }
  sort(ALL(a));
  // revese(ALL(a));
  vec< int > flg(M);
  //  set< int > st;
  REP(i, M) { flg[i] = i; }
  int reward = 0;
  FORA(e, a) {
    auto itr = lower_bound(flg.begin(), flg.end(), e.snd);
    // cout << e.fst << " " << e.snd << "\n";
    if (itr != flg.end()) {
      reward += e.fst;
      flg.erase(itr);
    }
  }
  reward *= -1;
  print(reward);
}

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

class DisjointSet{
public:
    //???????????????
    vector<int> rank;
    //??????????´??????????
    vector<int> p;

    DisjointSet(unsigned long size){
        //???????????´
        rank.resize(size,0);
        p.resize(size,0);
        //??????n?????????
        for(int i=0;i<size;i++)
            makeSet(i);
    }

    //???????????????????´?x?????°??????
    void makeSet(int x){
        p[x]=x;
        rank[x]=0;
    }

    //??????x???y????????¨???????????????
    bool same(int x,int y){
        return findSet(x)==findSet(y);
    }

    //?????¶x???y?????¨?????????
    void unite(int x,int y){
        link(findSet(x),findSet(y));
    }

    //?????\x???y
    void link(int x,int y){
        //?????????????????\??°????????????????????¢
        if(rank[x]>rank[y])
            p[y]=x;
        else{
            p[x]=y;
            //??????????????????????????????????????¶????????????????????????
            if(rank[x]==rank[y])
                rank[y]++;
        }
    }

    //?±???£??¨????´?
    int findSet(int x){
        //??????????¶??????¶??´???x???????????£??¨????´?
        if(x!=p[x])
            //????????????
            p[x]=findSet(p[x]);
        return p[x];
    }
};

int main(){
    int n,a,b,q,t;

    cin>>n>>q;
    DisjointSet ds(n);

    for(int i=0;i<q;i++){
        cin>>t>>a>>b;
        if(t==0)
            ds.unite(a,b);
        else if(t==1){
            if(ds.same(a,b))
                cout<<1<<endl;
            else
                cout<<0<<endl;
        }
    }
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K;
  cin >> K;
  long Ans = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        Ans += gcd(i, gcd(j, k));
      }
    }
  }
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
 
//Class.
vector<int> L[2000];
int N, M, E;
int match[2000];
bool used[2000];
int x[2000], y[2000];
 
bool DFS(int V) {
    used[V] = true;
    for (int i = 0; i < L[V].size(); i++) {
        int u = L[V][i]; int w = match[u];
        if (w < 0 || !used[w] && DFS(w)) {
            match[V] = u;
            match[u] = V;
            return true;
        }
    }
    return false;
}
 
int supermatching() {
    int r = 0;
    memset(match, -1, sizeof(match));
    for (int j = 0; j < N + M; j++) {
        if (match[j] < 0) {
            memset(used, 0, sizeof(used));
            if (DFS(j)) { r++; }
        }
    }
    return r;
}
 
//main.
int main() {
    while (true) {
        for (int i = 0; i < 2000; i++) { L[i].clear(); }
        cin >> N >> M; if (!N) { break; }
        for (int i = 0; i < N; i++) {
            cin >> x[i];
        }
        for (int i = 0; i < M; i++) {
            cin >> y[i];
        }
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                if (__gcd(x[i], y[j]) != 1) {
                    L[i].push_back(j + N);
                }
            }
        }
        cout << supermatching() << endl;
    }
    return 0;
}

Measured memory_bytes: 4088
#include<bits/stdc++.h>
#define N 100010
using namespace std;
int ans[N];
int main()
{
    int n, h;
    cin>>n;
    for(int i = 1;i<=n;i++) {
        int a;
        cin>>a;
        ans[a] = i;
    }

    for(int i = 1;i<=n;i++) cout<<ans[i]<<" ";
    cout<<endl;
}




Measured memory_bytes: 1152
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
	double r;cin >> r;
	cout << 2 * r * 3.1415926;
    return 0;
}


Measured memory_bytes: 3224
import collections

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]

if (N==1):
    print(1)
    quit()

pq = []
cost = N

for xyi in xy:
    for xyj in xy:
        pq.append((xyi[0]-xyj[0], xyi[1]-xyj[1]))

count = collections.Counter(pq)
if (count.most_common()[0][0] == (0,0)):
    print(N - count.most_common()[1][1])
else:
    print(N - count.most_common()[0][1])



Measured memory_bytes: 39536
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
using Map = vector<vector<char>>;
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 dx[] = {0, -1, 0, 1};
int dy[] = {1, 0, -1, 0};
int H, W;

int bfs(Map& maze, int h, int w) {
  int ret = 0;
  queue<int> quex, quey, max;
  quex.push(w); quey.push(h);
  maze[h][w] = '*';
  max.push(0);
  while(!quex.empty()) {
    int x = quex.front();
    int y = quey.front();
    int n = max.front();
    chmax(ret, n);
    quex.pop(); quey.pop(); max.pop();
    rep(i,4) {
      if(0<=x+dx[i] && x+dx[i]<W && 0<=y+dy[i] && y+dy[i]<H && maze[y+dy[i]][x+dx[i]]=='.') {
        maze[y+dy[i]][x+dx[i]]= '*';
        quex.push(x+dx[i]);
        quey.push(y+dy[i]);
        max.push(n+1);
      }
    }
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  Map S(H, vector<char>(W));
  rep(h,H) { rep(w,W) { cin >> S[h][w]; } }

  int ans = 0;
  rep(h,H) {
    rep(w,W) {
      Map maze = S;
      if(S[h][w] == '.') {chmax(ans, bfs(maze, h, w));}
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
#print(n)
#print(a)
count=0
flag=True
while(flag):
    flag=False
    for i in range(n):
        while(a[i]%2==0):
            #print(i)
            #a=list(map(lambda x:x*3,a))
            a[i]=int(a[i]/2)
            #print(a)
            count+=1
            flag=True
            #break
print(count)
#たぶんリスト全部に3かけて該当を６で割ればよさそう
#３倍する必要がない

Measured memory_bytes: 4148
a, b = map(int, input().split())
def factor(n):
    a = []
    while not n%2:
       n//=2
       a.append(2)
    i = 3
    while i*i<=n:
        while not n%i:
            n//=i
            a.append(i)
        i+=2
    if n>1:
        a.append(n)
    return a
print(len(set(factor(a))&set(factor(b)))+1)

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

int main(){
  int H, W;
  string S[50];
  int cnt[50][50] = {};
  int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  
  cin >> H >> W;
  for(int i = 0; i < H; i++) cin >> S[i];
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(S[i][j] == '.'){
        for(int k = 0; k < 8; k++){
          int x = j + dx[k], y = i + dy[k];
          if((0 <= x && x < W) && (0 <= y && y < H) && S[y][x] == '#') cnt[i][j]++;
        }
      }else cnt[i][j] = -1;
    }
  }
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(cnt[i][j] == -1) cout << '#';
      else cout << cnt[i][j];
    }
    cout << endl;
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

int getgcd(int n, int m){
int r;
if (n > m) {
int t = m;
m = n;
n = t;
}
while ((r = m % n) != 0) {
m = n;
n = r;
}
return n;
}

int main(void){
int k,a,b,c;
int gcd=0;

scanf("%d",&k);

for(a=1;a<=k;a++){
    for(b=1;b<=k;b++){
        for(c=1;c<=k;c++){
            gcd=gcd+getgcd(getgcd(a, b), c);
        }
    }
}

printf("%d\n",gcd);
return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	auto k = [&]() {
		puts("Yes");
		return 0;
	};
	if (a == b && a != c) { k(); return 0; }
	if (a == c && a != b) { k(); return 0; }
	if (b == c && a != b) { k(); return 0; }
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int sum =0;
  
  for(int i; i<N; i++){
    int l, r;
  	cin >> l >> r;
    sum += (r-l+1);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define MAX_N 10001
using namespace std;
int seq[MAX_N];
void init() {
    int ans = 1;
    for(int r = 0; r < MAX_N; r++) {
        seq[r] = ans; ans += r + 1;
    }
}

int main(void) {
    init();
    int input;
    while(cin >> input) {
        cout << seq[input] << endl;
    }
    return(0);
}

Measured memory_bytes: 1200