akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>

using namespace std;

// Problem https://atcoder.jp/contests/abc065/tasks/abc065_b
// Try C++ 2nd

int solver(int lampCounter,vector<int> nextShineLamp){
    int result;
    result = -1;
    int counter,nowShining;
    counter = 0;
    nowShining = 0; 
    const int objectShining = ( 2 - 1);
    while(true){

        if(nowShining == objectShining){
            result = counter;
            break;
        }
        else{
            if(counter < lampCounter ){
                counter = counter + 1;
                nowShining = nextShineLamp.at(nowShining);
            }
            else
            {
                break;
            }
        }
    }
    return result;
}

int main(void){
    int answer;
    answer = 0;
    int N;
    cin >> N;
    vector<int> Ai(N,0);
    for(int j=0;j<N;j++){
        int shineLamp;
        shineLamp=0;
        cin >> shineLamp;
        Ai.at(j)=shineLamp-1;
    }
    answer = solver(N,Ai);
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 1024
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    Q, *BC = map(int, read().split())

    total = sum(A)
    d = [0] * (10 ** 5 + 1)
    for a in A:
        d[a] += 1

    for b, c in zip(BC[::2], BC[1::2]):
        total += (c - b) * d[b]
        d[c] += d[b]
        d[b] = 0
        print(total)

    return


if __name__ == '__main__':
    main()


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

#define int long long
#define left left_
#define right right_

using namespace std;

int pref[100001];
int left[100001];
int right[100001];
int a[100001];

 main () {
	int n, k;
	cin >> n >> k;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i];
		pref[i] = pref[i - 1] + a[i];
	}
	for (int i = 1;i <= n;i ++) {
		left[i] = left[i - 1];
		if (a[i] > 0) left[i] += a[i];
	}
	for (int i = n;i >= 1;i --) {
		right[i] = right[i + 1];
		if (a[i] > 0) right[i] += a[i];
	}
	int ans = 0;
	for (int i = 1;i + k - 1 <= n;i ++) {
		int r = i + k - 1;
		ans = max (ans, left[i - 1] + right[r + 1] + pref[r] - pref[i - 1]);
		ans = max (ans, left[i - 1] + right[r + 1]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int N,A,B;

bool check(ll x,vector<ll> h){
    ll cnt = 0;
    rep(i,N){
        h[i] -= x*B;
        if(h[i] > 0){
            cnt += (h[i]+A-1)/A;
        }
    }
    return cnt <= x;
}

int main(){
    cin >> N >> A >> B;
    A -= B;
    vector<ll> h(N);
    rep(i,N) cin >> h[i];

    int ng = 0, ok = 1000000100;
    while(ng + 1 != ok){
        int x = (ng + ok) / 2;
        if(check(x,h)) ok = x;
        else ng = x;
    }
    cout << ok << endl;
}


Measured memory_bytes: 1792
#include<cmath>
#include<cstdio>

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

using namespace std;

const double EPS=1e-8;

struct point3{
	double x,y,z;
	point3():x(0),y(0),z(0){}
	point3(double x,double y,double z):x(x),y(y),z(z){}
	point3 &operator+=(const point3 &a){ x+=a.x; y+=a.y; z+=a.z; return *this; }
	point3 &operator-=(const point3 &a){ x-=a.x; y-=a.y; z-=a.z; return *this; }
	point3 &operator*=(double c){ x*=c; y*=c; z*=c; return *this; }
	point3 &operator/=(double c){ x/=c; y/=c; z/=c; return *this; }
	point3 operator+(const point3 &a)const{ return point3(x+a.x,y+a.y,z+a.z); }
	point3 operator-(const point3 &a)const{ return point3(x-a.x,y-a.y,z-a.z); }
	point3 operator/(double c)const{ return point3(x/c,y/c,z/c); }
	point3 operator-()const{ return point3(-x,-y,-z); }
};

point3 operator*(double c,const point3 &a){ return point3(c*a.x,c*a.y,c*a.z); }

double dot(const point3 &a,const point3 &b){ return a.x*b.x+a.y*b.y+a.z*b.z; }

point3 cross(const point3 &a,const point3 &b){ return point3(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x); }

double abs(const point3 &a){ return sqrt(a.x*a.x+a.y*a.y+a.z*a.z); }

double abs2(const point3 &a){ return a.x*a.x+a.y*a.y+a.z*a.z; }

struct segment3{
	point3 a,b;
	segment3(){}
	segment3(const point3 &a,const point3 &b):a(a),b(b){}
};

struct sphere{
	point3 c;
	double r;
	sphere():c(point3(0,0,0)),r(0){}
	sphere(const point3 &c,double r):c(c),r(r){}
};

double dist(const segment3 &S,const point3 &p){
	if(dot(S.b-S.a,p-S.a)<=0) return abs(p-S.a);
	if(dot(S.a-S.b,p-S.b)<=0) return abs(p-S.b);
	return abs(cross(S.b-S.a,p-S.a))/abs(S.a-S.b);
}

bool intersect(const sphere &C,const segment3 &S){
	return dist(S,C.c)<C.r+EPS;
}

bool cover(const sphere &S,const point3 &p){
	return abs(S.c-p)<S.r+EPS;
}

bool cover(const sphere &C,const segment3 &S){
	return cover(C,S.a) && cover(C,S.b);
}

int main(){
	for(int n,m,k;scanf("%d%d%d",&n,&m,&k),n;){
		sphere S[2000];
		rep(i,n) scanf("%lf%lf%lf%lf",&S[i].c.x,&S[i].c.y,&S[i].c.z,&S[i].r);
		point3 p[15];
		double bright[15];
		rep(i,m) scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z,bright+i);
		point3 tar; scanf("%lf%lf%lf",&tar.x,&tar.y,&tar.z);

		int mask[2000]={}; // mask[i] := ( 風船 i が遮断している光源の集合 )
		rep(j,m){
			segment3 T(p[j],tar);
			rep(i,n) if(!cover(S[i],T) && intersect(S[i],T)) mask[i]|=1<<j;
		}

		double power[15];
		rep(i,m) power[i]=bright[i]/abs2(p[i]-tar);

		double ans=0;
		rep(S,1<<m){
			double pwr=0;
			rep(i,m) if(S>>i&1) pwr+=power[i];
			if(pwr>ans){
				int cnt=0;
				rep(i,n) if(mask[i]&S) cnt++;
				if(cnt<=k) ans=pwr;
			}
		}
		printf("%.9f\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

ll mod = 1e9+7;

int main(){
    fastio
    int n,x,t;
    cin >> n >> x >> t;
    cout << (n+x-1)/x*t;
}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

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

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

string solve(vi a)
{
	int k=a.size();
	ll mn=2,mx=2;
	per(i,k){
		mn=(mn+a[i]-1)/a[i]*a[i];
		mx=mx/a[i]*a[i]+a[i]-1;
		if(mn>mx) return "-1";
	}
	return to_string(mn)+" "+to_string(mx);
}

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int k;cin>>k&&k;){
		vi a(k);
		rep(i,k) cin>>a[i];
		cout<<solve(a)<<endl;
	}
}


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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair 
#define COUT(v) for(int64_t i=0;i<(v).size();i++){ cout << v.at(i) << endl;}
#define REP(i, n) for(int64_t i=0;i<n;i++)
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal>palvec;


typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;

typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const int MOD = 1000000007;


ll gcd(ll x, ll y){
    ll r = x%y;
    if(r == 0) return y;
    else return gcd(y, r);
} 

ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}

lvec mfactor(ll n){
    bvec ip(n, true);
    lvec mf(n, -1);
    ip[0]=false; ip[1]=false; mf[0]=0; mf[1]=1;
    REP(i, n){
        if(ip[i]){
            mf[i] = i;
            for(ll j=i*i; j<n; j+=i){
                ip[j] = false;
                if(mf[j] == -1) mf[j]=i;
            }
        }
    }
    return mf;
}

palivec get_prime(ll n, const lvec &mf){
    palivec plist;
    while(n != 1){
        int cnt=0;
        ll m=mf[n];
        while(mf[n] == m){
            cnt++;
            n/=m;
        }
        plist.pb(pali(m, cnt));
    }
    return plist;
}

void COMinit(int m, lvec &fac, lvec &finv){
    lvec inv(m);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < m; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k, const lvec& fac, const lvec &finv){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    lvec a(n), s(n);
    VIN(a);
    sort(a.begin(), a.end());
    REP(i, n){
        if(i==0) s[i] = a[i];
        else s[i] = s[i-1] + a[i];
    }

    ll MAX =5*1e5+1;
    lvec fac(MAX), finv(MAX);
    COMinit(MAX, fac, finv);
    ll ans=0;
    REP(i, n-k+1){
        ll c = COM(k-2+i, k-2, fac, finv)%MOD;
        ans+=(((s[n-1]-s[k+i-2]) - (s[n-k-i]))%MOD)*c;
        ans%=MOD;

    }
    cout << ans%MOD<< endl;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using T = tuple<int, int, int>;
using T2 = tuple<ll, int, int>;
constexpr ll INF = 1e18+7;
int n, m, s, u, v, a, b;
vector<T> tp[55];
ll dp[55][2505], c[55], d[55], ans = INF;
priority_queue<T2, vector<T2>, greater<T2>> qu;
int main(){
	scanf("%d%d%d", &n, &m, &s);
	s = min(2499, s);
	fill(dp[0], dp[50], INF);
	rep(i,m){
		scanf("%d%d%d%d", &u, &v, &a, &b);
		u--; v--;
		tp[u].emplace_back(v, a, b);
		tp[v].emplace_back(u, a, b);
	}
	rep(i,n) scanf("%lld%lld", c+i, d+i);
	qu.emplace(dp[0][s] = 0, 0, s);
	while(!qu.empty()){
		auto[cost, town, coin] = qu.top(); qu.pop();
		if(dp[town][coin] < cost) continue;
		for(auto [nxtown, coin2, cost2]: tp[town]){
			if(coin2 > coin) continue;
			if(dp[nxtown][coin - coin2] > cost + cost2){
				qu.emplace(dp[nxtown][coin - coin2] = cost + cost2, nxtown, coin - coin2);
			}
		}
		if(coin + c[town] < 2500){
			if(dp[town][coin + c[town]] > cost + d[town]){
				qu.emplace(dp[town][coin + c[town]] = cost + d[town], town, coin + c[town]);
			}
		}
	}
	for(int i=1; i<n; i++){
		ans = INF;
		rep(j,2500) ans = min(ans, dp[i][j]);
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 6252
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define pii 3.14
#define mod (ll)(1e9 + 7)
#define inf (ll)(1e18)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
#define pi pair<int,int>
#define N (ll)(1e5+5)

double dp[3000][3000];
double p[3000];

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

    for(int i=1;i<=n;i++)
        cin>>p[i];

    dp[1][0] = 1-p[1];
    dp[1][1] = p[1];

    for(ll i=2;i<=n;i++)
    {
        double h = p[i];
        double t = 1-h;
        dp[i][0] = dp[i-1][0]*t;
        for(ll j=1;j<=i;j++)
            dp[i][j] = dp[i-1][j]*t + dp[i-1][j-1]*h;
    }

    double ans = 0;
    for(ll j=n;j>n/2;j--)
        ans += dp[n][j];

    cout<<fixed<<setprecision(10)<<ans<<"\n";
}

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


Measured memory_bytes: 68992
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define ll long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const int N = 1e5 + 10;
int n, a[N];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    sort(a+1, a+1+n, greater<int>());
    int s;
    for (int i = 1; i <= n; ++i) {
        if(i+1 > a[i+1]) {
            if((a[i]-i)%2) {
                s = 1;
                break;
            }
            s = 0;
            for (int j = i+1; j <= n; ++j) {
                if(a[j] == i) s ^= 1;
                else break;
            }
            break;
        }
    }
    if(s) puts("First");
    else puts("Second");
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v) cout << i << ' ' << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vin2(v, w) for (ll i = 0; i < v.size(); ++i) cin >> v[i] >> w[i];
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }

int main()
{
	//printf("使用可能な最大スレッド数：%d\n", omp_get_max_threads());

	long long int a, b, c, d;
	cin >> a >> b >> c >> d;
	vector<long long int> x(4);
	x.at(0) = a * c;
	x.at(1) = a * d;
	x.at(2) = b * c;
	x.at(3) = b * d;
	cout << maxel(x);
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <vector>
#include <utility>
#include <time.h>
#include <set>
#include <unordered_set>
#include <list>
#include <iterator>
#include <time.h>
#include <chrono>
#include <deque>
#include <cstdio>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <climits>
#include <tuple>
#include <map>
using namespace std;

#define ll long long
#define ldb long double
const ll M = 1e9 + 7;

ll mod(ll a, ll b)
{
	return (b + (a % b)) % b;
}

ll mulMod(ll a, ll b)
{
	return ((a % M) * (b % M)) % M;
}

ll subMod(ll a, ll b)
{
	return mod((mod(a, M) - mod(b, M)), M);
}

ll dayofweek(ll d, ll m, ll y)
{
	static ll t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
	y -= m < 3;
	return (y + y / 4 - y / 100 +
		y / 400 + t[m - 1] + d) % 7;
}

void test()
{

}



//ll nCr(ll n, ll r)
//{
//	ll* C = new ll[r + 1];
//
//	for (ll i = 0; i <= r; i++)
//	{
//		C[i] = 0;
//	}
//
//	C[0] = 1;
//	for (ll i = 1; i <= n; i++)
//	{
//		for (ll j = min(i, r); j > 0; j--)
//		{
//			C[j] = (C[j] + C[j - 1]) % M;
//		}
//	}
//
//	ll temp = C[r];
//	delete[] C;
//	return temp;
//}
//
//ll nCrLucas(ll n, ll r)
//{
//	if (r == 0) return 1;
//
//	ll ni = n % M, ri = r % M;
//	return (nCrLucas(n / M, r / M) * nCr(ni, ri)) % M;
//}


// C function for extended Euclidean Algorithm 
ll gcdExtended(ll a, ll b, ll* x, ll* y);

// Function to find modulo inverse of b. It returns 
// -1 when inverse doesn't 
ll modInverse(ll b, ll m)
{
	ll x, y; // used in extended GCD algorithm 
	ll g = gcdExtended(b, m, &x, &y);

	// Return -1 if b and m are not co-prime 
	if (g != 1)
		return -1;

	// m is added to handle negative x 
	return (x % m + m) % m;
}

// Function to compute a/b under modlo m 
ll modDivide(ll a, ll b, ll m)
{
	a = a % m;
	ll inv = modInverse(b, m);
	/*if (inv == -1)
		cout << "Division not defined";
	else
		cout << "Result of division is " << (inv * a) % m;*/

	return (inv * a) % m;
}

// C function for extended Euclidean Algorithm (used to 
// find modular inverse. 
ll gcdExtended(ll a, ll b, ll* x, ll* y)
{
	// Base Case 
	if (a == 0)
	{
		*x = 0, * y = 1;
		return b;
	}

	ll x1, y1; // To store results of recursive call 
	ll gcd = gcdExtended(b % a, a, &x1, &y1);

	// Update x and y using results of recursive 
	// call 
	*x = y1 - (b / a) * x1;
	*y = x1;

	return gcd;
}

ll power(ll x, ll y)
{
	ll temp;
	if (y == 0) return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0) return mulMod(temp, temp);
	else return mulMod(x, mulMod(temp, temp));
}


void solve()
{
	ll n;
	cin >> n;
	vector<ll> x(n);

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

	ll min = LLONG_MAX;

	for (ll p = 1; p <= 100; p++)
	{
		ll sum = 0;

		for (ll i = 0; i < n; i++)
		{
			sum += (x[i] - p) * (x[i] - p);
		}

		if (sum < min)
		{
			min = sum;
		}
	}

	cout << min;
}

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

	//test();

	solve();

	return 0;
}

Measured memory_bytes: 256
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var t = new Test();
            var nk = t.ParseIntList(t.ReadInput());
            var ansDic = new Dictionary<int,int>();
            var count = 0;
            
            for(var i = 1; i<=nk[0]; i++)
            {
                ansDic.Add(i, 0);
            }

            for (var i = 0; i < nk[1]; i++)
            {
                var d = int.Parse(Console.ReadLine());
                var aList = t.ParseIntList(t.ReadInput());
                for(var j = 0; j<d; j++)
                {
                    if (ansDic.ContainsKey(aList[j]))
                    {
                        ansDic[aList[j]]++;
                    }
                }
            }

            foreach(var val in ansDic)
            {
                if(val.Value == 0)
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }



        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public List<int> ParseIntList(string[] x)
        {
            var convertedList = new List<int>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(int.Parse(x[i]));
            }

            return convertedList;
        }


        public List<double> ParseDoubleList(string[] x)
        {
            var convertedList = new List<double>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(double.Parse(x[i]));
            }

            return convertedList;
        }

        public List<long> ParseLongList(string[] x)
        {
            var convertedList = new List<long>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(long.Parse(x[i]));
            }

            return convertedList;
        }

        public int CountContainWords(string source, string word)
        {
            var count = 0;
            var loopCount = source.Length - (word.Length - 1);
            for (var i = 0; i < loopCount; i++)
            {
                if (source.Substring(i, word.Length) == word)
                {
                    count++;
                }
            }
            return count;
        }
    }
}

Measured memory_bytes: 18524
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

ll n;
ll a[100000];
ll dp[100000];

ll solve(ll index)
{
	if(index==n-1) return 0;
	if(index>=n) return INT_MAX;
	if(dp[index]!=-1) return dp[index];
	ll left=abs(a[index+1]-a[index])+solve(index+1);
	ll right=INT_MAX;
	if(index+2<n)
	{
		right=abs(a[index+2]-a[index])+solve(index+2);
	}
	return dp[index]=min(left,right);
}


int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(ll i=0;i<n;i++) cin>>a[i];
	cout<<solve(0)<<endl;
	return 0;
}

Measured memory_bytes: 4864
from collections import defaultdict
import sys
sys.setrecursionlimit(10000000)


def dfs(node, graph, dist, visited):
    if visited[node] == True:
        return dist[node]
    visited[node] = True
    for child in graph[node]:
        dist[node] = max(dist[node], 1+dfs(child, graph, dist, visited))
    return dist[node]


def main():
    n, m = map(int, input().split())
    graph = defaultdict(list)
    for _ in range(m):
        u, v = map(int, input().split())
        graph[u].append(v)
    dist = [0]*(n+1)
    visited = [False]*(n+1)
    for node in range(1, n+1):
        if not visited[node]:
            dfs(node, graph, dist, visited)
    print(max(dist))


if __name__ == "__main__":
    main()


Measured memory_bytes: 130820
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ;

int n ,m ,arr[N] ,u ,v ;
vector<int> adj[N] ;
bool vis[N] ;
int vid ,cur[N] ;
vector<int> idx ;
void dfs(int p){
    vis[p] = 1 ;
    cur[arr[p]] = vid ;
    idx.push_back(p);
    for(int ch:adj[p]){
        if(vis[ch]) continue;
        dfs(ch) ;
    }
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i) scanf("%d",arr+i);
    while(m--){
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int ans = 0 ;
    for(int i=1;i<=n;++i){
        if(vis[i]) continue ;
        idx.clear() ;
        ++vid ;
        dfs(i) ;
        for(int j:idx)
            if(cur[j]==vid) ++ans ;
    }
    cout << ans ;
    return 0;
}


Measured memory_bytes: 10236
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <tuple>
#include <numeric>
using namespace std;

int main(int argc, char* argv[]){
	char cS[1000];
	char cT[1000];
	scanf("%s", cS);
	scanf("%s", cT);
	string S = cS;
	string T = cT;
//	printf("%d",S.size());
//	printf("%d",T.size());

	int match_max = 0;
	for(int i=0; i<(int)S.size()-(int)T.size()+1; i++){
		int match = 0;
		for(int j=0; j<(int)T.size(); j++){
//			printf("%c, %c\n", S[i+j], T[j]);
			if(S[i+j] == T[j]){
				match++;
				if(match > match_max){
					match_max = match;
				}
			}
		}
	}

	printf("%d\n", (int)T.size()-match_max);


}


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

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

	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0) {
			cout << " " << i;
		} else {
			for (int x = i; x > 0; x /= 10) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
			}
		}
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    int N,maxi,sum = 0;
    cin >> N;
    for(int i = 1;i <= N;i++){
        sum += i;
        maxi = i;
        if(sum >= N)break;
    }    
    for(int i = maxi;N > 0 && i >= 0;i--){
        if(N < i)continue;
        cout << i << endl;
        N -= i;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;
    int mx = 0;
    int cnt = 0;
    bool swap_flg = false;
    for( int i = min( a, b ) - 1; i < max( c, d ); ++i ) {
        if( s[i] != '#' ) {
            mx = max( cnt, mx );
            cnt = 0;

        } else {
            ++cnt;

        }
    }

    int tmx = 0;
    if( a < b && d < c ) {
        cnt = 0;
        int pos = b - 2;
        if( s[b] == '.' && s[b - 2] == '.' ) swap_flg = true;
        if( s[d] == '.' && s[d - 2] == '.' ) swap_flg = true;
        for( int i = b - 1; i < d; ++i ) {
            if( s[i] == '#' ) {
                tmx = max( cnt, tmx );
                cnt = 0;
            } else {
                ++cnt;

            }
        }

    } else if( b < a && c < d ){
        cnt = 0;
        int pos = a - 2;
        if( s[a] == '.' && s[a - 2] == '.' ) swap_flg = true;
        if( s[c] == '.' && s[c - 2] == '.' ) swap_flg = true;
        for( int i = a - 1; i < c; ++i ) {
            if( s[i] == '#' ) {
                tmx = max( cnt, tmx );
                cnt = 0;

            } else {
                ++cnt;

            }
        }
    }
    if( max( cnt, tmx ) > 2 ) swap_flg = true;
    if( mx > 1 ) cout << "No";
    else {
        if( ( a < b && d < c || b < a && c < d ) && !swap_flg ) cout << "No";
        else cout << "Yes";
        
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 592
//https://atcoder.jp/contests/abc137/tasks/abc137_c

#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stderr, stdin, BufRead, Write};

use std::iter::FromIterator;

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn sort_by_chars(a: &Vec<char>, b: &Vec<char>) -> Ordering {
    for (a_, b_) in a.iter().zip(b.iter()) {
        match a_.cmp(b_) {
            Ordering::Less => return Ordering::Less,
            Ordering::Greater => return Ordering::Greater,
            Ordering::Equal => (),
        }
    }
    Ordering::Equal
}

fn combinations(n: u64) -> u64 {
    (n * (n - 1)) / 2
}

fn main() {
    let n = read!(u64);
    let strings: Vec<String> = read!(String; n);

    let chars: Vec<Vec<char>> = strings.iter().map(|s| s.chars().collect()).collect();

    let mut sorted_chars = Vec::new();

    for mut word in chars {
        word.sort();
        sorted_chars.push(word);
    }

    sorted_chars.sort_by(sort_by_chars);

    let mut comb = 0;
    let mut count = 1;
    let mut prev_word: Vec<char> = (0..10).map(|_| ' ').collect();

    for w in sorted_chars {
        if w == prev_word {
            count += 1;
        } else {
            comb += combinations(count);
            count = 1;
        }
        prev_word = w;
    }

    comb += combinations(count);

    println!("{}", comb)
}


Measured memory_bytes: 24828
s=list(input())
n=len(s)

cta=0
for i in range(n):
  if s[i]!=s[n-1-i]:
    cta+=1

s2=s[0:(n-1)//2]
n2=len(s2)
ctb=0
m=(n-1)//2
for i in range(n2):
  if s2[i]!=s2[n2-1-i]:
    ctb+=1

s3=s[(n+3)//2-1:n+1]
n3=len(s3)
ctc=0
x=(n+3)//2
for i in range(n3):
  if s[i]!=s[n3-1-i]:
    ctc+=1

if cta==0 and ctb==0 and ctc==0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 39856
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N;
  cin >> N;
  vector<vector<pair<ll, ll>>> A(N);
  for (ll i = 0; i < N - 1; i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    A[a].emplace_back(b, i);
    A[b].emplace_back(a, i);
    // ここでiは行番号。
  }
  vector<ll> colors(N - 1);  // 答え格納用
  vector<ll> nodes(N, -1);   // -1は未訪問。
  // 幅優先探索
  queue<pair<ll, ll>> que;  // color, node
  que.push({-1, 0});        // color -1 は初回用
  while (!que.empty()) {
    ll prevcolor = que.front().first;
    ll node = que.front().second;
    que.pop();
    nodes[node] = 0;

    vector<ll> canusecolors(A[node].size() + 1);
    iota(begin(canusecolors), end(canusecolors), 1LL);
    sort(begin(canusecolors), end(canusecolors), greater<>());

    for (const auto& x : A[node]) {
      ll line = x.second;
      if (nodes[x.first] == 0) continue;
      // 色を塗る
      ll tail = canusecolors.back();
      canusecolors.pop_back();
      if (tail == prevcolor) {
        tail = canusecolors.back();
        canusecolors.pop_back();
      }
      colors[line] = tail;
      que.push({tail, x.first});
    }
  }
  ll maxNum = *max_element(begin(colors), end(colors));

  cout << maxNum << endl;
  for (const auto& x : colors) {
    cout << x << endl;
  }
  return 0;
}


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

const int N = 20;

char s[N];

int main(){
    scanf("%s", s);
    int n = strlen(s);
    int cnt = 15 - n;
    for (int i = 0; i < n; ++ i){
        cnt += s[i] == 'o';
    }
    puts(cnt >= 8 ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; ++i)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define P pair<int, string>

// 1 = a < b
// -1 = a > b
// 0 = a == b
int check(string a, string b){

  if(a == "NO" && b == "NO") return 0;
  else if(a == "NO") return -1;
  else if(b == "NO") return 1;

  int aa = 0, bb = 0;
  while(aa < a.length() && a[aa] == '0') aa++;
  while(bb < b.length() && b[bb] == '0') bb++;

  if(aa == a.length()) a = "0";
  else a = a.substr(aa);

  if(bb == b.length()) b = "0";
  else b = b.substr(bb);

  if(a.length() > b.length()) return 1;
  else if(a.length() < b.length()) return -1;
  else{
    REP(i, a.length()){
      if(a[i] - '0' > b[i] - '0') return 1;
      else if(a[i] - '0' < b[i] - '0') return -1;
    }
  }
  return 0;
}
int main() {
  int w, h;
  while(cin >>w >>h && w != 0){
    vector<string> v(h);
    REP(i, h) cin >>v[i];
    vector< vector<string> > dp(h + 1, vector<string>(w + 1, ""));
    REP(i, h) REP(j, w) if(isalpha(v[i][j])) dp[i + 1][j + 1] = "NO";

    REP(i, h){
      REP(j, w){
        int y = i + 1, x = j + 1;
        if(isalpha(v[i][j])) continue;
        //debug
        //cout <<"------------" <<endl;
        //cout <<"! " <<i <<", " <<j <<", " <<v[i][j] <<endl;
        //if(i != 0){
        //  cout <<v[i - 1][j] <<", ";
        //  cout <<dp[y - 1][x] <<endl;
        //}
        //if(j != 0){
        //  cout <<v[i][j - 1] <<", ";
        //  cout <<dp[y][x - 1] <<endl;
        //}

        dp[y][x] = v[i][j];

        if(dp[y - 1][x] != "NO"){
          dp[y][x] = dp[y - 1][x] + v[i][j];
        }
        if(dp[y][x - 1] != "NO" && check((dp[y][x - 1] + v[i][j]), dp[y][x]) == 1){
          dp[y][x] = dp[y][x - 1] + v[i][j];
        }
        //debug
        //cout <<dp[y][x] <<endl;
      }
    }
    //debug
    //FOR(i, 1, h + 1){
    //  FOR(j, 1, w + 1){
    //    cout <<i <<", " <<j <<endl;
    //    cout <<dp[i][j].first <<", " <<dp[i][j].second <<endl;
    //  }
    //}

    string ans = "0";
    REP(i, h + 1){
      REP(j, w + 1){
        if(check(dp[i][j], ans) == 1) ans = dp[i][j];
      }
    }

    int tmp = 0;
    while(tmp < ans.length() && ans[tmp] == '0') tmp++;
    if(tmp == ans.length()) ans = "0";
    else ans = ans.substr(tmp);
    cout <<ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1348
package main

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

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n, h, w := ri(), ri(), ri()
	ans := 0
	for i := 0; i < n; i++ {
		if a, b := ri(), ri(); a >= h && b >= w {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N;
	cin >> N;

	vector<pair<long long, long long>> info(N, make_pair(0, 0));

	for (int i = 0; i < N; i++)
	{
		int x, l;
		cin >> x >> l;

		info[i].first = x - l;
		info[i].second = x + l;
	}

	sort(info.begin(), info.end(), [](const pair<long long, long long>& l, const pair<long long, long long>& r)
	{
		if (l.second == r.second) return l.first < r.first;
		return l.second < r.second;
	});

	int result = 0;
	long long curr = -2e9;
	for (pair<long long, long long> e : info)
	{
		if (curr <= e.first)
		{
			curr = e.second;
			result++;
		}
	}

	cout << result;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    if(k==1){
        cout << 0<<endl;
    }
    else{
        cout << n-k<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main (){
    int n,x;
    scanf("%d",&n);
    for (int i = 1; i <= n; i++){
        x = i;
        if (x%3 == 0) {
            printf(" %d",i);
            continue;
        }
        do{
            if (x%10 == 3) {
                printf(" %d",i);
                break;
            }
            x /= 10;
        } while(x);
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2756
import sys
mod = 7 + 10 ** 9

def comb(n, r, fact, revfact, mod):
    return (fact[n] * revfact[n-r] * revfact[r]) % mod

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    Ad = dict()
    double = []
    for i, a in enumerate(A):
        if a in Ad:
            Ad[a].append(i)
            double = Ad[a]
        else: Ad[a] = [i]

    fact = [1] * (N + 2)
    for i in range(1, N + 2): fact[i] = (fact[i - 1] * i) % mod
    revfact = [1] * (N + 2)
    revfact[N + 1] = pow(fact[N + 1], mod - 2, mod)
    for i in reversed(range(1, N + 1)):revfact[i] = ((i + 1) * revfact[i + 1]) % mod
    mayOverCount = double[0] + N - double[1]
    
    for k in range(N + 1):
        total = comb(N + 1, k + 1, fact, revfact, mod)
        if k <= mayOverCount: 
            total += mod - comb(mayOverCount, k, fact, revfact, mod)
            total %= mod
        print(total)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 34844
import sys
input=sys.stdin.readline #文字列入力はするな！！



n,m=map(int,input().split())
ab=[[0,0] for i in range(m)]
for i in range(m):
    ab[i][0],ab[i][1]=map(int,input().split())


sys.setrecursionlimit(10**9) #再帰の上限をあげる

root=[-1 for i in range(n+1)] #自分が親なら自身の番号を、そうでないなら（元）親の番号を示す
def r(x):   #親は誰？
    if root[x]<0:
        return x
    else:
        root[x]=r(root[x])
        return root[x]


ans=n*(n-1)//2
d=[n*(n-1)//2]
for i in range(1,m+1):
    a,b=ab[-i][0],ab[-i][1]
    a=r(a)
    b=r(b)
    a,b=min(a,b),max(a,b)
    if a!=b:
        ans-=root[a]*root[b]
        root[a]+=root[b]
        root[b]=a
    d.append(ans)

for i in range(m):
    print(d[-2-i])


Measured memory_bytes: 96460
#include<bits/stdc++.h>
#define M 27
using namespace std;
int a[M];
int n;
bool solve(int r, int y){
	if(y==0){
		return true;
	}
	if(r>=n){
		return false;
	}
	
	return solve(r+1, y)||solve(r+1, y-a[r]);
}
int main(){
	
	cin >> n;
	
	int i;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	
	int q;
	cin >> q;
	int r;
	for(i = 0; i < q; i++){
		cin >> r;
		if(solve(0, r)){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}
	
	return 0;
} 


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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 1e5 + 5;
int app[2][MAX], arr[MAX];
int n;

int test(int a, int b) {
    if(a == b) {
        return 1 << 30;
    }
    int cost = 0;
    fori(i, 0, n) {
        if(i % 2 == 0) {
            cost += arr[i] != a;
        }
        else {
            cost += arr[i] != b;
        }
    }
    return cost;
}

int main() {
    scanf("%d", &n);
    fori(i, 0, n) {
        scanf("%d", arr + i);
        app[i & 1][arr[i]]++;
    }
    vector<ii> v[2];
    fori(i, 1, (int) 1e5 + 1) {
        v[0].emplace_back(app[0][i], i);
        v[1].emplace_back(app[1][i], i);
    }
    sort(v[0].begin(), v[0].end(), greater<ii>());
    sort(v[1].begin(), v[1].end(), greater<ii>());
    int ans = 1 << 30;
    fori(i, 0, 2) {
        fori(j, 0, 2) {
            ans = min(ans, test(v[0][i].second, v[1][j].second));
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define size_t szt
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

int K;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> K;
  if(K % 2 == 0){
    cout << K * K / 4 << endl;
  }
  else{
    cout << (K / 2 ) * (K / 2 + 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int
main(){
  int d;
  scanf("%d\n",&d);
  int array[d];
  int j = 0;
   for (int i = 0; i < d ;i++){
    int a,b;
    char s[1000];
    fgets(s,999,stdin);
    char* tp;
    tp = strtok(s," ");
   
    a = atoi(tp);
    while(tp = strtok(NULL," ")){
      b = atoi(tp);
    }
    if(a == 0){
      array[i-j] = b;
    }else if(a == 1){
      j++;
      printf("%d\n",array[b]);
      
    }else if(a == 2){
      j += 2;
    }
  }

  
    return 0;
}



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

using namespace std;

int main()
{
	

	int n; cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; ++i) cin >> v[i];
	sort(v.begin(), v.end());

	int index = 0;
	set<int> s;
	long long int ans = 0;
	vector<int> dp(1000001, 1);
	int limit = 1000000;
	while(index < n)
	{
		int cur = index;
		int next = index+1;
		while((next < n) and (v[cur] == v[next]))
		{
			++next;
		}
		int sameCnt = next - cur;
		
		int x = v[cur];
		int y = 2*x;

		if(dp[x] and (sameCnt == 1)) ++ans;

		while(y <= limit)
		{
			dp[y] = 0;
			y += x;
		}
		index = next;
	}
	cout << ans;
	return 0;
}

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

int sig(int n){
	return (n * (n + 1) / 2);
}

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

	for(int i = 1; i <= x; ++i){
		if(x <= sig(i)){
			cout << i <<endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>=1;
    }
    return res;
}



int main(){
    ll a,b,v,w,t;
    cin >> a >> v >> b >> w >> t;
    ll diff = abs(a-b);
    ll ve = v-w;
    if(diff <= ve*t){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}



Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            long n = IO.RLong;
            double root = Sqrt(n);
            //O(10^6)
            long j = 0;
            long k = 0;
            for (long i = (long)root; i > 0; i--)
            {
                if (n % i == 0)
                {
                    k = i;
                    j = (long)n / i;
                    break;
                }
            }
            WriteLine(k + j - 2);
        }

        public class IO
        {
            #region Input
            public static int RInt => int.Parse(ReadLine());
            public static long RLong => long.Parse(ReadLine());
            public static double RDouble => double.Parse(ReadLine());

            public static string[] RSString => ReadLine().Split();
            public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
            public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
            #endregion

            #region Output
            public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
            public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
            public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
            #endregion
        }

        public class Mod
        {
            #region
            private readonly static long M = 1000000007;

            public static long Add(long a, long b) => (a * b) % M;
            public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
            public static long Multi(long a, long b) => (a * b) % M;
            #endregion
        }

        public static int GCD(int x, int y)
        {
            if (x < y) Swap(ref x, ref y);
            if (y == 0) return x;
            else return GCD(x % y, y);
        }

        public static void Swap(ref int x, ref int y)
        {
            int tmp = x;
            x = y;
            y = tmp;
        }

        public static long Choice2(long n)
        {
            #region
            if (n <= 1)
                return 0;
            if (n == 2)
                return 1;
            else
                return n * (n - 1) / 2;
            #endregion
        }
    }
}

Measured memory_bytes: 13140