akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string as = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string ab = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

//--------------------------



int main() {

  int n;
  cin >> n;
  int d[n];
  rep(i, n) cin >> d[i];

  int sum = 0;
  for(int i=0; i<n-1; ++i) {
    for(int j=i+1; j<n; ++j) {
      sum += d[i]*d[j];
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    int X = N / 1000;
    if (X * 1000 == N) cout << 0 << endl;
    else cout << 1000 - (N - X * 1000) << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <complex>
#include <queue>
#include <cstring>

using namespace std;

const double EPS = 1e-8;

typedef complex<double> P;
struct L { P p, q; L(P p, P q) : p(p), q(q) {} };

class Node{
public:
	int b, p, q, num; double len;
	Node(int b, int p, int q, int num, double len) : b(b), p(p), q(q), num(num), len(len) {}
	bool operator < (const Node &nd) const {
		return make_pair(num, len) > make_pair(nd.num, nd.len);
	}
};

double dot(P a, P b) { return real(conj(a)*b); }
double cross(P a, P b) { return imag(conj(a)*b); }

P ssCrosspoint(L a, L b){
	double A = cross(a.q-a.p, b.q-b.p);
	double B = cross(a.q-a.p, a.q-b.p);
	return b.p + B/A * (b.q-b.p);
}

int main(){
	int n;
	int bit[10][10];
	int num[1024][10][10];
	double len[1024][10][10];
	while(cin >> n, n){
		memset(num, -1, sizeof(num));
		priority_queue<Node> qu;
		vector<P> vp(n);
		for(int i=0;i<n;i++){
			double x, y; cin >> x >> y;
			vp[i] = P(x, y);
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				int b = (1<<i)|(1<<j);
				for(int k=0;k<n;k++)
					if(abs(abs(vp[i]-vp[k])+abs(vp[k]-vp[j])-abs(vp[i]-vp[j])) < EPS) b |= (1<<k);
				bit[i][j] = bit[j][i] = b;
				qu.push(Node(b, i, j, 0, abs(vp[i]-vp[j])));
				qu.push(Node(b, j, i, 0, abs(vp[i]-vp[j])));
			}
		}
		pair<int, double> res;
		while(!qu.empty()){
			Node nd = qu.top(); qu.pop();
			if(nd.b == (1<<n)-1){
				res = make_pair(nd.num, nd.len); break;
			} 
			if(num[nd.b][nd.p][nd.q]!=-1) continue;
			num[nd.b][nd.p][nd.q] = nd.num;
			len[nd.b][nd.p][nd.q] = nd.len;
			L l = L(vp[nd.p], vp[nd.q]);
			for(int i=0;i<n;i++){
				if(nd.b&(1<<i)) continue;
				for(int j=0;j<n;j++){
					if(i==j) continue;
					if(abs(imag((l.q-l.p)/(vp[i]-vp[j]))) < EPS) continue;
					P p = ssCrosspoint(l, L(vp[i], vp[j]));
					if(dot(l.q-p, l.p-p) < -EPS || dot(vp[i]-p, vp[j]-p) < -EPS) continue;
					if(abs(p-l.q)>abs(p-l.p)||abs(p-vp[j])>abs(p-vp[i])) continue;
					qu.push(Node(nd.b|bit[i][j], j, i, nd.num+1, nd.len+abs(p-l.q)+abs(p-vp[i])));
				}
			}
		}
		printf("%d %.8lf\n", res.first, res.second);
	}
}

Measured memory_bytes: 4504
#include<stdio.h>

int main()
{
  int N, M, i;
  int A[10000];

  scanf("%d %d", &N, &M);

  for(i = 0; i < M; i++)
  {
    scanf("%d", &A[i]);
    N -= A[i];
  }
  if(N >= 0)
    printf("%d", N);
  
  else
    printf("-1");

  return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	
	vector<int> X(N), Y(N), P(N);
	REP(i, N) scanf("%d %d %d", &X[i], &Y[i], &P[i]);
	
	auto compress = [](auto &&v, auto &&cv, auto &z) -> void {
		for (auto &&u : v) cv.emplace_back(u);
		cv.emplace_back(INF);
		cv.emplace_back(-INF);
		cv.emplace_back(0);
		sort(ALL(cv));
		cv.erase(unique(ALL(cv)), cv.end());
		for (auto &&u : v) u = lower_bound(ALL(cv), u) - cv.begin();
		z = lower_bound(ALL(cv), 0) - cv.begin();
	};
	
	vector<int> cx, cy;
	int zx, zy;
	compress(X, cx, zx);
	compress(Y, cy, zy);

	vector<vector<int>> distx(1<<N, vector<int>(cx.size(), INF));
	vector<vector<int>> disty(1<<N, vector<int>(cy.size(), INF));
	vector<int> cntx(1<<N), cnty(1<<N);
	
	auto solve = [N](auto &&v, auto &&z, auto &&cv, auto&& distv, auto &&cntv) -> void {
		REP(s, 1 << N) {
			REP(i, N) if (s >> i & 1) distv[s][v[i]] = 0;
			distv[s][z] = 0;
			
			REP(i, cv.size()) if (i != z && distv[s][i] == 0) ++cntv[s];
			
			REP(i, cv.size() - 1) if (distv[s][i] != INF) chmin(distv[s][i + 1], distv[s][i] + cv[i + 1] - cv[i]);
			for (int i = cv.size() - 1; i > 0; --i) if (distv[s][i] != INF) chmin(distv[s][i - 1], distv[s][i] + cv[i] - cv[i - 1]);
		}
	};
	
	solve(X, zx, cx, distx, cntx);
	solve(Y, zy, cy, disty, cnty);
	
	vector<ll> ans(N + 1, longINF);
	REP(s1, 1 << N) { // 鉄道が通る集落
		int cnt = 0;
		REP(i, N) cnt += s1 >> i & 1;
		for (int s2 = s1;; s2 = (s2 - 1) & s1) { // s1 の内、上下に伸びる鉄道の集合
			int s3 = s2 ^ s1; // 左右
			
			ll cur = 0;
			REP(i, N) cur += (ll)min(distx[s2][X[i]], disty[s3][Y[i]]) * P[i];
			chmin(ans[cnt], cur);
			
			if (s2 == 0) break;
		}
	}
	
	REP(i, N + 1) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 10268
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		String str="";
		StringTokenizer stk;
		int[] go=new int[5];
		String aa="";

		try {
			str=bfr.readLine();
			stk=new StringTokenizer(str," ");

			for(int i=0; i<5; i++) {
				go[i]=Integer.parseInt(stk.nextToken());
			}
			go=Bubble(go);
			for(int i=4; i>0; i--) {
				aa=aa+go[i]+" ";
			}
			aa=aa+go[0];
			System.out.println(aa);

		}catch(IOException e) {

		}
	}

	static int[] Bubble(int[] a) {
		int tmp1,tmp2=0;
		int ookisa=a.length;

		for(int i=0; i<ookisa-1; i++) {
			for(int j=ookisa-1; j>=i+1; j--) {
				if(a[j]<a[j-1]) {
					tmp1=a[j];
					tmp2=a[j-1];
					a[j]=tmp2;
					a[j-1]=tmp1;
				}
			}
		}

		return a;
	}
}


Measured memory_bytes: 24156
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
const int INF = 1e18;

int n; //グラフの頂点数
typedef pair<int,int> P;
const int MAX_N = 1e5; //ここはちゃんと変える！
int d[MAX_N];
struct Edge{
    int to,cost;
    Edge(int to,int cost):to(to),cost(cost){}
    bool operator<(const Edge& a) const{
        return cost >a.cost;
    }
};
using Graph = vector<Edge>;
Graph G[MAX_N];

//s始点のdijkstra
void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d,d+n,INF);
    d[s] = 0;
    que.push(P(0,s));
    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        REP(i,G[v].size()){
            Edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

signed main(){
    int m; cin >> n >> m;
    while(m--){
        int l, r, c; cin >> l >> r >> c; l--; r--;
        G[l].pb({r,c});
    }
    REP(i,n-1)G[i+1].pb({i,0});
    dijkstra(0);
    cout << (d[n-1] != INF ? d[n-1] : -1 ) << endl;
}

Measured memory_bytes: 9340
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut spi: Vec<(String, i32, usize)> = (0..n).map(|i| (input(), input(), i + 1)).collect();

    spi.sort_by_key(|p| (p.0.clone(), -p.1));
    for (_, _, i) in spi {
        println!("{}", i);
    }
}


Measured memory_bytes: 4352
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
x,n=gsmi
pp=gsmi

0.upto 101 do |i|
  n1=x-i
  n2=x+i
  unless pp.include? n1
    putsend n1
  end
  unless pp.include? n2
    putsend n2
  end
end

Measured memory_bytes: 14380
fun main(args:Array<String>){
  val (n,m,x) = readLine()!!.split(" ").map(String::toInt)
  val ns = (0..n).map { 0 }.toMutableList()
  val cs = readLine()!!.split(" ").map(String::toInt).map { ns[it] = 1 }
  listOf(ns.slice(x..ns.size-1).sum(), ns.slice(0..x).sum()).min().let(::println)
}

Measured memory_bytes: 37772
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cstdint>
					/*多倍長整数/cpp_intで宣言
					#include <boost/multiprecision/cpp_int.hpp>

					using namespace boost::multiprecision;
					*/

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int w, h, n;
	scanf("%d%d%d", &w, &h, &n);
	int x1 = 0, x2 = w, y1 = 0, y2 = h;
	int x, y, a;
	rep(i, n) {
		scanf("%d%d%d", &x, &y, &a);
		if (a == 1) {
			x1 = max(x1, x);
		}
		else if (a == 2) {
			x2 = min(x2, x);
		}
		else if (a == 3){
			y1 = max(y1, y);
		}
		else {
			y2 = min(y2, y);
		}
	}
	printf("%d\n", max(((x2 - x1) > 0 && (y2 - y1) > 0) ? (x2 - x1) * (y2 - y1) : 0, 0));

	Please AC;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n,k,ans;
string S;
cin >> S;
n = S.size();
	vector<int> num,i(n);
	for(k=0;k<n;k++){
		num.push_back(S[k]-'0');
	}
	for(k=1;k<n;k++){
		if(num[k-1] != num[k]){
			i[k] = max(k,n-k);
		}else{
			i[k] = n;
		}
	}
	ans = n;
	for(k=1;k<n;k++){
		ans = min(ans,i[k]);
	}
	cout << ans << endl;
}
	

Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}
ll dp[1010][5000];

int main()
{
    ll N, M;
    cin >> N >> M;

    vector<long long> a(M), b(M), c(M, 0); // c はビットで表す
    for (int i = 0; i < M; ++i)
    {
        cin >> a[i] >> b[i];
        for (int j = 0; j < b[i]; ++j)
        {
            int t;
            cin >> t;
            --t;
            c[i] += (1 << t);
        }
    }
    for (int i = 0; i < 1010; ++i)
        for (int j = 0; j < 5000; ++j)
            dp[i][j] = INF;

    dp[0][0] = 0;

    for (int i = 0; i < M; i++)
    {
        for (int j = 0; j < (1 << N); j++)
        {
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);

            int nj = j | c[i];
            dp[i + 1][nj] = min(dp[i][j] + a[i], dp[i + 1][nj]);
        }
    }

    if (dp[M][(1 << N) - 1] < INF)
    {
        cout << dp[M][(1 << N) - 1] << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 40316
#include <stdio.h>

int A[10000000];
int n;

int binarySearch(int key)
{
	int left = 0;
	int right = n;
	int mid;
	
	while (left < right){
		mid = (left + right) / 2;
		if(key == A[mid]) return 1;
		if(key > A[mid]) left = mid + 1;
		else if(key < A[mid]) right = mid;
	}
	return 0;
}


int main()
{
	int i, q, k;
	int c = 0;
	
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &A[i]);
	}
	
	scanf("%d", &q);
	for(i=0; i<q; i++){
		scanf("%d", &k);
		if(binarySearch(k)) c++;
	}
	printf("%d\n", c);
	
	return 0;
}



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

int main()
{
	int n;
	cin >> n;
	vector<bool> same(n);
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		if (i + 1 == p[i]) same[i] = true;
	}

	int count = 0;
	for (int i = 0; i < n - 1; i++) {
		if (same[i]) {
			swap(p[i], p[i + 1]);
			same[i] = false;
			same[i + 1] = false;
			count++;
		}
	}
	if (same[n - 1]) {
		swap(p[n - 2], p[n - 1]);
		count++;
	}

	cout << count << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    int n;
    string s;
    cin >> n >> s;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        if(s[i] == 'R') a[i] = 0;
        if(s[i] == 'G') a[i] = 1;
        if(s[i] == 'B') a[i] = 2;
    }
    vector<ll> cnt(3);
    for(int i = 0; i< n; i++){
        cnt[a[i]]++;
    }
    ll ans= 1;
    for(int i = 0; i< 3; i++) ans *= cnt[i];
    for(int j = 0; j < n; j++){
        for(int i = 0; i < j; i++){
            int k = j + (j-i);
            if(k < n){
                if (a[i] == a[j]) continue;
                if (a[i] == a[k]) continue;
                if (a[k] == a[j]) continue;
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3164
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	ar := make([]string, h)
	for i := range ar {
		fmt.Scan(&ar[i])
	}
	vh := []int{-1, -1, -1, 0, 0, 1, 1, 1}
	vw := []int{-1, 0, 1, -1, 1, -1, 0, 1}
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if ar[i][j] == '#' {
				fmt.Print("#")
				continue
			}
			sum := 0
			for k := 0; k < 8; k++ {
				hh := i + vh[k]
				ww := j + vw[k]
				if 0 <= hh && hh < h && 0 <= ww && ww < w {
					if ar[hh][ww] == '#' {
						sum++
					}
				}
			}
			fmt.Print(sum)
		}
		fmt.Println()
	}
}


Measured memory_bytes: 512
from collections import Counter

def checkStraint(hand):
    hand=sorted(hand)
    if set(hand)==set([10,11,12,13,1]):
        return True
    for i in range(5):
        if hand[0]+i==hand[i]:
            continue
        else:
            return False
    return True

while True:
    try:
        hand=[int(i) for i in input().split(",")]
        hand=sorted(hand)
        c=Counter(hand)
        c=sorted(dict(c).items(),key=lambda w:w[1],reverse=True)
        if c[0][1]==4:
            print("four card")
            continue
        elif c[0][1]==3 and c[1][1]==2:
            print("full house")
            continue

        elif checkStraint(hand):
            print("straight")
            continue
        elif c[0][1]==3:
            print("three card")
            continue
        elif c[0][1]==2 and c[1][1]==2:
            print("two pair")
            continue
        elif c[0][1]==2:
            print("one pair")
            continue
        else:
            print("null")

    except EOFError:
        break



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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<pair<int, int>, int>> city(M);
  vector<string> ans(M);
  for (int i = 0; i < M; ++i) {
    int p, y;
    scanf("%d%d", &p, &y);
    city[i] = make_pair(make_pair(p, y), i);
  }
  sort(city.begin(), city.end());
  int cnt = 1;
  for (int i = 0; i < M; ++i) {
    int l = city[i].first.first;
    int r = city[i].first.second;
    if (i > 0 && city[i - 1].first.first == l) cnt++;
    else cnt = 1;
    char x[7], y[7];
    sprintf(x, "%06d", l);
    sprintf(y, "%06d", cnt);
    ans[city[i].second] = (string)x + (string)y;
  }
  for (int i = 0; i < M; ++i) cout << ans[i] << endl;
}

Measured memory_bytes: 8192
#include <stdio.h>

#define MAX(a, b) ((a) > (b) ? (a) : (b))

int n, m;
int A[100000];

int main(){
  int i;
  scanf("%d%d", &n, &m);
  for(i=0;i<m;i++){
    int a, b;
    scanf("%d%d", &a, &b);
    A[a-1] = MAX(A[a-1], n-b+1);
  }
  int min = 0;
  int count = 0;
 
  for(i=0;i<n-1;i++){
    min = MAX(min, A[i]);
    if(i == n-min-1){
      min = 0;
      count++;
    }
  }

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


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

#define max_n 100005
#define max_h 10002
int arr[max_n],n;
long dp[max_n];

long solve(int idx)
{
	if(idx==n-1)
	{
		return 0;
	}
	if(dp[idx]!=-1)
	{
		return dp[idx];
	}
	long best=LONG_MAX;
	for(int i=idx+1;i<=idx+2&&i<n;i++)
	{
		best=min(best,abs(arr[i]-arr[idx])+solve(i));
	}
	return dp[idx]=best;
}

signed main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n;
	assert(2<=n<=max_n);
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	cout<<solve(0)<<endl;
	return 0;
}


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

string s, t;
long long a, n, c, c1, c2;
int main() {
	int i;
	cin >> s >> a;
	n = s.size();
	t = s;
	sort(t.begin(), t.end());
	if(t[0] == t[n-1]) {cout << n * a / 2; return 0;}
	for(i=1; i<n; i++)
		if(s[i] == s[i-1])
			c++, i++;
	for(i=c1=0; i<n && s[i] == s[0]; i++, c1++);
	for(i=n-1, c2=0; i>=0 && s[i] == s[n-1]; i--, c2++);
	cout << (s[0] != s[n-1] ? c*a : c*a - (c1/2 + c2/2 - (c1+c2)/2) * (a-1));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
  int a = 0;
  cin >> a;
  vector<int> b(a);
  for(int i = 0;i <= a - 1;i++){
    cin >> b[i];
  }
  int k = 0;
  for(int i = 0; i<= a - 1;i++){
    if(b[i] % 2 == 0){
      if(b[i] % 3 != 0 && b[i] % 5 != 0){
        k = 1;
        i = a;
      }
    }
  }
  if(k == 0){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
  return 0;
}

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

import numpy as np

contest = np.zeros((2, n), dtype=int)

for i in range(m):
  a = list(input().split())
  t_num = int(a[0]) - 1
  if a[1] == "AC":
    if contest[0, t_num] == 0:
      contest[0, t_num] = 1
  else:
    if contest[0, t_num] == 0:
      contest[1, t_num] += 1

contest[1,:] = contest[0,:]*contest[1,:]

ans = np.sum(contest, axis = 1)
print(ans[0], ans[1])

Measured memory_bytes: 20636
#!/usr/bin/env python3
import sys
from heapq import heappush, heappop, heapify
from collections import deque
from collections import namedtuple
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]


INF = float("inf")
MOD = 10**9 + 7


def main():
    T = INT()
    for t in range(T):
        solve()
    return

def solve():
    # 解説PDFの指針
    N = INT()
    left_camel = []
    right_camel = []
    camel = namedtuple("camel", "value, kth")
    ans = 0
    for k, l, r in ZIP(N):
        if l >= r:
            left_camel.append(camel(l-r, k))
            ans += r
        else:
            right_camel.append(camel(r-l, N-k))
            ans += l
    left_camel.sort(key=lambda x: x.kth)
    right_camel.sort(key=lambda x: x.kth)
    left_camel = deque(left_camel)
    right_camel = deque(right_camel)
    for camels in [left_camel, right_camel]:
        S = []
        while camels and camels[0].kth == 0:
            camels.popleft()
        for j in range(1, N+1):
            while camels and camels[0].kth == j:
                heappush(S, camels.popleft())
            while len(S) > j:
                heappop(S)
        while S:
            ans += heappop(S).value
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 71040
function Main(input){
  return input.split("\n")[1].split(" ").map(a=>~~a-1).reduce((a,b)=>a+b);
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
7
994 518 941 851 647 2 581
`);

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    V<int> A(N);
    rep(i, N) cin >> A[i];

    int ans = TEN(9) + 10;

    rep(i, N) {
        int mi = A[i];
        VV<int> vec;
        {
            V<int> cur;
            rep(j, N) {
                if (A[j] < mi) {
                    vec.pb(cur);
                    cur.clear();
                } else {
                    cur.pb(A[j]);
                }
            }
            vec.pb(cur);
        }
        V<int> cand;
        for (auto& v : vec) {
            sort(ALL(v));
            int sz = v.size();
            rep(j, sz - K + 1) { cand.pb(v[j]); }
        }
        sort(ALL(cand));
        if (cand.size() >= Q) {
            chmin(ans, cand[Q - 1] - cand[0]);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
n, k = (map(int, input().split()))
h = list(map(int, input().split()))

dp = [0, abs(h[0] - h[1])]

for i in range(2, n):
    cost = []
    jump_range = min(i, k) + 1
    for n_jump in range(1, jump_range):
        jump_cost = dp[i - n_jump] + abs(h[i] - h[i - n_jump])
        cost.append(jump_cost)
    dp.append(min(cost))
    cost.clear()

print(dp[-1])


Measured memory_bytes: 85496
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] pos = new long[n];
		long[] sum = new long[n];
		for(int i = 0; i < n; i++) {
			pos[i] = sc.nextLong();
		}
		sum[0] = 0;
		for(int i = 1; i < n; i++) {
			sum[i] = sum[i - 1] + (pos[i] - pos[i - 1]);
		}
		long ans = sum[n - 1] * 2;
		for(int i = 0; i < n - k + 1; i++) {
			long tmp = 0;
			if(Math.abs(pos[i]) < Math.abs(pos[i + k - 1])) {
				tmp = sum[i + k - 1] - sum[i] + Math.abs(pos[i]);
			} else {
				tmp = sum[i + k - 1] - sum[i] + Math.abs(pos[i + k - 1]);
			}
			ans = Math.min(ans, tmp);
		}
		System.out.println(ans);

	}

}


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


#define rep(i,n) for(int i = 0;i<n;i++)
#define getint(n) scanf("%d",&n)

int main(int argc, char const *argv[])
 {
 	int  n = 0;
 	char c = 0;
 	char name[16]="";
 	long long names[5] = {0,0,0,0,0};

 	scanf("%d",&n);

 	rep(i, n){
 		scanf("%s",name);
 		switch(*name){
 			case 'M':names[0]++;break;
 			case 'A':names[1]++;break;
 			case 'R':names[2]++;break;
 			case 'C':names[3]++;break;
 			case 'H':names[4]++;break;
 		}
 	}
long long sum = 0;
 	for(int i = 0;i<=2;i++){
 		for(int j = i+1; j<=3;j++ ){
 			for(int k=j+1;k<=4;k++){
 				sum+=names[i]*names[j]*names[k];
 			}
 		}
 	}
 	printf("%lld\n",sum);


 	return 0;
 }

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  
  vector<int> A(M);
  vector<int> cost(N+1);
  for(int i = 0; i < M; i++ ){
    cin >> A.at(i);
    cost.at(A.at(i)) = 1;
  }
  
  for( int i = 0; i < N; i++ ){
    cost.at(i+1) += cost.at(i);
  }
  
  cout << min(cost.at(X-1), cost.at(N)-cost.at(X)) << endl;
  
}

Measured memory_bytes: 256
ban=[]
result=[False]*9
for i in range(3):
    a,b,c=map(int,input().split())
    ban.append(a)
    ban.append(b)
    ban.append(c)
n=int(input())
sen=[]
for i in range(n):
    temp=int(input())
    for i in range(9):
        if(ban[i]==temp):
            result[i]=True

ans=False
check=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
for c in check:
    if(result[c[0]] and result[c[1]] and result[c[2]]):
       ans=True

if(ans):
    print("Yes")
else:
    print("No")

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

#define N 10001

int f(int x, int y, int z) {
	return x*x + y*y + z*z + x*y + y*z + z*x;
}

int main() {

	IOS

	int n;
	cin >> n;

	int a[N] = {0};

	for (int i = 1; i <= 100; i++) {
		for (int j = 1; j <= 100; j++) {
			for (int k = 1; k <= 100; k++) {
				int val = f(i, j, k);
				if (val < N)
					a[val]++;
			}
		}
	}

	for (int i = 1; i <= n; i++)
		cout << a[i] << endl;

	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;
 
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
 
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
 

ll C(ll N) {
	return N * (N - 1) / 2;
}
 
const double PI = 3.14159265358979323846;
 
int main() {
	ll H, W; cin >> H >> W;
	char s[H + 2][W + 2];
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> s[i][j];
		}
	}
 
	int dx[8] = { 0,0,1,1,1,-1,-1,-1 };
	int dy[8] = { -1,1,1,0,-1,1,0,-1 };
 
	int cnt[H + 2][W + 2] = {};
	for(int  i= 0; i < H+2;i++){
		for (int j = 0; j < W + 2; j++) cnt[i][j] = 0;
	}
 
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (s[i][j] == '#')continue;
			for (int k = 0; k < 8; k++) {
				if (s[i + dx[k]][j + dy[k]] == '#') {
					cnt[i][j]++;
				}
			}
		}
	}
 
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
				if (s[i][j] == '#') {
					cout << '#';
				}
				else cout << cnt[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.PriorityQueue;
import java.util.Collections;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DPowerfulDiscountTickets solver = new DPowerfulDiscountTickets();
        solver.solve(1, in, out);
        out.close();
    }

    static class DPowerfulDiscountTickets {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int m = in.scanInt();
            PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
            for (int i = 0; i < n; i++) pq.add(in.scanInt());
            while (pq.size() > 0 && m-- > 0) {
                int temp = pq.poll();
                temp /= 2;
                if (temp > 0) pq.add(temp);
            }
            long ans = 0;
            while (pq.size() > 0) ans += pq.poll();
            out.println(ans);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



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

signed main(void)
{
	int n, T, ans;
	cin >> n >> T;
	ans = (int)1e9;
	rep(i, n)
	{
		int c, t;
		cin >> c >> t;
		if (t <= T)
			ans = min(ans, c);
	}
	if (ans == (int)1e9)
		cout << "TLE" << endl;
	else
		cout << ans << endl;
	return 0;
}


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

int main(int argc, char const *argv[]) {
  int n, m, k=0;
  unsigned long int val=0;
  cin >> n >> m;

  vector<pair<unsigned long int, int>> store(n);
  for (int i=0; i<n; i++) {
    cin >> store[i].first >> store[i].second;
  }

  sort(store.begin(), store.end());

  for (int i=0;; i++) {
    if(store[i].second > m){
      val += store[i].first * m;
      cout << val << endl;
      return 0;
    }
    val+= store[i].first * store[i].second;
    m -= store[i].second;
  }

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, x; cin >> n >> x;
    int ans = 1; int cur = 0;
    for (int i = 0; i < n; i++) {
        int c; cin >> c; cur += c;
        if (cur <= x) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n,m;
  cin>>n>>m;
  int ab=0,load[n+1];
  REP(i,n+1){
    load[i]=0;
  }
  REP(i,m*2){
    ab=0;
    cin>>ab;
    load[ab-1]++;
  }
  REP(i,n){
    cout<<load[i]<<endl;
  }
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ACはうれCすぎてうれD */
 
int main(void){ 
    double n;
    cin >> n;
 
    double pre_x = n / 1.08;

    int kari_1 = floor(pre_x) + 1;
    int kari_2 = floor(pre_x);
 
    int sik_1 = kari_1 * 1.08;
    int sik_2 = kari_2 * 1.08;
 
    if(int(n) == sik_1) cout << kari_1;
    else if(int(n) == sik_2) cout << kari_2;
    else cout << ":(";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    if (13 <= A ){
        cout << B << endl;
    }else if(6 <= A && A < 13){
        cout << B / 2 << endl; 
    }else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<pii> v(n);
  rep(i, n){
    int a,b;
    cin >> a >> b;
    v[i] = make_pair(a, b);
  }
  sort(all(v));
  priority_queue<int> que;
  int cnt = 0, ans = 0;
  for(int i = 1; i <= m; i++){
    while(v[cnt].first == i){
      que.push(v[cnt].second);
      cnt++;
    }
    if(!que.empty()){
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4620
#include <iostream>

using namespace std;
int main(){
    int a;
    int b;
    int c;
    cin >> a >> b >> c;
    if(a > b ){
        int a_1 = a;
        int b_1 = b;
        a = b_1;
        b = a_1;
    }
    if(b > c){
        int b_2 = b;
        int c_2 = c;
        b = c_2;
        c = b_2;
    }
    if(a > b){
        int a_3 = a;
        int b_3 = b;
        a = b_3;
        b = a_3;
    }
    cout << a << " " <<b<<" "<< c << endl;
}


Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
}

ll getdigit(ll n){
	string s=to_string(n);
	return s.size();
}
	
int main(){
	init();
	ll n;
	cin>>n;
	vector<ll>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	
	//start>0
	ll ans1=0;
	ll sum1=0;
	for(int i=0;i<n;i++){
		sum1+=a[i];
		if(i%2==0){
			if(sum1<=0){
				ans1+=abs(sum1)+1;
				sum1=1;
			}
		}
		if(i%2==1){
			if(sum1>=0){
				ans1+=sum1+1;
				sum1=-1;
			}
		}
	}
	
	//start<0
	ll ans2=0;
	ll sum2=0;
	for(int i=0;i<n;i++){
		sum2+=a[i];
		if(i%2==1){
			if(sum2<=0){
				ans2+=abs(sum2)+1;
				sum2=1;
			}
		}
		if(i%2==0){
			if(sum2>=0){
				ans2+=sum2+1;
				sum2=-1;
			}
		}
	}
	cout<<min(ans1,ans2)<<endl;
	
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(ll i=a;i<=b;i++)
#define N 1001000
#define mo 998244353
#define ll long long
using namespace std;
ll n,m,ans=0,jc[N],ny[N];
ll mi(ll a,ll b)
{
	ll c=1;
	for(;b;b/=2,a=(a*a)%mo) if(b%2==1) c=(c*a)%mo;
	return c;
}
ll C(ll m,ll n){return jc[m]*ny[n]%mo*ny[m-n]%mo;}
int main()
{
	scanf("%lld%lld",&n,&m);
	if(n>m) swap(n,m);
	jc[0]=ny[0]=1;
	fo(i,1,n+m) jc[i]=jc[i-1]*i%mo,ny[i]=mi(jc[i],mo-2);
	fo(i,1,n) 
	ans=(ans+C(i+i,i)*C(n-i+m-i,n-i))%mo;
	ans=ans*mi(2*C(n+m,n)%mo,mo-2)%mo;
	ans=(ans+m)%mo;
	printf("%lld\n",ans);
}

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

//bool cmp(pair<int, int>a, pair<int, int>b){if(a.first==b.first) return a.second > b.second;  else return a.first<b.first;   }
//bool valid(int i, int j){ return 0 <= i&&i < n && 0 <= j&&j < m; }
#define ll long long
#define MEMSET_INF 127
#define MEMSET_HALF_INF 63
#define Sc(a) scanf ("%I64d", &a)
#define sc(a) scanf ("%d", &a)
#define fi first
#define se second
#define siz 10000005

const ll INF = (1ll<<62);
const ll mod = 1e8;
typedef pair<int,int> pii;
typedef pair<int,pii > pip;
typedef pair< pair<int ,int> , pair<int ,int > > ppp;
vector<tuple<int,int,int> >tup;




//variables



int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
      //freopen("katryoshka.in","r",stdin);
     //freopen("output.txt","w",stdout);
    //memset(dist, MEMSET_INF, sizeof dist);
   //memset(dp, -1, sizeof dp);


    int n; cin>>n;
    int dp[100005],arr[100005]={0};

    for(int i=0;i<n;i++)
        cin>>arr[i];

    dp[1]=abs(arr[0]-arr[1]);
    dp[0]=0;
    for(int i=2;i<n;i++){
        dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
    }

    cout<<dp[n-1];

    return 0;
}


Measured memory_bytes: 1024
n, m = map(int, input().split())
s = [list(map(int,input().split())) for _ in range(n)]
ans = 0
ss = sorted(s)

for i in range(n):
    if ss[i][1] - m < 0:
        v = ss[i][0]*ss[i][1]
        ans += v
        m -= ss[i][1]
        if m == 0:
            break
        
    elif ss[i][1] - m >= 0:
        v = ss[i][0]*m
        ans += v
        m -= m
        if m == 0:
            break

print(ans)    

Measured memory_bytes: 28652
while True:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    for i in range(h):
        if i % 2 == 1:
            if w % 2 == 0:
                print('.#'*(w//2))
            elif w % 2 == 1:
                print('{}.'.format(".#"*(w//2)))
        if i % 2 == 0:
            if w % 2 == 0:
                print('#.'*(w//2))
            elif w % 2 == 1:
                print('{}#'.format('#.'*(w//2)))
    print()


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    vector<bool> G(N, true);
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        A--, B--;
        if (H[A] < H[B]) {
            G[A] = false;
        } else if (H[A] > H[B]) {
            G[B] = false;
        } else {
            G[A] = G[B] = false;
        }
    }

    int ans = 0;
    rep(i, N) if (G[i]) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 3788
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll N, K, S;
    cin >> N >> K >> S;
    vector<ll> A(N);
    if(S == 1000000000) {
        rep(i, K) A[i] = 1000000000;
        rep(i, K, N) A[i] = 1;
    }
    else {
        rep(i, K) A[i] = S;
        ll fi = 1000000000 + 1 - S;
        ll se = S + 1;
        rep(i, K, N) {
            if(K % 2 == i % 2) A[i] = fi;
            else A[i] = se;
        }
    }
    voutput(A);
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

   int n;
   cin >> n;
   vector <ll> hgt(n), bty(n), dp(n);
   for (auto &i : hgt)
      cin >> i;
   for (auto &i : bty)
      cin >> i;

   map <int, ll> m;
   m[hgt[0]] = bty[0];
   dp[0] = bty[0];

   ll ans = dp[0];
   for (int i = 1; i < n; i++) {
      auto it = m.upper_bound(hgt[i]);
      dp[i] = bty[i];
      if (it != m.begin()) {
         it--;
         dp[i] += it -> ss;
      }

      it = m.upper_bound(hgt[i]);

      while (it != m.end() && it -> ss <= dp[i]) {
         auto at = it;
         at++;
         m.erase(it);
         it = at;
      }

      m[hgt[i]] = dp[i];
      ans = max(dp[i], ans);
   }

   cout << ans << '\n';

   return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" ";
#define LOGE if(DEBUG)cout<<endl;

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 string YES = "Yes";
const string NO = "No";

void func(std::string S, std::string T){

    REP(i,0,S.size()*2){
        if(S==T){
            cout<<YES<<endl;
            return;
        }
        S = S.substr(S.size()-1,1) + S.substr(0,S.size()-1);
    }
    cout<<NO<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    func(S, T);
    return 0;
}


Measured memory_bytes: 256