akhauriyash/Code-Regression huggingface dataset:
// aribon3-5_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

// dinic
template <typename T = long long>
struct Dinic {
    struct edge { int to; T cap; int rev; };
    vector<vector<edge>> G;
    vector<int> itr, level;
    int n;
    T inf;

    explicit Dinic(int n): n(n), G(n) {inf=numeric_limits<T>::max();}

    void add_edge(int from, int to, T cap) {
        G[from].push_back((edge) {to, cap, (int) G[to].size()});
        G[to].push_back((edge) {from, 0, (int) G[from].size()-1});
    }

    void bfs(int s) {
        level.assign(n, -1);
        queue<int> q;
        level[s] = 0;
        q.push(s);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (auto &e: G[v]) {
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    T dfs(int v, int t, T f) {
        if (v == t) return f;
        for (int& i = itr[v]; i < (int) G[v].size(); ++i) {
            edge& e = G[v][i];
            if (e.cap > 0 and level[v] < level[e.to]) {
                T d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    T max_flow(int s, int t) {
        T ret = 0, f;
        while (bfs(s), level[t] >= 0) {
            itr.assign(n, 0);
            while ((f = dfs(s, t, inf)) > 0) ret += f;
        }
        return ret;
    }
};

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;

    auto dinic = Dinic<ll>(N+M+2);

    int s = N+M, t = N+M+1;
    REP(i, N) dinic.add_edge(s, i, 1);
    REP(j, M) dinic.add_edge(N+j, t, 1);

    REP(i, N){
        int k; cin >> k;
        REP(j, k) {
            int b; cin >> b; b--;
            dinic.add_edge(i, N+b, 1);
        }
    }

    int match = dinic.max_flow(s, t);

    if (match == M){
        print("Bob");
    } else {
        print("Alice");
    }

    return 0;
}



Measured memory_bytes: 14928
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d int64
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

	dividableC := dividable(a, b, c)
	dividableD := dividable(a, b, d)
	cd := lcm(c, d)
	dividableCD := dividable(a, b, cd)

	ret := b - a + 1 - dividableC - dividableD + dividableCD
	fmt.Println(ret)
}

func dividable(a int64, b int64, x int64) int64 {
	d := (b / x) - (a / x)
	if a%x == 0 {
		d++
	}
	return d
}

func gcd(c int64, d int64) int64 {
	for c%d != 0 {
		tmp := d
		d = c % d
		c = tmp

	}
	return d
}

func lcm(c int64, d int64) int64 {
	return c * d / gcd(c, d)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

struct edge {
    int to;
    int cost;
};

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

    int V, E, r;
    cin >> V >> E >> r;
    vector<vector<edge> > G(V);
    for (int i = 0; i < E; ++i) {
        int s, t, d;
        cin >> s >> t >> d;
        G.at(s).push_back(edge{t, d});
    }

    vector<int> d(V, INT_MAX);
    priority_queue<P, vector<P>, greater<P> > que;
    d.at(r) = 0;
    que.push(make_pair(0, r));
    while (!que.empty()) {
        auto p = que.top();
        que.pop();
        int now = p.second;
        if (d.at(now) < p.first) continue;
        for (auto &e : G.at(now)) {
            if (d.at(e.to) > d.at(now) + e.cost) {
                d.at(e.to) = d.at(now) + e.cost;
                que.push(make_pair(d.at(e.to), e.to));
            }
        }
    }

    for (auto &x : d) {
        if (x == INT_MAX) {
            cout << "INF" << endl;
        } else {
            cout << x << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 13104
x=int(input())

for a in range(0,200):
  a5 = a**5
  b5 = a5 - x
  if b5 >= 0:
    b = int( float(b5)**0.2 )
    if b**5 == b5:
      print(a,b)
      break
  else:
    b5 = -b5
    b = int( float(b5)**0.2 )
    if b**5 == b5:
      print(a,-b)
      break
#


Measured memory_bytes: 9268
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; (i) < (int) (n); (i) ++)
using namespace std;
 
//1-origin
template <typename T>
struct FenwickTree {
        vector<T> data;
        FenwickTree(int n) : data(n + 1, 0) {}
        //data[i] += x
        void add(int i, T x){
                while (i <= (int)data.size()) {
                        data[i] += x;
                        i += i & -i;
                }
        }
        //[1, i)
        T sum(int i){
                T res = 0;
                while (i > 0) {
                        res += data[i];
                        i -= i & -i;
                }
                return res;
        }
        //[l, r)
        T sum(int l, int r) { return sum(r) - sum(l); }
};
long long InversionNumber(const vector<int> &a) {
        FenwickTree<long long> ft(300030);
        long long res = 0;
        for (int i = 0; i < a.size(); i ++) {
                res += i - ft.sum(a[i]);
                ft.add(a[i], 1);
        }
        return res;
}
 
int main() {
        int n;
        scanf("%d", &n);
        vector<int> a(n);
        rep(i, n) {
                scanf("%d", &a[i]);
        }
        long long lb = 0, ub = 1e9 + 5;
        while (ub - lb > 1) {
                long long x = (lb + ub) / 2;
                vector<int> b(n);
                rep(i, n) {
                        b[i] = a[i] >= x ? 1 : -1;
                }
                vector<int> acc(n + 1);
                for (int i = 1; i <= n; i ++) {
                        acc[i] = acc[i - 1] + b[i - 1];
                }
                rep(i, n + 1) acc[i] += 150000;
                long long res = (long long) (n + 1) * n / 2 - InversionNumber(acc);
                if (res >= ((long long) (n + 1) * n / 2 + 1) / 2) {
                        lb = x;
                } else {
                        ub = x;
                }
        }
        printf("%lld\n", lb);
        return 0;
}

Measured memory_bytes: 3908
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void){
    ll n;
    cin >> n;
    vector<ll> c(100020, 0);
    for(ll i = 1; i <= n; i++){
        ll a;
        cin >> a;
        c[i] = a;
    }
    ll ans = 0;
    ll d = 0;
    for(ll i = 1; i <= n; i++){
        if(c[i]%2!=0 && i<n && c[i+1]!=0){
            c[i]--;
            c[i+1]--;
            ans++;
        }
        d = c[i]/2;
        ans+=d;
        c[i]-=d*2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>
#include <set>
#define MAX 100000
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
typedef long long int lli;

int main(void)
{
	int a, b, c, x, y; cin >> a >> b >> c >> x >> y;
	int half = min(x, y);
	int sum = half * min(a + b, 2 * c);
	sum += min((x - half)*a + (y - half)*b, (x + y - 2 * half) * 2 * c);
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::{i32, i64, i128, u32, u64, u128, f64};
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        x: i32,
        n: i32,
        ps: [i32; n],
    }
    for i in 0.. {
        if ! ps.contains(&(x - i)) {
            println!("{}", x - i);
            return;
        } else if ! ps.contains(&(x + i)) {
            println!("{}", x + i);
            return;
        }
    }
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int partition(vector<int> & a, int p, int r )
{
	int x = a[r];
	int i = p - 1;
	for (int j = p; j < r; j++ ){
		if (a[j] <= x ){
			i++;
			swap (a[i], a[j] );
		} // end dif
	} // end for
	swap (a[i+1], a[r] );

	return i+1;
}

int main()
{
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	vector<int> a(n, 0 );
	rep (i, n ) cin >> a[i];
	int base = partition (a, 0, n-1 );
	rep (i, n ){
		if (i == base ){
			cout << '[' << a[i] << ']';
		}else{
			cout << a[i];
		} // end if
		cout << (i != n - 1 ? ' ' : '\n' );
	} // end rep

	return 0;
}

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

int main(){
  int n, a, d;
  int ans = 100;//初期値
  cin >> n;//nこの整数がある

  rep(i, n) {//整数分ループする
    d = 0;
    cin >> a;//8
    while (a % 2 == 0) {//8を2でわってあまりが0なら
      a /= 2;//実際にaを2で割ってdをプラスする
      d++;
    }
    if (d < ans) ans = d;//もしdがansより小さければans = d;
  }
  cout << ans << endl;
}




Measured memory_bytes: 3652
/*
[abc104] C - All Green
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_D = 10;
const int MAX_P = 100;

int D, G;
int p[MAX_D], c[MAX_D];

ll solve() {
    int ans = MAX_D * MAX_P;
    for (int pat = 0; pat < (1 << D); pat++) {
        int score = 0;
        int questions = 0;
        int last_incomplete = -1;
        for (int i = 0; i < D; i++) {
            if (pat & (1 << i)) {
                score += 100 * (i + 1) * p[i] + c[i];
                questions += p[i];
            } else {
                last_incomplete = i;
            }
        }
        if (score < G) {
            int q = 100 * (last_incomplete + 1);
            int additional_qs = (G - score + q - 1) / q;
            if (additional_qs >= p[last_incomplete]) {
                continue;
            }
            questions += additional_qs;
        }
        ans = min(ans, questions);
    }

    return ans;
}

int main() {
    cin >> D >> G;
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

int minMovDis(int k, int x){
  if(x < k-x) return 2*x;
  else return 2*(k-x);
}

int main() {
  int n, k, x, ans = 0; cin >> n >> k;
  rep(i, n){
    cin >> x;
    ans += minMovDis(k, x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n=15,ans=0,d;
    cin>>n;
    while (n>9){
        d = log10(n)+1;
        if(d%2==1){
            ans+=(n-pow(10,d-1))+1;
            n=pow(10,d-1)-1;
        }
        else n = pow(10,d-1)-1;
        //cout<<n<<" "<<ans<<endl;
    }
    ans+=n;
    
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
ll inf=1e16;
const int MN=100000;
int N;
ll a[MN];
char o[MN];
ll dp[MN][3];
int main(){
	cin>>N;
	rep(i,N){
		cin>>a[i];
		if(i==N-1) break;
		cin>>o[i];
	}
	rep(i,N) rep(j,3) dp[i][j]=-inf;
	dp[0][0]=a[0];
	rep(i,N-1){
		rep(j,3) if(dp[i][j]!=-inf){
			if(o[i]=='-' && j!=2) chmax(dp[i+1][j+1],dp[i][j]+(j%2==0?-a[i+1]:a[i+1]));
			chmax(dp[i+1][j],dp[i][j]+ (((j%2==0) ^ (o[i]=='+'))?-a[i+1]:a[i+1]) );
		}
		chmax(dp[i+1][1],dp[i+1][2]);
		chmax(dp[i+1][0],dp[i+1][1]);
	}
	cout<<dp[N-1][0]<<endl;
}


Measured memory_bytes: 3456
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int a,b;
  cin >> a >> b;
  int s = a + b;
  if (s >= 24)
    s -= 24;
  cout << s;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

def gcd(x,y):  #最大公約数
    if x==0:
        return y
    else:
        return gcd(y%x,x)

a,b,c,d=intinput()
sums=b-a+1
c1=(a-1)//c
c2=b//c
d1=(a-1)//d
d2=b//d
lcmcd=(c*d)//gcd(c,d)
cd1=(a-1)//lcmcd
cd2=b//lcmcd
print(sums-(c2+d2-cd2-(c1+d1-cd1)))


Measured memory_bytes: 38528
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <functional>
#include <algorithm>
#include <random>
#include <cmath>
#include <climits>
#include <iomanip>
#include <cfloat>
#include <set>
#include <map>
#include <tuple>
struct Point {
	float x, y;
	float distance(const Point &that) const {
		return std::sqrt((x - that.x) * (x - that.x) + (y - that.y) * (y - that.y));
	}
};

void solve() {
	int n;
	float hx, hy, dx, dy; std::cin >> n >> hx >> hy >> dx >> dy;
	std::vector<std::vector<float>> memo(20, std::vector<float>(1 << 20, FLT_MAX));
	while (n != 0) {
		auto is_end = false;
		Point start{ hx, hy }, mao{ dx, dy };
		for (auto &m : memo)std::fill(m.begin(), m.end(), FLT_MAX);
		std::vector<Point> crystal(n); for (auto &c : crystal) std::cin >> c.x >> c.y;
		std::priority_queue<std::tuple<int, int, int>, std::vector<std::tuple<int, int, int>>, std::function<bool(const std::tuple<int, int, int> &, const std::tuple<int, int, int> &)>> queue([n, &memo](const std::tuple<int, int, int> &a, const std::tuple<int, int, int> &b) {return (std::get<2>(a) == std::get<2>(b)) ? memo[std::get<0>(a)][std::get<1>(a)] > memo[std::get<0>(b)][std::get<1>(b)] : std::get<2>(a) < std::get<2>(b); });
		for (auto i = 0; i < n && !is_end; ++i) {
			if (start.distance(crystal[i]) < mao.distance(crystal[i])) {
				memo[i][1 << i] = start.distance(crystal[i]);
				queue.push(std::make_tuple(i, 1 << i, 1));
			}
			else {
				std::cout << "NO\n";
				is_end = true;
			}
		}
		bool can = true;
		while (!queue.empty() && !is_end) {
			auto current = std::get<0>(queue.top());
			auto flag = std::get<1>(queue.top());
			auto count = std::get<2>(queue.top());
			auto distance = memo[current][flag];
			queue.pop();
				can = true;
				for (auto i = 0; i < n && can; ++i) {
					if ((flag & (1 << i)) == 0 && distance + crystal[current].distance(crystal[i]) >= mao.distance(crystal[i])) {
						can = false;
					}
				}
				if (can) for (auto i = 0; i < n && !is_end; ++i) {
					if ((flag & (1 << i)) == 0) {
						if (memo[i][flag | (1 << i)] > distance + crystal[current].distance(crystal[i])) {
							if (count + 1 == n) {
								std::cout << "YES\n";
								is_end = true;
							}
							memo[i][flag | (1 << i)] = distance + crystal[current].distance(crystal[i]);
							queue.push(std::make_tuple(i, flag | (1 << i), count + 1));
						}
					}
				}
		}
		if (!is_end) {
			if (std::any_of(memo.begin(), memo.end(), [n](const std::vector<float> &v) {return v[(1 << n) - 1] != FLT_MAX; })) {
				std::cout << "YES\n";
			}
			else {
				std::cout << "NO\n";
			}
		}
		std::cin >> n >> hx >> hy >> dx >> dy;
	}
}
int main() {
	solve();
}


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

int main(){
	int n, s[10000], q, t[500], cnt = 0;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> s[i];
	cin >> q;
	for(int i = 0; i < q; i++)
		cin >> t[i];
	for(int i = 0; i < q; i++){
		for(int j = 0; j < n; j++){
			if(s[j] == t[i]){
				cnt++;
				break;
			}
		}
	}
	cout << cnt << endl;
}


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

int main(){
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> v(n);
    for(auto& x : v) cin >> x.first, x.second = x.first + t;
    vector<pair<int, int>> rez;
    rez.emplace_back(-1, -1);

    for(const auto x : v)
        if(x.first <= rez.back().second) rez.back().second = x.second;
        else rez.push_back(x);
    int sol = 0;
    for(const auto x : rez) sol += x.second - x.first;
    cout << sol << endl;
    return 0; }


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

int n;
long long ans;
string s;
vector<pair<int,int> > prs;
vector<int> chs[26];
int dat[200005];

int sum(int i){
    int res=0;
    while(i>0){
        res+=dat[i];
        i-=i&-i;
    }
    return res;
}

void add(int i,int x){
    while(i<=n){
        dat[i]+=x;
        i+=i&-i;
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>s;n=s.size();
    for(int i=0;i<n;i++){
        chs[s[i]-'a'].push_back(i+1);
    }
    {
        int odd_cnt=0;
        for(int i=0;i<26;i++){
            if(chs[i].size()&1)odd_cnt++;
        }
        if(odd_cnt>1){
            cout<<-1<<endl;
            return 0;
        }
        for(int i=0;i<26;i++){
            for(int j=0;j<=(int)chs[i].size()-j-1;j++){
                prs.push_back(make_pair(chs[i][j],chs[i][chs[i].size()-j-1]));
            }
        }
    }
    for(int i=1;i<=n;i++){
        add(i,1);
    }
    sort(prs.begin(),prs.end());
    for(int i=0;i<prs.size();i++){
        if(prs[i].first!=prs[i].second)ans+=sum(n)-sum(prs[i].second);
        else ans+=(sum(n)-sum(prs[i].second))>>1;
        add(prs[i].first,-1);
        add(prs[i].second,-1);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3852
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  // val n = in.next().toInt
  val A, B, M = in.next().toInt
  val a = new Array[Int](A+1)
  val b = new Array[Int](B+1)
  for (i <- 1 to A)
    a(i) = in.next().toInt
  for (i <- 1 to B)
    b(i) = in.next().toInt

  var ans = a.drop(1).min + b.drop(1).min
  for (i <- 1 to M) {
    val x, y, c = in.next().toInt
    val t = a(x) + b(y) - c

    ans = ans min t
  }

  println(ans)

}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 56096
#include <bits/stdc++.h>
#define maxn 100010
using namespace std;
typedef long long ll;
int n,id[maxn],sz,cnt;
ll ans;
struct node {
	int x,y,bh;
} d[maxn];
struct edge {
	int from,to;
	ll dis;
} m[maxn*2];
int find(int a) {
	if (id[a]==a)
		return a;
	id[a]=find(id[a]);
	return id[a];
}
void connect(int a,int b) {
	id[find(a)]=find(b);
}
bool cmp1(node a,node b) {
	return a.x<b.x;
}
bool cmp2(node a,node b) {
	return a.y<b.y;
}
bool cmp3(edge a,edge b) {
	return a.dis<b.dis;
}
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		d[i].bh=i;
		scanf("%d %d",&d[i].x,&d[i].y);
	}
	sz=0;
	sort(d+1,d+(n+1),cmp1);
	for (int i=2;i<=n;i++) {
		sz++;
		m[sz].from=d[i-1].bh;
		m[sz].to=d[i].bh;
		m[sz].dis=(ll)d[i].x-d[i-1].x;
	}
	sort(d+1,d+(n+1),cmp2);
	for (int i=2;i<=n;i++) {
		sz++;
		m[sz].from=d[i-1].bh;
		m[sz].to=d[i].bh;
		m[sz].dis=(ll)d[i].y-d[i-1].y;
	}
	sort(m+1,m+(sz+1),cmp3);
	ans=0; cnt=n;
	for (int i=1;i<=n;i++)
		id[i]=i;
	for (int i=1;i<=sz;i++) {
		if (cnt==1)
			break;
		int a=m[i].from,b=m[i].to;
		if (find(a)!=find(b)) {
			cnt--;
			connect(a,b);
			ans+=m[i].dis;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    map<string, ll> ana;
    vector<string> s(n);
    for(int i = 0; i< n; i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
        ana[s[i]]++;
    }
    ll ans = 0;
    for(int i = 0; i< n; i++){
        if(ana[s[i]] > 1){
            ll a = ana[s[i]];
            ans += a*(a-1)/2;
            ana[s[i]] = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)

signed main(){

  int d;
  vector<int> c(26);
  cin>>d;
  for(auto& ci:c)cin>>ci;
  vector<vector<int>> s(d,vector<int>(26));
  for(auto& si:s)for(auto& sij:si)cin>>sij;

  auto calc_satisfaction_level = [&s,&c](int d,int i,auto last){
    int64_t res = s[d][i];
    for(int j=0;j<26;++j){
      if(i==j)continue;
      res -= c[j]*(d-last[j]+1);
    }
    return res;
  };

  //-----------------------------------------------------

  int k = 50;
  vector<vector<int>> last(k,vector<int>(26));
  vector<vector<int>> ans(k,vector<int>(d));
  vector<int64_t> top_k_val(k);

  auto test_all_get_max = [&](int di,auto last){
    // 日付を引数にして全てのコンテストタイプを試してmaxscoreになるタイプを返す
    // 上位k個を返す
    vector<pair<int,int>> valtype_max(26);
    for(int type=0;type<26;++type){
      valtype_max[type] = {calc_satisfaction_level(di,type,last),type};
    }
    sort(begin(valtype_max),end(valtype_max),greater<>());
    valtype_max.erase(begin(valtype_max)+k,end(valtype_max));
    assert(size(valtype_max)==k);
    return valtype_max;
  };

  rep(di,d){
    vector<tuple<int,int,int>> next_top_k;
    next_top_k.reserve(k*26);
    rep(ki,k){
      auto tmp = test_all_get_max(di,last[ki]);
      for(int i=0;i<26;++i)next_top_k.emplace_back(tmp[i].first+top_k_val[ki],tmp[i].second,ki);
    }
    sort(begin(next_top_k),end(next_top_k),greater<>());
    next_top_k.erase(begin(next_top_k)+k,end(next_top_k));
    vector<vector<int>> nxt_last(k,vector<int>(26));
    vector<vector<int>> nxt_ans(k,vector<int>(d));
    vector<int64_t> nxt_top_k_val(k);
    rep(i,k){
      auto [val,type,prv_ki] = next_top_k[i];
      nxt_last[i] = last[prv_ki];
      nxt_last[i][type] = di+1;
      nxt_ans[i] = ans[prv_ki];
      nxt_ans[i][di] = type;
      nxt_top_k_val[i] = val;
    }
    last = nxt_last;
    ans = nxt_ans;
    top_k_val = nxt_top_k_val;
  }

  //-----------------------------------------------------

  auto t = ans[0];
  auto l = last[0];
  auto v = top_k_val[0];
  int loop_cnt = 10000;
  random_device rnd;
  mt19937 mt(rnd());
  while(loop_cnt--){
    int di = mt()%d;
    int qi = mt()%26;
    auto nt = t;
    vector<int> nl(26);
    vector<int> nv(d);
    nt[di] = qi;
    rep(i,d){
      int64_t tmp = calc_satisfaction_level(i,t[i],nl);
      if(i==0)nv[i]=tmp;
      else nv[i]=nv[i-1]+tmp;
      nl[t[i]] = i+1;
    }
    if(nv.back()>v){
      v = nv.back();
      t = nt;
      l = nl;
    }
  }
  for(auto ti:t)cout<<ti+1<<endl;

}

Measured memory_bytes: 3888
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, a[3], dp[100100][3];

signed main() {
	cin >> n;
	rep(i,3) cin >> dp[1][i];
	reps(i,1,n) {
		rep(j,3) cin >> a[j];
		rep(j,3) rep(k,3) if (j!=k) chmax(dp[i+1][k], dp[i][j] + a[k]);
	}
	cout << *max_element(dp[n], dp[n]+3) << endl;
}

Measured memory_bytes: 1408
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n,len,len2,sum=0;
	char str[201],str2[201];
	memset(str2,NULL,sizeof(str2));
	cin>>n;
	cin>>str;
	len=strlen(str);
	for(int i=0;i<n;i++){//??????????????\???
		cin>>str2;
		len2=strlen(str2);
		for(int j=0;j<len2;j++){//???????????????????????????????????????????´¢
			if(str2[j]==str[0]){
				for(int y=1;y<len2;y++){
					for(int x=1;x<len;x++){
						if(str2[j+y*x]!=str[x]||j+y*x>len2){
							goto ruio;
						}
						if(x==len-1){
							sum++;
							goto sugii;
						}
					}
					ruio:;
				}
			}
		}
		sugii:;
	}
	cout<<sum<<endl;
}		

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

using namespace std;
typedef long long ll;
ll TN = 1;

int solution() {
    ll s, w;
    cin >> s >> w;
    if (w >= s) cout << "unsafe\n";
    else cout << "safe\n";
    return 0;
}

int main() {
    //cin >> TN;
    for (ll i = 0; i<TN; ++i) solution();
    return 0;
}


Measured memory_bytes: 3588
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
for i in range(n):
    a = inn()
    if a%2==1:
        print("first")
        exit()
print("second")


Measured memory_bytes: 44648
class DisjointSets:
    def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.siz = [1]*n

    def root(self,x):
        if x != self.parent[x]: 
            self.parent[x] = self.root(self.parent[x])
        return self.parent[x]

    def same(self,x,y): 
        return self.root(x) == self.root(y)

    def unite(self,x,y): 
        x = self.root(x)
        y = self.root(y)
        if x == y: 
            return
        if self.siz[x] < self.siz[y]: 
            x,y = y,x
        self.parent[y] = x
        self.siz[x] += self.siz[y]

    def size(self,x):
        return self.siz[self.root(x)]

n,m = map(int,input().split())
ds = DisjointSets(n)
for _ in range(m):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    ds.unite(x,y)
print(len(set(ds.root(i) for i in range(n))))

Measured memory_bytes: 13992
#include <iostream>
#include <vector>
#include <cstdint>

int main() {
  int N;
  std::cin >> N;
  
  int temp;
  std::vector<int> tako;
  while (std::cin >> temp) {
    tako.push_back(temp);
  }
  
  uint64_t ans = 0;
  
  for (int i=0; i<N-1; ++i) {
    for (int j=i+1; j<N; ++j) {
      ans += tako.at(i) * tako.at(j);
    }
  }
  
  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <set>
#include <numeric>

using namespace std;
#define int long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810;

#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOADVEC2(type,name0,name1,N) std::vector<type>name0(N),name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;



signed main() {
	ios::sync_with_stdio(false);
	LOAD(int, N);
	std::string S;
	cin >> S;
	int c[26];
	for (int i = 0; i < 26; ++i) {
		c[i] = 0;
	}
	for (int i = 0; i < N; ++i) {
		c[S[i] - 'a'] ++;
	}
	int res = 1;
	for (int i = 0; i < 26; ++i) {
		res *= c[i] + 1;
		res %= MOD;
	}
	res += MOD - 1;
	res %= MOD;
	cout << res;
	return 0;
}
#endif


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

int mygcd(int a, int b){
    if(a < b){
        int tmp = b;
        b = a;
        a = tmp;
    }

    while(b != 0){
        int r = a % b;
        a = b;
        b = r;
    }
    return a;
}

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

    vector<int> x(n+1);
    for(int i = 0; i < n; i++) cin >> x[i];
    x[n] = x0;
    sort(x.begin(), x.end());
    for(int i = 1; i <= n; i++) x[i] -= x[0];

    for(int i = 2; i <= n; i++){
        x[i] = mygcd(x[i], x[i-1]);
    }
    cout << x[n] << endl;
    return 0;
}

Measured memory_bytes: 3736
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()

    city = []
    dic = {}
    for i in range(N):
        S,P=isp()
        P = int(P)
        if not S in city:
            city.append(S)
            dic[S] = [(P,i)]
        else:
            dic[S].append((P,i))
    
    city.sort()
    for S in city:
        Ps = dic[S]
        Ps.sort(reverse=True) 
        for p,i in Ps:
            print(i+1)
    


if __name__ == "__main__":
    main()

Measured memory_bytes: 62820
def to2(num):
    if num % 2 == 0:
        return int(num / 2)
    else:
        return num

input()
a = list(map(int, input().split(' ')))

cout = 0
for n in a:
    while True:
        ret_n = to2(n)
        if ret_n == n:
            break
        else:
            cout += 1
        n = ret_n

print(cout)


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

int main ()
{
    string n;
    cin >>n ;
    if (n.at(1)==n.at(2) && (n.at(0)== n.at(1) || n.at(2)== n.at(3)))
    cout<<"Yes"<<endl;
    else 
    cout<< "No"<<endl;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a, p] <- getIntList
    print $ (3 * a + p) `div` 2

Measured memory_bytes: 380
#include <iostream>

constexpr int alpha_size = 'z' - 'a' + 1;
char S[15];

int main(void){
    std::cin.tie(nullptr); std::cin.sync_with_stdio(false);
    long long int n; std::cin >> n; --n;
    int len = 0; long long int sum = 0, kazu = 1;
    while(sum <= n){ kazu *= alpha_size; sum += kazu; ++len; }
    sum -= kazu; n -= sum; kazu /= alpha_size;
    while(len--){
        std::cout << static_cast<char>('a' + n / kazu);
        n %= kazu; kazu /= alpha_size;
    }
    std::cout << '\n';
    return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
 
/*
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
		   tree_order_statistics_node_update> oset;
*/

#define IO            ios::sync_with_stdio(false);cin.tie(0);
 
#define int           long long
#define pi            pair<int,int>
#define pii           pair<int,pi>
#define vi            vector<int>
#define vs            vector<string>
#define vb            vector<bool>
#define vii           vector<vector<int>>
#define vpi           vector<pi>
#define pb            push_back
#define mp            make_pair
#define eb            emplace_back
#define ff            first
#define ss            second
#define fo(i,val,n)   for(int i=val;i<n;i++)
#define rfo(i,val,j)  for(int i=val;i>=j;i--)
#define all(x)        x.begin(),x.end()
#define inf           0x3f3f3f3f3f3f3f3fLL
#define endl          '\n'
#define PI            acos(-1)

mt19937 rnd(time(0));

const int N=2e5+7;
//const int MOD=1e9+7;
const int MOD=998244353; 

int fastpow(int b,int p){
    //b %= MOD;
    //p %= (MOD - 1);
    int temp;
    if(p==0) return 1;
    if(p==1) return b;
    temp = fastpow(b , p/2);
    temp = temp * temp % MOD;
    if(p & 1){
        temp = temp * b % MOD;
    }
    return temp;
}

int32_t main(){
 	
	IO  

	int k,a,b;
	cin >> k >> a >> b;

	int x = ceil((double)a / k) * k;
	if(x <= b) cout << "OK";
	else cout << "NG";

	return 0; 
}	
	
	


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <sstream>
#include <vector>
using namespace std;

const int LIM = 5;

bool comp(const pair<int, string>& a, const pair<int, string>& b){
	if(a.first == b.first) return a.second < b.second;
	else return a.first > b.first;
}

int main(){
	int n;
	map<string, int> m;
	set<string> k;
	vector<pair<int, string> > v;
	char b;
	string s;
	stringstream ss;
	while(cin >> n, n){
		v.clear();
		k.clear();
		m.clear();
		getline(cin, s);
		for(int i = 0;i < n;++i){
			getline(cin, s);
			ss << s;
			while(ss >> s){
				++m[s];
				k.emplace(s);
			}
			ss.str("");
			ss.clear(stringstream::goodbit);
		}
		cin >> b;
		for(auto i : k){
			if(i[0] == b){
				v.emplace_back(make_pair(m[i], i));
			}
		}
		sort(v.begin(), v.end(), comp);
		for(int i = 0;i < v.size() && i < LIM;++i){
			if(i) cout << " ";
			cout << v[i].second;
			if(i == v.size() - 1 || i + 1 == LIM) cout << endl;
		}
		if(!v.size()) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
import math
from bisect import bisect_right, bisect_left
import sys
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for n in range(N):
    a[n], b[n] = map(int, input().split())
maximum = max(a)

sorted_b = sorted(b)

ans = 0

first = [sorted_b[i] for i in range(N - 1, bisect_left(sorted_b, maximum) - 1, -1)]
ans += len(first)
H_left = H - sum(first)

if H_left < 0:
    sorted_b = sorted(b, reverse=True)
    HP = H
    for i in range(N):
        HP -= sorted_b[i]
        if HP <= 0:
            print(i + 1)
            sys.exit()

ans += math.ceil(H_left / maximum)
print(ans)

Measured memory_bytes: 13360
main :: IO()
main = do
    getLine
    str <- getLine
    let kuro = countBlack str
        siro = (length str) - kuro
    print $ getsolve str siro 0 0


getsolve :: String -> Int -> Int -> Int -> Int
--ｓｔｒ→全体白→前半黒→前半白→回答
getsolve str allsiro maekuro maesiro
    | str == []					= maekuro + maesiro - allsiro
    | head str == '.'			= min nowstat (getsolve (tail str) allsiro maekuro (succ maesiro))
    | otherwise					= min nowstat (getsolve (tail str) allsiro (succ maekuro) maesiro)
    where nowstat = maekuro + (allsiro - maesiro)



countBlack :: String -> Int
countBlack str
    | str == []				= 0
    | head str == '.'		= countBlack $ tail str
    | otherwise				= 1 + (countBlack $ tail str)






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

int main(){
    string s;
    cin >> s;
    vector<string> vs(s.size());
    rep(i,s.size()){
        vs[i] = s[i];
    }
    sort(vs.begin(),vs.end());
    bool ans = true;
    for(int i=0;i<s.size()-1;i++){
        if(vs[i] == vs[i+1]){
            ans = false;
            break;
        }
    }
    if(ans) cout << "yes";
    else cout << "no";
}

Measured memory_bytes: 256
h, w = map(int, input().split())
if  h == 1 or w == 1:
    ans = 1
elif h % 2 == 0:
    ans = h // 2 * w
else:
    if w % 2 == 0:
        h_a = h//2 + 1
        ans = (h_a * 2 - 1) * w//2 
    else:
        h_a = h // 2 + 1
        ans = (h_a * 2 - 1) * (w//2) + h_a

print(ans) 
            

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++) 
#define FOR(i,ini,n) for(int i=(ini);i<(n);i++)

using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;
	while(cin >> a >> b >> c){
		bool ans = false;
		REP(i,b){
			if(a * i % b == c){
				ans = true;
			}
		}
		if(ans)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;


public class Main {
	
	public static BigInteger naive(BigInteger n) {
		if(n.compareTo(BigInteger.ONE.add(BigInteger.ONE)) < 0) { return BigInteger.ONE; }
		return n.multiply(naive(n.subtract(BigInteger.ONE).subtract(BigInteger.ONE)));
	}
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){	
			final long N = sc.nextLong();
			
			//System.out.println(naive(BigInteger.valueOf(N)));
			
			long answer = 0;
			for(long result = N; result > 0; result /= 5) {
				answer += result / 50;
			}
			//System.out.println(answer);

			
			if(N % 2 == 1) {
				System.out.println(0);
			}else {
				System.out.println(N / 10 + answer);
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 22740
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int m = sc.nextInt();
      	if(m == n){
          System.out.print("Yes");
        }else{
          System.out.print("No");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define N 100005
#define int long long
using namespace std;
int a[N],n,m;
bool b[N];
char c[N],c1[N];
signed main(){
	scanf("%lld",&n);
	int ans=n*(n-1)/2;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
/**
 	Template created by Danel Batyrbek
 	All rights are reserved 2017 (lol)
*/

#include <bits/stdc++.h>

#define speed_up ios_base :: sync_with_stdio(0);cin.tie(0)
#define fr first
#define sc second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define debug(x) cerr << x << '\n';
#define YES "YES"
#define NO "NO"
#define skip continue
#define left(x) x << 1
#define rght(x) x << 1 | 1
#define forn(x, y, z) for(int x = y; x <= z; ++ x)
#define for1(x, y, z) for(int x = y; x >= z; -- x)
#define fname ""
#define y1 naruto
using namespace std;

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

const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const ll LINF = 2e18;

int X[4] = {-1, 0, 1, 0};
int Y[4] = {0, 1, 0, -1};

int n, m, q, vertex[N3 * 2][N3 * 2], edge, col[N3 * 2][N3 * 2];
int hor[N3 * 2][N3 * 2], ver[N3 * 2][N3 * 2], u[N3 * 2][N3 * 2];

bool in(int x, int y){
	return ((0 < x && x <= n) && (0 <= y && y <= m));
}

void dfs(int x, int y){
	u[x][y] = 1;
	vertex[x][y] = 1;
	forn(dir, 0, 3){
		int nx = x + X[dir];
		int ny = y + Y[dir];
		if(in(nx, ny) && col[nx][ny] && !u[nx][ny]){
			edge ++;
			dfs(nx, ny);
		}
	}
}

int main(){
#ifndef DEBUG
	if(fname != ""){
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	}
#endif	
	cin >> n >> m >> q;
	forn(i, 1, n){
		forn(j, 1, m){
			char c;
			cin >> c;
			col[i][j] = c - '0';
		}
	}
	forn(i, 1, n){
		forn(j, 1, m){
			if(col[i][j] == 1){
				if(col[i - 1][j] == 1){
					ver[i][j] = 1;
				}
				if(col[i][j - 1] == 1){
					hor[i][j] = 1;
				}
			}
			if(col[i][j] && !u[i][j]){
				dfs(i, j);
			}
		}
	}
	forn(i, 1, n){
		forn(j, 1, m){
			hor[i][j] += hor[i - 1][j] + hor[i][j - 1] - hor[i - 1][j - 1];
			ver[i][j] += ver[i - 1][j] + ver[i][j - 1] - ver[i - 1][j - 1];
			vertex[i][j] += vertex[i - 1][j] + vertex[i][j - 1] - vertex[i - 1][j - 1];
		}
	}
	forn(i, 1, q){
		int x1, x2, y1, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int k, a, b;
		k = vertex[x2][y2] - vertex[x1 - 1][y2] - vertex[x2][y1 - 1] + vertex[x1 - 1][y1 - 1];
		a = hor[x2][y2] - hor[x2][y1] - hor[x1 - 1][y2] + hor[x1 - 1][y1];
		b = ver[x2][y2] - ver[x1][y2] - ver[x2][y1 - 1] + ver[x1][y1 - 1];
		cout << k - a - b << '\n';
		//cerr << k << ' ' << a << ' ' << b << '\n';
	}
	/*cerr << '\n';
	forn(i, 0, n){
		forn(j, 0, m){
			cerr << hor[i][j] << ' ';
		}
		cerr << '\n';
	}*/
	return 0;
}

Measured memory_bytes: 81536
#include <bits/stdc++.h>
using namespace std;
using ll=long long;using ull=unsigned ll;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPARR(i,v) for(int i=0;i<v.size();++i)
#define all(v) (v).begin(),(v).end()
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
#define cut(n, Min, Max) max(min(n,Max),Min)
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"":"im")<<"possible"<<endl
#define Poss(n) cout<<((n)?"P":"Imp")<<"ossible"<<endl
template<typename T>ostream&operator<<(ostream&o,const vector<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<typename T>ostream&operator<<(ostream&o,const set<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T,typename U>ostream&operator<<(ostream&o,const pair<T,U>&v){o<<v.first<<' '<<v.second;return o;}
int gcd(int a,int b){
    while((a%=b) && (b%=a));
    return a|b;
}
int main(){
    int n;
    cin>>n;
    int ans=-1;
    REP(i,n){
        int x;
        cin>>x;
        if(ans<1)ans=x;
        else ans=gcd(ans,x);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    long long n, a, b;
    cin >> n >> a >> b;

    long long wa = a + b;

    if(0 <= n % wa && n % wa < a) {
        cout << a * (n / wa) + (n % wa) << endl;
    } else {
        cout << a * (n / wa) + a << endl;
    }

    return 0;
}

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

int main() {
  int H,W;
  cin >> H >>W;
  string ans[H+2];
  
  for(int i=0;i<W+2;i++){
    ans[0]+="#";
  }
  cout << ans[0] <<endl;

  for(int i=0;i<H;i++){
    string s;
    cin >>s;
    cout << "#" << s <<"#"<<endl;
  }

  for(int i=0;i<W+2;i++){
    ans[H+1]+="#";
  }
    cout << ans[H+1]<<endl;

}


Measured memory_bytes: 256