akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <utility>

using namespace std;

typedef struct pp{
	string name;
	int time;
}P;

int main(void) {
	int n, q;
	cin >> n >> q;
	string name;
	int time;
	pair<string, int> a;
	queue<pair<string, int>> Q;
	while(n--) {
		cin >> name >> time;
		a = make_pair(name, time);
		Q.push(a);

	}
	int now = 0;
	while(! Q.empty()) {
		int t = Q.front().second;
		string n = Q.front().first;
		if (t <= q) {
			now += t;
			cout << n << " " << now << endl;
		}
		else {
			now += q;
			pair<string, int> p = make_pair(n, t - q);
			Q.push(p);
		}
		Q.pop();
	}
}



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

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}


long long LCM(long long a, long long b) {
    return (a/GCD(a,b))*b;
}

int main() {
  long long N; 
  cin >> N;
  
  vector<long long> vec(N);
  for (long long i=0;i<N;i++) {
    cin >> vec.at(i);
  }
  long long ans = vec.at(0);
  for (long long i = 0;i<N;i++) {
      ans = LCM(ans,vec.at(i));
  } 
  cout << ans << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read


#n,*a = [int(i) for i in read().split()]
a,b,c = [int(i) for i in readline().split()]

ok = 0
if c-(a+b) > 0 and 4*a*b < (c-(a+b))**2: ok = 1

if ok:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];
int DP[100100];

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

  for (int i = 0; i < N; i++) {
    cin >> Input[i];
  }

  multiset<int> X;

  X.insert(Input[0]);

  for (int i = 1; i < N; i++) {
    int T = Input[i];
    auto itr = X.lower_bound(T);
    if (itr == X.begin()) {
      X.insert(T);
    } else {
      X.erase(--itr);
      X.insert(T);
    }
  }

  cout << X.size() << endl;
  return 0;
}


Measured memory_bytes: 5376
#[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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, usize1) => {
        read_value!($next, usize) - 1
    };

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

pub fn prime_factorization(mut n: usize) -> Vec<(usize, usize)> {
    let mut i = 2;
    let mut ans = vec![];
    while i * i <= n {
        let mut cnt = 0;
        while n % i == 0 {
            n /= i;
            cnt += 1;
        }
        if cnt > 0 {
            ans.push((i, cnt));
        }
        i += 1;
    }
    if n > 1 {
        ans.push((n, 1));
    }
    ans
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      a: usize,
      b: usize,
    }

    use std::collections::HashSet;
    let p1 = prime_factorization(a);
    let s1: HashSet<usize> = p1.iter().map(|v| v.0).collect();
    let p2 = prime_factorization(b);
    let mut ans = 0;
    for (p, _) in p2 {
        if s1.contains(&p) {
            ans += 1;
        }
    }
    puts!("{}\n", ans+1);
}


Measured memory_bytes: 4352
N = int(input())
P = [int(input()) for _ in range(N)]

max_num = 0
max_index = 0
for i in range(N):
    p = P[i]
    if p > max_num:
        max_num = p
        max_index = i
for i in range(N):
    if i == max_index:
        P[i] = P[i]//2
sum_num = 0
for i in range(N):
    sum_num += P[i]
print(sum_num)


Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
using namespace std;
int m,n,__,e[20000][20000],root,inf=0x3f3f3f3f;
int low[100001],num[100001],book[100001],cnt=0;
int min(int a,int b)
{
	return a<b?a:b;
}
void gd(int cur,int fa)
{
    int ez=0;
    __++;
    num[cur]=__;
    low[cur]=__;
    for(int i=1;i<=m;i++)
        {
            if(e[cur][i]==1)
                {
                    if(num[i]==0)
                    {	
                        ez++;
                        gd(i,cur);
                        low[cur]=min(low[cur],low[i]);
                        if(low[i]>num[cur])
                            {
                            	book[cur]=1;
                        		cnt++;
							}
					}
                else if(fa!=i)
                    low[cur]=min(low[cur],num[i]);
                }
        
        }
    return;
}
int main()
{
    int a,b;
    cin>>m>>n;
    for(int i=1;i<=n;i++)
        {
            cin>>a>>b;
            e[a][b]=1;
            e[b][a]=1;
        }
    root=1;
    gd(1,root);

    cout<<cnt<<endl;
    
    return 0;
}

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

int main(){
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    
    if(a == 0){
        cout << 1 << endl;
    }else if(b == 0){
        cout << 2 << endl;
    }else if(c == 0){
        cout << 3 << endl;
    }else if(d == 0){
        cout << 4 << endl;
    }else{
        cout << 5 << endl;
    }
}

Measured memory_bytes: 3592
def f(n,x):
  if x == 0:
    return 0
  elif n == 0:
    return 1
  elif x <= 2**(n+1)-2:
    return f(n-1,x-1)
  elif x == 2**(n+1)-1:
    return 2**n
  elif x<= 2**(n+2)-4:
    return f(n-1,x-(2**(n+1)-1))+2**n
  else:
    return 2**(n+1)-1

n,x = map(int,input().split())
print(f(n,x))

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

int main() {
    int N, K;
    cin >> N >> K;

    int cost = 0;
    vector<int> p(N);
    for (int i = 0; i < N; i++){
        cin >>p[i];
    }
    sort(p.begin(), p.end());
    for (int i = 0; i < K; i++){
        cost += p[i];
    }

    cout << cost << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define N 1000
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> P;
int main(){

  int n;

  while(cin>>n,n){
    vector<pair<int,int> >g[1000],rg[1000];
    int s,t,m;
    cin>>s>>t;
    s--;t--;

    cin>>m;

    for(int i=0;i<m;i++){
      int a,b;
      cin>>a>>b;
      a--;b--;
      g[a].push_back(P(b, i+1));
      rg[b].push_back(P(a, i+1));
    }
   
    pair<int,int> d[n][2];
    memset(d,-1,sizeof(d));
    for(int i=0;i<n;i++)
      for(int j=0;j<2;j++) d[i][j] = P(1e9,1e9);
    d[s][0]=mk(0,0);

    queue<pair<int,int> >q;

    q.push(mk(s,0));

    while(!q.empty()){
      pair<int,int>p=q.front();q.pop();
      int v=p.fi,used=p.se;
      int cost=d[v][used].fi;
      int edge=d[v][used].se;
      
       for(int i=0;i<g[v].size();i++){
	 int nx=g[v][i].fi;
	 P ncost = P(cost+1,edge);
	 if(d[nx][used]>ncost ){
	   d[nx][used]=ncost;
	   q.push(mk(nx,used));
       	}
       }

      	if(!used)for(int i=0;i<rg[v].size();i++){
	    int nx=rg[v][i].fi;
	    P ncost = P(cost+1,rg[v][i].se);
	  if(d[ nx ][1]>ncost){
	    d[nx][1]=ncost;
	    q.push(mk(nx,1));
	  }
	 }
    }

    P ans=min(d[t][0],d[t][1]);

    cout<<ans.fi<<' '<<ans.se<<endl;
  }
}

Measured memory_bytes: 3368
#include<cstdio>
#include<ctime>
#include<cstring>
#include<vector>
using namespace std;
const int mod=1000000007;
int f[2][3][305][305];
int n,m;
int l[305],r[305],x[305];
vector<int> lim[305];
int a[3][2]={{1,2},{0,2},{0,1}};
bool check(int i,int j,int k1,int k2){
  for(vector<int>::iterator pt=lim[i].begin();pt!=lim[i].end();++pt){
    int cnt=1;
    if(k1>=l[*pt])cnt++;
    if(k2>=l[*pt])cnt++;
    if(cnt!=x[*pt])return false;
  }
  return true;
}
int main(){
  // double t1=clock();
  scanf("%d%d",&n,&m);
  for(int i=1;i<=m;++i)scanf("%d%d%d",l+i,r+i,x+i),lim[r[i]].push_back(i);
  bool no_solu=false;
  for(vector<int>::iterator pt=lim[1].begin();pt!=lim[1].end();++pt){
    if(x[*pt]!=1)no_solu=true;
  }

  if(no_solu)printf("0\n");
  else{
    for(int j=0;j<3;++j)f[0][j][0][0]=1;
    int flag=0; 
    for(int i=2;i<=n;++i){
      flag^=1;
      memset(f[flag],0,sizeof(f[flag]));
      for(int j=0;j<3;++j){
	for(int k1=0;k1<i;++k1){
	  for(int k2=0;k2<i;++k2){
	    if(!check(i-1,j,k1,k2))continue;

	    if(f[flag^1][j][k1][k2]!=0)(f[flag][j][k1][k2]+=f[flag^1][j][k1][k2])%=mod;
	    for(int j2=0;j2<3;++j2){
	      if(j2==j)continue;
	      if(j2==a[j][0]){
		(f[flag][j][i-1][k2]+=f[flag^1][j2][k1][k2])%=mod;
	      }else{
		(f[flag][j][k1][i-1]+=f[flag^1][j2][k1][k2])%=mod;
	      }
	    }
	  }
	}
	
      }
    }
    int ans=0;
    for(int j=0;j<3;++j){
      for(int k1=0;k1<n;++k1){
	for(int k2=0;k2<n;++k2){
	  if(check(n,j,k1,k2))ans=(ans+f[flag][j][k1][k2])%mod;
	}
      }
    }
    printf("%d\n",ans);
 
  }
  //double t2=clock();
  // printf("%.3fs\n",(t2-t1)/CLOCKS_PER_SEC);
  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin >> S;
    int cnt = 0;
    for (int i = 0; i < S.length(); i++){
        if (S[i] == 'o') {
            cnt += 1;
        }
    }
    cout << 700 + 100 * cnt << endl;
}

Measured memory_bytes: 256
n = int(input())
for _ in range(n):
    x = int(input())
    lst = list(map(int, input().split()))
    y, z = 0, 0
    for j in range(1, x):
        y = max(y, lst[j]-lst[j-1])
        z = min(z, lst[j]-lst[j-1])    
    print(y, -z)



Measured memory_bytes: 5608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var a = ReadLineInt();
            var b = ReadLineInt();
            Console.WriteLine(6-(a + b));
            ReadLine();
        }

        /// <summary>
        /// コンビネーション
        /// </summary>
        /// <param name="n"></param>
        /// <param name="m"></param>
        /// <returns></returns>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        /// <summary>
        /// stringを一文字ずつintにキャストして配列に変換します。
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int[] StringCharArrayIntArray(string str)
        {
            List<int> b = new List<int>();
            for (int i = 0; i < str.Length; i++) {
                b.Add( int.Parse(str[i].ToString()));
            }
            return b.ToArray();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }

        static string[] GetAplhaLowerArray() => new string[]{ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}

Measured memory_bytes: 11092
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
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; }
const int di[4] = {0, 1, 0, -1};
const int dj[4] = {1, 0, -1, 0};

template <typename T> vector<T> dijkstra(const vector<vector<pair<int, T>>> &G, int s){
    using P = pair<T, int>;
    const T inf = numeric_limits<T>::max();
    vector<T> ret(G.size(), inf); ret[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(ret[s], s);
    while (!que.empty()) {
        T dist; int node;
        tie(dist, node) = que.top(); que.pop();
        if (ret[node] < dist) continue;
        for (auto &e : G[node]) {
            int next_node; T next_dist;
            tie(next_node, next_dist) = e;
            if (ret[next_node] > ret[node] + next_dist) {
                ret[next_node] = ret[node] + next_dist;
                que.emplace(ret[next_node], next_node);
            }
        }
    }
    return ret;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    vector<vector<pair<int, long long>>> G(H*W);
    for (int i = 0; i < H; i++) cin >> S[i];
    
    auto idx = [&](int i, int j) { return i * W + j; };
    
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '#') continue;
            for (int k = 0; k < 4; k++) {
                int s = i + di[k], t = j + dj[k];
                if (s < 0 || H <= s || t < 0 || W <= t) continue;
                if (S[s][t] == '#') continue;
                G[idx(i, j)].emplace_back(idx(s, t), 1);
            }
        }
    }
    
    long long ans = 0;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        if (S[i][j] == '#') continue;
        vector<long long> dist = dijkstra(G, idx(i, j));
        for (int s = 0; s < H; s++) for (int t = 0; t < W; t++) {
            if (S[s][t] != '#') chmax(ans, dist[idx(s, t)]);
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline void chmax(T& a, T b){if(a<b)a=b;}
template<class T> inline void chmin(T& a, T b){if(a>b)a=b;}
const long long INF = 1LL << 60;

template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
template<class V> struct BIT {
    BIT() {}
    int NV;vector<V> bit;
    BIT(int n){ init(n); }
    void init(int n) { NV = 1; while (NV < n)NV *= 2; bit.resize(NV); clear(); }
    V operator[](int e) { V s = 0; e++; while (e) s += bit[e - 1], e -= e&-e; return s; }
    void add(int e, V v) { e++; while (e <= NV) bit[e - 1] += v, e += e&-e; }
    int lower_bound(V val) { 
        V tv = 0; int i, ent = 0; for (i = NV - 1; i >= 0; i--)
        if(tv+bit[ent+(1<<i)-1]<=val)tv+=bit[ent+(1<<i)-1],ent += (1 << i);return ent;
    }
    V get(int L, int R) {
        assert(0 <= L); assert(R <= NV); assert(L <= R);
        V res = 0; if(R) res += operator[](R - 1); if (L) res -= operator[](L - 1);return res;
    }
    void clear() { for(int i=0;i < NV;++i) bit[i] = 0; }
};


int N,K;
int a[110];
BIT<mint> dp[110];

int main(){
  cin >> N >> K;
  for(int i=0;i<N;++i) cin >> a[i];
  for(int i=0;i<=N;++i) dp[i].init(K+1);
  dp[0].add(K,1);
  for(int i=1;i<=N;++i){ 
    for(int j=0;j<=K;++j){ // dp[i][j] : i番目の子供に配った時にj個残る場合の数
       dp[i].add(j,dp[i-1].get(j,min(K,j+a[i-1])+1));
       // dp[i][j] = dp[i-1][j] + ... + dp[i-1][j+a[i-1]] (or dp[i-1][K])
       // i-1のjからj+a[i-1]の場合の数の和にBITを使用。
    }
  }   
  
  cout << dp[N].get(0,1) << endl;
  return 0;
}

Measured memory_bytes: 52352
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) {
    R a[i];
    a[i]=n-a[i];
  }
  ll dp[n];
  fill(dp,dp+n,MAX);
  for(int i = 0 ; i < n ; i++) *upper_bound(dp,dp+n,a[i]) = a[i];
  cout << lower_bound(dp,dp+n,MAX) - dp << endl;
}

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


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int n;
  cin >> n;
  ll last = 0;
  ll max = 0;
  rep(i, n) {
    ll k;
    cin >> k;
    if (i != 0) {
      if (k < last - 1 || k < max) {
        cout << "No" << endl;
        return 0;
      }
    }
    last = k;
    if (max < k - 1) max = k - 1;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

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

fn main() {
    let s: String = input();
    let mut n = 0;
    if s == "SUN" {
        n = 7;
    } else if s == "MON" {
        n = 6;
    } else if s == "TUE" {
        n = 5;
    } else if s == "WED" {
        n = 4;
    } else if s == "THU" {
        n = 3;
    } else if s == "FRI" {
        n = 2;
    } else if s == "SAT" {
        n = 1;
    }
    println!("{}", n);
}


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

ll solve() {
    ll N, H, W;
    cin >> N >> H >> W;
    ll ans = (N-H+1)*(N-W+1);
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long N = Long.parseLong(sc.next());
		sc.close();

		int answer = Integer.MAX_VALUE;
		for(int i = 1; i <=  Math.sqrt((double)N); i++) {
			if(N % i == 0) {
				long A = i;
				long B = N / i;
				int tmp = Math.max(String.valueOf(A).length(), String.valueOf(B).length());
				if(tmp < answer) answer = tmp;
			}else {
				continue;
			}
		}
		System.out.println(answer);

	}

}

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

int main()
{
    int n;
    cin>>n;
    int k;
    cin>>k;
    int* arr=new int[n];
    int* dp=new int[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<n;i++)
        dp[i]=INT_MAX;
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i;j<=i+k;j++)
        {
            if(j<n)
                dp[j]=min(dp[j],abs(arr[i]-arr[j])+dp[i]);
        }
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 4384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d;
  cin>>d;
  vector<int> c(26);
  for(int i=0;i<26;i++)
    cin>>c.at(i);
  vector<vector<int>> s(d,vector<int>(26));
  for(int i=0;i<d;i++)
    for(int j=0;j<26;j++)
      cin>>s.at(i).at(j);
  vector<int> t(d);
  for(int i=0;i<d;i++){
    cin>>t.at(i);
    t.at(i)--;
  }
  vector<set<int>> l(26);
  for(int i=0;i<26;i++)
    l.at(i).insert(0);
  int64_t p=0;
  for(int i=1;i<=d;i++){
    p+=s.at(i-1).at(t.at(i-1));
    l.at(t.at(i-1)).insert(i);
    for(int j=0;j<26;j++)
      p-=c.at(j)*(i-*rbegin(l.at(j)));
    cout<<p<<endl;
  }
}

Measured memory_bytes: 3656
//    https://youtu.be/N3oCS85HvpY

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;	// 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define shesh               "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define bp                  pop_back
#define pf                  push_front
#define fp                  pop_front
#define ub                  upper_bound
#define lb                  lower_bound
#define all(x)              x.begin(), x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"
#define mest(a,b)           memset(a,b,sizeof(a))

int main(){
    fast;
    ll t,n,m,r,i,j,k,temp,flag,ans=inf,a,b,c;
    cin>>n>>m>>r;
    vector<ll>v,u;
    for(i=0;i<r;i++){
        cin>>temp;
        v.pb(temp);
    }
    ll cost[n+1][n+1];
    //memset(cost,-1,sizeof(cost));
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            cost[i][j]=inf;
        }
    }
    for(i=0;i<m;i++){
        cin>>a>>b>>c;
        cost[a][b]=c;
        cost[b][a]=c;
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                cost[j][k]=min(cost[j][i]+cost[i][k],cost[j][k]);
            }
        }
    }
    u=v;
    do{
        for(temp=0,i=1;i<r;i++){
            temp+=cost[v[i-1]][v[i]];
        }
        ans=min(ans,temp);
        next_permutation(v.begin(),v.end());
    }while(u!=v);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int k,a,b;
    cin >> k >> a >> b;
    for(int i = a; i <= b; i++){
        if(i%k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

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

void event(void);

int main(void)
{
	int n;
	int i;
	
	scanf("%d", &n);
	//head tail
	
	for (i = 0; i < n; i++){
		event();
	}
	
	return (0);
}

void event (void)
{
	int out = 0;
	int hit = 0;
	char str[20];
	int score = 0;
	
	while (1){
		scanf("%s", str);
		if (strcmp(str, "HIT") == 0){
			hit++;
			if (hit == 4){
				score++;
				hit = 3;
			}
		}
		if (strcmp(str, "OUT") == 0){
			out++;
			if (out == 3){
				break;
			}
		}
		if (strcmp(str, "HOMERUN") == 0){
			score += hit;
			score++;
			hit = 0;
		}
	}
	
	printf("%d\n", score);
}

Measured memory_bytes: 596
#include <iostream>
#include <utility>
#include <map>
#include <array>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> p;

array<ll, 3> balls;
map<p, ll> memo;

ll solve(ll n, ll ball_index) {
  if (n == 0) {
    return 1;
  }

  if (ball_index == balls.size() - 1) {
    if (balls[2] == 0) {
      return 0;
    }
    return n % balls[2] == 0 ? 1 : 0;
  }

  if (balls[ball_index] == 0) {
    return solve(n, ball_index + 1);
  }

  auto key = p(n, ball_index);

  auto it = memo.find(key);
  if (it != memo.end()) {
    return it->second;
  }

  ll answer = 0;
  for (ll i = 0; ; i++) {
    ll rest_n = n - i * balls[ball_index];
    if (rest_n < 0) {
      break;
    }
    answer += solve(rest_n, ball_index + 1);
  }
  memo.insert(make_pair(key, answer));
  return answer;
}

int main() {
  ll n;
  cin >> balls[0] >> balls[1] >> balls[2] >> n;
  cout << solve(n, 0) << endl;
  return 0;
}


Measured memory_bytes: 384
n, l = map(int, input().split())

pie_n = (n*l) + (n*(n+1)//2) - n
taste = []
diff = []

for i in range(n):
  taste.append(pie_n - (l+i))
  diff.append(abs(l+i))
  
print(taste[diff.index(min(diff))])

Measured memory_bytes: 38384
#include <stdio.h>
int main()
{
  int i;
  int n, a= 0;
  scanf("%d", &n);
  int arr[n];
  for (i = 0; i < n; i++)
  {
    scanf("%d", arr+i);
  }
  for (i = 1; i < n-1; i++)
  {
    if (arr[i-1] < arr[i] && arr[i] < arr[i+1] ||
        arr[i-1] > arr[i] && arr[i] > arr[i+1]) {
      a++;
    }
  }
  printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int digit(int n){
int s=0;
while(n){
s+=(n%10);
n/=10;
}
return s;
}
int main(){
int n, i, j, min=INT_MAX, s;
cin>>n;
for(i=1; i<=n/2; i++){
j=n-i;
s=digit(i)+digit(j);
if(s<min){
min=s;
}
}
cout<<min;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void go()
{
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a;
}
int main()
{
    //FIO;
//    int t;
//    cin>>t;
//    while(t--)
        go();
    return 0;
}



Measured memory_bytes: 3632
H, W, K = map(int, input().split())
row_sum = [0] * H
column_sum = [0] * W
A = []
for i in range(H):
  a = input()
  b = [0] * W
  for j in range(W):
    if a[j] == '#':
      row_sum[i] += 1
      column_sum[j] += 1
      b[j] = 1
  A.append(b)
A_sum = sum(column_sum)
ans = 0
for h in range(2**H):
  h_bit = format(h, 'b').zfill(H)
  row = []
  row_judge = 0
  for h_num, bit in enumerate(h_bit, 0):
    if bit == '1':
      row.append(h_num)
      row_judge += row_sum[h_num]
  for w in range(2**W):
    w_bit = format(w, 'b').zfill(W)
    column = []
    column_judge = 0
    for w_num, bit2 in enumerate(w_bit, 0):
      if bit2 == '1':
        column.append(w_num)
        column_judge += column_sum[w_num]
    matrix_judge = 0
    if row and column:
      for i in row:
        for j in column:
          matrix_judge -= A[i][j]
    if A_sum - (row_judge + column_judge + matrix_judge) == K:
      ans += 1
    # print(h_bit, row, w_bit, column)
    # print(A_sum, row_judge, column_judge, matrix_judge, ans)
print(ans)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main(){
    ll n;   cin >> n;
    ll res=0, cnt=0;
    rep(i, n){
        ll a, b;    cin >> a >> b;
        if(a==b) cnt += 1;
        else cnt = 0;
        res = max(res, cnt);
    }
    if(3<=res) res = 1;
    else res = 0;
    cout << yes[res] << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
int main()
{
  ll a,b; cin >> a >> b;
  cout << lcm(a,b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;

int n;
vector<int> gph[MAXN];
vector<int> dfn;

int dp[MAXN];

int query(int k){
	for(auto &i : dfn){
		if(i == 1) break;
		vector<int> v;
		for(auto &j : gph[i]) v.push_back(dp[j] + 1);
		sort(v.begin(), v.end());
		auto trial_pos = [&](int x){
			int l = 0, r = v.size() - 1;
			for(int i=0; i<v.size()/2; i++){
				if(l == x) l++;
				if(r == x) r--;
				if(v[l] + v[r] > k) return 0;
				l++;
				r--;
			}
			return 1;
		};
		if(v.size() % 2 == 0){
			v.insert(v.begin(), 0);
		}
		int s = 0, e = v.size();
		while(s != e){
			int m = (s+e)/2;
			if(trial_pos(m)) e = m;
			else s = m + 1;
		}
		if(s == v.size() || v[s] >= k) return 0;
		dp[i] = v[s];
	}
	vector<int> v;
	for(auto &i : gph[1]) v.push_back(dp[i] + 1);
	sort(v.begin(), v.end());
	if(v.back() > k) return 0;
	if(v.size() % 2 == 1) v.pop_back();
	for(int i=0; i<v.size()/2; i++){
		if(v[i] + v[v.size()-i-1] > k) return 0;
	}
	return 1;
}

void dfs(int x){
	dfn.push_back(x);
	for(auto &i : gph[x]){
		gph[i].erase(find(gph[i].begin(), gph[i].end(), x));
		dfs(i);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1; i<n; i++){
		int s, e;
		scanf("%d %d",&s,&e);
		gph[s].push_back(e);
		gph[e].push_back(s);
	}
	dfs(1);
	int ans = n - 1;
	for(int i=1; i<=n; i++){
		ans -= ((i != 1) + gph[i].size()) / 2;
	}
	int s = 1, e = n;
	reverse(dfn.begin(), dfn.end());
	while(s != e){
		int m = (s+e)/2;
		if(!query(m)) s = m+1;
		else e = m;
	}
	printf("%d %d\n", ans, s);
}




Measured memory_bytes: 10616
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main = do
    [n] <- readInt
    a   <- readInt
    print $ solve n a

solve n a = a' !! 0 * a' !! 1
  where
    a' = (\x -> x ++ [0, 0, 0]) $ concatMap
        (\(a, b) -> replicate b a)
        ( map (\(a, b) -> (a, b `div` 2))
        $ filter (\x -> snd x > 1)
        $ map (\x -> (head x, length x))
        $ group
        $ sortOn Down a
        )


Measured memory_bytes: 25980
#include<iostream>
using namespace std;
const int MAXN=1e5+10;
int a[MAXN],b[MAXN];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n-1;i++)
	{
		cin>>b[i];
	}
	//a[1]=b[1];
	long long sum=b[1];
	for(int i=1;i<=n-1;i++)
	{
		if(b[i]<=b[i+1])
		{
			sum+=b[i];
		 } else {
		 	sum+=b[i+1];
		 }
	}
	sum+=b[n-1];
	cout<<sum<<endl;
 } 

Measured memory_bytes: 256
function main()
  
  (W,H,N) = map(x -> parse(Int,x), split(readline()))
  
  X = [0,W]
  Y = [0,H]
  
  x = zeros(Int,N)
  y = zeros(Int,N)
  a = zeros(Int,N)
  
  for i in 1:N
    
    (x[i],y[i],a[i]) = map(x -> parse(Int,x), split(readline()))
    
  end
  
  for i in 1:N
    
    if a[i] == 1 && X[1] < x[i]
      X[1] = x[i]
    elseif a[i] == 2 && X[2] > x[i]
      X[2] = x[i]
    elseif a[i] == 3 && Y[1] < y[i]
      Y[1] = y[i]
    elseif a[i] == 4 && Y[2] > y[i]
      Y[2] = y[i]
    end

  end
  
  if X[2]-X[1] > 0 && Y[2]-Y[1] > 0
    println((X[2]-X[1])*(Y[2]-Y[1]))
  else
    println(0)
  end
  
end

main()

Measured memory_bytes: 115200
mod = 10**9+7

n, m = gets.to_s.split.map{|t|t.to_i}

if n == 1
  puts 1
  exit
end

stairs = Array.new(n+1){ 0 }
stairs[0] = stairs[1] = 1

m.times do
  stairs[gets.to_s.to_i] = -1
end

2.upto(n) do |i|
  next if stairs[i] == -1
  stairs[i] += stairs[i-1] if stairs[i-1] > 0
  stairs[i] += stairs[i-2] if stairs[i-2] > 0
  stairs[i] %= mod if stairs[i] >= mod 
end

puts stairs[-1] % (10**9+7)

Measured memory_bytes: 4732
import math
n,p=map(int,input().split())
A=[int(i) for i in input().split()]
def com(i,j):
  return math.factorial(i)//math.factorial(i-j)//math.factorial(j)
k=0
for a in A:
  if a%2==0:
    k+=1
ans=2**k
mult=0
for i in range((n-k)//2+1):
  mult+=com(n-k,2*i)
ans*=mult
print(ans if p==0 else 2**n-ans)

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

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

using namespace std;
using ll = long long;

int main() {
  int n, m, a, t;
  priority_queue<ll> pq;
  cin >> n >> m;
  rep(i, n) cin >> a, pq.push(a);

  rep(i, m) t = pq.top() / 2, pq.pop(), pq.push(t);

  ll ans = 0;

  while (pq.size() > 0) ans += pq.top(), pq.pop();

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1400
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2754>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

double clac(int n,int add,vector<int>& S,vector<int>& H){
    double ret = 0;
    int sz = (int)S.size();
    for(int i = 0; i < sz;i++){
        int V = S[i]*H[i];
        if(add >= V){
            ret += H[i];
            add -= V;
        }else{
            ret += H[i]*add/(double)V;
            break;
        }
    }
    return ret;
}
double solve(){
    double res = 0;
    int N,M; cin >> N >> M;
    vector<int> K(N);
    vector<vector<int>> S(N),H(N);
    for(int i = 0; i < N;i++){
        cin >> K[i];
        S[i].resize(K[i]); H[i].resize(K[i]);
        for(int j = 0; j < K[i];j++){
            cin >> S[i][j] >> H[i][j];
        }
    }
    
    vector<vector<double>> dp(N+1,vector<double>(M+1,0));
    for(int i = 0; i < N;i++){
        for(int j = 0; j <= M;j++){
            for(int k = 0; k <= M; k++){
                if(j + k > M)continue;
                dp[i+1][j+k] = max(dp[i+1][j+k],dp[i][j] + clac(i,k,S[i],H[i]));
            }
        }
    }
    res = dp[N][M];
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12) <<  solve() << endl;
    return 0;
}



Measured memory_bytes: 3420
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < a.length; i++) {
      a[i] = sc.nextInt();
    }
    for(int i = 1; i < a.length; i++){
      System.out.print(a[a.length-i] +" ");
    }
    System.out.println(a[0]);
    sc.close();
  }
}



Measured memory_bytes: 26436
/*Infor {{{
 ******************************************************
 * > File Name: A.cpp
 * > Author: zrz_orz
 * > Mail: 1281941815@qq.com
 * > Created Time: 2018/10/27/锟斤拷锟斤拷 19:58:31
 ******************************************************
 }}}*/

#include <bits/stdc++.h>

using namespace std;

/*Abbreviation {{{ */
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define ROF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define cini(a) scanf("%d", &(a))
#define cinc(a) scanf("%c", &(a))
#define cinl(a) scanf("%lld", &(a))
#define cins(a) scanf("%s", (a))
#define cind(a) scanf("%lf", &(a))
#define coui(a) printf("%d", (a))
#define couc(a) printf("%c", (a))
#define coul(a) printf("%lld", (a))
#define cous(a) printf("%s", (a))
#define coud(a) printf("%f", (a))
#define SPA printf(" ")
#define LIN printf("\n")
#define ll long long int
/*}}}*/

/*Constant {{{*/
#define N 100001
/*}}}*/

/*Class {{{*/
/*}}}*/

/*Variable {{{*/
int n;
ll a[N];
ll ans[N];
/*}}}*/

/*Declare {{{*/
/*}}}*/

/*Main {{{*/
int main() {
  scanf ("%d", &n);
  FOR (i, 1, n) {
    scanf ("%lld", &a[i]);
  }
  sort(a + 1, a + n + 1);
  int top = 1, tail = n, cnt = 0;
  long long res = 0;
  while (top + 1 < tail) ans[++cnt] = a[top++], ans[++cnt] = a[tail--];
  if (top == tail) {
    ans[0] = a[tail];
  }
  else {
    ans[0] = a[tail];
    ans[++cnt] = a[top];
  }
  long long ans1 = 0;
  for (int i = 0; i < n - 1; i++) {
    ans1 += abs(ans[i + 1] - ans[i]);
  }
  res = max(res, ans1);
  top = 1;
  tail = n;
  cnt = 0;
  memset(ans, 0, sizeof ans);
  while (top + 1 < tail) ans[++cnt] = a[tail--], ans[++cnt] = a[top++];
  if (top == tail) {
    ans[0] = a[tail];
  }
  else {
    ans[0] = a[tail];
    ans[++cnt] = a[top];
  }
  long long ans2 = 0;
  for (int i = 0; i < n - 1; i++) {
    ans2 += abs(ans[i + 1] - ans[i]);
  }
  res = max(res, ans2);
  cout<<res<<endl;
  return 0;
}
/*}}}*/

/*Define {{{*/
/*}}}*/


Measured memory_bytes: 1792
#include<stdio.h>
char s[128];
bool vis[128];
int a[128];
int wz[128];
int num[128];
int n,k;
int jc[512],injc[512];
int answer=0;
bool sol(int m)
{
	for(int i=0;i<k;i++)
	{
		vis[i]=false;
	}
	int now=0;
	for(int i=0;i<m;i++)
	{
		while(s[now]=='b'||vis[now])
		{
			now++;
			if(now==k)
			{
				return false;
			}
		}
		wz[i]=now;
		vis[now]=true;
	}
	now=0;
	for(int i=0;i<m;i++)
	{
		if(a[i]==1)
		{
			break;
		}
		while(s[now]=='r'||vis[now]||now<wz[i])
		{
			now++;
			if(now==k)
			{
				return false;
			}
		}
		wz[i]=now;
		vis[now]=true;
	}
	now=0;
	for(int i=0;i<m;i++)
	{
		if(a[i]<=2)
		{
			break;
		}
		int rm=a[i]-2;
		while(rm--)
		{
			while(vis[now]||now<wz[i])
			{
				now++;
				if(now==k)
				{
					return false;
				}
			}
			wz[i]=now;
			vis[now]=true;
		}
	}
	for(int i=1;i<=k;i++)
	{
		num[i]=0;
	}
	for(int i=0;i<m;i++)
	{
		num[a[i]]++;
	}
	int ans=jc[m];
	for(int i=1;i<=k;i++)
	{
		ans=(long long)ans*injc[num[i]]%1000000007;
	}
	int nums=m+1;
	int nume=2;
	for(int i=0;i<m;i++)
	{
		if(a[i]==1)
		{
			nums++;
		}
		else
		{
			nume+=2;
			nums+=(a[i]<<1)-1;
		}
	}
	int u=n+nume-1;
	int d=nums-1;
	if(d>u)
	{
		return false;
	}
	ans=(long long)ans*jc[u]%1000000007;
	ans=(long long)ans*injc[d]%1000000007;
	ans=(long long)ans*injc[u-d]%1000000007;
	answer+=ans;
	if(answer>=1000000007)
	{
		answer-=1000000007;
	}
	return true;
}
void dfs(int wz,int mx,int rm)
{
	if(!sol(wz))
	{
		return;
	}
	if(mx>rm)
	{
		mx=rm;
	}
	for(int i=1;i<=mx;i++)
	{
		a[wz]=i;
		dfs(wz+1,i,rm-i);
	}
}
int main()
{
	injc[1]=1;
	for(int i=2;i<=300;i++)
	{
		injc[i]=(long long)1000000007/i*injc[1000000007%i]%1000000007;
		injc[i]=1000000007-injc[i];
	}
	jc[0]=1;
	injc[0]=1;
	for(int i=1;i<=300;i++)
	{
		jc[i]=(long long)jc[i-1]*i%1000000007;
		injc[i]=(long long)injc[i-1]*injc[i]%1000000007;
	}
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	dfs(0,k,k);
	printf("%d\n",answer);
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

typedef long long ll;
const int INF=1e8;

int N;

int dig(int n){
	int ret=0;
	while(n>0){
		ret+=n%10;
		n/=10;
	}
	return ret;
	
}

int main(){
	cin>>N;
	int ans=INF;
	FOR(i,1,N){
		int j=N-i;
		ans=min(ans,dig(i)+dig(j));
	}
	cout<<ans<<endl;
	return 0;
}


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

//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define dbg(x) cerr<<#x<<" : "<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
clock_t time_p=clock();
void timer(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}

template <typename Arg1> ostream& operator << (ostream& out, const vector<Arg1> &a) {out<<"[ ";for(const auto &x:a)out<<x<<" ";return out<<"]";}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b;
    cin>>a>>b;
    ll n = __gcd(a,b);
    ll ans = 1; //for 1;

    bool flag= false;
    while(n%2 == 0){
        flag = true;
        n /= 2;
    }
    if(flag) ans++;
    for(ll i=3; i*i <= n; i += 2){
        flag = false;
        while(n%i == 0){
            flag = true;
            n /= i;
        }
        if(flag){
            ans++;
        }
    }
    if(n > 2){
        ans++;
    }
    cout<<ans<<endl;


    timer();
    return 0;
}


Measured memory_bytes: 256
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;


signed main(){
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);
  int x, y;
  cin >> x >> y;
  double a, b;
  a = (y - 2 * x) / 2.;
  b = (4 * x - y) / 2.;
  string ans = a >= 0 and b >= 0 and abs(a - floor(a)) < .001 and abs(b - floor(b)) < .001 ? "Yes" : "No"; 
  cout << ans << endl;

}


Measured memory_bytes: 3704
#include <cstdio>
int N,count=0;
void dfs(long long,unsigned char);
int main(void)
{
    scanf("%d",&N);
    dfs(0,0);
    printf("%d\n",count);
    return 0;
}
void dfs(long long nextNum,unsigned char flag357)
{
    if(nextNum<=N)
    {
        if(flag357==07)    // 07 is BIN 111
            count++;
        dfs(nextNum*10+3,flag357|01); // BIN 001
        dfs(nextNum*10+5,flag357|02); // BIN 010
        dfs(nextNum*10+7,flag357|04); // BIN 100
    }
}


Measured memory_bytes: 128
import math
n, k = map(int, input().split())
mod = 10**9+7
for i in range(1, k+1):
    if i > n-k+1:
        print(0)
        continue
    count = 0
    i_pos_count = math.factorial(n-k+1) \
                   // (math.factorial(n-k-i+1) * math.factorial(i))
    split_count = math.factorial(k-1) \
                  // (math.factorial(k-i) * math.factorial(i-1))
    count = i_pos_count * split_count
    print(count % mod)


Measured memory_bytes: 66264
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  cout << "ABC";
  string s; cin >> s;
  while(s.length() != 3) s = "0" + s;
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256