akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,m;
    cin>>n>>m;
    bool br[n+1];
    fill(br,br+(n+1),false);
    for(int i=0;i<m;i++){
        int a;
        cin>>a;
        br[a]=true;
    }
    int dp[n+1];
    dp[0]=1;
    for(int i=1;i<=n;i++){
        if(br[i]){
            dp[i]=0;
        }else{
            if(i==1){
                dp[i]=dp[i-1];
            }else{
                dp[i]=(dp[i-1]+dp[i-2])%MOD;
            }
        }
    }
    cout<<dp[n]<<endl;
}


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

long long k, a[100010], lo, hi, mid, l, r;

long long f(long long n) {
	for (int i = 0; i < k; i++)
		n = (n / a[i]) * a[i];
	return n;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> k;
	for (int i = 0; i < k; i++)
		cin >> a[i];
	lo = 0;
	hi = 1e18;
	while (lo < hi) {
		mid = (lo + hi)/2;
		if (f(mid) < 2)
			lo = mid + 1;
		else
			hi = mid;
	}
	l = lo;
	lo = 0;
	hi = 1e18;
	while (lo < hi) {
		mid = (lo + hi + 1)/2;
		if (f(mid) <= 2)
			lo = mid;
		else
			hi = mid - 1;
	}
	r = lo;
	if (l > r)
		cout << -1;
	else
		cout << l << " " << r;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=2e5+5;
const int M=4;
int a[N];
ll dp[N][M]; 
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<M;j++){
			dp[i][j]=-1e17;
		}
	}
	if(n==2){
		printf("%d",max(a[1],a[2]));
		return 0;
	}
	if(n&1){
		dp[1][2]=a[1];
		dp[2][1]=a[2];
		dp[3][0]=a[3];
		for(int i=3;i<=n;i++){
			dp[i][0]=max(dp[i][0],dp[i-2][0]+a[i]);
			if(i>3)
			dp[i][0]=max(dp[i][0],dp[i-3][1]+a[i]);
			if(i>4)
			dp[i][0]=max(dp[i][0],dp[i-4][2]+a[i]);
			
			dp[i][1]=max(dp[i][1],dp[i-2][1]+a[i]);
			if(i>3)
			dp[i][1]=max(dp[i][1],dp[i-3][2]+a[i]);
			
			dp[i][2]=max(dp[i][2],dp[i-2][2]+a[i]);
			
		}
		printf("%lld",max(max(dp[n][0],dp[n-1][1]),dp[n-2][2]));
	}
	else{
		dp[1][1]=a[1];
		dp[2][0]=a[2];
		for(int i=3;i<=n;i++){
			dp[i][0]=max(dp[i][0],dp[i-2][0]+a[i]);
			if(i>3)
			dp[i][0]=max(dp[i][0],dp[i-3][1]+a[i]);
			dp[i][1]=max(dp[i][1],dp[i-2][1]+a[i]);
		}
		printf("%lld",max(dp[n][0],dp[n-1][1]));
	} 
}


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

using namespace std;

#define mod1 1000000007
#define mod2 998244353
#define int long long int
#define pii pair<int,int>
#define vpii vector<pii>
#define vi vector<int>
#define fi first
#define se second
#define psb push_back
#define ppb pop_back
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define all(x) x.begin(),x.end()
// #define endl "\n"

const int xn=1;
const int maxn=xn*1e3+5;
int ar[maxn];
vpii ans;

void solve()
{
	int n;
	cin>>n;
	cout<<(1000-n%1000)%1000<<endl;
}	

int32_t main()
{
	fio;
	int t;
	// cin>>t;
	t=1;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3636
import sys
from collections import defaultdict
from heapq import heappop,heappush
MA = 1000000
def v(y,x,d):
    if (x == 0 and d) or (x == w-1 and not d):
        return []
    k = 1-2*d
    l = [(i,x+k) for i in range(max(0,y-2),min(h,y+3))]
    if (x == 1 and d) or (x == w-2 and not d):
        return l
    for i in range(max(0,y-1),min(h,y+2)):
        l.append((i,x+2*k))
    if (x == 2 and d) or (x == w-3 and not d):
        return l
    l.append((y,x+3*k))
    return l

def dijkstra(start,goal):
    d = defaultdict(lambda : MA)
    q = []
    for y,x in start:
        for i in range(2):
            d[(y,x,i)] = 0
            heappush(q,(0,y,x,i))

    while q:
        dp,y,x,di = heappop(q)
        e = v(y,x,di)
        di ^= 1
        for y_,x_ in e:
            if s[y_][x_] == "X":continue
            cost = 0 if s[y_][x_] == "S" or s[y_][x_] == "T" else s[y_][x_]
            if dp+cost < d[(y_,x_,di)]: #昨日はずっとここでd[(y_,x_)]と比較してた。頭が悪い
                d[(y_,x_,di)] = dp+cost
                heappush(q,(d[(y_,x_,di)],y_,x_,di))

    res = MA
    for y,x in goal:
        for i in range(2):
            if d[(y,x,i)] < res:
                res = d[(y,x,i)]
    res = res if res < MA else -1
    return res

def solve(w,h,s):
    start = []
    goal = []
    for y in range(h):
        for x in range(w):
            if s[y][x].isdecimal():
                s[y][x] = int(s[y][x])
            elif s[y][x] == "S":
                start.append((y,x))
            elif s[y][x] == "T":
                goal.append((y,x))
    print(dijkstra(start,goal))

while 1:
    w,h = map(int, sys.stdin.readline().split())
    if w == 0:
        break
    s = [sys.stdin.readline().split() for i in range(h)]
    solve(w,h,s)



Measured memory_bytes: 6508
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }
signed main() {
	int a, b, c; cin >> a >> b >> c;
	if (a + b == c || a + c == b || b + c == a)cout << "Yes" << endl;
	else cout << "No" << endl;
	system("pause");
}

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

int main() {
  int H,W;
  cin >> H >> W;
  int outH = H + 2;
  int outW = W + 2;
  for (int i = 0; i < outH; i++) {
    for (int j = 0; j < outW; j++) {
      if (i == 0 || i == outH - 1 || j == 0 || j == outW - 1) {
        cout << "#";
      } else {
        char c;
        cin >> c;
        cout << c;
      }
    }
    cout << endl;
  }
  
}


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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

int dx4[] = {1, -1, 0, 0};
int dy4[] = {0, 0, 1, -1};
int dx8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy8[] = {1, -1, 0, 0, 1, -1, -1, 1};

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<bool>> d(N+1, vector<bool>(N+1));
    rep(i, M) {
        int n, m;
        cin >> n >> m;
        d[n][m] = d[m][n] = true;
    }
    int a[N];
    rep(i, N) a[i] = i+1;
    ll ans = 0;
    do {
        if (a[0] != 1) continue;
        bool f = true;
        rep(i, N-1) {
            f = f && d[a[i]][a[i+1]];
        }
        if(f) ++ans;
    } while (next_permutation(a, a + N));

    cout << ans << nl;
}


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

bool isSquare(int num)
{
  int r = (int)floor(sqrt((double)num));
  return (r * r) == num;
}

int main()
{
  int N, D;
  cin >> N >> D;
  vector<vector<int> > points;
  for (int i = 0; i < N; i++)
  {
    vector<int> point;
    for (int j = 0; j < D; j++)
    {
      int tmp;
      cin >> tmp;
      point.push_back(tmp);
    }
    points.push_back(point);
  }

  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = i+1; j < N; j++)
    {
      int sum = 0;
      for (int k = 0; k < D; k++)
      {
        sum += (points[i][k] - points[j][k]) * (points[i][k] - points[j][k]);
      }

      if (isSquare(sum)){
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main()
{
    int k,s;
    cin>>k>>s;
    int count=0;
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<=k;j++)
        {
            if(s-i-j>=0&&s-i-j<=k)
            {
                count++;
            }
        }
    }

    cout<<count<<endl;

    return 0;
}

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


int main(){
	int a=0;
    string s;
    cin >> s;
    for(int i=0;i<4;i++){
        if(s[i] == '+') a++;
        else a--;
    }
    cout << a << endl;
	
	return 0;
}


Measured memory_bytes: 256
#define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 1001
#define _MAX 100
#define HO 6
int main(void)
{
	char str[MAX];
	string word[_MAX];
	int pa[_MAX], rank[_MAX], cou, a;
	for (cou = 0; scanf_s("%s %d", str, &pa[cou]) != EOF;++cou) {
		string wo(str);
		word[cou] = wo;
		rank[cou] = cou;
	}
	for (int i = 0; i < cou; ++i) {
		for (int j = cou - 1; j > i; --j) {
			if (word[rank[j]] <= word[rank[j - 1]]) {
				if (word[rank[j]] == word[rank[j - 1]]) {
					if (pa[rank[j]] < pa[rank[j - 1]]) {
						a = rank[j]; rank[j] = rank[j - 1]; rank[j - 1] = a;
					}
				}
				else {
					a = rank[j]; rank[j] = rank[j - 1]; rank[j - 1] = a;
				}
			}
		}
	}
	for (int i = 0; i < cou; ++i) {
		if(i == 0 || word[rank[i - 1]] != word[rank[i]]) 
		cout << word[rank[i]] << "\n";
		if (i != 0 && word[rank[i - 1]] == word[rank[i]])
			printf(" ");
		printf("%d", pa[rank[i]]);
		if (i != cou - 1 && word[rank[i + 1]] != word[rank[i]])
			printf("\n");
	}
	printf("\n");
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
int a[250],b[250];
ll dp[(1<<15)];
int cnt[(1<<15)];
ll bin[255];
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i];
		a[i]--; b[i]--;
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<m;j++){
			if( ((i>>a[j])&1)+((i>>b[j])&1) == 2 ) cnt[i]++;
		}
	}
	bin[0] = 1;
	for(int i=1;i<255;i++) bin[i] = bin[i-1]*2LL%mod;
	for(int i=0;i<(1<<n);i++){
		int z = (((i>>0)&1));
		int o = (((i>>1)&1));
		if(z == o) continue;
		dp[i] = bin[cnt[i]];
		int j = i;
		while(j){
			j = (j-1)&i;
			if( ((j>>0)&1)+((j>>1)&1) == 1){
				dp[i] -= dp[j] * bin[cnt[i-j]] % mod;
			}
		}
		dp[i] = (dp[i]%mod+mod)%mod;
	}
	ll ans = 0;
	for(int mask=0;mask<(1<<n);mask++){
		if(((mask>>0)&1) == 0) continue;
		if(((mask>>1)&1) == 1) continue;
		int zan = (1<<n)-1-mask;
		while(1){
			if(((zan>>1)&1)){
				if(cnt[mask]+cnt[zan] == cnt[mask+zan]){
					ans += dp[mask]*dp[zan]%mod*bin[cnt[(1<<n)-1-mask-zan]]%mod;
					ans %= mod;
				}
			}
			if(zan == 0) break;
			zan = (zan-1)&((1<<n)-1-mask);
		}
	}
	cout << (bin[m]-ans+mod)%mod << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;

using namespace std;
const int N = 200001;

int main(){
  ll n, t;
  ll ts[N];
  cin >> n >> t;
  for (int i=0; i<n; i++) {
    scanf("%lld", &ts[i]);
  }
  ll sum = t;
  for (int i=1; i<n; i++) {
    sum += min(ts[i]-ts[i-1],t);
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)

using namespace std;

int main(void) {
  long H, W;
  cin >> H >> W;
  bool map[50][50];
  long white_count = 0;
  for (long h = 0; h < H; h++) {
    string tmp;
    cin >> tmp;
    for (long w = 0; w < W; w++) {
      map[h][w] = tmp[w] == '.';
      if (tmp[w] == '.') white_count ++;
    }
  }
  queue<pair<long, long>> q;
  long result[50][50] = {0};
  q.push(pair<long, long>(0, 0));
  while (q.size() > 0) {
    pair<long, long> current = q.front();
    q.pop();
    long current_step = result[current.first][current.second];
    if (current.first == H - 1 and current.second == W - 1) {
      cout << (white_count - current_step - 1) << endl;
      return 0;
    }
    for (long dh = -1; dh <= 1; dh++) for (long dw = -1; dw <= 1; dw++) {
      if (dh * dw != 0) continue;
      long nh = current.first + dh;
      long nw = current.second + dw;
      if (nh < 0 or nh >= H or nw < 0 or nw >= W or (not map[nh][nw]) or result[nh][nw] != 0) continue;
      result[nh][nw] = current_step + 1;
      q.push(pair<long, long>(nh, nw));
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back

main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int arr[20];
	arr[0]=1;
	for(int i=1;i<20;i++)
		arr[i]=arr[i-1]*2;

	int n,k;
	cin>>n>>k;

	double ans=0;
	for(int i=1;i<=n;i++)
	{
		if(i>=k)
			ans+=1.0/n;
		else
		{
			for(int j=0;j<20;j++)
			{
				if(arr[j]*i>=k)
				{
					ans+=1.0/(n*arr[j]);
					break;
				}
			}
		}
	}
	cout<<fixed<<setprecision(12)<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
 
using namespace std;
typedef long long ll;
const ll INF = 1e18;

# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()
# define pb push_back
 
ll N, M;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> M;
    vector<ll> a(M);
    vector<ll> b(M);
    
    ll min = INF;
    rep(i, M) {
        cin >> a[i];
        a[i]--;
        cin >> b[i];
        b[i]--;
    }
    
    vector<ll> v(N);
    rep(i, M) {
        v[a[i]]++;
        v[b[i]]++;
    }
    
    rep(i, N) {
        cout << v[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int r, d, x;
    cin >> r >> d >> x;
    rep(i, 10)
    {
        x = r * x - d;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(null);
            long A = long.Parse(line[0]);
            long B = long.Parse(line[1]);
            long C = long.Parse(line[2]);
            long K = long.Parse(line[3]);

            if (K % 2 == 0) Console.WriteLine(A - B);
            else Console.WriteLine(B - A);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
using namespace std;
int a, b, c, d, dis, con;
double soled;
int ans1, ans2;

void solve(int w){
	int s = min(con - w, w / 100 * dis);
	for (int i = 0; i <= s; i += c){
		int rem = s - i;
		int dnum = rem / d;
		int suger = i + d * dnum;
		if ((double)suger / (double)(suger + w) > soled){
			soled = (double)suger / (double)(suger + w);
			ans1 = w + suger;
			ans2 = suger;
		}
	}
}
int main(){
	scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &dis, &con);
	for (int i = 0; i <= con; i += 100 * a)
		for (int j = 0; j + i <= con; j += 100 * b){
			if (i + j == 0) continue;
			solve(i + j);
		}
	printf("%d %d\n", ans1 == 0 ? 100 * a : ans1, ans2);
}


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-12;
const double inf = 1000000;


bool equals(double a, double b) {
  return abs(a-b) < eps;
}

double cross(P a, P b) {
  return a.real()*b.imag() - a.imag()*b.real();
}

double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}

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

vector<P> convex_cut(vector<P> ps, P p1, P p2, int dir = -1) {
  vector<P> v;
  for(int i = 0; i < ps.size(); ++i) {
    P a = ps[i];
    P b = ps[(i+1)%ps.size()];
    if(ccw(p1, p2, a) != dir) v.push_back(a);
    if(ccw(p1, p2, a)*ccw(p1, p2, b) == -1)
      v.push_back(getCrossP(a, b, p1, p2));
  }
  return v;
}

double getArea2(const vector<P> &g) {
  int n = g.size();
  double s = 0;
  for(int i = 0; i < n; ++i) {
    s += cross(g[i], g[(i+1)%n]);
  }
  return s;
}

int main() {
  int n;
  vector<P> base;
  base.push_back(P(-inf,-inf));
  base.push_back(P(inf,-inf));
  base.push_back(P(inf,inf));
  base.push_back(P(-inf,inf));
  while(cin >> n && n) {
    vector<P> ps(n);
    for(int i = 0; i < n; ++i) {
      cin >> ps[i].real() >> ps[i].imag();
    }
    double l, r;
    l = 0.0;
    r = inf;
    while(!equals(l, r)) {
      double d = (l+r)/2.0;
      vector<P> g = base;
      for(int i = 0; g.size() > 2 && i < n; ++i) {
	int s = i;
	int t = (i+1)%n;
	P v = ps[t] - ps[s];
	P u = P(-v.imag(), v.real());
	g = convex_cut(g, ps[s]+u*d/abs(u), ps[t]+u*d/abs(u));
      }
      if(g.size() == 0) {
	r = d;
      } else {
	l = d;
      }
    }
    printf("%.6f\n", l);
  }
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
#define lson (k<<1)
#define rson (k<<1)+1
const int mod = 1e9+7;
const int maxn = 1e5+6;
const double eps = 1e-6;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll read(){
    ll 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;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int a[maxn];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,1,n+1) scanf("%d",a+i);
	sort(a+1,a+n+1);
	a[0] = -inf;
	int l = a[n],mid=(a[n]+1)/2;
	int pos = upper_bound(a+1,a+n+1,mid)-a;
	int t = a[pos-1],tt = a[n] - a[pos];
	if(t>=tt) printf("%d %d",l,t);
	else printf("%d %d",l,a[pos]);
	return 0;
}


Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var n, k float64
	fmt.Scan(&n, &k)


	res := 0.0
	for i := float64(1);i<=n;i++ {

		v := i
		tmp := 1.0
		for v < k {
			v*=2
			tmp /= 2.0
		}

		res += tmp
	}

	fmt.Println(res/ n)
}


Measured memory_bytes: 1768
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    public class Prog
    {
        const int MOD = 1000000007;
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Prog().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            var a = cin.ReadLong - 1;
            var b = cin.ReadLong;
            var c = cin.ReadLong;
            var d = cin.ReadLong;

            var lcm = Lcm(c, d);

            var ans = (b - b / c - b / d + b / lcm);
            
            ans -= (a - a / c - a / d + a / lcm);

            Console.WriteLine(ans);
        }

        /// <summary>
        /// 最大公約数
        /// </summary>
        static long Gcd(long a, long b)
        {
            return (a < b) ? Gcd(b, a)
                 : (b > 0) ? Gcd(b, a % b)
                           : a;
        }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
    }
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } }
    }
}


Measured memory_bytes: 13268
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

ll n, a;
ld ans;

int main() {
    fast_io; cout_precision;
    cin >> n >> ans;
    for (ll i = 1; i < n; i++) {
        cin >> a;
        ans = (ans * a) / (ans + a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import itertools 
n,x = list(map(int,input().split()))
l = list(map(int,input().split()))
k = list(itertools.accumulate(l))
k.append(0)
k.sort()
ii = 0
for i in k:
    if(i<=x):
        ii+=1
        continue
    else:
        break
print(max(1,ii))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int line[3];
	for (int i = 0; i < 3; ++i) {
		cin >> line[i];
	}
	sort(line, line + 3);
	if (line[0] + line[1] == line[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int x, y;
	while (1)
	{
		scanf("%d %d", &x, &y);
		if (x == 0 && y == 0) break;
		if (x <= y) printf("%d %d\n", x, y);
		else printf("%d %d\n", y, x);

	}
	return 0;
}

Measured memory_bytes: 1028
import std;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, K;
    scan(N, K);
    auto C = new long[](K + 1);
    long ans;
    foreach_reverse (x; 1 .. K + 1)
    {
        C[x] = powmod(K / x, N, MOD);
        long i = 2;
        while (x * i <= K)
        {
            C[x] = (MOD - C[x * i] + C[x]) % MOD;
            i++;
        }
        ans = (ans + C[x] * x) % MOD;
    }
    writeln(ans);
}

/// x^^n % m
T powmod(T = long)(T x, T n, T m = 10 ^^ 9 + 7)
{
    if (n < 1)
        return 1;
    if (n & 1)
    {
        return x * powmod(x, n - 1, m) % m;
    }
    T tmp = powmod(x, n / 2, m);
    return tmp * tmp % m;
}


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

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

        try{
            //入力
            int N = scan.nextInt();
            int K = scan.nextInt();
            int[] h_ = new int[N];
            for(int i = 0; i < N; i++){
                h_[i] = scan.nextInt();
            }

            Arrays.sort(h_);

            int high = getTree(h_,N, K);

            System.out.println(high);

        }finally{
            scan.close();
        }
    }

    //飾り付ける木の高さの範囲を取得
    static int getTree(int[] h, int n, int k){
        int diff = h[k-1]-h[0];
        for(int i = 1; i < n-k+1; i++){
            int tmp = h[i+k-1]-h[i];
            if(tmp < diff){
                diff = tmp;
            }
        }
        return diff;
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

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

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  int a[5];
  while(~scanf("%d,%d,%d,%d,%d",a,a+1,a+2,a+3,a+4)){
    sort(a,a+5);
    if(a[1]==a[2] && a[2]==a[3] && (a[0]==a[1] || a[3]==a[4])){
      cout<<"four card"<<endl;
    }else if(a[0]==a[1] && a[3]==a[4] && (a[1]==a[2] || a[2]==a[3])){
      cout<<"full house"<<endl;
    }else if((a[0]+1==a[1] && a[1]+1==a[2] && a[2]+1==a[3] && a[3]+1==a[4]) ||
             (a[0]==1 && a[1]==10 && a[2]==11 && a[3]==12 && a[4]==13)){
      cout<<"straight"<<endl;
    }else if((a[0]==a[1] && a[1]==a[2]) || (a[1]==a[2] && a[2]==a[3]) || (a[2]==a[3] && a[3]==a[4])){
      cout<<"three card"<<endl;
    }else if((a[0]==a[1] && (a[2]==a[3] || a[3]==a[4]) || (a[1]==a[2] && a[3]==a[4]))){
      cout<<"two pair"<<endl;
    }else if(a[0]==a[1] || a[1]==a[2] || a[2]==a[3] || a[3]==a[4]){
      cout<<"one pair"<<endl;
    }else{
      cout<<"null"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1224
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int NN = 220000;

int n, x, y, a[NN];

int main(){
	//freopen("a.in", "r", stdin);

	scanf("%d%d%d", &n, &x, &y);
	for (int i=1; i<=n-1; i++){
		for (int j=i+1; j<=n; j++){
			int dis1 = j - i;
			int dis2 = min(abs(x-i) + abs(y-j) + 1, abs(y-i) + abs(x-j) + 1);
			a[min(dis1, dis2)]++;
		} 
	}
	
	for (int i=1; i<=n-1; i++) printf("%d\n", a[i]);
	
	return 0;
} 

Measured memory_bytes: 256
// Problem : B - Mix Juice
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <iostream>
#include <algorithm>
using namespace std;
int p[1005];
int main()
{
 int n,k;
 cin>>n>>k;
 for(int i=1;i<=n;i++)
  cin>>p[i];
 sort(p+1,p+n+1);
 int sum=0;
 for(int i=1;i<=k;i++)
  sum+=p[i];
 cout<<sum<<endl;
 return 0;
}

Measured memory_bytes: 3640
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    A.sort(reverse=True)
    dp = ["-"]*(N+10)
    dp[0] = ""
    match = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
    for i in range(N+1):
        if dp[i] == "-":
            continue
        for a in A:
            cur = dp[i+match[a]]
            ne = dp[i] + str(a)
            if len(cur) < len(ne) or cur < ne:
                dp[i+match[a]] = ne
    # print(dp)
    print(dp[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 30068
#include<iostream>
using namespace std;
int main(){
  int S[1000000],T,n,m,a,i,R,L,count=0; 
  cin>>n;
  for(int i=0;i<n;i++) cin>>S[i];
  cin>>m;
  for(int i=0;i<m;i++){ cin>>T;R=n,L=0;
    while(L<R){
	a=(R+L)/2;
	if(T>S[a])L=a+1;
      else R=a;
    }
    if(S[R]==T) count++;
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 1552
#include <stdio.h>

void swap(long *x, long *y){
	long tmp = *x;
	*x = *y;
	*y = tmp;
}

int main(void){
	int n;
	long a=0, b=0, c=0;
	long div=1;
	
	//input&sort(a<b<c)
	scanf("%d", &n);
	if(n==2){
		scanf(" %ld %ld", &a, &b);
		if(a>b) swap(&a,&b);
	}
	else if(n==3){
		scanf(" %ld %ld %ld", &a, &b, &c);
		if(a>b) swap(&a,&b);
		if(b>c) swap(&b,&c);
		if(a>b) swap(&a,&b);
	}
	
	//printf("a=%ld, b=%ld, c=%ld\n",a,b,c);
	
	for(div=1; div<=a; div++){
		if(a%div==0 && b%div==0 && c%div==0)
			printf("%ld\n", div);
	}
	
	return 0;
}

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


int main(int argc, char const *argv[])
{
	ll n; cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	printf("%d\n", a[a.size() - 1] - a[0]);
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 10000000
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func main() {
	n, k := nextInt(), nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt() - 1
	}

	visited := make(map[int]int)
	visited[0] = 0
	t, start := n, 0
	s := []int{0}
	next := a[0]
	for i := 0; i < n; i++ {
		if v, ok := visited[next]; ok {
			t = i + 1 - v
			start = v
			break
		}
		s = append(s, next)
		visited[next] = i + 1
		next = a[next]
	}

	var ans int
	if k < start {
		ans = s[k] + 1
	} else {
		mod := (k - start) % t
		ans = s[start+mod] + 1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 20324
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    long long x, y=100, cnt=0;
    cin>>x;
 
    while(true){
        if(x<=y){
            cout<<cnt<<endl;
            return 0;
        }
        cnt++;
        y=y+y/100;
    }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define int long long
int kal[1005][1005];
bool isr[1005][1005];
int water[1005][1005];
typedef pair<int,pair<int,int> > P;
typedef pair<int,int> p;
priority_queue<P,vector<P>,greater<P> > Q;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
signed main(){
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>kal[i][j];
			isr[i][j]=false;
			Q.push(P(kal[i][j],p(i,j)));
			}
		}	
		
	while(Q.size()){
		P a=Q.top();
		Q.pop();
		int I=a.second.first,J=a.second.second;
		int N=a.first;
		
		int k=0,s=0,flg=0;
		set<int>S;
		for(int i=0;i<4;i++){
			if(0<=I+dx[i]&&I+dx[i]<h&&0<=J+dy[i]&&J+dy[i]<w){
				k++;
				if(kal[I+dx[i]][J+dy[i]]>N){
					s++;
					}
				else if(isr[I+dx[i]][J+dy[i]]){
					flg++;
					break;
					}
				else{
					S.insert(water[I+dx[i]][J+dy[i]]);
					}	
				}
			}
		if(flg)isr[I][J]=true;
		else if(s==k)water[I][J]=N;
		else if(S.size()==1){
			auto itr=S.begin();
			water[I][J]=*itr;
		}
		else isr[I][J]=true;	
		}	
	int ans=0;
	for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)ans+=isr[i][j];
	cout<<ans<<endl;	
	}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;cin >> n >> k;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	sort(a.begin(),a.end());
	int ans=1000000000;
	rep(i,n-k+1){
		ans=min(ans,a[i+k-1]-a[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    vector<ll> x(5);
    rep(i, 5) cin >> x[i];
    for(ll i = 0; i < x.size(); ++i){
        if(x[i] == 0){
            cout << i+1 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3544
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

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

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

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

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	string s; cin >> s;
	queue<int> q;
	rrep(i, n)if (s[i] == 'R')q.push(i);
	int res = 0;
	rep(i, n)
	{
		if (q.empty() || q.front() < i)break;
		if (s[i] == 'W')
		{
			swap(s[i], s[q.front()]);
			q.pop();
			++res;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
void func(vector<vector<int> > &G, int *d, int *c)
{
    int time(0);
    stack<int> s;
    int count = 0;
    bool check;
    rep(p, 1, G.size())
    {
        if (d[p] == 0)
        {
            do
            {
                // cout << p << endl;
                check = true;
                if (d[p] == 0)
                {
                    s.push(p);
                    d[p] = ++count;
                }
                rep(i, 0, G[p].size())
                {
                    if (d[G[p][i]] == 0)
                    {
                        check = false;
                        p = G[p][i];
                        break;
                    }
                }
                if (check)
                {
                    c[p] = ++count;
                    s.pop();
                    if (s.size())
                        p = s.top();
                    else
                    {
                        p = 0;
                    }
                }
            } while (s.size());
        }
    }
}
int main()
{
    int n;
    cin >> n;
    int u, k, v;
    vector<vector<int> > G(n + 1, vector<int>(0));   //グラフ
    int discover[n + 1] = {}, complete[n + 1] = {}; //発見時刻と完了時刻
    rep(i, 0, n)
    {
        cin >> u >> k;
        rep(j, 0, k)
        {
            cin >> v;
            G[u].push_back(v);
        }
    }
    func(G, discover, complete);
    rep(i, 1, n + 1)
    {
        printf("%d %d %d\n", i, discover[i], complete[i]);
    }
}


Measured memory_bytes: 3224
import numpy as np
S=input()

tmp=S.split()
N=int(tmp[0])
D=int(tmp[1])

X=[]
for i in range(N):
    X.append(np.array(input().split(),dtype=np.int32))

import math

def calc_dist(x_i,x_j):
    s=0
    for i in range(len(x_i)):
        s+=pow((x_i[i]-x_j[i]),2)
    return math.sqrt(s)

count=0
for i in range(N):
    for j in range(i+1,N):
        result=calc_dist(X[i],X[j])
        
        if(result.is_integer()):
            count+=1

print(count)

Measured memory_bytes: 13644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(),v.end()
#define endll "\n"

#define fin             freopen("input.txt","r",stdin);
#define fout            freopen("output.txt","w",stdout);


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x=0,mx=0;
    cin >> n;
    string s;
    cin >> s;
    for(int i=0;i<n;i++){
        if(s[i]=='I')x++;
        else x--;

        mx=max(mx,x);
    }
    cout << mx << endl;

    return 0;
}



Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
using namespace std;

int main(void){
    int M,D,cnt=0;
    cin>>M>>D;
    for(int i=1;i<=M;i++){
        for(int j=22;j<=D;j++){
            if(j%10>=2 && int(j/10)*(j%10)==i){
                cnt++;
            }
        }
    }
    cout<<cnt<<endl;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int dist(int N , int X , int Y , int a ,int b){
		if(b <= X){
			return b - a;
		}
		if(Y <= a){
			return b - a;
		}
		if(a <= X){
			if(Y <= b){
				int d0 = X - a;
				int d1 = b - Y;
				return d0 + d1 + 1;				
			}
			if(b < Y){
				int d0 = b - a;
				int d1 = X - a + 1 + (Y - b);
				return Math.min(d0, d1);
			}
		}
		// Y > a > X 
		if(b <= Y){
			int d0 = b - a;
			int d1 = a - X + 1 + (Y - b);
			return Math.min(d0, d1);
		}
		// X < a < Y < b
		int d0 = b -a;
		int d1 = a - X + 1 + (b - Y);
		return Math.min(d0, d1);
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt() - 1;
		int Y = sc.nextInt() - 1;
		int adj[][] = new int[N][N];
		for(int i = 0 ; i < N ; ++i){
			for(int j = i + 1 ; j < N ; ++j){
				int d = dist(N , X, Y , i , j);
				adj[i][j] = adj[j][i] = d;
			}
		}
		int counter[] = new int[N];
		for(int i = 0 ; i < N ; ++i){
			for(int j = i + 1 ; j < N ; ++j){
				counter[adj[i][j]]++;
			}
		}
		for(int i = 1 ; i < N ; ++i){
			System.out.println(counter[i]);
		}
	}
}


Measured memory_bytes: 53332
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	n,ww=MI()
	w1,v1=MI()
	li=[[] for _ in range(4)]
	li[0].append(v1)

	for _ in range(n-1):
		w,v=MI()
		li[w-w1].append(v)

	for i in range(4):
		li[i]=[0]+sorted(li[i],reverse=True)
	#print(li)

	for i in range(4):
		for j in range(len(li[i])-1):
			li[i][j+1]+=li[i][j]
	#print(li)

	ans=0

	for i0 in range(len(li[0])):
		for i1 in range(len(li[1])):
			for i2 in range(len(li[2])):
				for i3 in range(len(li[3])):
					#print(i0,i1,i2,i3,li[0][i0],li[1][i1],li[2][i2],li[3][i3],w1*i0+(w1+1)*i1+(w1+2)*i2+(w1+3)*i3,li[0][i0]+li[1][i1]+li[2][i2]+li[3][i3],w,ans)
					if w1*i0+(w1+1)*i1+(w1+2)*i2+(w1+3)*i3<=ww:
						ans=max(ans,li[0][i0]+li[1][i1]+li[2][i2]+li[3][i3])

	print(ans)


if __name__ == "__main__":
	main()


Measured memory_bytes: 9316
N = int(raw_input())
retval = False
if N < 4:
    retval = False
else:
    x_max = N/4
    y_max = N/7
    for i in range(1, x_max+1):
        if (N - i*4) % 7 == 0:
            retval = True
            break
    for i in range(1, 1+y_max):
        if (N - i*7) % 4 == 0:
            retval = True
            break
if retval:
    print 'Yes'
else:
    print 'No'

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

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> a(N);
	for (int i = 0; i < N; i++){
		cin >> a[i];
	}

	int res = 1;
	int len = N-K;
	int x = K-1;
	if (len%x == 0) res += len/x;
	else res += (len/x)+1;

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = (ll)998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = (1 << 18) + 3;
int n;
ll a[N];
ll b[N];
ll c[N];
ll S;

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

	scanf("%d", &n);
	for (int i = 0; i < (1 << n); i++) {
		scanf("%lld", &a[i]);
		S += a[i];
	}
	S = rev(S);
	for (int i = 0; i < (1 << n); i++)
		a[i] = mult(a[i], S);
	S = rev(1 << n);
	b[0] = sub(S, 1);
	for (int i = 1; i < (1 << n); i++)
		b[i] = S;
	for (int k = 0; k < n; k++) {
		for (int mask = 0; mask < (1 << n); mask++) {
			if ((mask >> k) & 1) continue;
			ll x = a[mask], y = a[mask ^ (1 << k)];
			a[mask] = add(x, y);
			a[mask ^ (1 << k)] = sub(x, y);
			x = b[mask];
			y = b[mask ^ (1 << k)];
			b[mask] = add(x, y);
			b[mask ^ (1 << k)] = sub(x, y);
		}
	}
	for (int i = 0; i < (1 << n); i++) {
		c[i] = mult(mult(b[i], 1), rev(sub(a[i], 1)));
	}
	for (int k = 0; k < n; k++) {
		for (int mask = 0; mask < (1 << n); mask++) {
			if ((mask >> k) & 1) continue;
			ll x = c[mask], y = c[mask ^ (1 << k)];
			c[mask] = add(x, y);
			c[mask ^ (1 << k)] = sub(x, y);
		}
	}
	for (int i = 0; i < (1 << n); i++)
		printf("%lld\n", sub(c[0], c[i]));

	return 0;
}


Measured memory_bytes: 8960
#include<stdio.h>

int main(void){
  int pm,pe,pj,n,i;
  
  for(;;){
    scanf("%d",&n);
    if(n==0)
      break;
    
    for(i=0;i<n;i++){
      scanf("%d%d%d",&pm,&pe,&pj);
      
      if(pm==100||pe==100||pj==100)
	puts("A");
      else if((pm+pe)/2>=90)
	puts("A");
      else if((pm+pe+pj)/3>=80)
	puts("A");
      else if((pm+pe+pj)/3>=70)
	puts("B");
      else if((pm+pe+pj)/3>=50&&(pm>=80||pe>=80))
	puts("B");
      else
	puts("C");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>

using lint = long long;
using ldouble = long double;

void solve() {
    int n, k;
    std::cin >> n >> k;
    k = std::min(k, n);

    std::vector<lint> hs(n);
    for (auto& h : hs) std::cin >> h;

    std::sort(hs.rbegin(), hs.rend());
    std::cout << std::accumulate(hs.begin() + k, hs.end(), 0LL) << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int n = a + b;
    n = max(n, a - b);
    n = max(n, a * b);
    cout << n;
}


Measured memory_bytes: 256