akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>
#include <random>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
mt19937 rnd(123);
const ll INF = 2e9 + 1000;

struct node {
	node *l, *r;
	ll x, d, sum;
	ll dx;
	int y;
	node() {
		l = r = 0;
		x = d = sum = dx = 0;
		y = rnd();
	}
};

void push(node *v) {
	if (!v || !v->dx)
		return;
	if (v->l) {
		v->l->dx += v->dx;
		v->l->x += v->dx;
	}
	if (v->r) {
		v->r->dx += v->dx;
		v->r->x += v->dx;
	}
	v->dx = 0;
}

void upd(node *v) {
	if (!v)
		return;
	v->sum = v->d;
	if (v->l)
		v->sum += v->l->sum;
	if (v->r)
		v->sum += v->r->sum;
}

node *merge(node *l, node *r) {
	if (!l)
		return r;
	if (!r)
		return l;
	if (l->y > r->y) {
		push(l);
		l->r = merge(l->r, r);
		upd(l);
		return l;
	}
	else {
		push(r);
		r->l = merge(l, r->l);
		upd(r);
		return r;
	}
}

void split(node *v, ll x, node *&l, node *&r) {
	if (!v) {
		l = r = 0;
		return;
	}
	if (v->x >= x) {
		push(v);
		split(v->l, x, l, v->l);
		upd(v);
		r = v;
	}
	else {
		push(v);
		split(v->r, x, v->r, r);
		upd(v);
		l = v;
	}
}

ll find(node *v, ll now) {
	push(v);
	if (v->l && v->l->sum + now > 0)
		return find(v->l, now);
	if (v->l)
		now += v->l->sum;
	if (now + v->d > 0)
		return v->x;
	else
		now += v->d;
	return find(v->r, now);
}
ll gpnt = 0;
ll gtmp = 0;

node *root;

void add(ll x) {
	gtmp += abs(x - gpnt);
	node *tmp = root;
	while (tmp->l)
		tmp->sum -= 1, tmp = tmp->l;
	tmp->sum -= 1;
	tmp->d -= 1;
	node *l, *r, *m;
	split(root, x, l, r);
	split(r, x + 1, m, r);
	if (m) {
		m->d += 2;
		m->sum += 2;
	}
	else {
		m = new node();
		m->x = x;
		m->d = 2;
		m->sum = 2;
	}
	root = merge(l, merge(m, r));
}

void diva(ll l1, ll l2) {
	gpnt -= l1;
	ll x = find(root, 0);
	node *l, *r;
	node *tmp;
	split(root, x, l, r);
	if (l)
		l->dx -= l1, l->x -= l1;
	if (r)
		r->dx += l2, r->x += l2;
	if ((l ? l->sum : 0) != 0) {
		ll k = (l ? l->sum : 0);
		tmp = new node();
		tmp->x = x - l1;
		tmp->d = tmp->sum = -k;
		l = merge(l, tmp);
		tmp = r;
		while (tmp->l) {
			tmp->sum += k;
			tmp = tmp->l;
		}
		tmp->sum += k;
		tmp->d += k;
	}
	root = merge(l, r);
}

ll gans = 0;

void dfs1(node *v, ll x) {
	push(v);
	if (v->x < x)
		gans += v->d * (x - v->x);
	if (v->l)
		dfs1(v->l, x);
	if (v->r)
		dfs1(v->r, x);
}

ll getans() {
	ll x = find(root, 0);
	dfs1(root, x);
	return gans;
}

int n;
ll l[120000];
ll r[120000];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%lld%lld", l + i, r + i);
	root = new node();
	add(l[0]);
	for (int i = 1; i < n; ++i) {
		ll len1 = r[i - 1] - l[i - 1];
		ll len2 = r[i] - l[i];
		diva(len2, len1);
		add(l[i]);
	}
	cout << gtmp + getans() << "\n";
	return 0;
}




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

	int main(){
      int N;
      string S;
      int x=0;
      int M=0;
      cin >> N >> S;
      for (int i;i<N;i++){
        x+=(S[i]-'D')/2-1;
        M=max(M,x);
      }
      cout << M;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

/* 基本要素 */
typedef complex<double> Point;
typedef pair<Point, Point> Line;
typedef vector<Point> VP;
const double PI = acos(-1);
const double EPS = 1e-7; // 許容誤差^2
const double INF = 1e9;
#define X real()
#define Y imag()
#define LE(n,m) ((n) - (m) < EPS)
#define GE(n,m) (EPS > (m) - (n))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// 内積　dot(a,b) = |a||b|cosθ
double dot(Point a, Point b) {
  return a.X*b.X + a.Y*b.Y;
}

// 外積　cross(a,b) = |a||b|sinθ
double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

// 点の進行方向
// !!! 誤差に注意 !!! (掛け算したものとかなり小さいものを比べているので)
int ccw(Point a, Point b, Point c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}

// 線分と点
bool isecSP(Point a1, Point a2, Point b) {
  return !ccw(a1, a2, b);
}

// 点pの直線aへの射影点を返す
Point proj(Point a1, Point a2, Point p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}

double distSP(Point a1, Point a2, Point p) {
  Point r = proj(a1, a2, p);
  if (isecSP(a1, a2, r)) return abs(r-p);
  //= !ccw(a1, a2, r)
  return min(abs(a1-p), abs(a2-p));
}

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

    vector<int> r(n);
    vector<VP> p(n,VP(2));
    rep(i,n){
        cin >>r[i];
        rep(j,2){
            int x,y;
            cin >>x >>y;
            p[i][j] = Point(x,y);
        }
    }

    vector<int> dp(1<<n);
    dp[0] = 1;
    int ans = 0;
    rep(mask,1<<n)if(dp[mask]){
        ans = max(ans, __builtin_popcount(mask));
        rep(i,n)if(!(mask>>i&1)){
            int ok = 1;
            rep(j,n)if(j!=i){
                Point c = p[j][mask>>j&1];
                double d = distSP(p[i][0], p[i][1], c);
                if(LE(d, r[i]+r[j])) ok = 0;
            }
            dp[(mask|(1<<i))] |= ok;
        }
    }
    cout << ans << "\n";
    return 0;
}



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

int n;
ll c[100001], k;

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		c[a] += b;
	}
	//cout << "k:" << k << endl;
	int ans;
	for (int i = 1; i <= 100000;i++) {
		if (k - c[i] <= 0) {
			ans = i;
			break;
		}
		k -= c[i];
		//cout << k << endl;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		String ans = "No";

		for (int i = 0; i < 3; i++) {

			if (n % 10 == 7) {
				ans = "Yes";
			}
			n = n / 10;
		}

		System.out.println(ans);
	}

}


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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int a;
	cin >> a;
	cout << a + a * a + a * a * a << endl;
    
    return 0;
}



Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b)
{
  return *(int*)b - *(int*)a;
}
int main(int argc, char **argv){
	int n, k, sum;
	sum = 0;
	scanf("%d\n", &n);
	scanf("%d\n", &k);
	int stk[n];

	for (int i = 0; i < n; i++) {
		(void)scanf("%d", &stk[i]);
	}
	qsort(stk, n, sizeof(int), compare_int);
	for (int i = 0; i < k; i++) {
		sum += stk[i];
	}
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n)  for(int i=0; i<(int) (n); i++)


const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];


int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}
//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	return lower_bound(all(vec), xx) - vec.begin();
}
template<typename T>
void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>
void vecin(vector<TT>& vec) {
	for (int i = 0; i < vec.size(); i++) {
		cin >> vec[i];
	}
}


// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
//グループが0個でもいいときはnにxを足す
// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx <= 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}


signed main() {
	int n,ans=0;
	cin >> n;
	vector<int>vec(n);
	vecin(vec);
	rep(i, n) {
		if (!(i & 1) && vec[i] & 1) {
			ans++;
		}
	}
	cout << ans << endl;
}


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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  vector<ll> p(n);
  vector<bool> v(n, false);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }
  ll ans = 0;
  rep(i, n) {
    if (v[i]) continue;
    if (i == p[i] && i == n-1) {
      reverse(p.begin()+i, p.begin()+i-1);
      ans++;
      break;
    }
    if (i == p[i]) {
      reverse(p.begin()+i, p.begin()+i+1);
      v[i] = true;
      v[i+1] = true;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100100;

// 入力
int N;
long long W, weight[MAX_N], value[MAX_N]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // 初期化
    for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;

    // 初期条件
    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {

            // i 番目の品物を選ぶ場合
            if (sum_v - value[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            // i 番目の品物を選ばない場合
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}


Measured memory_bytes: 86272
#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 a, b, m;
    cin >> a >> b >> m;
    int ref[a];
    int mic[b];
    int minref = 100001;
    int minmic = 100001;
    rep(i,a) {
        cin >> ref[i];
        minref = min(ref[i], minref);
    }
    rep(i,b) {
        cin >> mic[i];
        minmic = min(mic[i], minmic);
    }
    int ans = 1001001001;
    rep(i,m) {
        int x, y, c;
        cin >> x >> y >> c; x--, y--;
        ans = min(ref[x] + mic[y] - c, ans);
    }
    ans = min(minref + minmic, ans);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
struct LazySegmentTree {
    int n;
    vector<ll> node, lazy;
    vector<bool> lazyFlag;
    
    LazySegmentTree(vector<ll> v) {
        int sz=sz(v);
        n=1;
        while(n<sz) n*=2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, LINF);
        lazyFlag.resize(2*n-1, false);
        
        rep(i,sz) node[i+n-1]=v[i];
        rrep(i,n-1) node[i]=min(node[i*2+1], node[i*2+2]);
    }
    
    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k]=lazy[k];
            if(r-l>1) {
                lazy[k*2+1]=lazy[k];
                lazy[k*2+2]=lazy[k];
                lazyFlag[k*2+1]=true;
                lazyFlag[k*2+2]=true;
            }
            lazyFlag[k]=false;
        }
    }
    
    void update(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r<0) r=n;
        lazyEvaluate(k, l, r);
        if(b<=l || r<=a) return;
        
        if(a<=l && r<=b) {
            lazy[k]=x;
            lazyFlag[k]=true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k]=min(node[2*k+1], node[2*k+2]);
        }
    }
    
    ll getmin(int a, int b, int k=0, int l=0, int r=-1) {
        if(r<0) r=n;
        lazyEvaluate(k, l, r);
        
        if(b<=l || r<=a) return LINF;
        if(a<=l && r<=b) return node[k];
        
        ll vl=getmin(a, b, 2*k+1, l, (l+r)/2);
        ll vr=getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

int main() {
    int n,q;
    cin>>n>>q;
    vector<ll> v(n,(1LL<<31)-1);
    LazySegmentTree segt(v);
    while(q--) {
        int Q;
        cin>>Q;
        if(Q==0) {
            int s,t;
            ll x;
            cin>>s>>t>>x;
            segt.update(s,t+1,x);
        }
        else {
            int s,t;
            cin>>s>>t;
            ll ans=segt.getmin(s,t+1);
            cout<<ans<<endl;
        }
    }
}



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

int main()
{
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    vector<vector<int>> a(n, vector<int> (m));
    for (int i = 0; i < m; ++i) cin >> b[i];
    for (int i = 0; i < n; ++i) for (int k = 0; k < m; ++k) cin >> a[i][k];
    
    int count = 0;
    for (int i = 0; i < n; ++i)
    {
        int temp = 0;
        for (int k = 0; k < m; ++k) temp += a[i][k] * b[k];
        if (temp + c > 0) ++count;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int ab[] = new int[2];
        ab[0] = sc.nextInt();
        ab[1] = sc.nextInt();

        for(int i=0;i<ab.length;i++){
            if(ab[i] == 1){
                ab[i] = ab[i] + 13;
            }
        }

        if(ab[0] > ab[1]){
            System.out.println("Alice");
        }else if(ab[0] < ab[1]){
            System.out.println("Bob");
        }else{
            System.out.println("Draw");

        }

        }        
    }



Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
int32_t main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector <int> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	cout << v[n / 2 ] - v[n / 2 - 1 ];
}

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

#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define N 100005

int n, m;
int par[N], sz[N];

int find(int u) {
    if(par[u] == -1)    return u;
    return par[u] = find(par[u]); 
}

signed main() {
    cin >> n >> m;
    vi a(m), b(m);
    for(int i = 0; i < m; i++)  cin >> a[i] >> b[i];
    int ans = (n * (n - 1)) / 2;
    memset(par, -1, sizeof par);
    memset(sz, 0, sizeof sz);
    vi ret;
    for(int i = 1; i <= n; i++) sz[i]++;
    for(int i = m - 1; i >= 0; i--) {
        ret.pb(ans);
        int u = find(a[i]), v = find(b[i]);
        if(u != v) {
            par[u] = v;
            ans -= (sz[u] * sz[v]);
            sz[v] += sz[u];
        }
    }
    for(int i = m - 1; i >= 0; i--) cout << ret[i] << endl;
}


Measured memory_bytes: 5364
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long int x;
    std::cin >> x;
    long long int ans=x/11*2;
    if(x%11>6){
        ans+=2;
    }else if(x%11>0){
        ans++;
    }
    
    
    std::cout << ans << std::endl;
    
}


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

struct PrimalDual{
  const int INF = 1<<28;
  typedef pair<int,int> P;
  struct edge{
    int to,cap,cost,rev;
    edge(){}
    edge(int to,int cap,int cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}
  };

  int n;
  vector<vector<edge> > G;
  vector<int> h,dist,prevv,preve;

  PrimalDual(){}
  PrimalDual(int sz):n(sz),G(sz),h(sz),dist(sz),prevv(sz),preve(sz){}
  
  void add_edge(int from,int to,int cap,int cost){
    G[from].push_back(edge(to,cap,cost,G[to].size()));
    G[to].push_back(edge(from,0,-cost,G[from].size()-1));
  }

  int flow(int s,int t,int f){
    int res=0;
    fill(h.begin(),h.end(),0);
    while(f>0){
      priority_queue<P,vector<P>,greater<P> > que;
      fill(dist.begin(),dist.end(),INF);
      dist[s]=0;
      que.push(P(0,s));
      while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(dist[v]<p.first) continue;
        for(int i=0;i<(int)G[v].size();i++){
          edge &e=G[v][i];
          if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
            dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
            prevv[e.to]=v;
            preve[e.to]=i;
            que.push(P(dist[e.to],e.to));
          }
        }
      }
      if(dist[t]==INF) return -1;
      for(int v=0;v<n;v++) h[v]+=dist[v];
      int d=f;
      for(int v=t;v!=s;v=prevv[v]){
        d=min(d,G[prevv[v]][preve[v]].cap);
      }
      f-=d;
      res+=d*h[t];
      for(int v=t;v!=s;v=prevv[v]){
        edge &e=G[prevv[v]][preve[v]];
        e.cap-=d;
        G[v][e.rev].cap+=d;
      }
    }
    return res;
  }
};

int main(){
  int n,m,K;
  cin>>n>>m>>K;
  int a[n],b[m][n],t[m];
  r(i,n)cin>>a[i];
  r(i,m)r(j,n)cin>>b[i][j];
  r(i,m)cin>>t[i];
  int v=n+m+4;
  PrimalDual p(v);
  int start=n+m+1;
  int goal=n+m+2;
  int tite=n+m+3;
  r(i,n)p.add_edge(start,i,1,0);
  r(i,m+1){
    if(!i)p.add_edge(n+i,goal,1000,0);
    else p.add_edge(n+i,tite,t[i-1],0);
  }
  p.add_edge(tite,goal,n-K,0);
  r(i,n){
    r(j,m+1){
      if(!j)p.add_edge(i,n+j,1,-a[i]);
      else p.add_edge(i,n+j,1,-b[j-1][i]);
    }
  }
  cout<<-p.flow(start,goal,n)<<endl;
}


Measured memory_bytes: 3436
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;


int digit(ll n) {
    int x = 0;
    while (n > 0) {
        n /= 10;
        x++;
    }
    return max(1, x);
}

void Main()
{
    ll n;
    cin >> n;

    int res = 1e8;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            ll A = i;
            ll B = n / i;
            int dA = digit(A);
            int dB = digit(B);
            res = min(res, max(dA, dB));
        }
    }

    put(res)
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3644
N = int(input())
h = list(map(int, input().split()))

dp = [10 ** 4] * N
for i in range(N):
    if 0 == i:
        dp[0] = 0
    elif 1 == i:
        dp[1] = abs(h[1]-h[0])
    else:
        dp[i] = min(abs(h[i]-h[i-1]) + dp[i-1], abs(h[i]-h[i-2]) + dp[i-2])
print(dp[-1])


Measured memory_bytes: 13924
n, m = map(int, input().split())
ab = list(list(map(int, input().split())) for _ in range(n))
cd = list(list(map(int, input().split())) for _ in range(m))

for j in range(n):
    a, b = ab[j][0], ab[j][1]
    ans, res = 0, 1001001001
    for i in range(m):
        c, d = cd[i][0], cd[i][1]
        if abs(a-c)+abs(b-d) < res:
            res = abs(a-c)+abs(b-d)
            ans = i+1
    print(ans)

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a<b){
        cout << "a < b" <<endl;}
    else if(a>b){
        cout << "a > b" <<endl;}
    else{
        cout << "a == b" <<endl;}
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main (){
	string s; cin>>s;
	int a,b,c,d;
	d = ctoi(s[3]);
	c = ctoi(s[2]);
	b = ctoi(s[1]);
	a = ctoi(s[0]);
	int li[4] = {a,b,c,d};
	for (int bit = 0; bit < 1<<3; bit++){
		int ans = li[0];
		for (int i = 0; i < 3; i++){
			if (bit & (1<<i)){
				ans += li[i+1];
			}else{	
				ans -= li[i+1];
			}
		}
		if (ans==7){
			cout << li[0];
			for (int i = 0; i < 3; i++){
				if (bit & (1<<i)){
					cout << "+";
				}else{	
					cout << "-";
				}
				cout << li[i+1];
			}
			cout << "=7" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
while(True):
    H, W = map(int, input().split())
    if(H == 0 and W == 0):
        break
    else:
        for i in range(W):
            print("#", end = "")
        print("")
        for i in range(H-2):
            for k in range(W):
                if(k == 0 or k == (W-1)):
                    print("#", end = "")
                else:
                    print(".", end = "")
            print("")
        for i in range(W):
            print("#", end = "")
        print("")
        print("")


Measured memory_bytes: 7016
N, K = gets.split.map(&:to_i)

data = Array.new(10**5 + 1, 0)
while v = gets()
  a, b = v.split.map(&:to_i)
  data[a] += b
end
c = 0
data.each_with_index{|v, i|
  c += v
  if c >= K
    p i
    exit
  end
}



Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 10007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<LP> stores(N);
    llong A,B;
    REP(i,N){
        cin >> A >> B;
        stores[i]=make_pair(A,B);
    }
    sort(stores.begin(),stores.end());
    llong nokori=M;
    llong ans=0;
    REP(i,N){
        llong get_M = min(nokori,stores[i].second);
        ans +=get_M*stores[i].first;
        nokori-= get_M;
        if(nokori == 0) break;
    }
    cout << ans <<endl;

    return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  if(N%2!=0){
    cout << "No" << endl;
    return 0;
  }else{
    for(int i=0; i<N/2; i++){
      if(S.at(i) == S.at(N/2+i)) continue;
      else{
        cout << "No" << endl;
        return 0;
      }
    }
  }  
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramB
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var n = long.Parse(inputs[0]);
            var d = long.Parse(inputs[1]);
            var list = new int[n][];

            for (var i = 0; i < n; i++)
            {
                list[i] = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
            }

            var result = 0;

            for (var i = 0; i < n; i++)
            {
                for (var j = i + 1; j < n; j++)
                {
                    var dist = 0d;
                    for (var k = 0; k < d; k++)
                    {
                        var l = (list[i][k] - list[j][k]);
                        dist += l * l;
                    }
                    dist = Math.Sqrt(dist);
                    if (dist < (int)(dist) + 1e-10) result++;
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 28268
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
inline int qpow(int bas,int pw)
{
	int ret=1; for(;pw;pw>>=1,bas=1ll*bas*bas%mod)
	if(pw&1) ret=1ll*ret*bas%mod; return ret;
}
inline void Add(int &x,int y)
{
	x+=y; if(x>=mod) x-=mod;
	if(x<0) x+=mod;
}
int n,k,di[10010],F[10010];
int main()
{
	n=read(); k=read();
	for(int i=1;i*i<=n;i++) if(n%i==0)
	{
		di[++di[0]]=i; if(i*i!=n)
		di[++di[0]]=n/i;
	}
	sort(di+1,di+1+di[0]);
	for(int i=1;i<=di[0];i++)
	{
		F[i]=qpow(k,(di[i]+1)/2);
		for(int j=1;j<i;j++) if(di[i]%di[j]==0)
			Add(F[i],-F[j]);
	}
	int Ans=0;
	for(int i=1;i<=di[0];i++)
		if(di[i]&1) Add(Ans,1ll*di[i]*F[i]%mod);
		else Add(Ans,1ll*di[i]/2*F[i]%mod);
	cout << Ans << endl;
	return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
typedef long long int ll;
typedef long double ld;
const ll N = 2e5+9;
const ll m = 1e9 + 7;
const ll MAXN = 2e3 + 9;

const ll inf= 1e14;
const ll mod =163577857;
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pld pair<ld,ld>
ll powm(ll a, ll b) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }

int main()
{   
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif     
    ll T= 1;
    // cin >> T;
    while(T--){
        ll n;cin>>n;
        ll a[n];
        for(int i = 0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        ll is[n];
        ll k =a[n-1];
        ll mi = k/2;
        mi+=k%2;
        memset(is,0,sizeof(is));
        for(int i = 0;i<n;i++)
            is[a[i]]++;
        bool ans = 1;
        // cout<<k<<" "<<mi<<'\n';
        // for(int i = 0;i<n;i++){
        //     cout<<is[i]<<" ";
        // }
        // cout<<'\n';
        for(int i = 0;i<n;i++){
            if(i<=k){
                if(i<mi){   
                    ans&=(!is[i]);
                }
                else if(i>mi){
                    if(is[i]>=2){
                        ans&=1;
                    }
                    else{
                        ans&=0;
                    }
                }
                else{
                    if(k%2){\
                        if(is[i]==2){
                            ans&=1;
                        }
                        else{
                            ans&=0;
                        }

                    }
                    else{
                        if(is[i]==1){
                            ans&=1;
                        }
                        else{
                            ans&=0;
                        }
                    }
                }
            }
            else{
                ans&=(!is[i]);
            }
        }
        if(ans){
            cout<<"Possible\n";
        }
        else{
            cout<<"Impossible\n";
        }
    }
   
}   

Measured memory_bytes: 3608
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=303, mod=1e9+7;
struct dabt{ int next,to,dis; }e[N];
int head[N],k,n,m,dp[N][N][N],ans;
inline void add(int from,int to,int d){e[++k]=(dabt){head[from],to,d}; head[from]=k;}
inline int read(){
	char ch=getchar(); int x=0, f=1;
	while(ch<'0' || ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
	return x*f;}
inline int mx(int a,int b){return a>b ? a : b;}
inline bool chek(int i,int j,int l)
{
	int r=mx(i,mx(j,l));
	for(RG int ii=head[r];ii;ii=e[ii].next)
	{
		int v=e[ii].to, d=e[ii].dis, tt=(i>=v)+(j>=v)+(l>=v);
		if(tt!=d) return 0;
	}
	return 1;
}
int main()
{
//	freopen("RGB Sequence.in","r",stdin);
	n=read(); m=read();
	for(RG int i=1,a,b,c;i<=m;i++)
	{
		a=read(); b=read(); c=read();
		add(b,a,c);
	}
	dp[0][0][0]=1;
	for(RG int i=0;i<=n;i++)
	 for(RG int j=0;j<=n;j++)
	  for(RG int l=0;l<=n;l++)
	  {
			int r=mx(i,mx(j,l)); int &tt=dp[i][j][l];
			if(!tt || (i+j && i==j) || (j+l && j==l) || (i+l && i==l)) continue;
			if(!chek(i,j,l)) { tt=0; continue; }
			(dp[r+1][j][l]+=tt)%=mod; (dp[i][r+1][l]+=tt)%=mod; (dp[i][j][r+1]+=tt)%=mod;
			if(r==n) (ans+=tt)%=mod;
	  }
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 108800
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

#include <cstring>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>
using namespace std;

int st[32][32];
int dp[32][32][1 << 8];
int memo[1 << 8];

const int _dx[] = {0,0,1,0,-1};
const int _dy[] = {0,-1,0,1,0};

int main(){
  while(true){
    const int w = getInt();
    const int h = getInt();

    if(w + h == 0) break;

    int sx, sy;

    REP(i,h) REP(j,w){
      char c[2];
      scanf("%s", c);
      if(c[0] == '.'){
        st[i][j] = -1;
      }else if(c[0] == 'P'){
        st[i][j] = -1;
        sx = j; sy = i;
      }else{
        st[i][j] = c[0] - '0';
      }
    }

    const int n = getInt();

    vector<int> g(n);
    vector<int> d(n);
    vector<int> s(n);
    vector<int> e(n);

    REP(i,n){
      g[i] = getInt();
      d[i] = getInt();
      s[i] = getInt();
      e[i] = getInt();
    }

    REP(i,h) REP(j,w) if(st[i][j] != -1){
      REP(k,n) if(st[i][j] == g[k]){
        st[i][j] = k;
        break;
      }
    }

    memset(dp, -1, sizeof(dp));
    REP(i,1 << n){
      memo[i] = 0;
      REP(j,n) if(i & (1 << j))
        memo[i] += d[j];
    }

    int sp = 0;
    REP(i,5){
      const int xx = sx + _dx[i];
      const int yy = sy + _dy[i];
      if(ISIN(xx, yy, w, h) && st[yy][xx] != -1){
        const int p = st[yy][xx];
        if(IN(0, s[p], e[p])){
          sp |= (1 << p);
        }
      }
    }

    queue<pair<int, pair<int, int> > > q;
    dp[sy][sx][sp] = 0;
    q.push(make_pair(sp, make_pair(sx, sy)));

    while(q.size()){
      const pair<int, pair<int, int> > d = q.front(); q.pop();
      const int f = d.first;
      const int x = d.second.first;
      const int y = d.second.second;
      const int t = dp[y][x][f] + 1;

      if(t == 100) continue;

      REP(i,5){
        const int xx = x + _dx[i];
        const int yy = y + _dy[i];

        if(ISIN(xx, yy, w, h) && st[yy][xx] == -1){
          int ff = f;
          REP(j,5){
            const int xxx = xx + _dx[j];
            const int yyy = yy + _dy[j];

            if(ISIN(xxx, yyy, w, h) && st[yyy][xxx] != -1){
              const int p = st[yyy][xxx];
              if(IN(t, s[p], e[p])){
                ff |= (1 << p);
              }
            }
          }

          if(dp[yy][xx][ff] == -1 || i == 0){
            dp[yy][xx][ff] = t;
            q.push(make_pair(ff, make_pair(xx, yy)));
          }
        }
      }
    }

    int ans = 0;
    REP(i,h) REP(j,w) REP(k,1<<n)
      if(dp[i][j][k] != -1)
        ans = max(ans, memo[k]);

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

Measured memory_bytes: 2240
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

constexpr int lim = 100000;
char isprime[lim];
int prime[lim];
int ind = 0;

void set_prime() {
    fill(isprime, isprime + lim, 1);
    isprime[0] = isprime[1] = 0;

    for (int x = 2; x < lim; ++x) {
        if (!isprime[x]) continue;
        prime[ind++] = x;

        if (x * 2 >= lim) continue;
        for (int y = x * 2; y <  lim; y += x) {
            isprime[y] = 0;
        }
    }
}

pair<int, int> solve(const int& m, const int& a, const int& b) {
    int max_pq = 0;
    pair<int, int> ret;
    for (int j = 0; prime[j] <= m / 2; ++j) {
        int q = prime[j];

        int* lb = lower_bound(prime, prime + ind, (double)a * q / b);

        if(lb == prime + ind){
            break;
        }
        
        int p = *(upper_bound(prime, prime + ind, min(q, m / q)) - 1);

        if(*lb <= p && p * q > max_pq) {
            max_pq = p * q;

            ret = make_pair(p, q);
        }
    }

    return ret;
}

int main() {
    set_prime();

    int m, a, b;
    while (true) {
        cin >> m;
        cin >> a;
        cin >> b;

        if(m == 0) break;
        pair<int, int> ret = solve(m, a, b);
        cout << ret.first << ' ' << ret.second << endl;
    }
    return 0;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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; }



void solve(long long N, std::vector<long long> A){
	double res = 0;
	REP(i, N) {
		res += 1.0/A[i];
	}
	cout << 1.0/res << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#include <cmath>
#include <cstdio>
using namespace std;
 
typedef complex<double> P;
 
const double eps = 1e-3;
const double inf = 1e8;
 
bool equals(double a, double b) {
  return abs(a-b) < eps;
}
 
bool equals(P a, P b) {
  return equals(a.real(), b.real()) && equals(a.imag(), b.imag());
}
 
double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}
 
double cross(P a, P b) {
  return a.real()*b.imag() - a.imag()*b.real();
}
 
int ccw(P p, P a, P b) {
  a -= p;
  b -= p;
  if(cross(a,b) > eps) return 1;
  if(cross(a,b) < -eps) return -1;
  if(dot(a,b) < -eps) return 2;
  if(norm(b)-norm(a) > eps) return -2;
  return 0;
}
 
P project(P s1, P s2, P p) {
  P base = s2 - s1;
  double t = dot(p - s1, base)/norm(base);
  return s1 + base*t;
}

P reflect(P s1, P s2, P p) {
  return p + (project(s1, s2, p) - p)*2.0;
}

bool isIntersect(P a1, P a2, P b1, P b2) {
  return ( ccw(a1,a2,b1) * ccw(a1,a2,b2) <= 0 &&
           ccw(b1,b2,a1) * ccw(b1,b2,a2) <= 0 );
}
 
P getCrossP(P a1, P a2, P b1, P b2) {
  P a = a2 - a1;
  P b = b2 - b1;
  return a1 + a * cross(b, b1 - a1)/cross(b, a);
}

int N;
vector<P> s1, s2;
P src, dst;

double test(P v1, P v2) {
  double sum = 0;
  for(int t = 0; t <= 5; ++t) {
    int k;
    P p;
    double mini = inf;
    P a = v1;
    P b = v1+(v2-v1)*inf;
    for(int i = 0; i < N; ++i) {
      if(!equals(abs(cross(v2-v1,s2[i]-s1[i])), 0.0) &&
         isIntersect(a, b, s1[i], s2[i]) &&
         ccw(a,b,s1[i]) != 0 && ccw(a,b,s2[i]) != 0) {
        P q = getCrossP(a, b, s1[i], s2[i]);
        double dist = norm(q-v1);
        if(equals(dist, 0.0)) continue;
        if(dist < mini) {
          mini = dist;
          p = q;
          k = i;
        }
      }
    }

    if(ccw(a,b,dst) == 0 &&
       ( equals(norm(dst-v1), mini) || norm(dst-v1) < mini )) {
      return sum + abs(dst-v1);
    }

    if(mini == inf) return inf;
 
    if(t < 5) {
      sum += abs(p-v1);
      P base = s2[k] - s1[k];
      P n(-base.imag(), base.real());
      v2 = reflect(p, p+n, v1);
      v1 = p;
    }
  }
  return inf;
}
 
int main() {
  while(cin >> N && N) {
    s1.resize(N);
    s2.resize(N);
    for(int i = 0; i < N; ++i) {
      cin >> s1[i].real() >> s1[i].imag()
          >> s2[i].real() >> s2[i].imag();
    }
    cin >> dst.real() >> dst.imag() >> src.real() >> src.imag();
 
    vector<P> target;
    target.push_back(dst);
    for(int t = 0; t < 5; ++t) {
      int size = target.size();
      for(int i = 0; i < size; ++i) {
        for(int j = 0; j < N; ++j) {
          P p = reflect(s1[j], s2[j], target[i]);
          target.push_back(p);
        }
      }
    }
 
    double res = inf;
    for(int i = 0; i < target.size(); ++i) {
      if(equals(src, target[i])) continue;
      res = min(res, test(src, target[i]));
    }
    printf("%.10f\n", res);
  }
  return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

bool ng[10];

signed main()
{
        int N,K; cin>>N>>K;
        REP(i,K){
                int a; cin>>a;
                ng[a]=true;
        }
        for(int i=N;;i++){
                string s=to_string(i);
                bool ok=true;
                REP(j,s.size()){
                        if(ng[s[j]-'0']) ok=false;
                }
                if(ok){
                        cout<<i<<endl;
                        return 0;
                }
        }
}


Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    h1,m1,h2,m2,k = LI()
    t = (h2 * 60 + m2) - (h1*60 + m1)
    print(t-k)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68844
#include <iostream> 
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
int a[202020];
int k;
	int n;

inline long long calc(int len) {
	long long tot = 0;
	for (int i = 1;i <= n; i++)
		tot += (a[i]-1)/len;
	return tot;
}

int erf(int l,int r) {
	if (l == r) {
		return l;
	}
	int mid = (l+r)/2;
	if (calc(mid) <= k) {
		return erf(l,mid);
	}
	return erf(mid+1,r);
}
int main() {
	scanf("%d%d",&n,&k);
	for (int i  =1;i <= n; i++)
		scanf("%d",&a[i]);
	printf("%d",erf(1,1000000000));
	return 0;
}
/*
4
8 3
2 3 2 1 3 3 2 1
6 3
2 3 2 3 2 3
8 3
2 3 2 1 3 3 2 1
12 4
1 2 3 4 4 3 2 1 2 4 1 3

*/

Measured memory_bytes: 4004
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	vector<int> a;
	rep(i, n + 1) {
		if (s[i] == '0') a.push_back(i);
	}
	vector<int> ans;
	int now = n;
	while (now != 0) {
		auto ite = upper_bound(a.begin(), a.end(), now - m-1);
		if (*ite == now) {
			cout << -1 << endl;
			return 0;
		}
		ans.push_back(now-*ite);
		now = *ite;
	}
	reverse(ans.begin(), ans.end());
	rep(i, ans.size()) cout << ans[i] << " ";
	cout << endl;
}

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

int main(){
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	if (e - a > k){
		cout << ":(" << endl;
	}
	else{
		cout << "Yay!" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8

s = input()

if s[0] == s[1] and s[2] == s[3] and s[0] != s[2]:
    a = "Yes"
elif s[0] == s[2] and s[1] == s[3] and s[0] != s[1]:
    a = "Yes"
elif s[0] == s[3] and s[1] == s[2] and s[0] != s[1]:
    a = "Yes"
else:
    a = "No"

print(a)


Measured memory_bytes: 3060
#include <stdio.h>

int main() {
	int s, j, i, a[1000000];

	scanf("%d", &s);

	a[0] = s;
	for (i = 1; i < 1000000; i++) {
		if (a[i - 1] % 2 == 0) {
			a[i] = a[i - 1] / 2;
		}
		else {
			a[i] = a[i - 1] * 3 + 1;
		}
		for (j = i - 1; j >= 0; j--) {
			if (a[i] == a[j]) break;
		}
		if (j >= 0) break;
	}

	printf("%d", i + 1);

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

#define PI (3.141592653)

int main(void)
{
	double x, y, angle;
	int i, n;
	
	while (scanf("%d", &n), n != -1){
		x = 0;
		y = 0;
		angle = 90 * PI / 180;
		
		for (i = 0; i < n; i++){
			angle -= (90 * PI / 180);
			x += cos(angle);
			y += sin(angle);
			angle = atan2(0 - y, 0 - x);
		}
		
		printf("%.2lf\n%.2lf\n", x, y);
	}
	
	return (0);
}

Measured memory_bytes: 724
#include <iostream>

using namespace std;

int main(void) {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    int total = 100*A;
    int sugar = 0;
    double density = 0.0;
    for(int i=0; i<=30; i++) {
        for(int j=0; j<=15; j++) {
            int water_tmp = 100*(A*i+B*j);
            if(water_tmp == 0){
                continue;
            } else if(water_tmp > F) {
                break;
            } else {
                for(int k=0; k<=3000; k++) {
                    for(int l=0; l<=1500; l++) {
                        int sugar_tmp = C*k+D*l;
                        int total_tmp = water_tmp + sugar_tmp;
                        if(total_tmp > F) {
                            break;
                        } else {
                            int limit = water_tmp / 100 * E;
                            if(sugar_tmp > limit) {
                                break;
                            } else {
                                double density_tmp = 100.0 * (double)sugar_tmp / (double)total_tmp;
                                if(density_tmp > density) {
                                    density = density_tmp;
                                    total = total_tmp;
                                    sugar = sugar_tmp;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    cout << total << " " << sugar << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int MAX = 10000;
const int NIL = -1;

typedef struct binaryTree{
	int parent, left, right;
}bTree;

bTree T[MAX];
int n, D[MAX], H[MAX];

int setHeight(int u){
	int h1 = 0, h2 = 0;
	if(T[u].right != NIL) h1 = setHeight(T[u].right) + 1;
	if(T[u].left != NIL) h2 = setHeight(T[u].left ) + 1;
	return H[u] = max(h1, h2);
}                                                                                                         

void setDepth(int u, int d){
	if(u == NIL) return;
	D[u] = d;
	setDepth(T[u].left , d + 1);
	setDepth(T[u].right , d + 1);
}

int getSibling(int u){
	if(T[u].parent == NIL) return NIL;
	if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
	  return T[T[u].parent].left;
	if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
	  return T[T[u].parent].right;
	return NIL;
}

void print(int u){
	printf("node %d: ", u);
	printf("parent = %d, ", T[u].parent);
	printf("sibling = %d, ", getSibling(u));
	int deg = 0;
	if(T[u].left != NIL) deg++;
	if(T[u].right != NIL) deg++;
	printf("degree = %d, ", deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ", H[u]);
	
	if(T[u].parent == NIL){
		printf("root\n");
	}
	else if(T[u].left == NIL && T[u].right == NIL){
		printf("leaf\n");
	}
	else{
		printf("internal node\n");
	}
}

int main(){
	int v, l, r, root = 0;
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++) T[i].parent = NIL;
	
	for(int i = 0; i < n; i++){
		scanf("%d%d%d", &v, &l, &r);
		T[v].left = l;
		T[v].right = r;
		if(l != NIL) T[l].parent = v;
		if(r != NIL) T[r].parent = v;
	} 
	for(int i = 0; i < n; i++){
		if(T[i].parent == NIL) root = i;
	}
	
	setDepth(root, 0);
	setHeight(root);
	
	for(int i = 0; i < n; i++) print(i);
	
	return 0;
}


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

#define itn int
#define vi vector<int>
#define pb push_back
#define srt sort(v.begin(), v.end())
#define retunr return

//int infiint = std::numeric_limits<int>::max();
//float infiflt = std::numeric_limits<float>::infinity();


int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.txt", "rt", stdin);
	
	string s1, s2;
	cin >> s1 >> s2;
	int a, b;
	cin >> a >> b;
	string reject;
	cin >> reject;
	
	if(reject == s1)
		a--;
	else 
		b--;
		
	cout << a << " " << b;
	
	return 0;
}


Measured memory_bytes: 256