akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll INF = 1e18 + 1;

ll count(ll x, vector<ll> a, ll n) {
    ll ret = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] < 0) {
            int l = -1;
            int r = n;
            while (r - l > 1) {
                int mid = (l + r) / 2;
                if (a[mid] * a[i] < x) {
                    r = mid;
                } else {
                    l = mid;
                }
            }
            ret += n - r;
        } else {
            int l = -1;
            int r = n;
            while (r - l > 1) {
                int mid = (l + r) / 2;
                if (a[mid] * a[i] < x) {
                    l = mid;
                } else {
                    r = mid;
                }
            }
            ret += r;
        }
        if (a[i] * a[i] < x) {
            ret--;
        }
    }
    return ret / 2;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll lb = -INF;
    ll ub = INF;
    while (ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        if (count(mid, a, n) >= k) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    cout << lb << endl;
    return 0;
}


Measured memory_bytes: 3428
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<vector<ll>>> vvvll;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================





int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================

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

	cout << min(A, B) << " ";

	if (N >= A + B)
	{
		cout << 0;
	}
	else
	{
		cout << A+B-N;
	}



}





Measured memory_bytes: 256
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    ll n,k;
    ll h[100010];
    std::cin >> n>>k;
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }
    sort(h,h+n);
    ll result = 1e9;
    
    for (int i = 0; i + k -1 < n; i++) {
        result = min(result,h[i+k-1]-h[i]);
    }
    std::cout << result << std::endl;
    
}


Measured memory_bytes: 1024
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
import numpy as np

sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    N = I()
    A = LI()
    #  print(N, A)


    # 余りを活用する
    A = list(set(A))
    A.sort(reverse=True)
    if A[-1] == 0:
        del A[-1]
    #  print(A)
    while len(A) > 1:
        #  A[0] = A[0] % A[1]
        A = [a % A[idx+1] if idx < len(A) - 1 else a for idx, a in enumerate(A)]
        A = list(set(A))
        A.sort(reverse=True)
        if A[-1] == 0:
            del A[-1]

        #  if A[0] == 0:
        #      del A[0]

    print(A[0])

main()


Measured memory_bytes: 24888
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int a,b,x;
  cin>>a>>b>>x;
  if(x + x == a*a*b){
    cout<<45.0<<endl;
  } else if(x+x<a*a*b){
    double tt = a* b * b/(x * 2.0);
    printf("%.10f\n", atan(tt)*180/acos(-1));
  } else {
    double tt = 2*(a*a*b-x)/(a*a*1.0)/a;
    printf("%.10f\n", atan(tt)*180/acos(-1));
  }
  return 0;
}

Measured memory_bytes: 256
D, G = [int(i) for i in input().split()]
G //= 100
p = []
c = []
ans = float("inf")
for _ in range(D):
    a, b = [int(i) for i in input().split()]
    p.append(a)
    c.append(b//100)
for i in range(2**D):
    g = G
    count = 0
    B = bin(i)[2:].zfill(D)
    for j, b in enumerate(B):
        if b == "1":
            g -= c[j]+p[j]*(j+1)
            count += p[j]
    i0 = B.rfind("0")
    if i0 >= 0:
        for _ in range(p[i0]):
            if g <= 0:
                break
            g -= i0+1
            count += 1
    if g <= 0:
        ans = min(count, ans)
print(ans)


Measured memory_bytes: 41328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()
 
const int mod = 1000000007;

int main(void) {
    ll n; cin >> n;
    vector<ll> a(n);

    rep(i, 0, n) cin >> a[i];
    
    vector<ll> g(60, 0);
    rep(i, 0, n) {
        rep(j, 0, 60) {
            if (a[i]>>j&1) g[j]++;
        }
    }

    ll ans = 0;
    rep(i, 0, 60) {
        ll tmp = (g[i] * (n - g[i])) % mod;
        tmp *= (1LL<<i) % mod;
        ans += tmp % mod;
        ans %= mod;
    }

    cout << ans << endl;
}


Measured memory_bytes: 2560
/*
* @Author: 王文宇
* @Date:   2018-04-14 20:14:58
* @Last Modified by:   王文宇
* @Last Modified time: 2018-04-14 20:18:03
*/
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200007;
#define _for(i,a,b) for(int i=a;i<=b;i++)
int n,a[maxn],b[maxn];
int main(int argc, char const *argv[])
{
	int l,r;
	cin>>n;
	_for(i,1,n)
	{
		cin>>a[i];
		b[i]=a[i];
	}
	sort(a+1,a+1+n);
	_for(i,1,n)
	{
		if(b[i]<=a[n/2])cout<<a[n/2+1]<<endl;
		else cout<<a[n/2]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
const int N = 105;
ll x[N];
int main(){
	ios::sync_with_stdio(false);
	ll n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x[i];
		ans+=x[i];	
	} 
	ll sum=0,summ=0;
	ans=ans/n;
	ll ans1=ans+1;
	for(int i=0;i<n;i++){
		sum+=(x[i]-ans)*(x[i]-ans);
		summ+=(x[i]-ans1)*(x[i]-ans1);
	}
	cout<<min(sum,summ)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>


using namespace std;


#define MAX 10000


int parent[MAX];
int rank[MAX];


int find(int x)
{
    int now = x;
    vector<int> children;
    while (parent[now] != now) {
        children.push_back(now);
        now = parent[now];
    }

    // path compression
    for (vector<int>::iterator it = children.begin(); it != children.end(); ++it)
        parent[*it] = now;

    return now;
}


void unite(int x, int y)
{
    int rx = find(x);
    int ry = find(y);

    if (rank[rx] > rank[ry]) {
        parent[ry] = rx;
    } else if (rank[rx] < rank[ry]) {
        parent[rx] = ry;
    } else {
        parent[ry] = rx;
        rank[rx]++;
    }
}


bool same(int x, int y)
{
    int rx = find(x);
    int ry = find(y);
    return rx == ry;
}


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

    for (int i = 0; i < n; i++) {
        parent[i] = i;
        rank[i] = 0;
    }

    for (int i = 0; i < q; i++) {
        int cmd, x, y;
        cin >> cmd >> x >> y;
        switch (cmd) {
            case 0:
                unite(x, y);
                break;
            case 1:
                if (same(x, y))
                    cout << 1 << endl;
                else
                    cout << 0 << endl;
                break;
        }
    }
}



Measured memory_bytes: 3232
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

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

def foo(x):
    b = []
    for i in range(n):
        b.append([y for y in a[i]])
    #ddprint(b)
    cnt = 0
    rem = [False]*m
    while cnt<m:
        #ddprint("in loop x {} cnt {} b, rem".format(x,cnt))
        #ddprint(b)
        #ddprint(rem)
        top = [0]*m
        ok = True
        for i in range(n):
            top[b[i][-1]] += 1
        for j in range(m):
            if top[j]>x:
                ok = False
                rem[j] = True
                cnt += 1
                if cnt==m:
                    return False
        if ok:
            return True
        for i in range(n):
            while len(b[i])>0 and rem[b[i][-1]]:
                b[i].pop()
    return True

n,m = inm()
a = []
for i in range(n):
    aa = inl()
    aa = [x-1 for x in aa]
    aa.reverse()
    a.append(aa)

ddprint(a)
mx = n
mn = 0
while mx>mn+1:
    mid = (mx+mn)//2
    if foo(mid):
        mx = mid
    else:
        mn = mid
print(mx)


Measured memory_bytes: 51548
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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 (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define mo 1000000007
ll comb(ll N_, ll C_) {
	const int NUM_ = 400001;
	static ll fact[400002], factr[400002], inv[400002];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%mo, factr[i] = factr[i - 1] * inv[i] % mo;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % mo*factr[N_ - C_] % mo;
}
ll modpow(ll a, ll n = mo - 2) {
	ll r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % mo, a = a * a%mo, n >>= 1;
	return r;
}

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

	int N, K;
	cin >> N >> K;
	VI A(N);
	REP(i, N)cin >> A[i];
	SORT(A);
	int ans = 0;

	if (K == 1) {
		cout << 0 << endl;
		return 0;
	}
	int ma = 0, mi = 0;
	FOR(i, 1, N) {
		int cnt = comb(i, K - 1);
		ma += A[i] * cnt;
		mi += A[N - 1 - i] * cnt;
		ma %= mod;
		mi %= mod;
	}
	cout << ((ma + mod) - mi) % mod << endl;

	return 0;
}



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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    ll a, b, c;
    cin >> a >> b >> c;
    if (a + b >= c) {
        cout << "No" << endl;
        return 0;
    }

    ll x = a * b * 4;
    ll y = c - (a + b);
    y *= y;

    if (x < y) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
MOD = 2019

l, r = map(int, sys.stdin.readline().split())
r = min(r, l + MOD - 1)

def main():
    res = MOD - 1
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            res = min(res, (i % MOD) * (j % MOD) % MOD)
    print(res)

if __name__ ==  '__main__':
    main()

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

int main() {
    int n;
    cin >> n;
    int a[n+1]={};

    for(int i=1;i<n+1;i++){
        cin >> a[i];
    }

    int num = a[1];
    int count = 1;

    for(int k=1;k<n+1;k++){
        if(num==2) break;
        count++;
        if(a[num]==2) break;
        else num = a[num];
    } 

    if (count>=n) cout << -1 << endl;
    else cout << count << endl;
}




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

int main(){
	string s;
	cin >> s;
	while (cin){
		int a = 0, b = 0;
		for (int i = 0; i < 3; ++i){
			if (s[i] == 'A') ++a;
			else ++b;
		}
		if (a == 0 || a == 3) cout << "No\n";
		else cout << "Yes\n";
		cin >> s;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
inline int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int k=1,kk=0;if (c=='-')c=getchar(),k=-1;
	while (c>='0'&&c<='9')kk=kk*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(int x){if (x)write(x/10),putchar(x%10+'0');}
void writeln(int x){if (x<0)putchar('-'),x=-x;write(x);if (x==0)putchar('0');puts("");}
int n,x,a[1000000],ans;
int main(){
	n=read();for (int i=1;i<=n;i++){
		x=read();if (x<=n)a[x]++;else ans++; 
	} for (int i=1;i<=n;i++)if (a[i]<i)ans+=a[i];else ans+=a[i]-i;
	cout<<ans<<endl;
}


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

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

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

n=int(input())
l=list(intinput())
ans=0
for i in l:
    ans=gcd(ans,i)
print(ans)

Measured memory_bytes: 14172
import java.util.Scanner;

public class Main {
	public static final int[] dx = {-1,0,1,0};
	public static final int[] dy = {0,1,0,-1};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if (n == 0) {
				return;
			}
			int[] x = new int[n];
			int[] y = new int[n];
			for(int i=0;i<n-1;i++) {
				int a = sc.nextInt();
				int d = sc.nextInt();
				x[i+1] = x[a] + dx[d];
				y[i+1] = y[a] + dy[d];
			}
			int x1 = Integer.MAX_VALUE;
			int y1 = Integer.MAX_VALUE;
			int x2 = Integer.MIN_VALUE;
			int y2 = Integer.MIN_VALUE;
			for(int i=0;i<n;i++) {
				x1 = Math.min(x1, x[i]);
				y1 = Math.min(y1, y[i]);
				x2 = Math.max(x2, x[i]);
				y2 = Math.max(y2, y[i]);
			}
			System.out.println((x2-x1+1) + " " + (y2-y1+1));
		}
	}

}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m, a[300][300], q[300], c[300];

int main() {
	cin >> n >> m;
	inc(i, n) {
	inc(j, m) {
		int x;
		cin >> x;
		x--;
		a[i][x] = j;
	}
	}
	
	int ans = n;
	inc(k, m) {
		inc(j, m) { c[j] = 0; }
		
		inc(i, n) {
			int p = -1, mi = m;
			inc(j, m) {
				if(q[j] == 0 && setmin(mi, a[i][j])) { p = j; }
			}
			c[p]++;
		}
		
		int ma = 0, p = -1;
		inc(j, m) { if(setmax(ma, c[j])) { p = j; } }
		setmin(ans, ma);
		q[p] = -1;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int a,b,k;
    scanf("%d%d",&a,&b);
    k=b+a;
    if(k%2==0)
    {
        printf("%d\n",k/2);
    }
    else
    {
        printf("IMPOSSIBLE\n");
    }
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var A, B int
	fmt.Scan(&A, &B)
	check := map[int]bool{
		1: false,
		2: false,
		3: false,
	}
	check[A] = true
	check[B] = true
	for k, v := range check {
		if !v {
			fmt.Println(k)
			return
		}
	}
}


Measured memory_bytes: 512
import java.util.Scanner;

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

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int d = 0;
		if (N == 0) {
			System.out.println("0");
			return;
		}

		for (int i = 0; i < 7; i++) {
			d = (int) Math.pow(2, i);
			if (N / d == 1) {
				break;
			}
		}
		System.out.println(d);
	}
}


Measured memory_bytes: 23124
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			while (sc.hasNext()) {
				int n = sc.nextInt();
				System.out.println(solve(n));
			}
		}
	}

	public static int solve(int n) {
		if (n < 2) {
			return 0;
		}
		boolean[] result = new boolean[n];
		Arrays.fill(result, true);
		result[0] = false;
		for (int i = 1; i < ((int)Math.sqrt(n)) + 1; i++) {
			if (result[i]) {
				for (int j = ((int)Math.pow(i + 1, 2)) - 1; j < n; j += (i + 1)) {
					result[j] = false;
				}
			}
		}
		
		int count = 0;
		for (boolean b : result) {
			count += (b) ? 1 : 0;
		}
		return  count;
	}
}

Measured memory_bytes: 41732
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int q;
	while(1){
		cin>>q;
		if(q==-1) break;
		double x=(double)q/2;
		while(1){
			x=x-(double)(x*x*x-q)/(3*x*x);
			if(abs(x*x*x-q)<1e-5*q) break;
		}
		printf("%.7lf\n",x);
	}
}

Measured memory_bytes: 1192
#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
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

#define INF 200
int main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    int flag = 0;
    for(int k = 1; k <= INF; k++) {
        if((a*k)%b == c) {flag = 1; break; }
    }
    cout << (flag ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 3632
#<14>
#(point)
#全探索によってどの建物が見えるようにするかを決めて必要な費用を計算。
#建物が見える =　それより左にある建物maxより１大きいなので左から線形に
#最大値を更新、計算量は高々n_c_kのcombについてO(N)の操作なのでおｋ
from itertools import combinations
n, k = map(int,input().split())
a = list(map(int,input().split()))
mn = 10 ** 18

for b in combinations(range(1, n),k - 1):#一番左は固定
    mx = a[0] #初期値=一番左の建物
    score = 0
    for j in range(1, n):
        if j in b:#見えなあかん建物なら
            if a[j] <= mx : #低けりゃ高くする
                mx += 1
                score += (mx - a[j])
            else: #高さが十分なら最大値を更新するだけ
                mx = a[j]
        else:
            mx = max(mx, a[j])#別に見えんくてもいい建物なら最大値更新
    mn = min(mn, score)
print(mn)
                


Measured memory_bytes: 9044
import java.util.*;

public class Main {
	public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
        	a[i] = sc.nextInt();
        }
        int[] b = new int[9];
        for(int i = 0; i < n; i++) {
        	if(a[i] < 400) {
        		b[0]++;
        	} else if(a[i] < 800) {
        		b[1]++;
        	} else if(a[i] < 1200) {
        		b[2]++;
        	} else if(a[i] < 1600) {
        		b[3]++;
        	} else if(a[i] < 2000) {
        		b[4]++;
        	} else if(a[i] < 2400) {
        		b[5]++;
        	} else if(a[i] < 2800) {
        		b[6]++;
        	} else if(a[i] < 3200) {
        		b[7]++;
        	} else {
        		b[8]++;
        	}
        }
        int cout = 0;
        for(int i = 0; i < 8; i++) {
        	if(b[i] > 0) {
        		cout++;
        	}
        }
        System.out.print(Math.max(1, cout) + " ");
        System.out.println(cout + b[8]);
    }
}

Measured memory_bytes: 21716
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
typedef pair<ll, ll > P;
const int MOD = 1000000007;


int main() {
	ll i, j, k, l, m, n, sum, flag, cc, M, X, H, W, N,Y,Z,K;
	cc = 0;
	flag = 0;
	char S[100009];
	cin >> S;
	m = n = 0;
	REP(i, 0, strlen(S)) {
		if (i % 2 == 0) {
			if (S[i] == '0') {
				m++;
			}
		}
		else {
			if (S[i] == '1')
				m++;
		}
	}
	REP(i, 0, strlen(S)) {
		if (i % 2 == 0) {
			if (S[i] == '1') {
				n++;
			}
		}
		else {
			if (S[i] == '0')
				n++;
		}
	}

	output(fmin(m, n));
	return 0;
}





Measured memory_bytes: 384
#include <iostream>
#include <queue>
#define int long long

using namespace std;

signed main() {
	int k;
	cin >> k;
	
	queue<int> q;
	for (int i = 1; i <= 9; i++) q.push(i);
	while (!q.empty()) {
		int x = q.front(); q.pop(); k--;
		if (k == 0) {
			cout << x << '\n';
			break;
		}
		
		for (int y = (x % 10) - 1; y <= (x % 10) + 1; y++) {
			if (y < 0 || y > 9) continue;
			q.push(x * 10 + y);
		}
	}
	
	return 0;
}
//hello

Measured memory_bytes: 5084
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
	int n, i, j;
	n = 0;
	cin >> n;

	int a[n + 1];
	int b[n];

	for (i = 0; i < n + 1; i++) {
		cin >> a[i];
	}

	for (i = 0; i < n; i++) {
		cin >> b[i];
	}

	mp::cpp_int sum = 0;
	for (i = 0; i < n; i++) {
		if (b[i] >= a[i]) {
			b[i] = b[i] - a[i];
			sum += a[i];
			a[i] = 0;
		} else {
			a[i] = a[i] - b[i];
			sum += b[i];
			b[i] = 0;
		}

		if (b[i] >= a[i + 1]) {
			b[i] = b[i] - a[i + 1];
			sum += a[i + 1];
			a[i + 1] = 0;
		} else {
			a[i + 1] = a[i + 1] - b[i];
			sum += b[i];
			b[i] = 0;
		}
	}

	cout << sum;
	return 0;
}
  

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{ 
    string s;
    cin>>s;
    ll n=s.length();
    cout<<string(n,'x')<<"\n"; 
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

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

typedef long long int ll;
typedef long double ld;

#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define rep1(i, n)    for(ll i = 1; i <= (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define bpc(a) __builtin_popcount(a)
#define ff first 
#define ss second  
#define mk0(a) memset(a,0,sizeof(a))
#define mk_1(a) memset(a,-1,sizeof(a))

const ll MAX=1e5+2;
const ll MAX1=1e2+5;
const ll INF=1e15+2;
const ll MOD=1e9+7;

#define pb push_back
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi pair<ll,ll>
#define map1 unordered_map

inline ll nc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}

inline ll read(){ll ret=0;bool f=0;char ch=nc();while(ch>'9'|| ch<'0') f^=ch=='-',ch=nc();
while(ch<='9'&& ch>='0') ret=ret*10+ch-'0',ch=nc();return f?-ret:ret;}

ll power(ll base,ll ind,ll mod){ll res=1;while(ind){if(ind&1)res=(res*base)%mod;base=(base*base)%mod;ind>>=1;}return res;}

ll inv(ll den,ll mod){return power(den,mod-2,mod);}

ll dp[22][(1<<21)+2];
ll a[22][22],n;

ll calc(ll pos,ll mask)
{
    if(pos==n and mask == (1<<n)-1)
        return 1;
    if(pos==n)
        return 0;
    if(dp[pos][mask]>=0)
        return dp[pos][mask];
    ll &ans = dp[pos][mask];
    
    ans=0;
    for(int i=0;i<n;i++)
    {
        if(a[pos][i] and !(mask&(1<<i)))
        {
            ll newmask = mask | (1<<i);
            ans+=calc(pos+1,newmask);
            if(ans>=MOD)
                ans-=MOD;
        }
    }    
    return ans;
}

int main()
{
    faster;
    cin>>n;
    
    rep(i,n)
    {   
        rep(j,n)
            cin>>a[i][j];
    }
    mk_1(dp);
    cout<<calc(0,0)%MOD;
}

Measured memory_bytes: 360704
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    int N,L;
    cin>>N>>L;
    vector<string> all;
    string s;
    FOR(i, 0, N){
        cin>>s;
        all.push_back(s);
    }
    sort(all.begin(), all.end());
    FOR(i, 0, N){
        cout << all[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static int n;
    private static int A;
    private static int B;
    private static int C;
    private static int[] l;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }
        System.out.println(dfs(0, 0, 0, 0));
    }

    public static int dfs(int cur, int a, int b, int c) {
        if (cur == n) {
            if (a != 0 && b != 0 && c != 0) {
                return Math.abs(a - A) + Math.abs(b - B) + Math.abs(c - C);
            }
            return Integer.MAX_VALUE;
        }

        int ret = dfs(cur + 1, a, b, c);
        int retA = dfs(cur + 1, a + l[cur], b, c);
        if (a != 0 && retA != Integer.MAX_VALUE) {
            retA += 10;
        }
        int retB = dfs(cur + 1, a, b + l[cur], c);
        if (b != 0 && retB != Integer.MAX_VALUE) {
            retB += 10;
        }
        int retC = dfs(cur + 1, a, b, c + l[cur]);
        if (c != 0 && retC != Integer.MAX_VALUE) {
            retC += 10;
        }
        return Math.min(Math.min(ret, retA), Math.min(retB, retC));
    }

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    string s; cin >> s;
	int n = s.size();
	reverse(ALL(s));
	s+='0';
	int ans = 0;
	REP(i,n+1){
		int a = s[i] - '0';
		if(a > 5){
			ans += 10 - a;
			s[i+1]++;
		}
		else  if(a < 5){
			ans += a;
		}
		else{
			if(s[i+1] >= '5'){
				ans += a;
				s[i+1]++;
			}
			else{
				ans += a;
			}
		}
	}
	cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  int count = 0, ans = 0;
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    if (p == i + 1) {
      count++;
    }
    else {
      ans += count/2 + count%2;
      count = 0;
    }
  }
  ans += count/2 + count%2;
  cout << ans << endl;
}

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

int main() {
  int d;
  cin >> d;
  ll ans = 0;
  vector<int> open(26, -1);
  vector<ll> c(26);
  vector<vector<ll>> score(d, vector<ll>(26));
  rep(i, 26){
    cin >> c[i];
  }
  rep(i, d){
    rep(j,26){
      cin >> score[i][j];
    }
  }
  rep(i, d){
    int tmp;
    cin >> tmp;
    tmp--;
    ans += score[i][tmp];
    open[tmp] = -1;
    rep(i, 26){
      if(i != tmp){
        open[i]++;
        ans -= c[i] * (open[i] + 1);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3688
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

vector<ll> height;
vector<ll> patty;

ll rec(ll N, ll X)
{

	//レベルLハンバーガーを
	//パン|レベル(N - 1)|パティ|レベル(N - 1)|パン
	//に分けて考える。

	//メモで計算再利用
	if (X >= height[N]) return patty[N];

	//0枚以下->食べられない
	//1枚　　->パン
	if (X <= 1) return 0;
	X--;

	ll ret = 0;

	//下半分のレベル(N - 1)
	ret += rec(N - 1, X);

	X -= height[N - 1];

	//真ん中のパティ
	if (X > 0)
	{
		ret++;
		X--;
	}

	//上半分のレベル(N - 1)
	ret += rec(N - 1, X);

	return ret;
}

int main()
{	
	ll N, X;
	cin >> N >> X;

	//各レベルごとに枚数を計算
	height.resize(N + 1);
	height[0] = 1;

	rep(i, N)
	{
		height[i + 1] = 2 * height[i] + 3;
	}

	patty.resize(N + 1);
	patty[0] = 1;

	rep(i, N)
	{
		patty[i + 1] = 2 * patty[i] + 1;
	}

	cout << rec(N, X) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

int main()
{
    int n, k, a[1000009];
    while(~scanf("%d %d", &n ,&k))
    {
        memset(a, 0, sizeof(a));
        int num, l = 999999, r = 0;
        for(int i = 1; i <= n; i++)
        {
            scanf("%d", &num);
            a[num]++;
            l = min(l, num);
            r = max(r, num);
        }
        if(r - l + 1 <= k)
            printf("0\n");
        else
        {
            sort(a+l, a+r+1);
            int ans = 0;
            while(r - l + 1 > k)
                ans += a[l++];
            printf("%d\n", ans);
        }
    }
    return 0;
}


Measured memory_bytes: 4096
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sum=0;
    for (int i=0;i<5;++i){
        int x; cin >> x;
        sum+=x;
    }
    cout << 15-sum << '\n';
}

Measured memory_bytes: 3628
n = int(input())
A,B = [],[]
for i in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    
A,B = A[::-1],B[::-1]

num = 0
for i in range(n):
    A[i] +=num
    if A[i]%B[i] !=0:
        num = num + B[i] - A[i]%B[i]
        #print(num,B[i], B[i] - A[i]%B[i])
print(num)

Measured memory_bytes: 21688
//
//  main.cpp
//  c++proj
//
//  Created by chiiia12 on 2016/04/18.
//
//

#include <iostream>
#include <vector>
using namespace std;

int cnt;
vector<int> G;

void insertionSort(int* a,int g,int n){
    for(int i = g-1;i<n;i++){
        int j = i;
        while(j-g>=0&&a[j-g]>a[j]){
            int tmp = a[j];
            a[j] = a[j-g];
            a[j-g] = tmp;
            j=j-g;
            cnt++;
        }
    }
}
void selectionSort(int* a,int n){
    cnt = 0;
    for(int h =1;;){
        if(h>n)break;
        G.push_back(h);
        h=3*h+1;
    }
    for(int i = G.size()-1;i>=0;i--){
        insertionSort(a,G[i],n);
    }
}

int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i =0;i<n;i++){
        cin>>a[i];
    }
    selectionSort(a,n);
    cout<<G.size()<<endl;
    for(int i = G.size()-1;i>0;i--){
        cout<<G[i]<<" ";
    }
    cout<<G[0]<<endl;
    cout<<cnt<<endl;
    for(int i = 0;i<n;i++){
        cout<<a[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 5120
nmc = list(map(int, input().split()))
n = nmc[0]
m = nmc[1]
c = nmc[2]
b = list(map(int, input().split()))
cnt = 0
for i in range(n):
    ans = c
    a = list(map(int, input().split()))
    for j in range(m):
        ans += a[j] * b[j]
    if ans > 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
void swap(int *a,int *b){int tmp;tmp=*a;*a=*b;*b=tmp;}

int main(void){
    long long x,ans=100000;
    scanf("%lld",&x);
    while(x>=100){
        ans=ans<llabs(753-x%1000)?ans:llabs(753-x%1000);
        x/=10;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(vector<T> &x) {
	int n = x.size();
	rep(i,n) {
		cout << x[i];
		if (i!=n-1) cout<<" ";
		else cout << endl;
	}
}

template<typename T>
void print(vector<vector<T>> &x) {
	int n = x.size();
	rep(i,n) {
		rep(j,x[i].size()) {
			cout << x[i][j] << " ";
		}
		cout << endl;
	}
}

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

struct Info {
	ll ins, inb, outs,outb;
	Info(){}
	Info(ll ins, ll inb, ll outs, ll outb): ins(ins),inb(inb),outs(outs),outb(outb){}
};


int main(int argc, char const *argv[]) {
	ll n; cin>>n;
	vector<ll> a(n);
	rep(i,n) cin>>a[i];
	reverse(a.begin(), a.end());
	vector<Info> dp(n+1);

	auto fail= [](){
		cout << -1 << endl;
		exit(0);
	};

	if (a[0]!=2) fail();

	dp[0] = Info(2,3,2,2);

	for (int i = 1; i < n; ++i) {
		if (a[i] > dp[i-1].inb) fail();
		ll s = (dp[i-1].ins+a[i]-1)/a[i]; s*=a[i];
		ll b = dp[i-1].inb/a[i]; b*=a[i];
		if (s > b) swap(s,b);
		if (s < dp[i-1].ins && dp[i-1].inb < b) fail();
		dp[i] = Info(s,b+a[i]-1,s,b);
		// printf("i = %d, input_smaller = %lld, input_larger = %lld, output_smaller = %lld, output_larger = %lld\n",i,dp[i].ins,dp[i].inb,dp[i].outs,dp[i].outb);
	}
	
	cout << dp[n-1].ins << " " << dp[n-1].inb << endl;
	return 0;
}

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

int main() {
  int N;
  int t[110000], x[110000], y[110000];
  cin >> N;
  t[0] = x[0] = y[0] = 0;
  for (int i=0; i < N; i++) {
    cin >> t[i+1] >> x[i+1] >> y[i+1];
  }
  
  bool can = true;
  for(int i = 0; i < N; i++) {
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if (dt < dist) {
      can = false;
      break;
    }
    if (dt % 2 != dist %2) {
      can = false;
      break;
    }
  }
  if (can) {
    cout << "Yes" << endl;
  } else {
	cout << "No" << endl;
  }
}

Measured memory_bytes: 1408
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
			PrintWriter out=new PrintWriter(System.out);
	FastScanner fs=new FastScanner();
		long a=fs.nextLong();
		double b=fs.nextDouble();
		
	 BigDecimal bg1 = BigDecimal.valueOf(a);
            BigDecimal bg2 = BigDecimal.valueOf(b);
            out.println(bg1.multiply(bg2).setScale(0, RoundingMode.DOWN));
		out.close();
		
	
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble(){
		    return Double.parseDouble(next());
		}
}
}


Measured memory_bytes: 25800
#include <stdio.h>
int main() {
	int i;
	int N, odd = 0;
	scanf("%d", &N);

	for (i = 1; i <= N; i++) {
		if (i % 2 == 1) {
			odd++;
		}
	}
	printf("%lf", (double)odd / (double)N);

	return 0;
}

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

using namespace std;

int main()
{
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k - 1];
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int a;
	int b;
	int n=0;
	int m = 0;
	scanf("%d", &a);
	if (a < 3) {
		m = 1;
	}
	for (b = 1; b < 350; b++) {
		if (m == 1) { break; }
		a = a - 3;
		n++;
		if (a < 3) {
			break;
		}
	}
	printf("%d", n);
	return 0;
}

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

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

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int n = in();
  int weis[n];
  REP(i,n) {
    cin >> weis[i];
  }
  vector<int> left_v(n), right_v(n);
  REP(i,n) {
    left_v[i] = i - weis[i];
    right_v[i] = i + weis[i];
  }
  SORT(left_v); SORT(right_v);
  int ans = 0;
  REP(i,n) {
    int right = right_v[i];
    auto itr = lower_bound(ALL(left_v), right);
    if(itr == left_v.end()) continue;
    auto itr2 = upper_bound(itr, left_v.end(), right);
    int counter = distance(itr, itr2);
    // int index = itr - left_v.begin();
    // int counter = 0;
    // REPS(j, index, n) {
    //   if(left_v[j] != right) break;
    //   ++counter;
    // }
    ans += counter;
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 7956
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define INF (1LL << 60)
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2199&lang=jp

#define ll long long

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N, M;
	while (cin >> N >> M) {
		if (N == 0 && M == 0) break;
		// dp[i][j] := i??????????????????,?????????j?????????????????????????°????
		vector<vector<ll>> dp(N + 1, vector<ll>(256, INF));
		vector<int> C(M + 1);
		for (int i = 0; i < M;i++) cin >> C[i];
		vector<int> x(N + 1);
		for (int i = 0;i < N;i++) cin >> x[i];

		//????????¶???
		dp[0][128] = 0;

		for (int i = 0; i < N;i++) {
			for (int j = 0; j <= 255;j++) {
				if (dp[i][j] == INF) continue;
				for (int k = 0; k < M;k++) {
					int J = max(0, min(255, j + C[k]));
					int cost = pow(x[i] - J, 2);
					dp[i + 1][J] = min(dp[i + 1][J], dp[i][j] + cost);
				}
			}
		}

		ll ans = INF;
		for (int j = 0; j <= 255;j++) {
			//if (dp[N][j] != INF) cout << dp[N][j] << endl;
			ans = min(ans, dp[N][j]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 43760