akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
    int n, m, q;
    cin >> n >> m >> q;
    int abcd[q][4];
    rep(i, q)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--;
        b--;
        abcd[i][0] = a;
        abcd[i][1] = b;
        abcd[i][2] = c;
        abcd[i][3] = d;
    }
    int ans = 0;
    //愚直に10重ループでとける→DFSでこれを綺麗に実装できるっぽい
    for (int i1 = 1; i1 <= m; i1++)
    {
        for (int i2 = i1; i2 <= m; i2++)
        {
            for (int i3 = i2; i3 <= m; i3++)
            {
                for (int i4 = i3; i4 <= m; i4++)
                {
                    for (int i5 = i4; i5 <= m; i5++)
                    {
                        for (int i6 = i5; i6 <= m; i6++)
                        {
                            for (int i7 = i6; i7 <= m; i7++)
                            {
                                for (int i8 = i7; i8 <= m; i8++)
                                {
                                    for (int i9 = i8; i9 <= m; i9++)
                                    {
                                        for (int i10 = i9; i10 <= m; i10++)
                                        {
                                            vector<int> A = {i1, i2, i3, i4, i5, i6, i7, i8, i9, i10};
                                            int tmp = 0;
                                            rep(i, q)
                                            {
                                                if (A[abcd[i][1]] - A[abcd[i][0]] == abcd[i][2])
                                                    tmp += abcd[i][3];
                                            }
                                            ans = max(ans, tmp);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
P = LIST()

tmp = P[0]
ans = 1
for i in range(1, N):
	if P[i] <= tmp:
		ans += 1
		tmp = P[i]
print(ans)


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

#define ll long long 
#define sz(x) (int)x.size()

using namespace std;

int main(){
	int n;
	cin>>n;
	string s[n];
	map<string,int>m;
	for(int i=0;i<n;i++){
		cin>>s[i];
		m[s[i]]++;
	}
	cout<<"AC x "<<m["AC"]<<'\n';
	cout<<"WA x "<<m["WA"]<<'\n';
	cout<<"TLE x "<<m["TLE"]<<'\n';
	cout<<"RE x "<<m["RE"]<<'\n';

}

Measured memory_bytes: 6752
N = int(input())
W = list(map(int, input().split()))
total = sum(W)

subTotal = 0
minVal = 100 * 100
for i in range(N):
    subTotal += W[i]
    if minVal > abs((total - subTotal) - subTotal):
        minVal = abs((total - subTotal) - subTotal)

print(minVal)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n,x,sum,a,ans;
int main() {
	cin>>n>>x;
	for(int i=1; i<=n; i++) {
		cin>>a;
		sum+=a;
		if(sum<=x)ans++;
	}
	printf("%d",ans+1);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long d = scan.nextLong();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            long x = scan.nextLong();
            long y = scan.nextLong();
            if (x * x + y * y <= d * d) ans++;
        }
        System.out.println(ans);
    }
}


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

int main() {
  int n, k; cin >> n >> k; int a[k];
  for(int i=0; i<k; i++) cin >> a[i];
  int an=n;
  while(true) {
    int bn = an; bool able = true;
    while(bn && able) {
      for(int i=0; i<k; i++)
      	if (bn%10 == a[i]) able = false;
      bn/=10;
    }
    if (able == true) {cout << an << endl; break;}
    an++;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

const ll mod = 1e9+7;
ll n;

int main() {
    cin >> n;
    vector<ll> A(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> A.at(i);
    }

    vector<ll> zero(65, 0);
    vector<ll> nzero(65, 0);

    for(int i = 0; i < n; ++i) {
        for(ll j = 0; j < 63; ++j) {
            if(A.at(i)&((ll)1<<j)) {
                nzero.at(j)++;
            }else {
                zero.at(j)++;
            }
        }
    }

    ll ans = 0;
    ll now = 1;
    for(int i = 0; i < 63; ++i) {
        ll next = nzero.at(i)*zero.at(i);
        next %= mod;
        next *= now;
        next %= mod;
        now *= 2;
        now %= mod;
        ans += next;
        ans %= mod;
        // cout << "i " << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
  
using namespace std;
  
double EPS = 1e-10;
  
double add(double a,double b){
  if(abs(a+b)<EPS*(abs(a)+abs(b)))return 0;
  return a+b;
}
  
struct point{
  double x,y;
  point() {}
  point(double x,double y):x(x),y(y){
  }
  point operator + (point p){
    return point(add(x,p.x),add(y,p.y));
  }
  point operator - (point p){
    return point(add(x,-p.x),add(y,-p.y));
  }
  point operator * (double d){
    return point(x*d,y*d);
  }
  point operator / (double d){
    return point(x/d,y/d);
  }
};
  
double dist(point a,point b){
    return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}

int main(void){
    int n,x,y,v;
    vector<point>P;
    vector<double>V;
     
    while(cin >> n,n){
        P.clear();
        V.clear();
         
        for(int i=0;i<n;i++){
            cin >> x >> y >> v;
            P.push_back(point(x,y));
            V.push_back(v);
        }
        
        double r=0.99;
        point now(0,0);
         
        for(double d=10;d>EPS;d*=r){
            int mx=0;
            double mxd=0;
             
            for(int j=0;j<P.size();j++)
                if(dist(now,P[j])/V[j]>mxd)
		  mx=j,mxd=dist(now,P[j])/V[j];
             
            now=now+((P[mx]-now)/dist(P[mx],now))*d;
        }
         
        double ans=0;
        for(int i=0;i<P.size();i++){
            ans=max(ans,dist(now,P[i])/V[i]);
        }
        printf("%.8f\n",ans);
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    string S;
    cin >> S;
    int N = S.length();
    vector<int> n(N);
    REP(i,N){
        n[N-1-i] = S[i] - '0';
    }


    ll ans = 0;
    for(int i = 0; i < (1 << (N-1)); i++){
        ll tmp = 0;
        int idx = 0;
        for(int j = 0; j < N; j++){
            tmp += n[j]*pow(10, idx++);
            //cout << tmp << endl;
            if(i & (1 << j)) {
                ans += tmp;
                tmp = 0;
                idx = 0;
            }
        }
        ans += tmp;
        //printf("%d:%lld\n", i, ans);
    }

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
    int n;
    long long a[100005]={},f[100005]={};
int main()
{
    cin >> n;
    cin >> a[1] >> a[2];
    f[1]=0;
    f[2]=abs(a[1]-a[2]);
    for (int i=3;i<=n;i++)
    {
        scanf("%d",&a[i]);
        f[i]=min(f[i-1]+abs(a[i]-a[i-1]),f[i-2]+abs(a[i]-a[i-2]));
    }
    cout << f[n] << endl;
}


Measured memory_bytes: 5192
def find(ary, k):
    lo = 0
    hi = len(ary)
    while lo < hi:
        mid = lo + ((hi - lo) // 2)
        if ary[mid] == k:
            return mid
        if ary[mid] < k:
            lo = mid + 1
        else:
            hi = mid


def main():
    input()
    ary = [int(x) for x in input().split(' ')]
    q = int(input())
    for i in range(q):
        k = int(input())
        if find(ary, k) is not None:
            print(1)
        else:
            print(0)


if __name__ == '__main__':
    main()



Measured memory_bytes: 17176
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
int32_t main()
{
   fastio

   int h,w;
   cin>>h>>w;
   char arr[h][w];
   rep(i,h)rep(j,w)cin>>arr[i][j];
   int left[h][w];
   int right[h][w];
   rep(i,h)rep(j,w)right[i][j]=1;
   int top[h][w];
   int bottom[h][w];
      rep(i,h)rep(j,w)left[i][j]=1;
         rep(i,h)rep(j,w)top[i][j]=1;
            rep(i,h)rep(j,w)bottom[i][j]=1;
   for(int i=0;i<h;i++)
   {
     for(int j=w-2;j>=0;j--)
     {
       if(arr[i][j]=='.' && arr[i][j+1]=='.')right[i][j]=right[i][j+1]+1;
     }
   }
   for(int i=0;i<h;i++)
   {
     for(int j=1;j<w;j++)
     {
       if(arr[i][j]=='.' && arr[i][j-1]=='.')left[i][j]=left[i][j-1]+1;
     }
   }
   for(int j=0;j<w;j++)
   {
     for(int i=h-2;i>=0;i--)
     {
       if(arr[i][j]=='.' && arr[i+1][j]=='.')top[i][j]=top[i+1][j]+1;
     }
   }
   for(int j=0;j<w;j++)
   {
     for(int i=1;i<h;i++)
     {
       if(arr[i][j]=='.' && arr[i-1][j]=='.')bottom[i][j]=bottom[i-1][j]+1;
     }
   }
   int ans=0;
   rep(i,h)
   {
     rep(j,w)
     {
       if(arr[i][j]=='#')continue;
       else
       {
         ans=max(ans,top[i][j]+bottom[i][j]+left[i][j]+right[i][j]-3);
       }
     }
   }
   cout<<ans<<endl;
   return 0;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	string s;
	cin >> s;
	int y = stoi(s.substr(0,4));
	int m = stoi(s.substr(5,2));
	//int d = stoi(s.substr(8,2));
	if(y < 2019){
		ANS("Heisei");
	}else if(y == 2019 && m <= 4){
		ANS("Heisei");
	}else{
		ANS("TBD");
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    cout << (N-1) / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

namespace {
	int cnt, m;
	vector<int> G;

	void InsertionSort(vector<int>& A, int n, int g)
	{
		for (int i = g; i < n; ++i)
		{
			int v = A[i];
			int j = i - g;

			while (j >= 0 && A[j] > v) {
				A[j + g] = A[j];
				j -= g;
				cnt++;
			}

			A[j + g] = v;
		}
	}

	void ShellSort(vector<int>& A, int n)
	{
		cnt = 0;
		for (int i = 0; i <= n; ++i)
		{
			int g = pow(2, i + 1) - 1; // 2^(k+1)-1, ..., 7, 3, 1(k >= 0)
			if (g <= n) G.push_back(g);
			else { m = i; reverse(G.begin(), G.end()); break; }
		}

		for (int i = 0; i < m; ++i)
			InsertionSort(A, n, G[i]);
	}
}

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

	vector<int> A(n, 0);
	for (int i = 0; i < n; ++i)
		cin >> A[i];

	ShellSort(A, n);

	cout << m << endl;
	for (int i = 0; i < m; ++i) {
		cout << G[i];
		i != m - 1 ? cout << " " : cout << endl;
	}
	cout << cnt << endl;
	for (int i = 0; i < n; ++i)
		cout << A[i] << endl;

	return 0;
}

Measured memory_bytes: 4896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7,N=2e5+5;
int n,k;
ll sum[N];
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        sum[i]=sum[i-1]+i;
    ll ans=0;
    while(k<=n+1)
    {
        ll l=sum[k-1];
        ll r=sum[n]-sum[n-k];
        ans=(ans+r-l+1)%mod;
        k++;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 5384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    int n;
    cin >> n;
    int ans = n / 2 - (n % 2 == 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> integers=new ArrayList<Integer>(N);
		for(int i=0;i<N;i++) {
			integers.add(Integer.parseInt(sc.next()));
		}
		Collections.sort(integers, Comparator.reverseOrder());
		
		int max=integers.get(0);
		int min=integers.get(integers.size()-1);
        integers.remove(0);
		integers.remove(integers.size()-1);		
		ArrayList<Integer> anser=new ArrayList<Integer>(2*N);
		
		for(int num:integers) {
			if(num>0) {
				anser.add(min);
				anser.add(num);
				min=min-num;
			}else {
				anser.add(max);
				anser.add(num);
				max=max-num;
			}
		}
		System.out.println(max-min);
		
		for(int i=0;i<N-2;i++) {
			System.out.println(anser.get(2*i)+" "+anser.get(2*i+1));
		}
		System.out.println(max+" "+min);
		sc.close();
	}
}


Measured memory_bytes: 73876
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local ior = io.input()
local n, m = ior:read("*n", "*n")
local k = {}
local p = {}
for i = 1, m do
  k[i] = {}
  local knum = ior:read("*n")
  for j = 1, knum do
    k[i][j] = ior:read("*n")
  end
end
for i = 1, m do p[i] = ior:read("*n") end
local allcnt = 2^n
local succeed = 0

local function check(comb)
  local stat = true
  for i_m = 1, m do
    local tmp = 0
    for i_k = 1, #k[i_m] do
      tmp = tmp + comb[k[i_m][i_k]]
    end
    if tmp % 2 ~= p[i_m] then
      return false
    end
  end
  return true
end

for ti = 0, allcnt - 1 do
  local comb = {}
  local i = ti
  for j = 1, n do
    comb[j] = i % 2
    i = mfl(i / 2)
  end
  if check(comb) then
    succeed = succeed + 1
  end
end
print(succeed)


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	ll n;
	cin >> n;
	ll ans = n*(n-1)/2;
	cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int A(int a, int b){
    return a * a + b * b;
}

int main(){
    int h, w;
    while(cin >> h >> w, h||w){
        vector<pair<pair<int,int>,int>> v;
        range(i,1,200){
            range(j,i + 1,200){
                v.emplace_back(make_pair(make_pair(i * i + j * j, i), j));
            }
        }
        sort(all(v));
        rep(i,v.size()){
            if(h * h + w * w == v[i].first.first && v[i].first.second > h){
                cout << v[i].first.second << ' ' << v[i].second << endl;
                break;
            }else if(h * h + w * w < v[i].first.first){
                cout << v[i].first.second << ' ' << v[i].second << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 3328
#include <iostream>
#include <stdio.h>
#include <set>
#include<bits/stdc++.h>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int x , y;
    cin>>x>>y;
    if((4*x-y)>=0 ){
        if((4*x-y)%2==0 ){
            if(x>=  (4*x-y)/2){
                cout<<"Yes";
            }
            else{
                cout<<"No";
            }
        }
        else{
            cout<<"No";
        }
    }
    else{
        cout<<"No";
    }
}


Measured memory_bytes: 3552
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l  
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |   
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) reverse((a).begin(),(a).end())
#define REP(i, n) for(int i = 0; i < n; i++)
const int MOD = 1e9+7;
typedef long long ll;

int main(){
  int n,k;
  cin>>n>>k;
  vector<int>x(n);
  int ans=900000000;
  for(int i=0;i<n;i++) cin>>x[i];

  for(int i=0;i<n-k+1;i++){
    if(x[i]<0 &&x[i+k-1]>0) ans=min((min(abs(x[i]),abs(x[i+k-1]))+abs(x[i])+abs(x[i+k-1])),ans);
    else if(x[i]>0) ans=min(abs(x[i+k-1]),ans);
    else ans=min(abs(x[i]),ans);
  }

  cout<<ans<<endl;
}


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


int main() {

    int a, b;
    cin >> a >> b;
    if ((a+b) % 3 == 0 || a % 3 == 0 || b % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}

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


long long gcd( long long x, long long y ){

          if( y == 0 ) return x;

          return gcd( y, x % y );

          }


long long f( long long x, long long y, long long z ){

          return x - x / y - x / z + x / ( y * z / gcd(y, z) );

          }


int main(){


    long long a, b, c, d, k;


    cin >> a >> b >> c >> d;


    k = f( b, c, d ) - f( a - 1, c, d );


    cout << k << endl;

    
    return 0;


    }


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

using D = double;
struct Point {D x, y;};
struct Circle {D x, y, r;};
struct Edge {int from, to; D weight;};
using Graph = vector<vector<Edge>>;

using Node = pair<D, int>;
const D INF = 1e10;

D distance(auto c1, auto c2) {
  auto d = hypot(c1.x-c2.x, c1.y-c2.y);
  auto r = c1.r + c2.r;
  return max(0.0, d - r);
}

int main() {
  Point S, T;
  cin >> S.x >> S.y >> T.x >> T.y;
  int N;
  cin >> N;
  vector<Circle> C(N);
  for(auto& c: C) cin >> c.x >> c.y >> c.r;

  Graph G(N+2);
  const auto B = N;
  const auto E = N+1;
  for(auto i=0; i<N; ++i) for(auto j=0; j<N; ++j) if(i != j) G[i].push_back({i, j, distance(C[i], C[j])});
  for(auto i=0; i<N; ++i) G[B].push_back({B, i, distance(Circle{S.x, S.y, 0.0}, C[i])});
  for(auto i=0; i<N; ++i) G[i].push_back({i, E, distance(C[i], Circle{T.x, T.y, 0.0})});
  G[B].push_back({B, E, distance(Circle{S.x, S.y, 0.0}, Circle{T.x, T.y, 0.0})});

  vector<D> d(N+2, INF);
  priority_queue<Node, vector<Node>, greater<Node>> q;
  q.emplace(0, B);
  while(!q.empty()) {
    auto w = q.top().first;
    auto v = q.top().second;
    q.pop();
    if(d[v] != INF) continue;
    d[v] = w;
    for(auto e: G[v]) if(w + e.weight < d[e.to]) q.emplace(w + e.weight, e.to);
  }
  cout << setprecision(8) << fixed << d[E] << endl;
}


Measured memory_bytes: 26616
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;


int main() {
	string s, t; cin >> s >> t;
	vector<vector<int>> v(26);//アルファベット
	for (int i = 0; i < s.size(); i++) {//どうせ昇順になってる
		v[s[i] - 'a'].emplace_back(i + 1);
	}
	for (int i = 0; i < 26; i++) {
		v[i].emplace_back(INF);
	}

	int tmp = 0;
	ll ans = 0;
	bool flag = true;
	for (int i = 0; i < t.size(); i++) {
		int check = *upper_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), tmp);
		if (check != INF) {
			ans += (check - tmp);
			tmp = check;
		}
		else {//check=INF
			ans += (((int)s.size()) - tmp);
			tmp = 0;
			int check = *upper_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), tmp);
			if (check == INF) {
				flag = false;
				break;
			}
			ans += (check - tmp);
			tmp = check;
		}
	}

	if (flag) {
		cout << ans << endl;
	}
	else{
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long h,n,c;
    while(scanf("%lld %lld",&h,&n)==2){
            long long a[n];
c=0;
        for(int i=0;i<n;i++){
            scanf("%lld",&a[i]);
        }
        while(1){
            for(int i=0;i<n;i++){
                h-=a[i];
            }
            if(h>0){
                c=1;
                break;
            }
            else{
                c=0;
                break;
            }
        }
        if(c==0) printf("Yes\n");
        else printf("No\n");
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, K;
    cin >> N >> K;

    cout << min(N % K, K - N % K) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int i, l, house;
	int nnum, bnum = 0, longest = 0;
	int first;

	scanf("%d", &l);
	scanf("%d", &house);
	for (i = 0; i < house; i++) {
		if (i == 0) {
			scanf("%d", &bnum);
			first = bnum;
		}
		else {
			scanf("%d", &nnum);
			if ((nnum - bnum) > longest)
				longest = nnum - bnum;
			bnum = nnum;
			if (i == house - 1) {
				if (longest < (l - bnum + first))
					longest = l - bnum + first;
			}
		}
	}

	printf("%d\n", l - longest);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int N;
	int K;
	int ans = 0;
	cin >> N >> K;
	rep(i, N) {
		int htmp;
		cin >> htmp;
		if (htmp >= K)
			ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
    long long int n,m,c,i,j,co=0,s;
    scanf("%lld %lld %lld",&n,&m,&c);
    long long int b[m],a[n][m];
    for(i=0;i<m;i++)
        scanf("%lld",&b[i]);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%lld",&a[i][j]);
        }
    }
    for(i=0;i<n;i++){
        s=c;
        for(j=0;j<m;j++)
            s=s+a[i][j]*b[j];
        if(s>0)
            co++;
    }
    printf("%lld",co);
    }


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

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define test int t; cin >> t; while(t--)
#define skip continue
#define stop break
#define sz(v) v.size()
#define endl '\n'
#define PI 3.1415926535897932384626433832795
#define EPS 1e-9
#define FR(i, a, b) for(int i = a; i <= b; i++)
#define gcd __gcd 
#define FR(i, l, r) for(int i = (l); i <= (r); i++)
#define debug(a) cout << #a << ": " << a << endl
#define debug1(a, l, r) FR(i, l, r) cout << a[i] << " "; cout << endl
	
	
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <pii> vii;
typedef vector <pll> vll;

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }


/*********** TEMPLATE ENDS HERE *************/

#define int long long

main()
{
	string s;
	cin >> s;
	int k;
	cin >> k;
	for(int i = 0; i < k; i++)
		if(s[i] != '1')
			return cout << s[i], 0;
	cout << 1;
}


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

int main() {
  char c;
  cin >> c;
  
  if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u'){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  cout << s.substr(0, k);
  if (s.size() > k) {
    cout << "...";
  }
  cout << endl;

  return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

string S[55];
ll x[4] = {0, 1, 0, -1};
ll y[4] = {1, 0, -1, 0};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    REP(i, H) {
        cin >> S[i];
    }

    bool exist = true;
    REP(i, H) {
        REP(j, W) {
            if (S[i][j] == '.')
                continue;
            bool e = false;
            REP(n, 4) {
                ll nx = i + x[n], ny = j + y[n];
                if (nx < 0 || nx >= H || ny < 0 || ny >= W)
                    continue;
                if (S[nx][ny] == '#')
                    e = true;
            }
            if (!e)
                exist = false;
        }
    }

    if (exist)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

int n;
int d[100010][3];

int memo[100010][7];

int dp(int i, int bit){
  if(i == n){
    return 0;
  }

  if(memo[i][bit] != -1) return memo[i][bit];

  int ans = 0;
  for(int j = 0;j < 3;j++){
    if((bit & (1 << j)) == 0){
      ans = max(ans, dp(i+1, 1 << j) + d[i][j]);
    }
  }

  return memo[i][bit] = ans;
}

int main(){
  cin >> n;

  for(int i = 0;i < n;i++){
    for(int j = 0;j < 3;j++){
      cin >> d[i][j];
    }
  }

  memset(memo, -1, sizeof(memo));

  cout << dp(0, 0) << endl;

  return 0;
}

Measured memory_bytes: 10368
R,G,B,N = map(int,input().split())
res = 0
for i in range(N//R + 1):
    for j in range(N//G + 1):
        if i*R + j*G > N: # はそもそもむり
            continue
        k = (N - R*i - G*j)
        if k % B != 0: # その倍数じゃないと無理
            continue
        res += 1
print(res)


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

const int MAX_N = 100000;
long long iTbl[ MAX_N + 5 ];

int main( int argc, char *argv[] )
{
int i;
int N;
long long K;
int a;
int b;
long long c;

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

	i = 0;
	c = K;
	while( c > 0 )
	{
		i++;
		c -= iTbl[ i ];
	}

	cout << i << endl;

	return 0;
}






Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,s=0;
  cin>>n;
    s=n%10;

  if((s==0)||(s==1)||(s==6)||(s==8))
    cout<<"pon";
    
   else if((s==2)||(s==4)||(s==5)||(s==7)||(s==9))
      cout<<"hon";
      else
        cout<<"bon";

}


Measured memory_bytes: 3636
def main():
    """"ここに今までのコード"""
 
n = int(input())
A = [int(a) for a in input().split()]
mod=10**9+7
 
ans=0
for i in range(60):
    l=sum([a%2 for a in A])
    ans=(ans+l*(n-l)*(2**i))%mod
    A=[a//2 for a in A]
    
 
#ans=xor[0]
#for j in range(60-1):
#    ans=((2*ans)+xor[j+1])%mod
print(int(ans)) 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 137152
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	int n,k;
	cin>>n>>k;
	ll a[n],ans=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n,greater<int>() );
	for(int i=0;i<k;i++){
		ans+=a[i];
	}
	cout << ans<<endl;
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

def tostring(p,j):
    p = str(p+1)
    j = str(j+1)
    return (6 - len(p))*"0" + p + (6-len(j)) *"0" + j


if __name__ == "__main__":
    N, M = map(int, input().split())

    py = [[] for _ in range(N)]

    dat = [tuple(map(int, input().split())) for _ in range(M)]

    for i in range(M):
        p,y = dat[i]
        py[p-1].append((y,i))
    
    for p in range(N):
        py[p] = sorted(py[p])
    
    answer = M * [None]

    for p in range(N):
        for j in range(len(py[p])):
            y,i = py[p][j]
            answer[i]= tostring(p,j)
    
    for a in answer:
        print(a)

        


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

int n, in[100001], out[100001], T, sz[100001];
vector<pair<int, int> > tr[100001];
ll s[400000], z[400000], an;

void pl(int v = 1, int p = 0){
	in[v] = T++;
	sz[v] = 1;
	f(i, 0, tr[v].size()){
		int u = tr[v][i].first;
		if (u == p)continue;
		pl(u, v);
		sz[v] += sz[u];
	}
	out[v] = T;
}

inline void sl(int id){
	if (z[id]){
		int a = id << 1, b = id << 1 | 1;
		s[a] += z[id];
		z[a] += z[id];
		s[b] += z[id];
		z[b] += z[id];
		z[id] = 0;
	}
}

void ad(int x, int y, ll c, int l = 0, int r = n, int id = 1){
	if (l >= y || r <= x)return;
	if (l >= x && r <= y) { s[id] += c, z[id] += c; return; }
	sl(id);
	int m = l + r >> 1, a = id << 1, b = id << 1 | 1;
	ad(x, y, c, l, m, a);
	ad(x, y, c, m, r, b);
	s[id] = max(s[a], s[b]);
}

ll gt(int i, int l = 0, int r = n, int id = 1){
	if (l + 1 == r)return s[id];
	int m = l + r >> 1, a = id << 1, b = id << 1 | 1;
	sl(id);
	if (i < m)return gt(i, l, m, a);
	return gt(i, m, r, b);
}

ll pw(int s, int sm, int c){
	int os = n - s;
	if (s > os)swap(s, os), sm = 2 - sm;
	if (sm == 1)return (ll)c * ((s << 1) - 1);
	if (sm == 2 || s == os)return (ll)c * (s - 1 << 1);
	return (ll)c * s << 1;
}

inline void adin(int v, ll c) { ad(in[v], out[v], c); }
inline void adout(int v, ll c) { ad(0, in[v], c), ad(out[v], n, c); }

void pl2(int v = 1, int p = 0){
	f(i, 0, tr[v].size()){
		int u = tr[v][i].first;
		if (u == p)continue;
		adin(u, pw(sz[u], 1, tr[v][i].second));
		adout(u, pw(sz[u], 0, tr[v][i].second));
		pl2(u, v);
	}
}

void fn(int v = 1, int p = 0){
	ll t = gt(in[v]);
	ad(in[v], in[v] + 1, -t);
	an = max(an, s[1]);
	ad(in[v], in[v] + 1, t);
	f(i, 0, tr[v].size()){
		int u = tr[v][i].first;
		if (u == p)continue;
		adin(u, pw(sz[u], 1, -tr[v][i].second));
		adout(u, pw(sz[u], 0, -tr[v][i].second));
		adin(u, pw(sz[u], 2, tr[v][i].second));
		adout(u, pw(sz[u], 1, tr[v][i].second));
		fn(u, v);
		adin(u, pw(sz[u], 1, tr[v][i].second));
		adout(u, pw(sz[u], 0, tr[v][i].second));
		adin(u, pw(sz[u], 2, -tr[v][i].second));
		adout(u, pw(sz[u], 1, -tr[v][i].second));
	}
}

int main(){
	scanf("%d", &n);
	f(i, 1, n){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		tr[a].push_back(make_pair(b, c));
		tr[b].push_back(make_pair(a, c));
	}
	pl();
	pl2();
	fn();
	printf("%lld\n", an);
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}


/*{
}*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

//constexpr int mod = 1e9+7;
constexpr int inf = 1LL<<60;


int dp[50][500][500];

signed main() {
  int n, ma, mb;
  cin >> n >> ma >> mb;

  vi a(n), b(n), c(n);
  rep(i, 0, n) { cin >> a[i] >> b[i] >> c[i]; }

  rep(i, 0, 50) rep(j, 0, 500) rep(k, 0, 500) dp[i][j][k] = inf;
  dp[0][0][0] = 0;
  rep(i, 0, n){
    rep(j, 0, 500) rep(k, 0, 500){
      chmin(dp[i+1][j][k], dp[i][j][k]);
      chmin(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
    }
  }

  int ans = inf;
  for(int i = 1; ma*i < 500 and mb*i < 500; i++){
    chmin(ans, dp[n][ma*i][mb*i]);
  }

  if(ans == inf) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}



Measured memory_bytes: 97920
import java.util.Scanner;
public class Main{
	static int[]heap;
    static int MAXHEAP=5000;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int i,n;
		heap=new int[MAXHEAP+1];
       Scanner sca= new Scanner(System.in);
       n=sca.nextInt();
       for(i=1;i<=n;i++){
    	   heap[i]=sca.nextInt();
    	   heap[i*2]=heap[i*2+1]=-1;
       }
       for(i=1;i<=n;i++){
    	   System.out.print("node "+i+": key = "+heap[i]+", ");
    	   if(i/2>0)System.out.print("parent key = "+heap[i/2]+", ");
    	   if(i*2<=n){
    		   System.out.print("left key = "+heap[i*2]+", ");
    	   }
       	   if(i*2+1<=n){
    		   System.out.print("right key = "+heap[i*2+1]+", ");
    	   }   
       	 System.out.println("");  
       }
	}

}



Measured memory_bytes: 27232
n = int(input())
A = list(map(int, input().split()))
A.sort()
eo = False #False = even
suma = sum(A)
lta = 10**10
for j in range(n):
    i = A[j]
    if i <= 0: #0以下
        if j == n - 1 and not eo: break
        eo ^= True
        lta = i
        suma += 2*(-i)
        #print(i,"を+にした")
    else: #0以上なら
        if lta == 10**10: break
        if eo: #奇数回変更歴なら
            if abs(i) > abs(lta):
                suma += lta*2
            else:
                suma += 2*(-i)
         #   print("oddかつ",abs(i),">",abs(lta),"だったので元に戻した")
        break
print(suma)

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

int main() {
	int x,a,b,v1,v2;
	cin>>x>>a>>b;
	v1 = abs(x-a);
	v2 = abs(x-b);
	if(v1<v2){
	    cout<<"A";
	}else{
	    cout<<"B";
	}
	return 0;
}


Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <sstream>
#include <regex>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<int> v(n), t(n);
	rep(i, n)
	{
		int x, y; cin >> x >> y;
		v[i] = x + y;
		t[i] = x - y;
	}
	sort(all(v));
	sort(all(t));
	int res = max(v.back() - v[0], t.back() - t[0]);
	cout << res << endl;
}

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

int main() {
    uint64_t H;
    std::cin >> H;
    
    uint64_t out = 0, cnt = 0, i = 1;
    while (H > 1) {
        H /= 2;
        ++cnt;
        out += i;
        i *= 2;
    }

    out += std::pow(2, cnt);

    std::cout << out << std::endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import time
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, Q = MAP()
S = input().rstrip()
LR = [MAP() for _ in range(Q)]

loc = [0]*N
for i in range(N-1):
	if S[i]+S[i+1] == 'AC':
		loc[i+1] += loc[i]+1
	else:
		loc[i+1] = loc[i]
#print(loc)

for l, r in LR:
	print(loc[r-1]-loc[l-1])

Measured memory_bytes: 64728
R, G, B, N = map(int, input().strip().split(' '))
B, G, R = sorted([R, G, B])


ans = 0
for r in range(int(N/R)+1):
    rest = N - r * R
    for g in range(int(rest/G)+1):
        if (rest - g*G) % B == 0:
            #print(r, g, (rest-g*G)/B)
            ans += 1
print(ans)


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

int main(){
	long long P = 100, step = 0;
	long long X;
	cin >> X;

	while (P < X){
		P += P / 100;
		step++;
	}
	cout << step << endl;
	return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;

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

//pow(llpow,modpow)
template <class T>
ll llpow(ll x, T n)
{
    ll ans = 1;
    if (x == 0)
        ans = 0;
    while (n)
    {
        if (n & 1)
            ans *= x;
        x *= x;
        n >>= 1;
    }
    return ans;
}
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
template <class T>
inline T gcd(T x, T y)
{
    if (y == 0)
        return x;
    else
    {
        return gcd(y, x % y);
    }
}
//最小公倍数
template <class T>
inline T lcm(T x, T y) { return x / gcd(x, y) * y; }
//逆元
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i - 1; i >= (ll)end_i; i--)

long long INF = 1LL << 60;
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    ll mod = 1e9 + 7;
    //dp[桁][余り]
    vvll dp(n + 1, vll(13, 0));
    dp[0][0] = 1;
    rep(i, 0, n)
    {
        if (s[i] != '?')
        {
            int d = s[i] - '0';
            rep(ld, 0, 13)
            {
                ll to = (ld * 10 + d) % 13;
                dp[i + 1][to] += dp[i][ld];
                dp[i+1][to]=((dp[i+1][to]%mod)+mod)%mod;
            }
        }
        else{
            rep(now,0,10){
                rep(ld,0,13){
                    ll to=(ld*10+now)%13;
                    dp[i+1][to]+=dp[i][ld];
                    dp[i+1][to]=((dp[i+1][to]%mod)+mod)%mod;
                }
            }
        }
    }
    cout<<dp[n][5]<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n;
  cin >> n;
  vector<string> v(n);
  REP(i, n) cin >> v[i];

  map<string, int> mp;
  mp[v[0]] = 1;
  FOR(i, 1, n) {
    if(mp.find(v[i]) != mp.end()) {
      cout << "No" << endl;
      return 0;
    }
    if(v[i][0] != v[i-1].back()) {
      cout << "No" << endl;
      return 0;
    }
    mp[v[i]] = 1;
  }

  cout << "Yes" << endl;
 
  return 0;
}


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

int main() {
  int a;
  int b;
  int c;
  int ans;
  cin >> a >> b >> c;

  ans=b/a;

  if(ans>=c){
    ans=c;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=200005;
int n,a[M],dp[M];

int main(){
	fill(a,a+M,-1);
	cin>>n;
	dp[0]++;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(a[x]>=0&&a[x]!=i) dp[i+1]=dp[a[x]];
		a[x]=i+1;
		(dp[i+1]+=dp[i])%=mod;
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  private void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int heapSize = Integer.parseInt(br.readLine());
      String[] keys = br.readLine().split(" ");
      int[] mHeap = new int[heapSize+1];
      mHeap[0] = heapSize;
      for(int i=1; i<=heapSize; i++)
        mHeap[i] = Integer.parseInt( keys[i-1] );

      buildMaxHeap(mHeap);

      StringBuilder buf = new StringBuilder();
      for(int i=1; i<mHeap.length; i++) 
        buf.append(" ").append(mHeap[i]);

      System.out.println(buf);
    } catch(IOException e) {
      System.out.println("IOException!");
    }
  }
  private void buildMaxHeap(int[] heap) {
    for(int i= heap[0]/2; i>0; i--)
      maxHeapify(heap, i);
  }
  private void maxHeapify(int[] heap, int node) {
    int t,left,right,largest;
    left  = node*2;
    right = left+1;

    if( (left <= heap[0]) && (heap[left] > heap[node]) )
      largest = left;
    else
      largest = node;
    if( (right <= heap[0]) && (heap[right] > heap[largest]) )
      largest = right;

    if( largest != node ) {
      t = heap[node]; heap[node] = heap[largest]; heap[largest] = t;

      maxHeapify(heap, largest);
    }
  }
}


Measured memory_bytes: 75052
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
    
    
	public static void main (String[] args) throws java.lang.Exception
	{
			Scanner s = new Scanner(System.in);
			int n = s.nextInt();
			int k = s.nextInt();
			int ctr = 0;
			for(int i=0;i<n;i++) {
				int c = s.nextInt();
				if(c>=k)
					ctr++;
			}
			System.out.println(ctr);
	}
}

Measured memory_bytes: 46716