akhauriyash/Code-Regression huggingface dataset:
use std::cmp::max;

const COST: [usize; 9] = [2, 5, 5, 4, 5, 6, 3, 7, 6];
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut dp = vec![0; n + 1];
    let mut a = (0..m).map(|_| sc.read::<usize>() - 1).collect::<Vec<_>>();
    a.sort();
    a.reverse();
    for used in 0..n {
        if used > 0 && dp[used] == 0 {
            continue;
        }
        for &a in a.iter() {
            let cost = COST[a];
            if used + cost <= n {
                dp[used + cost] = max(dp[used + cost], dp[used] + 1);
            }
        }
    }

    let mut cur = n;
    while cur > 0 {
        for &a in a.iter() {
            let cost = COST[a];
            if cur >= cost && dp[cur - cost] + 1 == dp[cur] {
                if cur - cost > 0 && dp[cur - cost] == 0 {
                    continue;
                }
                print!("{}", a + 1);
                cur -= cost;
                break;
            }
        }
    }
    println!();
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize1,
        m: usize,
        ab: [(usize1,usize1);m]
    }
    let mut g = vec![Vec::<usize>::new();200_000];
    for (a,b) in ab {
        g[a].push(b);
    }
    for i in &g[0] {
        for j in &g[*i as usize] {
            if *j == n {
                println!("POSSIBLE");
                return;
            }
        }
    }
    println!("IMPOSSIBLE");
}

Measured memory_bytes: 22708
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

"""
条件を満たすとき
a_{(i+k) mod N} xor X = b_i
a_{(i+k+1) mod N} xor X = b_{i+1}が成り立つ
よって,a_{(i+k) mod N} xor a_{(i+k+1) mod N} = b_i xor b_{i+1}
各iについてb_i xor b_{i+1}を求めたリストをB,
数列aを2つ繋げて,a_i xor a_{i+1}を求めたリストをA,
BとAを繋げたリストをCとする.
Z_algorithmを用いるとSとS[i:|S|-1]の最長共通接頭辞の長さがO(N)で出せるので,
CにZ_algorithmを用いると,最初のBとAの共通部分列の長さが出せる.
共通部分列の長さがN以上のとき,条件を満たす.
"""

def Z_algorithm(s):
    n = len(s)
    Z = [0]*n
    Z[0] = n
    i,j = 1,0
    while i < n:
        while i+j < n and s[j] == s[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
 
        #再利用部分
        while i+k < n and k+Z[k] < j:
            Z[i+k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z

n = I()
a = LI()
b = LI()

x = [a[i%n]^a[(i+1)%n] for i in range(2*n)]
y = [b[i%n]^b[(i+1)%n] for i in range(n)]
z = Z_algorithm(y+x)
for i in range(n,2*n):
    if z[i] >= n:
        k = i-n
        x = a[k] ^ b[0]
        print(k,x)


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

int main() {
	long a,b;
	cin>>a>>b;
	
	if(a*b==15){
		cout<<"*"<<endl;
	}
	else if(a+b==15){
		cout<<"+"<<endl;
	}
	else{
		cout<<"x"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

string YorN(bool P) { if (P)return "YES"; else return "NO"; }

int main() {
    int r,g,b;
    cin >> r >> g >> b;

    cout << YorN((g*10+b)%4==0) << endl;

    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    char a[102], b[102], c[102];
    scanf("%s%s%s", a, b, c);
    int i;
    int ans = 0;
    for (i = 0; i < n; i++)
    {
        if (a[i] == b[i] && a[i] == c[i] && b[i] == c[i])
            continue;
        else if (a[i] == b[i] || a[i] == c[i] || b[i] == c[i])
            ans++;
        else
            ans += 2;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
int main() {
  int n, i, x;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    x = i;
    if (x % 3 == 0) {
      printf(" %d", i);
    } else {
      do {
        if (x % 10 == 3) {
          printf(" %d", i);
          x = 0;
        }
        x /= 10;
      } while (x);
    }
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2720
from itertools import product

d, g = map(int, input().split())
g //= 100

p = []
c = []
for _ in range(d):
    p_, c_ = map(int, input().split())
    p.append(p_)
    c.append(c_ // 100)

tmp_prbs = [0] * (2 ** d)
tmp_pts = [0] * (2 ** d)
for i, comp in enumerate(product([False, True], repeat=d)):
    tmp_pts[i] = sum((i+1)*p[i] + c[i] for i in range(d) if comp[i])
    tmp_prbs[i] = sum(p[i] for i in range(d) if comp[i])
    
    for j in reversed(range(d)):
        if tmp_pts[i] >= g:
            break
        if comp[j]:
            continue
        tmp_prbs[i] += min(p[j]-1, -((tmp_pts[i] - g) // (j+1)))
        tmp_pts[i] += min(p[j]-1, -((tmp_pts[i] - g) // (j+1))) * (j+1)
    
print(min(tmp_prb for tmp_pts, tmp_prb in zip(tmp_pts, tmp_prbs) if tmp_pts>=g))
        

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
signed main(){
  queue<string> a,b;
  string c,d,e,f,g;
  int p,z=0;
    cin>>c>>d;
  for(int i=0;i<c.size();i++){
    e=c[i];
    a.push(e);
    b.push(e);
  }
  for(int i=0;i<c.size();i++){
    p=0;
    for(int j=0;j<d.size();j++){
      if(j==0){
	f=a.front();
	a.pop();
	if(f[0]==d[0]){
	  p=p+2;
	}
      }
      else{
	g=a.front();
	a.pop();
	a.push(g);
	if(g[0]==d[j]){
	  p=p+1;
	}
      }
    }
    if(p==d.size()+1){
      cout<<"Yes\n";
      z=1;
      break; 
    }
    for(int k=0;k<c.size()-d.size();k++){
      g=a.front();
      a.push(g);
      a.pop();
    }
    a.push(f);
  }
  if(z==0) cout<<"No\n";
}



Measured memory_bytes: 3228
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}
#define FIX cout << fixed << setprecision(15)
signed main() {
  RAPID;
  // デフォルト変数定義
  double n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN2(n,x);
  double sum = 0;
  FOR(i,1,n+1){
    double tmp = 1.0 / n;
    int now = i;
    while(now < x){
      now *= 2;
      tmp /= 2;
    }
    sum += tmp;
  }
  FIX;
  OUT(sum);
}

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

using namespace std;

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

    int ans = 0;
    for (int i=1; i<=n; i+=2) {
        int count = 0;
        for (int j=1; j<=i; j++) {
            if (i%j == 0)
                count++;
        }
        if (count == 8)
            ans++; 
    }

    cout << ans << endl;
}

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

int main(){
int n;
cin >>n;
vector<int>a(n);
for(int i=0;i<n;i++){
  cin >>a.at(i);
}
int ans =0,che=0;
for(int i=0;i<n-1;i++){
  if(a.at(i)>=a.at(i+1)){
    che++;
  }
  else if(a.at(i)<a.at(i+1)){
    ans = max(ans,che);
    che =0;
  }
  if(i==n-2){
    ans = max(ans,che);
    break;
  }
}
cout << ans << endl;
}



Measured memory_bytes: 640
#!/usr/bin/env python3
import math
import sys


def solve(A: int, B: int, H: int, M: int):
    sa = H * 30.0 + M * 0.5
    la = M * 6.0
    a = abs(sa - la)
    if a > 180:
        a = 360 - a
    print((A * A + B * B - 2 * A * B * math.cos(math.radians(a))) ** 0.5)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(A, B, H, M)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9560
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
using namespace std;
typedef long long LL;
 
int main() {
	int t, i, j, k;
	int a, b, c ,d,F=0;
	char A[100];
	
	cin >> a >> b >> c >> d;
 
	F = max(a*b, c*d);
		
		
		cout << F << endl;
	return 0;
}

Measured memory_bytes: 256
# 入力
N, K = map(int, input().split())
A = list(map(int, input().split()))


# MSBから順に0or1を決めていく
# 0にする場合、下位ビットの最適値は貪欲に求まる
def s(i):
    return sum((a >> (i - 1)) & 1 for a in A)


def g(L, b):
    return (
        0 if b == 0 else
        g(L, b - 1) + 2**(b - 1) * s(b) if L < 2**(b - 1) else
        g(L >> 1, b - 1) + 2**(b - 1) * max(
            s(b),
            N - s(b)
        ) if L == (2**b - 1) else
        max(
            g(2**(b - 1) - 1, b - 1) + 2**(b - 1) * s(b),
            g(L - 2**(b - 1), b - 1) + 2**(b - 1) * (N - s(b))
        )
    )


ans = g(K, max(K, *A).bit_length())

# 出力
print(ans)


Measured memory_bytes: 71404
//
//  main.cpp
//  ABC164
//

//  Copyright © 2020 エロやん. All rights reserved.
//

#include <iostream>
using namespace std;
int main(){
    long long  X;
    long long tyokin=100;
    int count=0;
    cin>>X;
    while(tyokin<X)
    {
        tyokin=tyokin*1.01;
        
        count++;
        
    }
    cout<<count;
    
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int H,W,K;
vector<string> S;
int ans = 0;

void solve(string h, string w){
  if(h.size() < H){
    solve(h + "0", w);
    solve(h + "1", w);
  } else if(w.size() < W){
    solve(h, w + "0");
    solve(h, w + "1");
  } else {
    int num = 0;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(h[i] == '1' ||  w[j] == '1'){
          continue;
        } else { 
          if(S[i][j] == '#') num++;
        }
      }
    }
    if(num == K){
      ans++;
    }
  }
}


int main(){
  cout << setprecision(10);
  cin >> H >> W >> K;
  S.assign(H, "");
  for(int i = 0; i < H; i++){
    cin >> S[i];
  }

  solve("", "");
  cout << ans << endl;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
using Graph = vector<vector<ll> >; // グラフ型
const ll INF=99999999999999;
const ll MOD=1000000007;

vector<ll> counter(200010);
vector<ll> purasu(200010);
void dfs(const Graph &G, ll v, ll p, ll c){
  counter[v] += c;
  
  for(auto nv : G[v]){
    if(nv == p) continue;
    dfs(G, nv, v, c+purasu[nv]);
  }
}
 
int main() {
  ll n,q;
  cin >> n >> q;
  Graph G(n);
  rep(i,n-1){
    ll x,y;
    cin >> x >> y;
    G[x-1].push_back(y-1);
    G[y-1].push_back(x-1);
  }
  purasu.assign(200010,0);
  
  rep(i,q){
    ll z,w;
    cin >> z >> w;
    purasu[z-1] += w;
  }
    

  counter.assign(200010, 0);
  

  dfs(G, 0, -1, purasu[0]);
  
  rep(i,n){
    cout << counter[i] << " ";
  }

  
 return 0;
}


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

int main(){
  int M,N;
  cin >> N >> M;
  
  int num_odd = 0;
  int num_even = 0;
  
  if(M > 1){
    num_odd = M*(M - 1) / 2;
  }
  if(N > 1){
    num_even = N*(N - 1)/2;
  }
  cout << num_odd + num_even << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x) for(int i = 0;i < x;++i)
#define FOR(i,x,y) for(int i = x;i < y;++i)
#define ALL(a) a.begin(),a.end()
using ll = long long;


int main()
{
    for(;;)
    {
        int d,n,m;
        int p[234567],k[12345];
        cin >> d >> n >> m;
        if(d == 0)break;
        p[0] = 0;
        REP(i,n-1)
        {
            cin >> p[i + 1];
        }
        sort(p,p+n);
        REP(i,n)
        {
            p[n + i] = p[i] + d;
        }
        int ans = 0;
        REP(j,m)
        {
            cin >> k[j];
            int s = upper_bound(p,p+n+n,k[j]) - p;
            s--;
            int bit = min(p[s + 1] - k[j],k[j] - p[s]);
            ans += bit;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3844
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int N;
char buf[4005];
vector<int> R,G,B;


int main(){

	scanf("%d",&N);
	scanf("%s",buf);

	for(int i = 0; i < N; i++){
		switch(buf[i]){
		case 'R':
			R.push_back(i);
			break;
		case 'G':
			G.push_back(i);
			break;
		case 'B':
			B.push_back(i);
			break;
		}
	}

	ll ans = R.size()*G.size()*B.size();

	for(int i = 0; i < R.size(); i++){
		for(int k = 0; k < G.size(); k++){
			if((R[i]+G[k])%2 == 1)continue;

			if(buf[(R[i]+G[k])/2] == 'B')ans--;
		}
	}
	for(int i = 0; i < R.size(); i++){
		for(int k = 0; k < B.size(); k++){
			if((R[i]+B[k])%2 == 1)continue;

			if(buf[(R[i]+B[k])/2] == 'G')ans--;
		}
	}
	for(int i = 0; i < G.size(); i++){
		for(int k = 0; k < B.size(); k++){
			if((G[i]+B[k])%2 == 1)continue;

			if(buf[(G[i]+B[k])/2] == 'R')ans--;
		}
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 3844
#include <iostream>

using namespace std;
int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  if(a+b <= 2*c) {
    cout << a*x + b*y << endl;
  } else {
    if(x == y) {
      cout << c*(x+y) << endl;
    } else if(x > y) {
      cout << min(2*c*y + a*(x-y), 2*c*x) << endl;
    } else {
      cout << min(2*c*x + b*(y-x), 2*c*y) << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3620
def resolve():
    a, b, c = map(int, input().split())
    d, e, f = map(int, input().split())
    g, h, i = map(int, input().split())
    bingo = [a, b, c, d, e, f, g, h, i]
    n = int(input())
    s=0
    for i in range(n):
        z = int(input())
        if z in bingo:
            index = bingo.index(z)
            bingo[index] = 0

    a = bingo[0]
    b = bingo[1]
    c = bingo[2]
    d = bingo[3]
    e = bingo[4]
    f = bingo[5]
    g = bingo[6]
    h = bingo[7]
    i = bingo[8]

    if a + b + c == 0 or d + e + f == 0 or g + h + i == 0 or a + d + g == 0 or b + e + h == 0 or c + f + i == 0 or a + e + i == 0 or c + e + g == 0:
        print("Yes")
    else:
        print("No")
resolve()

Measured memory_bytes: 38256
flag = 0
N, Y = map(int, input().split())
for i in range(N+1):
  for j in range(N+1-i):
    k = N - i - j
    if 10000 * i + 5000 * j + 1000 * k == Y and k >= 0:
      flag = 1
      print(i,j,k)
      break
  if flag == 1:
    break
    
if flag == 0:
  print(-1,-1,-1)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    if (s == "SUN")
        ans = 7;
    if (s == "MON")
        ans = 6;
    if (s == "TUE")
        ans = 5;
    if (s == "WED")
        ans = 4;
    if (s == "THU")
        ans = 3;
    if (s == "FRI")
        ans = 2;
    if (s == "SAT")
        ans = 1;
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,ans=0;
	cin>>a>>b;
	for(int i=a;i<=b;i++){
		if(i/10000==i%10 && i/1000%10==i%100/10)
			ans++;
	}
	cout<<ans<<endl;
  return(0);
}

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

#define mem(arr, i) fill(arr, arr + sizeof(arr), i)
#define MEM(arr, i) memset(arr, i, sizeof(arr))
#define Push push_back
#define Pair make_pair
#define ALL(x) x.begin(), x.end()
#define X first
#define Y second
#define ACCEL ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef pair<pll,lli> p3l;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
typedef vector<p3l> v3L;
typedef vector<vcL> vvL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
      lli   mod = 1000000007;

/// templates ///

const lli maxN = 2E5;

vcL inv(maxN+5, 1);
vcL fac(maxN+5, 1);

void ADD(lli &x, lli y) {
	x += y;
	if (x >= mod) x -= mod;
	if (x < 0) x += mod;
}

void MUL(lli &x, lli y) {
	x *= y;
	x = (x % mod + mod) % mod;
}

lli mypow(lli b, lli e) {
	lli ans = 1;
	while (e) {
		if (e & 1) MUL(ans, b);
		MUL(b, b);
		e >>= 1;
	}
	return ans;
}

lli modinv(lli n) {
	return mypow(n, mod - 2);
}

void calcInv(lli n) {
	for (int i = 2; i <= n; ++i) {
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	}
}

void calcFac(lli n) {
	for (int i = 2; i <= n; ++i) {
		fac[i] = fac[i - 1] * i % mod;
	}
}

lli cm(lli a, lli b) {
	lli ans = 1;
	if (a < b) return 0;

	MUL(ans, inv[fac[a - b]]);
	MUL(ans, inv[fac[b]]);
	MUL(ans, fac[a]);

	return ans;
}

lli Lucas(lli n, lli m) {
	if (m == 0) return 1;
	return cm(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod;
}

lli doLucas(lli n, lli m) {
	calcInv(mod);
	calcFac(mod);
	return Lucas(n, m);
}

/// coding area ///

const lli maxn = 1E5;

void precal() {

	return;
}

void solve() {
	lli n;
	cin >> n;
	
	vcL num(n);
	for (auto &x : num) {
		cin >> x;
	}
	
	lli nowM = -1;
	bool flag = true;
	
	for (int i = 0; i < n; ++i) {
		nowM = max(nowM, num[i]);
		if (nowM - num[i] >= 2) {
			flag = false;
		}
	}
	
	if (flag) cout << "Yes\n";
	else cout << "No\n";
}

int main() {
	precal();
	int t = 1;
	#ifdef LOCAL
		t = INT_MAX;
	#else
		ACCEL;
	#endif
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}



Measured memory_bytes: 4224
#include <iostream>
#include <cmath>

using namespace std;

int h, w;

// h1, w1が小さいか判定
bool mini(int h1, int w1, int h2, int w2) {
	int hw1 = h1 * h1 + w1 * w1;
	int hw2 = h2 * h2 + w2 * w2;
	if (hw1 < hw2) return true;
	if (hw1 == hw2 && h1 < h2) return true;
	return false;
}

void solve() {
	int resh = 150, resw = 150;
	
	for (int ah = 1; ah <= 150; ah++) {
		for (int aw = ah + 1; aw <= 150; aw++) {
			if (mini(h, w, ah, aw)) {
				if (mini(ah, aw, resh, resw)) {
					resh = ah;
					resw = aw;
				}
			}
		}
	}
	
	cout << resh << " " << resw << endl;
}

int main() {
	while (cin >> h >> w, h) {
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1160
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
for_set_v = v # set用
set_v = set(v)
even = []
odd = []
count = 0 # 置き換えた回数
count_list = []
for num in range(n):
    if num % 2 == 0:
        even.append(v[num])
    else:
        odd.append(v[num])

even_most = Counter(even).most_common()
odd_most = Counter(odd).most_common()
#print(even_most)
#print(odd_most)
if len(set(v)) >= 2:
    if even_most[0][0] != odd_most[0][0]:
        if len(set(even)) != 1:
            count += (n/2) - int(even_most[0][1])
        if len(set(odd)) != 1:
            count += (n/2) - int(odd_most[0][1])
    else:
        try:
            count_list.append(n-int(even_most[0][1])-int(odd_most[1][1]))
            count_list.append(n-int(even_most[1][1])-int(odd_most[0][1]))
            #print(count_list)
            count += int(min(count_list))
        except:
            if len(even_most) == 1:
                count += (n/2)-int(odd_most[1][1])
            elif len(odd_most) == 1:
                count += (n/2)-int(even_most[1][1])
else:
    count += (n/2)
print(int(count))


Measured memory_bytes: 29276
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e16;
const double EPS=1e-8;
const ll mod = 1000000007;

int main(){
	ll n;
	cin>>n;
	vector<ll> a;
	vector<ll> b;
	for(ll i1=0;i1<n+1;i1++){
		ll temp;
		cin>>temp;
		a.push_back(temp);
	}
	for(ll i1=0;i1<n;i1++){
		ll temp;
		cin>>temp;
		b.push_back(temp);
	}
	ll ans=0;
	for(ll i1=0;i1<n;i1++){
		if(b[i1]>a[i1]){
			ans += a[i1];
			b[i1]-=a[i1];
			a[i1]=0;
			if(b[i1]>a[i1+1]){
				ans += a[i1+1];
				a[i1+1]=0;
			}else{
				ans+=b[i1];
				a[i1+1]-=b[i1];
			}

		}else{
			ans += b[i1];
		}
	}
	cout<<ans<<endl;


}


Measured memory_bytes: 2548
n, k = [int(x) for x in input().strip().split()]
ls = []
for _ in range(n):
    ls.append(tuple(int(x) for x in input().strip().split()))

bk = bin(k)[2:]
cands = [k]
for i in range(len(bk)):
    if bk[i] == '1':
        cands.append(int(bk[:i] + '0' + '1'*(len(bk)-i-1), base=2))

m_ = len(cands)
max_ = [0] * m_

for a, b in ls:
    for i in range(m_):
        if a | cands[i] == cands[i]:
            max_[i] += b

print(max(max_))


Measured memory_bytes: 16640
# -*- coding: utf-8 -*-

def b():
    time = []
    time_sum = 0
    nokori_sum = 0
    nokori = []
    N = 5
    for i in range(N):
        s = int(input())
        time.append(s)
        time_sum = time_sum + s
    
    for i in range(N):
        nokori.append(get_nokori(time[i]))
        nokori.sort()
    
    for i in range(N-1):
        nokori_sum = nokori_sum + nokori[i]
    print nokori_sum + time_sum


def get_nokori(cost):
    if cost % 10 == 0:
        return 0
    else:
        n = cost/10
        nokori = 10*(n+1) - cost
        return nokori


def main():
    b()
	
if __name__ == '__main__':
    main()

Measured memory_bytes: 2692
package main

import "fmt"

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

	dp := make([][]float64, n+1, n+1)
	dp[0] = []float64{1.0}

	for i := 1; i <= n; i++ {
		var p float64
		fmt.Scan(&p)

		dp[i] = make([]float64, i+1, i+1)
		for j := 0; j <= i; j++ {
			if j == 0 {
				dp[i][j] = dp[i-1][j] * (1.0 - p)
			} else if j == i {
				dp[i][j] = dp[i-1][j-1] * p
			} else {
				dp[i][j] = dp[i-1][j]*(1.0-p) + dp[i-1][j-1]*p
			}
		}
	}

	answer := 0.0

	for i := (n + 1) / 2; i <= n; i++ {
		answer += dp[n][i]
	}
	fmt.Println(answer)
}


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

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

const double PI = 3.14159265358979323846;
const int mod = 1e9+7;
// int 1e9+7 double 1e-12 long long 1e18

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (s < t){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
s = gets.chomp.split('')

p1 = ['0', '1'] * (s.length / 2 + 1)
p2 = ['1', '0'] * (s.length / 2 + 1)

c1 = s.length.times.count { |i| s[i] != p1[i] }
c2 = s.length.times.count { |i| s[i] != p2[i] }

puts [c1, c2].min


Measured memory_bytes: 8444
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

#define EPS 1e-9

struct crop{
    double ef;
    string name;

    bool operator<(const crop & arg) const{
        if(abs(ef - arg.ef) < EPS){
            return name < arg.name;
        }else{
            return ef > arg.ef;
        }
    }

    crop(int income, int time, string name){
        this->name = name;
        ef = (double) income / time;
    }
};

int main(){
    int n;
    while(cin >> n && n){
        vector<crop> crops;

        string l;
        int p,a,b,c,d,e,f,s,m,time,income;
        for(int i=0;i<n;i++){
            cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
            time = a+b+c+d+e+(d+e)*(m-1);
            income = f*s*m - p;
            crops.push_back(crop(income,time,l));
        }
        sort(crops.begin(), crops.end());

        for(int i=0;i<n;i++){
            cout << crops[i].name << endl;
        }
        cout << "#" << endl;
     
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int now[2]={1,-1};

int main (){
    int n,x,y;
    cin >> n >> x >> y;
    vector<int>ans(n+1,0);
    for(int i=1;i<=n;i++){
        queue<int>q;
        vector<int>cost(n+1,inf);
        cost[i]=0;
        q.push(i);
        while(!q.empty()){
            int st=q.front();q.pop();
            if(st==x){
                if(cost[y]==inf){
                    cost[y]=cost[x]+1;
                    q.push(y);
                }
            }
            if(st==y){
                if(cost[x]==inf){
                    cost[x]=cost[y]+1;
                    q.push(x);
                }
            }
            rep(k,2){
                int nx=st+now[k];
                if(nx<=0||nx>n) continue;
                if(cost[nx]==inf){
                    cost[nx]=cost[st]+1;
                    q.push(nx);
                }
            }
        }
        for(int j=1;j<=n;j++){
            ans[cost[j]]++;
        }
    }
    for(int i=1;i<n;i++){
        cout <<ans[i]/2 <<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
X = [10**9+7]*N
X[0] = 0
for i in range(N):
  if i-1 >= 0 and i-2 >= 0:
    X[i] = min([X[i-1] + abs(h[i]-h[i-1]),X[i-2]+abs(h[i]-h[i-2])])
  elif i-1 >= 0:
    X[i] = X[i-1] + abs(h[i]-h[i-1])
print(X[N-1])

Measured memory_bytes: 20488
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


int N;
int[] A, B;

int[][] G;

Tuple!(int, int) dfs(int u, int p) {
  auto ret = tuple(0, u);
  foreach (v; G[u]) {
    if (v != p) {
      auto tmp = dfs(v, u);
      ++tmp[0];
      chmax(ret, tmp);
    }
  }
  return ret;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      A = new int[N - 1];
      B = new int[N - 1];
      foreach (i; 0 .. N - 1) {
        A[i] = readInt() - 1;
        B[i] = readInt() - 1;
      }
      
      G = new int[][N];
      foreach (i; 0 .. N - 1) {
        G[A[i]] ~= B[i];
        G[B[i]] ~= A[i];
      }
      
      const res0 = dfs(0, -1);
      const res1 = dfs(res0[1], -1);
      const d = res1[0];
      debug {
        writeln(res0, " ", res1);
        writeln("diameter = ", d);
      }
      writeln((d % 3 != 1) ? "First" : "Second");
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 30844
#include <iostream>
using namespace std;
int n;
int x,y,ans;
int a[201][201],b[201][201],c[201];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){cin>>x>>y;a[x][y]=1;}
    for(int i=0;i<n;i++)cin>>x>>y,b[x][y]=1;
    n*=2;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(b[i][j]){
                int k=j-1;
                while(k>=0&&c[k]==0)k--;
                if(c[k])c[k]--,ans++;
            }
        }
        for(int j=0;j<n;j++)if(a[i][j])c[j]++;
    }
    cout<<ans<<endl;
}

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

using namespace std;

void solve(){
	int x;
	int ans = 1;
	for(int i = 1; i <= 5; i++){
		cin>>x;
		if(!x) ans = i;
	}
	cout << ans << "\n";
}
int main() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3560
inf = 10**10

N,M = map(int,input().split())
ab =[list(map(int,input().split())) for i in range(M)]
ab.sort(reverse=True)
ans = 0
tmp = inf
for i in range(M):
    if ab[i][1] > tmp:
        continue
    else:
        ans += 1
        tmp = ab[i][0]
print(ans)


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

ll n, a, ans = 0;
vector<ll> x(1, 0);
vector<vector<vector<ll>>> dp(51, vector<vector<ll>> (51, vector<ll> (2501, 0)));

int main(){
    cin >> n >> a;
    for(int i = 0; i < n; i++){
        ll y;
        cin >> y;
        x.push_back(y);
    }
    sort(x.begin(), x.end());
    for(ll i = 0; i <= n; i++){
        for(ll j = 0; j <= n; j++){
            for(ll k = 0; k <= n*max(a, x.back()); k++){
                if(i == 0 && j == 0 && k == 0){
                    dp[i][j][k] = 1;
                }
                else if(i >= 1 && k < x[i]){
                    dp[i][j][k] = dp[i - 1][j][k];
                }
                else if(i >= 1 && j >= 1 && k >= x[i]){
                    dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
                }
                else{
                    dp[i][j][k] = 0;
                }
            }
        }
    }
    for(ll i = 1; i <= n; i++){
        ans += dp[n][i][i*a];
    }
    cout << ans << endl;
}

Measured memory_bytes: 55068
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int N,s=0,c;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
        s+=a[i];
    }
    int b;
    b = s/N;
    c = b++;
    s=0;
    int s1=0;
    for(int i = 0; i < N; i++){
        s+=(a[i]-b)*(a[i]-b);
    }
    for(int i = 0; i < N; i++){
        s1+=(a[i]-c)*(a[i]-c);
    }
    cout << min(s,s1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	string s,s2;
	sc2(s,s2);
	ans+=(s[0]==s2[0])+(s[1]==s2[1])+(s[2]==s2[2]);
	pr(ans);
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

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

Measured memory_bytes: 3624
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

int main()
{
      ios::sync_with_stdio(0);

      int mark[150] = {0};
      int n, x;
      cin >> x >> n;
      
      while (n--)
      {
            int a;
            cin >> a;
            mark[a] = 1;
      }

      int ans = 1e9;

      for (int i = -150; i < 150; ++i)
      {
            if (mark[i] == 0 && abs(i - x) < abs(ans - x))
                  ans = i;
      }
      cout << ans;

      return 0;
}

Measured memory_bytes: 3652
class MASS
  def initialize(h, w)
    @h = h
    @w = w
    @m = Array.new(@h){Array.new(@w, 0)}
    @x = 0
    @y = 0
    @LR = 1
  end
  def draw(v, n)
    n.times do |i|
      @m[@y][@x] = v + 1
      @x += @LR
      if @x == @w
        @y += 1
        @x = @w - 1
        @LR = -1
      elsif @x < 0
        @y += 1
        @x = 0
        @LR = 1
      end
    end
  end
  def out
    @h.times do |i|
      puts @m[i].join(' ')
    end
  end
end

h, w = gets.split.map(&:to_i)
n = gets.to_i
a = gets.split.map(&:to_i)
m = MASS.new(h, w)
a.each_with_index do |v, i|
  m.draw(i, v)
end
m.out

Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

ll dp[200010];
ll dp2[200010];

int calc(int a,int b){
    int res=0;
    for(int i=0;i<100;i+=2){
        if((a>>i)<b){
            res = i;
            break;
        }
    }
    return res-2;
}
int calc2(int a,int b){
    int res=0;
    for(int i=0;i<100;i+=2){
        if((a>>i)<=b){
            res = i;
            break;
        }
    }
    return res;
}

int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n)cin >> a[i];
    dp[n-1]= 0;
    stack<pair<ll,ll> > st;
    ll s =0;
    for(ll i=n-2;i>=0;i--){
        dp[i] = dp[i+1];
        if(a[i]>a[i+1]){
            ll p = calc2(a[i],a[i+1]);
            ll t = i; 
            while(p!=0){
                if(st.size()==0){
                    dp[i] += p*(n-1-t);
                    p = 0;
                    break;
                }
                auto q = st.top();
                st.pop();
                if(q.first>p){
                    dp[i] += p*(q.second-t-1);
                    q.first-=p;
                    st.push(q);
                    p = 0;
                }else{
                    dp[i] += p*(q.second-t-1);
                    p-= q.first;
                    t = q.second-1;
                }
            }
        }else{
            ll p = calc(a[i+1],a[i]);
            if(p!=0)st.push(MP(p,i+1));
        }
    }
    reverse(a.begin(),a.end());
    dp2[n-1] = 1;
    while(!st.empty()){
        st.pop();
    }
    for(ll i=n-2;i>=0;i--){
        dp2[i] = dp2[i+1]+1;
        if(a[i]>a[i+1]){
            ll p = calc2(a[i],a[i+1]);
            ll t = i; 
            while(p!=0){
                if(st.size()==0){
                    dp2[i] += p*(n-1-t);
                    p = 0;
                    break;
                }
                auto q = st.top();
                st.pop();
                if(q.first>p){
                    dp2[i] += p*(q.second-t-1);
                    q.first-=p;
                    st.push(q);
                    p = 0;
                }else{
                    dp2[i] += p*(q.second-t-1);
                    p-= q.first;
                    t = q.second-1;
                }
            }
        }else{
            ll p = calc(a[i+1],a[i]);
            if(p!=0)st.push(MP(p,i+1));
        }
    }
    ll ans = 1LL<<60;
    // for(int i=0;i<n;i++){
    //     cerr << dp[i] << " ";
    // }
    // cerr << endl;
    // for(int i=0;i<n;i++){
    //     cerr << dp2[i] << " ";
    // }
    // cerr << endl;
    ans = min(ans,dp[0]);
    ans = min(ans,dp2[0]);
    for(int i=1;i<n;i++){
        ans = min(ans,dp[i]+dp2[n-i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long int Int;

bool dist[8][8];



int main(void)
{
    int n,m;
    vector<int> a;

    cin>>n>>m;
    for(int i = 0;i < 8;i++) {
	for(int j = 0;j < 8;j++) {
	    dist[i][j] = false;
	}
    }

    for(int i = 0;i < m;i++)
    {
	int x,y;
	cin>>x>>y;
	x--;
	y--;
	dist[x][y] = true;
	dist[y][x] = true;
    }

    for(int i = 0;i < n;i++)
	a.push_back(i);

    Int ans = 0;
    do
    {
	if(a[0] != 0)
	    continue;

	bool flag = true;
	for(int i = 0;i < n-1;i++)
	    if(!dist[a[i]][a[i+1]])
		flag = false;

	if(flag)
	    ans++;
	    
    }while(next_permutation(a.begin(),a.end()));

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
alist = []
for i in range(n):
    alist.append(int(input()))
alist.sort()
lar = alist[n//2:]
sma = alist[:n//2]
if n%2 == 0:
    ans = lar[0]-sma[-1]
    ans += 2*(sum(lar[1:])-sum(sma[:-1]))
    print(ans)
else:
    ans1 = lar[0]+lar[1]
    ans1 += 2*(sum(lar[2:])-sum(sma))
    ans2 = -sma[-1]-lar[0]
    ans2 += 2*(sum(lar[1:])-sum(sma[:-1]))
    print(max(ans1,ans2))

Measured memory_bytes: 8160
#include <cstdio>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void) {
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  printf("%d\n", min(a, b) + min(c, d));
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using itn = int;//typpo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl kai(intl k){//k!を求める関数
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

//--------------入力受け取る場所,分けてた方がデバッグしやすい気がする---------------------
intl n,m;
intl a,b,c,d;
string s,t;

void input_var(){
    cin >> n;
    cin >> s;
}
//-------------------------------------------------------------------------------


signed main(){
    cout << fixed << setprecision(10);
    input_var();
    intl len = s.length();
    t = "";
    if(len <= n)t = s;
    else{
        rep(i,n){
            t += s[i];
        }
        t += "...";
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll n;
  cin >> n;
  vector<ll> h(n), cnt(n, 0);
  rep(i, 0, n){
    cin >> h[i];
  }
  ll ans = 0;
  bool ok = false;
  while(1){
    rep(i, 0, n){
      if(h[i] > cnt[i]){
        cnt[i]++;
        if(ok == false) ans++, ok = true;
      }else ok = false;
      //cout << cnt[i] << ' ';
    }
    //cout << endl;
    if(ok) ok = false;

    ll cn = 0;
    rep(i, 0, n){
      if(h[i] == cnt[i]) cn++;
    }
    if(cn == n) break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256