akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N; cin >> N;
  vector<int> X(N);
  for(auto& x : X) {
    cin >> x;
  }
  int res = std::numeric_limits<int>::max();
  for (int P = 1; P <= 100; ++P) {
    auto sum = boost::accumulate(X, 0, [&P](int r, int x){
      int diff = x - P;
      return r + diff * diff;
    });
    chmin(res, sum);
  }
  cout << res << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
n,m=list(map(int, input().split()))
h=list(map(int, input().split()))
aa = []
ab = []
for j in range(m):
    a1,b1=[int(j) for j in input().split()]
    aa.append(a1)
    ab.append(b1)
d=[1]*n
for i in range (m):
    x=aa[i]-1
    y=ab[i]-1
    if h[x]>h[y]:
        d[y]=0
    elif h[x]==h[y]:
        d[x]=0
        d[y]=0
    else:
        d[x]=0
su=0
for f in range(n):
    su+=d[f]
print(su)


Measured memory_bytes: 22240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
 
int main(){
  int n; cin >> n;
  str s, t; cin >> s >> t;
  for (int i=0; i<n; i++){
    printf("%c", s[i]);
    printf("%c", t[i]);
  }
  return 0;
}

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

using namespace std;

int main(void) {
    int n, m;
    cin >> n >> m;
    vector<long long int> h(n + 1);
    map<int, long long int> t;
    long long int ans = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
        t[i] = 0;
    }
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        t[a] = max(t[a], h[b]);
        t[b] = max(t[b], h[a]);
    }

    for (auto i = t.begin(); i != t.end(); i++) {
        ans += h[i->first] > i->second;
    }
    cout << ans << endl;
}

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

#define swap(type, x, y) do{ type tmp = x; x = y; y = tmp; } while(0)

int main()
{
	int x = 0, y = 0, count = 0, a[6000] = { 0 };
	while (1){
		cin >> x >> y;
		if (x == 0 && y == 0) break;
		if (x > y) swap(int, x, y);
		a[count] = x, a[count + 1] = y;
		count += 2;
	}
	for (int i = 0; i < count; i += 2) cout << a[i] << " " << a[i + 1] << endl;
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    set<int> seta(a.begin(), a.end());
    cout << seta.size() << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
const int D_MAX_V=2010;
const int D_v_size=2010;
struct D_wolf{
	int t,c,r;
	D_wolf(){t=c=r=0;}
	D_wolf(int t1,int c1,int r1){
		t=t1;c=c1;r=r1;
	}
};
vector<D_wolf>D_G[D_MAX_V];
int D_level[D_MAX_V];
int D_iter[D_MAX_V];

void add_edge(int from,int to,int cap){
	D_G[from].push_back(D_wolf(to,cap,D_G[to].size()));
	D_G[to].push_back(D_wolf(from,0,D_G[from].size()-1));
}
void D_bfs(int s){
	for(int i=0;i<D_v_size;i++)D_level[i]=-1;
	queue<int> Q;
	D_level[s]=0;
	Q.push(s);
	while(Q.size()){
		int v=Q.front();
		Q.pop();
		for(int i=0;i<D_G[v].size();i++){
			if(D_G[v][i].c>0&&D_level[D_G[v][i].t]<0){
				D_level[D_G[v][i].t]=D_level[v]+1;
				Q.push(D_G[v][i].t);
			}
		}
	}
}
int D_dfs(int v,int t,int f){
	if(v==t)return f;
	for(;D_iter[v]<D_G[v].size();D_iter[v]++){
		int i=D_iter[v];
		if(D_G[v][i].c>0&&D_level[v]<D_level[D_G[v][i].t]){
			int d=D_dfs(D_G[v][i].t,t,min(f,D_G[v][i].c));
			if(d>0){
				D_G[v][i].c-=d;
				D_G[D_G[v][i].t][D_G[v][i].r].c+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	for(;;){
		D_bfs(s);
		if(D_level[t]<0)return flow;
		for(int i=0;i<D_v_size;i++)D_iter[i]=0;
		int f;
		while((f=D_dfs(s,t,99999999))>0){flow+=f;}
	}
	return 0;
}
int main(){
	int a,b,c,d,e,f,g;
	while(scanf("%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g),~a){
		for(int i=0;i<D_MAX_V;i++){
			D_level[i]=D_iter[i]=0;D_G[i].clear();
		}
		int s=2000;
		int t=2001;
		for(int i=0;i<a;i++)add_edge(s,i,1);
		for(int i=0;i<b;i++){
			int p;scanf("%d",&p);
			for(int j=0;j<p;j++){
				int q;scanf("%d",&q);
				q--;
				add_edge(q,a+i,1);
			}
			add_edge(a+i,a+b+i,1);
		}
		for(int i=0;i<a;i++)add_edge(i,a+b*2,1);
		add_edge(a+b*2,a+b*2+1,e);
		for(int i=0;i<c;i++){
			int p;scanf("%d",&p);
			for(int j=0;j<p;j++){
				int q;scanf("%d",&q);
				q--;
				add_edge(a+b+q,a+b*2+2+i,1);
			}
			add_edge(a+b*2+1,a+b*2+2+i,1);
			add_edge(a+b*2+2+i,a+b*2+2+c+i,1);
		}
		for(int i=0;i<b;i++)add_edge(a+b+i,a+b*2+2+c*2,1);
		add_edge(a+b*2+2+c*2,a+b*2+2+c*2+1,f);
		for(int i=0;i<d;i++){
			int p;scanf("%d",&p);
			for(int j=0;j<p;j++){
				int q;scanf("%d",&q);q--;
				add_edge(a+b*2+2+c+q,a+b*2+4+c*2+i,1);
			}
			add_edge(a+b*2+4+c*2+i,t,1);
			add_edge(a+b*2+c*2+3,a+b*2+4+c*2+i,1);
		}
		for(int i=0;i<c;i++)add_edge(a+b*2+2+c+i,a+b*2+4+c*2,1);
		add_edge(a+b*2+4+c*2,t,g);
		printf("%d\n",max_flow(s,t));
	}
}

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

int main() {
  string S;
  int N;
  cin >> S;
  N = S.size();
  int x = 0;
  for (int i=0; i<N; i++) {
    if (S[i] == 'x') {
      x++;
    }
  }
  if (x >= 8) {
    cout << "NO" << endl;
  }
  else {
    cout << "YES" << endl;
  }
}

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

int main() {
	int n, r, l = 0;
	cin >> n;
	vector<int> w(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		r += w[i];
	}
	int d, m = r;
	for (int j = 0; j < n; j++) {
		r -= w[j];
		l += w[j];
		d = abs(r - l);
		m = min(d, m);
	} 
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long max = Long.MIN_VALUE;
        int n = sc.nextInt();
        int[] binaryF = new int[n];
        int[][] p = new int[n][11];
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for(int j = 0; j < 10; j++) {
                int num = sc.nextInt();
                sum += num;
                if (j != 9) sum <<= 1;
            }
            binaryF[i] = sum;
        }
        for (int i = 0; i < n; i++) {
            for(int j = 0; j < 11; j++) {
                p[i][j] = sc.nextInt();
            }
        }
        for(int i = 1; i < 1024; i++) {
            int add  = 0;
            for(int j = 0; j < n; j++) {
                int count = oneCount(i & binaryF[j]);
                    add += p[j][count];
            }
            max = Math.max(max, add);
        }
        System.out.println(max);
    }
    private static int oneCount(int num) {
        int count = 0;
        while(num != 0) {
            if((num & 1) == 1) count++;
            num >>= 1;
        }
        return count;
    }
}

Measured memory_bytes: 27460
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n;
int a[maxn], b[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  return true;
}

void solve() {
  for (int i = 0; i < n; i++) {
    a[i] = 1;
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    while (2 * a[i] <= b[i]) {
      int j = i;
      while (j < n && 2 * a[j] <= b[j]) {
        j++;
      }
      res++;
      for (int k = i; k < j; k++) {
        a[k] *= 2;
      }
      if (i && a[i - 1] < b[i - 1]) {
        a[i - 1] = b[i - 1];
      }
      if (j < n && a[j] < b[j]) {
        a[j] = b[j];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] < b[i]) {
      res++;
      a[i] = b[i];
      if (i + 1 < n && a[i + 1] < b[i + 1]) {
        a[i + 1] = b[i + 1];
      }
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 1024
###############################################################################

from bisect import bisect_left as binl
from copy import copy, deepcopy

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * sy) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()

    if n == 1:
        print('Hello World')
    else:
        a = intin()
        b = intin()
        print(a + b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3540
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,p,a[80],e,o;
  e=0;
  o=0;
  cin >> n >> p;
  rep(i,n)cin >> a[i];
  rep(i,n){
    if(a[i]%2==1)o++;
    else e++;
  }
  if(o==0&&p==1)printf("0");
  else if(o==0&&p==0)printf("%lld",POW2(2,n));
  else printf("%lld",POW2(2,n)/2);
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void uniq(vector<int> &vec){sort(vec.begin(), vec.end());vec.erase(unique(vec.begin(), vec.end()), vec.end());}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main() {
    int n,ans=0;
    cin>>n;
    Vi d(n);
    REP(i,0,n) cin>>d[i];
    REP(i,1,n-1){
        if(d[i-1]<d[i] && d[i]<d[i+1]) ans++;
        if(d[i-1]>d[i] && d[i]>d[i+1]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int count = 0;
    for(int i=0;i<n;i++){
        if(a[i]%2 != 0){
            if((i+1)%2 != 0){
                count++;
            }
        }
    }
    cout<<count;
    return 0;
}


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

int n, k;
int a[100000];

signed main()
{
	while (true) {
		cin >> n >> k;
		if (n == 0 && k == 0) break;
		rep(i,k) cin >> a[i];

		sort(a, a + k);

		int mx_len = 1;
		if (a[0] != 0) {
			//0(????´?????????????)??????????????????????????£?????´???
			int len = 1;
			for (int i=1; i<k; i++) {
				if (a[i-1] + 1 == a[i]) {
					len++;
					mx_len = max(mx_len, len);
				} else {
					len = 1;
				}
			}
		} else {
			//0(????´?????????????)???????????????????????´???
			int now_count = 1;	//?????°?????????????¶???????????????°?????????
			int pre_count = 0;
			bool con;

			if (a[1] == 1) {
				con = false;
			} else {
				con = true;
			}

			for (int i=2; i<k; i++) {
				if (a[i-1] + 1 == a[i]) {
					now_count++;
					mx_len = max(mx_len, now_count);
				} else {
					if (con) mx_len = max(mx_len, pre_count + now_count + 1);
					if (a[i-1] + 2 == a[i]) {
						con = true;
					} else {
						con = false;
					}
					pre_count = now_count;
					now_count = 1;
				}
			}
			if (con) {
				mx_len = max(mx_len, pre_count + now_count + 1);
			}
		}

		cout << mx_len << endl;

		//rep(i,k) printf("%d ", a[i]);
	}
}

Measured memory_bytes: 1492
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

vector<long long> burger, patty;

long long dfs(int i, long long& x)
{
    if(x == 0)
        return 0;

    if(burger[i] <= x){
        x -= burger[i];
        return patty[i];
    }

    -- x;
    long long ans = dfs(i-1, x);
    if(x > 0){
        -- x;
        ans += dfs(i-1, x) + 1;
        if(x > 0)
            -- x;
    }
    return ans;
}

long long solve(int n, long long x)
{
    burger.assign(n+1, 1);
    patty.assign(n+1, 1);
    for(int i=1; i<=n; ++i){
        burger[i] = burger[i-1] * 2 + 3;
        patty[i] = patty[i-1] * 2 + 1;
    }
    return dfs(n, x);
}

int main()
{
    int n;
    long long x;
    cin >> n >> x;

    cout << solve(n, x) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;
vector<ll> to[100000];
ll h[100000];

ll ans = 0;
void f(ll v){
  bool ok = true;
  for(ll u: to[v]){
    if(h[u] >= h[v]) ok = false;
  }
  if(ok) ans++;
}

int main(void){
  ll n, m;
  cin >> n >> m;
  REP(i, n) cin >> h[i];
  REP(i, m){
    ll a, b;
    cin >> a >> b;
    a--; b--;
    to[a].emplace_back(b);
    to[b].emplace_back(a);
  }
  REP(i, n) f(i);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10264
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int p[SIZE];
int main(){
    DRI(N);
    REP(i,N){
        DRI(x);
        p[x]=i;
    }
    set<int>H;
    REPP(i,-1,N+1)H.insert(i);
    LL an=0;
    for(int i=N;i>0;i--){
        set<int>::iterator it=H.find(p[i]);
        it--;
        int ll=*it;
        it++;it++;
        int rr=*it;
        H.erase(p[i]);
        an+=(p[i]-ll)*1LL*(rr-p[i])*i;
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))

int main(){
	ll N,ans=0;
	cin >> N;
	vector<ll> T(N);
	FOR(i,0,N){
		cin >> T[i];
	}
	SORT(T);
	while(N){
		if(N==1){
			ans += T[N-1];
			N = 0;
		}else if(N==2){
			ans += T[N-1];
			N = 0;
		}else if(N==3){
			ans += T[N-1]+T[N-2]+T[N-3];
			N = 0;
		}else{
			ll costa = T[N-1] + T[N-2] + T[0]*2;
			ll costb = T[1]*2 + T[0] + T[N-1];
			ans += min(costa,costb);
			N -= 2;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3152
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;
int const N_MAX = 1e5;

// nCr
ll po[POW_MAX + 2];
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
ll mod_inv (ll x) {
  return mod_pow(x, MOD - 2) % MOD;
}
ll comb(int n, int r) {
  if (!po[n]) {
    po[0] = 1;
    FOR(i, 1, n + 1) po[i] = po[i - 1] * i % MOD;
  }
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}
// greatest common divisor
ll gcd(ll a, ll b) {
  while (a % b != 0) {
    ll tmp = a;
    a = b;
    b = tmp % b;
  }
  return b;
}

int N, K;

int main() {
  scanf("%d %d", &N, &K);

  int boxes = N - K + 1;
  for (int i = 1; i < K + 1; i++) {
    if (i > boxes) {
      printf("0\n");
      continue;
    }
    ll x = comb(boxes, i);
    ll y = comb(K - 1, i - 1);

    printf("%lld\n", x * y % MOD);
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  set<int> S;
  int q;
  cin >> q;
  while (q--) {
    int op, x;
    cin >> op >> x;
    if (op == 0) {
      S.insert(x);
      cout << S.size() << endl;
    } else if (op == 1) {
      cout << (S.find(x) != S.end()) << endl;
    } else {
      S.erase(x);
    }
  }
}


Measured memory_bytes: 12380
#include <stdio.h>

int main(void){
  int d,w,h,t;
  int n;
  int r;

  while (scanf("%d%d%d", &d, &w, &h), d*w*h){
    //sort
    if (d>w){
      t=d;d=w;w=t;
    }
    if (w>h){
      t=w;w=h;h=t;
    }
    if (d>w){
      t=d;d=w;w=t;
    }

    scanf("%d", &n);
    for (int i=0; i<n; i++){
      scanf("%d",&r);
      if (d*d+w*w < 4*r*r){
	puts("OK");
      } else {
	puts("NA");
      }
    }
  }
  return 0;
}

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

typedef  long long ll;
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;}

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n,m;
int main(){
    cin>>n>>m;
    vector<int> x(m);
    vector<int> dist(m);
    rep(i,m)cin>>x.at(i);
    if(n>=m){cout<<0<<endl;return 0;}
    sort(x.begin(),x.end());
    rep(i,m-1)dist.at(i)=x.at(i+1)-x.at(i);
    sort(dist.begin(),dist.end(),greater<int>());
    ll ans=x.at(m-1)-x.at(0);
    ll temp=0;
    rep(i,n-1){temp+=dist.at(i);}
    cout<<ans-temp<<endl;
    return 0;
}




Measured memory_bytes: 1024
# There are 3 paths, four cities
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())

patterns = [[(a1, a2, a3), (b1, b2, b3)],
            [(b1, a2, a3), (a1, b2, b3)],
            [(a1, b2, a3), (b1, a2, b3)],
            [(a1, a2, b3), (b1, b2, a3)],
            [(b1, b2, a3), (a1, a2, b3)],
            [(b1, a2, b3), (a1, b2, a3)],
            [(a1, b2, b3), (b1, a2, a3)],
            [(b1, b2, b3), (a1, a2, a3)]]

for pattern in patterns:
    set1 = set(pattern[0])
    set2 = set(pattern[1])
    if len(set1) == 3 and len(set2) == 3:
        print('YES')
        exit()

print('NO')

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

int main()
{
	bool see = true;
	int n, a[21], cnt = 1;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++)
	{
		see = true;
		for (int j = 0; j < i; j++)
		{
			if (a[j] > a[i])
			{
				see = false;
				break;
			}
		}
		if (see)
			cnt++;
	}
	cout << cnt << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,m; 
	while(cin>>n>>m,n)
	{
		int t[n],h[m];
		int tsum=0,hsum=0;
		for(int i = 0; i < n; ++i)
		{
			cin>>t[i];
			tsum+=t[i];
		}
		for(int i = 0; i < m; ++i)
		{
			cin>>h[i];
			hsum+=h[i];
		}

		int taro=1000,hanako=1000;
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < m; ++j)
			{
				int tnow=tsum-t[i];
				int hnow=hsum-h[j];
				tnow+=h[j]; hnow+=t[i];
				if(tnow==hnow&&t[i]+h[j]<taro+hanako)
				{
					taro=t[i]; hanako=h[j];
				}
			}
		}
		if(taro!=1000)
		{
			cout<<taro<<" "<<hanako<<endl;
		}
		else cout<<-1<<endl;
	}
  return 0;
}

Measured memory_bytes: 1160
a,v=[int(j)for j in input().split()]
b,w=[int(j)for j in input().split()]
t=int(input())
p=abs(a-b)
if v-w<0:
    print("NO")
else:
    if t*(v-w)>=p:
        print("YES")
    else:
        print("NO")








Measured memory_bytes: 61696
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N, M;
    cin >> N >> M;
    mat graph(N, vec()), from(N, vec());
    vec h(N, 0);
    Rep (i, N-1+M) {
        ll A, B;
        cin >> A >> B;
        A--; B--;
        graph[A].push_back(B);
        from[B].push_back(A);
        h[B]++;
    }

    stack<ll> st;
    Rep (i, N) {
        if (h[i] == 0) st.push(i);
    }

    vec topological;
    while (st.size()) {
        ll i = st.top(); st.pop();
        topological.push_back(i);
        for (auto &j : graph[i]) {
            h[j]--;
            if (h[j] == 0) st.push(j);
        }
    }

    vec order(N);
    Rep (i, N) {
        order[topological[i]] = i;
    }

    // Rep (i, N) {
    //     cout << topological[i] << " \n"[i==N-1];
    // }

    // Rep (i, N) {
    //     cout << order[i] << " \n"[i==N-1];
    // }

    vec mother(N);
    for (ll i = N-1; i >= 0; i--) {
        ll a = -1;
        for (ll e : from[topological[i]]) {
            chmax(a, order[e]);
        }
        if (a > -1) mother[topological[i]] = topological[a];
        else mother[topological[i]] = -1;
    }

    Rep (i, N) {
        cout << mother[i] + 1 << "\n";
    }
}

Measured memory_bytes: 15096
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll n,a[55];cin>>n;
    for(ll i=1;i<=n;i++)cin>>a[i];
    vector< pair<ll,ll> > ans;
    pair<ll,ll> mx={a[1],1},mn=mx;
    for(ll i=2;i<=n;i++)mx=max(mx,make_pair(a[i],i)),mn=min(mn,make_pair(a[i],i));
    if(mx.first+mn.first>=0){
        for(ll i=1;i<=n;i++)if(i!=mx.second)ans.push_back({mx.second,i});
        for(ll i=1;i<n;i++)ans.push_back({i,i+1});
    }
    else{
        for(ll i=1;i<=n;i++)if(i!=mn.second)ans.push_back({mn.second,i});
        for(ll i=n;i>1;i--)ans.push_back({i,i-1});
    }
    cout<<ans.size()<<"\n";
    for(auto &ele:ans)cout<<ele.first<<" "<<ele.second<<"\n";
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string s,t; cin >> s >> t;
  int ans = 0;
  rep(i,s.size()){
    if(s[i]==t[i]) ans++;
  }

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


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main() 
{
	ios::sync_with_stdio(false);
	string str;
	cin >> str;
	int len = str.length();
	int a=0, b=0;
	for (int i = 0; i < len; ++i)
	{
		if (i % 2)
		{
			if (str[i] == '1')
			{
				++a;
			}
			else
			{
				++b;
			}
		}
		else
		{
			if (str[i] == '1')
			{
				++b;
			}
			else
			{
				++a;
			}
		}
	}
	cout << min(a, b);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
//-------head-------
const int N = 107;
int n;
char s[N], t[N];
bool check(int L) {
	int i = n - L, j = 0;
	rep(l, 0, L) {
		if (s[i] != t[j])
			return false;
		++i, ++j;
	}
	return true;
}
int main() {
	scanf("%d", &n);
	scanf(" %s %s", s, t);
	for (int i = n; i >= 0; --i)
		if (check(i)) {
			printf("%d", 2 * n - i);
			break;
		}
	return 0;
}

Measured memory_bytes: 256
import sys
# input = sys.stdin.readline
from itertools import accumulate

def main():
    N = int(input())
    S = input()
    
    east = accumulate([0] + list(S), lambda total, c: total + (1 if c == "E" else 0))
    next(east)
    east = list(east)

    west = accumulate([0] + list(S), lambda total, c: total + (1 if c == "W" else 0))
    next(west)
    west = list(west)

    east_max = east[-1]
    for i in range(N):
        e = east_max - east[i]
        w = 0 if i == 0 else west[i-1]
        yield e + w



print(min(main()))

Measured memory_bytes: 29692
#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($( { splits.next().unwrap().parse::<$t>().unwrap() },)*)
    }}
}

#[allow(dead_code)]
pub fn gcd(n: u64, m: u64) -> u64 {
    match (n, m) {
        (0, 0) => return 0,
        (0, _) => return 0,
        (_, 0) => return 0,
        (n, m) => {
            let r = n % m;
            if r == 0 {
                m
            } else {
                gcd(m, r)
            }
        }
    }
}


#[allow(dead_code)]
fn prime_factorization(n: u64) -> std::collections::HashMap<u64, u32> {
    let primes = primes((n as f32).sqrt().ceil() as u64);
    let mut h = std::collections::HashMap::new();
    let mut current = n;
    while current != 1 {
        let mut found = false;
        for p in &primes {
            if current % p == 0 {
                let count = h.entry(*p).or_insert(0);
                *count += 1;
                current /= *p;
                found = true;
            }
        }
        if !found {
            let count = h.entry(n).or_insert(0);
            *count += 1;
            break;
        }
    }
    return h;
}


#[allow(dead_code)]
fn primes(n: u64) -> Vec<u64> {
    if n < 3 {
        return vec![];
    }
    let mut res: Vec<u64> = vec![2];
    for i in 3..n {
        let i = i as u64;
        let root = ((n as f64).sqrt().ceil() as usize + 1) as u64;
        let composite = res.iter().take_while(|&&x| x <= root).any(|x| i % x == 0);
        if !composite {
            res.push(i);
        }
    }
    return res;
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (a, b) = input!(u64, u64);

    let gcd = gcd(a, b);
    let ps = prime_factorization(gcd);
    let set: std::collections::HashSet<_> = ps.iter().collect();

    println!("{}", set.len() + 1);
}

fn main() {
    solve();
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const ld PI = 2.0 * acos(0.0);

ld rad(ld a) {
  return a * PI / 180;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  ld sol = sqrt(a * a + b * b - 2 * a * b * cos(rad(min(fabs((h + m / (ld) 60) * 30 - m * 6), 360 - fabs((h + m / (ld) 60) * 30 - m * 6)))));
  cout << fixed << setprecision(9) << sol << "\n";
  return 0;
}


Measured memory_bytes: 4156
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int n, a[100] = {0};
  double ans;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  for(int i = 0; i < n; i++){
    ans += 1.0 / (double)a[i];
  }
  printf("%.10f", 1.0 / ans);
  return 0;
}

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

def main():
    n, k = map(int, input().split())
    kmax = ((n - 1) * (n - 2)) // 2
    if k > kmax:
        print(-1)
        return

    edges = getedges(n, k, kmax)
    print(len(edges))
    for i, j in edges:
        print(i, j)

def getedges(n, k, kmax):
    edges = []
    for i in range(1, n):
        edges.append((i, n))
    if kmax == k:
        return edges
    c = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            edges.append((i, j))
            c += 1
            if c == kmax - k:
                return edges
    assert False

if __name__ == "__main__":
    main()


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j,ii,jj;
  ll result=0,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n),b(n),c(n);
  for(i=0;i<n;i++)cin>>a[i];
  for(i=0;i<n;i++)cin>>b[i];
  for(i=0;i<n;i++)cin>>c[i];
  sort(ALL(a));
  sort(ALL(b));
  sort(ALL(c));
  ll ai=0,bi=0,ci=0;
  vector<ll> bc(n+1);
  for(bi=0;bi<n;bi++){
    while(ci<n&&b[bi]>=c[ci])ci++;
    bc[bi]=n-ci;
    //cout<<bc[bi]<<endl;
  }
  for(i=n-1;i>=0;i--)bc[i]+=bc[i+1];
  
  for(ai=0,bi=0;ai<n;ai++){
    while(bi<n&&a[ai]>=b[bi])bi++;
    result+=bc[bi];
  }
  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
#define lowbit(x) ((x)&(-x))
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int maxn = 3e5 + 10;
const int maxm = 1e6 + 10;
const ll mod =  998244353;

int num[30];
string s[3];

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    for(int i = 0; i < 3; i++) cin >> s[i];
    int ans = 0;
    for(int i = 0; i < n; i++) {
        mst(num, 0);
        int mx = 0;
        for(int j = 0; j < 3; j++) {
            num[s[j][i] - 'a']++;
            mx = max(mx, num[s[j][i] - 'a']);
        }
        ans += 3 - mx;
    }
    cout << ans;
    return 0;
}


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

int main() {
  char S[3];
  char T[3];
  int count = 0;
  for(int i = 0; i < 3; i++){
    char c;
    cin >> c;
    S[i] = c;
    T[2-i] = c;
  }
  
  for(int i = 0; i < 3; i++){
    if(S[i] == T[i]) count++;
  }
  
  if(count == 3) cout << "Yes";
  else cout << "No";
  
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    rep(i, n) {
        ll a;
        cin >> a;
        pq.push(a);
    }
    vector<pair<ll, ll>> cb(m);
    rep(i, m) cin >> cb[i].second >> cb[i].first;
    sort(cb.rbegin(), cb.rend());
    rep(i, m) {
        rep(j, cb[i].second) {
            ll v = pq.top();
            if (v >= cb[i].first) break;
            pq.pop();
            pq.push(cb[i].first);
        }
    }
    ll ans = 0;
    while(!pq.empty()) {
        ans += pq.top(); pq.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2804
h,w = map(int,input().split())
s = list(map(int,input().split()))
g = list(map(int,input().split()))
s[0] -= 1
s[1] -= 1
g[0] -= 1
g[1] -= 1
raw = []
seen = []
for _ in range(h):
  tmp = input()
  raw.append(tmp)
  t = []
  for j in range(w):
    if tmp[j] == '.':
      t.append(0)
    else:
      t.append(1)
  seen.append(t)
#print(seen)
now = [s]
ans = 0
def check(ii,jj):
  if 0 <= ii < h and 0 <= jj < w:
    if seen[ii][jj] == 0:
      seen[ii][jj] = 1
      now.append([ii,jj])
seen[s[0]][s[1]] = 1
from collections import deque
now = deque([s])
while now:
  for i in range(10**6):
    try:
      a,b = now[i]
      check(a-1,b)
      check(a+1,b)
      check(a,b-1)
      check(a,b+1)
    except:
      break
  if seen[g[0]][g[1]] == 1:
    print(ans)
    break
  #print(now)
  ans += 1
  last = now
  now = deque()
  for x in last:
    a,b = x
    for di in range(-2,3):
      for dj in range(-2,3):
        check(a+di,b+dj)
  #print(now)
else:
  print(-1)

Measured memory_bytes: 108336
#include "iostream"
#include <math.h>
using namespace std;
 
int main(){
 
  int N,M;
  int H[100001]={0};
  bool box[100001]={0};
  int A,B;
  int ans=0;
    
  cin >> N >> M;
  
  for(int i=1; i<=N; i++){
   cin >> H[i]; 
    
   box[i]=1;
  }
  
  for(int i=1; i<=M; i++){
  
    cin >> A >> B;
    
    if(H[A] >= H[B]) box[B]=0;
    if(H[A] <= H[B]) box[A]=0;
    
  }
  
  for(int i=1; i<=N; i++){
    ans += box[i];
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 4120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define MP make_pair
#define llu unsigned long long
#define U unsigned int
#define ff first
#define ss second
#define SIZE 100005
#define pie 3.14159265358979323
#define minuss 1e-6
#define pair pair<ll,ll>
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define BIG 1000000000
#define INF 1000000000000005
#define N 10000
vector<ll>vec;
map<string,ll> mps;
map<ll,string> mpss;
set<ll>s1;
set<string>s2;
map<string,ll>::iterator str;
set<ll>::iterator itr;
/*
std::cout << std::fixed;
std::cout << std::setprecision(1);
std::cout << VALUE NAME<<endl;
*/
ll tra[100006],tra1[100006];


int main()
{
    fast_cin;
    ll t;

        map<ll,ll>mp;
        map<ll,ll>::iterator it;
        string s,s1;
        ll lock=0,sum=0,co=0;
        ll n,m;
        cin>>n;

        ll str[n+5];
        for(int i=0;i<n;i++)
            cin>>str[i];

        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(i!=j)
                {
                    sum+=str[i]*str[j];
                }
            }
        }

         cout<<sum<<endl;

        s1.clear();
        vec.clear();

}



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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define en '\n'
#define pb push_back
#define mp make_pair
#define P pair<int, int>

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;

struct aaa {
	aaa() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
}aaaaa;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];

	vector<ll> sum(n);
	rep(i, n) {
		sum[i] = a[i] + b[i];
	}

	sort(sum.begin(), sum.end());
	reverse(sum.begin(), sum.end());

	ll ans = 0;
	rep(i, n) {
		if (i % 2 == 0) {
			ans += sum[i];
		}
	}

	ll bSum = 0;
	rep(i, n) {
		bSum += b[i];
	}

	cout << ans - bSum << endl;
}

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int N,M,p,ac=0,wa=0;
    string s;
    cin >> N >> M;
    vector<bool> acManagement(N+1);
    vector<int> waManagement(N+1); 
    REP(i,0,M){
        cin >> p >> s;
        if(s=="AC"){
            if(acManagement[p]) continue;
            ac++;
            acManagement[p]=true;
            wa+=waManagement[p];
        }else{
            if(acManagement[p]) continue;
            waManagement[p]+=1;
        }
    }
    P2(ac, wa);
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <math.h>
#include <stack>
using namespace std;
typedef long long ll;

void solve(int i,int d,vector<pair<string,vector<int>>>v){
	for(int i=0;i<d;i++){
		cout << ".";
	}
	cout << v[i].first << endl;
	for(int t:v[i].second){
		solve(t,d+1,v);
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<pair<string,vector<int>>> v(n);
	for(int i=0;i<n;i++){
		int k; cin >> k;
		cin >> v[i].first;
		if(k){
			v[k-1].second.push_back(i);
		}
	}
	solve(0,0,v);
}


Measured memory_bytes: 66036
#include <iostream>
using namespace std;
int main()
{
    char c;
    cin >> c;
    c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'o' || c == 'i' || c == 'u')
        cout << "vowel\n";
    else
        cout << "consonant\n";
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> vec(m);
  vector<int> v(n);
  int i;
  for(i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    vec.at(i)=make_pair(a,b);
    v.at(a-1)++;
    v.at(b-1)++;
  }
  for(i=0;i<n;i++){
    cout << v.at(i) << endl;
  }
}

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

int main(void){
  int x, t;
  scanf("%d %d",&x,&t);
  if(x<t) printf("0\n");
  else printf("%d\n",x-t);

  return 0;
}


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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> L(M);
	vector<int> R(M);
	
	
	
	for (int i = 0; i < M; i++) {
		cin >> L[i] >> R[i] ;
	}
	;
	int answer;
	int noans = 0;
	int le = L[0], re = R[0];
	
	//for (int i = 0; i < M; i++) cout << L[i]<<R[i]<<endl;
	
	for (int j = 1; j < M; j++) {
		if (L[j] - re > 0) noans = 1;
		else if (L[j] - le > 0) {
			le = L[j];
			if (R[j] - re < 0) {
				re = R[j];
			}
			
		}

		else if(R[j] - re < 0)re = R[j];
		
			
		}
	
	
	if (noans)answer = 0;
	else answer = re - le+1;
	cout << answer;
	
	return 0;
}


Measured memory_bytes: 1152
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

#ifdef YDK
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...)
#endif

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    int N;
    i64 a[100010];

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

    multiset<i64> pend;
    pend.insert(a[0]);

    for (int i = 1;i < N; ++i) {
        auto it = pend.lower_bound(a[i]);
        if (it == pend.begin()) {
            pend.insert(a[i]);
            eprintf("%lld just insert\n", a[i]);
        } else {
            --it;
            const auto tmp = *it;
            pend.erase(it);
            pend.insert(a[i]);
            eprintf("%lld %lld update insert\n", a[i], tmp);
        }
    }

    cout << pend.size() << endl;

    return 0;
}

// vim: set foldmethod=marker :


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    char c[3][3],a,b,d;
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>c[i][j];
        }
    }
    cout<<c[0][0]<<c[1][1]<<c[2][2]<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC139
{
    class D
    {
        static void Main(string[] args)
        {
            long N = int.Parse(Console.ReadLine());
            long res = 0;
            for (long i = 0; i < N; i++)
            {
                res += i;
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 11092
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

ll gcd(int a, int b) {
  int r;
  if (a < b) swap(a, b);
  while (a % b != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

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

  // 比率はx:y
  int x[N], y[N];
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
  }

  ll A = x[0], B = y[0];
  for (int i = 0; i < N; i++) {
    ll n1 = A / x[i];
    ll n2 = B / y[i];
    if (A % x[i] != 0) n1++;
    if (B % y[i] != 0) n2++;
    ll n = max(n1, n2);
    A = n * x[i];
    B = n * y[i];
  }

  cout << A + B << endl;
  return 0;
}


Measured memory_bytes: 256