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

int main(){

    string s;cin >> s;

    bool flag,flag1,flag2;
    flag=1;
    for(int i=0;i<s.size();++i){
        if(i%2==0){
            if(s.at(i)=='L'){
                flag=0;
                break;
            }
            else continue;
        }else{
            if(s.at(i)=='R'){
                flag=0;
                break;
            }else continue;
        }
    }

    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}


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

int solve(vector<int> p, vector<int> v){
    int res = 0;
    
    while(p != v){
        next_permutation(v.begin(), v.end());
        res++;
    }
    return res;
}

int main(void){
    int n;
    cin >> n;
    
    vector<int> p(n), q(n), v(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 0; i < n; i++) cin >> q[i];
    
    for (int i = 0; i < n; i++) v[i] = i+1;
    
    int ans = abs(solve(p, v) - solve(q, v));
    cout << ans << endl;
}


Measured memory_bytes: 256
//ABC161 C

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

int N,M;
int A[1000];
long long ans = 0;

int main() {
  cin >> N >> M;
  
  for(int i=0;i<N;i++){
    scanf("%d",&A[i]);
    ans += A[i];
  }
  sort(A,A+N);
  reverse(A,A+N);
  if(A[M-1] >= ((double)ans/(4*M))){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  
  //printf("%d %d %d\n",X,Y,Z);
}


Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 04.12.2019 18:46:09       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int foo;
  cin >> foo;
  const long long SHIFT = (long long) 1e17;
  const int BITS = 60;
  long long ans = 0;
  while (foo--) {
    long long x, y;
    cin >> x >> y;
    x += SHIFT;
    vector<vector<long long>> dp(BITS + 1, vector<long long>(2, 0));
    vector<vector<long long>> dc(BITS + 1, vector<long long>(2, 0));
    dc[0][0] = 1;
    for (int i = 0; i < BITS; i++) {
      for (int carry = 0; carry < 2; carry++) {
        int bound = (y >> i) & 1;
        for (int here = 0; here <= bound; here++) {
          long long val = here + ((x >> i) & 1) + carry;
          dc[i + 1][val >> 1] += dc[i][carry];
          dp[i + 1][val >> 1] ^= dp[i][carry] + ((val & 1) << i) * (dc[i][carry] & 1);
        }
      }
    }
    ans ^= dp[BITS][0];
  }
  cout << ans - SHIFT << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int W,H,x,y,r,min;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(x<W && y<H){
    if(x<=y){
      min = x;
    }else{
      min = y;
    }
    if(r<=min){
      printf("Yes\n");
    }else{
      printf("No\n");
    }
  }else{
    printf("No\n");
  }
}

Measured memory_bytes: 1012
n,m,*t=map(int,open(0).read().split())
a=sorted(t[:n])[::-1]
m=0
for c,b in sorted(zip(t[n+1::2],t[n::2]))[::-1]:
 while a and b and c>a[-1]:m+=c;b-=1;a.pop()
print(m+sum(a))

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


int main(){
  int H, W;
  cin >> H >> W;
  vector<string> s(H,"");

  for (int i=0; i<H; i++){
    cin >> s[i];
    s[i].insert(0,".");
    s[i].append(".");
  }

  string tmp;
  for(int i=0; i<W+2; i++){
    tmp.append(".");
  }
  s.insert(s.begin(), tmp);
  s.insert(s.end(), tmp);

  int sum = 0;

  for(int i=1; i<H+1; i++){
    for (int j=1; j<W+1; j++){

      for (int k=-1; k<2; k++){
        for (int l=-1; l<2; l++){
          if(s[i+k][j+l] == '#'){
            sum += 1;
          }
        }
      }

      if(s[i][j] == '#'){
        s[i][j] = '#';
      }else{
        s[i][j] = '0' + sum;
      }
      sum =0;
    }
  }

  for(int i=1; i<H+1; i++){
    s[i].erase(W+1,1);
    s[i].erase(0,1);
    cout << s[i]<< endl;
  }

  return 0;
}



Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N;
    scan(N);
    auto a = readln.split.to!(int[]);
    a[] -= 1;

    auto cnt = new long[](N);
    foreach (ai ; a) {
        cnt[ai]++;
    }

    long tot;
    foreach (i ; 0 .. N) {
        tot += cnt[i] * (cnt[i] - 1) / 2;
    }

    foreach (k ; 0 .. N) {
        auto nm = a[k];
        long ans;
        if (cnt[nm] < 2) {
            ans = tot;
        }
        else {
            ans = tot - (cnt[nm] * (cnt[nm] - 1) / 2);
            ans += (cnt[nm] - 1) * (cnt[nm] - 2) / 2;
        }
        writeln(ans);
    }
}




void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


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

int main () {
  int a, b;
  cin >> a >> b;
  
  if (a <= b) {
    for (int i = 0; i < b; i++) cout << a;
  } else {
    for (int i = 0; i < a; i++) cout << b;
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    s = input().rstrip()

    if s == s[::-1]:
        print(0)
    else:
        s_len = len(s)//2
        a = s[:s_len]
        b = s[::-1][:s_len]
        ans = 0
        for x, y in zip(a, b):
            if x != y:
                ans += 1

        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast", "unroll-loops")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main() {
	string s; cin >> s;
	int ptr = s.length();
	while (ptr > 0) {
		if (ptr >= 7 && s.substr(ptr - 7, 7) == "dreamer")
			ptr -= 7;
		else if (ptr >= 6 && s.substr(ptr - 6, 6) == "eraser")
			ptr -= 6;
		else if (ptr >= 5 && s.substr(ptr - 5, 5) == "erase")
			ptr -= 5;
		else if (ptr >= 5 && s.substr(ptr - 5, 5) == "dream")
			ptr -= 5;
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

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

int main(){
    int x, y;
    cin >> x >> y;
    set<int> a = {4,6,9,11};

    if(x == 2 || y == 2){
        if(x == y) puts("Yes");
        else puts("No");
    }
    else if(a.count(x) || a.count(y)){
        if(a.count(x) == a.count(y)) puts("Yes");
        else puts("No");
    }
    else puts("Yes");
}

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

vector<vector<ll>> v(100010),rev(100010);
ll d[100010];

void depth(ll p,ll u,ll dist){
    d[p] = dist;
    for(auto i:v[p]){
        if(i != u){
            depth(i,p,dist+1);
        }
    }
}

ll n,k;
ll ans = 0;

void dfs(ll p,ll u,ll dist){
    d[p] = dist;
    if(dist == 1) return;
    for(auto i:v[p]){
        if(i != u){
            dfs(i,p,dist-1);
        }
    }
}

void merge(ll p,ll u,ll dist){
    if(dist == 1){
        dfs(p,-1,k);
        ans++;
        return;
    }
    for(auto i:rev[p]){
        if(i != u){
            merge(i,p,dist-1);
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    cin>>n>>k;
    ll a[n];
    cin>>a[0];
    a[0]--;
    if(a[0]!=0){
        ans++;
        a[0] = 0;
    }
    for(ll i=1;i<n;i++){
        cin>>a[i];
        a[i]--;
        v[a[i]].push_back(i);
        rev[i].push_back(a[i]);
    }
    depth(0,-1,0);
    pair<ll,ll> p[n];
    for(ll i=0;i<n;i++){
        p[i] = make_pair(d[i],i);
    }
    sort(p,p+n,greater<pair<ll,ll>>());
    for(ll i=0;i<n;i++){
        ll j = p[i].second;
        if(d[j]>k){
            merge(j,-1,k);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 23680
import heapq
list1 = input().split(' ')
list2 = input().split(' ')
list2 =  [int(s) for s in list2]

special = int(list1[1])
enemy = int(list1[0])

list = sorted(list2, reverse=True)
a = heapq.nsmallest(enemy-special, list)

if special >= enemy:
  print(0)
else:
  NN = 0
  for N in a:
    NN += N
  print(NN)
  

Measured memory_bytes: 29508
def chmin(a,b):
  if(a <= b):
    return a
  else:
    return b

def chmax(a,b):
  if(a >= b):
    return a
  else:
    return b


n = int(input())
h = list(map(int,input().split()))
INF = sum(h)+100

dp = [INF for i in range(n)]

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

for i in range(n-2):
  dp[i+2] = chmin(dp[i] + abs(h[i]-h[i+2]),dp[i+1] + abs(h[i+1] - h[i+2]))

print(dp[n-1])

Measured memory_bytes: 13908
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	double a, b, x; cin >> a >> b >> x;
	double s = x / a;
	double rad = 0;
	if (s >= (a * b) / 2) {
		double h = (2 * a * b - 2 * s) / a;
		rad = atan2(h, a);
	} else {
		double w = (2 * s) / b;
		rad = atan2(b, w);
	}
	double deg = (rad / (2 * PI)) * 360;
	printf("%.10f\n", deg);
	return;
}

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

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <math.h>

#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
	double x1 = 0;
	double y1 = 0;
	double x2 = 0;
	double y2 = 0;

#if INPUT_FROM_FILE
	ifs >> x1 >> y1 >> x2 >> y2;
#else
	std::cin >> x1 >> y1 >> x2 >> y2;
#endif
	std::cout << std::fixed << std::setprecision(5) << sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)) << std::endl; 
	return 0;
}

Measured memory_bytes: 3252
#include <iostream>
#include <vector>
#include <functional>


using lli=long long;

template<typename T>
class Segtree{
  int nbin;
  T param_def;
  std::vector<T> seg_vec;
  std::function<T(T, T)> seg_func;
  T segtree_query_partial(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return param_def;
    if(a <= l && r <= b) return seg_vec[k];
    const T v_l = segtree_query_partial(a, b, k*2+1, l, (l+r)/2);
    const T v_r = segtree_query_partial(a, b, k*2+2, (l+r)/2, r);
    return seg_func(v_l, v_r);
  }
  auto max_bit(int32_t n){
    n = n & 0xFFFF0000 ? n & 0xFFFF0000 : n;
    n = n & 0xFF00FF00 ? n & 0xFF00FF00 : n;
    n = n & 0xF0F0F0F0 ? n & 0xF0F0F0F0 : n;
    n = n & 0xCCCCCCCC ? n & 0xCCCCCCCC : n;
    n = n & 0xAAAAAAAA ? n & 0xAAAAAAAA : n;
    return n;
  }
  public:
  Segtree(const int N, const std::function<T(T, T)>& _seg_func, const T _param_def) :
    seg_func(_seg_func), param_def(_param_def) {
      nbin = max_bit(N-1)*2;
      seg_vec.resize(nbin*2-1, param_def);
      auto insert_top = seg_vec.begin();
      insert_top += nbin-1;
      for(int i = nbin-2; i >= 0; i--){
        seg_vec[i] = seg_func(seg_vec[i*2+1], seg_vec[i*2+2]);
      }
    }
  Segtree(const std::vector<T>& data, const std::function<T(T, T)>& _seg_func, const T _param_def) :
    seg_func(_seg_func), param_def(_param_def) {
      nbin = max_bit(data.size()-1)*2;
      seg_vec.resize(nbin*2-1, param_def);
      auto insert_top = seg_vec.begin();
      insert_top += nbin-1;
      std::copy(data.cbegin(), data.cend(), insert_top);
      for(int i = nbin-2; i >= 0; i--){
        seg_vec[i] = seg_func(seg_vec[i*2+1], seg_vec[i*2+2]);
      }
    }
  T get(int i){
    return seg_vec[nbin-1+i];
  }
  void update(int i, int x){
    i += nbin-1;
    seg_vec[i] = x;
    while(i > 0){
      i = (i-1)/2;
      seg_vec[i] = seg_func(seg_vec[i*2+1], seg_vec[i*2+2]);
    }
  }
  T query(int a, int b){
    return segtree_query_partial(a, b, 0, 0, nbin);
  }
};

lli lower_med(const std::vector<lli>& a_arr, lli t){
  Segtree<lli> seg(200005, [](const lli a, const lli b){return a+b;}, 0);
  lli sum = 100001, ans=0;
  seg.update(sum, seg.get(sum)+1);
  for(lli i = 0; i < a_arr.size(); i++){
    if(a_arr[i] <= t) sum--;
    else sum++;
    ans += i+1 - seg.query(0, sum+1);
    seg.update(sum, seg.get(sum)+1);
  }
  return ans;
}

int main(){
  lli N;
  std::cin >> N;

  std::vector<lli> a_arr(N);
  for(lli i = 0; i < N; i++){
    std::cin >> a_arr[i];
  }

  lli n_med_half = (N*(N+1)/2)/2+1;
  lli begin = 0, end = 1000000005;

  while(end-begin>1){
    lli med=(begin+end-1)/2;
    lli lm = lower_med(a_arr, med);
    if(lm >= n_med_half) end=med+1;
    else begin=med+1;
  }

  std::cout << begin << std::endl;

  return 0;
}



Measured memory_bytes: 5244
// AOJ 2867 Many Kinds of Apples
// 2018.3.29 bal4u

#include <stdio.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int c[1002];
int a[1002];

int main()
{
	int N, Q, i, t, x, d, ans;

	N = in();
	for (i = 1; i <= N; i++) c[i] = in();
	Q = in();
	ans = 0;
	while (Q--) {
		t = in(), x = in(), d = in();
		if (t == 1) {
			a[x] += d;
			if (a[x] > c[x]) { ans = x; break; }
		} else {
			a[x] -= d;
			if (a[x] < 0) { ans = x; break; }
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n)-1); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n)-1); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

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

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,b,k; cin >> a >> b >> k;
    rep(i,a,min(b-k+1,a+k)){
        cout << i << endl;
    }
    rep(i,max(b-k+1,a),b+1){
        cout << i << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  string s;
  cin>>s;
  int n = s.size();
  vector<vector<ll>> dp = vector<vector<ll>>(n,vector<ll>(13,0));
  if(s[n-1]=='?') {
    rep(i,10)
      dp[n-1][i]=1;
  } else {
    dp[n-1][(int)(s[n-1]-'0')]=1;
  }
  ll modexp = 10;
  const ll p = 1e9+7;
  revrep(i,n-1) {
    if(s[i]=='?') {
      rep(d,10) {
	rep(k,13) { // dp[i+1][k] -> dp[i][(k+d*modexp)%13]
	  dp[i][(k+d*modexp)%13]+=dp[i+1][k];
	  dp[i][(k+d*modexp)%13]%=p;
	}
      }
    } else {
      ll d = (int)(s[i]-'0');
      rep(k,13) {
	dp[i][(k+d*modexp)%13]+=dp[i+1][k];
	dp[i][(k+d*modexp)%13]%=p;
      }
    }
    modexp*=10;
    modexp%=13;
  }
  cout << dp[0][5] << endl;
  return 0;
}


Measured memory_bytes: 13648
#include<algorithm>
#include <bits/stdc++.h>
using namespace std;
int main(void){
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]) cout<<"YES"<<endl;
  	else cout<<"NO"<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

class SCCD {
public:
	stack<int> post;
	vb used;

	void dfs(int pos, int par, const Graph &G) {
		used[pos] = true;
		rep(i, G[pos].size()) {
			int to = G[pos][i].to;
			if (used[to])continue;
			dfs(to, pos, G);
		}
		post.push(pos);
	}

	void dfsrev(int pos, int par, const Graph &rev, vi &group) {
		used[pos] = true;
		group.push_back(pos);
		rep(i, rev[pos].size()) {
			int to = rev[pos][i].to;
			if (used[to])continue;
			dfsrev(to, pos, rev, group);
		}
	}

	void SCC(Graph G, vvi &scc, vi &n2g) {
		int N = G.size();
		Graph rev(N);
		rep(i, N) {
			rep(j, G[i].size()) {
				Edge e = G[i][j];
				rev[e.to].push_back(Edge{ e.to,e.from,1 });
			}
		}

		used = vb(N, false);
		rep(i, N) {
			if (!used[i])dfs(i, -1, G);
		}

		fill(all(used), false);
		while (!post.empty()) {
			int pos = post.top();
			post.pop();
			if (used[pos])continue;
			vi group;
			dfsrev(pos, -1, rev, group);
			scc.push_back(group);
		}

		rep(i, scc.size()) {
			rep(j, scc[i].size()) {
				n2g[scc[i][j]] = i;
			}
		}
	}
};

int main() {
	int V, E;
	cin >> V >> E;
	Graph G(V);
	
	rep(i, E) {
		int s, t;
		cin >> s >> t;
		G[s].push_back(Edge{ s,t,1 });
	}

	vvi scc;
	vi n2g(V);

	SCCD sccd;
	sccd.SCC(G, scc, n2g);

	int Q;
	cin >> Q;
	rep(i, Q) {
		int a, b;
		cin >> a >> b;
		if (n2g[a] == n2g[b])printf("1\n");
		else printf("0\n");
	}
}

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

const int maxn = 510;
int n, num[maxn], cur[maxn], pos[maxn], ans[maxn * maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &num[i]), pos[i] = i;
    }
    sort(pos + 1, pos + n + 1, [&](int x, int y) { return num[x] < num[y]; });
    for (int i = 1; i <= n * n; i++) {
        bool flag = 1;
        for (int k = 1; k <= n; k++) {
            int j = pos[k];
            if (num[j] < i) continue;
            if (num[j] == i) {
                if (cur[j] ^ (j - 1)) flag = 0;
                else ans[i] = j, cur[j]++;
                break;
            }
            if (cur[j] < j - 1) { ans[i] = j, cur[j]++; break; }
        }
        if (!flag) printf("No\n"), exit(0);
        if (!ans[i]) {
            for (int j = 1; j <= n; j++) if (num[j] < i) {
                if (cur[j] < n) { ans[i] = j, cur[j]++; break; }
            }
        }
        if (!ans[i]) {
            for (int j = 1; j <= n; j++) {
                if (cur[j] < n) { ans[i] = j, cur[j]++; break; }
            }
        }
        if (!ans[i]) printf("No\n"), exit(0);
    }
    printf("Yes\n");
    for (int i = 1; i <= n * n; i++) {
        printf("%d ", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
    int i,j;
    int n;
    cin>>n;
    vi a(n);
    rep(i,n) cin >> a[i];
    int ans = INF;
    rep(i,n){
        int tmp = 0;
        while(a[i]%2==0){   
            a[i]/=2;
            tmp++;
        }
        ans=min(ans,tmp);

    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, b, c, x, i, j, k, d, e, f, cnt=0;
	scanf("%d %d %d %d", &a, &b, &c, &x);
	for(i=0; i<=a; i++)
	{
		d=x-500*i;
		if(d<=0)
		{
			if(d==0) cnt++;
			break;
		}
		for(j=0; j<=b; j++)
		{
			e=d-100*j;
			if(e<=0)
			{
				if(e==0) cnt++;
				break;
			}
			for(k=0; k<=c; k++)
			{
				f=e-50*k;
				if(f<=0)
				{
					if(f==0) cnt++;
					break;
				}
			}
		}
	}
	printf("%d", cnt);
}

Measured memory_bytes: 128
import sys


def main():
    input = sys.stdin.readline
    n, k = map(int, input().split())
    MOD = 10**9 + 7
    answer = 0
    for i in range(k, n+2):
        mi = sigma(0, 1, i)
        ma = sigma(n, -1, i)
        answer += ma - mi + 1
    print(answer % MOD)


def sigma(a, d, n):
    return (2*a+(n-1)*d)*n//2


if __name__ == "__main__":
    main()


Measured memory_bytes: 9220
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

bool is_frind_pair(pair<int, int> red, pair<int, int> blue)
{
	return red.second < blue.first && red.first < blue.second;
}

int main()
{
	int ans = 0;
	int N;

	cin >> N;

	vector<pair<int, int>> red(N), blue(N);
	vector<int> is_used(N, 0);

	for (int i = 0; i < N; i++)
	{
		cin >> red[i].second >> red[i].first; // y, x
	}

	for (int i = 0; i < N; i++)
	{
		cin >> blue[i].first >> blue[i].second; // x, y
	}

	sort(blue.begin(), blue.end());
	sort(red.begin(), red.end());
	reverse(red.begin(), red.end());

	for (int i = 0; i < N; i++)
	{
		auto pos = blue[i];

		for (int j = 0; j < N; j++)
		{
			if (is_used[j])
			{
				continue;
			}

			if (is_frind_pair(red[j], pos))
			{
				is_used[j] = 1;

				ans++;
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <memory.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define len 101
int map[len][len],color[len],length[len],queue[len],head=0,tail=1;
void enqueue(int x){
    queue[tail]=x;
    tail=(tail+1)%len;
}
int dequeue(void){
    int x=queue[head];
    head=(head+1)%len;
    return x;
}
void bfs(void){
    int x,i;
    queue[0]=1;
    color[1]=BLACK;
    length[1]=0;
    while(head != tail){
        x=dequeue();
        for(i=0;i<map[x][0];i++){
            if(color[map[x][i+1]] == WHITE){
            enqueue(map[x][i+1]);
            color[map[x][i+1]]=GRAY;
            length[map[x][i+1]]=length[x]+1;
            }
        }
        color[x]=BLACK;
    }
}
int main(void){
    int n,i,o,num,sign;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&sign);
        scanf("%d",&num);
        map[sign][0]=num;
        for(o=1;o<=num;o++)
            scanf("%d",&map[sign][o]);
    }
    bfs();
    for(i=1;i<=sign;i++)
        printf("%d %d\n",i,color[i]==0?-1:length[i]);
    return 0;
}

Measured memory_bytes: 636
N = int(input())
A = sorted(map(int, input().split()), reverse=True)

ans = 0
for i, A_i in enumerate(A):
  if i == 0:
    ans += A_i
    continue
  elif 2 * i >= N:
    break
  elif 2 * i == N - 1:
    ans += A_i
    break
  else:
    ans += 2 * A_i

print(ans)

Measured memory_bytes: 30948
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;
int h, w;

int Isrange (int i, int j) {
    if (i>=0 && i<h && j>=0 && j<w)
        return 1;
    return 0;
}

void testCase() {
    //int h, w;
    cin >> h >> w;
    string s[h+1];
    for (int i=0; i<h; i++)
        cin >> s[i];
    int dp[h+2][w+2];
    dp[0][0] = 0;
    if (s[0][0] == '#')
        dp[0][0] = 1;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (i==0 && j==0)
                continue;
            int mn = 1e9;
            int wt;
            if (Isrange(i-1, j)) {
                if (s[i-1][j]=='.' && s[i][j]=='#')
                    wt=1;
                else
                    wt=0;
                mn = min (mn, wt+dp[i-1][j]);
            }
            if (Isrange (i, j-1)) {
                if (s[i][j-1]=='.' && s[i][j]=='#')
                    wt=1;
                else
                    wt=0;
                mn = min (mn, wt+dp[i][j-1]);
            }
            dp[i][j] = mn;
        }
    }
    cout << dp[h-1][w-1] << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

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

using namespace std;
int main()
{
	char ls;
	string ans;

	cin >> ls;

	switch (ls) {
	case 'a':
	case 'e':
	case 'i':
	case 'o':
	case 'u':
		ans = "vowel";
		break;

	default:
		ans = "consonant";
		break;
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
struct WeightedUnionFind{
  vector< pair<int, long long> > data;
  WeightedUnionFind(int n) : data(n, pair<int,long long>(-1,0LL)) {}
  bool unite(int x, int y, long long w){
    int x_ = find(x), y_ = find(y);
    if(x_ == y_) return true;
    if(data[y_].first < data[x_].first){
      swap(x_,y_); swap(x,y);
      w *= -1LL;
    }
    data[x_].first += data[y_].first;
    data[y_].first = x_;
    data[y_].second += w + rel_weight(x) - rel_weight(y);
    return true;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int find(int x){
    if(data[x].first < 0) return x;
    int p = find(data[x].first);
    data[x].second += data[data[x].first].second;
    data[x].first = p;
    return data[x].first;
  }
  long long rel_weight(int x){
    return data[x].second;
  }
};
int main(){
  int n, q;cin >> n >> q;
  WeightedUnionFind wuf(n);
  while(q--){
    int t, x, y, z;cin >> t >> x >> y;
    if(t){
      if(wuf.same(x,y)) cout << wuf.rel_weight(y) - wuf.rel_weight(x) << endl;
      else cout << "?" << endl;
      continue;
    }
    cin >> z;
    wuf.unite(x,y,z);
  }
}


Measured memory_bytes: 4416
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
mod = 10 ** 9 + 7

class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
f = Factorial(2 * N, mod)
dp = [0] * N
dp[0] = 1
for i in range(N - 1):
  x = i + 1
  dp[i + 1] = f.combi(N, x) * f.combi(x + (N - x - 1), N - x - 1) % mod
  dp[i + 1] += dp[i]
  dp[i + 1] %= mod
if K >= N: print(dp[-1])
else: print(dp[K])

Measured memory_bytes: 73456
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    double x,t;
    cin >> x >> t;
   
    printf("%.10lf\n",x/t);
    
	return  0;
}

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

int main(){
	double v, t, y;
	int N;
	while(cin >> v){
		t = v / 9.8;
		y = pow(t, 2) * 4.9;
		N = (y/5 + 1);
		cout << N + 1 << endl;
	}
}

Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>


using namespace std;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j, a,b,count=0,sum,val,k;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        sum=a+b;
        while(sum!=0)
        {
            count++;
            sum/=10;
        }
        cout<<count<<endl;
        count=0;
    }
}



Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
  int n = 0;
  cin >> n;
  int point = 0, i = 0;
  for (i=1; i<=n; i++) {
    point += i;
    if (point >= n) {
      break;
    }
  }
  for (int j=1; j<=i; j++) {
    if (j == point - n) continue;
    cout << j << endl;
  }
  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 28);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	ll L,R;
	cin>>L>>R;

	ll lcnt = L/2019;
	ll rcnt = R/2019;

	if(lcnt!=rcnt){
		cout<<0<<endl;
		return 0;
	}
	vector<bool> b(2019,false);
	FOR(i, L, min(R+1, L+2019ll)){
		b[i%2019]=true;	
	}
	
	ll res = INF;
	REP(l,2019)FOR(r,l+1,2019)
		if(b[l] && b[r])
			res = min(res, (l*r)%2019);
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, r, b;
	cin>>n;
	string s;
	cin>>s;
	r = b = 0;
	for(int i = 0; i < n; ++i){
		if(s[i]=='R')r++;
		else b++;
	}
	if(r > b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(ll i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;


int main(){
  ll n;
  cin >> n;
  vector<int> a(n);
  map<int,int> mp;
  rep(i,n){
    cin >> a[i];
    mp[a[i]]++;
  }

  vector<ll> b;
  for(auto it:mp){
    b.emplace_back(it.S);
  }
  sort(b.begin(),b.end());
  ll m= b.size();
  vector<ll> r(n+1,0);
  rep(i,n){ r[i+1] = r[i]+(i<m?b[i]:0); }

  REP(k,1,n+1){
    ll ok=-1,ng=n+1,mid=(ok+ng)/2;
    while(ng-ok>1){
      mid=(ok+ng)/2;
      ll pos = lower_bound(b.begin(),b.end(),mid) - b.begin();
      ll cnt = r[pos] + mid*(m-pos);      
      if(cnt >= mid*k){ 
        ok=mid; 
      }else{ 
        ng=mid; 
      }
    }
    ll ans = ok;
    cout << ans << ln;
  }
  return 0;
}

Measured memory_bytes: 22412
#include "bits/stdc++.h"
using namespace std;

#define all(x) (x).begin(),(x).end()
#define fastio ios_base::sync_with_stdio(false)

typedef double db;
typedef long long ll;
typedef unsigned long long ull;

typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

int main() {
	fastio;
	int x; cin >> x;
	int q1 = x/500;
	int left = x - (500 * q1);
	int q2 = left/5;
	long long int ans = (1000 * q1) + (5 * q2);
	cout <<  ans << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    a--;
    m[i] = a;
  }
  int cnt = 0;
  for (auto mm : m) {
    if (m[mm.second] == mm.first) cnt++;
  }

  cout << cnt / 2 << endl;
}

Measured memory_bytes: 4992
from collections import Counter

n = int(input())
d = Counter()
for _ in range(n):
    s = input()
    d[s] += 1
mc = d.most_common()
occ = mc[0][1]
ret = []
for w, o in mc:
    if o == occ:
        ret.append(w)
    else:
        break
for w in sorted(ret):
    print(w)


Measured memory_bytes: 47676
/*
g++ -std=c++14 -O2 -Wall a.cpp -o a && a
*/

//  io
#include <iostream>
//#include <fstream> //http://www.cplusplus.com/reference/fstream/fstream/
//#include <cstdio>
//#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
//  util
#include <string>
#include <cstring>
#include <algorithm>
//#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
//#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <vector>
//#include <queue>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//int modadd(int a, int b) { return ((a += b) < mod) ? a : (a - mod); }
//int modmult(int a, int b) { return (int)((a * b) % mod) }

//file input routed to stdinout
/*
std::ifstream inFile("input.txt");
std::ofstream outFile("output.txt");
std::cin.rdbuf(inFile.rdbuf());
std::cout.rdbuf(outFile.rdbuf());
*/

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

    int a;
    string str;
    cin >> a >> str;

    if (a >= 3200)
    {
        cout << str;
    }
    else
    {
        cout << "red";
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,d;
  cin>>d>>n;
  int temp=n;
  if(!d){
    if(n!=100) cout<<n<<endl;
    else cout<<n+1<<endl;
  }else if(d==1){
    if(n==100) cout<<n*101<<endl;
    else cout<<n*100<<endl;
  }else{
    if(n!=100) cout<<n*100*100<<endl;
    else cout<<101*100*100<<endl;
  }

  return 0;
}

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



int main() {
   priority_queue<long long> pq;
   int n,m;
   cin>>n>>m;
   long long sum=0;
   for(int i=0;i<n;i++){
      int a;
      cin>>a;
      pq.push(a);
      sum+=a;
   }
   for(int i=0;i<m;i++){
      pq.push(pq.top()/2);
      sum-=(pq.top()/2)+(pq.top()%2);
      pq.pop();
   }
   
   
   cout<<sum<<endl;


}

Measured memory_bytes: 1400
use std::collections::{HashSet, HashMap, BinaryHeap};

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().split_whitespace()
        .map(|x| x.parse().ok().unwrap()).collect()
}

fn main() {
    let nm = read_vec::<i64>();
    let (n, m) = (nm[0], nm[1]);
    let mut AB = Vec::<(i64, i64)>::with_capacity(n as usize);

    for i in 0..n as usize {
        let ab = read_vec::<i64>();
        AB.push((ab[0], ab[1]));
    }
    AB.sort();
    let mut res : i64 = 0;
    let mut idx : usize = 0;
    let mut heap = BinaryHeap::new();
    for i in 1..m+1 {
        while idx < AB.len() && AB[idx].0 <= i {
            heap.push(AB[idx].1);
            idx += 1;
        }
        if heap.len() > 0 {
            res += heap.pop().unwrap();
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
int solve(vector<char> c) {
  int res = 0;
  bool p = false;
  rep(i, SIZE(c)) {
    if (c[i] == 'D') {
      res += 1;
      if (p) res += 1;
      p = false;
    }
    p = c[i] == 'P';
  }
  return res;
}
vector<char> cres;
ll res2 = -1;
void dfs(int d, vector<char> c) {
  if (d == SIZE(c)) {
    int res = solve(c);
    if (res >= res2) {
      cres = c;
      res2 = res;
      debug(res);
    }
    return;
  }
  if (c[d] == '?') {
    c[d] = 'P';
    dfs(d + 1, c);
    c[d] = 'D';
    dfs(d + 1, c);
  } else {
    dfs(d + 1, c);
  }
}

int main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  vector<char> t;
  string s;
  cin >> s;
  rep(i, SIZE(s)) { t.push_back(s[i]); }
  // dfs(0, t);
  for (char i : t) {
    if (i == '?')
      cout << 'D';
    else
      cout << i;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3892
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

template<typename T> void cinpb(vector<T>& x) { T n; cin >> n; x.push_back(n); }
ull gcd(ull a, ull b) { return b ? gcd(b, a%b) : a; }
ull lcm(ull m, ull n) {	return ((0 == m) || (0 == n)) ? 0 : ((m / gcd(m, n)) * n); }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

void yesno(bool f) { cout << (f ? "Yes" : "No") << endl; }

//


int main()
{
	int x, y;
	cin >> x >> y;

	cout << x + y / 2 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++) // for簡略表記
#define DUMP(ar) for(int loop=0; loop<(int)ar.size(); loop++) cout << "[" << loop << "]:" << ar[loop] << endl // 配列一覧表示
#define DUMPL(ar) for(int loop=0; loop<(int)ar.size(); loop++) { cout << ar[loop]; if(loop<(int)ar.size()-1) cout << ' '; } cout << endl; // 配列一行一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
#define LOOPD(i) cout << "ループ[" << i << "]回目---------------" << endl // ループ回数デバグ
using namespace std;
// cout << fixed << setprecision(4) で小数点以下4桁の桁そろえ
// cout << setw(5) << ... で表示形式を5桁に設定 5桁未満なら頭に空白がつく 5桁越なら先頭から5桁まで
// cout << setw(5) << setfill('0') << ... で空白部分の埋め文字に5を使う
// getline(cin, [変数]); で空白などを含む入力の受け取り(行ごとの受け取り)
// cin >> ws; でそこまでにストリームに残されたホワイトスペースを取り除く(=以降のgetlineの有効化)

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

    int n, m;
    cin >> n >> m;

    int i=m/n;
    while(true){
        if((m - i*n) % i == 0) break;
        // LOOPD(i);
        i--;
        if(i == 0) break;
    }
    COUT(i);

    return 0;
}

Measured memory_bytes: 384
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS

   int a, b; cin>>a>>b;
   cout<<(a * b)<<"\n";

    







}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 3612
#include<stdio.h>
#define N 100
int selectionSort(int a[], int n);

int main() {
	int a[N], n, i,k;

	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &a[i]);

	k = selectionSort(a, n);

	for (i = 0; i < n; i++) {
	  if(i > 0){
	    printf(" ");
	  }
		printf("%d", a[i]);
	}
	printf("\n");
	printf("%d\n",k);

	return 0;
}


int selectionSort(int a[], int n) {
  int i, j,minj,z,k = 0;
	for (i = 0; i < n; i++) {
		minj = i;
		for (j = i; j < n; j++) {
		  if (a[j] < a[minj]){
		    minj = j;
		  }
		}
		z = a[i];
		a[i] = a[minj];
		a[minj] = z;
		if (i != minj){
		 k++;
		}
	}
	return k;
}



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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    ll i = 0;
    while (true) {
        if (i & 1) {
            a -= d;
            if (a <= 0) {
                cout << "No\n";
                return 0;
            }
        }
        else {
            c -= b;
            if (c <= 0) {
                cout << "Yes\n";
                return 0;
            }
        }
        ++i;
    }
    return 0;
}



Measured memory_bytes: 3652