akhauriyash/Code-Regression huggingface dataset:
module MakeBinaryHeap (M : sig type t val compare : t -> t -> int end) = struct

  type t = { node : M.t array; mutable size : int }

  let make n (init : M.t) = { node = Array.make n init; size = 0 }

  let empty_p t = if t.size = 0 then true else false

  let pop t =
    let rec max_heapify i =
      let l = 2*i in
      let r = 2*i + 1 in
      let m = if l <= t.size && M.compare t.node.(l) t.node.(i) > 0 then l else i in
      let m = if r <= t.size && M.compare t.node.(r) t.node.(m) > 0 then r else m in
      if m = i then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(m);
        t.node.(m) <- tmp;
        max_heapify m
      end in
    let ret = t.node.(1) in
    t.node.(1) <- t.node.(t.size);
    t.size <- t.size - 1;
    max_heapify 1;
    ret

  let push x t =
    let parent i = int_of_float (floor (float_of_int i) /. 2.) in
    let rec doit i =
      let p = parent i in
      if i <= 1 || M.compare t.node.(p) t.node.(i) >= 0 then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(p);
        t.node.(p) <- tmp;
        doit p
      end in
    t.size <- t.size + 1;
    t.node.(t.size) <- x;
    doit t.size

end

module H = MakeBinaryHeap(struct type t = (int * int) let compare (_, x) (_, y) = x - y end)

let dijkstra g n =
  let h = H.make 100000 (0, 0) in
  let min_costs = Array.make n max_int in
  let reached_p = Array.make n false in
  min_costs.(0) <- 0;
  H.push (0, 0) h;
  while not (H.empty_p h) do
    let (u, x) = H.pop h in
    reached_p.(u) <- true;
    if min_costs.(u) < -x then ()
    else
      List.iter (fun (v, c) ->
        if not reached_p.(v) && min_costs.(v) > min_costs.(u) + c then begin
          min_costs.(v) <- min_costs.(u) + c;
          H.push (v, (-min_costs.(v))) h;
        end) g.(u);
  done;
  min_costs

let rec make_pair acc = function
  | [] -> acc
  | v :: c :: tl -> make_pair ((v, c) :: acc) tl
  | _ -> assert false

let make_pair lst = make_pair [] lst

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let g = Array.make n [] in
  for _ = 0 to n - 1 do
    match read_line () |> split_on_char ' ' |> List.map int_of_string with
    | u :: _ :: l -> g.(u) <- make_pair l
    | _ -> assert false
  done;
  dijkstra g n |> Array.iteri (fun i e -> Printf.printf "%d %d\n" i e)

Measured memory_bytes: 4020
S=input()
T=input()
flag=1
buf=""
ans=""
sus=[]
piv=0
if len(S)<len(T):
    print("UNRESTORABLE")
else:
    for i in range(len(S)-len(T)+1):
        for j in range(len(T)):
            #print(S[i+j],T[j])
            if (S[i+j]!="?")and(T[j]!=S[i+j]):
                flag=0
                break
            #input()
        if flag==1:
            sus.append(i)
        flag=1
    if len(sus)<1:
        print("UNRESTORABLE")
    else:
        piv=max(sus)
        for i in range(len(S)):
            if piv<=i<=piv+len(T)-1:
                buf="".join((buf,T[i-piv]))
            else:
                buf = "".join((buf, S[i]))
        #print(buf)
        for i in range(len(S)):
            if buf[i]=="?":
                ans="".join((ans,"a"))
            else:
                ans = "".join((ans, buf[i]))
        print(ans)


Measured memory_bytes: 38256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int N, X, T;
	cin >> N >> X >> T;
  	int count = N/X;
  	if(N%X > 0) count++;
  	int ans = count * T;
  	cout << ans << endl;

}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)

using ll = long long;
using ull = unsigned long long;
constexpr ll mod = 1e9 + 7;
using namespace std;

int main() {

	int N; cin >> N;
	cout << N * N * N;

	return 0;

}

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

int main() {
  int n,k,t,l;
  cin>>t;
  while(t--) {
    cin>>n>>k;
    vector<int> x;
    for(int i=0; i<n; ++i) {
      cin>>l;
      x.push_back(l);
    }

    priority_queue< int ,vector<int>, greater<int> > Q;
    for(int i=0; i<n-1; ++i) {
      Q.push(x[i+1] - x[i]);
    }

    long long ans = 0;
    while(n-k>0) {
      ans += Q.top();
      Q.pop();
      n--;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1716
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int64 h, n;
    cin >> h >> n;
    vector<int64> a(n);
    vector<int64> b(n);
    int64 amax = -1;
    for (int64 i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        amax = max(amax, a[i]);
    }
    h += amax + 10;
    vector<int64> dp(h+1, INT_MAX);
    dp[0] = 0;

    for (int64 i=0; i < n; i++) {
        for (int64 j=1; j <=h; j++) {
            if (j - a[i] < 0) continue;
            dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
        }
    }

    int64 ans = INT_MAX;
    for (int64 i=h- amax - 10; i<h; i++) {
        if (ans > dp[i]) {
            ans = min(ans, dp[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <math.h>
using namespace std;

struct ufo {
	double x,y,sx,sy,sl,r,v;
};
ufo uf[100];
int cnt,n,m,r,mn,f[100];
double s,hx1,hy1,hx2,hy2;

void move() {
	int i;
	double x,y,g;
	g=999999;
	for (i=0;i<n;i++) {
		if (f[i]==1) continue;
		x=uf[i].sx-uf[i].sx*uf[i].v*s/uf[i].sl;
		y=uf[i].sy-uf[i].sy*uf[i].v*s/uf[i].sl;
		if (x*x+y*y<=r*r || x*uf[i].sx<0 || y*uf[i].sy<0) { f[i]=1; cnt++; m--;}
		if (f[i]==0) { uf[i].x=x; uf[i].y=y;
		     if (x*x+y*y<g) { g=x*x+y*y; mn=i;}
		     } 
	    }
	  };

void hit(double x,double y,double r,double a) {
	int f=0;
	double c,z;
	if (a==9999) { a=0; z=x; x=y; y=z; f=1;}
	c=(2*x+2*a*y)*(2*x+2*a*y)-4*(1+a*a)*(y*y+x*x-r*r);
	if (c<0) { hx1=9999; return;}
	hx1=(2*x+2*a*y+sqrt(c))/(2*(1+a*a));
	hx2=(2*x+2*a*y-sqrt(c))/(2*(1+a*a));
	hy1=a*hx1; hy2=a*hx2;
	if (f==1) { hy1=hx1; hy2=hx2; hx1=hx2=0;}
} 

void attck() {
	int i;
	double a=0;
	if (uf[mn].x!=0) { a=uf[mn].y/uf[mn].x;} else a=9999;
	for (i=0;i<n;i++) {
		if (f[i]==1) continue;
		hit(uf[i].x,uf[i].y,uf[i].r,a);
		if (hx1==9999) continue;
		if (hx1*uf[mn].x>=0 && hy1*uf[mn].y>=0 && hx1*hx1+hy1*hy1>r*r) { f[i]=1; m--;}
		else if (hx2*uf[mn].x>=0 && hy2*uf[mn].y>=0 && hx2*hx2+hy2*hy2>r*r) { f[i]=1; m--;}
	}
	};

int main() {
    int i;
    while(cin >> r >> n) {
		if (n==0) break;
		m=n; s=0; cnt=0;
		for (i=0;i<n;i++) {
			f[i]=0;
		    cin >> uf[i].sx >> uf[i].sy >> uf[i].r >> uf[i].v;
		    uf[i].sl=sqrt(uf[i].sx*uf[i].sx+uf[i].sy*uf[i].sy);
		    uf[i].x=uf[i].sx; uf[i].y=uf[i].sy;
		}
		while(m>0) {
			s+=1;
			move();
			attck();
			}
		cout << cnt << endl;
	} 
	return 0;
}

Measured memory_bytes: 1236
cnt=0
n,m=map(int,input().split())
dis=[[float('inf') for i in range(n)]for j in range(n)]
tmp=[]
for i in range(m):
    tmp.append(list(map(int,input().split())))
for a,b,t in tmp:
    dis[a-1][b-1]=t
    dis[b-1][a-1]=t
for k in range(n):
    for i in range(n):
        for j in range(n):
            dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j])
for a,b,t in tmp:
    if t>dis[a-1][b-1]:
        cnt+=1
print(cnt)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    vector<int> H(N); for (auto &h : H) cin >> h;
    sort(begin(H), end(H));
    cout << accumulate(begin(H), begin(H) + max(0, N - K), 0LL) << endl;
    return 0;
}


Measured memory_bytes: 1024
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let mut s = read::<String>().chars().collect::<Vec<_>>();

    let mut b_count = 0;
    let mut ans = 0i64;
    for i in 0..s.len() {
        if s[i] == 'B' {
            b_count += 1;
        } else {
            ans += b_count;
            //b_count -= 1;
        }
    }
    println!("{}", ans);
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 3172
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace at
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine().Split(' ');
            var a = int.Parse(x[0]);
            var b = int.Parse(x[1]);
            var c = int.Parse(x[2]);

            var list = new List<int>(){a,b,c};

            list.Sort();

            Console.WriteLine(list[0]+" "+list[1]+" "+list[2]);

        }
    }
}



Measured memory_bytes: 16008
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9+7;
void EE(ll a, ll b, ll& x, ll& y)
{
    if(a%b == 0)
    {
        x=0;
        y=1;
        return;
    }
    EE(b,a%b,x,y);
    ll temp = x;
    x = y;
    y = temp - y*(a/b);
    y %= mod;
    y = (y+mod)%mod;
}
ll inverse(ll a, ll m)
{
    ll x,y;
    EE(a,m,x,y);
    if(x<0) x += m;
    return x;
}

template <typename T> T mod_pow(T a, T b, T m) {
	T ans = 1;
	while(b) {
        if(b&1)ans=(ans*a)%m;
        a=(a*a)%m;
        b=b/2;
    }
    return ans;
}
int main(){
	/*#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif*/
	ll n;
	cin>> n;
	ll a[n];
	map<ll, ll> mp;
	for(ll i = 0; i < n; ++i){
		cin>> a[i];
		ll x = a[i];
		for(ll j = 2; j <= x && j*j <= a[i]; ++j){
			if(x%j==0){
				ll cnt = 0;
				while(x%j==0){
					cnt++;
					x /= j;
				}
				mp[j] = max(mp[j], cnt);
			}
		}
		if(x!=1){
			mp[x] = max(mp[x], 1LL);
		}
	}
	ll mx = 1;
	ll ans = 0;
	ll mod = 1e9+7;
	for(auto it = mp.begin(); it != mp.end(); ++it){
		//cout << it->first << " " << it->second << endl;
		mx *= mod_pow(it->first, it->second, mod);
		mx %= mod;
	}
	//cout << mx << endl;
	for(ll i = 0; i < n; ++i){
		ans = (ans + (mx*inverse(a[i], mod))%mod)%mod;
	}
	cout << ans << endl;

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int x,y;
  cin>>x>>y;
  
  int res = 4*x-y;
  
  if(res%2==0 and res>=0) {
    
    int t = res/2;
    int k = x-t;
    
    if (t>=0 and k>=0) {
      cout<<"Yes";
    } else {
      cout<<"No";
    }
  }else {
    cout<<"No";
  }
    
  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#define PRE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
const int Mod = 1e9 + 7;
ll lst[Max];
int ls[Max];

int main()
{
	PRE
	int n;
	cin >> n;
	map<int, int> ma;
	for (int i = 1;i <= n;i++)
	{
		int t;
		cin >> t;
		ma[t]++;
	}
	int sum = 0;
	for (auto i = ma.begin();i != ma.end();i++)
	{
		if (i->second % 2 == 1)sum++;
	}
	cout << sum;
}

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

ll absll(ll x) {
  if (x < 0) {
    return x * -1;
  } else {
    return x;
  }
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0) {
      b[i] = a[i];
    } else {
      b[i] = a[i] + b[i - 1];
    }
    sum += a[i];
  }
  ll mini = 0, minv = LLONG_MAX;
  for (int i = 0; i < n; i++) {
    if (minv > absll(b[i] - sum + b[i])) {
      minv = absll(b[i] - sum + b[i]);
      mini = i;
    }
    //cout << absll(b[i] - sum + b[i]) << endl;
  }
  cout << minv << endl;
  return 0;
}

Measured memory_bytes: 6408
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;

int main(){
  ll k,x ; cin>> k>>x ;
  if(x+k-1>1000000&&x-k+1<-1000000){
  
  for(int i=-1000000;i<=1000000;i++){
    if(i=1000000) cout<<i<<endl;
  else cout<<i<<" ";
  }
  
  }
  else if(x-k+1<-1000000){
  for(int i=-1000000;i<=x+k-1;i++){
    if(i==x+k-1) cout<<i<<endl;
  else cout<<i<<" ";
  }
  }
  else if(x+k-1>1000000){
  for(int i=x-k+1;i<=1000000;i++){
    if(i==1000000) cout<<i<<endl;
  else cout<<i<<" ";
  }
  }
  
  else{
  for(int i=x-k+1;i<=x+k-1;i++){
    if(i==x+k-1) cout<<i<<endl;
  else cout<<i<<" ";
  }
  }
 
}

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

using namespace std;

#define PB push_back  
#define MP(A, B) make_pair(A, B)  
#define fi first  
#define se second  

#define gcd(a,b) __gcd(a,b)
#define pi acos(-1.0)
#define pii pair<int,int>
#define ll long long  
#define typec long long   
#define MAX 1000005  
#define MOD 1000000007  
#define INF 0x3f3f3f3f  
#define EXP 1e-8  
#define lowbit(x) (x&-x)  
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

int n, m;
ll h[100005] = {0};
int cnt[100005] = {0};
int main() {
    cin >> n >> m;
    int ans = n;
    for (int i = 0; i < n; ++i) cin >> h[i+1];
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        if (h[a] >= h[b] && cnt[b] == 0) {
            ans--; cnt[b] = 1;
        } 
        if (h[a] <= h[b] && cnt[a] == 0) {
            // cout << cnt[a] << endl;
            ans--; cnt[a] = 1;
        } 
        
        // cout << a << ' ' << b << ' ' <<ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4804
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	ll N, K; cin >> N >> K;
	vector<pair<ll, ll>>vec(N);
	rep(i, 0, N) {
		ll a, b; cin >> a >> b;
		vec[i] = make_pair(a, b);
	}
	sort(all(vec));
	rep(i, 0, N) {
		K -= vec[i].second;
		if (K <= 0) {
			cout << vec[i].first << "\n";
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 1792
/*B - Balance*/

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

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int ans = INT_MAX;
	int suma = 0;
	int aux;
	int tam;

	cin >> tam;
	vector <int> arr(tam);


	for (int i = 0; i < tam; ++i)
	{
		cin >> arr[i];
		suma += arr[i];
	}

	aux = arr[0];
	int sumaIzq;
	sumaIzq = aux;

	ans = abs((suma - sumaIzq ) - sumaIzq);

	for (int i = 1; i < tam; ++i)
	{
		sumaIzq += arr[i];
		ans = min(ans, abs(suma - sumaIzq - sumaIzq));
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

struct query {
    int pos;
    int ticket;
    double d;
    query(int a, int b, double c) {
        pos = a;
        ticket = b;
        d = c;
    }
};


bool operator >(const query &a, const query &b) {
    return a.d > b.d;
}
double dist[1000][32];
vector<i_i> pathes[32];
double t[10];

int main() {
    cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int n, m, p, a, b;
        cin >> n >> m >> p >> a >> b;
        if(n == 0) break;
        for(int i = 1; i <= m; i++) pathes[i].clear();
        for(int i = 0; i < n; i++) cin >> t[i];
        while(p--) {
            int x, y, z;
            cin >> x >> y >> z;
            pathes[x].push_back({y, z});
            pathes[y].push_back({x, z});
        }
        priority_queue<query, vector<query>, greater<query>> que;
        for(int i = 0; i < (1 << n); i++) {
            for(int j = 0; j <= m; j++) {
                dist[i][j] = INF;
            }
        }
        dist[(1<<n)-1][a] = 0;
        que.emplace(a, (1<<n)-1, 0.0);
        double ans = INF;
        while(!que.empty()) {
            query now = que.top();
            que.pop();
            if(now.pos == b) ans = min(ans, now.d);
            for(int ticket = 0; ticket < n; ticket++) {
                if(!(now.ticket & (1 << ticket))) continue;
                int newticket = now.ticket ^ (1 << ticket);
                for(int i = 0; i < pathes[now.pos].size(); i++) {
                    int to = pathes[now.pos][i].first;
                    double newdist = dist[now.ticket][now.pos] + pathes[now.pos][i].second / t[ticket];
                    if(dist[newticket][to] > newdist) {
                        dist[newticket][to] = newdist;
                        que.emplace(to, newticket, newdist);
                    }
                }
            }
        }
        if(abs(ans - INF) < 1e-9) cout << "Impossible" << endl;
        else cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4668
#include <iostream>
#include <climits>

using namespace std;

int main() {
    long L, R;
    cin >> L >> R;
    long minimum = LONG_MAX;
    if(R - L > 2019){
        minimum = 0;
    } else {
        for(long i = L; i <= R; i++){
            for(long j = i+1; j <= R; j++) {
                if((i*j) % 2019 < minimum){
                    minimum = (i*j) % 2019;
                }
            }
        }
    }
    cout << minimum << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    try:
        N = int(input())
        B = list(map(int, input().split()))
        A = [2**31] * N
        
        A[0] = B[0]
        for i in range(1, N-1):
            A[i] = min(B[i-1], B[i])
            
        A[N-1] = B[N-2]
        #print(A)
        print(sum(A))
    except:
        break

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

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

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

fn main() {
    input! {
        n: usize,
        s: chars,
        t: chars
    }
    let mut res = String::new();
    for i in 0..n {
        res.push(s[i]);
        res.push(t[i]);
    }
    println!("{}", res);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  ll n;
  cin >> n;
  ll num = 1;
  for (ll i = 1; i <= n;i++){
    num *= i;
    num %= MOD;
  }
  print(num);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  string s;cin>>s;
  ll q;cin>>q;
  struct dmc{
    ll d=0,dm=0,dmc=0,mc=0,c=0,m=0;
  };
  rep(i,q){
    ll k;cin>>k;
    dmc cnt;
    rep(i,k){
      if(s[i]=='D')cnt.d++;
      if(s[i]=='M'){cnt.dm+=cnt.d;cnt.m++;}
      if(s[i]=='C')cnt.dmc+=cnt.dm;
    }

    rrep(i,k){
      if(s[i]=='M')cnt.mc+=cnt.c;
      if(s[i]=='C')cnt.c++;
    }
    ll res=cnt.dmc;
    rep(i,n-k){
      if(s[i]=='D'){
        cnt.dmc-=cnt.mc;
        cnt.dm-=cnt.m;
        cnt.d--;
      }
      if(s[i]=='M'){
        cnt.mc-=cnt.c;
        cnt.m--;
      }
      if(s[i]=='C'){
        cnt.c--;
      }
      if(s[i+k]=='D'){
        cnt.d++;
      }
      if(s[i+k]=='M'){
        cnt.dm+=cnt.d;
        cnt.m++;
      }
      if(s[i+k]=='C'){
        cnt.dmc+=cnt.dm;
        cnt.mc+=cnt.m;
        cnt.c++;
        res+=cnt.dm;
        //cout<<"DMC detected!! "<<i+k<<" "<<cnt.dm<<endl;
      }
      //cout<<" "<<s[i+k]<<" "<<cnt.dm<<endl;
    }
    cout<<res<<endl;
  }

  return 0;

}


Measured memory_bytes: 1948
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
int gcd(int a, int b) // assuming a,b >= 1
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    if (a % b == 0)
        return b;
    return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
    return  a * b / gcd(a, b);
}
using namespace std;
#pragma endregion
signed main() {
    int A,B,C,D,E,K;
    cin >> A >> B >> C >> D >> E >>K;
    if (E - A <= K)
        cout << "Yay!";
    else
        cout << ":(";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

//++時計回り --反時計回り
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, 1, 0, -1};

int main() {
  string S;
  cin >> S;
  int N = S.size();
  ll dp[N+1][13] = {};
  dp[0][0] = 1;
  REP(i, N) {
    int c = S[i] == '?' ? -1 : S[i] - '0';
    REP(j, 10) {
      if (c != -1 && c != j) continue;
      REP(k, 13) {
        dp[i+1][(k*10+j) % 13] += dp[i][k];
      }
    }
    REP(j, 13) dp[i+1][j] %= MOD;
  }
  cout << dp[N][5] << '\n';
}


Measured memory_bytes: 10624
X,Y= map(int, input().split())
s=False
a=(Y-2*X)/2
b=(4*X-Y)/2
if a.is_integer() and a>=0 and b.is_integer() and b>=0:
  
    s=True
    
    
if s:
    print('Yes')
else:
    print('No')


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

long long Euclidean(long long a, long long b){
    if(a < b){
        long long temp = a;
        a = b;
        b = temp;
    }

    long long ret;

    if(b == 0) return a; // xと0の最大公約数を便宜上xとする
    long long remain = a % b;
    if(remain != 0) ret = Euclidean(b, remain);
    else return b;

    return ret;
}

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

    vector<long long> x(N);
    for(int i = 0; i < N; i++){
        cin >> x[i];
        x[i] = abs(X -x[i]);
    }

    long long gcd = x[0];
    for(int i = 0; i < N; i++){
        gcd = Euclidean(gcd, x[i]);
    }

    cout << gcd << endl;

}



Measured memory_bytes: 1024
#include <stdio.h>
#define N 100000

int main(void)
{
	int i=0;
	int buff[N];
	do {
		scanf("%d", &buff[i]);
		i++;
	} while(buff[i-1]!= 0);
	
	i = 0;
	while(buff[i] != 0){
		printf("Case %d: %d\n", i+1, buff[i]);
		i++;
	}

	return 0;

}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n;
        cin>>n;
        int len = 1,curr = 26LL,cnt = 0,last = 0;
        while(true)
        {
            cnt += curr;
            if(cnt >= n)break;
            len++;
            curr *= 26LL;
            last = cnt;
        }
        n -= last;
        n--;
        vector<char> ans;
        for(int i=0;i<len;i++)
        {
            int mod = n%26;
            ans.pb(char('a'+mod));
            n/=26LL;
        }
        reverse(all(ans));
        for(auto c:ans)cout<<c;cout<<endl;
    }
    return 0;
}


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

int main() {
	int n, a[200000],b[200000],m,gap,s,t;
	cin >> n;
	m = n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	b[0] = -1;
	if (m % 2 == 1)m--;
	s = m / 2;
	if(n%2==0)gap = -1;
	else gap = 1;
	t = 0;
	b[s] = a[t];
	s = s + gap;
	t++;
	gap = gap * (-1);
	if(gap>0)gap++;
  else gap--;
	while (b[0] == -1) {
		b[s] = a[t];
		s = s + gap;
		t++;
		gap = gap * (-1);
		if(gap>0)gap++;
  else gap--;
	}
	cout << b[0];
	for (int i = 1; i < n; i++) {
		cout << ' '<<b[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3712
import scala.util.control.Breaks.{ break, breakable }

object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val nums = scala.collection.mutable.MutableList.empty[List[Int]]

    breakable {
      while (true) {
        val num = sc.next().split("").toList.map(_.toInt)
        if (num(0) == 0) break
        nums += num
      }
    }

    nums.foreach { num =>
      println(num.foldLeft(0)((a, b) => a + b))
    }
  }
}

Measured memory_bytes: 45716
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define pb          push_back
#define ff          first
#define ss          second
#define ll          int64_t
#define ld          long double
#define mod         1000000007
#define mod2        998244353
#define inf         1000000000000007
#define pi          3.14159265358979323846
#define nl          cout<<"\n"
#define dbg(x)      cerr<<#x<<" = "<<x<<"\n"
#define all(v)      v.begin(),v.end()
#define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i)
#define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i)
#define fastio()    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

template<typename T,typename U> static inline void amin(T &x,U y)   {if(y<x)x=y;}
template<typename T,typename U> static inline void amax(T &x,U y)   {if(x<y)x=y;}  

ll lcm(ll a,ll b)       {return (a*b)/__gcd(a,b);} 
ll count_digits(ll n)   {ll dig=floor(log10(n)+1);return dig;}
ll mpow(ll x,ll y,ll p) {ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;} 
string dec_bin_32(ll n) {string s;for(ll i=31;i>=0;i--){ll k=n>>i;s+=(k&1)?'1':'0';}return s;} 
string dec_bin_64(ll n) {string s;for(ll i=63;i>=0;i--){ll k=n>>i;s+=(k&1)?'1':'0';}return s;} 
ll mod_inv(ll a,ll m)   {ll m0=m,y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;} 

//-------------------------------L_I_Erq34-------------------------------

int main()
{
	fastio();
	ll z,n,m,t,k,i,j,l,d,h,r;
	cin>>n;
	ll a[n],dp[n];
	forn(i,0,n)
		cin>>a[i];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	forn(i,2,n)
		dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
	cout<<dp[n-1]<<"\n";
	cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";
	return 0;
}


Measured memory_bytes: 1792
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll A[200010];
    rep(i,0,N) cin >> A[i];
    sort(A, A+N);
    ll zero = 0;
    rep(i,0,N){
        if(A[i] == 0) zero++;
    }
    vector<ll> plus, minus;
    rep(i,0,N){
        if(A[i] > 0) plus.push_back(A[i]);
        else if(A[i] < 0) minus.push_back(A[i]);
    }
    ll zero_cnt = N*(N-1)/2 - (N-zero) * (N-zero-1) / 2;
    ll lv = -1e18+1, rv = 1e18+1;
    while(rv - lv > 1){
        ll mid = (rv + lv) / 2;
        bool ok = true;
        ll res = 0;
        ll res_tmp = 0;
        rep(i,0,plus.size()){
            ll v = plus[i];
            if(mid >= 0){
                ll lv1 = i, rv1 = plus.size();
                while(rv1 - lv1 > 1){
                    ll mid1 = (lv1 + rv1) / 2;
                    if(v * plus[mid1] <= mid){
                        lv1 = mid1;
                    }else{
                        rv1 = mid1;
                    }
                }
                res += lv1 - i;
            }
            ll lv1 = -1, rv1 = minus.size();
            while(rv1 - lv1 > 1){
                ll mid1 = (rv1 + lv1) / 2;
                if(v * minus[mid1] <= mid){
                    lv1 = mid1;
                }else{
                    rv1 = mid1;
                }
            }

            res_tmp += lv1+1;
        }

        rep(i,0,minus.size()){
            ll v = minus[i];
            if(mid >= 0){
                ll lv1 = i, rv1 = minus.size();
                while(rv1 - lv1 > 1){
                    ll mid1 = (lv1 + rv1) / 2;
                    if(v * minus[mid1] <= mid){
                        rv1 = mid1;
                    }else{
                        lv1 = mid1;
                    }
                }
                res += minus.size() - rv1;
            }
            ll lv1 = -1, rv1 = plus.size();
            while(rv1 - lv1 > 1){
                ll mid1 = (rv1 + lv1) / 2;
                if(v * plus[mid1] <= mid){
                    rv1 = mid1;
                }else{
                    lv1 = mid1;
                }
            }
            res_tmp += plus.size() - rv1;
        }

        res += res_tmp/2;
        if(mid >= 0) res += zero_cnt;

        if(res >= K){
            ok = true;
        }else{
            ok = false;
        }

        if(ok){
            rv = mid;
        }else{
            lv = mid;
        }
    }
    print(rv);

    

}

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

using namespace std;

int M,W,memo[13][1<<13];
vector<int> A,B;

int getEn(int bm,int bw){
  int x = abs(bm-bw);
  return x*pow(x-30,2);
}

int solve(int idx,int S){
  if(idx == M){ return memo[idx][S] = 0; }
  if(memo[idx][S] >= 0){ return memo[idx][S]; }
  int res = -1;
  for(int i = 0 ; i < W ; i++){
    if(S >> i & 1){ continue; }
    res = max(res,solve(idx+1,S|(1<<i))+getEn(A[idx],B[i]));
  }
  return memo[idx][S] = res;
}

int main(){
  while(cin >> M >> W, M){
    A.resize(M); B.resize(W);
    for(int i = 0 ; i < M ; i++){ cin >> A[i]; }
    for(int i = 0 ; i < W ; i++){ cin >> B[i]; }
    if(M > W){ swap(M,W); swap(A,B); }
    memset(memo,-1,sizeof(memo));
    cout << solve(0,0) << endl;
  }
  return 0;
}

Measured memory_bytes: 1636
(let* ((n (read))
       (lst (concatenate 'list (sort (loop :repeat n :collect (read)) #'<) '(0)))
       (ans 0)
       (mem (cons 0 0)))
  (mapcar (lambda (k)
            (if (= (car mem) k)
                (incf (cdr mem))
                (progn
                  (if (oddp (cdr mem))
                      (incf ans))
                  (setf mem (cons k 1))))) lst)
  (princ ans))

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

int main(){
  string s;
  cin >> s;
  int a=0;
  for(int i = 0;i<s.size();i++){
    if(s.at(i) == 'o'){
      a++;
    }
  }
  if(15-s.size()>=8-a){
    cout << "YES" << endl;
  }else cout << "NO" << endl;
}

Measured memory_bytes: 256
/*input
async layered coding
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b) cout<<c;
	else if(a==c) cout<<b;
	else cout<<a;
	return 0;
}


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

int main() {
  int n,n1,n2,n3,n4;
  cin >> n;
  n1=n%10;n2=n/10%10;n3=n/100%10;n4=n/1000%10;
  if (n1==n2&&n2==n3){
    cout<<"Yes"<<endl;
  }
  else if (n2==n3&&n3==n4){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <string>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < (n);++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)

const ll INF = 1e9+7;

// 各桁の和
template<typename T>T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;}
template<typename T>T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int main() {
  int n;cin>>n;
  vector<double> a(n);rep(i,n)cin>>a[i];
  double tmp = 0;
  rep(i,n){
    tmp += (1/a[i]);
  }
  double ans = 1/tmp;
  print(ans);
  return 0;
}

Measured memory_bytes: 256
fn main() {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    println!("{}", solve(&input));
}

fn solve(input: &str) -> String {
    let mut iter = input.split_whitespace().map(|w| w.parse().unwrap());
    let n: i32 = iter.next().unwrap();
    for _ in 0..n {
        let a: i32 = iter.next().unwrap();
        if !(a & 1 == 1 || a % 3 == 0 || a % 5 == 0) {
            return "DENIED\n".to_string();
        }
    }
    return "APPROVED\n".to_string();
}


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

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

  double a, b, c;
  double pi = 3.141592653589793;
  cin >> a >> b >> c;
  double s = sin(c/180 * pi) * a * b / 2;
  double l = sqrt(a*a + b*b - 2*a*b*cos(c/180 * pi)) + a + b;
  cout << fixed << setprecision(9) << s << endl;
  cout << l << endl;
  cout << 2*s / a << endl;
} 


Measured memory_bytes: 3608
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int N;
  cin >> N;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    sum += a;
  }
  cout << sum - N << endl;
  return 0;
}

Measured memory_bytes: 384
#include <algorithm>  //min, max, sort, unique, fill
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>  //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<ll>;
using VB = vector<bool>;
using VP = vector<P>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)

static const ll kIntMax = numeric_limits<ll>::infinity();
static const double kFloatMax = numeric_limits<double>::infinity();

vector<ll> vi;

int main() {
  int  a, b;
  cin >> a >> b;
  if(a*b%2)cout << "Odd" <<endl;
  else cout <<"Even" << endl;

  return 0;
}


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

using namespace std;

const int N = 1100006;

int n, m, q, mod;
int g;
int u[N], v[N], c[N];
int fa[N];
bool able[2][N];

int find(int t);
void merge(int x, int y);
int val(int x, int y, int z);

int main() {
  scanf("%d%d%d%d", &n, &m, &q, &mod);
  for (int i = 1; i <= m; ++i)
    scanf("%d%d%d", &u[i], &v[i], &c[i]);
  for (int i = 1; i <= m; ++i) 
    g = __gcd(g, abs(c[i] - c[1]));
  if (!g) g = mod;
  mod = __gcd(mod, 3 * g);
  int z = c[1] % g;
  for (int i = 0; i <= 6 * n; ++i) 
    fa[i] = i;
  for (int i = 1; i <= m; ++i) {
    int w = (c[i] - z) / g;
    for (int p = 0; p <= 1; ++p) {
      for (int q = 0; q <= 2; ++q) {
        merge(val(u[i], p, q), val(v[i], 1 - p, (2 * q + w) % 3));
        merge(val(v[i], p, q), val(u[i], 1 - p, (2 * q + w) % 3));
      }
    }
  }
  int x = z;
  for (int i = 0; i < mod * 2; ++i) {
    able[i & 1][x] = true;
    (x <<= 1) %= mod;
  }
  while (q--) {
    int s, t, r;
    scanf("%d%d%d", &s, &t, &r);
    bool res = 0;
    for (int p = 0; p <= 1; ++p) {
      for (int q = 0; q <= 2; ++q) {
        if (find(val(t, 0, 0)) != find(val(s, p, q))) continue;
        res |= able[p][(r + z + (3 - q) * g) % mod];
      }
    }
    puts(res ? "YES" : "NO");
  }
  return 0;
}

int find(int t) { 
  if (fa[t] != t) fa[t] = find(fa[t]);
  return fa[t];
}

void merge(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return ;
  fa[x] = y;
}

int val(int x, int y, int z) {
  return (x - 1) * 6 + y * 3 + z;
}


Measured memory_bytes: 10624
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	vector<llong> A(N);
	for(int i=0; i<N; ++i) cin >> A[i];
	sort(A.begin(), A.end());
	llong ans = 1;
	for(int i=0; i<N; ++i){
		if(A[i]==0){
			ans = 0;
			break;
		}else if(A[i] <= 1000000000000000000 / ans){
			ans *= A[i];
		}else{
			ans = -1;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3932
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	static string s,z="abcdefghijklmnopqrstuvwxyz";
	static char[] c;
	static int[,] h;
	static int[] g;
	static int m=26,t=0,o=1;
	static bool b=true;
	static void Main(){
		Sc sc=new Sc();
		s=sc.S;
		g=new int[s.Length];
		h=new int[s.Length+1,m];
		for(int i=s.Length-1;i>=0;i--){
			if(t==(1<<m)-1){o++;t=0;}
			t|=1<<(s[i]-'a');
			g[i]=o;
			if(i==s.Length-1){continue;}
			for(int j=0;j<m;j++){h[i,j]=h[i+1,j];}
			h[i,s[i+1]-'a']=i+1;
		}
		if(t==(1<<m)-1){o++;t=0;}
		int q=0;
		while((t&(1<<q))!=0){q++;}
		if(o==1){Console.WriteLine("{0}",z[q]);}
		else{
			c=new char[o];
			Fu((s[0]-'a')==q?0:h[0,q],0);
			Console.WriteLine("{0}",String.Join("",c));
		}
	}
	static void Fu(int n,int a){
		c[a]=s[n];
		if(a==o-1||a>=o-g[n]){return;}
		for(int i=0;i<m&&b;i++){
			if(h[n,i]==0){
				b=false;
				c[a+1]=z[i];
				if(a!=o-2){}
			}
			else{Fu(h[n,i],a+1);}
		}
	}
}

class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 35404
#include <iostream>
#include <iomanip>

int main()
{
    int a, b;
    std::cin >> a >> b;
    std::cout << a/b << ' ' << a%b << ' ' << std::fixed << std::setprecision(5) << static_cast<double>(a)/b << std::endl;
    return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include <cstring> // memset()
#include <cmath> // pow(a, b)
#include <string> // string, stoi(string)
#include <cstdlib> //abs(int x)
#include <bitset> //bitset<int>(int)
using namespace std;

//print all substring

long long all_substring(string S){
  int head = 0;
  int num = 1;
  int n = (int)strlen(&S[0]);
  int bit = pow(2, n-1);
  long long acc = 0;
  for (int i=0; i<bit; i++){
    // cout << bitset<8>(i) << " : ";
    for (int j=0; j<n; j++){
      int mask = (1<<j);
      if (head + num == n){
        acc += stoll(S.substr(head, num));
        head = 0;
        num = 1;
        break;
      }
      if (!(i & mask)){
        num++;
      } else {
        acc += stoll(S.substr(head, num));
        head = head + num;
        num = 1;
      }
    }
  }
  return acc;
}


int main(){
  string S; cin >> S;
  cout << all_substring(S) << endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	class Pair {
		int y, x;
		Pair(int y, int x) {
			this.y = y;
			this.x = x;
		}
	}

	final int MAX_N = 200;
	void run() {
		Scanner scan = new Scanner(System.in);
		while (true) {
			int N = scan.nextInt();
			if (N == 0)
				return;
			if (N == 1) {
				System.out.println(1 + " " + 1);
				continue;
			}
			Pair[] pairs = new Pair[N];
			pairs[0] = new Pair(0, 0);
			int[] dy = { 0, -1, 0, 1 };
			int[] dx = { -1, 0, 1, 0 };
			for (int i = 1; i < N; i++) {
				int n = scan.nextInt();
				int d = scan.nextInt();
				Pair p = pairs[n];
				pairs[i] = new Pair(p.y + dy[d], p.x + dx[d]);
			}
			int max_x = 0, max_y = 0;
			int min_x = 0, min_y = 0;
			for (int i = 0; i < N; i++) {
				max_x = Math.max(max_x, pairs[i].x);
				max_y = Math.max(max_y, pairs[i].y);
				min_x = Math.min(min_x, pairs[i].x);
				min_y = Math.min(min_y, pairs[i].y);
			}
			System.out.println((max_x - min_x + 1) + " " + (max_y - min_y + 1));
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k%2==1){
    cout<<(b-a)<<endl;
  }else{
    cout<<(a-b)<<endl;
  }
  return 0;
}


Measured memory_bytes: 256