akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>
#include <math.h>

#define nl '\n'

using namespace std;

int n, e, x;

int nextperm(vector<int> a, vector<int> b){
    x = 0;
    do {
        if(a == b){
            return x;
        }
        x++;
    }while(next_permutation(a.begin(), a.end()));

    return x;
}


int main(){

    vector<int> v;
    vector<int> p;
    vector<int> q;

    cin >> n;
    
    for(int i = 1; i < n+1; i++){
        v.push_back(i);
    }

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

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

    cout << abs(nextperm(v, p) - nextperm(v, q));


}

//g++ -std=c++14 comp.cpp -o b; ./b.exe

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main(){
    string ans = "";
    ll n;
    cin >> n;
    n--;
    while(n>=0){
        ans.push_back((char)(n%26 +'a'));
        n/=26;
        n--;
    }
    for(int i=ans.size()-1;i>=0;i--)cout << ans[i];
    cout << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector <int> a(N+1);
  for (int i = 1; i <= N; i ++) {
    cin >> a[i];
  }
  int ans = 0;
  int button = 1;
  for (ans = 0; ans < N; ans++) {
    if (button==2) break;
    button = a[button];
  }
  if (ans >= N) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3784
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int S = scan.nextInt();
        int W = scan.nextInt();
        if (S <= W) {
            System.out.println("unsafe");
        } else {
            System.out.println("safe");
        }
        scan.close();
    }
}

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

using namespace std;

int cor2Idx(const int i, const int j, const int width)
{
    return i * width + j;
}

void idx2Cor(const int idx, int &i, int &j, const int width)
{
    i = idx / width;
    j = idx % width;
}

bool isRange(const int i, const int j, const int w, const int h)
{
    return i >= 0 && i < h && j >= 0 && j < w;
}

void refine(vector<char> &v, const int i, const int j, const int w, const int h, int &ans)
{
    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, 1, 0, -1};

    for (int k = 0; k < 4; k++)
    {
        if (!isRange(i + dx[k], j + dy[k], w, h))
            continue;
        int idx = cor2Idx(i + dx[k], j + dy[k], w);
        if (v[idx] == '-' || v[idx] == '#')
            continue;
        else if (v[idx] == '.')
        {
            v[idx] = '-';
            ans++;
            refine(v, i + dx[k], j + dy[k], w, h, ans);
        }
    }
}

int main()
{
    while (true)
    {
        int w;
        scanf("%d", &w);
        int h;
        scanf("%d", &h);

        if (w == 0 && h == 0)
            break;

        int si, sj;
        vector<char> v(w * h);
        for (int i = 0; i < w * h; i++)
        {
            char buf;
            scanf("%c", &buf);
            if (buf == '\n')
                i--;
            else
            {
                v[i] = buf;
                if (buf == '@')
                    idx2Cor(i, si, sj, w);
            }
        }

        int ans = 1;
        refine(v, si, sj, w, h, ans);
        printf("%d\n", ans);
    }

    return 0;
}



Measured memory_bytes: 3276
import std.stdio;

void main(){
	int n, c, t;
	int[4] m, s;
	while (readf("%d\n", &n), n) {
		int[int] time;
		foreach (i; 0..n) {
			readf("%d %d %d %d %d %d %d %d %d\n", &c, &m[0], &s[0], &m[1], &s[1], &m[2], &s[2], &m[3], &s[3]);
			t = 0;
			foreach (j; 0..4) t += m[j]*60+s[j];
			time[t] = c;
		}
		auto list = time.keys.sort;
		writeln(time[list[0]]);
		writeln(time[list[1]]);
		writeln(time[list[$-2]]);
	}
}

Measured memory_bytes: 1580
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int r = 3;
	if (a == b&&b == c)r = 1;
	else if (a == b || b == c || c == a)r = 2;
	cout << r << endl;
	//printf((a < 1200) ? "ABC\n" : "ARC\n");
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int dp[555][555];
string s;
int rec(int l,int r){
	if(dp[l][r])return dp[l][r];
	if(l==r)return dp[l][r]=1;
	if(s[l]!='m'||s[r-1]!='w')return dp[l][r]=-1;
	REP(i,l,r){
		if(s[i]=='e'&&rec(l+1,i)==1&&rec(i+1,r-1)==1){
			return dp[l][r]=1;
		}
	}
	return dp[l][r]=-1;
}
int main(){
	cin>>s;
	int n=s.size();
	int ret=rec(0,n);
	if(ret==1)cout<<"Cat"<<endl;
	else cout<<"Rabbit"<<endl;
	return 0;
}


Measured memory_bytes: 4108
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<numeric>
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
bool isDigit(char c){return '0' <= c && c <= '9';}
template<typename T> void remove(std::vector<T>& vector, unsigned int index){vector.erase(vector.begin() + index);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    int n;
    cin >> n;
    int ans;
    if(105<=n&&n<135)ans = 1;
    else if(135<=n&&n<165)ans = 2;
    else if(165<=n&&n<189)ans = 3;
    else if(189<=n&&n<195)ans = 4;
    else if(195<=n)ans = 5;
    else ans = 0;
    cout << ans << endl;
    //105,135,,165,189,195
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a ,b) for(int i = a; i < (b); ++i)
using namespace std;
 
const int INF = 0x3f3f3f3f;
const int MAXD = 123;
const int MAXK = 112345;
const int mod = 1e9+7;
 
char ent[MAXK];
int d, n;
int dp[MAXK][MAXD][2];
string numStr;
 
int rec(int k, int s, int edge){
    if (k == n) return (s % d) == 0;
    if (dp[k][s][edge] != -1) return dp[k][s][edge];
    int lim = 9, resp = 0;
    if (edge) lim = ent[k] - '0';
    rep(i, 0, lim + 1){
        int nedge = edge && (i == lim);
        resp += rec(k + 1, (s + i) % d, nedge);
        resp %= mod;
    }
    return dp[k][s][edge] = resp;
}
 
int main()
{
    scanf("%s\n%d", ent, &d);
    n = strlen(ent);
 
    memset(dp, -1, sizeof(dp));
 
    int resp = 0;
    for(int i=0; i<(ent[0]-'0'); i++){
        resp += rec(1,i%d,0);
        resp %= mod;
    }
    resp += rec(1,(ent[0]-'0')%d,1);
    resp %= mod;
    cout <<  ((resp-1) % mod  < 0 ? (resp-1) % mod + mod : (resp-1) % mod) << '\n';
    return 0;
}

Measured memory_bytes: 109184
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	int n,s=0,m;
	cin >> n;
	m = n;
	while (n>0) {
		s += n % 10;
		n /= 10;
	}
	if (m%s==0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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


int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> arr(n);
  arr[0] = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == 'A' && s[i + 1] =='C') {
      arr[i + 1] = arr[i] + 1;
    } else {
      arr[i + 1] = arr[i];
    }
  }
  for (int i = 0; i < q; ++i) {
    int left, right;
    cin >> left >> right;
    cout << arr[right - 1] - arr[left - 1] << endl;
  }
}


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

int main(){
  string color;
  cin >> color;
  int ans = 0;
  for (int i = 1; i < color.length(); i++){
    if (color[i] == color[i - 1]) {
      ans++;
      if (color[i] == '0') color[i] = '1';
      else color[i] = '0';
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 512
n,k=map(int,input().split())
import math
# コインを連続i回表出さないといけないサイコロの目
# n >= k ならi=0

i=1
ans=max(0,(n-k+1)/n)

while k*2**(-i+1) > 1:
    a = min(n,math.ceil(k*2**(-i+1))-1)
    b = math.ceil(k*2**(-i))
    ans+=max(a-b+1,0) * 2**(-i) /n
    i+=1
print(ans)



Measured memory_bytes: 3060
#include <iostream>
#include <vector>

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  int N;
  std::cin>>N;
  
  uint64_t sum=0;
  std::vector<int> A(100001);
  for(int i=0;i!=N;i++)
  {
    int a;
    std::cin>>a;
    sum+=a;
    A[a]++;
  }
  
  int Q;
  std::cin>>Q;
  
  int B,C;
  for(int i=0;i!=Q;i++)
  {
    std::cin>>B>>C;
    
    sum=sum+(C-B)*A[B];
    
    A[C]=A[C]+A[B];
    A[B]=0;
    
    std::cout<<sum<<"\n";
  }
  
  std::cout<<std::endl;
  
  return 0;
}

Measured memory_bytes: 3728
from math import sqrt

def main():
    N = int(input())

    ans = 10**12+1
    for i in range(1, int(sqrt(N))+1):
        if N % i == 0:
            tmp = i + (N // i) - 2
            ans = min(ans, tmp)
        
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    bool ans=true;
    string s;
    cin>>s;

    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]=='L'){
                ans=false;
                break;
            }
        }
        else{
            if(s[i]=='R'){
                ans=false;
                break;
            }
        }
    }

    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
/*
___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat.
___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat.
___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb.

___az dast o zabane ke barayad ?
___kaz ohdeye shokrash be dar ayad !


___man be to dami gharar natvanam kard
___va ehsane to ra shomar natvanam kard
####################
___gar bar tane man zaban shavad har moyee
___yek shokre to az hezar natvanam kard

*/

#include <bits/stdc++.h>

#define pb push_back
#define SALI main
#define left(x) ((x)*2)
#define right(x) (((x)*2)+1)
#define fuck(x) cout << #x << " : " << x << endl;
#define findLowVec(v,x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define findUpVec(v,x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define findLowArr(a,n,x) (lower_bound(a, a+n, x) - a)
#define findUpArr(a,n,x) (upper_bound(a, a+n, x) - a)
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;

template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p)
{return out << "(" << p.first << ", " << p.second << ")";}

template<class A> ostream& operator <<(ostream& out, const vector<A> &v)
{out << "[";for(int i = 0; i < v.size(); i++) {if(i) out << ", ";out << v[i];}return out << "]";}

template<class A,class B> ostream& operator <<(ostream& out, const set<A,B> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

template<class A> ostream& operator <<(ostream& out, const set<A> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}


int32_t SALI()
{
    int n,W; cin >> n >> W;
    int w[n];
    int v[n];
    int dp[W+1];
    fill(dp,dp+W+1,-1);
    dp[0] = 0;
    int ans = 0;
    for(int i = 0; i < n; i++) cin >> w[i] >> v[i];

    for(int i = 0; i < n; i++){
        for(int j = W; j >= w[i]; j--){
            if(dp[j-w[i]] != -1)
                dp[j] = max(dp[j],dp[j-w[i]] + v[i]);
                ans = max(ans,dp[j]);
        }
    }
    cout << ans << endl;
}


/**< WRITEN BY ALI ADELKHAH */



Measured memory_bytes: 4380
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, M, S, T, u, v;
vector<lint> to[300000];
lint dp[300000];

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> M;
	REP(i, M) {
		cin >> u >> v; u--; v--;
		to[u].push_back(v + N);
		to[u + N].push_back(v + N * 2);
		to[u + N * 2].push_back(v);
	}
	cin >> S >> T; S--; T--;
	REP(i, N * 3) {
		dp[i] = INF;
	}

	queue<lint> que;
	que.push(S);
	dp[S] = 0;
	while (!que.empty()) {
		lint curr = que.front(); que.pop();
		REP(i, SZ(to[curr])) {
			lint next = to[curr][i];
			if (dp[curr] + 1 < dp[next]) {
				dp[next] = dp[curr] + 1;
				que.push(next);
			}
		}
	}
	cout << (dp[T] != INF ? dp[T]/3 : -1) << endl;
}


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

using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)

typedef long long ll;
typedef long long int64;

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;

  if(s.erase(n/2) == s.substr(n/2)){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

int main() {
    int n;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++)
        cin>>a[i];
    int ans=1<<30;
    for (int i=-100;i<=100;i++) {
        int sm=0;
        for (int x:a)
            sm+=(i-x)*(i-x);
        ans=min(ans,sm);
    }
    cout<<ans<<endl;
    return 0;
}

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 = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

class UnionFind {
  vector<int> par, sz;
public:
  UnionFind(int n) {
    par.resize(n);
    for (int i = 0; i < n; i++)
      par[i] = i;
    sz.resize(n, 1);
  }
  int root(int x) {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sz[root(x)];
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (sz[x] >= sz[y]) {
      sz[x] += sz[y];
      par[y] = x;
    } else {
      sz[y] += sz[x];
      par[x] = y;
    }
    return true;
  }
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  vector<int> sa = a, sb = b;
  sort(sa.begin(), sa.end());
  sort(sb.begin(), sb.end());
  rep(i, n) {
    if (sa[i] > sb[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  rep(i, n-1) {
    if (sa[i+1] <= sb[i]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  vector<pair<int, int>> ba(n);
  rep(i, n) ba[i] = {b[i], a[i]};
  sort(ba.begin(), ba.end());
  vector<pair<int, int>> a2(n);
  rep(i, n) a2[i] = {ba[i].second, i};
  sort(a2.begin(), a2.end());
  UnionFind uf(n);
  rep(i, n) uf.unite(a2[i].second, i);
  set<int> st;
  rep(i, n) st.insert(uf.root(i));
  if (st.size() > 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

typedef pair<int,char> P;

int main() {
    int N,K,i,m=0,t,l;
    string S;
    vector<int> h;
    cin >> N >> K >> S;
    char p=S.at(0);

    h.push_back(0);
    for(i=1; i<N; i++) {
        if(p != S.at(i))
            h.push_back(i);
        p = S.at(i);
    }
    h.push_back(N);

    l = h.size()-1;
    for(i=0; i<h.size()-1; i++) {
        if(S.at(h.at(i)) == '0')
            t = h.at(min(i+K*2, l));
        else
            t = h.at(min(i+K*2+1, l));
        m = max(m, t-h.at(i));
    }

    cout << m << endl;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, m;
//ll a[101010], b[101010];
unordered_map<ll, ll> a, b;
int main(){
    cin>>n>>m;
    REP(i, 0, n){
        ll tmp;
        cin>>tmp;
        a[tmp]++;
    }
    REP(i, 0, m){
        ll tmp;
        cin>>tmp;
        b[tmp]++;
    }

    ll sum=0;
    for(auto itra : a){
        for(auto itrb : b){
            sum+=(itra.first*itra.second*itrb.first*itrb.second);
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3184
def ncr(n, r, p): 
  num = den = 1 
  for i in range(r): 
      num = (num * (n - i)) % p 
      den = (den * (i + 1)) % p 
  return (num * pow(den, p - 2, p)) % p
p=10**9+7
n,a,b = map(int,(input().split()))
bb = ncr(n,a,p)+ncr(n,b,p)+1
print((pow(2,n,p)-(bb%p))%p)

Measured memory_bytes: 38640
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  if (n % 2 == 0) {
    n /= 10;
    ans += n;
    while (n) {
      n /= 5;
      ans += n;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int main(){
    long long A,B,C,D;cin >> A >> B >> C >> D;
    cout << (B-B/C-B/D+B/lcm(C,D))-((A-1)-(A-1)/C-(A-1)/D+(A-1)/lcm(C,D)) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define inv_num_valtype tuple
#define inf 1e9

typedef struct {
	double A;
	double B;
	double C;
	int i;
}tuple;

double X;

//比較関数
int compare(inv_num_valtype a, inv_num_valtype b){
	return a.i - b.i;
}

//昇順
int inv_num_sub(inv_num_valtype *origin, int left, int right, inv_num_valtype *tmp){
	int ans = 0;
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		ans += inv_num_sub(origin, left, half, tmp);
		ans += inv_num_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				ans += k - i;
				k++;
			}
		}
	}
	return ans;
}

//i < j && a[i] > a[j] となる組(i, j)の数
//effect: sortされる
int inv_num(inv_num_valtype *origin, int N){
	inv_num_valtype *tmp = (inv_num_valtype *)malloc(sizeof(inv_num_valtype) * N);
	return inv_num_sub(origin, 0, N, tmp);
}

signed compare_tuple_X(const void *a, const void *b){
	tuple ta = *(tuple *)a, tb = *(tuple *)b;
	double sub = (-ta.A * X + ta.C) / ta.B - (-tb.A * X + tb.C) / tb.B;
	if(sub < 0){
		return -1;
	}
	else if(sub == 0){
		return 0;
	}
	else{
		return 1;
	}
}

signed main(){
	int N, mid, inv, i;
	scanf("%lld", &N);
	mid = ((N * (N - 1)) / 2 + 1) / 2;
//	printf("mid = %lld\n", mid);
	tuple *tp = (tuple *)malloc(sizeof(tuple) * N);
	for(i = 0; i < N; i++){
		scanf("%lf%lf%lf", &tp[i].A, &tp[i].B, &tp[i].C);
	}
	double l, h, r;
	X = -inf;
	qsort(tp, N, sizeof(tuple), compare_tuple_X);
	for(i = 0; i < N; i++){
		tp[i].i = i;
	}
/*	for(i = 0; i < N; i++){
		printf("tp[%lld] = (%lf, %lf, %lf, %lld)\n", i, tp[i].A, tp[i].B, tp[i].C, tp[i].i);
	}
*/	for(i = 0, l = -inf, r = inf; i < 100; i++){
		h = (l + r) / 2;
		X = h;
//		printf("X = %lf\n", X);
		qsort(tp, N, sizeof(tuple), compare_tuple_X);
		inv = inv_num(tp, N);
//		printf("inv = %lld\n", inv);
		if(inv >= mid){
			r = h;
		}
		else{
			l = h;
		}
	}
	printf("%.12lf ", r);

	for(i = 0; i < N; i++){
		double tmp = tp[i].A;
		tp[i].A = tp[i].B;
		tp[i].B = tmp;
	}
	X = -inf;
	qsort(tp, N, sizeof(tuple), compare_tuple_X);
	for(i = 0; i < N; i++){
		tp[i].i = i;
	}
	for(i = 0, l = -inf, r = inf; i < 100; i++){
		h = (l + r) / 2;
		X = h;
		qsort(tp, N, sizeof(tuple), compare_tuple_X);
		inv = inv_num(tp, N);
		if(inv >= mid){
			r = h;
		}
		else{
			l = h;
		}
	}
	printf("%.12lf\n", r);
	return 0;
}

Measured memory_bytes: 251416
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int INF = 1000000;

struct info{
	double total;
	int vertex;
	int ticket;
	info(int t, int v, int ti){
		total = t; vertex = v; ticket = ti;
	}

	bool operator <(const info &other) const{
		return total > other.total;
	}
};

int main(){
	//freopen("test.txt", "r", stdin);

	while(1){
		int n, m, p, a, b;
		cin >> n >> m >> p >> a >> b;
		if(!n)break;
		vector<int> ticket(n);
		rep(i, n){
			cin >> ticket[i];
		}

		m++;
		vector<vector<double> > edge(m, vector<double>(m, INF));

		rep(i, p){
			int x, y, z;
			cin >> x >> y >> z;
			edge[x][y] = edge[y][x] = z;
		}

		int ticketflag = 0;
		rep(i, n){
			ticketflag |= 1<<i;
		}

		priority_queue<info> q;
		q.push(info(0, a, ticketflag));

		vector<vector<double> > best(ticketflag+2, vector<double>(m, INF));

		while(!q.empty()){
			info p = q.top();
			q.pop();

			if(best[p.ticket][p.vertex] <= p.total) continue;
			best[p.ticket][p.vertex] = p.total;
			if(p.vertex == b)break;

			rep(i, m){
				if(edge[p.vertex][i] == INF)continue;
				rep(j, n){
					if((p.ticket & (1<<j)) == 0) continue;
					info next = p;
					next.total = p.total + edge[p.vertex][i]/ticket[j];
					next.ticket &= ~(1<<j);
					next.vertex = i;
					q.push(next);
				}
			}
		}

		double bestway = INF;
		rep(i, 1<<n){
			bestway = min(bestway, best[i][b]);
		}

		if(bestway != INF)printf("%.8lf\n", bestway);
		else cout << "Impossible" << endl;
	}

	return 0;
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n,m;
  cin >> n >> m;
  int a[n];
  priority_queue<int> queue;
  ll sum = 0;
  REP(i,n){
    cin >> a[i];
    queue.push(a[i]);
    sum += a[i];
  }
  int q;
  REP(i,m){
	q = queue.top();queue.pop();
    sum -= (q-q/2);
    queue.push(q/2);
  }
  
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4284
n,k = map(int,input().split())	
a = list(map(int,input().split()))
cnt={}
for i in a:
    if i not in cnt:
        cnt[i]=1
    else:
        cnt[i]+=1
num=[]
for i in cnt:
    num.append(cnt[i])
num.sort()
num_l=len(num)
ans=i=0
while num_l > k:
    ans+=num[i]
    i+=1
    num_l-=1
print(ans)

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

long long calc_fee(int v, int w) {
//    cout << v << ' ' << w << endl;
    if (v <= 60 && w <= 2) {
        return 600;
    } else if (v <= 80 && w <= 5) {
        return 800;
    } else if (v <= 100 && w <= 10) {
        return 1000;
    } else if (v <= 120 && w <= 15) {
        return 1200;
    } else if (v <= 140 && w <= 20) {
        return 1400;
    } else if (v <= 160 && w <= 25) {
        return 1600;
    }
    return 0;
};

int main() {
    int n;
    while (cin >> n, n != 0) {
        long long total_fee = 0;
        for (int i = 0; i < n; i++) {
            int x, y, h, w;
            cin >> x >> y >> h >> w;
            total_fee += calc_fee(x+y+h, w);
        }
        cout << total_fee << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		 long double   ld;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;


int main()
{

    ll x;
    cin>>x;

    for(ll i=x; ; i++)
    {
        ll y=i;

        ll f=1;
        for(ll j=2;j*j<=y;j++)
        {
            if(y%j==0)
            {
                ll a=y/j;
                ll b=j;
                if(a!=1&&a!=y) f=0;
                if(b!=1&&b!=y) f=0;
            }
        }

        if(f)
        {
            cout<<y<<nn;
            return 0;
        }
    }





}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll x[n+5];
    for(ll i=0;i<n;i++)
    {
        cin>>x[i];
    }
    sort(x,x+n);
    ll sum=0;
    for(ll i=0;i<k;i++)
    {
        sum+=x[i];
    }
    cout<<sum<<endl;
 return 0;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int x=-1,y=-1,z=-1,N,Y;
int main()
{
	cin>>N>>Y;
	Y/=1000;
	for(int i=0;i<=N;i++)
	  for(int j=0;j<=N-i;j++)
	  {
	  	if(i*10+j*5+(N-i-j)*1==Y&&(N-i-j)>=0)
	  	{
	  		cout<<i<<" "<<j<<" "<<N-i-j<<endl;
	 // 		cout<<"10000*i="<<10000*i<<endl;
//	  		cout<<"5000*j="<<5000*j<<endl;
	 // 		cout<<"1000*(N-i-j)="<<1000*(N-i-j)<<endl;
	 // 		cout<<10000*i+5000*j+1000*(N-i-j)<<endl;
	  		return 0;
	  	}
	  }
	cout<<"-1 -1 -1"<<endl;
	return 0;
}

Measured memory_bytes: 256
/*
    Mbak Rose Dong
*/
#include<bits/stdc++.h>
using namespace std;
struct angka
{
    int score;
    string city;
    int id;
};

struct angka node[105];
bool desc(struct angka a, struct angka b)
{
    if(a.city == b.city)
        return a.score > b.score;
    else
        return a.city < b.city;
}
int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m,h;
    cin >> n;
    for(i=0;i<n;i++)
    {
        string a;
        cin >> a >> curr;
        node[i].id = i+1;
        node[i].city = a;
        node[i].score = curr;
    }
    sort(node,node+n,desc);
    for(i=0;i<n;i++)
        cout << node[i].id << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;
const double PI = acos(-1.0);

using namespace std;

int main()
{
    string ans;
    int a, b;
    cin >> a >> b;
    if (a * 500 >= b)
    {
        ans = "Yes";
    }
    else
    {
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}

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

ans = 0
for i in range(1, int(m ** 0.5) + 1)[::-1]:
    if (m % i == 0):
        if m / i >= n:
            ans = max(ans, i)
        if i >= n:
            ans = max(ans, m // i)
print(ans)


Measured memory_bytes: 3188
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        s: chars,
        t: chars,
    }
    let mut dp: Vec<Vec<u16>> = vec![vec![0; t.len() + 1]; s.len() + 1];
    for i in (0..s.len()).rev() {
        for j in (0..t.len()).rev() {
            if s[i] == t[j] {
                dp[i][j] = dp[i + 1][j + 1] + 1;
            } else {
                dp[i][j] = std::cmp::max (dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }
    let mut x = 0;
    let mut y = 0;
    while x < s.len() && y < t.len() {
        if s[x] == t[y] {
            print! ("{}", s[x]);
            x += 1;
            y += 1;
        } else if dp[x][y] == dp[x + 1][y] {
            x += 1;
        } else {
            y += 1;
        }
    }
    println! ();
}

fn main() {
    run();
}


Measured memory_bytes: 22780
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.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 FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#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 F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int X,A; R(X,A);
    W(X<A?0:10);
    return 0;
}


Measured memory_bytes: 256
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
N = int(input())
table = list(map(int,input().split()))
 
swap_count = 0
 
for i in range(0,len(table)-1): #最小値を持ってくる場所のループ
    for k in range(len(table)-1,i,-1):
        if table[k-1] > table[k]:
            table[k-1],table[k] = table[k],table[k-1]
            swap_count += 1
 
print(' '.join(map(str,table)))
print("%d"%(swap_count))


Measured memory_bytes: 6380
#include <iostream>
#include <algorithm>
#include <vector>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


void dfs(vector<int>* gp, bool* pos, int p) {
	int i;
	for (i = 0; i < gp[p].size(); i++) {
		if (!pos[gp[p][i]]) {
			pos[gp[p][i]] = true;
			dfs(gp, pos, gp[p][i]);
		}
	}
}

int main(void) {
	int n, m, p, i, j, a, b, c;
	vector<P> g[2503];
	vector<int> gp[2503];
	bool pos[2503] = { false };

	scanf("%d%d%d", &n, &m, &p);
	for (i = 0; i < m; i++) {
		scanf("%d%d%d", &a, &b, &c);
		g[a - 1].push_back(P(b - 1, c - p));
		gp[b - 1].push_back(a - 1);
	}

	pos[n - 1] = true;
	dfs(gp, pos, n - 1);

	int update = 0;
	bool con = true;
	ll hl[2503] = {};

	for (i = 0; i < n; i++) {
		hl[i] = (ll)-1e18;
	}

	hl[0] = 0;
	while (con) {
		con = false;
		for (i = 0; i < n; i++) {
			if (!pos[i] || hl[i] == (ll)-1e18) {
				continue;
			}
			for (j = 0; j < g[i].size(); j++) {
				if (hl[g[i][j].first] < hl[i] + g[i][j].second && pos[g[i][j].first]) {
					hl[g[i][j].first] = hl[i] + g[i][j].second;
					con = true;
					if (update == m) {
						printf("-1\n");
						return 0;
					}
				}
			}
		}
		update++;
	}

	printf("%lld\n", max(0ll, hl[n - 1]));

	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), is_sorted(),

int R,C,K;
int v[3005][3005];
int dp[3005][3005][4];

int f(int i,int j,int left){
    if((i==R+1 && j==C)||(j==C+1 && i==R))return 0;
    if(i==R+1 || j==C+1)return -INF;
    int &ans=dp[i][j][left];
    if(ans!=-1)return ans;
    
    if(v[i][j]){
        if(left)ans=max(ans,v[i][j]+f(i+1,j,3));
        if(left)ans=max(ans,v[i][j]+f(i,j+1,left-1));
    }
    ans=max(ans,f(i+1,j,3));
    ans=max(ans,f(i,j+1,left));
    
    return ans;
}

signed main(){
    FASTER;
    memset(dp,-1,sizeof dp);
    cin>>R>>C>>K;
    for(int i=1;i<=K;i++){
        int x,y,z;cin>>x>>y>>z;
        v[x][y]=z;
    }
    cout<<f(1,1,3);
}






Measured memory_bytes: 356684
program sum_of_large_numbers
  implicit none
  integer(8), parameter :: m = 1000000007_8, h = (m+1)/2, s = (m+1)/6
  integer(8) :: n, k, i
  read(*,*) n, k
  write(*,'(i0)') modulo(f(n+1)-f(k-1),m)
contains
  integer(8) function f(i)
    integer(8), intent(in) :: i
    f = i*mod((n+1)*mod(h*(i+1),m)-mod(s*mod((i+1)*(i*2+1),m),m)+1,m)
  end
end program sum_of_large_numbers

Measured memory_bytes: 2864
n,a,b = map(int,input().split())

h = [int(input()) for i in range(n)]

h.sort(reverse=True)
tmp = 0
#print(ima_max)
#exit()
ans = 0

low = 0

high = 10**9

while low+1 < high:
    tmp = 0
    mid = (low + high) //2
    #print(mid)
    
    num = 0
    
    for i in range(n):
        num += max(0,(h[i]-mid*b+(a-b-1))//(a-b))
    #print(tmp)
    #print(num)
    
    if num <= mid:
        high = mid
    else:
        low = mid
        
print(high)

Measured memory_bytes: 51544
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, K;
priority_queue<int, vector<int>, greater<int> > que;

// g++ a.cpp -std=gnu++17

int main() {
  INCANT;
  cin >> N >> K;
  int a;
  rep(i, N) {
    cin >> a;
    que.push(a);
  }
  int sum=0;
  rep(i, K) {
    sum+=que.top();
    que.pop();
  }
  cout << sum << "\n";
  return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1e15
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

struct edge{
    ll to,cost,time;
    edge(ll to,ll cost,ll time):to(to),cost(cost),time(time){}
};

struct Data{
    ll ind, time, S;
    Data(ll ind, ll time, ll S): ind(ind),time(time), S(S){
    }
    bool operator<(const Data& other) const {
        return time> other.time;
    }
};

ll dp[51][2505];
ll cd[51][2];
vector<edge> edges[51];

void dijkstra(ll fs){
    priority_queue<Data> pq;
    auto push = [&](ll h,ll t,ll s){
        if(s > 2500) s = 2500;
        if(s < 0) return;
        if(dp[h][s] <= t)return;
        dp[h][s] = t;
        pq.emplace(h,t,s);
    };
    push(0,0,fs);
    while(!pq.empty()){
        Data d = pq.top();pq.pop();
        push(d.ind,d.time + cd[d.ind][1],d.S+cd[d.ind][0]);
        for(edge e: edges[d.ind]){
            push(e.to,d.time + e.time,d.S-e.cost);
        }
    }
}

int main(){
    ll N,M,S;
    cin>>N>>M>>S;
    rep(i,0,N)rep(j,0,2501){
        dp[i][j] = INF;
    }
    rep(i,0,M){
        ll u,v,a,b;
        cin>>u>>v>>a>>b;u--;v--;
        edges[u].emplace_back(v,a,b);
        edges[v].emplace_back(u,a,b);
    }
    rep(i,0,N){
        cin>>cd[i][0]>>cd[i][1];
    }
    dijkstra(S);
    rep(i,1,N){
        ll min_S = INF;
        rep(j,0,2500){
            min_S = min(min_S, dp[i][j]);
        }
        cout<<min_S<<endl;
    }

    return 0;
}

Measured memory_bytes: 7220
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Integer[] list = new Integer[n];
        for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        }
        Integer[] sorted = Arrays.copyOf(list, n);
        Arrays.sort(sorted);

        String ans = "YES";

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (!sorted[i].equals(list[i])) {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 22736
<?php
  fscanf(STDIN, "%d %d", $N, $M);
  $copyN = $N;
  $A = explode(" ", trim(fgets(STDIN)));
  rsort($A);
  $sum = [];
  $arr = [];
  for ($i = 0; $i < $M; $i++) {
    fscanf(STDIN, "%d %d", $BB, $CC);
    if (!isset($sum[$CC])) {
      $sum[$CC] = $BB;
    } else {
      $sum[$CC] += $BB;
    }
  }
  krsort($sum);
  // var_dump($sum);
  foreach ($sum as $num => $cnt) {
    $repeat = min($copyN, $cnt);
    $copyN -= $repeat;
    for ($i = 0; $i < $repeat; $i++) {
      $arr[] = $num;
    }
  }
  if (count($arr) < $N) {
    $arr = array_pad($arr, $N, 0);
  }
  sort($arr);
  // var_dump($arr);
  // echo implode(" ", $A) . PHP_EOL;
  // echo implode(" ", $arr) . PHP_EOL;
  $ans = 0;
  foreach ($A as $k => $v) {
    $ans += max($v, $arr[$k]);
  }
  echo $ans;


Measured memory_bytes: 23028
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k; cin >> n >> k;
	vector<double> p(n);
	for(int i=0; i<n; ++i){
		cin >> p[i];
		p[i]=(p[i]+1)/2;
	}
	
	double sum=0, mx;
	for(int i=0; i<k; ++i) sum += p[i];
	mx=sum;
	for(int i=0; i+k<n; ++i){
		sum = sum-p[i]+p[i+k];
		if(mx<sum){
			mx=sum;
		}
	}
	cout << fixed << setprecision(12);
	cout << mx << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
using namespace std;
const int N=30;
int n;
char str[N];
bool e[N][N];
void readData(){
	scanf("%s",str+1);
	n=strlen(str+1);
}
bool solve(){
	for(int i=1;i<=n;i++){
		for(int j=0;j<26;j++)
			e[i][j]=e[i-1][j];
		e[i][str[i]-'a']=true;
	}
	if(n<26){
		for(int i=1;i<=n;i++) putchar(str[i]);
		for(int j=0;j<26;j++)
			if(!e[n][j]){
				putchar('a'+j);
				break;
			}
		return true;
	}
	for(int j=n-1;j>=1;j--){
		for(int k=str[j]-'a'+1;k<26;k++)
			if(!e[j][k]){
				for(int i=1;i<j;i++) putchar(str[i]);
				putchar('a'+k);
				return true;
			}
	}
	return false;
}
int main(){
	readData();
	if(!solve())
		puts("-1");	
	return 0;
}

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

int main(void)
{
  int N, R;
  cin >> N >> R;

  if (N >= 10)
  {
    cout << R << endl;
  }
  else
  {
    cout << (R + (100 * (10 - N))) << endl;
  }
}

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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    vector<int> p(n+1);
    rep(i,n){
        cin >> p[i];
    } 
    //vector<vector<int>> dp(n,vector<int>(n,0));
    int count=0;
    int min_=inf;
    rep(i,n){
        if(p[i]<=min_){
            count++;
            min_=min(min_,p[i]);
        }
    }
    cout << count;

}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
              int n = sc.nextInt();
              int N = n % 10;
              if(N == 2 || N == 4 || N == 5 || N == 7 || N == 9){
                System.out.println("hon");
              } else if(N == 0 || N == 1 || N == 6 ||  N == 8){
                System.out.println("pon");
              } else {
                System.out.println("bon");
              }             
      }
    }

Measured memory_bytes: 35772
N, X, Y = map(int, input().split())
dist = [[0] * (N+1) for _ in range(N+1)]
cnt = [0] * N
for i in range(1, N):
    for j in range(i + 1, N+1):
        dist = min(j - i, abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X))
        cnt[dist] += 1
print(*cnt[1:], sep='\n')

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);


	int n; cin >> n;
	vector<int> a(n + 1);
	vector<ll> pf(n + 1, 0);
	REPU(i, 1, n + 1) {
		cin >> a[i];
		pf[i] = pf[i - 1] + a[i];
	}
	unordered_map<ll, int> mp;
	mp[pf[n]] = 1;
	ll ans = 0;
	REPD(i, n, 0) {
		ans += mp[pf[i - 1]];
		mp[pf[i - 1]] += 1;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 10824