akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int gaiseki(int x1,int y1,int x2,int y2){
	return x1*y2-x2*y1;
}
double dist(double x1,double y1,double x2,double y2){
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double sqsa(int x1,int y1,int x2,int y2){
	return x2*x2+y2*y2-x1*x1-y1*y1;
}
bool naibu(double p,double q,double r,int x,int y){
	return ((x-p)*(x-p)+(y-q)*(y-q)<=r*r);
}
int main(){
	int N;
	int x[51],y[51];
	scan(N);
	rep(i,N) scan(x[i]>>y[i]);
	if(N==2){
		prin(setprecision(11)<<dist(x[0],y[0],x[1],y[1])/2);
		return 0;
	}
	else{
		double rmin=0,rmax=2000;
		while(rmax-rmin>1e-8){
			double rmid=(rmax+rmin)/2;
			int flag=0;
			rep(i,N){
				if(flag) break;
				rep(j,N){
					if(flag) break;
					if(i==j) continue;
					if(dist(x[i],y[i],x[j],y[j])>2*rmid) continue;
					double h=sqrt(pow(rmid,2)-pow(dist(x[i],y[i],x[j],y[j])/2,2));
					double midx=(double)(x[i]+x[j])/2,midy=(double)(y[i]+y[j])/2;
					double vecx=(double)(x[i]-x[j]),vecy=(double)(y[i]-y[j]);
					double p[2],q[2];
					double hvecx=h*vecy/sqrt(vecx*vecx+vecy*vecy),hvecy=-h*vecx/sqrt(vecx*vecx+vecy*vecy);
					p[0]=midx+hvecx,q[0]=midy+hvecy;
					p[1]=midx-hvecx,q[1]=midy-hvecy;
					rep(s,2){
						int flag2=1;
						rep(k,N){
							if(k==i||k==j) continue;
							if(dist(x[k],y[k],p[s],q[s])>rmid){
								flag2=0;
								break;
							}
						}
						if(flag2){
							flag=1;
						}
					}
				}
			}
			//printf("%f %f %f %d\n",rmax,rmid,rmin,flag);
			if(flag) rmax=rmid;
			else rmin=rmid;
		}
		prin(setprecision(11)<<rmax);
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n, i, j, x, y;

	while(scanf("%d", &n) != EOF){
		i = n-1;
		while(1){
			x = 0;

			for(j = 2; j < i; j++){
				if(i % j == 0) {x = 1; break;}
			}

			if(x == 0) {x = i; break;}

			i--;
		}

		i = n+1;
		while(1){
			y = 0;

			for(j = 2; j < i; j++){
				if(i % j == 0) {y = 1; break;}
			}

			if(y == 0) {y = i; break;}

			i++;
		}

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

Measured memory_bytes: 596
#include <iostream>
#include <cmath>

using namespace std;
bool isint(int x)
{
  int root = sqrt(x);

  if(x==root*root)
    return true;
  else
    return false;
}
  
int main()
{
  int n,d;
  cin>>n>>d;
  int point[n][d];
  int count=0;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<d;j++)
    {
      cin>>point[i][j];
    }
  }
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      int dist = 0;
      for(int k=0;k<d;k++)
     	 dist += (point[i][k]-point[j][k])*(point[i][k]-point[j][k]);
      
      if(isint(dist))
         count++;
    }
    
  }
  cout<<count;
  return 0;
}

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

using namespace std;

#define int long long
#define pii pair<int, int>
#define pb push_back

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x, N;
    cin >> x >> N;
    cout << (x * 500 >= N ? "Yes": "No") << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define all(x) x.begin(), x.end()
#define uni(x) x.erase(unique(all(x)), x.end());
#define BUG(x) cout << #x << " = " << x << endl
#define BUGP(x) cout << #x << " = " << x._1 << ", " << x._2 << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto i:x) cout << i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 1e-6
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

int n, u, v, par[100005], pre[100005][20], lvl[100005], dp[100005];
vector<int> adj[100005];

void dfs(int x) {
	dp[x] = 1;
	pre[x][0] = par[x];
	FOR (i, 1, 19) pre[x][i] = pre[pre[x][i - 1]][i - 1];
	for (auto nex: adj[x]) if (!lvl[nex]) {
		lvl[nex] = lvl[x] + 1;
		par[nex] = x;
		dfs(nex);
		dp[x] += dp[nex];
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	REP (i, n - 1) {
		cin >> u >> v;
		adj[v].pb(u);
		adj[u].pb(v);
	}
	lvl[1] = 1;
	par[1] = 1;
	dfs(1);
	int tmp = lvl[n];
	tmp /= 2;
	tmp--;
	int cur = n;
	FORD (i, 19, 0) {
		if ((1 << i) & tmp) cur = pre[cur][i];
	}
	// BUG(pre[6][0]);
	// BUG(cur);
	if (dp[cur] >= n - dp[cur]) cout << "Snuke";
	else cout << "Fennec";
}

Measured memory_bytes: 19456
#include <bits/stdc++.h>
using namespace std;
int n,a[21],b[21],com[21],ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for (int i=0;i<n;++i) cin>>a[i];
	for (int i=0;i<n;++i) cin>>b[i],com[i]=a[i]-b[i];
	for (int i=0;i<n;++i) if (com[i]>0) ans+=com[i];
	cout<<ans;
	return 0;
}

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


int main(){
  int n,sum=0,a=0;cin>>n;
  vector<int>ans(n);
  vector<int>v(n);
  rep(i,n)cin>>v[i];
  rep(i,n)sum+=v[i];
  for(int i=1;i<n;i+=2)a+=v[i];
  ans[0]=sum-a*2;
  for(int i=1;i<n;i++)ans[i]=v[i-1]*2-ans[i-1];
  rep(i,n)cout<<ans[i]<<endl;
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

const int INF = (int)1e9;
int n, x;
VI A;
LL numOperations()
{
	LL ret = 0;	
	for(int i = 1; i + 1 <= n; ++i)
	{
		int sum = A[i] + A[i + 1];
		if(sum > x)
		{
			int sub = sum - x;
			ret += sub;
			int f = min(sub, A[i + 1]); 
			sub -= f; A[i + 1] -= f;
			if(sub > 0) {
				int s = min(sub, A[i]); 
				sub -= s; A[i] -= s;
			}
		}
	}
	return ret;
}

LL solve()
{
	LL ret = 0;
	for(int i = 1; i <= n; ++i)
	{
		int sum = A[i] + A[i - 1];
		if(sum > x)
		{
			ret += sum - x;
			A[i] -= sum - x;
		}
	}
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n >> x;

	A.resize(n + 1);
	REPC(i, 1, n) cin >> A[i];

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 640
class Problem
  attr_accessor :a, :b, :c, :k, :n, :m, :h, :w
  def initialize
    @n,@k = gets.to_s.split.map{ |v| v.to_i }
  end

  def solve
    k == 1 ? 0 : n - k
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main(){
	int N; cin >> N;
	int sum = 0;

	REP(i, N){
		int l, r; cin >> l >> r;
		sum += r-l+1;
	}

	cout << sum << endl;
}


Measured memory_bytes: 256
N = int(input())
S =[]
for n in range(N):
    s = input()
    S.append(s[0])
S=sorted(S)
NAME = sorted(["M","A","R","C","H"])
from itertools import combinations
from collections import Counter
pattern = list(combinations(NAME,3))
LEN = len(S)
cnt=0
Counter_S =Counter(S)
cnt = 0
for p in pattern:
    cnt +=(Counter_S[p[0]] * Counter_S[p[1]] * Counter_S[p[2]])
print(cnt)


Measured memory_bytes: 5092
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n);
	LL hs[n], ans = 0;
	rep(i, 0, n) {
		hs[i] = scanLong();
		bool cansee = true;
		rep(j, 0, i) {
			if(hs[j] > hs[i])	cansee = false;
		}
		if(cansee)	ans++;
	}
	cout << ans << endl;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v),end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

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

    int n;
    while(cin>>n,n)
    {
        int ans=0;
        bool l=false,r=false,f=true;
        REP(i,n){
            string s; cin>>s;
            if(s=="lu") l=true;
            else if(s=="ru") r=true;
            else if(s=="ld") l=false;
            else r=false;

            if(l==r && l==f){ 
                ans++;
                f=!f;
            }
        }   
        cout<<ans<<endl;
    }       
} 

Measured memory_bytes: 3212
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
vector<ll> vec[3];
ll n, c, d[35][35], f[550][550], a, res1, k[3][35];
int main(void){
    // Your code here!
    cin >> n >> c;
    for (ll i = 1; i <= c; i++) {
        for (ll j = 1; j <= c; j++) {
            cin >> d[i][j];
        }
    }
    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= n; j++) {
            cin >> a;
            vec[(i + j) % 3].push_back(a);
        }
    }
    for (ll i = 1; i <= c; i++) {
        for (ll j = 0; j != vec[1].size(); j++) {
            k[1][i] += d[vec[1][j]][i];
        }
    }
    for (ll i = 1; i <= c; i++) {
        for (ll j = 0; j != vec[2].size(); j++) {
            k[2][i] += d[vec[2][j]][i];
        }
    }
    for (ll i = 1; i <= c; i++) {
        for (ll j = 0; j != vec[0].size(); j++) {
            k[0][i] += d[vec[0][j]][i];
        }
    }
    for (ll i = 1; i <= c; i++) {
        for (ll j = 1; j <= c; j++) {
            for (ll l = 1; l <= c; l++) {
                if (i == j || j == l || l == i) continue;
                if (i == 1 && j == 2 && l == 3) res1 = k[0][i] + k[1][j] + k[2][l];
                else res1 = min(res1, k[0][i] + k[1][j] + k[2][l]);
            }
        }
    }
    cout << res1 << endl;
}


Measured memory_bytes: 2608
k = int(input())
L = []

def lunlun(d,v,L):
    L.append(v)
    if d == 10:
        return
    for i in range(-1,2):
        t = v%10 + i
        #print(v)
        if 0 <= t <=9:
            lunlun(d+1,v*10+t,L)
#lunlun(1,1,L)
for v in range(1,10):
    lunlun(1,v,L)
print(sorted(L)[k-1])

Measured memory_bytes: 20840
#include <iostream>

int suitToNum(char c)
{
	if (c=='S') return 0;
	else if (c=='H') return 1;
	else if (c=='C') return 2;
	else if (c=='D') return 3;
	else return -1;
}

char numToSuit(int n)
{
	switch (n) {
	case 0:
		return 'S';
	case 1:
		return 'H';
	case 2:
		return 'C';
	case 3:
		return 'D';
	default:
		return ' ';
	}
}

int main()
{
	int n;
	std::cin >> n;
	
	bool cards[4][13];
	for (int i=0; i<4; i++) {
		for (int j=0; j<13; j++) cards[i][j] = false;
	}
	
	char suit;
	int rank;
	for (int i=0; i<n; i++) {
		std::cin >> suit >> rank;
		cards[suitToNum(suit)][rank-1] = true;
	}
	
	for (int i=0; i<4; i++) {
		for (int j=0; j<13; j++) {
			if (!cards[i][j]) {
				std::cout << numToSuit(i) << " " << j+1 << std::endl;
			}
		}
	}
	
	return 0;
}




Measured memory_bytes: 3104
def is_prime(x):
    if x == 2:
        return True
    if x%2 == 0:
        return False
    for i in range(3, int(x**0.5)+1, 2):
        if not x%i:
            return False
    return True


if __name__ == "__main__":
    n = int(input())
    ans = 0
    for _ in range(n):
        num = int(input())
        ans += is_prime(num)
    print(ans)


Measured memory_bytes: 5672
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

#define F first
#define S second

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
        int h, n;
        cin >> h >> n;
        vector<pair<int, int>> a(1005);
        for(int i=0;i<n;i++)
            cin >> a[i].F >> a[i].S;

        int dp[10005] = {};
        fill_n(dp, 10005, INT_MAX);
        dp[0] = 0;

        for(int i = 1 ; i <= h ; i++)
        {
            for(int j = 0 ; j < n ; j++)
                dp[i] = min(dp[i], dp[max(0ll, i - a[j].F)] + a[j].S);
        }

        cout << dp[h] << '\n';
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 384
import itertools
import math
import fractions
import functools
n, k, q = map(int, input().split())
a = []
for i in range(q):
    a.append(int(input()) - 1)

score = [0]*n
for i in range(q):
    score[a[i]] += 1

for i in range(n):
    if k-q+score[i] > 0:
        print("Yes")
    else: print("No")

Measured memory_bytes: 81620
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define F(i,a,b) for(int i=a;i<b;i++)
#define RF(i,a,b) for(int i=a;i>b;i--)
#define mp(a,b) make_pair(int a,int b)
#define ll long long
const int mxn=1e5+10,mxm=4e5+10;
const ll modl=998244353;
int nm,n,m,p,t,k;
int ans,sum;
int a[mxn],b[mxn],h[mxn];
int l,r;
int main(){
    ios_base::sync_with_stdio(false);
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    cin>>nm;
    string s,s1,s2;char c;
    while(cin>>s){
//        priority_queue<dp,vector<dp>,cmp>q;
        if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes";
        else cout<<"No";
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long int k,a,b,ans,x,z;
    cin>>k>>a>>b;
    if((b-a)<3){
        ans=k+1;
    }
    else{
        if((k+1)/(a+2)<1){
            ans=k+1;
        }
        else{
           z=(k-a-1)/2;
           x=(k-a-1)%2;
           ans=b+z*(b-a)+x;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np

N, W = map(int, input().split())
wv = [tuple(map(int,input().split())) for _ in range(N)]
vmax = sum([wv[i][1] for i in range(N)])
INF = 10**20
  
dp = np.full(vmax+1, INF)
dp[0] = 0

for i in range(N):
  w,v = wv[i-1]
  dp[v:] = np.minimum(dp[v:], dp[:-v]+w)
  
print(max([i for i in range(vmax+1) if dp[i] <= W]))

Measured memory_bytes: 35656
#include<cstdio>
#include<vector>

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

using namespace std;

template<class T>
struct point{
	T x,y;
	point operator-(const point &a)const{ return (point){x-a.x,y-a.y}; }
};

template<class T>
struct segment:vector< point<T> >{
	segment(const point<T> &a,const point<T> &b){ push_back(a), push_back(b); }
};

template<class T>
struct circle{
	point<T> c;
	T r;
};

template<class T>
T dot(const point<T> &a,const point<T> &b){ return a.x*b.x+a.y*b.y; }

template<class T>
T cross(const point<T> &a,const point<T> &b){ return a.x*b.y-a.y*b.x; }

template<class T>
T dist2(const point<T> &a,const point<T> &b){
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

template<class T>
T dist2(const segment<T> &S,const point<T> &p){
	if(dot(S[1]-S[0],p-S[0])<=0) return dist2(p,S[0]);
	if(dot(S[0]-S[1],p-S[1])<=0) return dist2(p,S[1]);
	return cross(S[1]-S[0],p-S[0])*cross(S[1]-S[0],p-S[0])/dist2(S[0],S[1]);
}

template<class T>
bool intersect(const circle<T> &C,const segment<T> &S){
	return dist2(S,C.c)<=C.r*C.r;
}

template<class T>
bool cover(const circle<T> &C,const point<T> &p){
	return dist2(C.c,p)<=C.r*C.r;
}

template<class T>
bool cover(const circle<T> &C,const segment<T> &S){
	return cover(C,S[0]) && cover(C,S[1]);
}

int main(){
	for(int n;scanf("%d",&n),n;){
		circle<int> C[100];
		rep(i,n) scanf("%d%d%d",&C[i].c.x,&C[i].c.y,&C[i].r);

		int m; scanf("%d",&m);
		while(m--){
			point<int> p,q;
			scanf("%d%d%d%d",&p.x,&p.y,&q.x,&q.y);
			segment<int> S(p,q);
			bool ok=false;
			rep(i,n) if(intersect(C[i],S) && !cover(C[i],S)) ok=true;
			puts(ok?"Safe":"Danger");
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int X[100], Y[100];

int main() {
  int N, result;
  int i, j, p, q, k, l, cnt;
  scanf ("%d", &N);
  
  for (i=0;i<N;i++) {
      scanf("%d %d", &X[i], &Y[i]);
  }
  
  result = 0;
  for (i=0;i<N;i++) {
    for (j=0;j<N;j++) {
      if (i!=0) {
        p=X[j]-X[i];
        q=Y[j]-Y[i];
        cnt=0;
        for (k=0;k<N;k++) {
          for (l=0;l<N;l++) {
            if (l!=k && p==X[l]-X[k] && q==Y[l]-Y[k]) cnt++;
          }
        }
        if (cnt>result) result = cnt;
      }
    }
  }
  
  
  printf("%d", N-result);
  return 0;
}




Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
	int ans=0,n,t,s=0,tc=1;
	cin >> n;
	for (int i = 0; i <= n; ++i){
		if(i<n)
			cin >> t;
		else 
			t=s-1;
		if(s==t){
			tc++;
		}else{
			ans+=tc/2;
			tc=1;
			s=t;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	string s;
	cin>>n;
	cin>>s;
	int i;
	int MAX=0;
	int x=0;
	for(i=0;i<n;i++){
		if(s[i]=='D')	x--;
		else	x++;
		MAX=max(MAX,x);
	}
	cout<<MAX<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
#pragma warning (disable:4996)
const int maxn = 100005;
int a[maxn];
map<int, int> Map;
vector<int> E;
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		if (++Map[a[i]] == 1) {
			E.push_back(a[i]);
		}
	}
	if (E.size() > 3) {
		printf("No\n");
		return 0;
	}
	sort(E.begin(), E.end());
	if (E.size() == 1 && E[0] == 0) {
		printf("Yes\n");
		return 0;
	}
	if (n % 3)
		printf("No\n");
	else if (E.size() == 2 && E[0] == 0 && Map[E[1]] == 2 * Map[E[0]])
		printf("Yes\n");
	else if (E.size() == 3 && Map[E[0]] == Map[E[1]] && Map[E[1]] == Map[E[2]]) {
		if (E[0] == (E[1] ^ E[2]) && E[1] == (E[0] ^ E[2]) && E[2] == (E[0] ^ E[1]))
			printf("Yes\n");
		else
			printf("No\n");
	}
	else
		printf("No\n");
}

Measured memory_bytes: 4472
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////

int main() {
	int N; cin >> N;
	string s[10100];
	for (int i = 0; i < N; ++i)cin >> s[i];
	int rightA = 0;
	int leftB = 0;
	int leftBrightA = 0;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < s[i].size() - 1; ++j) {
			if (s[i][j] == 'A'&&s[i][j + 1] == 'B') {
				ans++;
			}
		}
		if (s[i][0] == 'B'&&s[i][s[i].size() - 1] != 'A') {
			leftB++;
		}
		else if (s[i][0] != 'B'&&s[i][s[i].size() - 1] == 'A') {
			rightA++;
		}
		else if (s[i][0] == 'B'&&s[i][s[i].size() - 1] == 'A') {
			leftBrightA++;
		}
	}
	int key1 = min(leftB, rightA);
	int key2 = max(leftB, rightA);
	if (leftB == rightA && leftB == 0) {
		cout << ans + max(0, leftBrightA - 1);
	}
	else {
		cout << ans + leftBrightA + min(leftB, rightA) << endl;
	}
	return 0;
}


Measured memory_bytes: 768
m,d=map(int,input().split())
ans=0
if d<22:
    print(ans)
    exit()
for i in range(1,m+1):
    for j in range(22,d+1):
        if int(str(j)[-1])>=2:
            if i==int(str(j)[0])*int(str(j)[-1]):
                ans+=1
print(ans)

Measured memory_bytes: 3060
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

ll mergeCount(vec<int>& v)
{
    ll ret{};

    if (v.size() > 1)
    {
        auto c = v.size() / 2;
        vec<int> l{ v.cbegin(), v.cbegin() + c };
        vec<int> r{ v.cbegin() + c, v.cend() };
        ret += mergeCount(l);
        ret += mergeCount(r);
        
        for (int i = 0, j = 0, k = 0; i < v.size(); ++i)
        {
            if (j == l.size())
                v[i] = r[k++];
            else if (k == r.size())
                v[i] = l[j++];
            else if (l[j] <= r[k])
                v[i] = l[j++];
            else
            {
                v[i] = r[k++];
                ret += c - j;
            }
        }
    }
    return ret;
}

int main()
{
    using namespace std;
    // cerr.rdbuf(nullptr);

    int n;
    cin >> n;
    vec<int> v(n);
    for (auto& e : v)
        cin >> e;

    auto ans = mergeCount(v);

    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 5384
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int N, M;
vector<int> graph[200005];

int main() {
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  for (auto e : graph[1]) {
    vector<int> v = graph[e];
    for (auto i : v) {
      if (i==N) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 12016
#include <iostream>
using namespace std;
int main()
{
	int n[26] = {}, i, t;
	char c;

	while( true )
	{
		t = 0;
		while( true )
		{
			cin.get(c);
			if( c == '\n' )
				break;

			i = -1;
			if( 'a' <= c && c <= 'z')
				i = c - 'a';
			else if( 'A' <= c && c <= 'Z')
				i = c - 'A';

			if( i != -1 )
				++n[i];
			++t;
		}

		if( 0 == t )
			break;
	}

	for(i = 0; i < 26; ++i)
	{
		c = i + 'a';
		cout << c << " : " << n[i] << "\n";
	}

	return 0;
}

Measured memory_bytes: 1132
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int dp[12345][123];
//main
signed main(){
  string s;int D;cin>>s>>D;
  int sum=0;
  memset(dp,0,sizeof(dp));
  for(int i=0;i<s.size();i++){
    for(int j=0;j<D;j++){
      for(int k=0;k<10;k++){dp[i+1][(j+k)%D]+=dp[i][j];dp[i+1][(j+k)%D]%=MOD;}
    }
    for(int k=0;k<s[i]-'0';k++){dp[i+1][(sum+k)%D]++;dp[i+1][(sum+k)%D]%=MOD;}
    sum+=s[i]-'0';
    sum%=MOD;
  }
  int a=0;
  for(char p:s)a+=p-'0';a%=D;
  if(a==0)cout<<dp[s.size()][0]<<endl;
  else cout<<(dp[s.size()][0]-1+MOD)%MOD<<endl;
}


Measured memory_bytes: 12160
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

long long gcd(long long a,long long b){
  if(a % b == 0) return b;
  else return gcd(b,a%b);
}

int main(){
  long long a,b;
  cin >> a >> b;
  long long c;
  c = gcd(a,b);
  long double rt;
  rt = sqrt(double(c));
  long long count = 1;
  for(int i=2;i<int(rt)+1;i++){
    if(c == 1) break;
    if(c%i == 0){
      count += 1;
    }
    while(c%i == 0){
      c = c/i;
    }
  }
  if(c != 1) count += 1;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    int Alice_score=0;
    int Bob_score=0;
    int result=0;
    cin >> N;
    vector<int>a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    

    sort(a.begin(),a.end(),greater<int>());

    for(int i=0;i<N;i+=2){
         Alice_score+=a[i];
         if(i==N-1){break;}
         Bob_score+=a[i+1];

    }
    result=Alice_score-Bob_score;
    cout << result << endl;
}



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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

//グラフ関連
struct Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    string s;
    cin >> n >> s;
    ll con = 0;
    REP(i, n) {
        if(s[i] == 'R') {
            con++;
        }
    }

    ll ans = 0;
    rep(i, con, n) {
        if(s[i] == 'R')
            ans++;
    }
    cout << ans << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ii {
    int a, b;
    bool operator < (ii o) const {
        return tie(a, b) < tie(o.a, o.b);
    }
};
struct iii {
    int a, b, c;
    bool operator < (iii o) const {
        return tie(a, b, c) < tie(o.a, o.b, o.c);
    }
};

const int MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 1000005;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    string s;
    cin >> s;
    int sumDigit = 0;
    for (char c: s) {
        sumDigit += c-'0';
    }
    if (sumDigit%9 == 0) cout << "Yes\n";
    else cout << "No\n";
    
}


Measured memory_bytes: 3732
N=int(input())
upper_cake=N//7
upper_d=N//4
flag=False
for i in range(upper_cake+1):
        for j in range(upper_d+1):
                if 7*i+4*j==N:
                        flag=True
                        break

if flag:
        print('Yes')
else:
        print('No')

Measured memory_bytes: 2940
#include <stdio.h>
int main(void)
{
    int a[1100000],x,y,i,k=0;

    scanf("%d%d",&x,&y);
    for (i = 0; i < y; i++){
        scanf("%d",&a[i]);
        k=k+a[i];
    }
    if(k>=x) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    while(1){
        ll n; cin >> n;
        if(n==0) break;
        vl w(n);
        rep(i,n) cin >> w[i];
        ll dp[n+1][n+1] = {};
        for(ll W=2; W<=n; W++){
            rep(l,n){
                if(l + W > n) continue;
                ll r = l + W;
                if(dp[l+1][r-1] == W-2 && abs(w[l]-w[r-1])<=1){
                    dp[l][r] = W;
                }
                REP(mid,l,r+1){
                    dp[l][r] = max(dp[l][r], dp[l][mid] + dp[mid][r]);
                }
            }
        }
        cout << dp[0][n] << endl;
    }
}



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

using namespace std;

#define boost                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long int
// #define int ll
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<ll, ll>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define sz(A) (ll)(A).size()
#define F first
#define S second
#define loop(z, v) for (auto &z : v)
#define sp << ' ' <<
#define sps << ' '
#define nl "\n"
// #define nl endl
// #define fat 1000000007
#define fat 998244353
#define PI_2 1.57079632679489661923

int main()
{
    ll tt = 1, n, m, k = 0, i, j, p, q;
    ll a, b, c, d, u, v, x, y;
    ll ans = 0;

    ll l = 0, r = 0;
    bool poss = true;

    boost;
    string sa, sb;

    // cin >> tt;  
    for(int _ = 1; _ <= tt; _++){
        // cout << "Case #" << _ << ": ";
        cin >> a >> b;
      cout << a*b << nl;
    }   

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int N;
	string S;
	cin >> S;
	N = S.length();
	vi RL(N + 1, 0);
	vi ans(N, 0);
	int Rs = 0;
	int i = 0;
	RL[0] = -1;
	rep(i, N - 1) {
		if (S[i] == 'R' && S[i + 1] == 'L') {
			RL[i + 1] = 1;
		}
		else if (S[i] == 'L' && S[i + 1] == 'R') {
			RL[i + 1] = -1;
		}
	}
	RL[N] = -1;
	int RL_prev = 0;
	int LR_prev = 0;
	rep(i, N + 1) {
		if (RL[i] == 1) {
			RL_prev = i;
		}
		else if (RL[i] == -1) {
			int Rnum = RL_prev - LR_prev;
			int Lnum = i - RL_prev;
			ans[RL_prev - 1] = (Rnum + 1) / 2 + Lnum / 2;
			ans[RL_prev] = (Lnum + 1) / 2 + Rnum / 2;
			LR_prev = i;
		}
	}
	rep(i, N) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int key;
  node *left,*right,*p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
bool find(int z){
  node *x=root;
  while(x!=NULL){
    if(z==x->key) return true;
    if(z<x->key) x=x->left;
    else x=x->right;
  }
  return false;
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
signed main(){
  int n;
  cin>>n;
  root=NULL;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    //cout<<(root==NULL?-1:root->key)<<endl;
    if(s=="print"){
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
      continue;
    }
    int x;
    cin>>x;
    if(s=="insert"){
      insert(node(x));
    }
    if(s=="find"){
      cout<<(find(x)?"yes":"no")<<endl;
    }
  }
  return 0;
}


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

typedef long long ll;

using namespace std;
int main()
{
  int n;
  cin >> n;
  
  ll sum = 0;
  
  map<int,int> memo;
  for(int i=0; i< n; i++){
    ll value;
    cin >> value;
    sum += value;
    if(memo.find(value) == memo.end()){
      memo[value] = 0;
    }
    memo[value]++;
  }
  
  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    ll b,c;
    cin >> b >> c;
    if(memo.find(c) == memo.end()){
        memo[c] = 0;
    }
    if(memo.find(b) != memo.end()){
      memo[c] += memo[b];
      sum -= memo[b] * b;
      sum += memo[b] * c;
      memo[b] = 0;
    }
    
    cout << sum << endl;
  }
  
}



Measured memory_bytes: 7652
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int w,d;

int main(){
  while(cin >> w >> d && w+d){
    vector<int>g(w);
    vector<int>h(d);
    rep(i,w) cin >> g[i];
    rep(i,d) cin >> h[i];

    int res = 0;
    rep(i,g.size()){
      vector<int>::iterator it = find(h.begin(), h.end(), g[i]);
      if(it!=h.end()){
	res += g[i];
	g.erase(g.begin()+i);
	h.erase(it);
	i--;
      }
    }

    rep(i,g.size()) res += g[i];
    rep(i,h.size()) res += h[i];
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;

int main()
{
    ll n;
    cin >> n;
    cout << n * (n - 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

int solve(int a,int b,int n){
	int s=0;
	for(int i=0;i<n;++i){
		if(a/b>0){
			a%=b;
			--i;
		}
		else{
			a*=10;
			s+=a/b;
			a%=b;
		}
	}
	return s;
}

int main(){
	while(1){
		int a,b,n;
		std::cin>>a>>b>>n;
		if(std::cin.eof())break;
		std::cout<<solve(a,b,n)<<std::endl;
	}
	return 0;
}

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

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

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

const int MAX = 1 << 17;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

class SegmentTree {
    int dat[2 * MAX - 1];
    public:
        unsigned int N;
        SegmentTree(int n);
        int query(int a, int b, int k, int l, int r);
        void update(int k, int a);
};

SegmentTree::SegmentTree(int n) {
    N = 1;
    while (N < n) N *= 2;
    if (N == 1) N *= 2;
    rep(i, N) dat[i] = INF;
}

int SegmentTree::query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INF;

    if (a <= l && r <= b) {
        return dat[k];
    } else {
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
}

void SegmentTree::update(int k, int a) {
    k += N - 1;
    dat[k] = a;

    while (0 < k) {
        k = (k - 1) / 2;
        dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
};

int main() {
    int N, M;
    string S;
    cin >> N >> M >> S;

    SegmentTree st = SegmentTree(N);
    st.update(N, 0);
    vector<int> dp(N + 1);
    dp[N] = 0;
    for (int i = N - 1; i >= 0; --i) {
        if (S[i] == '1') {
            dp[i] = INF;
            st.update(i, INF);
            continue;
        }
        int l = i + 1, r = min(N + 1, l + M);
        dp[i] = st.query(l, r, 0, 0, st.N) + 1;
        st.update(i, dp[i]);
    }

    if (dp[0] >= INF) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> ans;
    int x = 0;
    while (x < N) {
        int i = 1;
        while (dp[x] - 1 != dp[x + i]) i++;
        x += i;
        ans.push_back(i);
    }

    for (int i : ans) cout << i << " ";
    cout << endl;
}

Measured memory_bytes: 2424
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,x,ans=0,p=0; cin>>n>>x;
    vector<int> l(n,0);
    rep(i,n) cin>>l[i];
    while(p<=x && ans<=n){
        ans++;
        p+=l[ans-1];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int main(){
    ll N;
    cin >> N;
    ll a, b, c;
    a = 1;
    b = 1;
    c = 1;
    REP(i,N){
        a*=10;
        a%=mod;
        b*=9;
        b%=mod;
        c*=8;
        c%=mod;
    }
    b*=2;
    b%=mod;
    ll ans = a - b + c;
    ans %= mod;
    if(ans<0) ans+=mod;
    cout << ans << endl;
}

Measured memory_bytes: 3632
/**
 *   author: malviyanshiv
 *   created: 07 September 2019  17:29:06
**/
#include<bits/stdc++.h>

using namespace std;

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

    int n;
    cin >> n;
    vector<int> ai(n), bi(n), ci(n);

    for(int i = 0; i < n; i++)
        cin >> ai[i];
    for(int i = 0; i < n; i++)
        cin >> bi[i];
    for(int i = 0; i < n-1; i++)
        cin >> ci[i];
    int sm = 0;
    for(int i = 0; i < n; i++){
        if( i == 0 ){
            sm += bi[ai[i]-1];
        }else{
            sm += bi[ai[i]-1];
            if(ai[i]-ai[i-1] == 1){
                sm += ci[ai[i-1]-1];
            }
        }
    }
    cout << sm;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

bool cmp(int a, int b)
{
    return a<b;
}

struct compare
{
  bool operator()(const int& l, const int& r)
  {
      return l>r;
  }
};
ll inf=1e18;
int mod=1e9+7;

int main()
{
//    READ;
    ll a,b,c,ta,tb,tc;
    sl3(a,b,c);
    int cnt=0;
    while(a%2==0 && b%2==0 && c%2==0)
    {
        ta=(b/2)+(c/2);
        tb=(a/2)+(c/2);
        tc=(a/2)+(b/2);
        cnt++;
        a=ta;
        b=tb;
        c=tc;
        if(a==b && b==c && a==c)
        {
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  string s = readString();
  int cnt = 0;
  REP(i, s.size()) {
    REP(j, s.size()) {
      if (i == j) continue;
      if (s[i] == s[j]) cnt++;
    }
  }
  if (cnt == 4)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
    int n,A[10],C[10][10],ans=0,a,b,c;
    bool B[1000];
    REP(i,10) A[i]=0;
    REP(i,1000) B[i]=false;
    REP(i,10){
        REP(j,10) C[i][j]=0;
    }
    string s,l;
    cin>>n>>s;
    REP(i,n-2){
        a=s[i]-'0';
        if(A[a]==0){
            A[a]++;
            FOR(j,i+1,n-1){
                b=s[j]-'0';
                if(C[a][b]==0){
                    C[a][b]++;
                    FOR(k,j+1,n){
                        l="";
                        l+=s[i];
                        l+=s[j];
                        l+=s[k];
                        c=atoi(l.c_str());
                        if(B[c]==false){
                            B[c]=true;
                            ans++;
                        }
                    }
                }
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(),B = sc.nextInt(),C = sc.nextInt(),D = sc.nextInt();
		int t1,t2;
		if(D<=A || B<=C)System.out.print(0);
		else {
			t1=(int)Math.max(C,A);
			t2=(int)Math.min(D,B);
			System.out.print(t2-t1);
		}
		sc.close();
	}
}

Measured memory_bytes: 23892
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    double d,t,s;cin>>d>>t>>s;
    if((d/s)<=t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3716
fun main() = Thread(null, ::soundhound2018summerqualC, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun soundhound2018summerqualC() {
    val (n, m, d) = readLine()!!.split(" ").map { it.toLong() }

    val diffEqualToD = (n - d) * if (d == 0L) 1 else 2
    val probOfDiffEqualToD = diffEqualToD.toDouble() / (n * n)

    val answer = "%.10f".format((m - 1) * probOfDiffEqualToD)

    println(answer)
}


Measured memory_bytes: 37944
n = int(input())
w = [int(x) for x in input().split()]
for i in range(n-1):
    w[i+1] += w[i]
 
ans = 1000000000000

max_sum = w[n-1]
for i in range(n):
    k = abs(max_sum-w[i]*2)
    if ans > k:
        ans = k

print(ans)

Measured memory_bytes: 3064