akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn extgcd(a: i64, b: i64, x: &mut i64, y: &mut i64) -> i64 {
    let mut d = a;
    if b == 0 {
        *x = 1;
        *y = 0;
    } else {
        d = extgcd(b, a % b, y, x);
        *y -= (a / b) * (*x);
    }
    return d;
}

fn mod_inverse(a: i64, m: i64) -> i64 {
    let mut x: i64 = 0;
    let mut y: i64 = 0;
    extgcd(a, m, &mut x, &mut y);
    (m + x % m) % m
}

struct ModFactorial {
    fact: Vec<i64>,
}

// returns n! under mod m
impl ModFactorial {
    fn new(n: i64, m: i64) -> ModFactorial {
        let mut fact = vec![1; n as usize + 1];
        for i in 2..fact.len() {
            fact[i] = (i as i64 * fact[i - 1]) % m;
        }
        ModFactorial { fact: fact }
    }
}

fn pow_m(n: i64, mut p: i64, m: i64) -> i64 {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % m;
            p /= 2;
        } else {
            ret = ret * r % m;
            p -= 1;
        }
    }
    ret
}

fn main() {
    let v: Vec<usize> = read_vec();
    let (n, a, b, c, d) = (v[0], v[1], v[2], v[3], v[4]);

    let big_int: i64 = 1000_000_000 + 7;
    let fact = ModFactorial::new(n as i64, big_int).fact;
    let inv_fact = fact.iter()
        .map(|&x| mod_inverse(x, big_int))
        .collect::<Vec<_>>();

    let mut dp = vec![vec![0i64; n + 1]; n + 1];
    for i in 0..n + 1 {
        dp[i][0] = 1;
    }

    for i in a..b + 1 {
        for j in 1..n + 1 {
            dp[i][j] = dp[i - 1][j]; // k = 0;
            for k in c..d + 1 {
                if j < k * i {
                    continue;
                }
                if j > n + k * i {
                    continue;
                }
                let mut temp = dp[i - 1][j - k * i];
                temp *= fact[n - j + k * i];
                temp %= big_int;
                temp *= inv_fact[n - j];
                temp %= big_int;

                temp *= pow_m(inv_fact[i], k as i64, big_int);
                temp %= big_int;

                temp *= inv_fact[k];
                temp %= big_int;
                dp[i][j] += temp;
                dp[i][j] %= big_int;
            }
        }
    }
    println!("{}", dp[b][n]);
}


Measured memory_bytes: 12540
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int a[100010];
int b[100010];
int main()
{
	cin >>n;
	for (int i=0;i<n;i++) cin >>a[i];
	b[0]=0;
	b[1]=abs(a[1]-a[0]);
	for (int i=2;i<n;i++)
	    b[i]=min(b[i-2]+abs(a[i]-a[i-2]),b[i-1]+abs(a[i]-a[i-1]));
    cout <<b[n-1];
    return 0;
}

Measured memory_bytes: 1024
// 5A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 100000
#define INFTY (1<<30)

class Edge {
public:
    int t, w;
    Edge(){}
    Edge(int t,int w):t(t),w(w){}
};

vector<Edge>G[MAX];
int n, d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s) {
    for (int i = 0; i < n; i++)d[i] = INFTY;
    queue<int>Q;
    Q.push(s);
    d[s] = 0;
    int u;
    while (!Q.empty()) {
        u=Q.front(); Q.pop();
        for (int i = 0; i < G[u].size(); i++) {
            Edge e = G[u][i];
            if (d[e.t] == INFTY) {
                d[e.t] = d[u] + e.w;
                Q.push(e.t);
            }
        }

    }
}

void solve() {
    bfs(0);

    int maxv = 0;
    int tgt = 0;
    for (int i = 0; i < n; i++) {
        if (d[i] == INFTY)continue;
        if (maxv < d[i]) {
            maxv = d[i];
            tgt = i;
        }
    }

    bfs(tgt);
    maxv = 0;
    for (int i = 0; i < n; i++) {
        if (d[i] == INFTY)continue;
        maxv = max(maxv, d[i]);
    }

    cout << maxv << endl;

}


int main()
{
    int s, t, w;
    cin >> n;

    for (int i = 0; i < n - 1; i++) {
        cin >> s >> t >> w;
        G[s].push_back(Edge(t, w));
        G[t].push_back(Edge(s, w));

    }
    solve();
}



Measured memory_bytes: 9840
import java.util.*;

class Main{

    public static void main(String[] args){

	Scanner sc = new Scanner(System.in);

	int N = sc.nextInt();

	double sum = 0;

	double[] A = new double[N];

	for(int i=0; i<N; i++){

	A[i] = sc.nextInt();

  }

	for(int i=0; i<N; i++){

	sum += 1/A[i];		

  }

	System.out.println(1/sum);
 }
}

Measured memory_bytes: 21204
M = [input() for i in range(3)]
M[0] = M[0].split()
s = str(M[0][0])
t = str(M[0][1])

M[1] = M[1].split()
a = int(M[1][0])
b = int(M[1][1])

U = str(M[2])


if s == U:
  a -= 1
else:
  b -= 1

print(str(a) + ' ' + str(b))


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

int main()
{
  int n;
  cin >> n;
  int l[1010], r[1010];
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
  }
  int p = 0;
  for (int i = 0; i < n; i++) {
    p += r[i] - l[i] + 1;
  }
  cout << p << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vii vector<vi>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  string s; cin >> s;
  int ans = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '+') ans++;
    else ans--;
  }
  cout << ans << endl;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> P(N);
    rep (i, N) {
        cin >> P[i];
        P[i]--;
    }

    rep (i, N-1) {
        if (P[i] > P[i+1]) {
            break;
        }
        if (i == N-2) {
            cout << 0 << endl;
            return 0;
        }
    }

    vector<ll> Q(200010);
    rep (i, N) {
        Q[P[i]] = i;
    }

    ll ans = 1;
    ll cnt = 1;
    rep (i, N-1) {
        ans = max(ans, cnt);
        if (Q[i] < Q[i+1]) {
            cnt++;
        } else {
            cnt = 1;
        }
    }

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

Measured memory_bytes: 3456
while True:
    H,W=[int(x) for x in input().split()]
    if H == 0 and W == 0:
        break
    for a in range (H):
        if a == 0 or a == H-1:
            print("#"*W)
        else:
            print("#" + "."*(W-2) + "#")
    print('')


Measured memory_bytes: 5624
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>  
#include<memory.h> 
#include<sstream>
#include<time.h>
#include<iomanip>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const long long MOD=1000000007;
const long long LMOD=998244353;
//const long long LMOD=1000000007;
#define Fi first
#define Se second
#define P2 pair
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define Cb make_pair
#define ll long long
#define Ull unsigned long long
#define Sf scanf
#define Pf printf
#define Pb push_back
#define Psh push
#define Stc stack
#define Vct vector
#define Ret return
#define Re0 return 0z
#define Sz size
#define Is insert
#define Que queue
#define Emp empty
#define Fro front
#define Rv reverse
#define Er erase
#define Bg begin
#define Srt sort
#define Pq priority_queue
#define Ite iterator
ll a[100005];
ll b[100005];
ll n;
int main()
{
	Sf("%lld",&n);
	for(ll i=0;i<=n;i++)
	{
		Sf("%lld",&a[i]);
	}
	for(ll i=1;i<=n;i++)
	{
		Sf("%lld",&b[i]);
	}
	ll s=0;
	for(ll i=1;i<=n;i++)
	{
		s+=min(a[i-1]+a[i],b[i]);
		b[i]-=a[i-1];
		if(b[i]>0)a[i]=max(a[i]-b[i],0ll);
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
INF = 10**11
A,B,Q = map(int,input().split())
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
s.sort()
t = [-INF] + [int(input()) for _ in range(B)] + [INF]
t.sort()
def binary_search(lis,x):
    ok = 0
    ng = len(lis)-1
    while ng-ok > 1:
        mid = (ok+ng)//2
        if lis[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok
#print(s,t)
for _ in range(Q):
    x = int(input())
    ps = binary_search(s,x)
    pt = binary_search(t,x)
    ans = INF
    #print(ps,pt)
    for i in range(ps,ps+2):
        for j in range(pt,pt+2):
            ds = x - s[i]
            dt = x - t[j]
            
            if (ds < 0 and dt < 0) or (ds > 0 and dt > 0):
                ans = min(ans,max(abs(ds),abs(dt)))
            else:
                ans = min(ans,abs(ds)+abs(dt)+min(abs(ds),abs(dt)))
    print(ans)  
            


Measured memory_bytes: 82344
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
int32_t main(){
    fastio;
    int n;
    cin >> n;
    vector<pii> v(n);
    int ans = 0;
    for(int i=0;i<n;i++){
        cin >> v[i].ff;
    }
    for(int i=0;i<n;i++){
        cin >> v[i].ss;
        ans+= max(0LL,v[i].ff-v[i].ss);
    }
    cout << ans << endl;
} 

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	long ans = 0;
	int i, j, k;
	int itop, iend;
	int jtop, jend;
	int iketa, ketagawari;

	cin >> n;
	itop = iend = 1;
	ketagawari = 10;
	for (i = 1; i <= n; i++,iend++) {
		if (i % 10 == 0) {
			if (i >= ketagawari*10) {
				ketagawari *= 10;
			}
			itop = i / ketagawari;
			iend = 0;
			continue;
		}
		int anstmp = 0;
		int kakeru = 1;
		int jmin, jmax;

		if (itop == iend) {
			anstmp++;
		}
		for (;;) {
			kakeru *= 10;
			jmin = iend * kakeru + itop;
			jmax = jmin + kakeru - 10;
			/*
			if (i == 2) {
				cout << i << " : " << jmin << " / " << jmax << " -> ";
			}
			*/
			if (jmax <= n) {
				anstmp += kakeru / 10;
				/*
				if (i == 2) {
					cout << anstmp << endl;
				}
				*/
			}
			else if (jmin <= n) {
				anstmp += (n - iend * kakeru) / 10+1;
				if (n % 10 < itop) {
					anstmp--;
				}
/*
				if (i == 2) {
					cout << anstmp << endl;
				}
*/
				break;
			}
			else {
				break;
			}
		}
		ans += anstmp;
		if (i < 10) {
			itop++;
		}
		/*
		if (i == 2) {
			cout << i << " : " << anstmp << endl;
		}
		*/

	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
const ll MINF = LLONG_MIN;
const int INT_INF = INT_MAX;

int main()
{
    int n, m;
    cin >> n >> m;
    cout << (n == m ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 3010
using namespace std;
typedef long long ll;
ll n;
ll mod;
ll C[maxn][maxn],s[maxn][maxn];
ll qp(ll x,ll p,ll m)
{
	ll an=1;
	ll po=x;
	while(p)
	{
		if(p%2)   an=(an*po)%m;
		po=(po*po)%m;
		p/=2;
	}
	return an;
}
int main()
{
	scanf("%lld%lld",&n,&mod);
	C[0][0]=1;
	C[1][0]=1;C[1][1]=1;
	for(int i=1;i<=n;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=n;j++)
		{
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
		}
	}
	s[0][0]=1;
	for(int i=1;i<=n+1;i++)
	{
		for(int j=1;j<=i;j++)
		{
			s[i][j]=(s[i-1][j-1]+(s[i-1][j]*(ll)j)%mod)%mod;
		}
	}
	ll ans=0;
	for(int i=0;i<=n;i++)
	{
		ll sum=1;
		sum=(sum*qp(2,qp(2,n-i,mod-1),mod))%mod;
		//cout<<sum<<endl;
		sum=(sum*C[n][i])%mod;
		ll x=0;
		for(int j=0;j<=i;j++)
		{
			x=(x+((qp(2,(ll)(n-i)*j%(mod-1),mod))*s[i+1][j+1])%mod)%mod;
		}
		sum=(sum*x)%mod;
		int k;
		if(i%2==0)  k=1;
		else        k=-1;
		sum=((sum*k)%mod+mod)%mod;
		ans=(ans+sum)%mod;
	}
	//cout<<ans<<endl;
	//ll tmp=qp((ll)n,mod-2,mod);
	//cout<<tmp<<endl;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 140032
n, m = gets.split.map(&:to_i)

available_day = []
works = []
n.times { works << gets.split.map(&:to_i) }

(1..m).each{|i| available_day << i}

works.sort!{|a, b| (b[1] <=> a[1]).nonzero? || b[0] <=> a[0] }

sum = 0
works.each do |day, salary|
  if index = available_day.bsearch_index{|e| e >= day }
    available_day.delete_at(index)
    sum += salary
  end
end

p sum


Measured memory_bytes: 13416
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<"The value of "<<#x<<" is "<<x<<endl;
typedef long long ll;
typedef unsigned long long ull;
void max_self(ll& a,ll b){
    a=max(a,b);
}
int main()
{
    cin.sync_with_stdio(0); cin.tie(0); 
    ll n,w;
    cin>>n>>w;
    vector<ll>dp(w+1);
    for(ll i=0;i<n;i++){
        ll weight,value;
        cin>>weight>>value;
        for(ll weight_already=w-weight;weight_already>=0;--weight_already)
        max_self(dp[weight_already+weight],dp[weight_already]+value);
    } 
    ll ans=0;
    for(auto i:dp)
    max_self(ans,i);
    cout<<ans<<endl;
    
}


Measured memory_bytes: 1024
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, usize1) => {
        read_value!($next, usize) - 1
    };

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: chars
    }
    let mut f = vec![false; 4];
    for &c in &s {
        match c {
            'N' => {f[0] = true;},
            'E' => {f[1] = true;},
            'W' => {f[2] = true;},
            'S' => {f[3] = true;},
            _ => {}
        }
    }
    println!("{}", if f[0] ^ f[3] || f[1] ^ f[2] {"No"} else {"Yes"});
}


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

int main()
{
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	if(s.size()!=(a+b+1)){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0; i<s.size(); i++){
		if(i!=a){
			//if(!isdigit(s[i])){
			if(!(s[i]>='0' && s[i]<='9')){
				cout<<"No"<<endl;
				return 0;
			}
		}else if(s[i]!='-'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 114514
#define NIL -1

int main(){
    int n,A[MAX],ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&A[i]);
    A[n] = NIL;
    sort(A,A+n);
    //for(int i=0;i<n;i++) printf("%d ",A[i]);
    for(int i=0;i<n;){
        if(A[i]==A[i+1]){
            i += 2;
        }
        else{
            ans++;
            i++;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int i,x;
    int [] num = new int[101];
    x = sc.nextInt();
    for(i = 0;i < x;i++){
      num[i] = sc.nextInt();
    }
    while(true){
      i--;
      if(i <= 0){
        System.out.print(num[i]);
        break;
      }
      System.out.print(num[i] + " ");
    }
    System.out.println();
  }
}

Measured memory_bytes: 26292
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int a, b, c, d;
  
  a = n / 1000;
  b = n % 1000 / 100;
  c = n % 1000 % 100 / 10;
  d = n % 1000 % 100 % 10 /1;
    
    if (a == b && b == c && c == d){
      cout << "Yes" << endl;
    }
    
    else if (a == b && a == c){
      cout << "Yes" << endl;
    }
    else if(b == c && b == d){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
}
  
      


Measured memory_bytes: 3532
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
vi v;
void dfs(int k) {
    if(k>3500000000) return;
    v.pb(k);
    for(int i = max(k%10-1,0LL);i<=min(k%10+1,9LL);i++) {
        dfs(10*k+i);
    }
}
signed main() {
    int k;cin >> k;
    rep1(i, 9) dfs(i);
    // dfs(1);
    sort(all(v));
    cout << v[k-1] << endl;
    // rep(i, k) cout << v[i] << endl;
    return 0;
}

Measured memory_bytes: 4236
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int R;

double calc(double height){
	return sqrt(fabs((double)R*(double)R - ((double)R-height)*((double)R-height)));
}


int main(){

	int N,left,right,height;
	bool map[21][41];
	bool FLG;
	double sun_right,sun_height,ans;

	while(true){
		scanf("%d %d",&R,&N);
		if(R == 0 && N == 0)break;

		for(int i = 0; i <= 40; i++){
			for(int k = 0; k <= 20; k++)map[k][i] = false;
		}

		for(int i = 0; i < N; i++){
			scanf("%d %d %d",&left,&right,&height);

			for(int a = 20+left; a <= 20+right-1; a++){
				for(int b = 0; b < height; b++){
					map[b][a] = true;
				}
			}
		}

		for(double time = 0.0001; time <= 20.0001; time += 0.0001){
			if(time <= (double)R*2.0){
				sun_height = time;

				height = (int)ceil(sun_height);

				FLG = true;

				for(int h = 0; h < height; h++){
					sun_right = calc(sun_height-(double)(h));
					right = (int)ceil(sun_right);
					left = -right;

					for(int w = 20+left; w <= 20+right-1; w++){
						if(map[h][w] == false){
							FLG = false;
							break;
						}
					}
					if(!FLG)break;
				}

				if(!FLG){
					ans = time - 0.0001;
					break;
				}
			}else{

				sun_height = time;

				height = (int)ceil(sun_height);

				FLG = true;

				for(int h = height-2*R; h < height; h++){
					sun_right = calc(sun_height-(double)(h));
					right = (int)ceil(sun_right);
					left = -right;

					for(int w = 20+left; w <= 20+right-1; w++){
						if(map[h][w] == false){
							FLG = false;
							break;
						}
					}
					if(!FLG)break;
				}

				if(!FLG){
					ans = time - 0.0001;
					break;
				}
			}
		}

		printf("%.4lf\n",ans);
	}

	return 0;
}

Measured memory_bytes: 2580
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,M,P = LI()

import collections

class BellmanFord():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.e = collections.defaultdict(list)
    def add(self,u,v,d,directed = False):
        if directed is False:  # 無向グラフの場合
            self.e[u].append((v,d))
            self.e[v].append((u,d))
        else:  # 有向グラフの場合
            self.e[u].append((v,d))
    def BellmanFord_negative_bool2(self,s,t):  # sから辿り着ける負の閉路で、tにたどり着けるものは存在するか
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        for i in range(self.N):
            for u in self.e.keys():
                for v,c in self.e[u]:
                    if d[v] > d[u] + c:
                        if i != self.N - 1:
                            d[v] = d[u] + c
                        else:
                            d[v] = -float('inf')
                            for i in range(self.N):
                                for u in self.e.keys():
                                    for v, c in self.e[u]:
                                        if d[v] > d[u] + c:
                                            d[v] = d[u] + c
                            if d[t] == -float('inf'):
                                return True, d
                            else:
                                return False, d
        return False,d

G = BellmanFord(N)

for i in range(M):
    a,b,c = LI()
    G.add(a,b,P-c,directed=True)

bool,d = G.BellmanFord_negative_bool2(1,N)

if not bool:
    print(max(0,-d[N]))
else:
    print(-1)

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

vector<int> buf;
int n, m, q;
vector<int> as, bs, cs, ds;
ll ans = 0;

void dfs(int i, const int size, const int range_start, const int range_end)
{
  if (i == size)
  {
    // ll prev = 0;
    // rep(j, buf.size()) {
    //   if(buf[j] < prev) return;
    //   prev = buf[j];
    // }

    ll num = 0;
    rep(j, q)
    {
      int a = as[j];
      int b = bs[j];
      int c = cs[j];
      int d = ds[j];
      if (buf[b-1] - buf[a-1] != c) continue;
      num += d;
    }
    ans = max(ans, num);
    return;
  }
  else
  {
    for (int j = range_start; j <= range_end; ++j)
    {
      buf[i] = j;
      dfs(i + 1, size, j, range_end);
    }
  }
}

int main(void)
{
  cin >> n >> m >> q;
  as.resize(q);
  bs.resize(q);
  cs.resize(q);
  ds.resize(q);
  rep(i, q)
  {
    cin >> as[i] >> bs[i] >> cs[i] >> ds[i];
  }

  int size = n;
  int range_start = 1;
  int range_end = m;


  buf.resize(size);
  dfs(0, size, range_start, range_end);

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


Measured memory_bytes: 3676
def main():
    n,a,b = map(int,input().split())
    if a>b:
        print(0)
    elif n==1 and a!=b:
        print(0)
    else:
        sum_min = a+b+a*(n-2)
        sum_max = a+b+b*(n-2)
        print(sum_max-sum_min+1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int i=1;
		while(true){
        	String x=br.readLine();
        	if(x.equals("0")) break;
        	sb.append("Case "+i+": "+x+"\n");
        	if(i%500==0){
        		System.out.print(sb.toString());
        		sb.setLength(0);
        	}
    		i++;
        }
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 25112
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
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 long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	string s;
	cin>>s;
	int i,c=s.length(),f=s.length();
	for(i=0;i<s.length();i++){
		if(s[i]=='C'){
			c=i;
			break;
		}
	}
	for(i=c+1;i<s.length();i++){
		if(s[i]=='F'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[100005];
int main(){
  ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a,a+n);
	cout << a[n/2]-a[n/2-1];
    return 0;
}


Measured memory_bytes: 768
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli a, b, c, d;
    cin >> a >> b >> c >> d;
    out(c + b - d << " " << d + c - a << " " << a + b - d << " " << b + c - a);
}

Measured memory_bytes: 3644
fun main(args: Array<String>) {
    val n = readInt()
    val a = readIntList()

    var two = 0
    var four = 0
    var x = 0
    a.forEach {
        var cnt = 0
        var ta = it
        do {
            if (ta % 2 == 0) {
                ta /= 2
                cnt++
            } else {
                break
            }
        } while (true)
        when {
            cnt == 1 -> two++
            cnt >= 2 -> four++
            else -> x++
        }
    }

    if (two == 0) {
        if (x <= four + 1) {
            println("Yes")
        } else {
            println("No")
        }
    } else {
        if (x <= four) {
            println("Yes")
        } else {
            println("No")
        }
    }
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)

Measured memory_bytes: 51732
#include<bits/stdc++.h>
using namespace std; 
int N,ptr,res;
int A[100000]; 
int main (){
  cin>>N;
  for(int i=0;i<N;i++) cin>>A[i]; 
  sort(A,A+N);
  while(ptr<N){
    int cc=A[ptr],f=0;
    while(ptr<N&&A[ptr]==cc) f++,ptr++;
    res+=f%2;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 640
sDict = {}
n = int(input())

for m in range(n):
    s = input()
    if s:
        if not s in sDict:
            sDict[s] = 1
        else:
            sDict[s] += 1
    else:
        break

sDict = sorted(sDict.items(), key=lambda x:x[1])

tempValue = ""
tempList = []

for key, value in reversed(sDict):
    if tempValue:
        if tempValue != value:
            break   
    else:
        tempValue = value
    
    tempList.append(key)

for element in sorted(tempList):
    print(element)

Measured memory_bytes: 43228
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define abu ios_base::sync_with_stdio(0)
#define said cin.tie(0)
using namespace std;

void yes(){
    cout<<"Yes"<<endl;
}

void no(){
    cout<<"No"<<endl;
}

void solve(){
    ll x;
    cin>>x;
    ll ans = 1000 * (x/500) + 5*(x%500/5);
    cout<<ans<<endl;
}

int main(){
    abu;
    said;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll n; cin >> n;
  vector<ll> a(n+1), b(n);
  for(ll i=0; i<n+1;++i) cin>>a[i];
  vector<ll> ad = a;
  for(ll i=0; i<n;++i) cin>>b[i];
  ll out_l =0;
  for(ll j=0;j<n;++j){
    if(b[j]<=a[j]){
      out_l += b[j];
    } else {
      out_l += a[j];
      ll res = b[j] - a[j];
      if(res>=a[j+1]){
        out_l += a[j+1];
        a[j+1] = 0;
      } else {
        out_l += res;
        a[j+1] -= res;
      }
    }
  }
  cout << out_l << endl;
  return 0;
}


Measured memory_bytes: 2688
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) throws IOException{ 
		Scanner sc = new Scanner(System.in);
		Double x1 = sc.nextDouble();
		Double y1 = sc.nextDouble();
		Double x2 = sc.nextDouble();
		Double y2 = sc.nextDouble();
		Double xl = x2 - x1;
		Double yl = y2 - y1;
		Double length = Math.sqrt( xl*xl + yl*yl);
		System.out.printf("%.5f",length);
	}
}

Measured memory_bytes: 28236
Scanf.scanf "%d" (fun n ->
    let rec loop i u d r l =
        if i = n then u, d, r, l else
            let x, y, dir = Scanf.scanf " %d %d %c" (fun x y u -> x, y, u) in
            match dir with
            | 'U' -> loop (i + 1) ((x, y) :: u) d r l
            | 'D' -> loop (i + 1) u ((x, y) :: d) r l
            | 'R' -> loop (i + 1) u d ((x, y) :: r) l
            | 'L' -> loop (i + 1) u d r ((x, y) :: l)
            | _ -> failwith "??"
    in
    let proc sc a1 a2 f1 f2 =
        let arena = Array.make 400001 [] in
        List.iter (fun xy -> let p, v, dir = f1 xy in arena.(p) <- (v, dir) :: arena.(p)) a1;
        List.iter (fun xy -> let p, v, dir = f2 xy in arena.(p) <- (v, dir) :: arena.(p)) a2;
        let count l =
            let rec loop m = function
                | (h1, 1) :: ((h2, -1) as h) :: tl -> loop (min m ((h2 - h1) * sc)) (h :: tl)
                | _ :: h :: tl -> loop m (h :: tl)
                | _ -> m
            in
            loop max_int (List.sort compare l)
        in
        Array.fold_left (fun acc l -> min acc (count l)) max_int arena
    in
    let u, d, r, l = loop 0 [] [] [] [] in
    let m1 = proc  5 u d (fun (x, y) -> x,              y, 1) (fun (x, y) -> x,              y, -1) in
    let m2 = proc  5 r l (fun (x, y) -> y,              x, 1) (fun (x, y) -> y,              x, -1) in
    let m3 = proc 10 u r (fun (x, y) -> x + y,          y, 1) (fun (x, y) -> x + y,          y, -1) in
    let m4 = proc 10 l d (fun (x, y) -> x + y,          y, 1) (fun (x, y) -> x + y,          y, -1) in
    let m5 = proc 10 u l (fun (x, y) -> x - y + 200000, y, 1) (fun (x, y) -> x - y + 200000, y, -1) in
    let m6 = proc 10 r d (fun (x, y) -> x - y + 200000, y, 1) (fun (x, y) -> x - y + 200000, y, -1) in
    let ( *@) a b = min a b in
    let c = m1 *@ m2 *@ m3 *@ m4 *@ m5 *@ m6 in
    if c = max_int then print_endline "SAFE" else Printf.printf "%d\n" c
)

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

using namespace std;

#define ll long long

int main(){
  ll n, ans; 
  cin >> n;
  ll gold = n/500;
  n %= 500;
  ans += (gold * 1000);
  ans += ((n/5)*5);
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        if (x<a){
            System.out.println(0);
        } else {
            System.out.println(10);
        }
    }
}

Measured memory_bytes: 20820
#include<bits/stdc++.h>
#define fu(a,b) for(int i=a;i<b;i++)
#define fv(a,b) for(int j=a;j<b;j++)
#define ll long long
#define dl double

using namespace std;

int main()
{
	string a,b;
	cin>>a>>b;
	
	int dp[a.length()+1][b.length()+1];
	fu(0,a.length()+1)
	{
		fv(0,b.length()+1)
		dp[i][j]=0;
	}
	int res=0;
	fu(0,a.length())
	{
		fv(0,b.length())
		{
			if(a[i]==b[j])
			{
				dp[i+1][j+1]=dp[i][j]+1;
			}
			else
			{
				dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
			}
			
		}
	}
	int l=dp[a.length()][b.length()];
	char s[l+1];
	int ind=l;
	s[l]='\0';
	ind--;
	int i=a.length();
	int j=b.length();
	while(i>0 && j>0)
	{
		if(a[i-1]==b[j-1])
		{
			s[ind]=a[i-1];
			i--;
			j--;
			ind--;
		}
		else
		{
			if(dp[i-1][j]>dp[i][j-1])
			i--;
			else
			j--;
		}
	}
	/*
	fu(0,a.length()+1)
	{
		fv(0,b.length()+1)
		cout<<dp[i][j]<<" ";
		cout<<"\n";
	}
	cout<<l<<"\n";
	*/
	cout<<s;
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
string s;
int k;
int main(){
  cin >> s;
  cin >> k;
  string ans = "1";
  for(int i = 0; i < k; i++){
    if(s[i] != '1') {
      ans = s[i];
      break;
    }
  }
  cout << ans << endl;
}

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

const int kN = 11000;

void primeNumber(bool prime[kN], vector<int> &p){
    rep(i,kN) prime[i] = 1;
    prime[0] = prime[1] = 0;
    rep(i,kN){
        if(prime[i]){
            p.push_back(i);
            for(int j = i + i; j < kN; j+=i){
                prime[j] = 0;
            }
        }
    }
}

int main(){
    bool prime[kN];
    vector<int> p;
    primeNumber(prime, p);

    int n;
    while(cin >> n, n){
        int ans = 0;
        for(int i = 0; p[i] <= n; i++){
            int sum = 0;
            for(int j = i; p[j] <= n; j++){
                sum+=p[j];
                if(sum == n){
                    ans++;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1240
import java.util.*

fun bubbleSort(A: Array<Int>) {
    var count = 0
    var flg = true
    var i = 1
    while(flg) {
        flg = false
        for (j in A.size - 1 downTo i) {
            if (A[j] < A[j - 1]) {
                A[j] = A[j - 1].also { A[j - 1] = A[j] }
                flg = true
                count++
            }
        }
        i++
    }
    println(A.joinToString(" "))
    println(count)
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val N = scanner.nextInt()
    val list = mutableListOf<Int>()
    for (i in 0 until N) {
        list.add(scanner.nextInt())
    }
    bubbleSort(list.toTypedArray())
}


Measured memory_bytes: 31860
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define ll long long
#include <math.h> /* M_PI */
#define INF 2147483647
int main()
{
    ll n;
    cin >> n;
    vector<ll> A(n);
    vector<ll> B(n);
 
    rep(i, n)
    {
        cin >> A[i] >> B[i];
    }
    if (n % 2 == 1)
    {
 
        vector<ll> hi = A;
        vector<ll> low = B;
        sort(hi.begin(), hi.end());
        sort(low.begin(), low.end());
 
        ll max1 = hi[n / 2];
        ll min1 = low[n / 2];
        cout << min1 - max1 + 1 << endl;
    }
    if (n % 2 == 0)
    {
        vector<ll> hi = A;
        vector<ll> low = B;
        sort(hi.begin(), hi.end());
        sort(low.begin(), low.end());
 
        ll max1 = (hi[(n - 1) / 2] + hi[n / 2]);
 
        ll min1 = (low[(n - 1) / 2] + low[n / 2]);
        cout << min1 - max1 + 1;
    }
}

Measured memory_bytes: 9556
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)
















int main(){
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<pair<ll, ll>> v;
    REP(i, a){
        ll p;
        cin >> p;
        v.push_back({p, 1});
    }
    REP(i, b){
        ll q;
        cin >> q;
        v.push_back({q, 2});
    }
    REP(i, c){
        ll r;
        cin >> r;
        v.push_back({r, 0});
    }
    sort(v.begin(), v.end(), greater<pair<ll, ll>>());
    ll c1 = 0, c2 = 0, c3 = 0;
    ll ans = 0;
    REP(i, v.size()){
        ll val = v[i].first, col = v[i].second;
        if(col == 1){
            if(c1 < x){
                c1++;
                ans += val;
            }
        }
        else if(col == 2){
            if(c2 < y){
                c2++;
                ans += val;
            }
        }
        else{
            ans += val;
            c3++;
        }
        if(c1 + c2 + c3 == x + y) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 10348
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#include <bits/stdc++.h>
//~ #include <atcoder/all>
using namespace std;
using ll = long long;
using P = pair<int, int>;

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
//~ int A = (1<<2) | (1<<3) | (1<<5) | (1<<7);
//~ for (int bit=A; ; bit=(bit-1)&A){
//~ if (!bit) break;
//~ }
int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
//~ int n=5;
//~ int k=3; // nCkの組み合わせ、ただしk=0には対応してない
//~ int bit=(1<<k)-1; // 1000 -> 0111
//~ for(; bit < (1<<n); bit=nex_combination(bit){
//~ }
bool isPrime(int a) {
    if (a == 2) return true;
    if (a <= 1 || a % 2 == 0) return false;

    for (int i = 3; i * i <= a; i += 2) {
        if (a % i == 0) return false;
    }
    return true;
}
//~ vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
vector<int> aaa;
// index が条件を満たすかどうか
bool isOK(int index, int key) {
    if (aaa[index] >= key)
        return true;
    else
        return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
    int ng = -1;  //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok =
        (int)aaa
            .size();  // 「index =
                      // a.size()-1」が条件を満たさないこともあるので、初期値は
                      // a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//~ int v[100100];
//~ int INF = 1 << 30;
//~ vector<vector<int>> dp(310, vector<int>(310));
//~ ll dp[110][100100];
//~ vector<int> dp(100100, 0));

//~ int seen[110];
//~ int ans[110][2];
//~ ll MOD = 1e9 + 7;

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

    int ans = 0;
    int sa = a, sb = b, sc = c;
    while (true) {
        if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) break;
        int ta = a, tb = b, tc = c;
        a = tb / 2 + tc / 2;
        b = ta / 2 + tc / 2;
        c = ta / 2 + tb / 2;
        ans++;
        if (sa == a && sb == b && sc == c) {
            ans = -1;
            break;
        }
    }

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


Measured memory_bytes: 3592
N, M = [int(_) for _ in input().split()]
city = [[] for i in range(N + 1)]
for i in range(M):
    P, Y = [int(_) for _ in input().split()]
    city[P].append((Y, i + 1))

result = []

for j in range(len(city)):
    city[j].sort()
    for i in range(len(city[j])):
        Y, i1 = city[j][i]
        result.append((i1, j, i + 1))

result.sort()

for ri in result:
    _, a, b = ri
    print("{:06d}{:06d}".format(a, b))

Measured memory_bytes: 40716
#pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF (1e17)
#define int ll
#define EPS (1e-6)
#define DB(x) #x<<" "<<x<<" "
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
	b%=MOD;
	int ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int dp[110][4][2];
//pos,k,== or <

int32_t main() {
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);

	//code...
	int n; cin>>n;
	int now=1;
	int ans=0;
	while(n){
		ans+=now;
		n/=2;
		now*=2;
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	ll n, m;
	cin >> n >> m;
	ll ans = 0;
	if (n >= 3 && m >= 3)ans = (n - 2) * (m - 2);
	else if (n == 1 && m >= 3)ans = m - 2;
	else if (m == 1 && n >= 3)ans = n - 2;
	else if (n == 1 && m == 1)ans = 1;
	else ans = 0;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    val in = StdIn.readLine().split(" ").map(_.toInt)
    val n = in(0)
    val m = in(1)

    val A = Array.ofDim[Int](n,m)
    val b = new Array[Int](m)

    for(i <- 0 to n - 1){ A(i) = StdIn.readLine().split(" ").map(_.toInt) }
    for(i <- 0 to m - 1){ b(i) = StdIn.readInt() }

    for(i <- 0 to n - 1){
      println((A(i),b).zipped.map(_ * _).sum)
    }
  }
}

Measured memory_bytes: 47868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  ll ans=inf;
  for(ll i=1;i*i<=n;i++) {
    if(n%i==0) {
      ans=min(ans,i+n/i-2);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys

N = int(input())

dp = [[0]*3  for i in range(N)]

dp[0][0], dp[0][1], dp[0][2] = map(int, sys.stdin.readline().split())

tmp = [0, 0, 0]

for i in range(1, N):
    tmp[0], tmp[1], tmp[2] = map(int, sys.stdin.readline().split())
    for j in range(3):
        dp[i][j] = max(dp[i-1][(j+1)%3]+tmp[j], dp[i-1][(j+2)%3]+tmp[j])

print(max(dp[N-1]))

Measured memory_bytes: 22812
#include <bits/stdc++.h>
#define vc vector<int>
#define um unordered_map<int,int>
#define ll long long 
#define rep(i,a,b) for(__typeof(a) i=a; i<b; i++)
#define si(a) a.size()
#define all(a) a.begin(),a.end()
#define ss(a) a.second
#define ff(a) a.first
#define M 1000000
#define pb push_back
#define repit(i,a) for(auto i=a.begin(); i!=a.end(); i++)
#define take(arr,n) for(int i=0;i<n;i++)cin>>arr[i]
#define out(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<' '
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define reprev(i,b,a) for(__typeof(b) i=b; i>=a; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define doublearray vector<vector<int>>
#define mod 998244353 
using namespace std;
ll max(ll a, ll b){ return a>b?a:b; }
ll min(ll a, ll b){ return a<b?a:b; }
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}
int binaryS(ll x, ll sb[], int m){
    int l = 0, r=m;
    int mid = (l+r)/2;
    while(l<r){
        mid = (l+r)/2;
        if(sb[mid]<x) l= mid+1;
        else if(sb[mid]>x) r = mid-1;
        else return mid;
    }
    return l;
}
int main(){
    fastio;
    int n,k; cin>>n>>k;
    ll arr[n]; take(arr,n);
    sort(arr,arr+n);
    ll ans = 0;
    rep(i,0,(int)min(k,n)){
        ans += arr[i];
    }cout<<ans<<endl;
    return 0;
}





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

int main() {
  int A, B, C, D;
  1 <= A, B, C, D <= 10;
  cin >> A >> B >> C >> D;

  if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  }
  else if ( (A + B) < (C + D) ) {
    cout << "Right" << endl;
  }
  else if ( (A + B) == (C + D) ) {
    cout << "Balanced" << endl;
  }
}


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

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int N, M;
set<string> U;
string T;

int main() {
  cin>>N;
  REP(i,0,N) cin>>T, U.insert(T);
  cin>>M;
  int st = 0;
  REP(i,0,M){
    cin>>T;
    if(U.find(T) == U.end()) cout<<"Unknown "<<T<<endl;
    else if(st == 0)cout<<"Opened by "<<T<<endl, st = 1;
    else cout<<"Closed by "<<T<<endl, st = 0;
  }

  return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mx 2000001
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t,n,m,a,b,c,d,e,f;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
    return 0;
}



Measured memory_bytes: 256