akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
const int N=1505;
int val[N<<11|1],b[N<<11|1],S[N],n,u[N<<11|1],l[N],r[N],flag[N<<11|1];
char A[N][N];
int main(){
	scanf("%d",&n);
	for (register int i=1;i<=n;++i)scanf("%s",A[i]+1);
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)flag[i<<11|j]=A[i][j]>='0'&&A[i][j]<='9',b[i<<11|j]=A[i][j]-'0';
	for (register int i=0;i<=n;++i)
		for (register int j=0;j<=n;++j)u[i<<11|j]=flag[i<<11|j]?min(i,min(u[(i-1)<<11|j],u[i<<11|(j-1)])):1<<30;
	long long ans=0;
	for (register int x=1;x<=n;++x){
		for (register int j=1;j<=n;++j)S[j]=S[j-1]+(u[x<<11|j]<=x?b[x<<11|j]:0);
		for (register int j=n+1;j;--j){
			if (flag[x<<11|j]){
				l[j]=j-1;
				r[j]=r[j+1]==-1?j:r[j+1];
				val[x<<11|j]+=S[r[j]]-S[l[j]]-b[x<<11|j];
			}
			else l[j]=1e9,r[j]=-1;
		}
		for (register int i=x-1;i;--i){
			for (register int j=1;j<=n;++j)S[j]=S[j-1]+(u[x<<11|j]<=i?b[x<<11|j]:0);
			for (register int j=n+1;j;--j){
				if (flag[i<<11|j]){
					l[j]=min(l[j+1],l[j]);
					r[j]=max(r[j+1],r[j]);
					if (l[j]<=r[j])val[i<<11|j]+=(S[r[j]]-S[l[j]]);
				} 
				else l[j]=1e9,r[j]=-1;
			}
		}
	}
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)ans+=val[i<<11|j]*b[i<<11|j];
	printf("%lld\n",ans);
}


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

int main() {
	int a,b;
	cin >> a >> b;
	int c=-1;
    for(int i=0;i<2000 ;i++){
	      if(( i*8)/100 == a&& (i*10)/100 ==b ) {
		  	cout << i << endl;
			return 0; 
		  }
	}
	cout << -1<< endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<pair<long long, long long>> s;
	vector<pair<long long, long long>> c;
	for (auto i = 0; i < N; ++i)
	{
		long long a, b;
		cin >> a >> b;
		s.push_back(make_pair(a, b));
	}
	for (auto i = 0; i < M; ++i)
	{
		long long a, b;
		cin >> a >> b;
		c.push_back(make_pair(a, b));
	}

	for (auto i = 0; i < N; ++i)
	{
		auto& sp = s[i];
		auto t = -1;
		auto dist = LLONG_MAX;
		for (auto j = 0; j < M; ++j)
		{
			auto& cp = c[j];
			auto d = abs(sp.first - cp.first) + abs(sp.second - cp.second);
			if (dist > d)
			{
				dist = d;
				t = j;
			}
		}

		cout << t + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P;
map<int, int> dp;
#define REP(i, n) for (int i = 0; i < n; i++)

bool in(int target, int max) { return 0 <= target && target < max - 1; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  cout << 180 * N - 360 << endl;
  return 0;
}


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

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

    int a,b;
    // 引数の受け取り
    //
    cin >> a >> b ;
    
    cout << ((a-1)*(b-1))<< endl;
    

    // 出力
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
const int maxn=1e5+10;
char input[maxn];
long long dp[maxn][13];
int main()
{
    // freopen("in.txt","r",stdin);
    scanf("%s",input+1);
    for(int i=1;i<=12;i++) dp[0][i]=0;dp[0][0]=1;
    int i;for(i=1;input[i];i++)
    {
        for(int j=0;j<=12;j++) dp[i][j]=0;
        if(input[i]=='?')
        {
            for(int now=0;now<=9;now++)
            {
                for(int j=0;j<=12;j++)
                {
                    int k=j*10+now;
                    dp[i][k%13]=(dp[i][k%13]+dp[i-1][j])%mod;
                }
            }
        }else
        {
            int now=input[i]-'0';
            for(int j=0;j<=12;j++)
            {
                int k=j*10+now;
                dp[i][k%13]=(dp[i][k%13]+dp[i-1][j])%mod;
            }
        }
    }
    printf("%lld",dp[i-1][5]);
    return 0;
}

Measured memory_bytes: 10496
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
using namespace std;

long long solve(string N, int K) {
    vector<long long> dp = vector<long long>(5, 0);
    vector<long long> topdp = vector<long long>(5, 0);
    dp[0] = 1;
    dp[1] = N[0] - '1';
    topdp[1] = 1;
    bool moveTop = false;
    for (int i = 1; i < N.size(); i++) {
        int x = N[i] - '0';
        for (int j = 3; j >= 1 ; j--) {
            if (x > 0) {
                dp[j] = dp[j-1] * 9 + dp[j] + topdp[j-1] * (x-1) + topdp[j];
            } else {
                dp[j] = dp[j-1] * 9 + dp[j];
            }
        }
        if (x > 0) {
            for (int j = 4; j >= 1 ; j--) {
                topdp[j] = topdp[j-1];
            }
        }
//        cout << topdp[1];
    }
    return dp[K] + topdp[K];
}

long long test(int N, int K) {
    int sum = 0;
    for (int i = 1; i <= N; i++) {
        int num = 0;
        int j = i;
        while (j > 0) {
            if (j % 10 > 0) {
                num++;
            }
            j /= 10;
        }
        if (num == K) {
            sum++;
        }
    }
    return sum;
}

int main()
{
    std::cout<<std::fixed<<std::setprecision(10);
    
    string N;
    int K;
    cin >> N >> K;
    
    cout << solve(N, K);
//    cout << test(stoi(N), K);
    
    
    return 0;
}

struct M {
    long long X;
    long long H;

    bool operator<(const M &another) const
    {
        return X < another.X;
    };
};

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int b = -1, e;
  for(int i = 0; i < s.length(); i++) {
    if(s[i] == 'A' && b == -1)
      b = i;
    if(s[i] == 'Z')
      e = i;
  }
  cout << e - b + 1 << "\n";
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    vector<mint> cnt(100001, 0);
    for (int i = k; i >= 1; --i) {
        mint multi = (k - i + 1 + i - 1) / i;
        cnt[i]     = mint(multi).pow(n);
        for (int j = i * 2; j <= k; j += i) {
            cnt[i] -= cnt[j];
        }
    }
    mint ret = 0;
    for (lint i = 1; i <= k; ++i) {
        ret += cnt[i] * i;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 4788
i;
p(a,b){for(i=0;i++<b;)putchar(a);}

int main(void){

    int x,y,u,v;
    scanf("%d%d%d%d",&u,&v,&x,&y);
    
    x-=u;
    y-=v;
    //85:U 82:R 68:D 76:L
    p(85,y);
    p(82,x+1);
    p(68,y+1);
    p(76,x+1);
    p(85,1);
    p(76,1);
    p(85,y+1);
    p(82,x+1);
    p(68,y+1);
    p(76,x);
    
}

Measured memory_bytes: 1644
#include<iostream>
#include<chrono>
#include<cmath>

using namespace std;

#define MOD 1000000007

// modpow 
// 繰り返し二乗法を利用し, 高速に a^n% mod p を計算する
// 計算量：O(log(n))
long long modpow(long long  a, long long n, long long mod) {
    int res = 1;
    if (n==1) return a % mod;
    if (n % 2 == 1) return (a * modpow(a, n-1, mod)) % mod;
    long long t = modpow(a, n/2, mod);
    return (t * t) % mod;
}

long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 返り値：a, b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) を格納する.
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if(b==0) {
        x = 1;
        y = 0;
        return a;
    }
    long long r = a%b;
    long long d = extGCD(b, r, y, x);
    // x = t, y = s-q*t
    y -= a/b * x;
    return d;
}

// 逆元計算
// フェルマーの小定理を利用版
// 利用条件：p が素数
// 計算量 O(log(p))
long long modinv(long long a, long long p) {
    return mod(modpow(a, p-2, p), p);
}

long long modinv_extGCD(long long a, long long p) {
    long long x, y;
    long long d = extGCD(a, p, x, y);
    if (x < 0) x += p;
    return x;
}

long long mod_comb(long long n, long long k, long long p) {
    long long res = 1;
    for(long long i=n; i>=n-k+1; i--) {
        res *= i;
        res %= p;
    }
    for(long long i=1; i<=k; i++) {
        res *= modinv(i, p);
        res %= p;
    }
    return res;
}

int main() {

    // chrono::system_clock::time_point start, end;

    // start = chrono::system_clock::now();

    // long long ans = mod_comb(1000000000, 4, MOD);

    // end = chrono::system_clock::now();

    // double time = static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
    // printf("time %lf[ms]\n", time);

    // cout << ans << endl;

    // return 0;

    long long n, a, b;
    cin >> n >> a >> b;
    long long ans = modpow(2, n, MOD) - 1 - mod_comb(n, a, MOD) - mod_comb(n, b, MOD);
    while(ans < 0) {
        ans += MOD;
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
	int ans = 0;
	int x, a, b;

	cin >> x >> a >> b;

	int n = (x - a) / b;
	ans = (x - a) - b * n;

	cout << ans << endl;

	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N+1);
  for(int i = 0; i <= N; ++i) cin >> A[i];
  vector<long long> B(N+1);
  B[0] = 1;
  for(int i = 1; i <= N; ++i){
    B[i] = min<long long>(2*(B[i-1]-A[i-1]),1e14);
  }
  B[N] = A[N];
  for(int i = N-1; i >= 0; --i){
    B[i] = min(B[i],B[i+1]+A[i]);
  }
  for(int i = 0; i <= N; ++i){
    if(A[i] > B[i]){
      cout << -1 << endl;
      return 0;
    }
    if(i < N and A[i] == B[i]){
      cout << -1 << endl;
      return 0;
    }
    if(i < N and 2*(B[i]-A[i]) < B[i+1]){
      cout << -1 << endl;
      return 0;
    }
  }
  if(B[0] != 1){
    cout << -1 << endl;
    return 0;
  }
  long long ans = 0;
  for(auto e : B){
    ans += e;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4844
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
struct multi {
  ll first;
  ll second;
  ll third;
};
bool multicomp(const multi &a, const multi &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll Q, H, S, D, N;
  cin >> Q >> H >> S >> D;
  cin >> N;

  ll min1 = min(min(4 * Q, 2 * H), S);
  ll min2 = min(min(8 * Q, 4 * H), min(2 * S, D));
  cout << ((N / 2) * min2) + ((N % 2) * min1) << endl;
  return 0;
}


Measured memory_bytes: 888
#[allow(unused_macros)]
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)*}
    };
}
 
#[allow(unused_macros)]
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)*}
    };
}
 
#[allow(unused_macros)]
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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
use std::cmp::Ordering;
 
use std::cmp;
use std::cmp::min;
use std::collections::BTreeMap;
use std::process;
use std::cmp::Ord;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::BTreeSet;
use std::mem;
 
use std::ops::{Deref, DerefMut, Index, IndexMut};
use std::any::{Any, TypeId};

fn main(){
    input!{
        n:usize,
        c:i64,
        xv:[(i64, i64);n],
    }
    let mut sj = vec![0;n+10];
    let mut sz = vec![0;n+10];

    for i in 1..n+1{
        sj[i] = sj[i-1]+xv[i-1].1;
        sz[i] = cmp::max(sz[i-1], sj[i]-xv[i-1].0);
    }

    let mut nj = vec![0;n+10];
    let mut nz = vec![0;n+10];

    for i in (1..n+1).rev(){
        nj[i] = nj[i+1]+xv[i-1].1;
        nz[i] = cmp::max(nz[i+1], nj[i]-(c-xv[i-1].0));
    }
    let mut ans = 0;
    for i in 1..n+1{
        ans = cmp::max(ans, sz[i]);
        ans = cmp::max(ans, sj[i]+nz[i+1]-2*xv[i-1].0);
    }
     for i in 1..n+1{
        ans = cmp::max(ans, nz[i]);
        ans = cmp::max(ans, nj[i]+sz[i-1]-2*(c-xv[i-1].0));
    }
    println!("{}", ans);


}



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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define _sort(a) sort(a.begin(), a.end())
#define _sortd(a) sort(a.rbegin(), a.rend())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

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

  int result = 0;
  for (int i = 1; i < n; ++i) {
    string first = s.substr(0, i);
    string second = s.substr(i, s.length() - i);

    int count = 0;
    for (char c = 'a'; c <= 'z'; c++) {
      bool f_exist = false, s_exist = false;
      for (char cf : first) {
        if (cf == c) f_exist = true;
      }
      for (char cs : second) {
        if (cs == c) s_exist = true;
      }
      if (f_exist && s_exist) count++;
    }
    result = max(result, count);
  }
  p(result);
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main(){
  int A, B, C, X, n, count = 0;
  cin >> A >> B >> C >> X;

  for(int i = 0; i <= A; i++){
    if(500 * i > X) break;
    for(int j = 0; j <= B; j++){
      for(int k = 0; k <= C; k++){
        if(500 * i + 100 * j + 50 * k == X) count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int N;
int L[64];

int ruiseki[64];

int sedai;
int saisyou;
int target;
int visited[64];

int dekiru(int idx) {
	int i;
	if (idx >= N) return 1;
	if (visited[idx] >= sedai) return visited[idx] & 1;
	for (i = idx + 1; i <= N; i++) {
		int len = ruiseki[i] - ruiseki[idx];
		if (len < saisyou) continue;
		if (saisyou + target < len) break;
		if (dekiru(i)) {
			visited[idx] = sedai + 1;
			return 1;
		}
	}
	visited[idx] = sedai;
	return 0;
}

int dekirukana(void) {
	int i, j, k;
	/* doko wo saisyou ni suru ka tansaku */
	for (i = 0; i < N; i++) {
		for (j = i + 1; j <= N; j++) {
			saisyou = ruiseki[j] - ruiseki[i];
			/* toriaezu kiru */
			for (k = 1; k < N; k++) {
				int len = ruiseki[k] - ruiseki[0];
				if (len < saisyou) continue;
				if (saisyou + target < len) break;
				sedai += 2;
				if (dekiru(k)) return 1;
			}
		}
	}
	return 0;
}

int main(void) {
	int i;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 1; i <= N; i++) {
		if (scanf("%d", &L[i]) != 1) return 1;
		ruiseki[i] = ruiseki[i - 1] + L[i];
	}
	target = 0;
	if (dekirukana()) {
		puts("0");
	} else {
		int ng = 0, ok = 1000;
		while (ng + 1 < ok) {
			int mid = ng + (ok - ng) / 2;
			target = mid;
			if (dekirukana()) ok = mid; else ng = mid;
		}
		printf("%d\n", ok);
	}
	return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
ll n,m,c;
vector <vector<char>> grid;
vector <vector<ll>> mat,vis;
vector <set<ll>> g;
vector <ll> level;
//map <pair<ll,ll>,ll> mp;
pair<ll,ll> d[]={{0,1},{1,0},{0,-1},{-1,0}};
ll check(ll i,ll j)
{
    if(i>=n||i<0||j>=m||j<0)
     return 0;
    return 1; 
}
void dfs(ll i,ll j)
{
    vis[i][j]++;
    mat[i][j]=c;
    for(ll p=0;p<4;p++)
    {
        ll x=i+d[p].ff,y=j+d[p].ss;
        if(check(x,y)&&!vis[x][y]&&grid[x][y]=='.')
         dfs(x,y);
    }
}
void dfs2(ll x,ll y)
{
    vis[x][y]++;
    ll i,j,p=mat[x][y];
    for(i=x-2;i<=x+2;i++)
     for(j=y-2;j<=y+2;j++)
     {
         if(i==x&&j==y)
          continue;
         if(!check(i,j))
          continue;
         if(grid[i][j]=='#'||mat[i][j]==p)
          continue; 
         g[p].insert(mat[i][j]);
         g[mat[i][j]].insert(p); 
     }
}
void bfs()
{
    queue <ll> q;
    vector <ll> v(c+5);
    q.push(1);
    v[1]++;
    level[1]=0;
    while(!q.empty())
    {
        ll x=q.front();
        q.pop();
        for(auto u:g[x])
        {
            if(!v[u])
            {
                v[u]++;
                level[u]=level[x]+1;
                q.push(u);
            }
        }
    }
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {
       cin>>n>>m;
       grid.resize(n,vector<char>(m));
       vis.resize(n,vector<ll>(m));
       mat.resize(n,vector<ll>(m,0));
       ll i,j,sx,sy,dx,dy,ans=0;
       cin>>sx>>sy>>dx>>dy;
       for(i=0;i<n;i++)
        for(j=0;j<m;j++)
         cin>>grid[i][j];
       c=1;
       dfs(sx-1,sy-1);
       c++;
       for(i=0;i<n;i++)
        for(j=0;j<m;j++)
         if(!vis[i][j]&&grid[i][j]=='.')
          dfs(i,j),c++;
       g.resize(c+5,set<ll>()); 
       level.resize(c+5,-1);    
       vis.assign(n,vector<ll>(m,0));
       for(i=0;i<n;i++)
        for(j=0;j<m;j++)
         if(!vis[i][j]&&grid[i][j]=='.')
          dfs2(i,j); 
       bfs();
       ans=level[mat[dx-1][dy-1]]; 
       cout<<ans;
   }
}

Measured memory_bytes: 46092
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <bitset>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <string>
#include <functional>

using namespace std ;

const int eps=1e-6 ;
const int inf=0x3f3f3f3f ;

#define mp make_pair
#define pb push_back
#define first fi
#define second se
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define REP(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)

typedef unsigned long long ull ;
typedef long long ll ;

inline int read(){
    char c ;
    int f=1 ;
    while((c=getchar())<'0' || c>'9') if (c=='-') f=-1 ;
    int res=c-'0' ;
    while((c=getchar())>='0' && c<='9') res=res*10+c-'0' ;
    return res*f ;
}

const int N = 110 ; 

int n,m ;
int a[110],b[110],dp[110][110][330] ;

int main(){
    n=read();m=read();
    for (int i=1;i<=n;i++) a[i]=read(),b[i]=read() ;
    for (int i=1;i<=n;i++)
    for (int j=0;j<=i;j++)
    for (int k=0;k<=3*j;k++){
        dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]) ;
        dp[i+1][j+1][k+a[i]-a[1]]=max(dp[i+1][j+1][k+a[i]-a[1]],dp[i][j][k]+b[i]) ;
    }

    int ans=0 ;
    for (int i=0;i<=n;i++)
    for (int j=0;j<=3*i;j++){
        ll W= (ll) a[1]*i+j;
        if (W<=m) ans=max(ans,dp[n+1][i][j]) ;
    }
    printf("%d",ans) ;
    return 0 ;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e18;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define repb(bit,n,init) for(ll bit=init;bit<(1<<n);++bit)

int main()
{
    ll N;
    cin >> N;
    cout << (N/3600)%24 << ":" << (N/60)%60 << ":" << N%60 << endl;
    return 0;
}


Measured memory_bytes: 3096
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}


const ll N=2e5+5;


int main()
{ 

IOS;

ll x,k,d;
cin>>x>>k>>d;

ll x1=abs(x);

ll y=x1/d;

if(!x&&k%2==0){
  d1(0);
  return 0;
}


if(k<=y){
ll p1=abs(x+k*d);
ll p2=abs(x-k*d);
ll ans=min(p1,p2);
d1(ans);

return 0;
}

ll par1=k%2;
ll par2=y%2;

if(par1!=par2){
  ll y1=y+1;
  ll p1=abs(x+y1*d);
  ll p2=abs(x-y1*d);
  ll ans=min(p1,p2);
 // d1(ans);
  if(y){
    ll y2=y-1;
    ll p3=abs(x+y2*d);
    ll p4=abs(x-y2*d);
   // d2(p3,p4);
    ans=min({ans,p3,p4});
  }
  d1(ans);
return 0;
}

 ll p1=abs(x+y*d);
  ll p2=abs(x-y*d);
  ll ans=min(p1,p2);

  d1(ans);
/*
if(y&1){
  if(k&1){
    ll p1=abs(x+y*d);
    ll p2=abs(x-y*d);
    ll ans=min(p1,p2);
    d1(ans);
  }
  else {
    ll y2=y+1;


  }
}

*/

//end_routine();

return 0;
 
 }


Measured memory_bytes: 3648
import math
N, P = map(int, input().split())
A = list(map(int, input().split()))
even = 0
odd = 0
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(N):
    if A[i] % 2 == 0:
        even += 1
    else:
        odd += 1

oddcmb = 0
if P == 0:
    for i in range(odd+1)[::2]:
        # print(i)
        oddcmb += comb(odd, i)
    ans = 2**even*oddcmb
    # oddcmb = comb()
else:
    for i in range(1, odd+1)[::2]:
        # print(i)
        oddcmb += comb(odd, i)
    ans = 2**even*oddcmb

print(ans)

Measured memory_bytes: 3064
//#i#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}


struct UnionFind{
    int size;
    std::vector<int> par;
    std::vector<int> rank;
    UnionFind(int x){
        size=x;
        par=std::vector<int> (x);
        rank=std::vector<int> (x,1);
        for (int i=0;i<x;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        else return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        x=root(x);y=root(y);
        if(x==y) return;
        if(rank[x]<rank[y]) par[x]=y;
        else par[y]=x;
        if(rank[x]==rank[y]) rank[x]++;
    }
    bool check(int x,int y){
        return root(x)==root(y);
    }
    void initialize(){
        for (int i=0;i<size;i++){
            par[i]=i;rank[i]=1;
        }
    }
};

using namespace std;

int main(){
	int n,q;
	cin >> n >> q;
	UnionFind uf(n);
	rip(i,q,0){
		int c,x,y;
		cin >> c >> x >> y;
		if(c==0) uf.unite(x,y);
		else cout << uf.check(x,y) << '\n';
	}
	return 0;
}


Measured memory_bytes: 3184
import java.util.*;
public class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		sc.close();
		if((A+B)%2==0) {
			System.out.println((A+B)/2);
		}else {
			System.out.println("IMPOSSIBLE");
		}
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
const ll MOD=1e9+7;
using namespace std;

ll a[1005];
int main(){
  ll N;
  cin >> N;
  vector<ll> a(N),b;
  rep(i,N){
    cin >> a[i];
  }
  sort(All(a));
  for(ll i=0;i<N-1;i++){
    if(a[i]==a[i+1]){
      b.push_back(a[i]);
      i++;
    }
  }
  if(b.size()<2) {
    cout << 0 << endl;
    return 0;
  }
  cout << b[b.size()-1]*b[b.size()-2] << endl;
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	
	std::vector<int> V;
	for( int ii = 0; ii < N; ++ii ){
		int tmp;
		cin >> tmp;
		V.push_back(tmp);
	}
	
	std::vector<int> C;
	for( int ii = 0; ii < N; ++ii ){
		int tmp;
		cin >> tmp;
		C.push_back(tmp);
	}
	
	//---------
	
	int max = 0;
	for( int ii = 0; ii <= N ; ++ii ){
		int trueValue = V[ii] - C[ii];
		if(trueValue > 0){
			max += trueValue;
		}
	}

	cout << max << endl;
	
	return 0;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
N = I()
S = input()
left = 0
right = 0
for i in range(N):
    if S[i] == '(':
        right += 1
    if S[i] == ')':
        if right >= 1:
            right -= 1
        else:
            left += 1
print('('*left + S + ')'*right)


Measured memory_bytes: 10456
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
  int n,m;cin>>n>>m;
  vector<int> v[n+1];
  rep(i,0,m){
    int a,b;cin>>a>>b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int qq;cin>>qq;
  int t[qq],d[qq],c[qq];
  rep(i,0,qq)cin>>t[i]>>d[i]>>c[i];
  int col[n+1];
  fill(col,col+n+1,0);
  int dp[n+1];
  fill(dp,dp+n+1,-1);
  rrep(i,qq-1,0){
    if(dp[t[i]]>=d[i])continue;
    queue<pii> q;q.push({t[i],d[i]});
    while(q.size()>0){
      pll p=q.front();q.pop();
      int now=p.first,dis=p.second;
      if(col[now]==0)col[now]=c[i];
      dp[now]=dis;
      if(dis==0)continue;
      rep(j,0,v[now].size()){
        int ne=v[now][j];
        if(dp[ne]>=dis-1)continue;
        q.push({ne,dis-1});
      }
    }
  }
  rep(i,1,n+1)cout<<col[i]<<endl;
}

Measured memory_bytes: 8912
#include<bits/stdc++.h>
#define rap(i,n) for(int i=0;i<n;++i)
using namespace std;
signed main(){
	int n,a[1000000],max1=0,max2=0;
  cin>>n;
  rap(i,n){
    cin>>a[i];
  }
  rap(i,n){
    if(max1<a[i]){
      max1=a[i];
    }else if(max2<a[i]){
      max2=a[i];
    }
  }
  rap(i,n){
    if(max1==a[i]){
      cout<<max2<<"\n";
    }else{
      cout<<max1<<"\n";
    }
  }
  return(0);
}

Measured memory_bytes: 4224
inf = 10**10
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))
ans = inf
for a in range(-100,101):
    cur = 0
    for i in range(n):
        cur += (A[i]-a)**2
    ans = min(ans,cur)
print(ans)

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(5e2 + 5);
const int MAX_M = (int)(2e5 + 5);
const int MAX_Q = (int)(1e5 + 5);

int n, m, q;
int cnt[MAX_N][MAX_N];

int memo[MAX_N][MAX_N];

int solve(int p, int q) {
  auto key = make_pair(p, q);
  if (memo[p][q] != -1) return memo[p][q];

  if (p > q) return 0;

  int ret = cnt[p][q];

  if (p == q) {
    return memo[p][q] = ret;
  }

  ret += solve(p + 1, q);
  ret += solve(p, q - 1);
  ret -= solve(p + 1, q - 1);

  return memo[p][q] = ret;
}

int main(void) {
  // Here your code !
  scanf("%d %d %d", &n, &m, &q);

  for (int i = 0; i < m; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    cnt[l][r] += 1;
  }

  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= n; ++j) {
      memo[i][j] = -1;
    }

  for (int i = 0; i < q; ++i) {
    int p, q;
    scanf("%d %d", &p, &q);

    int ans = solve(p, q);

    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 2944
#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <cstring> 
#include <climits> 
#include <cfloat> 
#include <map> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <numeric>
#include <cassert>

#define FOR(i, min, max) for (int i = (min); i < (max); ++i) 
#define FORE(i, min, max) for (int i = (min); i <= (max); ++i) 
#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define REPV(vec, i) for (int i = 0; i < (int)(vec.size()); ++i) 
#define FOR_EACH(vec, it) for (typeof((vec).begin()) it = (vec).begin(); it != (vec).end(); ++it)

using namespace std; 
static const double EPS = 1e-12; 
typedef long long ll; 

template<typename T>
vector<T> getVector(int N) {
    vector<T> v(N);
    REP(i, N) cin >> v[i];
    return v;
}

int main(void)
{
    int S, W;
    cin >> S >> W;
    if (S <= W)
        cout << "unsafe" << endl;
    else
        cout << "safe" << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N, Q;
    string S;
    cin >> N >> Q;
    cin >> S;

    vector<int> l(Q), r(Q);
    for(int i = 0; i < Q; i++) {
        cin >> l[i] >> r[i];
    }

    vector<int> sum(N + 1, 0);

    // ACが出る可能性があるのは2文字目から(0-indexedで1から)
    for(int i = 1; i < N; i++) {
        sum[i + 1] = sum[i];
        if(S[i - 1] == 'A' && S[i] == 'C') {
            sum[i + 1]++;
        }
    }

    for(int i = 0; i < Q; i++) {
        int ans = sum[r[i]] - sum[l[i]];
        cout << ans << endl;
    }
}


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

signed main(){
  char C;
  cin>>C;
  string ans="consonant";
  if(C=='a'||C=='e'||C=='i'||C=='u'||C=='o')ans="vowel";
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
  int n;
  std::cin >> n;
  int l[100];
  for (int i=0; i<n;++i)
  {
    std::cin >> l[i];
  }
  int ans = 0;
  for (int i=0;i<n-2;++i)
  {
    for (int j=i+1;j<n-1;++j)
    {
      for (int k=j+1;k<n;++k)
      {
        if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i])
        {
          continue;
        }
        if (l[i] > l[j] && l[i] > l[k] && l[i] < l[j] + l[k])
        {
          ans++;
        }
        else if (l[j] > l[k] && l[j] > l[i] && l[j] < l[k] + l[i])
        {
          ans++;
        }
        else if (l[k] > l[i] && l[k] > l[j] && l[k] < l[j] + l[i])
        {
          ans++;
        }
      }
    }
  }
  std::cout << ans;
  
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>

using namespace std;

int main(){
	int o,n,d[6],e[6];
	string r;

	while(1){
		cin >> n;
		if(n != 0){

			o = 1;
			for(int i = 0; i < 6; i++){
				d[i] = e[i] = i+1;
			}

			for(int i = 0; i < n; i++){
				cin >> r;

				switch(r.at(0)){
					case 'N':
						e[0] = d[1];
						e[1] = d[5];
						e[5] = d[4];
						e[4] = d[0];
						break;
					case 'E':
						e[0] = d[3];
						e[3] = d[5];
						e[5] = d[2];
						e[2] = d[0];
						break;
					case 'W':
						e[0] = d[2];
						e[2] = d[5];
						e[5] = d[3];
						e[3] = d[0];
						break;
					case 'S':
						e[0] = d[4];
						e[4] = d[5];
						e[5] = d[1];
						e[1] = d[0];
						break;
					case 'R':
						e[1] = d[2];
						e[2] = d[4];
						e[4] = d[3];
						e[3] = d[1];
						break;
					case 'L':
						e[1] = d[3];
						e[3] = d[4];
						e[4] = d[2];
						e[2] = d[1];
						break;
				}

				for(int j = 0; j < 6; j++){
					d[j] = e[j];
				}

				o += d[0];
			}

			cout << o << endl;
		}else{
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 0
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
fun solve(N: Int, M: Int, P: IntArray, Y: IntArray) {
    val prefs = Array<MutableList<Int>>(N + 1) { mutableListOf<Int>() }
    val ps = (0 until M)
        .map { Pair(P[it], Y[it]) }
        .sortedBy{ it.second }
    for (i in 0 until M) { prefs[ps[i].first].add(ps[i].second) }
    for (i in 0 until M) {
        val cityID = prefs[P[i]].binarySearch(Y[i]) + 1
        pw.println("${P[i]}".padStart(6, '0') + "$cityID".padStart(6, '0'))
    }
    pw.flush()
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val M = sc.next().toInt()
    val P = IntArray(M)
    val Y = IntArray(M)
    for (i in 0 until M) {
        P[i] = sc.next().toInt()
        Y[i] = sc.next().toInt()
    }
    solve(N, M, P, Y)
}


Measured memory_bytes: 92112
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m, V, p;
    cin >> n >> m >> V >> p;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(rall(a));

    // 判定問題「a[x]は問題セットに採用される可能性があるか？」を二分探索で解く
    ll left = 0;
    ll right = n;
    while(right - left > 1) {
        ll x = (left + right)/2;
        if(x < p) {
            left = x;
            continue;
        }
        if(a[x] + m < a[p-1]) {
            right = x;
            continue;
        }
        ll cnt = m*((p-1) + (n-x));
        exrep(i, p-1, x-1) {
            cnt += a[x] + m - a[i];
        }
        if(cnt < m*V) {
            right = x;
        }
        else {
            left = x;
        }
    }

    out(right);
    re0;
}

Measured memory_bytes: 1024
#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 mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0; i<x; i++)
#define repn(i,x) for(int 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())

int main() {
    int n, k;
    cin >> n >> k;
    double ans = 0;
    for (int i = 1; i <= n; i++)
    {
        double p = 1;
        int x = i;
        while (x > 0 && x < k) {
            p *= 0.5;
            x *= 2;
        }
        ans += p / n;
    }
    printf("%.12f\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
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(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

lint gcd(lint p, lint q){
    if(p < q) swap(p, q);
    while(q){
        lint r = p % q;
        p = q;
        q = r;
    }
    return p;
}

int main(){
    int n;
    scanf("%d", &n);
    lint g[n+1][n+1];
    For(i, 1, n+1)For(j, 1, n+1){
        g[i][j] = gcd(i, j);
    }
    lint ans = 0;
    For(a, 1, n+1)For(b, 1, n+1)For(c, 1, n+1){
        ans += g[g[a][b]][c];
    }
    printf("%lld\n", ans);
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i32 n,k; cin >> n >> k;
    vi h(n); rep(i,n) cin >> h[i];

    i32 ans = inf;
    sort(all(h));
    for(i32 i = 0, j = k-1; j < n; ++i, ++j) {
        chmin(ans, h[j]-h[i]);
    }

    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 4020