akhauriyash/Code-Regression huggingface dataset:
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(h1:i64 m1:i64 h2:i64 m2:i64 k:i64));
    (((h2 * 60 + m2) - (h1 * 60 + m1)) - k).max(0).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}
tests! {
    test1: "10 0 15 0 30\n" => "270\n",
    test2: "10 0 12 0 120\n" => "0\n",
}


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

using namespace std;

void print_vector(const vector<int> &v) {
	cout << v[0];
	for (auto i = 1u; i < v.size(); ++i) {
		cout << ' ' << v[i];
	}
	cout << '\n';
}

int main() {
	int N;
	cin >> N;
	
	vector<int> arr(N);
	for (auto &a: arr) {
		cin >> a;
	}

	print_vector(arr);
	for (int i = 1; i < N; ++i) {
		int current = arr[i];
		int j = i-1;
		for (; j >= 0 && current < arr[j]; --j) {
			arr[j+1] = arr[j];
		}
		arr[j+1] = current;
		print_vector(arr);
	}
}


Measured memory_bytes: 3068
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main()
{
    int n, m;
    cin >> n >> m;
    ll a[100002];
    vector<int> v[100002];
    cin >> a[0];
    a[0]--;
    v[a[0]].push_back(0);
    ll now = 0;
    ll cross = 0;
    for(int i = 1; i < n; i++){
        cin >> a[i];
        a[i]--;
        v[a[i]].push_back(i);
        if(a[i] < a[i - 1]){
            cross++;
            now += a[i] + 1;
        }
        else now += a[i] - a[i - 1];
    }
    ll ans = now;
    for(int i = 1; i < m; i++){
        for(int x : v[i - 1]){
            if(x == 0) continue;
            cross--;
            now += (a[x] - a[x - 1] + m - 1) % m;
        }
        now -= cross;
        for(int x : v[i - 1]){
            if(x == n - 1) continue;
            cross++;
        }
        ans = min(ans, now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define PI acos(-1)
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cerr<<x<<endl;
#define endl "\n"
#define pb push_back
#define min3(a,b,c) min(a,min(b,c)) 
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int nmax=1e5+10;
const int eps=1e-8;


int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(10);
    //cout<<fixed;
    //cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int>h(n+1);
    for(int i=1;i<=n;i++)
        cin>>h[i];


    vector<int>dp(n+5,inf);
    dp[1]=0;

    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=i+k;j++)
        {
            if(j<=n)
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
        }
    }

    cout<<dp[n];

    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int i;
int main()
{
	scanf("%d",&i);
	if(i%10==7||(i/10)%10==7||i/100==7) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 3828
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
vector<int>memo;
signed main() {
	while (1) {
		int a;
		cin >> a;
		if (a == 0)break;
		memo.push_back(a);
	}
	rep(i, memo.size())cout << "Case" << " " << i + 1 << ":" << " " << memo[i] << endl;
	ggr
}



Measured memory_bytes: 3176
str1 = io.read()
str2 = io.read()
str3 = io.read()

str1 = string.sub(str1, 1, 1)
str2 = string.sub(str2, 2, 2)
str3 = string.sub(str3, 3, 3)
print(str1 .. str2 .. str3)

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n, m;
  cin >> n >> m;
  vp p(m);
  rep(i,m) cin >> p[i].fi >> p[i].se;
  rep(x,1000) {
    int keta = 1;
    int nx = x/10;
    vi d(1,x%10);
    while (nx) {
      keta++;
      d.pb(nx%10);
      nx /= 10;
    }
    if (keta != n) continue;
    reverse(rng(d));
    bool ok = true;
    rep(i,m) {
      if (d[p[i].fi-1] != p[i].se) ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    struct p {
        public int x, y;
        public p(int X, int Y) {
            x = X;
            y = Y;
        }
    }
    static void Main() {
        int H = cin.Int();
        int W = cin.Int();
        var S = Enumerable.Repeat(0, H).Select(_ => Console.ReadLine()).ToArray();

        var dx = new int[] { -1, 1, 0, 0 };
        var dy = new int[] { 0, 0, -1, 1 };
        var que = new Queue<p>();

        var cnt = new int[H, W];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cnt[i, j] = -1;
            }
        }
        cnt[0, 0] = 1;
        que.Enqueue(new p(0, 0));

        while(que.Count > 0) {
            p tmp = que.Dequeue();
            int nx = tmp.x;
            int ny = tmp.y;
            if (ny == H - 1 && nx == W - 1) break;
            for (int i = 0; i < 4; i++) {
                if(0 <= ny + dy[i] && ny + dy[i]< H && 0 <= nx + dx[i]&& nx + dx[i] < W){
                    if (S[ny + dy[i]][nx + dx[i]] != '#' && cnt[ny + dy[i], nx + dx[i]] == -1) {
                        que.Enqueue(new p(nx + dx[i], ny + dy[i]));
                        cnt[ny + dy[i], nx + dx[i]] = cnt[ny, nx] + 1;
                    }
                }
            }
        }

        if (cnt[H - 1, W - 1] == -1) Console.WriteLine(-1);
        else {
            int black = 0;
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if (S[i][j] == '#') black++;
                }
            }

            Console.WriteLine(H * W - black - cnt[H - 1, W - 1]);
        }
        Console.ReadLine();
    }
}

Measured memory_bytes: 13524
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

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

  if(n < 10){
    r += 100 * (10-n);
  }
  
  cout << r << endl;
}

Measured memory_bytes: 3572
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n,a,b;
  scanf("%d%d%d",&n,&a,&b);
  if(ABS(a-b)==1 && (a==1 || a==n)){
    printf("Borys\n");
    return;
  }
  printf("%s\n",ABS(a-b-1)%2==0?"Borys":"Alice");
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <assert.h>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
//#include <cmath>

int main(){
    int32_t N, M;
    std::cin >> N >> M;

    // sort A ... O(NlogN), for each j(1<=j<=M),
    // check if A[0] to A[Bi] is smaller than C, swap ... M*N
    // re-sort ... O(NlogN) with Naiive
    // overall ... M*N*NlogN
    //  re-sort need to check against previously updated values Bx <= N, and they have the same value(Ci).
    //      start from A[Bx+1] find the value where Ai > Ci, then swap.
    //      -> O(N)
    //    -> overall O(MN*N)
    //
    // Another approach
    // from Bi to BM, don't have to update sequentially.
    // Create Max updated value array. 1.sort Cs in decsendant order, 2. take B items until the length reach to N. MlogM -> M 
    // then compare with sorted A(NlogN), take bigger value(N).
    // -> overall NlogN

    std::vector<int32_t> A(N);
    for(auto& a : A){
        std::cin >> a;
    }
    std::sort(A.begin(), A.end());
    
    using BCpair_t = std::pair<int32_t, int32_t>;
    using ops_vec_t = std::vector<BCpair_t>;
    ops_vec_t ops_vec(M);
    for(auto& pair : ops_vec){
        std::cin >> pair.second >> pair.first;
    }

    // sort ops with C
    std::sort(ops_vec.begin(), ops_vec.end(), std::greater<>());
    // create max updatable vector
    std::vector<int32_t> update_vect(N);
    int32_t update_vec_length = 0;
    for(int32_t i = 0; i < M; i++){
        int32_t C = ops_vec[i].first;
        int32_t B = ops_vec[i].second;
        int32_t num_put = std::min(B, N - update_vec_length);
        for(int32_t j = 0; j < num_put; j++){
            update_vect[update_vec_length + j] = C;
        }
        update_vec_length += num_put;
        assert(update_vec_length <= N);
        if(update_vec_length == N){
            break;
        }
    }
    while(update_vec_length < N){
        update_vect[update_vec_length] = 0;
        update_vec_length++;
    }

    // replace A's smallest value with update_vec's biggest value.
    // std::vector<int32_t> res_vec(N);
    int64_t res = 0;
    for(int32_t i = 0; i < N; i++){
        res += std::max(A[i], update_vect[i]);
    }

    std::cout << res;
    

    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  string s, t;
  cin >> s >> t;
  vector<int> s_((int)s.size());
  vector<int> t_((int)t.size());
  for (int i = 0; i < (int)s.size(); ++i) {
    s_[i] = (int)s[i] - (int)'a';
  }
  for (int i = 0; i < (int)t.size(); ++i) {
    t_[i] = (int)t[i] - (int)'a';
  }

  sort(s_.begin(), s_.end());
  sort(t_.rbegin(), t_.rend());

  for (int i = 0; i < min((int)s_.size(), (int)t_.size()); ++i) {
    if (s_[i] < t_[i]) {
      cout << "Yes" << endl;
      return 0;
    } else if (s_[i] == t_[i]) {
      continue;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  if (s_.size() < t_.size()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
# 解答AC

N = int(input())

M = 0
ans = []

# 1 <= i < j <= N

if N % 2 == 0:
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            if i + j != N + 1:
                ans.append((i, j))
                M += 1
else:
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            if i + j != N:
                ans.append((i, j))
                M += 1

print(M)
for i, j in ans:
    print(i, j)

Measured memory_bytes: 3956
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
 
ll n,k,x,y;
 
int main(){
  ll ans=1;
  cin >> n;
  
  ll cnt=0;
  vi a(n),b(n);
  REP(i,n){
	  cin>>a[i];
	  if (a[i]<n){
	  b[a[i]]+=1;
	  cnt++;
	  }
  }
 
  if (a[0]!=0){
	cout<<0<<endl;
	return 0;
  }
  if (b[0]!=1){
	cout<<0<<endl;
	return 0;
  }
  if (n==1){
	cout<<1<<endl;
	return 0;
  }
  if (cnt!=n){
	  cout<<0<<endl;
	  return 0;
  }
 
 
 
  ll w=n;
  for(ll i=1;i<n;i++){
	  if (b[i]==0){
		  w=i;
		  break;
	  }
	  REP(j,b[i]){
		ans*=b[i-1];
		ans%=998244353LL;
	  }
  }
  
  for(ll i=w;i<n;i++){
	  if (b[i]!=0)ans=0;
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1792
h,w = map(int, input().split())
a = [list(map(int,input().split())) for i in range(h)]

ans = 1e9
for i in range(h):
    for j in range(w):
        cnt = 0
        for m,row in enumerate(a):
            for n,x in enumerate(row):
                cnt += min(abs(i-m),abs(j-n))*x
        ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 5624
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

struct pii_cmp {
  bool operator()(const pii& x, const pii& y) const {
    return x.second < y.second;
  }
};

int main() {
    int n;
    cin >> n;
    map<int, int> m1, m2;

    for (int i = 0; i < n; i++) {
        int v;
        cin >> v;
        if (i & 1) {
            if (m1.find(v) != m1.end()) {
                m1[v] += 1;
            } else {
                m1[v] = 1;
            }
        } else {
            if (m2.find(v) != m2.end()) {
                m2[v] += 1;
            } else {
                m2[v] = 1;
            }
        }
    }

    priority_queue<pii, vector<pii>, pii_cmp> q1, q2;
    for (auto x: m1) {
        q1.push(x);
    }
    for (auto x: m2) {
        q2.push(x);
    }

    int cnt = 0;
    if (q1.top().first != q2.top().first) {
        q1.pop(); q2.pop();
        while (!q1.empty()) {
            cnt += q1.top().second;
            q1.pop();
        }
        while (!q2.empty()) {
            cnt += q2.top().second;
            q2.pop();
        }
        cout << cnt << endl;
        return 0;
    } else {
        int r1 = 0, r2 = 0;
        r1 += q1.top().second;
        r2 += q2.top().second;
        q1.pop(); q2.pop();
        if (!q1.empty()) r2 += q1.top().second;
        if (!q2.empty()) r1 += q2.top().second;
        cout << n - max(r1, r2) << endl;

        // if (q1.top().second >= q2.top().second) {
        //     q1.pop();
        //     cnt += q2.top().second; q2.pop();
        //     if (!q2.empty()) q2.pop();
        //     while (!q1.empty()) {
        //         cnt += q1.top().second;
        //         q1.pop();
        //     }
        //     while (!q2.empty()) {
        //         cnt += q2.top().second;
        //         q2.pop();
        //     }
        //     cout << cnt << endl;
        // } else {
        //     q2.pop();
        //     cnt += q1.top().second; q1.pop();
        //     if (!q1.empty()) q1.pop();
        //     while (!q1.empty()) {
        //         cnt += q1.top().second;
        //         q1.pop();
        //     }
        //     while (!q2.empty()) {
        //         cnt += q2.top().second;
        //         q2.pop();
        //     }
        //     cout << cnt << endl;
        // }
        return 0;
    }
}


Measured memory_bytes: 6136
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << x << endl
using namespace std;
int input() {
	int r;
	cin >> r;
	//scanf("%lld", &r);
	return r;
}
int n, p, cnt[3], k = 0, c = 1;
signed main() {
	cin >> n >> p;
	while (n--)cnt[input() % 2]++;
	for (int i = p; i <= cnt[1]; i += 2) {
		if (i == 1)c = cnt[1];
		k += c;
		c *= (cnt[1] - i) * (cnt[1] - i - 1);
		c /= (i + 1) * (i + 2);
	}
	for0(i, cnt[0])k *= 2;
	puts(k);
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
const long long MOD = 1000000007;
int main() {
  while (cin >> N) {
	long long res = 1;
	for (long long n = 1; n <= N; ++n) {
	  res *= n;
	  res %= MOD;
	}
	cout << res << endl;
  }
}


Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
H = iil()
ans = 0
high = H[0]
for item in H:
    if item >= high:
        ans += 1
    high = max(item,high)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	string s; cin>>s;
	vector<vector<bool>> poss(n,vector<bool>(1000,false)), poss2=poss, poss3=poss;
	poss[0][s[0]-'0']=true;
	for (int i=1; i<n; i++) {
		poss[i]=poss[i-1];
		poss[i][s[i]-'0']=true;
	}

	for (int i=1; i<n; i++) {
		poss2[i]=poss2[i-1];
		for (int j=0; j<10; j++)
			if(poss[i-1][j])
				poss2[i][j*10+s[i]-'0']=true;
	}

	for (int i=2; i<n; i++) {
		poss3[i]=poss3[i-1];
		for (int j=0; j<100; j++)
			if(poss2[i-1][j])
			poss3[i][j*10+s[i]-'0']=true;
	}
	int ret=0;
	for (int i=0; i<1000; i++)
		if(poss3[n-1][i])
			ret++;
	cout<<ret<<"\n";
	return 0;
}

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

template<typename T>
T largest_rectangle(vector<T> &v) {
    int n = v.size();
    vector<int> L(n, -1);
    vector<int> R(n, n);
    // index, height
    using P = pair<int, T>;
    stack<P> sl;
    stack<P> sr;

    // L
    for (int i = n - 1; i >= 0; --i) {
        // stackに入っているより大きい要素を取り除く
        while (!sl.empty() && sl.top().second > v[i]) {
            // 現在のindexを渡す
            L[sl.top().first] = i;
            sl.pop();
        }
        // stackへ追加
        sl.emplace(i, v[i]);
    }

    // R
    for (int i = 0; i < n; ++i) {
        // stackに入っているより大きい要素を取り除く
        while (!sr.empty() && sr.top().second > v[i]) {
            // 現在のindexを渡す
            R[sr.top().first] = i;
            sr.pop();
        }
        // stackへ追加
        sr.emplace(i, v[i]);
    }

    T res = numeric_limits<T>::min();
    for (int i = 0; i < n; ++i) {
        res = max(res, v[i] * (R[i] - L[i] - 1));
    }
    return res;
}

/*
    verified https://onlinejudge.u-aizu.ac.jp/problems/DPL_3_C
*/
int main() {
    int N;
    cin >> N;
    vector<long long> h(N);
    for (int i = 0; i < N; ++i) cin >> h[i];
    cout << largest_rectangle(h) << endl;
}


Measured memory_bytes: 7544
#include <iostream>
using namespace std;
int main(){
	int x,i;
	int a[100];
	cin >> x;
	for( i=0; i<x; i++ ){
		cin >> a[i];
	}
	for( i=x-1; i>=0; i-- ){
		if( i!=x-1 ) cout << " ";
		cout << a[i];
	}
	cout << endl; 

	return 0;
}

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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int N;
  cin >> N;
  vector<bool> color(8, false);
  int rate, cnt = 0;
  for(int i = 0; i < N; i++) {
    cin >> rate;
    if     (rate < 400)  color[0] = true;
    else if(rate < 800)  color[1] = true;
    else if(rate < 1200) color[2] = true;
    else if(rate < 1600) color[3] = true;
    else if(rate < 2000) color[4] = true;
    else if(rate < 2400) color[5] = true;
    else if(rate < 2800) color[6] = true;
    else if(rate < 3200) color[7] = true;
    else if(rate >= 3200)                cnt++;
  }

  cout << max(accumulate(color.begin(), color.end(), 0), 1) << " " << accumulate(color.begin(), color.end(), 0) + cnt << endl;

  return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main () {
    long long int n, k, i, j, ans, c1 ;
    scanf ( "%lld %lld", &n, &k ) ;
    ans = 0 ;
    for ( i = k ; i <= n ; i++ ) {
        if ( i == 0 ) {
            ans = n * n ;
            break ;
        }
        c1 = n / i ;
        ans += ( i - k ) * c1 ;
        j = n % ( c1 * i ) ;
        if ( j - k + 1 > 0 ) {
            ans += j - k + 1 ;
        }
    }
    printf ("%lld\n", ans ) ;
    return 0 ;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a>>b>>c>>d;
  int p=abs(b-a);
  int q=abs(c-b);
  int u=abs(c-a);
  string s="No";
  if(p<=d && q<=d){
    s="Yes";
  }
  if(u<=d){
    s="Yes";
  }
  cout << s;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    using ull = unsigned long long;
    int n;
    cin >> n;
    vector< ull > a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++){
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    const ull mx = 1e18;
    ull ans = 1;
    for(int i=0;i<n;i++){
        if(a[i]>mx/ans){
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

struct edge{int to, cost;};

class Graph
{
public:
    int N;
    vector<vector<edge>> G;
    vec dp;

    Graph(int N): N(N){
        G = vector<vector<edge>>(N, vector<edge>(0));
        dp = vec(N, 0);
    }

    void add_edge(int from, int to, int cost = 0){
        G[from].push_back(edge({to, cost}));
    }

    void add_edge2(int v1, int v2, int cost = 0){
        add_edge(v1, v2, cost);
        add_edge(v2, v1, cost);
    }

    void dfs(int v, int p = -1, int c = -1){
        if(p != -1) dp[v] = dp[p] + c;
        for(auto e: G[v]) if(e.to != p) dfs(e.to, v, e.cost);
    }

};

signed main(){

    int N; cin >> N;
    Graph G(N);
    int u, v, w;
    REP(i, N - 1){
        cin >> u >> v >> w;
        G.add_edge2(u - 1, v - 1, w);
    }
    G.dfs(0);
    REP(i, N) Out(G.dp[i] % 2);

    return 0;
}


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

using namespace std;

using ll = long long;

constexpr char endl('\n');

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)

size_t smaller_count(size_t pos, vector<size_t> & v) {
    size_t k = v.at(pos);
    size_t ret = 0;
    FOR(i, pos + 1, v.size()) {
        if (k > v.at(i)) ++ret;
    }
    return ret;
}

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

    size_t n;
    cin >> n;
    vector<size_t> p(n);
    vector<size_t> q(n);
    vector<size_t> f(n+1);
    f.at(0) = 1;

    REP(i, n) {
        cin >> p.at(i);
    }
    REP(i, n) {
        cin >> q.at(i);
    }
    FOR(i, 1, n+1) {
        f.at(i) = f.at(i-1)*i;
    }
    size_t a = 0;
    REP(i, n) {
        a += f.at(n - 1 - i) * smaller_count(i, p);
    }
    size_t b = 0;
    REP(i, n) {
        b += f.at(n - 1 - i) * smaller_count(i, q);
    }
    ll diff = a - b;
    if (diff < 0) diff = -diff;
    cout << diff << ::endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int n, y, ans;

int main()
{
    cin >> n >> y;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n - i; j++)
        {
            if (y == 10000 * i + 5000 * j + 1000 * (n - i - j))
            {
                cout << i << " " << j << " " << n - i - j << endl;
                return 0;
            }
        }
    }
    puts("-1 -1 -1");
}


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

#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    int N, M;
    cin >> N >> M;
    cout << N * (N - 1)/2 + M * (M - 1)/2;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define OPERATOR_PLUS -1
#define OPERATOR_ASTERISK -2

/* 演算子の優先度を指定して計算式を計算する */
int calculate(const int* expression, int length, int plusPriority, int asteriskPriority) {
	int e[17];
	int i, j, p;
	for (i = 0; i < length; i++) e[i] = expression[i];

	/* 計算 */
	for (p = 0; p < 2; p++) {
		for (i = 0; i < length - 2; i++) {
			int flag = 0; /* 演算が行われたか */
			if (p == plusPriority && e[i+1] == OPERATOR_PLUS) {
				e[i] += e[i+2];
				flag = 1;
			} else if (p == asteriskPriority && e[i+1] == OPERATOR_ASTERISK) {
				e[i] *= e[i+2];
				flag = 1;
			}
			/* 処理を終えた計算式を消去して詰める */
			if (flag) {
				for (j = i + 1; j < length - 2; j++) {
					e[j] = e[j+2];
				}
				length -= 2;
				i--;
			}
		}
	}

	return e[0];
}

int main(void) {
	int expression[17];
	int length = 0;
	int answer;
	int m, l;
	char c;

	/* 計算式を読み込む */
	while (scanf("%1[0-9+*]", &c) == 1) {
		if (c == '+') expression[length++] = OPERATOR_PLUS;
		else if (c == '*') expression[length++] = OPERATOR_ASTERISK;
		else if (c >= '0' && c <= '9') expression[length++] = c - '0';
	}
	/* 計算結果を読み込む */
	scanf("%d", &answer);

	/* 各演算規則で実際に計算する */
	m = calculate(expression, length, 1, 0);
	l = calculate(expression, length, 0, 0);

	/* 出力 */
	if (answer == m && answer == l) c = 'U';
	else if (answer == m) c = 'M';
	else if (answer == l) c = 'L';
	else c = 'I';
	printf("%c\n", c);

	return 0;
}

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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v[111111],v1;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c,h;

int o[1111][1111];
int l[3];
int j[1];
int e;


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> s[222][22];
//priority_queue<P> q;
queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

//string r,r1;
char r[2222][1111];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;

}




int main()
{
    scanf("%d %d",&a,&b);
    memset(o,-1,sizeof(o));
    for(int t=1;t<=a;t++)
        scanf("%s",r[t]+1);
    o[1][1]=1;
    for(int t=1;t<=a;t++)
        for(int w=1;w<=b;w++)
            if(r[t][w]=='.')
            if(t!=1||w!=1)
            o[t][w]=(max(o[t-1][w],0)+max(o[t][w-1],0))%mod;
    printf("%d",o[a][b]);
}





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

int main() {
  string S; cin >> S;
  int count = 0;
  
 
  for(int i=0; i<S.length()-1; i++) {
    if(S[i]=='0' && S[i+1]!='1') {
      S[i+1] = '1';
      count++;
    }else if(S[i]=='1' && S[i+1]!='0'){
      S[i+1] = '0';
      count++;
    }
  }  
    cout << count << endl;  
}
      
      

Measured memory_bytes: 512
n,k=map(int,input().split())
P=[int(i) for i in input().split()]
import collections
from collections import deque
M1,M2=deque(),deque()
A1,A2=[],[]
M1.append(0)
for i in range(1,n):
  while M1:
    if P[M1[-1]]>P[i]:
      M1.pop()
    else:
      M1.append(i)
      break
  if not M1:
    M1.append(i)
  if M1[0]==i-k-1:
    M1.popleft()
  if i<k:
    continue
  else:
    A1.append(P[M1[0]])
M2.append(0)
for i in range(1,n):
  while M2:
    if P[M2[-1]]<P[i]:
      M2.pop()
    else:
      M2.append(i)
      break
  if not M2:
    M2.append(i)
  if M2[0]==i-k-1:
    M2.popleft()
  if i<k:
    continue
  else:
    A2.append(P[M2[0]])
ans=1
for i in range(n-k):
  if A1[i]==P[i] and A2[i]==P[i+k]:
    continue
  else:
    ans+=1
Q=[0]*n
for i in range(1,n):
  if P[i]>P[i-1]:
    Q[i]=Q[i-1]+1
  else:
    continue
count=0
for i in range(n):
  if Q[i]==k-1:
    count+=1
print(ans-max(0,count-1))

Measured memory_bytes: 27108
# A - Frog1
import numpy as np

N = int(input())
h = list(map(int, input().split()))
dp = [10**9]*(N+2)
dp[0] = 0

for i in range(N):
    if i+1<N:
        dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]))
    if i+2<N:
        dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]))
print(dp[N-1])

Measured memory_bytes: 22728
#include <bits/stdc++.h>
#define INF 999999999999
using namespace std;

typedef long long ll;

int main(){
	ll a, b, q;
	cin >> a >> b >> q;
	vector<ll> s(a);
	for(ll i = 0; i < a; i++)cin >> s[i];
	vector<ll> t(b);
	for(ll i = 0; i < b; i++)cin >> t[i];
	for(int i = 0; i < q; i++){
		ll x;
		cin >> x;
		ll s1, s2, t1, t2;
		auto itr1 = lower_bound(s.begin(), s.end(), x);
		if(!(s.end()-itr1)){
			s2 = INF;
			s1 = s[a-1];
		}else{
			s2 = *itr1;
			itr1--;
			if(itr1-s.begin()+1)s1 = *itr1;
			else s1 = -INF;
		}
		auto itr2 = lower_bound(t.begin(), t.end(), x);
		if(!(t.end()-itr2)){
			t2 = INF;
			t1 = t[b-1];
		}else{
			t2 = *itr2;
			itr2--;
			if(itr2-t.begin()+1)t1 = *itr2;
			else t1 = -INF;
		}
		ll ans = INF;
		ans = min(ans, t2-s1+min(t2-x, x-s1));
		ans = min(ans, s2-t1+min(s2-x, x-t1));
		ans = min(ans, max(t2, s2)-x);
		ans = min(ans, x-min(s1, t1));
		cout << ans << endl;
	}
    return 0;
}

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


int main(){
  int x,a,b;
  cin >> x >> a >>b;
    int c =x-a;
    while(c>0){
      if(c>=b){
        c-=b;
      }
      else break;
    }
    cout << c << endl;
  }


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

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

  ll sumyen = 0;
  ll sumbit = 0;
  ll brate = 380000;
  ll ten8 = 100000000;
  for (auto i = 0; i < N; i++) {
    string x, u;
    cin >> x >> u;
    if (u == "JPY") {
      sumyen += stoi(x);
    } else {
      auto dotpos = x.find(".");
      sumbit += stoi(x.substr(0, dotpos)) * ten8 + stoi (x.substr(dotpos + 1));
    }
  }
  double res = sumyen + (sumbit * brate / (double) ten8);

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int x[6];
	scanf("%d %d", &x[0], &x[1]);
	scanf("%d %d", &x[2], &x[3]);
	scanf("%d %d", &x[4], &x[5]);
	
	int ka[4];
	int N;
	
	for(N=0; N<4; N++)
	{
		ka[N] = 0;
	}

	for(N=0; N<6; N++)
	{
		ka[x[N]-1]++;
	}

	if(ka[0] < 3 && ka[1] < 3 && ka[2] < 3 && ka[3] < 3 && ka[0]*ka[1]*ka[2]*ka[3] == 4) printf("YES");
	else printf("NO");
	
	return 0;
} 


Measured memory_bytes: 128
# E - Red and Green Apples
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

l=p[:x]+q[:y]+r
l.sort(reverse=True)
print(sum(l[:x+y]))

Measured memory_bytes: 23328
n = int(input())
a = list(map(int,input().split()))
b = {}
for i in a:
    b[i] = b.get(i,0)+1
s =0
for i in b.keys():
    c = b[i]
    if(c<i):
        s += c
    elif(c>i):
        s += c-i
print(s)

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

  const int MOD = 1000000007;
  const double PI = acos(-1); 

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }








int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double s = x / a;
  double rad;
  if(a * b / 2 <= s){
    double h = 2 * (a * b - s) / a;
    rad = atan2(h, a);
  }else{
    double w = 2 * s / b;
    rad = atan2(b, w);
  }
double ans = rad / (2 * PI) * 360;
cout << fixed << setprecision(10) << ans << endl;

}


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

int main()
{
    std::string s;
    std::cin >> s;

    std::reverse(std::begin(s), std::end(s));

    const int mod = 1000000007;

    long long reminds[13] = { 1 };
    int position = 1;
    for (auto num : s) {
        long long new_reminds[13] = { 0 };
        if (num == '?') {
            for (int i = 0; i < 10; i++) {
                for (int k = 0; k < 13; k++) {
                    new_reminds[(i * position + k) % 13] += reminds[k];
                    new_reminds[(i * position + k) % 13] %= mod;
                }
            }
        } else {
            int i = num - '0';
            for (int k = 0; k < 13; k++) {
                new_reminds[(i * position + k) % 13] += reminds[k];
                new_reminds[(i * position + k) % 13] %= mod;
            }
        }
        position *= 10;
        position %= 13;

        std::copy(std::begin(new_reminds), std::end(new_reminds), reminds);
    }

    std::cout << reminds[5] << std::endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
 int w,h,n;
 cin>>w>>h>>n;
 int x,y,a;
 int b[100][100]={}; 
 while(1){
  if(n==0)break;
  cin>>x>>y>>a;
  if(a==1)
   for(int i=0;i<h;i++)
    for(int j=0;j<x;j++)b[i][j]=1;
  else if(a==2)
   for(int i=0;i<h;i++)
    for(int j=x;j<w;j++)b[i][j]=1;
  else if(a==3)
   for(int i=0;i<y;i++)
    for(int j=0;j<w;j++)b[i][j]=1;
  else 
   for(int i=y;i<h;i++)
    for(int j=0;j<w;j++)b[i][j]=1;
  n--;
 }
 int ans=0;
 for(int i=0;i<h;i++)
  for(int j=0;j<w;j++)if(b[i][j]==0)ans++;
 cout<<ans<<endl;
 return 0;
}

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

using namespace std;

int main() {
    int a,b,c,d; cin >> a >> b >> c >> d;
    bool at = false;
    while (c > 0) {
        if (at) a -= d;
        else c -= b;
        at = !at;
        if (a <= 0) {cout << "No" << endl;return 0;}
    }
    cout << "Yes" << endl;
    return 0;
}

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

int n, m, a[100010][2];
bool done[100010];

vector<pair<int, int>> e;

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &a[i][0], &a[i][1]);
    e.emplace_back(a[i][1], -i);
    e.emplace_back(a[i][0], i);
  }
  sort(e.begin(), e.end());
  vector<int> b;
  int ans = 0;
  for (auto it : e) {
    int x = it.second;
    if (x > 0) b.push_back(x);
    else if (!done[-x]) {
      for (int y : b) done[y] = true;
      b.clear();
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define REP(i,n) for (int i = 0; i < n; ++ i)
#define FOR(i,a,b) for (int i = a; i <= b; ++ i)
#define FORD(i,b,a) for (int i = b; i >= a; -- i)
#define debug(x) cerr << #x << ": " << x << "\n"
#define task ""
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> li;
typedef vector<int> vi;

const int N = 1e5 + 5;
int n, a[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	//freopen(task".inp", "r", stdin);
	//freopen(task".out", "w", stdout);
	cin >> n;
	FOR(i, 1, n) cin >> a[i];
	sort(a+1, a+n+1);
	int x = a[1];
	FOR(i, 2, n-1) if (abs(a[i] - (a[n] + 1) / 2) < abs(x - (a[n] + 1) / 2))
		x = a[i];
	cout << a[n] << " " << x;
}


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

int main()
{
  int h,n;
  cin >> h >> n ;
  vector<int> a(n),b(n);
  for(int i=0 ;i<n ;i++)
  {
  cin >>a[i]>> b[i];
  }
  vector<long long > dp(h+1,LLONG_MAX);
  dp[0]=0;
  for(int i=0 ;i<=h ;i++)
  {
  for(int j=0 ;j<n ;j++)
  {
  if(dp[i]>LLONG_MAX-b[j])
  ;
  else
  {
  dp[min(i+a[j],h)]=min(dp[min(i+a[j],h)],dp[i]+b[j]);
 
  }
  }
  }
  cout<<dp[h]<<'\n';
  return 0;
}


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

char* abacusFigure[] =
{
	"* = ****",
	"* =* ***",
	"* =** **",
	"* =*** *",
	"* =**** ",
	" *= ****",
	" *=* ***",
	" *=** **",
	" *=*** *",
	" *=**** ",
};

int main()
{
	bool first = true;
	char input[ 6 ];
	while( cin >> input ){
		char figure[ 6 ];
		int len = strlen( input );
		for( int i = 0; i < 5 - len; ++i ){
			figure[ i ] = '0';
		}
		for( int i = 0; i < len; ++i ){
			figure[ 5 - len + i ] = input[ i ];
		}
		figure[ 6 ] = '\0';

		if( first ){
			first = false;
		}else{
			cout << endl;
		}
		for( int i = 0; i < 8; ++i ){
			for( int j = 0; j < 5; ++j ){
				cout << abacusFigure[ figure[ j ] - '0' ][ i ];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1132