akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

#[derive(Debug)]
pub struct UnionFind {
    par: Vec<usize>,
}
impl UnionFind {
    pub fn new(n: usize) -> UnionFind {
        let mut vec = vec![0; n];
        for i in 0..n {
            vec[i] = i;
        }
        UnionFind { par: vec }
    }
    pub fn find(&mut self, x: usize) -> usize {
        if x == self.par[x] {
            x
        } else {
            let par = self.par[x];
            let res = self.find(par);
            self.par[x] = res;
            res
        }
    }
    pub fn same(&mut self, a: usize, b: usize) -> bool {
        self.find(a) == self.find(b)
    }
    pub fn unite(&mut self, a: usize, b: usize) {
        let apar = self.find(a);
        let bpar = self.find(b);
        self.par[apar] = bpar;
    }
}

fn main() {
    input!{
      n: usize,
      m: usize,
      xyzs: [(usize, usize, usize); m],
    }

    let mut uf = UnionFind::new(n);
    for &(x, y, z) in xyzs.iter() {
        uf.unite(x-1, y-1);
    }
    let mut ans = vec![];
    for i in 0..n {
        ans.push(uf.find(i));
    }
    ans.sort();
    ans.dedup();
    println!("{}", ans.len());
}


Measured memory_bytes: 11388
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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 COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}


  int main(){
       lint N;
       lint count=0,x=INF;
       lint ans=0;
       cin >>N; lint M[N];
       rep(i,N){cin >> M[i];
        if(M[i]<0){count++;
           
        }
        x=min(x,abs(M[i]));
        ans+=abs(M[i]);
       }
       if(count%2==1)cout<<ans-2*x;
       else cout<<ans;

  }

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
int ps[100100];

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

    std::cin >> N;

    for(int i=1;i<=N;++i){
        std::cin >> ps[i];
    }

    ll res = 0;
    for(int i=1,j=1;i<=N;i=j){
        while(j <= N && ps[j] != j){++j;}

        i = j;

        while(j <= N && ps[j] == j){++j;}

        res += (j - i + 1) / 2;
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define myp pair<ll,ll>
using namespace std;
const int N=200010;
const ll oo=9e18;
int n,q,x[N],a,b;
ll f[N],tot_add;
struct Node{
	int l,r,o;
	ll v;
}node[2][N<<2];
void build(int k,int l,int r,bool b){ 
	node[b][k].l=l,node[b][k].r=r;
	if(l==r){node[b][k].v=b?f[l]+l:f[l]-l,node[b][k].o=l;return;}
	int mid=(l+r)>>1;
	build(k<<1,l,mid,b);
	build(k<<1|1,mid+1,r,b);
	if(node[b][k<<1].v<=node[b][k<<1|1].v) node[b][k].v=node[b][k<<1].v,node[b][k].o=node[b][k<<1].o;
	else node[b][k].v=node[b][k<<1|1].v,node[b][k].o=node[b][k<<1|1].o;
	return;
}
void setd(int k,int aim,ll d,bool b){
	int nl=node[b][k].l,nr=node[b][k].r,mid=(nl+nr)>>1;
	if(nl==nr&&nl==aim){node[b][k].v=min(node[b][k].v,b?d+aim:d-aim);return;}
	if(aim<=mid) setd(k<<1,aim,d,b);
	else setd(k<<1|1,aim,d,b);
	if(node[b][k<<1].v<=node[b][k<<1|1].v) node[b][k].v=node[b][k<<1].v,node[b][k].o=node[b][k<<1].o;
	else node[b][k].v=node[b][k<<1|1].v,node[b][k].o=node[b][k<<1|1].o;
	return;
}
myp get_min(int k,int l,int r,bool b){
	if(l>r) return make_pair(oo,oo);
	if(l==node[b][k].l&&node[b][k].r==r) return make_pair(node[b][k].v,node[b][k].o);
	int nl=node[b][k].l,nr=node[b][k].r,mid=(nl+nr)>>1;
	if(l>mid) return get_min(k<<1|1,l,r,b);
	else if(r<=mid) return get_min(k<<1,l,r,b);
	myp temp1=get_min(k<<1,l,mid,b),temp2=get_min(k<<1|1,mid+1,r,b);
	return temp1<=temp2?temp1:temp2;
}
ll get_t_min(int k){
	int nl=node[0][k].l,nr=node[0][k].r;
	if(nl==nr) return node[0][k].v+nl;
	return min(get_t_min(k<<1),get_t_min(k<<1|1));
}
//int get_v(int k,int b,int aim){
//	int nl=node[b][k].l,nr=node[b][k].r,mid=(nl+nr)>>1;
//	if(nl==nr&&nr==aim) return node[b][k].v;
//	if(aim<=mid) return get_v(k<<1,b,aim);
//	return get_v(k<<1|1,b,aim);
//}
int main(){
	ll temp_add;
	myp tp1,tp2;
	scanf("%d%d%d%d",&n,&q,&a,&b);
	for(int i=1;i<=q;i++) scanf("%d",&x[i]);
	for(int i=1;i<=n;i++) f[i]=min(abs(a-x[1])+abs(b-i),abs(b-x[1])+abs(a-i));
	build(1,1,n,0);build(1,1,n,1);
//	for(int i=1;i<=n;i++) cout<<get_v(1,0,i)<<" ";
//	cout<<endl;
//	for(int i=1;i<=n;i++) cout<<get_v(1,1,i)<<" ";
//	cout<<endl;
	for(int i=2;i<=q;i++){
		tot_add+=abs(x[i]-x[i-1]);
		temp_add=abs(x[i]-x[i-1]);
		tp1=get_min(1,1,x[i],0);
		tp2=get_min(1,x[i]+1,n,1);
		tp1.first+=x[i],tp2.first-=x[i];
		if(tp1<=tp2){
			setd(1,x[i-1],tp1.first-temp_add,0);
			setd(1,x[i-1],tp1.first-temp_add,1);
		}else{
			setd(1,x[i-1],tp2.first-temp_add,0);
			setd(1,x[i-1],tp2.first-temp_add,1);
		}
//		for(int j=1;j<=n;j++) cout<<get_v(1,0,j)<<" ";
//		cout<<endl;
//		for(int j=1;j<=n;j++) cout<<get_v(1,1,j)<<" ";
//		cout<<endl;
	}
	ll ans=get_t_min(1)+tot_add;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 31872
#include <iostream>
#include <queue>
#define INFTY -1
using namespace std;



int a[124][124] = {{}};
int d[124] = {};
int n;
void bfs(int k){
  queue <int> q;
  q.push(k);
  int u;


  while(!q.empty()){
    u = q.front(); q.pop();
    for(int v = 0;v < n;v++){
      if(a[u][v] == 0) continue;
      if(d[v] == INFTY) {
        d[v] = d[u] + 1;
        q.push(v);
        //cout << v << " " << d[v] << endl;
      }
    }

  }
}

int main(){

  int u,k,x;
  cin >> n;

d[0] = 0;
for(int i = 1; i < n;i++) d[i] = INFTY;

  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> x;
      a[u - 1][x - 1] = 1;
    }
  }

  bfs(0);

  for(int i = 0;i < n;i++){
    cout << i + 1 << " " << d[i] << endl;
  }
}

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

const ll MOD = 1000000007;

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

struct Combination
{
    int maxn;
    vector<ll> fmemo;
    vector<ll> imemo;
    vector<ll> ifmemo;
    
    Combination(int maxn) : maxn(maxn){
        fmemo.resize(maxn + 1);
        imemo.resize(maxn + 1);
        ifmemo.resize(maxn + 1);
        for(ll i = 1; i <= maxn; i++){
            imemo[i] = modpow(i, MOD - 2);
        }
    }

    ll fact(ll n){
        if(n == 0) return 1;
        if(fmemo[n]) return fmemo[n];
        return fmemo[n] = n * fact(n - 1) % MOD;
    }

    ll ifact(ll n){
        if(n == 0) return 1;
        if(ifmemo[n]) return ifmemo[n];
        return ifmemo[n] = imemo[n] * ifact(n - 1) % MOD;
    }

    ll com(ll n, ll k){
        if(k > n || k < 0) return 0;
        if(k == n || k == 0) return 1;
        return (fact(n) * ifact(k) % MOD) * ifact(n - k) % MOD;
    }
};

int main()
{
    int n;
    cin >> n;
    int a[100005];
    int b[100005];
    for(int i = 1; i <= n; i++) b[i] = -1;
    int l, r;
    for(int i = 0; i < n + 1; i++){
        cin >> a[i];
        if(b[a[i]] != -1){
            l = b[a[i]];
            r = i;
        }
        else b[a[i]] = i;
    }
    Combination com(n + 1);
    for(int i = 1; i <= n + 1; i++){
        cout <<
            (com.com(n, i) + com.com(n - 1, i - 1) - com.com(n - (r - l), i - 1) + com.com(n - 1, i - 2) + MOD) % MOD <<
            endl;
    }
}


Measured memory_bytes: 9588
// ABC127 E - Cell Distance.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <numeric>


using lolo=long long;
using namespace std;
using vec=vector<lolo>;
using vvec=vector<vec>;
using vecb=vector<bool>;
#define FOR(i,n) for (lolo i=0; i<n; ++i)
#define FORN(i,a,b) for (lolo i=a; i<b; ++i)
#define REV(i,a,b) for (lolo i=a; i>b; --i)
#define ALL(x) x.begin(), x.end()
constexpr lolo MOD = lolo(1e9 + 7);
lolo myPow(lolo x, lolo n, lolo m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

int main()
{
	lolo N, M, K;
	cin >> N >> M >> K;
	lolo ans = 0;
	vec FAC(N*M + 2);
	FAC[0] = 1;
	FAC[1] = 1;
	FOR(i, N*M+1) {
		if (i == 0)continue;
		(FAC[i + 1] = FAC[i] * (i + 1)) %= MOD;;
	}
	vec DEFAC(N*M + 2);
	DEFAC[N * M] = myPow(FAC[N * M], MOD - 2, MOD);
	REV(i, N* M, 0) {
		DEFAC[i - 1] = (DEFAC[i] * i) % MOD;
	}

	auto getComb = [&FAC, &DEFAC](lolo n, lolo b) {
		// nCb
		
		return ((FAC[n] * DEFAC[n - b]) % MOD) * DEFAC[b] % MOD;
	};
	FOR(i, N* M) {
		auto row = i / M;
		auto col = i % M;
		lolo score = 0;
		(score += (1 + col) * col / 2 * N) %= MOD;
		(score += (1 + M - 1 - col) * (M - 1 - col) / 2 * N) %= MOD;
		(score += (1 + row) * row / 2 * M) %= MOD;
		(score += (1 + N - 1 - row) * (N - 1 - row) / 2 * M) %= MOD;
		(score *= getComb(N * M - 2, K - 2)) %= MOD;
		(score *= DEFAC[2]) %= MOD;
		(ans += score) %= MOD;
		;
	}
	cout << ans << endl;
	
}



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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

ll N, M, Q;
vector<ll> a, b, c, d;

ll score(const vector<ll> A){
    ll res = 0;
    rep(j, Q) if (A[b[j]] - A[a[j]] == c[j]) res += d[j];
    return res;
}

ll dfs(vector<ll> &A){
    if(A.size() == N){
        return score(A);
    }

    ll p = (A.empty() ? 1 : A.back()), res = 0;
    for(ll i = p; i <= M; i++) {
        A.PB(i);
        res = max(dfs(A), res);
        A.pop_back();
    }
    return res;
}

int main(){
    cin >> N >> M >> Q;
    a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
    rep(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }
    vector <ll> A;
    cout << dfs(A) << endl;
    return 0;
}

Measured memory_bytes: 3604
n=gets.chomp.to_i
hash={}
(1..n).each do |i|
  s,p=gets.chomp.split
  p=p.to_i
  hash.store([s,p],i)
end

#p hash
hash_sorted=hash.sort_by{|list,i| list[1] }
.reverse.sort_by{|list,i| list[0]}.to_h
#p hash_sorted

hash_sorted.each do |list,i|
  puts i
end


Measured memory_bytes: 1788
s = input()
size = len(s)
b_num = 0
w_num = 0

for each in s:
    if each == 'W':
        w_num += 1
    else:
        b_num += 1

ans = 0
b_left = w_num
for i in range(size):
    if s[i] == 'B':
       ans += b_left - i
       b_left += 1

print(ans)

Measured memory_bytes: 9296
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

int main() {
  
  int N, L = 0;
  std::cin >> N >> L;
  std::vector<std::string> words;
  std::string inputString;
  
  for (int i = 0; i < N; ++i) {
    std::cin >> inputString;
    words.push_back(inputString);
  }
  
  std::sort(words.begin(), words.end());
  
  for (std::string s : words) {
    std::cout << s;
  }
  
}

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int n,ans=0,chk,tmp;
    scanf("%d",&n);
    vector<int> ar(n);
    for(auto&e:ar){
        scanf("%d",&e);
    }
    for(;;){
        chk=0;
        for(int i=1;i<n;i++){
            if(ar[i-1]>ar[i]){
                tmp=ar[i];
                ar[i]=ar[i-1];
                ar[i-1]=tmp;
                ans++;
                chk=1;
            }
        }
        if(chk==0) break;
    }
    for(int i=0;i<n-1;i++){
        printf("%d ",ar[i]);
    }
    printf("%d\n",ar[n-1]);
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

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

int main(){
	//input
	ll N; cin>>N;
    cout<<N*N*N;
}

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

const int mod = 1e9 + 7;

long long bp(long long a, int n) {
	if(n == 0) return 1;
	if(n & 1) return a * bp(a % mod, n - 1) % mod;
	return bp(a * a % mod, n / 2) % mod;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int s;
	cin >> s;
	if(s < 3) {
		cout << 0 << endl;
		return 0;
	}
	long long ans[s + 1];
	ans[0] = ans[1] = ans[2] = 0;
	ans[3] = 1;
	for(int i = 4; i <= s; i++) {
		ans[i] = 1;
		for(int j = 3; j <= i - 3; j++) {
			ans[i] += ans[i - j]; // - (j % (i - j) == 0 or (i - j) % j == 0);
			ans[i] %= mod;
		}
	}
	// for(int i = 1; i <= 10; i++) cout << ans[i] << ' ';
	// cout << endl;
	cout << ans[s] << endl;
	return 0;
}

Measured memory_bytes: 3644
h, w = map(int, input().split())
grid = []

for _ in range(h):
    grid.append(input())

for i in range(h):
    if ".#." in grid[i]:
        if i == 0:
            if grid[i+1][grid[i].find(".#.") + 1] != "#":
                print("No")
                exit()
        elif i == h-1:
            if grid[i-1][grid[i].find(".#.") + 1] != "#":
                print("No")
                exit()
        else:
            if grid[i-1][grid[i].find(".#.") + 1] != "#" and grid[i+1][grid[i].find(".#.") + 1] != "#":
                print("No")
                exit()

print("Yes")

Measured memory_bytes: 62096
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
   int A,B,K;
   scanf("%d%d",&A,&B);
    K=0.5*(A+B);
   if(abs(A-K)==abs(B-K))
   {

       printf("%d",K);
   }
   else
       printf("IMPOSSIBLE");
   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
  int count=0;
  int N;
  cin>>N>>count;
  rep(i,N-1){
    int a;
    cin>>a;
    if(count>a+1){
      cout<<"No";
      return 0;
    }
    if(count<a)
    count=a;
  }
  cout<<"Yes";
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int n;
    string s[55];
    int t[55];
    cin>>n;
    REP(i,n)cin>>s[i]>>t[i];
    string x;
    cin>>x;
    bool f=false;
    int cnt=0;
    REP(i,n)
    {
        if(f)cnt+=t[i];
        if(x==s[i])f=true;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=110;
int a[maxn];int sum,ans;
int avr;
int n;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	avr=floor((double)sum/n+0.5);
	for(int i=1;i<=n;i++){
		ans+=(a[i]-avr)*(a[i]-avr);
	}
	cout<<ans;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    N = int(input())
    cnt = 0
    if N == 100000:
        cnt = 90000 + 900 + 9
    elif N >= 10000 and N < 100000:
        cnt = (N - 10000)+ 910
    elif N >= 1000 and N < 10000:
        cnt = 909
    elif N >= 100 and N < 1000:
        cnt = (N - 100)+ 10 
    elif N >=10 and N < 100:
        cnt = 9
    elif N < 10:
        cnt = N
    print(cnt)

Measured memory_bytes: 3060
#include <stdio.h>

int b[110], a[110];

int min(int a, int b){
	return (a < b ? a : b);
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n - 1; i++) scanf("%d", &b[i]);
	for(int i = 1; i < n - 1; i++) a[i] = min(b[i - 1], b[i]);
	a[0] = b[0]; a[n - 1] = b[n - 2];
	int sm = 0;
	for(int i = 0; i < n; i++) sm += a[i];
	printf("%d\n", sm);
}

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

int main() {
    int n, a[3][3], b[10];
    bool ans = false, isOK[3][3] = {false};
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    cin >> n;
    for (int k = 0; k < n; k++) {
        cin >> b[k];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (b[k] == a[i][j]) isOK[i][j] = true;
            }   
        }
    }
    if (isOK[0][0] == true && isOK[0][1] == true && isOK[0][2] == true) ans = true;
    if (isOK[1][0] == true && isOK[1][1] == true && isOK[1][2] == true) ans = true;
    if (isOK[2][0] == true && isOK[2][1] == true && isOK[2][2] == true) ans = true;
    if (isOK[0][0] == true && isOK[1][0] == true && isOK[2][0] == true) ans = true;
    if (isOK[2][1] == true && isOK[1][1] == true && isOK[2][1] == true) ans = true;
    if (isOK[2][2] == true && isOK[1][2] == true && isOK[0][2] == true) ans = true;
    if (isOK[0][0] == true && isOK[1][1] == true && isOK[2][2] == true) ans = true;
    if (isOK[0][2] == true && isOK[1][1] == true && isOK[2][0] == true) ans = true;
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
b = list(map(int, input().split()))
ans = []
for i in range(N):
  for j in range(len(b) - 1, -1, -1):
    if j + 1 == b[j]:
      ans.append(b.pop(j))
      break
if b:
  print(-1)
else:
  for a in reversed(ans):
    print(a)


Measured memory_bytes: 3060
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof (a))
#define gcd(a,b) __gcd(a,b)
#define all(a) a.begin(),a.end()
#define in(a) insert(a)
#define sz() size()
#define endl '\n'
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn=100010;
const ll inf=1e18;
const ll mod=998244353;
const double pi=3.14159265358979;
const double ep=0.0;
ll a[maxn];
int main(){
    int n;
    cin>>n;
    ll sum=0;
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        sum^=a[i];
    }
    ll ans=0,b=0;
    vector<int> vis(n);
    for(int j= 61;j>=0;j--)
    {
        if(sum&(1ll<<j))
            for (int i=0;i<n;i++)
                if(a[i]&(1ll<<j))
                    a[i]^=1ll<<j;
        for (int i=0;i<n;i++)
        {
            if(vis[i])
                continue;
            if(a[i]&(1ll<<j))
            {
                vis[i]=1;
                for (int k=0;k<n;k++)
                {
                    if(i==k)
                        continue;
                    if(a[k]&(1ll<<j))
                    a[k]^=a[i];
                }
                break;
            }
        }
    }
    sort(a,a+n);
    reverse(a,a+n);
    if (n>65)
        n=65;
    int t=40000;
    while (t--)
    {
        for (int i=0;i<n;i++)
            vis[i]=0;
        b=0;
        for(int j=61;j>=0;j--)
        {
            if(b&(1ll<<j))
                continue;
            for (int i=0;i<n;i++)
                if(!vis[i]&&a[i]&(1ll<<j))
                {
                    b^=a[i];
                    vis[i]=1;
                    break;
                }
        }
        ans=max(ans,b+(b^sum));
        random_shuffle(a, a+n);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  int A = 0, B = 0, ans = 1e9;

  vector<int> W(N);
  for (int i = 0; i < N; i++) {
    cin >> W.at(i);
    A += W.at(i);
  }

  for (int i = 0; i < N; i++) {
    B += W.at(i);
    ans = min(ans, abs(A - B - B));
  }

  cout << ans << "\n";
}

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

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    vector<vector<int>> c(3, vector<int>(3));
    Rep (i, 3) Rep (j, 3) {
        cin >> c[i][j];
    }

    vector<int> a(3), b(3);
    Rep (i, 3) {
        a[i] = c[i][0];
        b[i] = c[0][i] - c[0][0];
    }

    string ans = "Yes\n";
    Rep (i, 3) Rep (j, 3) {
        if (a[i] + b[j] != c[i][j]) ans = "No\n";
    }

    cout << ans << flush;
}

Measured memory_bytes: 256
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
fn main() {
    let n: i32 = read();
    let k: i32 = read();
    let v:Vec<i32> = read_vec();
    let middle = k as f64 / 2.0;
    let mut ans = 0;
    for i in v {
        if i as f64  <= middle {
            ans += i;
        } else {
            ans += k - i;
        }
    }
    println!("{}", ans * 2);
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <set>
using namespace std;

int main()
{
	int n;
	cin >> n;
	
	for (int i = 0; i  < n; i++) {
		string before;
		cin >> before;
		
		set<string> strs;
		for (int j = 1; j < before.length(); j++) {
			string left = before.substr(0, j);
			string right = before.substr(j);
			string leftR = "";
			for (int k = left.length() - 1; k >= 0; k--) {
				leftR += left[k];
			}
			string rightR = "";
			for (int k = right.length() - 1; k >= 0; k--) {
				rightR += right[k];
			}
			strs.insert(left + right);
			strs.insert(right + left);
			strs.insert(left + rightR);
			strs.insert(rightR + left);
			strs.insert(leftR + right);
			strs.insert(right + leftR);
			strs.insert(leftR + rightR);
			strs.insert(rightR + leftR);
		}
		cout << strs.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1304
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int temp;
  int i,j,k;
  int ans = 0;
  for(i = 0;i <= a;++i){
    for(j = 0;j <= b;++j){
      for(k = 0;k <= c;++k){
        temp = 500*i + 100*j + 50*k;
        if(temp == x){++ans;}
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>

using namespace std;

int main(){

    string s;cin>>s;

    REP(i,s.size()-1)if(s[i]=='A'&&s[i+1]=='C'){
            cout<<"Yes"<<endl;
            return 0;
        }
    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K;
	string S;
	vint retu;
	scan(N>>K);
	scan(S);
	int ans=0;
	int flag=1,num=0,iniflag=0;
	if(N<=2){
		prin(N);
		return 0;
	}
	if(K>N){
		return 0;
	}
	rep(i,N){
		if(S[i]=='1'){
			iniflag=1;
			if(flag==0){
				flag=1;
				ans=max(ans,num);
				retu.push_back(num);
				num=0;
			}
			num++;
		}
		else if(iniflag){
			if(flag==1){
				flag=0;
				retu.push_back(num);
				num=0;
			}
			num++;
		}
		if(i==N-1){
			if(flag==1) retu.push_back(num);
		}
	}
	int bubunwa[100001]={};
	rep(i,retu.size()){
		bubunwa[i+1]=bubunwa[i]+retu[i];
	}
	for(int i=0;i<max(1,(int)retu.size()-2*K);i+=2){
		ans=max(ans,bubunwa[min(i+2*K+1,(int)retu.size())]-bubunwa[i]);
	}
	if(S[0]=='0'){
		int zerocount=1;
		for(int i=1;i<N&&S[i]=='0';i++,zerocount++){

		}
		ans=max(ans,bubunwa[min(2*K-1,(int)retu.size())]+zerocount);
	}
	if(S.back()=='0'){
		int zerocount=1;
		for(int i=N-2;i>=0&&S[i]=='0';i--,zerocount++){

		}
		ans=max(ans,bubunwa[(int)retu.size()]-bubunwa[max(0,(int)retu.size()-2*K+1)]+zerocount);
	}
	prin(ans);
	return 0;
}


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

int main(){
  int n;
  cin>>n;
  string s;
      int a=0,b=0,c=0,d=0;

  while(n--){
  cin>>s;
    if(s=="AC")
      a++;
    else if(s=="WA")
      b++;
    else if(s=="TLE")
      c++;
    else if(s=="RE")
      d++;
  }
  cout<<"AC x "<<a<<endl;
  cout<<"WA x "<<b<<endl;
  cout<<"TLE x "<<c<<endl;
  cout<<"RE x "<<d<<endl;
return 0;}


Measured memory_bytes: 3628
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    X = int(read())
    list = [i*200 for i in range(9, 1, -1)]
    for i, l in enumerate(list):
        if X >= l:
            ans = i + 1
            break
    print(ans)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
import sys

mod = 10**9+7
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    A = LI()
    A_sum = sum(A)
    ans = 0
    for i in range(n-1):
        A_sum -= A[i]
        ans += A[i]*A_sum
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31232
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int ans = 1;
		int max = 0;
		for(int i = 0; i < n; i++){
			h[i] = sc.nextInt();
			if(i != 0){
				if(h[i] >= max){
					ans++;
				}
			}
			max = Math.max(max,h[i]);
		}
		System.out.print(ans);
	}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  int c[1001][2];
  repi(i,1,1001){
    c[i][0]=(i*8)/100;
    c[i][1]=i/10;
    if(c[i][0]==a && c[i][1]==b){
      cout<<i<<endl;
      return 0;
    }
    
  }
    cout<<-1<<endl;

  return 0;
}


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

int main() {
  int a;
  int b;
  int x;
  int y;
  
  cin >> a;
  cin >> b;
  
  x = (a+b)/2;
  y = a+b-x*2;
  
  cout << x+y << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                          \
  cout << #v << "=(" << v[0];                              \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; } \
  cout << ")" << endl;
#define mdebug(m)                                                           \
  cout << #m << "=" << endl;                                                \
  REP(i_debug, m.size())                                                    \
  {                                                                         \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; } \
    cout << endl;                                                           \
  }
#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 ll long long
// #define f first
// #define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T>
void readv(vector<T> &a)
{
  REP(i, a.size())
  cin >> a[i];
}
void readv_m1(vector<int> &a)
{
  REP(i, a.size())
  {
    cin >> a[i];
    a[i]--;
  }
}

ll mod = 1000000007;

int main()
{
  string T;
  cin >> T;

  ll N = T.size();
  ll ans = 0;
  REP(i, N)
  {
    if (T[i] == '?')
      T[i] = 'D';
  }
  cout << T << endl;

  return 0;
}

Measured memory_bytes: 3752
#include <stdio.h>
  
int main(){
    int a, b, r;
    char op;
    while(1){
        scanf("%d %c %d\n", &a, &op, &b);
        if(op == '?') break;
        switch(op){
            case '+':
                r = a + b;
                break;
            case '-':
                r = a - b;
                break;
            case '*':
                r = a * b;
                break;
            case '/':
                r = a / b;
                break;
        }
        printf("%d\n", r);
    }
    return 0;
}

Measured memory_bytes: 2756
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int n,d; cin >> n >> d;
    int temp = d * 2 + 1;
    int ans = 0;
    if(!(n % temp)) ans = n / temp;
    else ans  = n / temp + 1;
    cout << ans  << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int n;
		cin>>n;
		ll int arr[n+1];
		ll int mini=1e18;
		ll int cnt=0;
		for(ll int i=1;i<=n;i++)
		{
			cin>>arr[i];
			mini=min(mini,arr[i]);
			if(mini>=arr[i]) cnt++;
		}
		cout<<cnt;
	}
	return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;
		int count = 0;
		int amount = 0;
		List<Integer> list = new ArrayList<Integer>();
		try {
			while ((buffer = reader.readLine())  != null) {
				if (count == 0) {
					count++;
					amount = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));
				}
				else {
					for (int i = 0; i < amount; i++) {
						if (i != 0) {
							buffer = buffer.substring(buffer.indexOf(" ") + 1);
						}
						int a = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));
						list.add(a);
					}
					int min = Integer.MAX_VALUE;
					int max = Integer.MIN_VALUE;
					long sum = 0;
					for (int i : list) {
						if (min > i) min = i;
					}
					for (int i : list) {
						if (max < i) max = i;
					}
					for (int i : list) {
						sum += i;
					}
					System.out.println(min + " " + max + " " + sum);
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}

Measured memory_bytes: 281588
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
<url:>
問題文============================================================

=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    string S,T; cin >> S >> T;
    string ans(S.length(),'z');
    bool f = false;
    for(int i = 0; i < S.length();i++){
        if(i + T.length() >S.length())break;
        string tmp = "";
        for(int j = 0; j < i;j++){
            if(S[j] == '?') tmp+="a";
            else tmp += S[j];
        }
        bool dame = false;
        for(int j = i; j < i + T.length();j++){
            if(S[j] == '?') tmp += T[j-i];
            else{
                if(S[j] == T[j-i]){
                    tmp += T[j-i];
                }else{
                    dame = true;
                    break;
                }
            }
        }
        if(dame)continue;
        for(int j = i + T.length(); j < S.length();j++){
            if(S[j] == '?') tmp += "a";
            else tmp += S[j];
        }
        
        f = true;
        ans = min(ans,tmp);
    }
    
    if(f){
        cout << ans << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }
	return 0;
}


Measured memory_bytes: 256
n,m,x,y = gets.chomp.split.map(&:to_i)
xs = gets.chomp.split.map(&:to_i)
ys = gets.chomp.split.map(&:to_i)
xs << x
ys << y
xs.sort!
ys.sort!
puts xs[-1] < ys[0] ? "No War" : "War"


Measured memory_bytes: 1788
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX_STRING 50

	char sInput[MAX_STRING+1]="";
	int anX[200001];
	int anY[100000];

	int compar(const int *val1, const int *val2);

int main() {
//	char* psInput;

	int i=0;
	int j=0;
	int nNumber=0;
	int nTargetKind=0;
	int nTemp=0;
	int nTargetNumber=0;
	int nLastTarget=0;
	int nFriends=0;
	int nMustBeRemoved=0;

	// read line 1
    scanf("%d", &nNumber);
    scanf("%d", &nTargetKind);
	// read line 2
	for(i=0; i<nNumber; i++) {
        scanf("%d", &nTemp);
		anX[nTemp]=anX[nTemp]+1;
	}
	// sort
    qsort(anX, 200001, sizeof(int),
        (int (*)(const void *, const void *))compar
    );

	// calc
	for(i=0; i<=200000; i++) {
		if(anX[i]>0){
			if(nTargetKind>0){
				nTargetKind--;
			} else {
				nMustBeRemoved=nMustBeRemoved+anX[i];
			}
		}
	}
	printf("%d\n",nMustBeRemoved);
	

    return 0;
}
int compar(const int *val1, const int *val2) {
    if ( *val1 > *val2 ) {
        return -1;
    } else if ( *val1 == * val2 ) {
        return 0;
    } else {
        return 1;
    }
}



Measured memory_bytes: 1788
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define FOR(i,a,b) for(int i =(a) ; i <= (b); i++)
#define REP(i,n)  FOR( i, 0, (n) - 1 )

int main(){
  int n; cin >> n;
  cout << 1110-n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T, class U> vector<U> make_vec(size_t a, U val) {
    return vector<U>(a, val);
}
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

using Graph = vector<vector<int>>;

int main() {
    int N, M;
    cin >> N >> M;
    Graph G(N, vector<int>());
    rep(i, M) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].pb(v);
    }
    int S, T;
    cin >> S >> T;
    S--, T--;
    auto dist = make_vec<size_t, size_t, int>(N, 3, INF);
    queue<pair<int, int>> que;
    que.push(MP(0, S));
    while(!que.empty()) {
        auto p = que.front();
        que.pop();
        int d = p.first;
        int v = p.second;
        for(auto nv : G[v]) {
            if(dist[nv][(d + 1) % 3] <= d + 1)
                continue;
            que.push(MP(d + 1, nv));
            dist[nv][(d + 1) % 3] = d + 1;
        }
    }
    cout << (dist[T][0] == INF ? -1 : dist[T][0] / 3) << endl;
    return 0;
}

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

int dp[223456][3];
bool used[223445][3];
long long n, a[312312], b[312312], c[312312];
int mx;
vector <int> v[5];
int mn = 50102031;

long long f = 1;
double s;
int main() {
   
   cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	//reverse(a + 1, a + n + 1);

	s = a[1];
	for(int i = 2; i <= n; i++) s = (a[i] + s) / 2;
	cout << fixed << setprecision(18) << s * 1.;
	  
}



Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>
int main(void)
{
  int N,M,i;
  scanf("%d %d",&N,&M);
  int accept[100000],penalty[100000];
  int ac_total=0,pen_total=0;
  for(i=0;i<100000;i++)
  {
    accept[i] = 0;
    penalty[i] = 0;
  }
  int p[100000];
  char S[2];
  for(i=0;i<M;i++)
  {
    scanf("%d %s",&p[i],S);
    if(strcmp(S,"AC")==0) accept[p[i]] = 1;
    else if(accept[p[i]] !=1) 
      penalty[p[i]]++;
  }

  for(i=0;i<N;i++)
  {
    ac_total += accept[i+1];
    if(accept[i+1]==1) 
    {
      pen_total += penalty[i+1];
    }

  }
    printf("%d %d\n",ac_total,pen_total);
  
  return 0;
  
}

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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
typedef long long ll;

int gcd(int x, int y)
{
	int r;
	while (y > 0)
	{

		if (y > x) swap(y, x);
		r = x%y;
		x = y;
		y = r;
	}
	return x;
}

int main()
{
	int a, b;
	cin >> a >> b;
	
	cout << gcd(a, b) << endl;

	return 0;
}

Measured memory_bytes: 1164
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let a1: i32 = iter.next().unwrap().parse().unwrap();
    let a2: i32 = iter.next().unwrap().parse().unwrap();
    let a3: i32 = iter.next().unwrap().parse().unwrap();    
    println!("{}", if a1 + a2 + a3 <= 21 { "win" } else { "bust" });
}


Measured memory_bytes: 4352
S = input()

if len(S) == 1:
    print(1)
    exit(0)

now = S[0]
k = 1
l = 2
ans = 1
while k < len(S) and l <= len(S):
    while S[k:l] == now:
        l += 1
        if l == len(S)+1:
            if now == S[k:l]:
                ans -= 1
            break
    now = S[k:l]
    k = l
    l = k+1
    ans += 1

print(ans)


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL N; cin >> N;
	VL a(N);
	VL b(1e5 + 10);
	FOR(i, 0, N) {
		cin >> a[i];
		a[i]++;
		b[a[i]]++;
	}
	LL ans = 0;
	FOR(i, 0, N) {
		LL c = a[i];
		ans = max(ans, b[c - 1] + b[c] + b[c + 1]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,ra,re) for((i)=ra;(i)<(re);(i)++)
#define _rep(i,ra,re) for((i)=ra;(i)>(re);(i)--)
#define rep_(i,ra,re) for((i)=ra;(i)<=(re);(i)++)
#define _rep_(i,ra,re) for((i)=ra;(i)>=(re);(i)--)
#define put(n) cout << n << " "; 
#define puts(n) cout << n << endl;
#define pu(n) cout << n;
#define mod 1000000007
int i,j,k,l;
static const int MAX_N=10e5;
vector<int> V,E;
int ans[MAX_N],x[MAX_N],y[MAX_N],z[MAX_N];
int main(void){
	string S;
	cin >> S;
	
	rep(i,1,S.size()){
		if(S[i-1]=='R' && S[i]=='L'){
			V.push_back(i-1);
			ans[i]++;
		}
	}
	rep(i,0,V.size()){			//puts("vi-> " << V[i]);
		int j=V[i];
		ans[j]++;
		int k=1;
		while(1){
			int l=j-k;
			if(l<0)break;
			else if(S[l]=='L')break;
								//	puts("R-> " << l);
			if(k%2==1){
				ans[j+1]++;//puts("	itis sei" );
			}else{//k%2==0
				ans[j]++;
			}
			k++;
		}
		
		k=2;
		while(1){
			int l=j+k;
			if(l>=S.size())break;
			else if(S[l]=='R')break;
			
			if(k%2==1){
				ans[j+1]++;
			}else{
				ans[j]++;
			}
			k++;
		}
	}
	
	rep(i,0,S.size())put(ans[i]);
	

	return 0;
}


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

int main(){
    int flag=0;
    int a[4];
    int app=0;
    string s;
    cin >> s;

    map <char,int> m;

    for (int i = 0; i < 4; i++){
        m[s[i]] += 1;
    }
    if(m.size()==2 && m[s[0]]==2)flag=1;

    //cout <<fixed<<setprecision(16)<< << endl;

    if(flag==1)cout << "Yes" <<endl;
    else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long num = sc.nextLong();
		long start = sc.nextLong();
		System.out.println(num + cal(start, num - start));
	}

	public static long cal(long width, long height) {
		if(width * height == 0) {
			return - Math.max(width, height);
		}else if(width == height) {
			return width;
		}else if (width > height) {
			return width / height * height * 2 + cal(width % height, height);
		}else {
			return height / width * width * 2 + cal(width, height % width);
		}
	}
}

Measured memory_bytes: 23764