akhauriyash/Code-Regression huggingface dataset:
def solve():
    s = int(input())
    al = [s]
    prev = s

    while True:
        new_a = fn(prev)
        if new_a in al:
            break
        al.append(new_a)
        prev = new_a
    print(len(al) + 1)

def fn(n):
    if n % 2 == 0:
        return int(n / 2)
    else:
        return 3 * n + 1

if __name__ == "__main__":
    solve()



Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int N;
int num[10];
int lnum,rnum;
bool dfs(int n){
	if(n==10) return true;
	if((num[n]<lnum)&&(num[n]<rnum)) return false;
	else{
		if((num[n]>=lnum)&&(num[n]<rnum)){
			lnum=num[n];
			if(dfs(n+1)) return true;
		}
		else if((num[n]>=rnum)&&(num[n]<lnum)){
			rnum=num[n];
			if(dfs(n+1)) return true;
			
		}
		else{
			int temp=lnum;
			lnum=num[n];
			if(dfs(n+1)) return true;
			else{
				lnum=temp;
				rnum=num[n];
				if(dfs(n+1)) return true;
			}
		}
	}
	return false;
}
void solve(){
	cin>>N;
	for(int i=0;i<N;i++)
	{
		rnum=0;
	    for(int j=0;j<10;j++)
	    cin>>num[j];
	    lnum=num[0];
	    if(dfs(1)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
int main(){
	solve();
	return 0;
}


Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define N 101
const ll INF=1e15+7;
ll n,d,x,a[N],ans=0;

int main(){
	cin>>n>>d>>x;
	FOR(i,0,n){
		cin>>a[i];
		ans+=1+(d-1)/a[i];
	}
	ans+=x;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

const int MOD=1000000007;

int n;
double x[15],y[15];


double score(vector<int> &v)
{
	double po=0;
	for(int i=0;i<n-1;i++)	
	{
		po+=sqrt((x[v[i+1]]-x[v[i]])*(x[v[i+1]]-x[v[i]])+(y[v[i+1]]-y[v[i]])*(y[v[i+1]]-y[v[i]]));
	}
	return po;	
}

double dfs(vector<int> &v)
{
	if(v.size()==n)
	{
		/*for(int i=0;i<n;i++)
		{
			cout<<v[i];
			
		}
		cout<<"\n";
		cout<<score(v)<<"\n"; */
		return score(v);
	}
	double po=0;
	
	for(int i=0;i<n;i++)
	{
		bool flag=true;
		for(int j=0;j<v.size();j++)
		{
			if(v[j]==i)
			{
				flag=false;
				break;
			}
		}
		if(flag)
		{
			v.push_back(i);
			po+=dfs(v);
			v.pop_back();	
		}		
	}
	return po;
}

int kaijo(int w)
{
	if(w==0)return 1;
	return w*kaijo(w-1);
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>x[i]>>y[i];
	
	vector<int> nu;
	cout<<setprecision(15)<<dfs(nu)/((double)kaijo(n))<<"\n";
	return 0;
}

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

// 数字の各桁の和を返す
int sumDigits (int n) {
    int s;
    while (n > 0) {
        s += n % 10;
        n /= 10;
    }
    return s;
}

// 最大公約数を返す
int gcd (int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main () {
  int N; cin >> N;
  
  int fx = sumDigits(N);
  if (N % fx == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
use std::cmp::min;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let a: i64 = sc.read();
    let b: i64 = sc.read();
    let c: i64 = sc.read();
    let k: i64 = sc.read();

    let mut ans = 0;
    ans += min(k, a);
    if k > a + b {
        ans -= k - (a + b);
    }
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
int main(){
	int numbers[3];
	cin >> numbers[0] >> numbers[1] >> numbers[2];
	int tmp;
	int i;
	int j;
	for(i =0 ; i < 2 ;i++){
		for(j = i+1; j<3;j++){
			if(numbers[i]>numbers[j]){
				swap(numbers[i], numbers[j]);
			}
		}
	}
	cout << numbers[0] << " " << numbers[1] << " " << numbers[2] << endl;
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <vector>

int main() {
  int n;
  scanf("%d",&n);
  if(n%2==0) {
    printf("%d\n",n);
  } else {
    printf("%d\n",n*2);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k; cin >> k;
    string s; cin >> s;
    int n= s.size();
    cin >> k;
    if (n > k) {
        cout << s.substr(0, k) << "...";
    } else cout << s;
    cout << endl;

    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > P;
#define rep(i,n) for(int i=0;i< (int)(n);i++)

int main()
{
  int n;
  ll ans=0;
  cin>>n;
  int a[n],b[n],c[n];
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,n) cin>>c[i];

  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);

  //それぞれより小さいやつを二部探索で求める
  //a<b<cとしたい
  //それぞれのbに対して条件を満たすa,cの個数を求める
  //vector<auto> aa(n,0),cc(n,0);
  //aa(i)はb(i)より小さいもの，cc(i)は大きいものの個数を格納
  //upper_boundする

  rep(i,n)
  {
    int x=b[i];
    int aa=lower_bound(a,a+n,x)-a;
    int cc=upper_bound(c,c+n,x)-c;

    ans+=(ll)aa*(n-cc);
  }


  cout<<ans<<endl;

}

Measured memory_bytes: 1408
N, A, B = map(int, input().split())
H = [0] * (N)
for i in range(N):
  H[i] = int(input())

#めぐる式二分探索
#indexが条件を満たすか判定
def isOK(index, H):
  now_min = index * B
  all_H = []
  for i in range(len(H)):
    if H[i] > now_min:
      all_H.append(H[i] - now_min)
  count = 0 
  for j in all_H:
    if j % (A - B) == 0:
      count += int(j // (A - B))
    else:
      count += int(j // (A - B)) + 1
  if count <= index:
    return True
  else:
    return False
  
#にぶたん
#A : 配列
def binary_search(H):
  N = 10 ** 9 + 1
  ng = -1
  ok = N
  while (abs(ok - ng) > 1):
    mid = int((ok + ng) / 2)
    if isOK(mid, H):
      ok = mid
    else:
      ng = mid
  return ok
  

print(binary_search(H))  


Measured memory_bytes: 16672
import java.util.Scanner;

public class Main {

	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
	
	public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			// 文字列の入力
			if(a==b && b==c) {
				System.out.println("Yes");
			} else {
			// 出力
  				System.out.println("No");
			}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
 
int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> x(N);
    rep(i, 0, N) cin >> x[i];
    ll ans = 0;
    rep(i, 0, N){
        ans += 2*min(x[i], K-x[i]);
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n+7];
    for(int i=1;i<=n;i++) cin>>a[i];
    ll dp[n+7];
    for(int i=1;i<=n;i++) dp[i]=12345678901234;
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(int i=2;i<=n;i++){
        for(int j=1;j<=k;j++){
            if(i-j>0){
                dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
            }
        }
    }
    cout<<dp[n]<<endl;

}


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

int main(){
	int n,m,x;
	cin >> n >> m >> x;
	
	int c[12];
	int a[12][12];
	
	for(int i=0;i<12;i++){
		c[i]=0;
		for(int j=0;j<12;j++){
			a[i][j]=0;
		}
	}
	
	for(int i=0;i<n;i++){
		cin >> c[i];
		for(int j=0;j<m;j++){
			cin >> a[i][j];
		}
	}
	
	int cost,money=999999999;
	for(int i=0;i<(1<<n);i++){
		vector<int> A(m,0);
		cost=0;
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				cost+=c[j];
				for(int k=0;k<m;k++){
					A[k]+=a[j][k];
				}
			}
		}
		bool ok=true;
		for(int k=0;k<m;k++){
			if(A[k]<x)ok=false;
		}
		if(ok)money=min(money,cost);
	}
  
	if(money==999999999){
		cout << "-1" << endl;
		return 0;
	}
	cout << money << endl;
	return 0;
}


Measured memory_bytes: 3652
//@author yash
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define x first
#define y second
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
	fast();
	ll n,a,b;
	cin>>n>>a>>b;
	if(a==0&&b==0)
	cout<<0<<endl;
	else
	{
	
	ll x=n/(a+b);
	ll y=n%(a+b);
	if(y<=a)
	cout<<a*x+y<<endl;
	else
	cout<<a*x+a<<endl;
}
		
}



Measured memory_bytes: 256
const [WHITE, BLACK] = [0, 1];

(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const adj = lines.map((e, i) => e.trim().split(' ').map(n => n == -1 && Infinity || Number(n)));
  const range_n = Array.from(Array(n), (e, i) => i);

  const dist = [];
  const color = [];
  for (let i = 0; i < n; i++) {
    dist[i] = Infinity;
    color[i] = WHITE;
  }
  dist[0] = 0;

  let mincost, u, sum = 0;

  while (true) {
    mincost = range_n.reduce((min, i) => {
      if (color[i] === BLACK || dist[i] >= min) return min;
      return dist[u = i];
    }, Infinity);

    if (mincost === Infinity) break;

    sum += mincost;
    color[u] = BLACK;

    adj[u].forEach((v, i) => {
      if (color[i] !== BLACK && dist[i] > v) dist[i] = v;
    });
  }

  console.log(sum);
})();



Measured memory_bytes: 17500
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
struct UnionFind {
  vector<int> par; 

  UnionFind(int N) : par(N) { 
    rep(i,N) par[i] = i;
  }
  int root(int x) { 
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x); 
    int ry = root(y);
    if (rx == ry) return; 
    par[rx] = ry; 
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int n,m;
  cin >> n>>m;
  UnionFind tree(n);
  int ans=0;
  rep(i,m){
    int x,y,z;
    cin>>x>>y>>z;
    x--;
    y--;
    tree.unite(x,y);
  }
  vector<bool>a(100000);
  rep(i,n){
    if(!a.at(tree.root(i))){
      a.at(tree.root(i))=true;
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
const int N = 2e5 + 5;
char str[N];
int n;
int dp[N];
int nxt[N][26];
int main(){
	scanf("%s" , str + 1);
	n = strlen(str + 1);
	for(int i = 0 ; i < 26 ; ++i){
		nxt[n + 1][i] = n + 1;
	}
	for(int i = n ; i >= 1 ; --i){
		for(int j = 0 ; j < 26 ; ++j){
			nxt[i][j] = nxt[i + 1][j];
		}
		nxt[i][str[i] - 'a'] = i;
	}
	dp[n + 1] = 1;
	dp[n + 2] = 0;
	for(int i = n ; i >= 1 ; --i){
		int res = n;
		for(int j = 0 ; j < 26 ; ++j){
			res = min(res , dp[nxt[i][j] + 1]);
		}
		dp[i] = 1 + res;
	}
	for(int i = 1 ; i <= n + 1 ; ++i){
		for(int j = 0 ; j < 26 ; ++j){
			if(dp[nxt[i][j] + 1] + 1 == dp[i]){
				printf("%c" , char(j + 'a'));
				i = nxt[i][j];
				break;
			}
		}
	}
	printf("\n");
}

Measured memory_bytes: 21504
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n,m,x,y = sc.nextInt
  val xs = List.fill(n)(sc.nextInt)
  val ys = List.fill(m)(sc.nextInt)

  println(if ((x::xs).max < (y::ys).min) "No War" else "War")
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int a[3][3];
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++) scanf("%d", &a[i][j]);
	int n; scanf("%d", &n);
	set<int> b;
	for (int i = 0; i < n; i++) {
		int x; scanf("%d", &x);
		b.insert(x);
	}

	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++) a[i][j] = b.count(a[i][j]);

	int ans = false;
	for (int i = 0; i < 3; i++) {
		ans |= a[i][0] * a[i][1] * a[i][2] == 1;
		ans |= a[0][i] * a[1][i] * a[2][i] == 1;
	}
	ans |= a[0][0] * a[1][1] * a[2][2] == 1;
	ans |= a[0][2] * a[1][1] * a[2][0] == 1;
	puts(ans ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

const i64 mod = 1e9 + 7;
i64 fact_memo[200001];
i64 fact(i64 x) {
  if (x == 0) return 1;
  if (fact_memo[x]) return fact_memo[x];
  return fact_memo[x] = x * fact(x - 1) % mod;
}
i64 ipow(i64 a, i64 b) {
  return (b & 1 ? a : 1) * (b > 1 ? ipow(a * a % mod, b >> 1) : 1) % mod;
}
i64 inv(i64 x) {
  return ipow(x, mod - 2);
}
int main() {
    i64 n;
    cin >> n;
    vector<i64> x(n);
    for (int i = 0; i < n; ++i) cin >> x[i];

    i64 ans = 0, k = 0;
    for (int i = 0; i < n - 1; ++i) {
        (k += inv(i + 1)) %= mod;
        (ans += k * (x[i + 1] - x[i]) % mod) %= mod;
    }
    cout << fact(n - 1) * ans % mod << endl;
    return 0;
}

Measured memory_bytes: 3960
import math

def main():
    N, K = map(int, input().split())
    As = list(map(int, input().split()))

    l = 0
    r = 10**9

    while (r - l) >= 10**(-6):
        m = (l + r) / 2
        t = 0
        for A in As:
            t += math.ceil(A / m - 1)
            if t > K:
                break

        if t <= K:
            l, r = l, m
        else:
            l, r = m, r

    print(math.ceil(l))

main()


Measured memory_bytes: 31468
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=200010,M=20,Inf=2e9;
int n,a[N],cnt[M],ans,f[1<<M];
void chkmin(int &x,int y){x=min(x,y);}
int main(){
	n=gi();
	for(int i=1;i<n;i++){
		int u=gi()+1,v=gi()+1,w=gi();
		a[u]^=w;a[v]^=w;
	}
	int now=0;
	for(int i=1;i<=n;i++)cnt[a[i]]++;
	for(int i=1;i<=15;i++){ans+=cnt[i]/2;cnt[i]&=1;now+=cnt[i]<<(i-1);}
	memset(f,127,sizeof(f));f[now]=0;
	for(int i=(1<<15)-1;i;i--)
		if(f[i]<Inf)
			for(int j=1;j<=15;j++)
				if(i&(1<<j-1))
					for(int k=1;k<=15;k++)
						if(i&(1<<k-1) && j!=k){
							int x=j^k;
							if(i&(1<<x-1))chkmin(f[i-(1<<j-1)-(1<<k-1)-(1<<x-1)],f[i]+2);
							else chkmin(f[i-(1<<j-1)-(1<<k-1)+(1<<x-1)],f[i]+1);
						}
	printf("%d\n",f[0]+ans);
	return 0;
}


Measured memory_bytes: 4736
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
using ll = long long;
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑

void solve()
{
	int n, m, a;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> a;
	}
	cout << (n - m - 1) << endl;
}

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


Measured memory_bytes: 3172
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

bool solve() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    if (v <= w) return false;

    ll dv = v - w;
    ll d = abs(a - b);
    return dv * t >= d;
}

int main() {
    cout << (solve() ? "YES" : "NO") << "\n";
    return 0;
}


Measured memory_bytes: 3636
package main

import(
	"fmt"
)

func main() {
	var r,g,b int
	fmt.Scan(&r,&g,&b)
	
	num := 100*r + 10*g + 1*b
	if num % 4 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}	
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <map>
#include <cstdlib>

using namespace std;

int gcd(int x, int y){
  int r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

void solve(){
  int n; cin >> n;
  vector<int> v(n); for(int i = 0; i < n; i++) cin >> v[i];
  int ans = 1000000000;
  int flag = 0;
  for(int i = 0; i < n - 1; i++){
    if(ans == 1) break;
    if(v[i] % ans == 0) continue;
    for(int j = i + 1; j < n; j++){
      int large = max(v[i], v[j]);
      int small = min(v[i], v[j]);
      ans = min(gcd(large, small), ans);
    }
  }

  cout << ans << endl;
  return;
}

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
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;}
int const INF = 1001001001;

void err() {
    cout << -1 << endl;
    exit(0);
}

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



int n;
cin >> n;
vl a(n+1);
rep(i,n+1) cin >> a[i];

if(n == 0 && a[0] == 1) {
    cout << 1 << endl;
    return 0;
}
if(a[0] != 0) {
    err();
}

vl le(n+1), re(n+1), ln(n+1), rn(n+1);
ln[n] = a[n], rn[n] = a[n];

drep(i,n) {
    le[i] = (ln[i+1]+1)/2;
    re[i] = (rn[i+1]);
    if(le[i] > re[i]) err();
    ln[i] = le[i] + a[i];
    rn[i] = re[i] + a[i];
}
if(le[0] > 1) err();
vl edge(n+1);
edge[0] = 1;
rrep(i,n) {
    if(edge[i-1]*2 < le[i]) err();
    edge[i] = min(edge[i-1]*2-a[i],re[i]);
}
ll ans = 0;
rep(i,n+1) {
    ans += edge[i] + a[i];
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 7952
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c <= 21) {
        cout << "win" << endl;
    }
    else {
        cout << "bust" << endl;
    }
}

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


const int MAX_SIZE=100001;
const long long int MOD=1e9+7;

int N;
long long int DP[2][MAX_SIZE];
bool visited[MAX_SIZE];
vector<int> graph[MAX_SIZE];

long long int multiply(const long long int &a,const long long int &b){
	return ((a%MOD*b%MOD)%MOD+MOD)%MOD;
}

long long int add(const long long int &a,const long long int &b){
	return ((a%MOD+b%MOD)%MOD+MOD)%MOD;
}

void reset(){
	for(int i=0;i<2;i++){
		for(int j=0;j<MAX_SIZE;j++){
			DP[i][j]=-1;
		}
	}
}

long long int solve(int pos,int color){
	if(DP[color][pos]>-1) 
		return DP[color][pos];
	
	long long int ret=1,temp=0;
	vector<int> &u=graph[pos];
	
	visited[pos]=true;
	for(int i=0;i<u.size();i++){
		const int &v=graph[pos][i];
		if(!visited[v]){
			temp=add(temp,solve(v,0));
			if(color==0) temp=add(temp,solve(v,1));
			ret=multiply(ret,temp);
			temp=0;
		}
	}
	visited[pos]=false;
//	cerr<<pos<<"-"<<(color==0?"WHITE":"BLACK")<<" ret:"<<ret<<"\n";
	return DP[color][pos]=ret;
}
int main(){
	reset();
	cin>>N;
	int a,b;
	for(int i=0;i<N-1;i++){
		cin>>a>>b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	cout<<add(solve(1,0),solve(1,1))<<'\n';
	return 0;
}

Measured memory_bytes: 15744
def main():
  n,p=map(int,input().split())
  s=input()
  if 10%p==0:
    print(sum(i for i,x in enumerate(s,1) if int(x)%p==0))
    exit()
  s=s[::-1]
  x=[0]*p
  x[0]=1
  a,t=0,1
  for i in range(n):
    a=(a+int(s[i])*t)%p
    x[a]+=1
    t=(t*10)%p
  ans=sum([i*(i-1)//2 for i in x])
  print(ans)
if __name__=='__main__':
  main()

Measured memory_bytes: 3500
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner c = new Scanner(System.in);
        int numRooms = c.nextInt();
        int numPaths = c.nextInt();
        ArrayList<Integer>[] x = new ArrayList[numRooms+1];
        for (int i = 0; i < x.length; i++) {
            x[i] = new ArrayList<>();
        }
        int[] answer = new int[numRooms+1];
        //boolean[] checked = new boolean[numRooms+1];
        for (int i = 0; i < numPaths; i++) {
            int from = c.nextInt();
            int to = c.nextInt();
            x[from].add(to);
            x[to].add(from);
        }
        ArrayList<Integer> currentList = new ArrayList<>();
        currentList.add(1);
        answer[1] = -1;
        while(!currentList.isEmpty()){
            int currentIndex = currentList.remove(0);
            for (int i = 0; i < x[currentIndex].size(); i++) {
                int nextConnectedRoom = x[currentIndex].get(i);
                if(answer[nextConnectedRoom] == 0){
                    answer[nextConnectedRoom] = currentIndex;
                    currentList.add(nextConnectedRoom);
                }
            }
        }
        for (int i = 2; i < answer.length; i++) {
            if(answer[i] == 0){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
        for (int i = 2; i < answer.length; i++) {
            System.out.println(answer[i]);
        }
    }
}


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

#define DeltaCube23 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define minimum(a) *min_element(a.begin(), a.end())
#define maximum(a) *max_element(a.begin(), a.end())
#define MOD 1000000007
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i >= (b); i--)

typedef long long int lli;

using namespace std;

const int mx=1e5+5;

int main()
{
    DeltaCube23
    int n;
    cin>>n;
    lli a[n];
    lli t=0;
    forf(i,0,n)
    {
        cin>>a[i];
        t=t^a[i];
    }
    lli b[n];
    forf(i,0,n)
    {
        b[i]=a[i]^t;
        cout<<b[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 6784
while True:
    d, w = map(int, input().split())
    if d == 0:
        break
    area = []
    for _ in range(d):
        area.append(list(map(int, input().split())))
    a = 0
    for dp in range(1, d - 1):
        for wp in range(1, w - 1):
            for i in range(1, d - dp):
                for j in range(1, w - wp):
                    mawari = min(area[i - 1][j - 1:j + wp + 1] + area[i + dp][j - 1:j + wp + 1])
                    naka = 0
                    for ii in range(dp):
                        mawari = min(mawari, area[i + ii][j - 1], area[i + ii][j + wp])
                        naka = max([naka] + area[i + ii][j:j + wp])
                    if mawari > naka:
                        vn = 0
                        for ii in range(dp):
                            for jj in range(wp):
                                vn += mawari - area[i + ii][j + jj]
                        a = max(vn, a)
    print(a)


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> l;
  for( int i = 0; i < n; i++ ) {
    int a;
    cin >> a;
    l.push_back( a );
  }
  sort( l.begin(), l.end() );
  int max = l[n - 1];
  int others = 0;
  for( int i = 0; i < n - 1; i++ )
    others += l[i];
  if( max < others )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; return(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

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

int main() {
    cin >> n;
    vl a(n + 10);
    IPT(a, n)

    ll first = -1;
    ll second = -1;
    NREP() {
        if (a[i] > first) {
            first = a[i];
        } else if (a[i] > second) {
            second = a[i];
        }
    }

    NREP() {
        if (a[i] == first) {
            MSG(second)
        } else {
            MSG(first)
        }
    }
}


Measured memory_bytes: 4788
program ATc
  implicit none
  character(len=10) :: S
  integer :: i,j,Maxk,N
  integer,allocatable :: Flags(:)
  character :: si
  read(*,*) S
  N=len_trim(S)
  allocate(Flags(N))
  Flags=0
  do i=1,N
     si=S(i:i)
!     write(*,*) si                                                                                                                                         
     if((si.eq.'A').or.(si.eq.'T')) then
        Flags(i)=1
!        write(*,*) 'arude'                                                                                                                                 
     elseif((si.eq.'C').or.(si.eq.'G')) then
        Flags(i)=1
     endif
  enddo
  Maxk=0
  j=0
 ! write(*,*) N,Flags                                                                                                                                       
  do i=1,N
     if(Flags(i).eq.1) then
        j=j+1
     else
        j=0
     endif
     if(j.gt.Maxk) then
        Maxk=j
     endif
  enddo
  write(*,'(i0)') Maxk

  deallocate(Flags)
end program ATc


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

int main() { 
    int a,b;
    cin >> a >> b;

    int now_slot = 1;
    int tap_cnt = 0;
    while(now_slot < b){
        now_slot = now_slot + (a-1);
        tap_cnt++;
    }

    cout << tap_cnt << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main(int argc, const char * argv[]) {
   
    int a,b,c,d;
    
    scanf("%d %d %d %d",&a,&b,&c,&d);
    
    if(a+b == c+d) printf("Balanced");
    else if(a+b > c+d) printf("Left");
    else printf("Right");
    
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

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

    ll lucas[100] = {0};
    lucas[0] = 2;
    lucas[1] = 1;
    repi(i, 2, n+1){
        lucas[i] = lucas[i-1] + lucas[i-2];
    }

    cout << lucas[n] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;

int main(){
  int x;cin>>x;
  if(x<600)cout<<8;
  else if(x<800)cout<<7;
  else if(x<1000)cout<<6;
  else if(x<1200)cout<<5;
  else if(x<1400)cout<<4;
  else if(x<1600)cout<<3;
  else if(x<1800)cout<<2;
  else cout<<1;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

struct dat{
    int l;
    int r;
};

int ans=0,N,M;

void solve(vector<dat> &S){
    int left=0,right=min(N,M)+1;
    sort(all(S),[](auto a,auto b){
        return a.l>b.l;
    });
    while(right-left>1){
        int mid=(left+right)/2;
        int siz=0,id=0;
        bool ok=true;
        for(int t=mid;t>=1;t--){
            while(id<N&&S[id].l>=t){
                siz++;
                id++;
            }
            
            siz--;
            if(siz<0) ok=false;
        }
        
        if(ok) left=mid;
        else right=mid;
    }
    
    int mid=left;
    
    priority_queue<int> PQ;
    int id=0;
    for(int t=mid;t>=1;t--){
        while(id<N&&S[id].l>=t){
            PQ.push(S[id].r);
            id++;
        }
        PQ.pop();
    }
    while(id<N){
        PQ.push(S[id].r);
        id++;
    }
    
    int cnt=0,now=M;
    while(!PQ.empty()&&now>left){
        if(PQ.top()<=now){
            PQ.pop();
            cnt++;
            now--;
        }else PQ.pop();
    }
    chmax(ans,left+cnt);
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>M;
    vector<dat> S(N);
    for(int i=0;i<N;i++){
        cin>>S[i].l>>S[i].r;
    }
    solve(S);
    for(int i=0;i<N;i++){
        swap(S[i].l,S[i].r);
        S[i].l=M+1-S[i].l;
        S[i].r=M+1-S[i].r;
    }
    solve(S);
    
    cout<<N-ans<<endl;
    
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    string s;
    cin >> s;
  	int a=0,b=0;
    for(int i=0; i<s.size(); i++){
        if(i%2){
            if(s[i]=='0') a++;
            else b++;
        }
        else{
            if(s[i]=='1') a++;
            else b++;
        }
    }
    cout << min(a,b) << endl;
    return 0;
}


Measured memory_bytes: 3732
/* C++14(GCC5.4.1) */
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll MAX_N = 1000000;


// m>=nを想定している
ll gcd(ll m, ll n){
    if(n==0) return m;
    return gcd(n,m%n);
}


map<ll,ll> prime_factor(ll n){
    map<ll,ll> res;
    for(ll i=2; i*i<=n; i++){
        while(n%i==0){
            res[i]++;
            n /= i;
        }
    }
    if(n!=1) res[n]=1;
    return res;
}

// [[vectorを使うかmapを使うか.]]
// 要素の個数に興味があるので
// insertがO(1)のvectorの方が
// insertにO(log n)かかるmapよりも
// 使えるってことね!

// 素因数分解
// nを次々と割っていく
// i=2からスタート
/*vector<pair<ll,int>> prime_factor(ll n){
    vector<pair<ll,int>> res;
    // **このfor文のllをintにしているとTLEがでる**
    for(ll i=2; i*i<=n; i++){
        int k=0;
        while(n%i==0){
            n/=i;
            k++;
        }
        // iで一回以上割り切れるなら追加
        if(k!=0) res.push_back({i,k});
    }
    // 残ったnが1ではない時、i*i<=nに引っかかったn=iである.
    if(n!=1) res.push_back({n,1});
    return res;
}*/


int main(void){
    // 入力
    ll a,b;
    cin >> a >> b;

    // a,bのGCDを求める
    ll gcd_of_ab;
    if(a>=b) gcd_of_ab = gcd(a,b);
    else gcd_of_ab = gcd(b,a);

    // 求めたいのはGCD以下のGCDを割り切る素数の個数
    ll ans=1;
    auto m = prime_factor(gcd_of_ab);
    ans += m.size();

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
h=list(map(int,input().split()))
ans=[0]*N
ans[1]=abs(h[1]-h[0])

for i in range(2,N):
  ans[i]=min(ans[i-1]+abs(h[i]-h[i-1]),ans[i-2]+abs(h[i]-h[i-2]))
  
print(ans[N-1])

Measured memory_bytes: 13980
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <float.h>
#include <iostream>
#include <map>
using namespace std;
int main()
{
	int nN=0;
	cin >> nN;
	long lnPrice[10];
	long lnMaxIdx = 0;
	for (int i = 0; i < nN; i++)
	{
		cin >> lnPrice[i];
		if (i >= 1 && lnPrice[lnMaxIdx] < lnPrice[i])
			lnMaxIdx = i;
	}

	long lnTotal = 0;
	for (int i = 0; i < nN; i++)
	{
		if (i != lnMaxIdx)
			lnTotal += lnPrice[i];
		else
			lnTotal += (lnPrice[i] / 2);
	}

	cout << lnTotal;
	return 0;
}

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

int main(void){
  long long A,B,K;
  cin>>A>>B>>K;
  if(K<=A){
    cout<<A-K<<" "<<B<<endl;
  }else if(K<=A+B){
    cout<<0<<" "<<A+B-K<<endl;
  }else{
    cout<<0<<" "<<0<<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=13;
string s;
ll dp[M];

int main(){
	cin>>s;
	dp[0]++;
	for(auto c:s){
		ll DP[M]={0};
		if(c=='?'){
			for(int j=0;j<10;j++) for(int i=0;i<M;i++) (DP[(j+i*10)%M]+=dp[i])%=mod;
		}
		else{
			for(int i=0;i<M;i++) (DP[(c-'0'+i*10)%M]+=dp[i])%=mod;
		}
		for(int i=0;i<M;i++) dp[i]=DP[i];
	}
	cout<<dp[5]<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    int K;
    string S;
    cin >> K >> S;
    if (S.size() > K) S = S.substr(0, K) + "...";
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 3628
n,q=map(int,input().split())
s=str(input())
a=[0]*n
s=list(s)
for i in range(1,n):
  temp=0
  if s[i]=="C" and s[i-1]=="A":
    temp=1
  a[i]=a[i-1]+temp
for i in range(0,q):
  l,r=map(int,input().split())
  print(a[r-1]-a[l-1])

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll H, W;
    cin >> H >> W;
    for(ll i = 0;i < W + 2;i++) cout << '#';
    cout << endl;
    for(ll i = 0;i < H;i++) {
        string temp;
        cout << '#';
        cin >> temp;
        cout << temp;
        cout << '#' << endl;
    }
    for(ll i = 0;i < W + 2;i++) cout << '#';
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import math

def get_distance(hl,ml,h,m):
    (hx,hy) =  get_hx(hl,h,m)
    (mx,my) = get_mx(ml,m)
    return _get_distance(hx,hy,mx,my)

def _get_distance(x1, y1, x2, y2):
    d = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
    return d

def get_hx(length,time, m):
    radius = math.radians( 360 - ( (time * 30) + ( 30 *(m/60))))
    # x = rcos si-ta
    x = length * math.cos(radius)
    y = length * math.sin(radius)
    return (x,y)

def get_mx(length,time):
    r= 360 - (time * 6)
    radius = math.radians(r)
    # x = rcos si-ta
    x = length * math.cos(radius)
    y = length * math.sin(radius)
    return (x,y)


if __name__ == '__main__':

    n=int(1)
    string_list=[input() for i in range(n)]
    
    #string_list<-['hoge','foo','bar']
    l =  string_list[0].split(" ")
    hl = int(l[0])
    ml =int(l[1])
    h=int(l[2]) 
    m=int(l[3])

    d = get_distance

    d = get_distance(hl,ml,h,m)
    print(d)

Measured memory_bytes: 62880
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;

int main(){
    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    vector<ll > vec;
    //一番左端が0なら調整を加える
    if(s[0] == '0') vec.push_back(0);
    //00..または11…が続いているところをまとめ上げる

    for(ll i = 0; i < s.size();){
        ll j = i;
        //一緒の間ループを回し続けて，切れ目を探す
        while(j < s.size() && s[j] == s[i]){
            ++j;
        }
        vec.push_back(j - i);
        //次の始点へすっ飛ばす
        i = j;
    }
    //最高尾が0だったら調整を加える
    if(s[s.length()-1] == '0'){
        vec.push_back(0);
    }

    //累積和を取る
    //始点は0から
    vector<ll > sum(vec.size() + 1, 0);
    for(ll i = 0; i < vec.size(); i++){
        sum[i + 1] = sum[i] + vec[i];
    }

    //累積和メイン
    ll ans = 0;
    for(ll left = 0; left < sum.size(); left += 2){
        ll right = left + K * 2 + 1;
        if(right >= sum.size()){
            right = sum.size() - 1;
        }
        ans = max(ans, sum[right] - sum[left]);
    }

    cout << ans << endl;

} 

Measured memory_bytes: 2164
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( true ) {
	    final int n = stdin.nextInt();
	    if ( n == 0 ) {
		break;
	    }
	    //System.err.println( n );
	    int count = 0;
	    int from = 1;
	    int to = 1;
	    int sum = 1;
	    while ( to < n ) {
		while ( sum < n ) {
		    to++;
		    sum += to;
		}
		while ( n < sum ) {
		    sum -= from;
		    from++;
		}
		if ( to < n && sum == n ) {
		    //System.err.printf( "from, to = %d, %d\n", from, to );
		    count++;
		    to++;
		    sum += to;
		}
	    }
	    //System.err.println();
	    System.out.println( count );
	}	
    }    
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rrepn(i, n) for (int i = ((int)(n)); i > 0; --i)
#define SZ(x) ((int)(x).size())
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

int main() {
    long long A;
    scanf("%lld", &A);
    string B;
    cin >> B;
    ll b = (B[0] - '0') * 100 + (B[2] - '0') * 10 + (B[3] - '0');
    cout << A * b / 100 << endl;
    return 0;
}


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

int main() {
	int H, W;

	do {
		cin >> H >> W;
		if(H == 0 && W == 0) break;

		for(int h = 0; h < H; ++h) {
			for(int w = 0; w < W; ++w) {
				if((w + h) % 2 == 0) {
					cout << "#";
				} else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	} while(true);
	
	return 0;
}

Measured memory_bytes: 3108
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();

        String temp = Integer.toString(N);
        String answer = Integer.toString(Integer.parseInt(temp, 10), K);
        System.out.println(answer.length());
    }
}

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

int main(void){
    int N, Abuf;
    vector<int> KeyPlus, KeyMinus;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> Abuf;
        KeyMinus.push_back(i-Abuf);
        KeyPlus.push_back(i+Abuf);
    }
    sort(KeyMinus.begin(), KeyMinus.end());
    sort(KeyPlus.begin(), KeyPlus.end());
    long long res = 0LL;
    for(int i=0; i<N; i++){
        res += upper_bound(KeyPlus.begin(), KeyPlus.end(), KeyMinus[i])
             - lower_bound(KeyPlus.begin(), KeyPlus.end(), KeyMinus[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5028
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
    return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
    a+=b;
    if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
    a-=b;
    if(a<0){
        a+=mod;
    }
    return a;
}
 
int powz(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1){
            res=mul(res,a);
        }
        b/=2;
        a=mul(a,a);
    }
    return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
    input>>x.F>>x.S;
    return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
    for(auto& i:x)
        input>>i;
    return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
    for(auto& i:x)
        output<<i<<' ';
    return output;
}
 
const int N=200005;

void solve(){
	int n,L;
	cin>>n>>L;
	vi a(n);
	cin>>a;
	for(int i=0;i<n-1;i++){
		if(a[i]+a[i+1]>=L){
			cout<<"Possible\n";
			for(int j=0;j<i;j++){
				cout<<j+1<<'\n';
			}
			for(int j=n-1;j>i+1;j--){
				cout<<j<<'\n';
			}
			cout<<i+1;
			return;
		}
	}
	cout<<"Impossible";
	
}
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tc=1;
    //~cin>>tc;
    for(int _=0;_<tc;_++){
        //~ cout<<"Case #"<<_+1<<": ";
        solve();
        if(_!=tc-1)
        cout<<"\n";
    }
}


Measured memory_bytes: 1664
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

ll N,t,l[110]={},r[110]={},v[110];

double small(double x){
	double ans = 1e9;
	rep(i,N+2){
		double a;
		if(x<l[i]){
			a=l[i]-x+v[i];
		}else if(x>r[i]){
			a=x-r[i]+v[i];
		}else{
			a=v[i];
		}
		if(ans>a)ans = a;
	}
	return ans;
}

int main(void){
	scanf("%lld",&N);
	l[0]=0;r[0]=0;v[0]=0;
	reg(i,1,N){
		scanf("%lld",&t);
		l[i]=r[i-1];
		r[i]=l[i]+t;
	}
	reg(i,1,N)scanf("%lld",&v[i]);
	l[N+1]=r[N];r[N+1]=r[N];v[N+1]=0;
	double b,a=0,ans=0;
	rep(i,r[N]){
		b=small((double)i+0.5);
		ans+=(a+b)*0.25;
		a=small((double)i+1);
		ans+=(a+b)*0.25;
	}
	printf("%lf\n",ans);
	return 0;
}

Measured memory_bytes: 256