akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
const ll N=20+5;
string a[N];
bool vis[N][N];
ll dist[N][N];
ll n,m;

/*----------------------Graph Moves----------------*/
const ll fx[]={+1,-1,+0,+0};
const ll fy[]={+0,+0,+1,-1};

bool chk(ll x,ll y)
{
	if(x<0 || y<0 || x>=n || y>=m || a[x][y]=='#')
		return false;
	return true;
}

ll bfs(ll x,ll y)
{
	if(!chk(x,y))
		return 0;
	ll ans=0;	
	memset(vis,false,sizeof(vis));
	memset(dist,false,sizeof(dist));	
	queue<pll>q;
	q.push({x,y});
	vis[x][y]=true;
	dist[x][y]=0;
	while(!q.empty())
	{
		pll top=q.front();
		q.pop();
		for(ll i=0;i<4;i++)
		{
			ll tx=top.first+fx[i];
			ll ty=top.second+fy[i];
			if(chk(tx,ty) && !vis[tx][ty])
			{
			    vis[tx][ty]=true;
				q.push({tx,ty});
				dist[tx][ty]=dist[top.first][top.second]+1;
				ans=max(ans,dist[tx][ty]);
			}
		}
	}
	return ans;
}


int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	cin>>n>>m;
 	for(ll i=0;i<n;i++)
 	{
 		cin>>a[i];
 	}
 	ll ans=0;
 	for(ll i=0;i<n;i++)
 	{
 		for(ll j=0;j<m;j++)
 		{	
 			ans=max(ans,bfs(i,j));
 		}
 	}
 	cout<<ans<<endl;
    return 0;
}

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

int gcd(int x, int y){return y ? gcd(y, x%y) : x;}

int main(){
  int n, x; cin >> n >> x;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
    v[i] = abs(v[i] - x);
  }
  
  int ans = v[0];
  for(int i=0;i<n-1;i++) ans = gcd(ans, v[i+1]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0;
    int tmp;
    for(int j=0;j<n;j++){
        tmp = a[j];
        while(1){
            if(tmp%2==0){
                tmp = tmp/2;
                ans++;
            }
            else{
                break;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
# coding=utf-8

def counting_sort(A, B, k):
    C = [0 for i in range(k+1)]

    for a in A:
        C[a] += 1

    for i in range(1, k+1):
        C[i] = C[i] + C[i-1]

    for a in A[::-1]:
        B[C[a]-1] = a
        C[a] -= 1

    return B


n = int(input())
A = list(map(int, input().split()))
k = max(A)
B = [0 for x in range(n)]

B = counting_sort(A, B, k)
print(*B)

Measured memory_bytes: 233904
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define int long long

int p[10];

signed main(){
    int m;
    string c;
    cin >> m >> c;
    int s = 1;
    if(c.size()==1&&m==0){
        cout << 0 << endl;
        return 0;
    }
    reverse(c.begin(),c.end());
    int n = c.size();
    int k = 0;
    rep(i,n){
        p[c[i]-'0'] +=s;
        p[c[i]-'0'] %= mod;
        s *=10;
        s %= mod;
        k = c[i]-'0';
    }
    vector<int> v(10);
    rep(i,10){
        v[i] = i;
    }
    string t;
    bool ok = 0;
    do{
        int sm = 0;
        rep(i,10){
            sm += p[i] * v[i];
            sm%= mod;
        }
        if(sm==m&&v[k]!=0){
            rep(i,n){
                t.push_back(v[c[i]-'0']+'0');
            } 
            ok = true;
            break;
        }  
    }while(next_permutation(v.begin(),v.end()));
    if(ok){
        reverse(t.begin(),t.end());
        cout << t << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


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

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

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

  if (A.size() == 2) {
    cout << max(A.at(0), A.at(1)) << endl;
  } else {
    ll a = A.at(0);
    ll b = A.at(1);
    ll c = A.at(2);
    ll gcd_max = 0;
    ll gcd_all = gcd(a, b);
    if (gcd(a, c) > gcd(b, c)) {
      gcd_max = gcd(a, c);
    } else {
      gcd_max = gcd(b, c);
    }
    for (int i = 2; i < N; i++) {
      ll c = A.at(i);
      gcd_max = gcd(gcd_max, c) > gcd_all ? gcd(gcd_max, c) : gcd_all;
      gcd_all = gcd(gcd_all, c);
    }
    cout << gcd_max << endl;
  }
}


Measured memory_bytes: 1024
def bubble_sort(array):
    flag = True
    while flag:
        flag = False
        for i in range(N-1, 0, -1):
            if array[i] < array[i-1]:
                array[i], array[i-1] = array[i-1], array[i]
                flag = True

def merge_count(array):
    if len(array) <= 1:
        return array, 0
    mid = len(array) // 2
    left, cl = merge_count(array[:mid])
    right, cr = merge_count(array[mid:])
    count = cl + cr
    left = list(reversed(left))
    right = list(reversed(right))
    for i in range(len(array)):
        if not left:
            array[i] = right.pop()
        elif not right:
            array[i] = left.pop()
        elif left[-1] <= right[-1]:
            array[i] = left.pop()
        else:
            array[i] = right.pop()
            count += len(left)
    return array, count

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    a, b = merge_count(A)
    print(*a)
    print(b)

Measured memory_bytes: 7784
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] limit = new int[n];
		for (int i=0;i<n;i++) {
			limit[i] = sc.nextInt();
		}
		int[] apples = new int[n];
		int q = sc.nextInt();
		boolean breakFlag = false;
		for (int i=0;i<q;i++) {
			int t = sc.nextInt();
			int x = sc.nextInt() - 1;
			int d = sc.nextInt();
			if (t == 1) {
				apples[x] += d;
				if (apples[x] > limit[x]) {
					System.out.println(x + 1);
					breakFlag = true;
					break;
				}
			} else {
				apples[x] -= d;
				if (apples[x] < 0) {
					System.out.println(x + 1);
					breakFlag = true;
					break;
				}
			}
		}
		if (!breakFlag) System.out.println(0);
	}
}


Measured memory_bytes: 99656
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: usize,
        p: usize,
    }
    println!("{}", (a * 3 + p) / 2);
}


Measured memory_bytes: 4352
s = input()
n = len(s) - 1

a = 0
for x in  range(2**n):
  ans = s[0]
  for y in range(n):
    if (x>>y)&1:
      ans = ans + "+" + s[y+1]
    else:
      ans = ans + s[y+1]
  a += eval(ans)
print(a)

Measured memory_bytes: 3060
import math
from functools import reduce
K = int(input())

def gcd(*numbers):
  return reduce(math.gcd, numbers)

ans = 0
for a in range(1,K+1):
  if (a==1):
    ans += K*K
    continue
  for b in range(1,K+1):
    t = gcd(a,b)
    if(t==1):
      ans += K
      continue
    for c in range(1,K+1):
      ans += gcd(t,c)
print(ans)

Measured memory_bytes: 9572
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull t;cin>>t;while(t--)
#define pll pair<ll,ll>
#define puu pair<ull,ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vll vector<ll>
#define Vull vector<ull>
#define nl cout<<endl
#define sp cout<<" "
#define MOD 1000000007
#define all(x) x.begin(),x.end()
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};


int main() 
{
	// ios::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	
	ll n;
	cin>>n;
	vector<vector<int>> v(n,vector<int>(3,0));
	ll dp[n+1][3];
	memset(dp,0,sizeof(dp));
	loop(i,0,n){
		cin>>v[i][0]>>v[i][1]>>v[i][2];
	}	

	loop(i,1,n+1){
		dp[i][0] = v[i-1][0] + max(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = v[i-1][1] + max(dp[i-1][0],dp[i-1][2]);
		dp[i][2] = v[i-1][2] + max(dp[i-1][1],dp[i-1][0]);

	}

	ll ans = 0;

	loop(i,0,3)
		ans = max(ans,dp[n][i]);

	cout<<ans;

}

Measured memory_bytes: 11004
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
double zettai(double a) {
  if(a < 0) {
    return -a;
  }else {
    return a;
  }
}
int main () {
  int N;
  bool half = true;
  cin >> N;
  vector<int>a(N);
  int k = 0;
  for(int i = 0; i < N; i ++) {
    cin >> a[i];
    k += a[i];
  }
  double ave = static_cast<double>(k) / N;
  vector<double>b(N);
  vector<double>c(N);
  for (int i = 0; i < N; i ++) {
    b[i] = c[i] = zettai(a[i] - ave);
  }
  sort (b.begin(),b.end());
  bool ans = false;
  for (int i = 0; i < N; i ++) {
    if(c[i] == b[0]) {
      cout << i << endl;
      ans = true;
    }
    if(ans) break;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n;
struct edge{/*重み付き,有向*/
    int to , cost;/*toは接続先*/
    edge(ll to_ ,ll cost_ = 1){ to=to_; cost=cost_; };/*全てのcost=1 <=> 無向グラフ*/
};
bool operator<(edge e1 ,edge e2){return e1.cost < e2.cost; }
bool operator>(edge e1 ,edge e2){return e1.cost > e2.cost; }
using graph =  vector< vector<edge> >;
graph g;


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n; g.resize(n+1);
    ll ina,inb;
    rep(i,n-1){
        cin>>ina>>inb;
        g[ina].pb(edge(inb));
        g[inb].pb(edge(ina));
    }
    Vi ck(n+1,-1);
    queue<ll> f,s;
    ck[1] = 1; ck[n]=0;
    f.push(1); s.push(n);
    while( (!f.empty()) || (!s.empty() ) ){
        ll tpf = f.size();
        ll tps = s.size();
        rep(i,tpf){
            rep(j,g[f.front()].size()){
                if(ck[g[f.front()][j].to]==-1){
                    ck[g[f.front()][j].to] = 1;
                    f.push(g[f.front()][j].to);
                }
            }
            f.pop();
        }
        rep(i,tps){
            rep(j,g[s.front()].size()){
                if(ck[g[s.front()][j].to] == -1){
                    ck[g[s.front()][j].to] = 0;
                    s.push(g[s.front()][j].to);
                }
            }
            s.pop();
        }
    }
    ll sk=0,fn=0;
    rep(i,ck.size()){
        if(ck[i]==0){
            sk++;
        }else if(ck[i]==1){
            fn++;
        }
    }
    if(sk>=fn){
        print("Snuke");
    }else{
        print("Fennec");
    }
    // rep(i,ck.size()){
    //     princ(ck[i]);
    // }
    // print("");
    return 0;
}

Measured memory_bytes: 7168
#from fractions import gcd
from collections import Counter
mod = 10**9+7
def inv(a):
  return pow(a,mod-2,mod)
def prm(a):
  if a == 1 or a == 4:
    return False
  for i in range(2,int((a)**0.5+1)):
    if a%i == 0:
      return False
  else:
    return True
prime = []
for i in range(1,10**4+1):
  if prm(i):
    prime.append(i)
def sepa(a):
  ans = []
  while a>1:
    for x in prime:
      if a%x == 0:
        ans.append(x)
        a = a//x
        break
      elif x == prime[-1]:
        ans.append(a)
        a = 1
  return Counter(ans)
n = int(input())
a = list(map(int,input().split()))
f = [inv(a[i]) for i in range(n)]
lcm = sepa(1)
for i in range(n):
  x = sepa(a[i])
  for y,z in x.items():
    if z>lcm[y]:
      lcm[y] = z
k = 1
for i,j in lcm.items():
  k = k*(i**j)%mod
print(k*sum(f)%mod)

Measured memory_bytes: 52828
//
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


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

    int n;
    cin>>n;
    vector<ll> d(n+10);
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j=j+i){
            d[j]+=1;
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=i*d[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 81340
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        System.out.println((int)Math.pow(2, m) * (1900 * m + 100 * (n - m)));
    }
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

/*
    Expr = Term {'+'|'-' Term}*
    Term = Fact {'*'|'/' Fact}*
    Fact = Number | '(' Expr ')'
*/

int Fact(int*, std::string);
int Term(int*, std::string);
int Expr(int*, std::string);

int Fact(int* pos, std::string s) {
    int res = 0;
    if(s[*pos] == '(') {
        *pos += 1;
        res = Expr(pos, s);
        *pos += 1;
    } else {
        while(*pos < s.length() && s[*pos] >= '0' && s[*pos] <= '9') {
            res *= 10;
            res += (int)(s[*pos] - '0');
            *pos += 1;
        }
    }
    return res;
}

int Term(int* pos, std::string s) {
    int fact = Fact(pos, s);
    if(*pos >= s.length()) return fact;
    while( *pos < s.length() && (s[*pos] == '*' || s[*pos] == '/') ) {
        char op = s[*pos];
        *pos += 1;

        int nfact = Fact(pos, s);
        if(op == '*') {
            fact *= nfact;
        } else {
            fact /= nfact;
        }
    }
    return fact;
}

int Expr(int* pos, std::string s) {
    int term = Term(pos, s);
    if(*pos >= s.length()) return term;
    while( *pos < s.length() && (s[*pos] == '+' || s[*pos] == '-') ) {
        char op = s[*pos];
        *pos += 1;

        int nterm = Term(pos, s);
        if(op == '+') {
            term += nterm;
        } else {
            term -= nterm;
        }
    }
    return term;
}

int main() {
    int N;
    std::string str;
    std::cin >> N;
    REP(i, N) {
        int pos = 0;
        std::cin >> str;
        std::cout << Expr(&pos, str) << std::endl;
    }
}

Measured memory_bytes: 3136
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int A[200000];
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }
 
    long ans = 0;
 
    //i について全探索する
    for (int i = 0; i < N; i++)
    {
        //A[i+1] ... A[N] の値を更新する
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans += A[i] * sum;
        ans %= mod;
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 4404
N = int(input())
tree = [[] for _ in range(N)]

for i in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))

Q, K = map(int, input().split())
K -= 1

depth = [0 for _ in range(N)]

def dfs(v, p = -1, d = 0):
    St = []
    St.append([v, p, d])
    # 空のシーケンスは偽になる
    while St:
        cur = St.pop()
        depth[cur[0]] = cur[2]
        for i, j in tree[cur[0]]:
            if i == cur[1]:
                continue
            St.append([i, cur[0], cur[2] + j])

dfs(K)

for i in range(Q):
    x, y = map(int, input().split())
    x -= 1; y -= 1
    print (depth[x] + depth[y])


Measured memory_bytes: 48852
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

typedef long long int ll;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define int long long int
constexpr ll INF = 1001001001001001LL;

// Sparse Table 構築 O(N log N), クエリ O(1)
// 配列で init することでテーブルを構築し、
// [l, r) のクエリに O(1) でこたえられる
// Verified: Codeforces #361 Div.2 D: Friends and Subsequences

constexpr int SIZE = 200010;
constexpr int LOGS = 20;

template <typename T>
struct SparseTable_min {
    T a[SIZE];
    int table[SIZE][LOGS], log_table[SIZE];
    int n;
    void init(vector<T> p) {
        n = (int)p.size();
        for(int i=0; i<n; i++) {
            a[i] = p[i];
            table[i][0] = i;
        }
        for(int i=2; i<=n; i++) {
            log_table[i] = log_table[i>>1] + 1;
        }

        for(int k=1; (1<<k)<=n; k++) {
            for(int i=0; i+(1<<(k-1))<=n; i++) {
                int x = table[i           ][k-1];
                int y = table[i+(1<<(k-1))][k-1];
                if(a[x] <= a[y]) table[i][k] = x;
                else table[i][k] = y;
            }
        }
    }

    // 半開区間 [l, r) における最大値のインデックスを返す
    int query(int l, int r) {
        int d = log_table[r - l];
        int x = table[l       ][d];
        int y = table[r-(1<<d)][d];
        if(a[x] <= a[y]) return x;
        else return y;
    }
};

SparseTable_min<int> sp;

signed main() {
    int N; cin >> N;
    vector<int> v(N);
    rep(i,0,N) cin >> v[i];
    sp.init(v);

    int ans = 0;
    rep(i,0,N) {
        int vl, vr;
        int lb = -1, ub = i;
        while(ub - lb > 1) {
            int mid = (ub + lb) / 2;
            if(v[sp.query(mid, i)] < v[i]) lb = mid;
            else ub = mid;
        }

        vl = i - lb;

        lb = i, ub = N;
        while(ub - lb > 1) {
            int mid = (ub + lb) / 2;
            if(v[sp.query(i, mid+1)] < v[i]) ub = mid;
            else lb = mid;
        }

        vr = ub - i;
        // printf("vl = %lld, vr = %lld\n", vl, vr);

        ans += (vl * vr * v[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 37760
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iterator>
#include <math.h>
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define dd double
#define mp make_pair
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // int T,p;
    // cin>>T;
    // for(p=1;p<=T;p++)
    // {
        ll N;
        cin>>N;
        ll A[N],i,j,k,a,b,c,count=0;
        for(i=0;i<N;i++)
        {
          cin>>A[i];
          if(i>=1)
          {
            if(A[i]<A[i-1])
            {
              count+=A[i-1]-A[i];
              A[i]=A[i-1];
            }
          }
        }
        cout<<count;
        return 0;
}

Measured memory_bytes: 5200
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class d{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        char[] str = Console.ReadLine().ToCharArray();
        int left=0, right=n-1;
        int ans = 0;
        search(ref left, ref right, n, str);
        while(left < right){
            Swap(ref str[left], ref str[right]);
            ans++;
            search(ref left, ref right, n, str);
        }
        Console.WriteLine(ans);
    }
    public static void search(ref int left, ref int right, int n, char[] arr){
        for(;left < n; left++){
            if(arr[left] == 'W'){
                break;
            }
        }
        for(; right >= 0; right--){
            if(arr[right] == 'R'){
                break;
            }
        }
    }
    public static void Swap<T>(ref T a, ref T b){
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 17988
n=int(input())
s=[list(input()) for i in range(3)]
p=list(s[0])
for j in range(n):
  if s[1][j]==s[2][j]:
    p[j]=s[1][j]
c=0
for k in range(n):
  if p[k]!=s[0][k]:
    c+=1
  if p[k]!=s[1][k]:
    c+=1
  if p[k]!=s[2][k]:
    c+=1
print(c)    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define bs ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
int main()
{
	bs;
	int n,x,t;
	cin >> n >> x >> t;
	cout << ((n + x - 1)/x)*t;	
}

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

int main(){
  int D,T;
  double S;
  cin>>D>>T>>S;
  double t;
 t=D/S;//double同士の演算なら小数点以下の結果も出る
  if(t<=T)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3672
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(int argc, char const *argv[])
{
    map<char, long long> scount;
    int n;
    string s;
    cin >> n;

    scount['M'] = 0;
    scount['A'] = 0;
    scount['R'] = 0;
    scount['C'] = 0;
    scount['H'] = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        scount[s[0]] += 1;
    }
    cout << scount['M'] * scount['A'] * scount['R'] +
                scount['M'] * scount['A'] * scount['C'] +
                scount['M'] * scount['A'] * scount['H'] +
                scount['M'] * scount['R'] * scount['C'] +
                scount['M'] * scount['R'] * scount['H'] +
                scount['M'] * scount['C'] * scount['H'] +
                scount['A'] * scount['R'] * scount['C'] +
                scount['A'] * scount['R'] * scount['H'] +
                scount['A'] * scount['C'] * scount['H'] +
                scount['R'] * scount['C'] * scount['H'];

    return 0;
}


Measured memory_bytes: 256
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    ans = 0
    l = 0
    sm = 0
    for i,ai in enumerate(a):
        while sm&ai != 0:
            sm -= a[l]
            l += 1
        ans += (i-l+1)
        sm += ai

    print(ans)


    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 99276
#include <iostream>
#include <string>
using namespace std;
int main() {

	int a, b = 1, c = 0, d = 2, n = 3, m;
	string str;
	cin >> a;

	if (a - 111 == 0) {
		cout << 3 << endl;
	}
	if (a - 110 == 0) {
		cout << 2 << endl;
	}
	if (a - 101 == 0) {
		cout << 2 << endl;
	}
	if (a - 100 == 0) {
		cout << 1 << endl;
	}
	if (a - 11 == 0) {
		cout << 2 << endl;
	}
	if (a - 10 == 0) {
		cout << 1 << endl;
	}
	if (a - 1 == 0) {
		cout << 1 << endl;
	}
	if (a - 0== 0) {
		cout << 0 << endl;
	}

	cin >> a;



	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>

using namespace std;

void Solution()
{
    char op;
    
    int a, b;
    int c;
    
    while(cin>>a>>op>>b)
    {
        if (op == '+' )
        {
            c = a + b;
        }
        else if (op == '-')
        {
            c = a - b;
        }
        else if (op == '*')
        {
            c = a * b;
        }
        else if (op == '?')
        {
            break;
        }
        else
        {
            c = a / b;
        }
        
        cout<<c<<endl;
    }
}

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

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

int main(){
  int n, ans;
  float d;
  cin >> d >> n;
  
  if(d==0 && n!=100){
    ans = n;
  }else if(d==0 && n==100){
    ans = 101;
  }else if(d!=0 && n!=100){
    ans = (int)(pow(100, d)) * n;  
 }else{
   ans = (int)(pow(100, d))*(n+1);
 }
  cout << ans << '\n';

  return 0;

}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  // 重ならない場合
  if (B <= C || D <= A) {
    cout << 0 << endl;
    return 0;
  }
  cout << min(B, D) - max(A, C) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long int ll;
typedef vector<pair<ll,ll> > vpl;
typedef vector<pair<int,int> > vpi;
typedef vector<ll> vec;
typedef map<ll,ll> mp;
ll GCD(ll a,ll b)
{
    if(a == 0)
    {
        return b;
    }
    return GCD(b%a,a);
}
int main()
{
    FastIO;
    int q = 1;
    //cin >> q;
    while(q--)
    {
        int n,d;
        cin >> n >> d;
        ll ara[n][2];
        for(int i =0;i<n;i++)
        {
            cin >> ara[i][0] >> ara[i][1];
        }
        int c = 0;
        for(int i =0;i<n;i++)
        {
            double x = sqrt((ara[i][0]*ara[i][0])+(ara[i][1]*ara[i][1]));
//            cout << x << endl;
            if(x <= d)
            {
                c++;
            }
        }
        cout << c << endl;
    }
}




Measured memory_bytes: 6716
#include <stdio.h>
#include <string.h>

int main(void) {
	static const char* youbis[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	char S[128];
	int i;
	if (scanf("%127s", S) != 1) return 1;
	for (i = 0; i < 7; i++) {
		if (strcmp(S, youbis[i]) == 0) {
			printf("%d\n", 7 - i);
			return 0;
		}
	}
	puts("ERROR!");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define range(i) (i).begin(),(i).end()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans*(b&1?a:1);
}
inline constexpr int modpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll LINF=0x1fffffffffffffff;

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,0,n) cin>>a[i];
    cout<<*max_element(range(a))-*min_element(range(a));
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as U

readIntPair :: BS.ByteString -> (Int, Int)
readIntPair s = let Just (a, s') = BS.readInt s
                    Just (b, _) = BS.readInt $ BS.dropWhile isSpace s'
                in (a, b)

main = do
  (n,m) <- readIntPair <$> BS.getLine
  (ls,rs) <- fmap U.unzip $ U.replicateM m (readIntPair <$> BS.getLine)
  let maxL = U.maximum ls
      minR = U.minimum rs
  print $ max 0 (minR - maxL + 1)


Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a / gcd(a, b) * b;
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

/*   *   *   *   *   *   *   *   *   *   *   */

void solve() {
    ll n; cin >> n;
    ll h[100100];
    Rep(i, 1 ,n) cin >> h[i];

    //dp[i] : iにたどり着くまでに支払うコストの総和の最小値
    ll dp[100100];
    dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);
    Rep(i, 3, n){
        dp[i] = 
        min(dp[i-2]+abs(h[i]-h[i-2]), 
        dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout << dp[n] << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
int a,b,c,d,i,m,n,o,p;
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d),m=(a+b)/(a<b?a+1:b+1),b-=a/m;
		if((long long)(a%m)*m<b)
		{
			b-=(a%m)*m,o=a/m*m;
			if(m!=1)
			{
				o-=(b-1)/((long long)m*m-1)*m,b-=(b-1)/((long long)m*m-1)*((long long)m*m-1);
				if(!o||b<=m-1)p=b;
				else o--,b-=m-1,o-=(b-1)/m,p=b-(b-1)/m*m;
			}
			else o=0,p=b;
		}
		else o=a-(b-1)/m,p=b-(b-1)/m*m;
		for(i=c;i<=d;i++)
		if(i<=o+o/m)putchar(i%(m+1)?65:66);
		else if(i<=o+o/m+p)putchar(66);
		else putchar((i-o-o/m-p-1)%(m+1)?66:65);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
use std::cmp;

fn main(){
  loop {
    let n: usize = read();
    if n == 0 { break; }

    let mut mt: Vec<Vec<usize>> = Vec::new();
    
    for _ in 0 .. n {
      mt.push(read_vec());
    }
    
    let m: usize = read();
    
    for _ in 0 .. m {
      mt.push(read_vec());
    }
    
    mt.sort();

    let mut dp: Vec<usize> = vec![1;n+m];

    for i in 1 .. n+m {
      for j in 0 .. i {
        if mt[i][1] > mt[j][1] && mt[i][0] > mt[j][0] {
          dp[i] = cmp::max(dp[i], dp[j]+1);
        }
      }
    }
    
    println!("{}", dp.iter().max().unwrap());
  }
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



Measured memory_bytes: 5044
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long A = sc.nextLong();
    long B = sc.nextLong();
    
    long C = A+B;
    long ansA = A*(N/C);
    long ansB = Math.min(N%C, A); 
    System.out.println(ansA + ansB);
  }
}

Measured memory_bytes: 22868
#include <stdio.h>

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  printf("%ld", a[n-1]);
  for (long i = n-3; i >= 0; i -= 2) {
    printf(" %ld", a[i]);
  }
  for (long i = 0; i < n; i += 2) {
    if ((n-1-i)%2 == 0) {
      i++;
      if (i >= n) {
        break;
      }
    }
    printf(" %ld", a[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(true){
			int sum = 0;
			String num = scan.next();
			if(num.equals("0")){
				scan.close();
				break;
			}
			char subnum[] = num.toCharArray();
			for(int i = 0; i < subnum.length; i++){
				sum += Character.getNumericValue(subnum[i]);
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 26516
# frozen_string_literal: true

a, b = gets.chomp.split(' ').map(&:to_i)

gcd = a.gcd(b)

factor = `factor #{gcd}|sed -r 's/[0-9]+://g'|tr ' ' '\n'|sort -n|uniq`.split.map(&:to_i)

copied_factor = factor.dup

factor.each do |i|
  copied_factor.delete_if do |j|
    j > i && j % i == 0
  end
end

puts copied_factor.length + 1


Measured memory_bytes: 3260
#include <iostream>
#include <map> 
#include <cmath> 
using namespace std;
// typedef pair<int, int> P;
typedef long long ll;

long long *L = new long long[200001];
long long *R = new long long[200001];

int main() {
    int N;
    cin >> N;
    map<long long, long long> mp; 
    for(int i=1;i<N + 1;i++){
        long long a;
        cin >> a;
        L[i] = i + a;
        R[i] = i - a;
    }
    ll cnt = 0;
    for(int i=1;i<N+1;i++){
        auto itr = mp.find(L[i]);
        if( itr != mp.end() ) {
            mp[L[i]] = itr->second + 1;
        }else{
            mp[L[i]] = 1;
        }
        // mp[L[i]]++;
        itr = mp.find(R[i]);
        if( itr != mp.end() ) {
            cnt += itr->second;
        }
        // cnt += mp[R[i]];
    }
    // for(int i=1;i<N+1;i++){
    //     auto itr = mp.find(R[i]);
    //     if( itr != mp.end() ) {
    //         cnt += itr->second;
    //     }
    // }
    
    cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 18740
import java.util.Scanner
object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextInt //最初の整数が読み込まれる
    val b = sc.nextInt 
    val c = sc.nextInt 
    
    var x = a
    var y = b
    var z = c
    
// 入れ替え1
    var tmp = y
    y = x
    x = tmp
    
//入れ替え２
    tmp = z
    z = x
    x = tmp
    println(s"$x $y $z")
  }
}


Measured memory_bytes: 25908
#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 <thread>
#include <exception>
*/

using namespace std;

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

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



/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/

/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/

/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/

int a[2 * 114514];
int b[2 * 114514];

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


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

	sort(b, b + n);

	for (int i = 0; i < n; i++) {
		if (a[i] == b[n - 1]) {
			cout << b[n - 2] << endl;
		}
		else {
			cout << b[n - 1] << endl;
		}
	}



	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<long> A(N);
  
  for(int i=0;i<N;i++)cin>>A[i];
  
  long sum=0,re=A[0];
  for(int i=1;i<N;i++){
  	if(re>A[i]){
      sum+=re-A[i];
    }else{
      re=A[i];
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  uint64_t H;
  cin >> H;
  uint64_t count_divide_2 = 0;
  while (H > 1) {
    H /= 2;
    count_divide_2++;
  }
  uint64_t result = 0;
  result = pow(2, count_divide_2 + 1) - 1;
  cout << result << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2383>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

const ll MOD = 1e9+7;
template<class Type>
Type solve(Type res = Type()){
    ll N,T; cin >> N >> T;
    vector<ll> D(N); for(auto &in:D) cin >> in;
    sort(D.begin(),D.end());
    vector<ll> dp(N);
    dp[0] = 1;
    for(int i = 1; i < N;i++){
        int j = (int)(lower_bound(D.begin(),D.end(),D[i]-T)-D.begin());
        dp[i] = (dp[i-1]*(i-j+1))%MOD;
    }
    res = dp[N-1];
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}



Measured memory_bytes: 4468
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define endl '\n'
//#define TOAD
//#define int ll
using namespace std;
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#else
#define bug(...)
#endif
const ll inf = 1ll<<60;
const int iinf=1e9+7;
const ll mod = 1e9+7;
ll pow(ll a, ll b){
  ll re=1;
  while(b){
    if (b&1){
      re*=a;
      re%=mod;
    }
    a*=a;
    a%=mod;
    b>>=1;
  }
  return re;
}

signed main (){
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n,m; cin>>n>>m;
  vector<int> wa(n);
  vector<bool> ac(n);
  REP(i,m){
    int k; cin>>k;
    string str; cin>>str;
    if (str=="WA"){
      if (!ac[k-1]) wa[k-1]++;
    }else {
      ac[k-1]=true;
    }
  }
  int ansa=0, ansb=0;
  REP(i,n){
    if (ac[i]) {
      ansa++;
      ansb+=wa[i];
    }
  }
  cout<<ansa<<' '<<ansb<<endl;
}


Measured memory_bytes: 640
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    System.out.println(main.solve());
  }

  int[] a;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      a = IntStream.range(0, 4).map(i -> sc.nextInt()).toArray();
    } finally {
      sc.close();
    }
  }

  String solve() {
    return a[3] == 1 ? "1" : "0";
  }
}


Measured memory_bytes: 36088
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
vector<string>moji(N);
  for(int i=0;i<N;i++){
  cin>>moji.at(i);
  }
  int AC=0;
  int WA=0;
  int TLE=0;
  int RE=0;
  for(int i=0;i<N;i++){
  if(moji.at(i)=="AC"){
  AC++;
  }
    else if(moji.at(i)=="WA"){
    WA++;
    }
    else if(moji.at(i)=="TLE"){
    TLE++;
    }
    else if(moji.at(i)=="RE"){
    RE++;
    }
   }
  cout<<"AC"<<" "<<"x"<<" "<<AC<<endl;
  cout<<"WA"<<" "<<"x"<<" "<<WA<<endl;
  cout<<"TLE"<<" "<<"x"<<" "<<TLE<<endl;
  cout<<"RE"<<" "<<"x"<<" "<<RE<<endl;
}

Measured memory_bytes: 6360
A = [list(map(int, input().split())) for _ in range(3)]
C = [[0]*3 for _ in range(3)]
n = int(input())
for _ in range(n):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        C[i][j] = 1
def hoge():
  print("Yes")
  exit()
 
if C[0][0] & C[0][1] & C[0][2]:
  hoge()
if C[1][0] & C[1][1] & C[1][2]:
  hoge()
if C[2][0] & C[2][1] & C[2][2]:
  hoge()
if C[0][0] & C[1][0] & C[2][0]:
  hoge()
if C[0][1] & C[1][1] & C[2][1]:
  hoge()
if C[0][2] & C[1][2] & C[2][2]:
  hoge()
if C[0][0] & C[1][1] & C[2][2]:
  hoge()
if C[0][2] & C[1][1] & C[2][0]:
  hoge()
print("No")

Measured memory_bytes: 3064
//085B
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;
int main(void){
    int n, tmp;
    set<int>moti;
    cin >> n;
    rep(i, n){
        cin >> tmp;
        moti.insert(tmp);
    }
    cout << moti.size();
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    B = list(map(int,input().split()))
    A = [B[0]]
    ans = B[0]
    for i in range(1,N-1):
        tmp = min(B[i-1],B[i])
        ans += tmp
        A.append(tmp)
    tmp = max(A[-1],B[-1])
    A.append(tmp)
    ans += tmp
    #print(A)
    print(ans)

if __name__ == '__main__':
    main()




Measured memory_bytes: 5368
s = input().split("T")
x,y = map(int,input().split())

h,v = [],[]
hv = 0
for ft in s:
    if hv % 2 == 0:
        h.append(len(ft))
    else:
        v.append(len(ft))
    hv += 1
    
ax,ay = False,False
tx,ty = h.pop(0),0

for i in sorted(h,reverse=True):
    if tx > x:
        tx -= i
    else:
        tx += i
if tx == x:
    ax = True

for i in sorted(v,reverse=True):
    if ty > y:
        ty -= i
    else:
        ty += i
if ty == y:
    ay = True
    
if ax and ay:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3188