akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <fstream>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v; ll w; };

const int MOD = 1000000007;
const int _MOD = 1000000009;
double EPS = 1e-10;
const ll INF = LLONG_MAX / 2;

struct segment_tree_max {
	int n; vector<ll> v;
	segment_tree_max(int _n) {
		for (n = 1; n < _n; n *= 2);
		v = vector<ll>(n * 2 - 1, LLONG_MIN);
	}
	void set(int i, ll x) {
		int k = i + n - 1;
		v[k] = max(v[k], x);
		while (k > 0) {
			k = (k - 1) / 2;
			v[k] = max(v[k * 2 + 1], v[k * 2 + 2]);
		}
	}
	ll _get(int i, int j, int k, int l, int r) {
		if (r <= i || j <= l) return LLONG_MIN;
		if (i <= l && r <= j) return v[k];
		ll vl = _get(i, j, k * 2 + 1, l, (l + r) / 2);
		ll vr = _get(i, j, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
	ll get(int i, int j) { return _get(i, j, 0, 0, n); }
};

int main() {
	int N; cin >> N;
	vector<int> a(N), b(N);
	rep(i, N) scanf("%d%d", &a[i], &b[i]);
	vector<int> c(N * 2);
	rep(i, N) c[i] = a[i];
	rep(i, N) c[N + i] = b[i];
	sort(c.begin(), c.end());
	c.erase(unique(c.begin(), c.end()), c.end());
	int M = c.size();
	rep(i, N) a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin();
	rep(i, N) b[i] = lower_bound(c.begin(), c.end(), b[i]) - c.begin();
	vector<vector<int> > v(M);
	rep(i, N) {
		v[a[i]].pb(i);
		v[b[i]].pb(~i);
	}
	segment_tree_max st1(M), st2(M);
	st1.set(0, 0);
	st2.set(0, 0);
	rep(x, M) {
		vector<i_i> unko1, unko2;
		for (int i: v[x])
			if (i >= 0) {
				int z = st2.get(0, b[i]) + 1;
				unko1.pb(i_i(b[i], z));
			}
			else {
				i = ~i;
				int z = st1.get(0, a[i]) + 1;
				unko2.pb(i_i(a[i], z));
			}
		for (i_i p: unko1) st1.set(p.first, p.second);
		for (i_i p: unko2) st2.set(p.first, p.second);
	}
	int ans = max(st1.get(0, M), st2.get(0, M));
	cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    ll a, b;
    cin >> a >> b;
    if (a % 2 != b % 2)
    {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    cout << (a + b) / 2 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int A, B;

  cin >> A >> B;

  int d = abs(A - B);

  if (d % 2) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << min(A, B) + d / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
// typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;

int main(){
  int x; cin>>x;
  if(x==7||x==5||x==3){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct UF {
  vector<int> pare, rank;
  UF(int n) : pare(n), rank(n){ for(int i=0; i<n; i++){ pare[i]=i; rank[i]=0; } }
  int root(int x){ return (pare[x]==x)?x:pare[x]=root(pare[x]); }
  bool same(int x, int y){ return root(x)==root(y); }
  void marg(int x, int y){
    x=root(x); y=root(y); if(x==y) return;
    if(rank[x]<rank[y]){ pare[x]=y; }
    else{ pare[y]=x; if(rank[x]==rank[y]){rank[x]++;} }
  }
};

int main(){
int N, M; cin >> N >> M; int p[N], x[M], y[M], ans=0; UF G(N);
for(int i=0; i<N; i++){ cin >> p[i]; p[i]--; }
for(int i=0; i<M; i++){ cin >> x[i] >> y[i]; G.marg(--x[i], --y[i]); }
for(int i=0; i<N; i++){ if(G.same(i, p[i])){ ans++; } }
cout << ans << "\n";
}

Measured memory_bytes: 2176
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;
typedef long long LL;

const int INF = 1 << 30;

int solve(vector<int> x, vector<int> y, vector<string> dir) {
	int ans = INF;
	int n = (int)x.size();
	map<int, set<int>> a, b, v, h;
	for (int i = 0; i < n; ++i) {
		if (dir[i] == "L") {
			a[x[i] - y[i]].insert(x[i]);
			h[y[i]].insert(x[i]);
		}
		if (dir[i] == "R") {
			b[x[i] + y[i]].insert(x[i]);
		}
		if (dir[i] == "D") {
			v[x[i]].insert(y[i]);
		}
	}
	for (int i = 0; i < n; ++i) {
		if (dir[i] == "R") {
			if (h.find(y[i]) != h.end()) {
				set<int>& s = h[y[i]];
				auto it = s.lower_bound(x[i]);
				if (it != s.end()) {
					ans = min(ans, (*it - x[i]) * 5);
				}
			}
		}
		if (dir[i] != "U") {
			continue;
		}
		int key = x[i] - y[i];
		if (a.find(key) != a.end()) {
			set<int>& s = a[key];
			auto it = s.lower_bound(x[i]);
			if (it != s.end()) {
				ans = min(ans, (*it - x[i]) * 10);
			}
		}
		key = x[i] + y[i];
		if (b.find(key) != b.end()) {
			set<int>& s = b[key];
			auto it = s.lower_bound(x[i]);
			if (it != s.begin()) {
				--it;
				ans = min(ans, (x[i] - *it) * 10);
			}
		}
		if (v.find(x[i]) != v.end()) {
			set<int>& s = v[x[i]];
			auto it = s.lower_bound(y[i]);
			if (it != s.end()) {
				ans = min(ans, (*it - y[i]) * 5);
			}
		}
	}
	return ans;
}

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		int ans = INF;
		LL n = -1;
		cin >> n;
		if (n < 0) return 0;
		vector<int> x(n), y(n);
		vector<string> dir(n);
		for (int i = 0; i < n; ++i) {
			cin >> x[i] >> y[i] >> dir[i];
		}
		ans = solve(x, y, dir);
		map<string, string> t;
		t["D"] = "U";
		t["U"] = "D";
		t["L"] = "R";
		t["R"] = "L";
		for (int i = 0; i < n; ++i) {
			x[i] = -x[i];
			y[i] = -y[i];
			dir[i] = t[dir[i]];
		}
		ans = min(ans, solve(x, y, dir));
		if (ans == INF) {
			cout << "SAFE" << endl;
		} else {
			cout << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 54112
class Solver():
    def __init__(self, N, costs):
        self.dp = [-1] * N
        self.dp[0] = 0
        self.costs = costs

    def solve(self):
        for i in range(1, len(self.costs)):
            if i == 1:
                self.dp[i] = abs(self.costs[i]-self.costs[i-1])
                continue
            self.dp[i] = min(self.dp[i - 1] + abs(self.costs[i] - self.costs[i-1]),
                        self.dp[i - 2] + abs(self.costs[i] - self.costs[i-2]))

        return self.dp[-1]


def main():
    N = int(input())
    costs = [int(i) for i in input().split()]
    solver = Solver(N, costs)
    print(solver.solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 13976
extern crate core;

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

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

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

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

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

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

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

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

fn solve(input: String) -> String {
  input!(input=>(r: i64));

  ((2.0 * r as f64) * 3.14159).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
  test1: "1\n" => "6.28318530717958623200\n",
  test2: "73\n" => "458.67252742410977361942\n",
}


Measured memory_bytes: 2208
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main(){
	int A, B;
	cin >> A >> B;

	int ans = -1;
	for (double i=0; i<20000; i++) {
		if ((int)(i * 0.08) == A && (int)(i * 0.10) == B) {
			ans = i;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        long X = int.Parse(str[0]);
        long Y = int.Parse(str[1]);
        long count = 0;
        if(X < Y){
            count = Y - X;
        }
        else{
            count = X - Y + 2;
        }
        if(- X <= Y){
            count = Math.Min(Y+X+1,count);
        }
        else{
            count = Math.Min(-Y-X+1,count);
        }
        sb.Append(count+"\n");
    }
}

Measured memory_bytes: 2776
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
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(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int A, B; cin >> A >> B;

    int ans = A+B;
    ans = max(ans, A-B);
    ans = max(ans, A*B);

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
    int64_t X;
    cin >> X;
    
    int64_t i = 0;
    int64_t k = 100;
    while (k<X)
    {
        k+=k*0.01;
        i++;
    }
    

    cout << i << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << x
#define print(x) cout << x << '\n'
#define debug(x) cerr << #x << ": " << x << '\n'
ll gcd(ll a, ll b){
    return b != 0 ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> m){
        vll list;
        mn = INF;
        rep(i, n){
            cin >> a;
            list.pb(a);
        }
        list.pb(0);
        sort(all(list));
        rep(i, n - m + 1){
            cnt = abs(list[i] - list[i + m]) + min(abs(list[i]), abs(list[i + m]));
            mins(mn, cnt);
        }
        print(mn);
    }
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int x;
    cin >> x;
    cout << (not x) << endl;
    return 0;
}


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

typedef long long   ll;
typedef long double ld;
using namespace std;
const int MOD=1e9+7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin >> n >> m;
    if(abs(n-m)>1){
        cout << "0" << "\n";
        return 0;
    }
    else{
        ll dog=1;
        ll mon=1;

        for(ll i = 0; i < n; i++) {
            dog=dog*(i+1)%MOD;
        }
        for(ll i = 0; i < m; i++) {
            mon=mon*(i+1)%MOD;
        }

        ll ans=dog*mon%MOD;
        if(n==m) ans=ans*2%MOD;
        cout << ans << "\n";
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void doit(){
  int i;
  int t[3];
  for(i=0;i<3;i++){
    scanf("%d",&t[i]);
  }
  if((t[0]*t[1]==1)||(t[2]==1)){
    printf("Open\n");
  }
  else{
    printf("Close\n");
  }
}

int main(){
  doit();
  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define inf 10000
using namespace std;

int a, b, c, q, x, y;
string s, t;

int main() {
  cin >> q;
  while(q--) {
    a = inf;
    cin >> s >> t;
    for(int i = 0; i < s.size(); ++i) {
      if(s[i] != t[i]) a = min(a, i);
      if(s[i] == '1') b = i;
      if(t[i] == '1') c = i;
    }
    if(a == inf)
      cout << 0 << endl;
    else {
      x = max(b - a, 0);
      y = c - min(a, b);
      if(y < 0) y *= -1;
      cout << x + y << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[5000010];
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=5000001;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){return modpow(x,mod-2);}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,x[1010],y[1010],dp[(1<<20)],a[20];
bool check[2];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    vector<int>v={1};
    rep(hoge,30)v.pb(v.back()*2);
    reverse(all(v));
    rep(i,n){
        cin>>x[i]>>y[i];
        check[(x[i]+y[i]+2000000000)%2]=true;
    }
    if(check[0]&&check[1]){
        puts("-1");
        return 0;
    }
    if(check[0])v.pb(1);
    cout<<v.size()<<endl;
    rep(i,v.size()){
        cout<<v[i];
        if(i==v.size()-1)cout<<endl;
        else cout<<" ";
    }
    rep(i,n){
        int X=x[i]+y[i],Y=x[i]-y[i];
        vector<bool>a,b;
        int nowx=0,nowy=0;
        for(int d:v){
            if(X>=nowx){
                nowx+=d;
                a.pb(true);
            }
            else{
                nowx-=d;
                a.pb(false);
            }
            if(Y>=nowy){
                nowy+=d;
                b.pb(true);
            }
            else{
                nowy-=d;
                b.pb(false);
            }
        }
        rep(i,a.size()){
            if(a[i]==true&&b[i]==true)cout<<'R';
            if(a[i]==true&&b[i]==false)cout<<'U';
            if(a[i]==false&&b[i]==true)cout<<'D';
            if(a[i]==false&&b[i]==false)cout<<'L';
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lson k<<1
#define rson k<<1|1
unsigned ll maxn=1e18;
unsigned ll num[100005];
int main()
{
    int n;
    cin >> n;
    unsigned ll ans=1;
    int f=1;
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&num[i]);
        if(!num[i])
        {
            printf("0");
            return 0;
        }
    }
    for(int i=0;i<n;i++)
    {
        unsigned ll t=num[i],tans=0;
        while(t)
        {
            if(ans>maxn)
            {
                printf("-1");
                return 0;
            }
            if(t%10)
                tans+=ans*(t%10);
            if(tans>maxn)
            {
                printf("-1");
                return 0;
            }
            t/=10;
            ans*=10;
        }
        ans=tans;
    }
    cout << ans;
    return 0;
}


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

#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define endl '\n'
#define mod 1000000007
#define INF64 1e18

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  string s,t;cin>>s>>t;
  int n=s.size(),m=t.size();
  vvi dp(n+1,vi(m+1));
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++){
      if(s[i-1]==t[j-1])
        dp[i][j]=dp[i-1][j-1]+1;
      else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
  //cout<<dp[n][m]<<endl;
  string lcs="";
  int i=n,j=m;
  while(i>0&&j>0){
    if(s[i-1]==t[j-1]){
      lcs+=s[i-1];
      i--;j--;
    }
    else if(dp[i-1][j]>dp[i][j-1])
        i--;
      else j--;
  }
  reverse(all(lcs));
  cout<<lcs;
}

Measured memory_bytes: 73688
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <numeric>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 1e9;

int a, b, c;
int N, rtn = INF;
vector<int> l(8);

void dfs(int depth, vector<pair<int, int>>& abcd) {
    if (depth == N) {
        if (abcd[0].second == 0 || abcd[1].second == 0 || abcd[2].second == 0) return;
        int irtn = abs(a - abcd[0].first) + abs(b - abcd[1].first) + abs(c - abcd[2].first);
        for (int i = 0; i < 3; i++) {
            if (abcd[i].second >= 2) irtn += (10 * (abcd[i].second - 1));
        }
        // cout << "irtn=" << irtn << " " << "a=" << abcd[0].second << " " << "b=" << abcd[1].second << " " << "c=" << abcd[2].second << endl;
        rtn = min(rtn, irtn);
        return;
    }
    for (int i = 0; i < 4; i++) {
        abcd[i].first += l[depth];
        abcd[i].second++;
        dfs(depth+1, abcd);
        abcd[i].first -= l[depth];
        abcd[i].second--;
    }
}

int main() {
    cin >> N >> a >> b >> c;
    vector<pair<int, int>> abcd(4);
    for (int i = 0; i < N; i++) cin >> l[i];
    dfs(0, abcd);
    cout << rtn << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
using ll=long long;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  ll N,K; cin >> N >> K;
  vector<ll> A(N),F(N);
  rep(i,N){cin >> A[i];}
  rep(i,N){cin >> F[i];}
  sort(A.begin(),A.end());
  sort(F.rbegin(),F.rend());
  ll l=-1,r=1e12;
  while(r-l!=1){
    ll mid=(l+r)/2;
    ll sumk=0;
    rep(i,N){
      sumk+=max(0ll,A[i]-mid/F[i]);
    }
    if(sumk<=K) r=mid;
    else l=mid;
  }
  cout << r << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>

using namespace std;
#define i64  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807



void solve(void)
{
    int S = 52;
    vector<tuple<char,int,bool> > card(S);
    for (int i = 0; i < 52; i++)
    {
            if(i<13)
            {
                get<0>(card[i]) ='S';
            }
            else if(i<26)
            {
                get<0>(card[i]) ='H';
            }
            else if(i<39)
            {
                get<0>(card[i]) ='C';
            }
            else if(i<52)
            {
                get<0>(card[i]) ='D';
            }
            get<1>(card[i]) =  i%13 + 1;
            get<2>(card[i]) =false;

    }
    
    int N;
    cin>>N;

    char c; int n;

    for (int i = 0; i < N; i++)
    {
      cin>>c>>n;
      for (int j = 0; j < 52; j++)
      {
        if( (get<0>(card[j]) == c) &&(get<1>(card[j]) == n))
          get<2>(card[j]) = true;
      }
      
    }
    

      for (int j = 0; j < 52; j++)
      {
        if( get<2>(card[j]) == false) cout<<get<0>(card[j]) <<" "<<get<1>(card[j]) <<endl;
      }


    
  return;
}

int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



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

def solve(N: int, K: int):
    i = 0
    while True:
        if N >= (K ** i):
            i += 1
        else:
            print(i)
            break

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


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

fn main() {
    let a = read_i64();
    let b = read_i64();
    let c = read_i64();
    let d = read_i64();
    let res = min(a,b) + min(c,d);
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std ;
template < class R > inline void Readin( R &K ) {
	K = 0 ; bool F = false ; char C = getchar() ; while( C < '0' or C > '9' ) { if( C == '-' ) F = true ; C = getchar() ; }
	while( C <= '9' and C >= '0' ) K = ( K << 1 ) + ( K << 3 ) + C - '0' , C = getchar() ; if( F ) K = -K ;
}
template < class R > inline void Checkmax( R &A , R B ) {
	if( A < B ) A = B ;
}
template < class R > inline void Checkmin( R &A , R B ) {
	if( A > B ) A = B ;
}
const int MaxN = 200 + 10 ;
int N , A[MaxN] , Ans ;
int main() {
	Readin( N ) ; N <<= 1 ;
	for(register int i = 0 ; ++i <= N ; )
		Readin( A[i] ) ;
	sort( A + 1 , A + 1 + N ) ;
	for(register int i = 1 ; i <= N ; i += 2 )
		Ans += A[i] ;
	return not printf( "%d\n" , Ans ) ;
}

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

int main() {
    int N;
    cin >> N;
    multiset<int> A;
    for(int i=0; i<(1<<N); ++i) {
        int a; cin >> a;
        A.insert(-a);
    }

    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0, *begin(A));
    A.erase(begin(A));
    while(!que.empty()) {
        P cur = que.top();
        int val = cur.second, depth = cur.first;
        que.pop();
        auto itr = A.upper_bound(val);
        if(itr == end(A)) {
            cout << "No" << endl;
            return 0;
        } else if(depth < N - 1) {
            que.emplace(depth + 1, val);
            que.emplace(depth + 1, *itr);
        }
        A.erase(itr);
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 13692
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	vector<pair<long long, long long> >a;
	vector<pair<long long, long long> >b;
	bool used[N];
	long long l[N];
	long long r[N];
	long long n, m, k;
	long long x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%lld", &n);
	for(long long i=0;i<n;i++){
		scanf("%lld %lld", &x,&y);
		a.push_back(make_pair(x, i));
		b.push_back(make_pair(y, i));
		l[i] = x;
		r[i] = y;
		used[i] = false;
	}
	sort(a.begin(), a.end(), greater<pair<long long, long long> >());
	sort(b.begin(), b.end());
	x = 0;
	y = 0;
	z = 0;
	k = 0;
	f(i,n){
		if (z == 0){
			while (used[a[x].second])x++;
				m = a[x].second;
				if (k < l[m]){
					ans += (l[m] - k);
					k = l[m];
				}
				else if (r[m] < k){
					ans += (k - r[m]);
					k = r[m];
				}
				used[m] = true;
				z = 1;
		}
		else{
			while (used[b[y].second])y++;
			m = b[y].second;
			if (k < l[m]){
				ans += (l[m] - k);
				k = l[m];
			}
			else if (r[m] < k){
				ans += (k - r[m]);
				k = r[m];
			}
			used[m] = true;
			z = 0;
		}
	}
	z = k;
	if (z < 0)z = -z;
	ans += z;
  
  
  	for(int i=0;i<n;i++){
		used[i] = false;
	}
  s=0;
  x = 0;
	y = 0;
	z = 1;
	k = 0;
	f(i,n){
		if (z == 0){
			while (used[a[x].second])x++;
				m = a[x].second;
				if (k < l[m]){
					s += (l[m] - k);
					k = l[m];
				}
				else if (r[m] < k){
					s += (k - r[m]);
					k = r[m];
				}
				used[m] = true;
				z = 1;
		}
		else{
			while (used[b[y].second])y++;
			m = b[y].second;
			if (k < l[m]){
				s += (l[m] - k);
				k = l[m];
			}
			else if (r[m] < k){
				s += (k - r[m]);
				k = r[m];
			}
			used[m] = true;
			z = 0;
		}
	}
	z = k;
	if (z < 0)z = -z;
	s += z;

  if(ans<s)ans=s;
  
	printf("%lld\n", ans);


	return 0;
}

Measured memory_bytes: 6500
#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    cout << n - k + 1 << endl;
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	string s; cin >> s;
	ll n = s.size();
	vector<ll> v(26, 0);
	rep(i, n)++v[s[i] - 'a'];
	ll res = n * (n - 1) / 2 + 1;
	for (ll x : v)
	{
		if (x == 0)continue;
		res -= x * (x - 1) / 2;
	}
	cout << res << endl;
}

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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("d",&a,&b)
#define sfff(a,b,c)     scanf("d%d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int z=1 ; z<=t ; z++)
#define PRINT_CASE printf("Case %d: ",z)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = 100005;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;
int n,k,a[102];

int win_dp[maxn];

int cal(int stone)
{
    if(stone<a[1] || stone==0) return 0;

    int &win=win_dp[stone];
    if(win!=-1){
        return win;
    }
    win=0;
    f1(i,n) if(a[i]<=stone)
    win|=!cal(stone-a[i]);

    return win;
}

int main() {

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin>>n>>k;

    f1(i,n) cin>>a[i];


    memset(win_dp , -1 , sizeof(win_dp));


    int win=cal(k);
    if(win) cout<<"First"<<endl;
    else cout<<"Second"<<endl;

    return 0;
}

Measured memory_bytes: 5376
import java.util.Scanner;
public class Main {
	public static void main (String args[]) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if (n==0) {
				break;
			}
			int num[] = new int[n];
			for (int i=0;i<n;i++) {
				num[i] = sc.nextInt();
			}
			int searchNum = sc.nextInt();
			int begin = 0,end = n-1,center = end/2,ans = 1;
			while (num[center]!=searchNum) {
				if (num[center]>searchNum) {
					end = center - 1;
				}else{
					begin = center + 1;
				}
				center = (begin+end)/2;
				if(begin>end) {
					break;
				}
				ans++;
			}
			System.out.println(ans);
		}
	}
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];
    ll dp[100005][2];
    mem(dp,0);
    dp[0][0]=a[0];dp[0][1]=-a[0];
    rep(i,n-2){
        rep(j,2){
            if(j==0){
                dp[i+1][0]=max(dp[i][0]+a[i+1],dp[i][1]-a[i+1]);
            }
            else{
                dp[i+1][1]=max(dp[i][0]-a[i+1],dp[i][1]+a[i+1]);
            }
        }
    }
    cout<<max(dp[n-2][0]+a[n-1],dp[n-2][1]-a[n-1]);
}

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

int const N = 100;
char s[N + 1];
int k, n;
bool w[N];

void win(ll x) { printf("%lld\n", x); exit(0); }

pair<int, bool> go(bool z){
	w[0] = z;
	int an = z;
	f(i, 1, n)if (!w[i - 1] && s[i] == s[i - 1]){
		w[i] = true;
		++an;
	}else w[i] = false;
	return make_pair(an, !w[n - 1] && s[n - 1] == s[0]);
}

int main(){
	scanf("%s%d", s, &k);
	n = strlen(s);
	pair<int, bool> z = go(0), o = go(1);
	if (z.second){
		if (o.second)win(z.first + (ll)o.first * (k - 1));
		else {
			ll an = (ll)k / 2 * (z.first + o.first);
			if (k & 1)an += z.first;
			win(an);
		}
	}else win((ll)z.first * k);
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    
    if(a < b){
        printf("a < b\n");
    }else if(a > b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }

    return 0;
}

Measured memory_bytes: 1008
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 25555;
int n,a[4],tot;
	const int M = 200000;const ll inf = 1e16;
	int S,T,edgenum=1,head[N],cur[N],to[M],nxt[M],cap[M],val[M];
	inline void addedge(int u, int v, int c, int w){
		to[++edgenum]=v;cap[edgenum]=c;val[edgenum]=w;
		nxt[edgenum]=head[u];head[u]=edgenum;
	}
	inline void add(int u, int v, int c, int w){
		assert(u<=T&&v<=T&&u&&v);w=-w;
		addedge(u,v,c,w);addedge(v,u,0,-w);
	}
	int rec[N],q[N];bool vis[N];ll dis[N];
	inline void inc(int &x){x++;x=x==N?0:x;}
	inline bool spfa(){
		int f=0,r=1;rep(i,0,T)dis[i]=inf;dis[T]=0;q[f]=T;
		while(f!=r){
			int u=q[f];inc(f);vis[u]=0;
			L(i,u)if(cap[i^1]&&dis[to[i]]>dis[u]+val[i^1]){
				dis[to[i]]=dis[u]+val[i^1];rec[to[i]]=i;
				if(!vis[to[i]]){
					q[r]=to[i],inc(r);vis[to[i]]=1;
				}
			}
		}
		return dis[S]<inf;
	}
	bool incir[N];
	inline int dfs(int u, int flow){
		if(u==T||!flow)return flow;assert(!incir[u]);int tot=0;incir[u]=1;
		for(register int &i=cur[u];i;i=nxt[i])if(cap[i]&&dis[u]==dis[to[i]]+val[i]&&!incir[to[i]]){
			int tmp=dfs(to[i],min(flow,cap[i]));
			cap[i]-=tmp;cap[i^1]+=tmp;tot+=tmp;flow-=tmp;if(!flow)break;
		}
		incir[u]=0;return tot;
	}
	inline ll solve(){
		ll res=0;
		while(spfa()){
			memcpy(cur,head,4*(T+2));
			int qaq=dfs(S,0x3f3f3f3f);res+=1LL*qaq*dis[S];
		}
		return -res;
	}
int main() {
	read(n);S=2*n+11;T=S+1;tot=2*n+1;
	rep(j,0,3)a[j]=tot+j;
	rep(i,1,n){
		int x,y,c;read(x);read(y);read(c);
		add(S,i,c,0);
		add(i,a[0],c,-x-y);
		add(i,a[1],c,-x+y);
		add(i,a[2],c,x-y);
		add(i,a[3],c,x+y);
	}
	rep(i,1,n){
		int x,y,c;read(x);read(y);read(c);
		add(n+i,T,c,0);
		add(a[0],n+i,c,x+y);
		add(a[1],n+i,c,x-y);
		add(a[2],n+i,c,-x+y);
		add(a[3],n+i,c,-x-y);
	}
	cout<<solve();
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int Max = 10000;
int main()
{
	
	int a, b, k;
	cin >> a >> b >> k;
	int cnt = 0;
	for (int i = max(a,b);i>0; i--) {
		if (a % i == 0 and b % i == 0) {
			cnt++;
		}
		if (cnt==k) {
			cout << i;
			return 0;
		}
	}
}

Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<string>

int main(){
    std::string S;
    for(int i = 0; i < 5; i++){
        std::cin >> S;
        if(S == "0"){
            std::cout << i + 1 << std::endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3596
using System;
using System.Linq;

namespace V2013{
    public class Program{
        public static void Main(string[] args){
            while(true){
                var N = int.Parse(Console.ReadLine());
                if(N == 0) break;

                var sum = new int[24 * 60 * 60];
                for(var i = 0; i < N; i++){
                    var T = Console.ReadLine().Split(' ');

                    var from = (int)TimeSpan.Parse(T[0]).TotalSeconds;
                    var to = (int)TimeSpan.Parse(T[1]).TotalSeconds;
                    for(var j = from; j < to; j++) sum[j]++;
                }

                Console.WriteLine(sum.Max());
            }
        }
    }
}

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int H, W;
    string S[2000];
    vector< vector<int*> > lx (2001, vector<int*>(2001));
    vector< vector<int*> > ly (2001, vector<int*>(2001));

    cin >> H >> W;

    for(int h = 0; h < H; h++) {
        cin >> S[h];
    }

    for(int h = 0; h < H; h++) {
        int *v = new int;
        *v = 0;
        for(int w = 0; w < W; w++) {
            if(S[h][w] == '#') {
                v = new int;
                *v = 0;
            } else {
                *v = *v + 1;
                lx[h][w] = v;
            }
        }
    }
    IFD {
        for(int h = 0; h < H; h++) {
            for(int w = 0; w < W; w++) {
                if(S[h][w] == '#') {
                    cout << "x ";
                } else {
                    cout << *lx[h][w] << " ";
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    for(int w = 0; w < W; w++) {
        int *v = new int;
        *v = 0;
        for(int h = 0; h < H; h++) {
            if(S[h][w] == '#') {
                v = new int;
                *v = 0;
            } else {
                *v = *v + 1;
                ly[h][w] = v;
            }
        }
    }
    IFD {
        for(int h = 0; h < H; h++) {
            for(int w = 0; w < W; w++) {
                if(S[h][w] == '#') {
                    cout << "x ";
                } else {
                    cout << *ly[h][w] << " ";
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    int ans = 0;
    for(int w = 0; w < W; w++) {
        for(int h = 0; h < H; h++) {
            if(S[h][w] != '#') {
                ans = max(ans, *lx[h][w] + *ly[h][w] - 1);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector <int>;
using vll = vector <ll>;
using vvi = vector <vi >;
using pii = pair <int, int>;
using pll = pair <long, long>;
using vpi = vector <pii >;

#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define dg(x) cout << #x << " = " << x << endl

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

    int x;
    cin >> x;
    if (x >= 30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll rwpw(ll a, ll p){
	ll ret = 1ll;
	while(p){
		if(p%2){
			mul_mod(ret,a);
		}
		mul_mod(a,a);
		p /= 2;
	}
	return ret;
}

int n;
ll hlf=(MOD+1)/2,x[225816]={1ll},y[225816]={0ll},ans=0ll;
vector<int> g[225816];

int solve(int v, int p=-1){
	int i,ret=1,u,tmp;
	ll ex = hlf;
	add_mod(ex,MOD-x[n]);
	for(i=(g[v].l_ength()-1); i>=0; --i){
		u = g[v][i];
		if(u == p){
			continue;
		}
		tmp = solve(u,v);
		add_mod(ex,MOD-y[tmp]*x[n-tmp]%MOD);
		ret += tmp;
	}
	add_mod(ex,MOD-y[n-ret]*x[ret]%MOD);
	add_mod(ans,ex);
	return ret;
}

int main(void){
	int i,u,v;
	cin >> n;
	for(i=1; i<=n; ++i){
		x[i] = x[i-1]*hlf%MOD;
		y[i] = MOD+1-x[i]; y[i]%=MOD;
	}
	for(i=1; i<n; ++i){
		cin >> u >> v;
		--u; --v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	solve(0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 26112
package main

import "fmt"

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	fmt.Println(min(n%k, abs(n%k-k)))
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int N, T;
  cin >> N >> T;
  vector<int> t(N);
  rep(i, N) cin >> t.at(i);
  ll res = 0;
  rep(i, N) {
    if (i != N - 1) {
      res += min(T, t.at(i + 1) - t.at(i));
    } else {
      res += T;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1024