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

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),* $(,)*) => {
        #[cfg(debug_assertions)]
        eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
    };
}

#[derive(Clone, Copy, PartialEq)]
pub struct Point {
    pub x: isize,
    pub y: isize,
}

fn cross3(p0: Point, p1: Point, p2: Point) -> isize {
    (p2.x - p0.x) * (p1.y - p0.y) - (p1.x - p0.x) * (p2.y - p0.y)
}

fn graham_scan(points: &[Point]) -> Vec<usize> {
    let mut indices = (0..points.len()).collect::<Vec<_>>();
    indices.sort_by_key(|&i| (points[i].x, points[i].y));
    indices.dedup_by_key(|i| points[*i]);

    if indices.len() <= 2 {
        return indices;
    }

    let mut upper = vec![];
    for &k in &indices {
        while upper.len() >= 2
            && cross3(
                points[upper[upper.len() - 2]],
                points[upper[upper.len() - 1]],
                points[k],
            ) <= 0
        {
            upper.pop();
        }
        upper.push(k);
    }

    let mut lower = vec![];
    for &k in &indices {
        while lower.len() >= 2
            && cross3(
                points[lower[lower.len() - 2]],
                points[lower[lower.len() - 1]],
                points[k],
            ) >= 0
        {
            lower.pop();
        }
        lower.push(k);
    }

    lower.reverse();
    upper.pop();
    lower.pop();
    for &k in &lower {
        upper.push(k);
    }
    upper
}

fn dist(i: usize, j: usize, xy: &Vec<(isize, isize)>) -> isize {
    let (x1, y1) = xy[i];
    let (x2, y2) = xy[j];
    (x1 - x2).abs() + (y1 - y2).abs()
}

fn main() {
    input! {
        n: usize,
        xy: [(isize, isize); n],
    }

    let points = xy
        .iter()
        .map(|&(x, y)| Point { x, y })
        .collect::<Vec<Point>>();
    let ch = graham_scan(&points);

    let mut p = vec![];
    for &i in &ch {
        debug!(xy[i]);
        p.push(i);
    }
    for &i in &ch {
        p.push(i);
    }
    debug!(p);

    let mut result = 0;
    let mut l = 0;
    for k in 0..ch.len() {
        if l < k {
            l = k;
        }
        let mut d0 = dist(p[k], p[l], &xy);
        let d = loop {
            if l + 1 >= p.len() {
                break d0;
            }
            let d = dist(p[k], p[l + 1], &xy);
            // debug!(k, l + 1);
            // debug!(xy[p[k]], xy[p[l + 1]]);
            // debug!(p[k], p[l + 1], d, d0);
            if d <= d0 {
                if l > k {
                    l -= 1;
                }
                break d0;
            }
            l += 1;
            d0 = d;
        };
        // debug!(d);
        result = max(result, d);
    }
    println!("{}", result);
}


Measured memory_bytes: 14508
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

typedef long long i64; 
typedef vector< int > vi;
typedef vector< i64 > vi64;
typedef pair< int, int > pi;
typedef vector< pair< int, int > > vpi;

void crypt() {
	int pos[3], curr;
	FILL(pos, 0);
	string cards[3];
	forn(i, 3) cin >> cards[i];
	curr = pos[0];
	while (1) {
		if (pos[curr] == (int) cards[curr].size()) {
			cout << (char)('A' + curr) << "\n";
			return;
		} else {
			int temp = curr;
			curr = cards[curr][pos[curr]] - 'a';
			pos[temp] += 1;
		}   			
	}
}

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	cout << fixed;
	int t = 1; 
//	cin >> t;
	while (t--) crypt();
	return 0;
}

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

int main(){
    
    size_t n;

    std::cin >> n;

    std::vector<size_t> d(n);

    for(auto&& e : d){
        std::cin >> e;
    }

    std::sort(d.begin(), d.end());

    std::cout << d[n / 2] - d[n / 2 - 1] << std::endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n , x) for (int i = (int)(x); i < (int)(n); ++i)
#define repB(i, n) for (int i = n; i >= 1; --i)
#define repBX(i, n , x) for (int i = (int)(n); i >= int(X); --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int K,X;
    cin >> K >> X;
    cout << ((500 * K >= X) ? "Yes" : "No") << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//nCrを返す関数.
long long int comb(long long int n, long long int r){
	if(n < r || n < 0)
		return 0;
	long long int x = 1, y = 1;
	if (n-r < r) r = n - r;
	for (long long int i = 0; i < r; i++)
	{
		x = x * (n - i);
		y = y * (i + 1);
	}
	return x / y;
}


int main(){
	ll a,b;
	cin >> a >> b;
	if((a+b)%2==0){
		cout << (a + b) / 2 << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var;
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;


int main(){


	int N, M, X; std::cin >> N >> M >> X;
	std::vector<int> A(M);


	int right = 0;
	int left = 0;
	rep(i, M){
		int A; std::cin >> A;
		if(A > X)right++;
		else left++;
	}

	std::cout << std::min(right, left);


	return 0;
}


Measured memory_bytes: 256
//#pragma GCC oplmize(2)
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define sc(x) scanf("%lld",&x)
#define scs(x) scanf("%s",x+1)
#define pr(x) printf("%lld\n",x)
#define prs(x) printf("%s\n",x)
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
const double pi=acos(-1.0);
const double eps = 1e-8;
ll t,n,x;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    sc(n),sc(x),sc(t);
    if(n%x==0) pr(n/x*t);
    else pr((n/x+1)*t);
    return 0;
}


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 500100, MAXK = 30;
const ll MOD = 998244353;
const ll INF = 1e15;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

int n;
ll a[MAXN];
ll dp[MAXN][5];
bool found[MAXN][5];

int main() {
	setIO();

    cin >> n;
    FOR(i, 1, n) cin >> a[i];

    FOR(i, 0, n) FOR(j, 0, 4) dp[i][j] = -INF;
    FOR(i, 0, n) FOR(j, 0, 4) found[i][j] = false;

    FOR(i, 1, n) FOR(j, 0, 2) {

        ll mx = -INF;

        FOR(k, 0, j) {
            if (i > k+2 && found[i-2-k][j-k]) {
                mx = max(mx, dp[i-2-k][j-k]);
                found[i][j] = true;
            }
        }
//cout << " mx=" << mx << " =inf=" << (-INF) << endl;
        if (mx > (-INF)) dp[i][j] = mx;
        else if (i == j+1) {
            mx = 0ll;
            found[i][j] = true;
        }
//cout << " mx=" << mx << " =inf=" << (-INF) << endl;

        dp[i][j] = mx;

        if (found[i][j])dp[i][j] += a[i];
        else dp[i][j] = -INF;

        //cout << " i=" << i << " j=" << j << " dp(i,j)=" << dp[i][j] << endl;
    }

    ll ans = -INF;
    if (n%2 == 0) {
        ans = max(ans, dp[n-1][0]);
        ans = max(ans, dp[n][1]);
    } else {
        ans = max(ans, dp[n-2][0]);
        ans = max(ans, dp[n-1][1]);
        ans = max(ans, dp[n][2]);
    }

    cout << ans;

	return 0;
}




Measured memory_bytes: 14024
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;
void change(string& s) {
    vector<Int> v(26, 0);
    for (Int i = 0; i < (Int)s.length(); ++i) {
        v[s[i] - 'a']++;
    }
    s = "";
    for (Int i = 0; i < 26; ++i) {
        for (Int j = 0; j < v[i]; ++j) {
            s += ('a' + i);
        }
    }
    return;
}

int main(void) {
    Int n;
    cin >> n;
    vector<string> s(n);
    for (Int i = 0; i < n; ++i) {
        cin >> s[i];
        change(s[i]);
    }
    sort(s.begin(), s.end());

    Int result = 0;
    Int start = 0;
    Int end = 0;
    for (Int i = 1; i < n; ++i) {
        if (s[i] == s[i - 1]) {
            end++;
        } else {
            result += ((end - start) * (end - start + 1) / 2);
            start = i;
            end = i;
        }
    }
    result += ((end - start) * (end - start + 1) / 2);
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 6368
#include <iostream>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const int MAX=2e5;

ll fact[MAX+1],factInv[MAX+1];

inline void factorial(ll n) {
  fact[0]=fact[1]=1;
  for (int i=2; i<=n; i++) {
    fact[i]=(i*fact[i-1])%MOD;
  }
}
inline ll power(ll x,ll n) {
  if (n==0) {
    return 1LL;
  }
  ll ret=power((x*x)%MOD,n/2)%MOD;
  if (n%2) {
    ret=(ret*x)%MOD;
  }
  return ret;
}
inline void factorial_Inverse(ll x) {
  factInv[x]=power(fact[x],MOD-2);
  for (int i=x-1; i>=1; i--) {
    factInv[i]=((factInv[i+1]*(i+1))%MOD);
  }
}
inline void init(ll n) {
  factorial(n);
  factorial_Inverse(n);
}
inline ll nCr(ll n,ll r) {
  if (n<r || r<0) {
    return 0LL;
  }
  if (n==r || r==0) {
    return 1LL;
  }
  return (((fact[n]*factInv[r])%MOD)*factInv[n-r])%MOD;
}
inline ll nPr(ll n,ll r) {
  if (n<r || r<0) {
    return 0LL;
  }
  return (fact[n]*factInv[r])%MOD;
}
int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int H,W,A,B;
  cin>>H>>W>>A>>B;
  init(MAX);
  ll ans=0;
  for (int i=B; i<W; i++) {
    ans=(ans+(nCr(H-A-1+i,i)*nCr(A-1+W-i-1,W-i-1)))%MOD;
  }
  cout<<ans<<endl;
  return 0;
}


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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int N;
    cin >> N;

    int A, B;
    vector<pair<int, int>> BA;
    for (int i=0; i<N; ++i) {
        cin >> A >> B;
        BA.emplace_back(B, A);
    }
    sort(BA.begin(), BA.end());

    long long t = 0;
    for (int i=0; i<N; ++i) {
        t += BA[i].second;
        if (BA[i].first < t) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 2420
const Main = (stdin) => {
  const inputs = stdin.split(' ');
  const a = inputs[0];
  const b = inputs[1];
  const c = a * b;
  if (c % 2 === 1) {
    console.log('Odd');
  } else {
    console.log('Even');
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
    long long int a, aux, soma = 0;
    cin >> a;
    aux = a;
    while(a > 0){
        soma = soma + a % 10;
        a /= 10;
    }
    
    if(aux % soma == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,a[200005],i,j;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(i=1;i<n;i++)
	{
		if(a[i]==a[i-1])
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 1792
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    FOR(i, 0, n) {
        cin >> s[i];
    }
    vector<int> moji(26, 100000);
    FOR(i, 0, n) {
        vector<int> moji_tmp(26, 0);
        for (auto c : s[i]) {
            moji_tmp[c - 'a']++;
        }
        FOR(j, 0, 26) {
            moji[j] = min(moji[j], moji_tmp[j]);
        }
    }
    FOR(i, 0, 26) {
        FOR(j, 0, moji[i]) {
            cout << (char)(i + 'a');
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	int max=a[0];
	int total = 0; int count=0;
	for (int i = 0;i < 3;i++) {
		total += a[i];
		if (max < a[i])
			max = a[i];
	}
	if ((2*max - (total - max)) % 2 == 0)
		count = (3 * max - total) / 2;
	else count = (3 * max - total) / 2 + 2;
	cout << count;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    vector<string> vc(n);
    rep(i,n) cin >> vc.at(i);
    bool res = true;
    char head, tail = vc.at(0).at(vc.at(0).size() - 1);
    for(int i=1; i<n; i++){
        head = vc.at(i).at(0);
        if(tail != head){
            res = false;
            break;
        }
        tail = vc.at(i).at(vc.at(i).size() - 1);
    }
    sort(vc.begin(), vc.end());
    if(res){
        rep(i,n-1){
            if(vc.at(i) == vc.at(i+1)){
                res = false;
                break;
            }
        }
    }
    if(res){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


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

int tot=0,h[100005];
int n,x,y,siz[100005],f[100005];
struct Edge{
    int x,next;
}e[200005];

inline void add_edge(int x,int y){
    e[++tot].x=y;
    e[tot].next=h[x],h[x]=tot;
}

bool dfs(int x,int fa){
    siz[x]=1;
    int cnt=0;
    for(int i=h[x];i;i=e[i].next){
        if(e[i].x==fa)continue;
        if(dfs(e[i].x,x))return true;
        if(siz[e[i].x]){
            cnt++,siz[x]=0;
            if(cnt==2)return true;
        }
    }
    return false;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        scanf("%d%d",&x,&y);
        add_edge(x,y);
        add_edge(y,x);
    }
    printf(dfs(1,0)||siz[1]?"First":"Second");
}

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
signed main() {
  int n; cin >> n;
  int buttons[n];
  REP(i,n) {
    cin >> buttons[i];
    --buttons[i];
  }
  unordered_map<int, bool> have_seen;
  int next = 0;
  int counter = 0;
  while(next != 1 && !have_seen[next]) {
    have_seen[next] = true;
    next = buttons[next];
    ++counter;
  }
  if(next == 1) {
    cout << counter << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 5156
#include<bits/stdc++.h>
using namespace std;
const int N=2e5;
bool v[N];
int n,a[N],l,r;
bool C(int k)
{
	for(int i=1;i<n+n;i++)
		v[i]=(a[i]>=k);
	for(int i=1;i<n;i++)
	{
		if(v[n+i]==v[n+i-1])
			return v[n+i];
		if(v[n-i]==v[n-i+1])
			return v[n-i];
	}
	return v[1];
}
int main()
{
	cin>>n;
	for(int i=1;i<n+n;i++)
		cin>>a[i];
	r=n+n;
	while(l<r)
		if(C((l+r+1)/2))
			l=(l+r+1)/2;
		else
			r=(l+r-1)/2;
	cout<<l;
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int i,a,num[100];
  cin>>a;
  for(i=0; i<a; i++){
    scanf("%d",&num[i]);
}
  i=i-1;
  while(i>0){
    printf("%d ",num[i]);
    i=i-1;
  }
  printf("%d",num[i]);
  cout<<"\n";
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k,a,b; cin >> k >> a >> b;
    ll ans = 1;
    if(b-a<=2) ans += k;
    else {
        ll n = max(0LL,(k-(a-1))/2);
        ans += n*(b-a) + (k - n*2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
    I LOVE CLARICE STARLING

     ♥LOVE♥        ♥LOVE♥
  ♥LOVE♥♥LOVE♥  ♥LOVE♥♥LOVE♥
♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
   ♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
      ♥LOVE♥♥LOVE♥♥LOVE♥
         ♥LOVE♥♥LOVE♥
            ♥LOVE♥
               ♥


        EXPLAINATION BELOW->
        Read Editorial first
      
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
ll gcd(ll a,ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
          
} 
void solve()
{
  ll a,b,c,k,sum=0;cin>>k;
  foe(a,1,k)
  foe(b,1,k)
  foe(c,1,k)
  sum+=gcd(a,gcd(b,c));
  
  cout<<sum<<"\n";
}
int main()
{
   fastio
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

Measured memory_bytes: 3536
#include<bits/stdc++.h>
#define eb emplace_back
typedef long long ll;

using namespace std;

signed main(void){
  
  int L; cin >> L;
  
  int a;
  
  for(int i = 0; i < 20; i++){ 
    if( (L >> i) & 1 ){ a = i;}
  }
  //a+1個のノードが必要
  
  vector<tuple<int,int,int>> ans;
  
  for(int i = 0; i < a; i++){
    ans.eb(i,i+1,0);
    ans.eb(i,i+1,pow(2,i));
  }
  
  int res = pow(2,a);
  for(int i = a-1; i >= 0; i--){ 
    if(  ( L >> i ) & 1 ){
      ans.eb(i,a,res);
      res += pow(2,i);
    }
  }
  
  cout << a+1 << " " <<  ans.size() << endl;
  
  for(auto ne : ans){
    cout << get<0>(ne)+1 << " " << get<1>(ne)+1 << " " << get<2>(ne) << endl;
  }
  
  return 0;
}
  

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

class UnionFind
{
public:
    vector<int> parent;
    vector<int> sz;
    
    UnionFind(int n): parent(n), sz(n)
    {
        for(int i=0;i<n;i++)
        {
            parent[i] = i;
            sz[i] = 1;
        }
    }
    int root(int x) {return parent[x]==x ? x : parent[x] = root(parent[x]);}
    bool same(int x, int y) {return root(x)==root(y);}
    void unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (sz[x] < sz[y])
            {
                parent[x] = y;
                sz[y] += sz[x];
            }
            else
            {
                parent[y] = x;
                sz[x] += sz[y];
            }
        }
    }
    int size(int x) {return sz[root(x)];}
};

#include <iostream>
#include <functional>
#include <set>

int main()
{
    int N;
    cin>>N;
    vector<int> P(N);
    for (int &p: P)
        cin>>p, p--;

    UnionFind UF(N);
    for (int i=0; i<N; i++)
        if (P[i]>=0)
            UF.unite(i, P[i]);
    vector<int> V;
    for (int i=0; i<N; i++)
        if (P[i]<0)
            V.push_back(UF.size(i));
    int K = (int)V.size();

    long long M = 1000000007LL;

    //  要請方法の総数
    long long t = 1;
    for (int i=0; i<K; i++)
        t = t*(N-1)%M;

    //  すでにできている閉路
    set<int> S;
    for (int i=0; i<N; i++)
        S.insert(UF.root(i));
    int c = (int)S.size()-K;

    long long ans = (N-c)*t%M;

    //  T[i]: Vの中からi個選んで掛け合わせた数の和
    vector<long long> T(K+1);
    T[0] = 1;
    for (int i=0; i<K; i++)
        for (int j=i; j>=0; j--)
            T[j+1] = (T[j+1]+T[j]*V[i])%M;

    //  サイズkの閉路の寄与分を引いていく
    for (int k=1; k<=K; k++)
    {
        long long t = 1;
        for (int i=1; i<k; i++)
            t = t*i%M;
        if (k==1)
            t = t*((T[k]-K+M)%M)%M;
        else
            t = t*T[k]%M;
        for (int i=k; i<K; i++)
            t = t*(N-1)%M;
        ans = (ans-t+M)%M;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3460
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#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;

ll ceil(ll a, ll b) {  // a÷b以上の最小の整数
    if(b == 0) {
        return 0;
    }
    if(a%b == 0) {
        return a/b;
    }
    else {
        return a/b + 1;
    }
}

int main() {
    ll h, w, n;
    cin >> h >> w >> n;
    out(ceil(n, max(h, w)));
    re0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
    int N, T, A;
    int H[100001];
    scanf("%d", &N);
    scanf("%d %d", &T, &A);
    int i;
    for (i = 0; i < N; i++){
        scanf("%d", &H[i]);
    }

    double min = 100000;
    int num;
    for (i = 0; i < N; i++){
        if (min > fabs(A-(T-0.006*H[i]))){
            num = i + 1;
            min = fabs(A-(T-0.006*H[i]));
        }
    }
    printf("%d\n", num);


    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
	int i, N, A[82];
	long long X = 1000, Y;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	A[N+1] = 0;
	for (i = 1; i <= N; i++) {
		for (; i <= N && A[i+1] <= A[i]; i++);
		if (i <= N) {
			Y = X / A[i];
			X %= A[i];
			for (i++; A[i+1] >= A[i]; i++);
			X += Y * A[i];
		}
	}
	printf("%lld\n", X);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1736
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrD = list(map(int,input().split()))
M = int(input())
arrT = list(map(int,input().split()))

cntD = Counter(arrD)
cntT = Counter(arrT)

for dif,cnt in cntT.items():
    if dif in cntD:
        if cnt > cntD[dif]:
            print("NO")
            exit()
    else:
        print("NO")
        exit()

print("YES")
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 57056
MOD = 10**9+7
fac = [1, 1]
f_inv = [1, 1]
inv = [0, 1]

def prepare(n, mod):
    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod//i)) % mod)
        f_inv.append((f_inv[-1] * inv[-1]) % mod)


def modcmb(n, r, mod):
    if n < 0 or r < 0 or r > n:
        return 0

    return fac[n] * f_inv[r] * f_inv[n-r] % mod


def f(r, c):
    return modcmb(r+c, r, MOD)


def g(x, y):
    return ((y+2) * modcmb(x+y+2, x, MOD) - (x+1)) * pow(x+1, MOD-2, MOD)


def main():
    prepare(2*10**6+10, MOD)
    r1,c1,r2,c2 = map(int, input().split())

    ans = g(r2, c2) - g(r1-1, c2) - g(r2, c1-1) + g(r1-1, c1-1)
    ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 133940
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n;
    cin >> n;
    int p;
    int cnt = 0;
    rep(i,n){
        cin >> p;
        if(p!=(i+1)) cnt++;
    }   
    if(cnt <=2) cout << "YES" << endl;
    else cout << "NO" << endl;  
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        
        String c = scanner.nextLine();
        int length = Integer.parseInt(c);
        
        String[] numbers = scanner.nextLine().split(" ");
        List<Integer> s = Arrays.asList(numbers).stream().map(i -> Integer.parseInt(i)).collect(Collectors.toList());
        
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        long sum = 0;
        
        for (int aa = 0; aa<length; aa++) {
            int i = s.get(aa);
            if (i < min) {
                min = i;
            }
            if (i > max) {
                max = i;
            }
            sum += i;
        }

        System.out.println(String.format("%d %d %d", min, max, sum));
    }
}


Measured memory_bytes: 35720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int, int > pii;
const int maxn = 100005;
const int INF = 0x3f3f3f3f;

int n, m, s, t;
struct Edge { int to, nxt; } p[maxn << 1];
int head[maxn], cnt;

int f[maxn][3];
inline void addedge(int u,int v) {
    p[++cnt].to = v, p[cnt].nxt = head[u], head[u] = cnt;
}

void bfs() {
    queue < int > q;
    q.push(s);
    memset(f, 0x3f, sizeof(f)); f[s][0] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int i = head[u]; i; i = p[i].nxt) {
            int j = p[i].to;
            bool check = false;
            if (f[j][0] > f[u][2] + 1) f[j][0] = f[u][2] + 1, check = true;
            if (f[j][1] > f[u][0] + 1) f[j][1] = f[u][0] + 1, check = true;
            if (f[j][2] > f[u][1] + 1) f[j][2] = f[u][1] + 1, check = true;
            if (check) q.push(j);
        }
    }
}

int main() {
    cin>>n>>m;int u, v;
    for (int i = 1; i <= m; i++){
    	cin>>u>>v;
    	addedge(u, v);
	}
    cin>>s>>t;
    bfs();
    if (f[t][0] == INF) puts("-1");
    else cout << f[t][0] / 3 << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=200010;
const ll mod=1e9+7;

int main(){  
  int n,k;
  cin >> n >> k;
  vector<ll> data(n);
  rep(i,n){ cin >> data[i]; }
  
  int m = (1<<n);
  ll ans=longinf;
  rep(b,m)if(__builtin_popcount(b) == k && bit(b,0)){
    ll tmp=0;
    ll cnt=0;
    auto a=data;
    int pre=-1;
    rep(i,n){
      if(bit(b,i)){
        if(pre!=-1){
          tmp += (cnt>a[pre]?cnt-a[pre]:0);
        }
        tmp += (cnt>=a[i]?cnt-a[i]+1:0);
        cnt = max(cnt+1, a[i]);
        a[i] = cnt;
        pre = i;
      }
      cnt = max(cnt, a[i]);
    }

    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC044
{
	class Q1
	{
		static void Main()
		{
			int N = int.Parse(Console.ReadLine());
			int K = int.Parse(Console.ReadLine());
			int X = int.Parse(Console.ReadLine());
			int Y = int.Parse(Console.ReadLine());

			int ans = 0;

			for(int i = 1; i <= N; i++)
			{
				if (i <= K)
					ans += X;
				else
					ans += Y;
			}

			Console.WriteLine(ans);
		}
	}
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll s,w;
	cin >> s >> w;
	if(w>=s) cout << "unsafe\n";
	else cout << "safe\n";
	return 0;
}

Measured memory_bytes: 3636
import sys
X = int( input() )
if X == 2:
    print(2)
    sys.exit()
if X == 3:
    print(3)
    sys.exit()
while(True):
    for i in range(2,int(X**0.5)+1):
        if X % i == 0:
            X += 1
            break
    if i == int(X**0.5):
        print(X)
        sys.exit() 

Measured memory_bytes: 38384
package main

import "fmt"

func main() {
	var x, n int
	fmt.Scan(&x, &n)

	list := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&list[i])
	}
	if n == 0 {
		fmt.Println(x)
		return
	}

	min := 0
	diff := 100
	for i := x - 1; i >= 0; i-- {
		flag := false
		for j := 0; j < n; j++ {
			if i == list[j] {
				flag = true
			}
		}
		if !flag && x-min >= x-i {
			min = i
			diff = x - i
		}
	}
	min2 := 101
	diff2 := 100
	for i := x; i <= 101; i++ {
		flag := false
		for j := 0; j < n; j++ {
			if i == list[j] {
				flag = true
			}
		}
		if !flag && min2-x >= i-x {
			min2 = i
			diff2 = i - x
		}
	}
	if diff > diff2 {
		fmt.Println(min2)
	} else if diff < diff2 {
		fmt.Println(min)
	} else {
		fmt.Println(min)
	}
}


Measured memory_bytes: 1840
N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(M)]

UF = list(range(N + 1))
SIZE = [0] + [1] * N  # 1-indexed


def find(x):
    if UF[x] != x:
        UF[x] = find(UF[x])
    return UF[x]


def unite(x, y):
    X, Y = find(x), find(y)
    SX,SY=SIZE[X],SIZE[Y]
    m = min(X,Y)
    SIZE[m] = SX + SY
    SIZE[X+Y-m]=0
    UF[X+Y-m] = m


def is_same(x, y):
    return find(x) == find(y)


def scan_uf():
    for i in range(len(UF)):
        find(i)


ans = [N * (N - 1) // 2]
for a, b in AB[::-1]:
    if not is_same(a, b):
        ans += [ans[-1] - SIZE[find(a)] * SIZE[find(b)]]
        unite(a, b)
    else:
        ans += [ans[-1]]
print(*ans[-2::-1], sep='\n')


Measured memory_bytes: 31124
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll n, m;
ll fact(ll x) {
  if (x == 0)
    return 1;
  return x * fact(x - 1) % MOD;
}

ll mod_pow(ll x, ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % MOD, n / 2);
	if (n & 1) res = res * x % MOD;
	return res;
}
 
ll comb(ll a, ll b) {
	ll mul = 1;
	ll div = 1;
	rep(i, 0, b) {
		mul *= (a - (ll)i);
		mul %= MOD;
		div *= ((ll)i + 1);
		div %= MOD;
	}
 
	mul *= mod_pow(div, MOD - 2);
	return mul%MOD;
}

vector<int> makePrimes(int n) {
  vector<int> res, pr(n + 1, 1);
  pr[0] = pr[1] = 0;
  rep(p, 2, sqrt(n) + 2) 
    if (pr[p]) 
    for (int x = p * 2; x <= n; x += p) pr[x] = 0;
  rep(p, 2, n + 1) 
    if (pr[p]) 
      res.push_back(p);
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m;
    ll t = m, ans = 1;
    for (int i = 2; i * i <= m; i++) {
        int p = 0;
        while (m % i == 0) {
            m /= i;
            p++;
        }
        ans = (ans * comb(n + p - 1, n - 1)) % MOD;
    }
    if (m > 1) ans = (ans * comb(n, n - 1)) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  char s[4];
  int i, j;
  int count = 0;

  scanf ("%s", s);

  for (i = 0; i < 4; i++)
  {
    for (j = 0; j < 4; j++)
    {
      if (s[i] == s[j])
      {
        count++;
      }
    }
  }
  
  if (count != 8){
    printf ("No\n");
  }

  else
  {
    printf ("Yes\n");
  }
  
  return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
const ll MAXN=520233;
ll n,m,sum,w[MAXN+10],a[MAXN+10],f[MAXN+10],ff[MAXN+10];
ll M(ll x){return (x%m+m)%m;}
int main()
{
	scanf("%lld%lld%lld",&n,&m,a+1);--a[1];
	for(ll i=2,ad;i<=n;++i)
	{
		scanf("%lld",a+i);--a[i];
		sum+=M(a[i]-a[i-1]);
		if(a[i-1]==a[i])continue;
		ad=(a[i-1]>a[i])*m;
		++ff[a[i-1]+2];
		--ff[ad+a[i]+1];
		f[ad+a[i]+1]-=(ad+a[i]+1)-(a[i-1]+2);
	}
	for(ll i=1;i<2*m;++i)ff[i]+=ff[i-1];
	for(ll i=1;i<2*m;++i)ff[i]+=ff[i-1];
	for(ll i=1;i<2*m;++i)f[i]+=f[i-1];
	ll mx=0;
	for(ll i=0;i<m;++i)mx=max(mx,f[i]+ff[i]+f[m+i]+ff[m+i]);
	printf("%lld",sum-mx);
	return 0;
}

Measured memory_bytes: 9984
import math
def min_cost(arr):
    n = len(arr)
    dp = [0 for _ in range(n)]
    dp[1] = abs(arr[1]- arr[0])
    for i in range(2,n):
        dp[i] =  min(dp[i-1] + abs(arr[i] - arr[i-1]),dp[i -2 ] + abs(arr[i]-arr[i-2]))
        
    return dp[n-1]

n = input()
arr = list(map(int,input().split()))
print(min_cost(arr))

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

double n, k;

double p(int i) {
  int cnt = 0;
  while (i < k) {
    i *= 2;
    cnt++;
  }
  return pow(0.5, cnt)/n;
}

int main() {
  cin >> n >> k;
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += p(i);
  }
  printf("%.12lf\n", ans);
  return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#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 FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  char n;
  cin >> n;
  char ans = n + 1;
  
  //cout << fixed << setprecision(10);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n,i,a[200005],max,min;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	max=a[1]-a[0];
	min=a[0];
	for(i=1;i<n;i++)
	{
		max=max>a[i]-min?max:a[i]-min;
		min=min<a[i]?min:a[i];
	}
	printf("%d\n",max);
	return 0;
}


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

bool ques(ll n){
    cout<<"? "<<n<<endl<<flush;
    string ans;
    cin>>ans;
    return (ans=="Y");
}

int main(void){
    int d=1e9;
    if(ques(d)){
        while(d>1 && ques(d-1)) d/=10;
        cout<<"! "<<d<<endl;
    }else{
        while(d/=10,!ques(d));
        ll l=d,r=d*10;
        while(l+1<r){
            ll m=(l+r)/2;
            if(ques(m*10)) r=m;
            else l=m; 
        }
        cout<<"! "<<r<<endl;
    }
    return 0;
}


Measured memory_bytes: 596
import java.util.Scanner;

public class Main 
{
	static int w, h;
	static int[][][] dp;
	static boolean[][] g;
	static int BIGNUM = 999999999;
	
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		h = sc.nextInt();
		w = sc.nextInt();
		
		g = new boolean[w][h];
		
		dp = new int[w][h][2]; //2 states: current tile is covered in inversion (1) or not (0)
		for(int y = 0; y < h; y++)
		{
			String s = sc.next();
			for(int x = 0; x < w; x++)
			{
				g[x][y] = s.charAt(x) == '#';
			}
		}

		for(int y = 0; y < h; y++)
			for(int x = 0; x < w; x++)
				for(int s = 0; s < 2; s++)
				{
					dp[x][y][s] = BIGNUM;
				}
		
		//no more cost when you've reached finish
		dp[w-1][h-1][0] = 0;
		dp[w-1][h-1][1] = 0;
		
		//s=1 means flipped
		for(int y = h-1; y >= 0; y--)
			for(int x = w-1; x >= 0; x--)
				for(int s = 0; s < 2; s++)
				{
					//right
					if(x < w-1)
					{ //tax is only when moving to a wall when we're at state 0 (uninverted)
					  //moving to an originally floor tile when we're at state 1,
					  //does not incur tax because we can simply not cover that tile in our inversion.
					  //(the inversion that covers current tile)
						int reqstate = g[x+1][y]?1:0;
						int tax = reqstate==1&&s==0?1:0;
						dp[x][y][s] = Math.min(dp[x][y][s], dp[x+1][y][reqstate]+tax);
					}
					
					//down
					if(y < h-1)
					{
						int reqstate = g[x][y+1]?1:0;
						int tax = reqstate==1&&s==0?1:0;
						dp[x][y][s] = Math.min(dp[x][y][s], dp[x][y+1][reqstate]+tax);
					}
				}

		if(g[0][0]) //if starting tile is wall, we must invert it
			System.out.println(dp[0][0][1]+1);
		else //otherwise we must not
			System.out.println(dp[0][0][0]);
			
	}

}


Measured memory_bytes: 23812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int N;
    cin >> N;
    vector<ll> l(N);
    rep(i,N) cin >> l[i];
    ll ans = 0;
    sort(all(l));
    for(int i=0;i < N;i++){
        for(int j = i+1;j < N;j++){
            for(int k = j+1;k < N;k++){
                if(l[i] == l[j] || l[j] == l[k] || l[i] == l[k]) continue;
                int maxn = max({l[i],l[j],l[k]});
                int sum = l[i] + l[j] + l[k] - maxn;
                if(sum > maxn) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		int red = 0;
		int blue = 0;
		for (int i=0;i<s.length();i++) {
			if (s.charAt(i)=='R') {
				red ++;
			} else {
				blue ++;
			}
		}
		if (red >blue) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35672