akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)

int main() {
    int n;
    cin >> n;
    int ans = 1;
    int sa = n-1;
  
    for(int i = 2; i < 32; i++) {

        int tmp = i;
      
      	//cout << "i: " << i << endl;

        while(n >= i*i && tmp <= 1000) {
          	//cout << " tmp: " << tmp << endl;
          	int tmp1 = n - tmp;
          
          	if(tmp <= n) {
              //cout << "  sa: " << sa << ' ';  
              //cout << "tmp1: " << tmp1 << endl;
              sa = min(sa, tmp1);
              //cout << "  sa: " << sa << ' ';  
              //cout << "tmp1: " << tmp1 << endl;
              if(sa == tmp1) ans = tmp;
              tmp = tmp*i;
              //cout << "  ans: " << ans << endl;
            }else{
              	//cout << "  break" << endl;
            	break;
            }
          
        }

    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())
S = '#' + input()

if '##' in S[A: C] or '##' in S[B: D]:
    print('No')
    exit(0)

if C > D:
    if '...' not in S[B - 1: D + 2]:
        print('No')
        exit(0)

print('Yes')


Measured memory_bytes: 3572
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

struct SegT {
private:
	int n; vector<vec> node;
	vector<vec> lazy;
	vec e;
public:
	SegT(vector<int> v) {
		int sz = v.size();
		n = 1;
		while (n < sz)n <<= 1;
		vec t(10, 0);
		node.resize(2 * n - 1, t);
		e.resize(10);
		rep(i, 10) {
			e[i] = i;
		}
		lazy.resize(2 * n - 1, e);
		rep(i, sz) {
			node[i + sz - 1][v[i]]++;
		}
		per(i, sz - 1) {
			node[i] = f(node[2 * i + 1], node[2 * i + 2]);
		}
	}
	vec f(vec &a, vec &b) {
		vec ret(10,0);
		rep(i, 10) {
			ret[i] = a[i] + b[i];
		}
		return ret;
	}
	//lazy & lazy
	vec g(vec &a, vec &b) {
		vec ret(10);
		rep(i, n) {
			ret[i] = a[b[i]];
		}
		return ret;
	}
	void eval(int k, int l, int r) {
		vec nex(10, 0);
		rep(i, 10) {
			nex[lazy[k][i]] += node[k][i];
		}
		node[k] = nex;
		if (r - l > 1) {

		}
	}
};

struct uf {
private:
	vector<int> par, ran;
public:
	uf(int n) {
		par.resize(n, 0);
		ran.resize(n, 0);
		rep(i, n) {
			par[i] = i;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return;
		if (ran[x] < ran[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (ran[x] == ran[y])ran[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int n, m;

struct edge {
	int a, b; ld cost, dist;
};
vector<edge> v;

void solve() {
	cin >> n >> m;
	v.resize(m);
	rep(i, m) {
		int a, b;ld c, d; cin >> a >> b >> c >> d;
		v[i] = { a,b,c,d };

	}
	ld le = 0, ri = 2000000;
	rep (aa,50) {
		ld mid = (le + ri) / 2.0;
		vector<pair<ld, P>> a;
		uf u(n);
		rep(i, m) {
			ld score = v[i].dist - v[i].cost*mid;
			a.push_back({ score,{v[i].a,v[i].b} });
		}
		sort(a.begin(), a.end(),greater<pair<ld,P>>());
		ld sum = 0;
		rep(i, m) {
			int l = a[i].second.first, r = a[i].second.second;
			sum += a[i].first;
			if (!u.same(l, r)) {
				u.unite(l, r);
				sum -= a[i].first;
			}
		}
		if (sum <= 0) {
			ri = mid;
		}
		else {
			le = mid;
		}
	}
	cout << ri << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(6);
	solve();
	//stop
		return 0;
}


Measured memory_bytes: 4252
open Scanf

let rec for_iter_ a b f = if a >= b then () else (f a; for_iter_ (a+1) b f)

let min_dists num start graph =
  let res = Array.make num (-1) in
  let rec trav v p d =
    res.(v) <- d;
    List.iter (fun (w, c) -> if w <> p then trav w v (d + c)) graph.(v) in
  trav start (-1) 0;
  res

let () =
  let n = scanf "%d" (fun i -> i) in
  let edges = Array.init (n-1) (fun _ -> scanf " %d %d %d" (fun a b c -> a, b, c)) in
  let graph = Array.init (n+1) (fun _ -> []) in
  Array.iter (fun (a, b, c) ->
    graph.(a) <- (b, c) :: graph.(a);
    graph.(b) <- (a, c) :: graph.(b)) edges;

  let q, k = scanf " %d %d" (fun q k -> q, k) in
  let dists = min_dists (n+1) k graph in
  for_iter_ 0 q (fun _ ->
    let x, y = scanf " %d %d" (fun x y -> x, y) in
    Printf.printf "%d\n" (dists.(x) + dists.(y)))


Measured memory_bytes: 29184
#include<stdio.h>
int main()
{
	int a, b, c, d, e, k;
	
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);	
	scanf("%d", &d);
	scanf("%d", &e);
	scanf("%d", &k);
	
	if(e-a > k){
	printf(":(");
	}
	
	else printf("Yay!");
	
	return 0;
	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
#define MOD 1000000007
#define MSG(a) cout << #a << " " << a << endl;
#define print(a) cout << a << endl;
template <class T, class C>
void chmax(T &a, C b)
{
    if (a <= b)
        a = b;
}
template <class T, class C>
void chmin(T &a, C b)
{
    if (a >= b)
        a = b;
}

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

template <class T>
T sum(const vector<T> &v)
{
    T res = 0;
    for (size_t i = 0; i < v.size(); ++i)
        res += v[i];
    return res;
}
// vector の出力
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v)
{
    size_t last = v.size() - 1;
    for (size_t i = 0; i < v.size(); ++i)
    {
        out << v[i];
        if (i != last)
            out << " ";
    }
    return out;
}

int main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //////////////////////////////////////////

    // string a, b;
    // cin >> a >> b;
    int h, w, n;
    cin >> h >> w >> n;
    
    int a[n];
    rep(i, n)
    {
        cin >> a[i];
    }
    int x = 0;
    int xi = 0;
    vector<int> ans(w);

    rep(i, h)
    {
        rep(j, w)
        {
            if (i % 2 == 0)
            {
                ans[w - j - 1] = x + 1;
            }
            if (i % 2 == 1)
            {
                ans[j] = x + 1;
            }

            xi += 1;
            if (xi >= a[x])
            {
                x += 1;
                xi = 0;
            }
        }
        print(ans);
    }

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <iterator>
#include <queue>
#include <vector>

using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    vector<queue<int>> A(n);
    int x, y, z;
    for(int i = 0; i < q; i++){
        cin >> x;
        if(x == 0){
            cin >> y >> z;
            A[y].push(z);
        }else if(x == 1){
            cin >> y;
            if(A[y].empty()){
                continue;
            }else{
                cout << A[y].front() << "\n";
            }
        }else{
            cin >> y;
            if(A[y].empty()){
                continue;
            }else{
                A[y].pop();
            }
        }
    }

    return 0;
}


Measured memory_bytes: 4240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int X;
  cin>>X;
  if(X>=30) cout<<"Yes\n";
  else cout<<"No\n";
}


Measured memory_bytes: 3588
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  if p[i]!=max(p[i-1],p[i],p[i+1]) and p[i]!=min(p[i-1],p[i],p[i+1]):
    ans=ans+1
print(ans)

Measured memory_bytes: 3060
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Digit Sums
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  int sum = 0;
  for (int m = n; m > 0; m /= 10) sum += m % 10;

  if (n % sum == 0) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

template <class T>
vector<T> sumup(const vector<T>& a) {
  int N = a.size();
  vector<T> res(N + 1);
  for (int i = 0; i < N; i++) res[i + 1] = res[i] + a[i];
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<ll> A(N);
    for (ll& x : A) cin >> x;
    ll S = accumulate(A.begin(), A.end(), 0ll);
    ll res = 1ll << 60;
    ll F = 0;
    for (int i = 0; i < N - 1; i++) {
      F += A[i];
      S -= A[i];
      chmin(res, abs(F - S));
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1920
import sys

input = sys.stdin.readline

def main():
    ans = 'No'
    N = int(input())
    c = 0
    for _ in range(N):
        d1, d2 = map(int, input().split())
        if d1 == d2:
            c += 1
            if c >= 3:
                ans = 'Yes'
                break
        else:
            c = 0

    print(ans)

if __name__ == '__main__':
    main()

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

template<typename D, typename F> class BinarySearch {
    D left;
    D right;
    F func;

    public:
        BinarySearch(D l, D r, F f) {
            left = l;
            right = r;
            func = f;
        }

        D calc() {
            while (abs(right - left) > 1) {
                ll m = (left + right) / 2;
                if (func(m)) {
                    right = m;
                } else {
                    left = m;
                }
            }
            return right;
        }
};
 
void solve() {
    int n;
    ll k;
    cin >> n >> k;

    vector<ll> a(n);
    vector<ll> f(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> f[i];
    sort(ALL(a));
    sort(ALL(f), greater<int>());

    auto isOk = [&](ll m) {
        ll x = k;
        bool b = true;
        REP(i, n) if (a[i] * f[i] > m) {
            x -= a[i] - m / f[i];
            if (x < 0) {
                b = false;
                break;
            }
        }
        return b;
    };

    BinarySearch<ll, function<bool(ll)>> bs = BinarySearch<ll, function<bool(ll)>>(-1LL, LINF, isOk);
    cout << bs.calc() << EOL;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

int A, B;
string ans;

signed main() {
	cin >> A >> B;

	if (A <= 8 && B <= 8) {
		ans = "Yay!";
	}
	else {
		ans = ":(";
	}

	

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll D = 1000000007;
int main(){
  	int N, M;
  	cin >> N >> M;
    bool safe[N+1];
    for(int i=0;i<=N;i++) safe[i] = true;

    for(int i=0;i<M;i++){
        int a;
        cin >> a;
        safe[a] = false;
    }

    ll pat[N+1];
    pat[0] = 1;
    if(safe[1]){
        pat[1] = 1;
    }else{
        pat[1] = 0;
    }

    for(int i=2;i<=N;i++){
        if(safe[i]){
            pat[i] = pat[i-1] + pat[i-2];
            pat[i] = pat[i]%D;
        }else{
            pat[i] = 0;
        }
    }
    cout << pat[N] <<endl;


  	return 0;
}


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

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

using namespace std;

const int IINF = INT_MAX;

bool converter(int value,int base,string &s){
  string ret = "";
  while( value >= base ){
    int tmp = value % base;
    value /= base;
    if( 0 <= tmp && tmp <= 9 ) ret += string(1,(char)('0'+tmp));
    else                       return false;
  }
  if( value != 0 ) {
    int tmp = value;
    if( 0 <= tmp && tmp <= 9 ) ret += string(1,(char)('0'+tmp));
    else                       return false;
  }
  if( ret.empty() ) ret = "0";
  reverse(ret.begin(),ret.end());
  s = ret;
  return true;
}

string itos(int i) { stringstream ss; ss << i; return ss.str(); }

int main(){
  int A,C;
  string B;
  while( cin >> A >> B >> C ){
    if( A == -1 && B == "-1" && C == -1 ) break;
    string boarder = B;
    bool failed = false;
    REP(age,A,C+1){
      //cout << age << " " << boarder << endl;
      int nebear = IINF;
      REP(base,2,17){
        string tmp = "";
        if( !converter(age,base,tmp) ) continue;
        if( age == A && tmp != boarder ) continue;
        else {
          int boar = (atoi)(boarder.c_str());
          int curr = (atoi)(tmp.c_str());
          if( boar > curr ) continue;
          nebear = min(nebear,curr);
        }
      }
      if( nebear == IINF ) failed = true;
      if( failed ) break;
      boarder = itos(nebear);
    }
    if( failed ) puts("-1");
    else cout << boarder << endl;
  }
  return 0;
}

Measured memory_bytes: 1244
n = int(input())
a = list(map(int, input().split()))
if a[0] == 0:
    ans1 = 1
    tmp = 1
else:
    ans1 = 0
    tmp = a[0]
is_plus = tmp > 0
for i in range(1, n):
    tmp += a[i]
    if is_plus == (tmp > 0):
        ans1 += abs(tmp) + 1
        if is_plus:
            tmp = -1
        else:
            tmp = 1
        is_plus = tmp > 0
    else:
        is_plus = tmp > 0

ans2 = abs(a[0]) + 1
if a[0] == 0:
    ans2 = 1
    tmp = -1
else:
    ans2 = abs(a[0]) + 1
    tmp = -a[0] // abs(a[0])
is_plus = tmp > 0
for i in range(1, n):
    tmp += a[i]
    if is_plus == (tmp > 0):
        ans2 += abs(tmp) + 1
        if is_plus:
            tmp = -1
        else:
            tmp = 1
        is_plus = tmp > 0
    else:
        is_plus = tmp > 0

print(min(ans1, ans2))


Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int n,m;cin>>n>>m;
    int sum=0;
    sum+=n*(n-1)/2;
    sum+=m*(m-1)/2;
    cout<<sum<<endl;

}

Measured memory_bytes: 3596
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include <algorithm>

using namespace std;
int n, m;
int a;
int M[1000][1000];
int H;

int solve(){
	int px = a; 
	int py = H;
	for (; py >= 0; py--){
		if (M[px][py] != -1){
			px =  M[px][py];
		}
	}
	return px;
}

int main(void)
{
	while (1){
	cin >> n >> m >> a;
	if (!n) break;
	for (int i = 0; i < n+1; i++){
		for (int j = 0; j < 1000; j++){
			M[i][j] = -1;
		}
	}
	H = 0;
	for (int i = 0; i < m; i++){
		int p, q, h;
		cin >> h >> p >> q;
		M[p][h] = q;
		M[q][h] = p;
		H = max(H, h);
	}

	cout << solve() << endl;
	}

	return 0;

}

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

int main(){
	int n;
	int a[100002];
	int res = 0;
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}
	for(int i = 0;i < n;i++){
		if(a[i] == 0)continue;
		else if(a[a[i]] == i){
			res++;
			a[i] = a[a[i]] = 0;
		}
	}
	cout << res <<endl;
	return 0;
}

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

// types - only for stuff used a lot 
using ll = long long;
#define vv vector
#define Pp pair

// IO
#define get(x) scanf("%d",&x)
#define getl(x) scanf("%d",&x);

// Operations
#define pb push_back
#define pob pop_back
// for those annoying warnings
#define sz(a) int(a.size()) 

// Debugging

#ifndef LOCAL
#define cerr if (0) cerr
#else
#define cerr cout
#endif

#define print(arr,n) {for (int _ = 0; _ < n; _++) cerr<<arr[_]<<" "; cerr << endl; }
#define printv(vec)  {for (int _ : vec) cerr<<_<<" "; cerr<<endl;}

const bool DEBUG = 1;
const ll oo = 1e18;

const int mxn = 1e5;
int n,X;
int a[mxn],b[mxn],f[mxn],p[mxn];

ll D(int i, int g) {
	if (g < f[i]) return -1LL*a[i]*(f[i]-g);
	else return 1LL*b[i]*(g-f[i]);
}

ll func(int i) {
	return D(i,X)-D(i,0);
}

bool check(ll m) {
	int q = min(n*1LL,m/X), r = min(m%X,1LL*X);	
	if (q==n) return 1;
	ll pos = 0;
	// one of the chosen to be reduced
	for (int i = 0; i < q+1; i++)
		pos += D(p[i],X);
	for (int i = q+1; i < n; i++)
		pos += D(p[i],0);
	for (int i = 0; i < q; i++)
		if (pos+D(p[i],r)-D(p[i],X)>=0)
			return 1;
	pos = 0;
	for (int i = 0; i < q; i++)
		pos += D(p[i],X);
	for (int i = q; i < n; i++) 
		pos += D(p[i],0);
	if (pos>=0) return 1;
	for (int i = q; i < n; i++)
		if (pos+D(p[i],r)-D(p[i],0)>=0) return 1;	
	return 0;
};


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	if (DEBUG) freopen("input.txt", "r", stdin);
	if (DEBUG) freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	get(n); get(X);
	auto cmp = [&](int i, int j) {return func(i)>func(j);};

	for (int i = 0; i < n; i++) {
		get(f[i]);
		get(a[i]); 
		get(b[i]);
		p[i]=i;
	}
	sort(p,p+n,cmp);
	ll lo = 0, hi = oo;
	while (lo<=hi) {
		ll m = (lo+hi)/2;
		if (check(m)) hi = m-1;
		else lo = m+1;
	}

	cout << lo << endl;


#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int X;
  cin >> X;
  for (int a = 1; a < 1000; a++){
    ll a5 = 1;
    rep(i,5) a5 *= a;
    for (int b = -1000; b < 1000; b++){
      ll b5 = 1;
      rep(i,5) b5 *= b;
      if (a5 - b5 == X){
        cout << a << " "  << b << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3592
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std; 

using namespace std;
 
typedef long long LL;
 
typedef pair<LL,LL> p;
typedef pair<LL,p> pp;

 
template <typename T>
class UF{
public:
	vector<T> par,rank;
 
	UF(T n){
		par.resize(n);
		rank.resize(n);
		for(T i=0;i<n;i++){
			par[i]=i;
			rank[i]=0;
		}
	}
 
	T find(T x){
		if(par[x]==x)
			return x;
		else
			return par[x]=find(par[x]);
	}
 
	bool unite(T x, T y){
		x=find(x);
		y=find(y);
		if(x==y) return false;
 
		if(rank[x]<rank[y])
			par[x]=y;
		else{
			par[y]=x;
			if(rank[x] == rank[y]) rank[y]++;
		}

		return true;
	}
 
	bool same(T x, T y){
		return find(x)==find(y);
	}
 
};

int main(){

	int n;
	cin>>n;

	vector<long long> x(n),y(n);
	vector< p > xi(n),yi(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		x[i]--,y[i]--;
		xi[i]=p(x[i],i);
		yi[i]=p(y[i],i);
	}

	sort(xi.begin(),xi.end());
	sort(yi.begin(),yi.end());

	vector<pp> edge;
	for(int i=0;i<n-1;i++){
		int from=xi[i].second;
		int to=xi[i+1].second;
		long long cost = min( abs(x[from]-x[to]),abs(y[from]-y[to]) );
		edge.push_back( pp(cost,p(from,to) ));
	}

	for(int i=0;i<n-1;i++){
		int from=yi[i].second;
		int to=yi[i+1].second;
		long long cost = min( abs(x[from]-x[to]),abs(y[from]-y[to]) );
		edge.push_back( pp(cost,p(from,to) ));
	}

	sort(edge.begin(),edge.end());

	UF<long long> uf(n);
	long long res=0;
	for(int i=0;i<edge.size();i++){

		int from=edge[i].second.first;
		int to=edge[i].second.second;
		long long cost=edge[i].first;

		if( uf.unite(from,to) )	res+=cost;

	}
	//cout<<uf.same(0,1)<<uf.same(1,2)<<uf.same(0,2)<<endl;
	cout<<res<<endl;

	return 0;
}


Measured memory_bytes: 13040
N = int(input().strip())
A = list(map(int,input().strip().split(' ')))


import statistics
import math
def kanashimi(b):
    
    out = 0
    for i in range(N):
        out = out + abs(A[i]-(b+(i+1)))
    return out 
  
B = [A[i]-(i+1) for i in range(N)]
b = statistics.median(B)

print(int(kanashimi(b)))


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s;
  cin >> s;
  int n = s.size();
  vi32 cost(n + 1);
  queue<int> q;
  repc(i, n) {
    bool ok = true;
    if (i > 0 && s[i - 1] == '<') ok = false;
    if (i < n && s[i] == '>') ok = false;
    if (ok) q.emplace(i);
  }
  while (q.size()) {
    int v = q.front(); q.pop();
    if (v > 0 && s[v - 1] == '>') {
      q.emplace(v - 1);
      cost[v - 1] = cost[v] + 1;
    }
    if (v < n && s[v] == '<') {
      q.emplace(v + 1);
      cost[v + 1] = cost[v] + 1;
    }
  }
  i64 ans = 0;
  repc(i, n) ans += cost[i];
  cout << ans << endl;
}


Measured memory_bytes: 3740
#include<iostream>
using namespace std;
int main(){
  int h,w;
  while(1){
    cin>>h>>w;
    if(h==0)break;
    int d=h*h+w*w,ah=100,aw=100;
    for(int i=1;i<=150;i++)
      for(int j=i+1;j<=150;j++){
	int k=i*i+j*j;
	if(((k==d&&i>h)||k>d)&&(ah*ah+aw*aw>k||(k==ah*ah+aw*aw&&ah>i)))ah=i,aw=j;
 }
    cout<<ah<<' '<<aw<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k;
  int c[100][100],t[100][100],m,n,o;
  while(cin>>n>>m&&n+m){
    for(i=0;i<m;i++){
      for(j=0;j<m;j++){
	c[i][j]=10000;
	t[i][j]=10000;
      }
    }
    for(i=0;i<n;i++){
      int p,q,r,s;
      cin>>p>>q>>r>>s;
      p--;
      q--;
      c[p][q]=min(c[p][q],r);
      c[q][p]=c[p][q];
      t[p][q]=min(t[p][q],s);
      t[q][p]=t[p][q];
    }
    for(k=0;k<m;k++){
      for(i=0;i<m;i++){
	for(j=0;j<m;j++){
	  c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
	  t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
	}
      }
    }
    cin>>o;
    for(i=0;i<o;i++){
      int p,q,r;
      cin>>p>>q>>r;
      p--;
      q--;
      if(r)
	cout<<t[p][q]<<endl;
      else
	cout<<c[p][q]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define MAX 10000007
#define PI acos(-1)
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define endl "\n"
#define MEM(a,x) memset(a,x,sizeof(a))

using namespace std;
typedef long long ll ;
const int INF= 1e9+7;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<long long,null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
{
    return (a.second<b.second);
}
*/
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.tie(NULL);
    int n;
    cin>>n;

    double ans=0;

    while(n--)
    {
        double amount;
        string s;

        cin>>amount>>s;

        if(s=="JPY")
            ans+=amount;
        else
        {
            ans+=(amount*380000.0);
        }
    }

    cout<<fixed<<setprecision(10)<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N;
    cin >> N;
    vector<vector<long long>> a(N, vector<long long>(N));
    REP(i, N) REP(j, N)
        cin >> a[i][j];
    vector<long long> dp(1<<N);
    REP(i, 1<<N) REP(j, N) REP(k, j+1, N)
        if((i & (1<<j)) && (i & (1<<k)))
            dp[i] += a[j][k];

    REP(i, 1<<N){
        for(int j=i; j>0; j=(j-1)&i){
            int k = i ^ j;
            dp[i] = max(dp[i], dp[j] + dp[k]);
        }
    }
    cout << dp[(1<<N)-1] << endl;
    return 0;
}

Measured memory_bytes: 896
from collections import Counter

NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]

d = list()
A = list()
for _ in range(K):
	d.append(int(input()))
	A.append(list(map(int, input().split())))

lst = Counter(num for sublst in A for num in sublst)
allLst = [0] * N
for sunuke, cnt in sorted(lst.items(), key=lambda x: x[0]):
	allLst[sunuke - 1] = cnt

print(allLst.count(0))

Measured memory_bytes: 9468
#include<bits/stdc++.h>
#include<cstring>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int           long long
#define umapii        unordered_map<int,int>
#define ps(x,y)       fixed<<setprecision(y)<<x // sets precision upto required digits
#define arr(a,n)      int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];}
#define outarr(a,n)   for(int i=0;i<n;i++){cout<<a[i]<<" ";}
#define mod           1000000007
#define ff            first
#define big           1e15
#define ss            second
#define add           push_back
#define remove        pop_back
#define mapii         map<int,int>
#define large         *max_element
#define small         *min_element
#define float         double
#define pqi           priority_queue<int>
#define mpqi          priority_queue<int,vector<int>,greater<int>>
#define in(n)         int n;cin>>n;
#define w(t)          int t;cin>>t;while(t--)
#define vi            vector<int>
#define vivi          vector<vector<int>>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>pbds;




int32_t main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output3.txt", "w", stdout);
#endif
    string s, t;
    cin >> s >> t;
    int x = s.size() - t.size() + 1;
    int ans = INT_MIN;
    for (int i = 0; i < x; i++) {
        int cnt = 0;
        int j = i;
        int k = 0;
        while (j < i + t.size() and k < t.size()) {
            if (s[j] == t[k]) {
                cnt++;
            }
            j++;
            k++;
        }
        ans = max(ans, cnt);
    }
    cout << t.size() - ans << endl;


}


Measured memory_bytes: 3392
N=[input() for i in range(int(input()))]
M=[input() for i in range(int(input()))]
point={}

for i in N:
    if i not in point:
        point[i]=1
    else:point[i] +=1

for i in M:
    try:
        point[i] -=1
    except:continue

ans=max(point.values())
print(ans if ans>0 else 0)

Measured memory_bytes: 38256
#include<iostream>
using namespace std;
int a,b;
int gcd(int x,int y){
	if(x < y) swap(x,y);
	if(y != 0){
		int z = x % y;
		gcd(y,z);
	}else{
		return x;
	}
}
int main(){
	cin >> a >> b;
	cout << gcd(a,b) << endl;
}


Measured memory_bytes: 3088
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs.shift());
const adj = inputs.map((s) => s.split(' ').map(Number));

class Queue {
  constructor() {
    this.list = [];
  }
  enqueue(item) {
    this.list.push(item);
  }
  dequeue() {
    return this.list.shift()
  }
}

class Node {
  constructor(id) {
    this.id = id;
    this.list = [];
    this.params = new Map();
  }
  add(node) {
    this.list.push(node);
  }
  get(key) {
    return this.params.get(key);
  }
  set(key, value) {
    return this.params.set(key, value);
  }
  has(key) {
    return this.params.has(key);
  }
  toString() {
    return [this.id, this.has('depth') ? this.get('depth') : -1].join(' ');
  }
}

class Graph {
  constructor() {
    this.map = new Map();
    this.queue = new Queue();
  }
  setNode(node) {
    this.map.set(node.id, node);
  }
  hasNode(id) {
    return this.map.has(id);
  }
  getNode(id) {
    return this.map.get(id);
  }
  bfs() {
    const node = this.queue.dequeue();
    if (!node) {
      return;
    }

    node.list.forEach(_node => {
      if (_node.has('depth')) {
        return;
      }
      _node.set('depth', node.get('depth') + 1);
      this.queue.enqueue(_node);
    });
    this.bfs();
  }
  print() {
    for (let i = 1; i <= this.map.size; i++) {
      const node = this.map.get(i);
      console.log(node.toString());
    }
  }
}

const tree = new Graph();

adj.forEach(([id, k, ...ck]) => {
  tree.hasNode(id) || tree.setNode(new Node(id));
  const node = tree.getNode(id);
  ck.forEach(c => {
    tree.hasNode(c) || tree.setNode(new Node(c));
    const _node = tree.getNode(c);
    node.add(_node);
  });
});

const root = tree.getNode(1);
root.set('depth', 0);
tree.queue.enqueue(root);
tree.bfs();

tree.print();



Measured memory_bytes: 16864
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int X = Integer.parseInt(sc.next());

        int result = 0;
        for (int i = 0; i <= A; i++) {
            for (int j = 0; j <= B; j++) {
                int c = (X - i * 500 - j * 100) / 50;
                if (c >= 0 && c <= C) result++;
            }
        }
        System.out.println(result);
    }
}

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

int n,m,cnt[26],a4,a2,a1;
char ch;

void work()
{
	scanf("%d %d",&n,&m);
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++)
			{
				do  ch=getchar();  while ((ch<'a')||('z'<ch));
				cnt[ch-'a']++;
			}
	a4=(n/2)*(m/2),a2=(n&1)*(m/2)+(m&1)*(n/2),a1=(n&1)*(m&1);
	for (int i=0; i<26&&a1; i++)  if (cnt[i]&1)  cnt[i]--,a1--;
	for (int i=0; i<26; i++)  if (cnt[i]&1)  puts("No"),exit(0);
	for (int i=0; i<26&&a2; i++)  if (cnt[i]&2)  cnt[i]-=2,a2--;
	if (a2&1)  puts("No"),exit(0);
	for (int i=0; i<26; i++)  if (cnt[i]&2)  puts("No"),exit(0);
	puts("Yes");
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    int mod = 1000000007;
    int n, m;
    cin >> n >> m;

    vector<long long> ans(n+1, 0);
    ans[0] = 1;
    for (int i=0; i<m; ++i) {
        int a;
        cin >> a;
        ans[a] = -1;
    }

    for (int i=1; i<=n; ++i) {
        if (ans[i] == -1) continue;

        if (ans[i-1] != -1)
            ans[i] += ans[i-1];
        if (i-2 >= 0 && ans[i-2] != -1)
            ans[i] += ans[i-2];
        ans[i] %= mod;
    }
    cout << ans[n]%mod <<  endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int max = 0;
    int len = s.size();
    int i, j;
    rep(i, len) {
      int count = 0;
      if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') {
        count++;
        j = i + 1;
        while (1) {
          if (s[j] == 'A' || s[j] == 'T' || s[j] == 'G' || s[j] == 'C') {
            count++;
            j++;
          } else {
            break;
          }
        }
        max = count > max ? count : max;
      }
    }

    cout << max << '\n';

    return 0;
}


Measured memory_bytes: 256
def binsearch(good, bad, fn):
    while abs(good - bad) > 1:
        m = (good + bad) // 2
        if fn(m):
            good = m
        else:
            bad = m
    return good

def solve(a, b):
    if a > b:
        a, b = b, a
    if a == b:
        return 2 * (a - 1)
    t = binsearch(1, a * b, lambda x: (x + 1) // 2 * (x // 2 + 1) < a * b)
    return t - 1

def main():
    Q = int(input())
    for _ in range(Q):
        a, b = map(int, input().split())
        print(solve(a, b))

if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;

int main(){
    ll a,b;
    ll k;
    cin >> a >> b;
    if( (a+b)%2 == 1 ) cout << "IMPOSSIBLE" << endl;
    else{
        if( a > b ) cout << (a+b)/2 << endl;
        else cout << (b+a)/2 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>

using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using intpv=vector<intpair>;
using llpair=pair<ll,ll>;
using llpv=vector<llpair>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;
using pairmat=vector<llpv>;

template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())
#define matin(mat,H,W) for(int i__=0; i__<H; i__++)for(int j__=0; j__<W; j__++) cin>>mat[i__][j__]
#define out(n) cout<<n<<endl

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

template<class T>
inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

template<class T>
inline void init(T& v) {
	for(auto &a__: v) cin>>a__;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a__: v) cin>>a__;
}

template<class N> void resiz(N n) {} // empty
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll GCD(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll binpow(ll a, ll ex, ll p) { //繰り返し二乗法
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}

ll Fact(ll x, ll p) { //階乗
	ll f=1;
	for(ll i=2; i<=x; i++) {
		f*=i;
		f%=p;
	}
	return f;
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll div=1LL;
	while(n/div) {
		digit++;
		div*=10;
	}
	return digit;
}


int N;
intvec P;
intvec ser;

void input() {
	cin>>N;
	init(P,N);
	ser.resize(N+1,0);
}

void solve() {
	for(int i=0; i<N; i++) {
		ser[P[i]]=ser[P[i]-1]+1;
	}
	
	int lser=-1;
	for(int i=1; i<=N; i++) chmax(lser,ser[i]);

	cout<<N-lser<<endl;
}

int main() {
	while(1) {
		input();
		solve();
		break;
	}
}


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

using namespace std;

long long mm = 1000000007;

int main()  {
    int n,m;
    scanf("%d%d",&n,&m);
    long long mul = -(n-1),a,sum=0;
    for ( int c=1 ; c<=n ; c++ )
    {
        cin >> a;
        sum += a*mul;
        sum %= mm;
        mul += 2;
    }
    long long sum2 = 0;
    mul = -(m-1);
    for ( int c=1 ; c<=m ; c++ )
    {
        cin >> a;
        sum2 += a*mul;
        sum2 %= mm;
        mul += 2;
    }
    cout << (sum*sum2) % mm;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

const int MAX = 200005;

int main() {
    int n; scanf("%d", &n);
    int a[MAX];
    int i;
    for (i = 0; i < n; ++i) scanf("%d", a + i);
    long long ans = 0;
    int cur_max = a[0];
    for (i = 1; i < n; ++i) {
        if (a[i] > cur_max) {
            cur_max = a[i];
        } else {
            ans += (cur_max - a[i]);
        }
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 2480
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1; char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=520;
const int mod=1e9+7;

inline int power (int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=(ll)ans*a%mod;
		b>>=1;
		a=(ll)a*a%mod;
	}
	return ans;
}

int n,c[maxn],X;
int jc[maxn<<1],jcn[maxn<<1],inv[maxn<<1];

inline void init()
{
	n=read();X=read();
	REP(i,1,n)c[read()]++;
	jc[0]=jc[1]=jcn[0]=jcn[1]=inv[1]=1;
	REP(i,2,X*2)jc[i]=(ll)jc[i-1]*i%mod,inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod,jcn[i]=(ll)jcn[i-1]*inv[i]%mod;
}

inline int C(int n,int m){ if(n<m)return 0;return 1ll*jc[n]*jcn[m]%mod*jcn[n-m]%mod;}

int dp[maxn][maxn];

inline void pls(int &a,int b){ a+=b; a-=a>=mod?mod:0;}

inline void doing()
{
	dp[0][0]=1;
	DREP(i,X,1)
	{
		DREP(j,X,0)DREP(k,X,0)if(dp[j][k])
		{
			REP(x,1,X)if(j+x<=X && k+x*i<=X)
			{
				pls(dp[j+x][k+x*i],(ll)dp[j][k]*jcn[x]%mod);
			}else break;
		}
		REP(j,0,X)REP(k,0,X)dp[j][k]=(ll)dp[j][k]*power(k-(i-1)*j,c[i])%mod;
		
	}
	int ans=0;
	REP(j,0,X)REP(k,0,X)ans=(ans+(ll)dp[j][k]*(X-k&1?-1:1)*jc[j]%mod*C(X-k+1,j))%mod;
	ans=(ans+mod)%mod;
	printf("%d\n",ans);
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 1280
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>

using namespace std;

template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vector<T>>;
using ll = long long;
using ld = long double;

#define REPi(i, s, e) for(int i = (s); i < (e); ++i)
#define REPll(i, s, e) for(ll i = (s); i < (e); ++i)

ll gcd(ll a, ll b)
{
	return b != 0 ? gcd(b, a % b) : a;
}

int main()
{
	cin.tie(0);

	int A, B; cin >> A >> B;
	if (A >= 13) cout << B << endl;
	else if (12 >= A && A >= 6) cout << B / 2 << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
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;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

struct PrimalDual{
	struct edge{
		int to,cap,cost,rev;
	};
	vector<vector<edge>>graph;
	void add_edge(int from,int to,int cap,int cost){
		graph[from].push_back({to,cap,cost,len(graph[to])});
		graph[to].push_back({from,0ll,-cost,len(graph[from])-1});
	}
	int minCostFlow(int s,int t,int f){
		int V=len(graph);
		vector<int>potential(V),minCost,prevv(V,-1),preve(V,-1);
		vector<bool>used(V);
		int res=0;
		while(f>0){
			minCost.assign(V,inf);
			used.assign(V,0);
			minCost[s]=0;
			rep(_,V-1){
				int mn=inf,idx;
				rep(i,V)if(!used[i]&&chmin(mn,minCost[i]))idx=i;
				used[idx]=true;
				rep(i,len(graph[idx])){
					edge &e=graph[idx][i];
					int nextcost=mn+e.cost+potential[idx]-potential[e.to];
					if(e.cap>0&&minCost[e.to]>nextcost){
						minCost[e.to]=nextcost;
						prevv[e.to]=idx;preve[e.to]=i;
					}
				}
			}
			if(minCost[t]==inf)return -1;
			rep(i,V)potential[i]+=minCost[i];
			int addflow=f;
			for(int i=t;i!=s;i=prevv[i])chmin(addflow,graph[prevv[i]][preve[i]].cap);
			f-=addflow;
			res+=addflow*potential[t];
			for(int i=t;i!=s;i=prevv[i]){
				edge &e=graph[prevv[i]][preve[i]];
				e.cap-=addflow;
				graph[i][e.rev].cap+=addflow;
			}
		}
		return res;
	}
	PrimalDual(int V):graph(V){};
};

int N,K;
int A[50][50];
signed main(){
	cin>>N>>K;
	PrimalDual F(2*N+2);
	F.add_edge(2*N,2*N+1,N*K,1e9);
	rep(i,N){
		F.add_edge(2*N,i,K,0);
		F.add_edge(i+N,2*N+1,K,0);
	}
	rep(i,N)rep(j,N){
		int a;cin>>a;
		F.add_edge(i,j+N,1,(int)1e9-a);
	}
	cout<<(int)1e9*N*K-F.minCostFlow(2*N,2*N+1,N*K)<<"\n";
	rep(i,N){
		REP(j,N+1)cout<<(F.graph[i][j].cap?'.':'X');
		cout<<"\n";
	}
}

Measured memory_bytes: 3888
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
ans = float('inf')
for i in range(1, int(n ** 0.5) + 1):
    x, y = divmod(n, i)
    if y == 0:
        ans = min(ans, x + i)
print(ans - 2)


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

using namespace std;

typedef long long ll;

const ll INF = 1LL << 60;

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

    ll N;
    cin >> N;

    vector<ll> X;
    X.resize(N);

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

    ll L;
    cin >> L;

    vector< vector<ll> > T;
    T.resize(N);

    ////
    //for (ll i = 0; i < N; ++i) {
    //    cout << i << " " << X[i] << endl;
    //}
    //cout << endl;

    //for (ll i = 0; i < N; ++i) {
    //    ll j = upper_bound(X.begin(), X.end(), X[i]+L) - X.begin() - 1;
    //    cout << i << " " << j << " " << X[j] << endl;
    //}
    //cout << endl;

    //
    for (ll i = 0; i < N; ++i) {
        ll j = upper_bound(X.begin(), X.end(), X[i]+L) - X.begin() - 1;

        T[i].resize(20);
        T[i][0] = j;
    }

    for (ll x = 1; x < 20; ++x) {
        for (ll i = 0; i < N; ++i) {
            T[i][x] = T[T[i][x-1]][x-1];
        }
    }

    ////
    //for (ll i = 0; i < N; ++i) {
    //    cout << i << " ";
    //    for (ll x = 0; x < 3; ++x) {
    //        cout << T[i][x] << "(" << X[T[i][x]] << ")" << " ";
    //    }
    //    cout << endl;
    //}

    //
    ll Q;
    cin >> Q;

    while (Q--) {
        ll a;
        ll b;

        cin >> a >> b;
        a--;
        b--;

        if (a > b) {
            swap(a, b);
        }

        ll ans = 0;

        while (true) {
            if (T[a][0] >= b) {
                break;
            }
            for (ll x = 0; x < 19; ++x) {
                if (T[a][x] < b && b <= T[a][x+1]) {
                    ans += pow(2, x);
                    a = T[a][x];
                    break;
                }
            }
        }
        cout << ans+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 21120