akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back
#define fi first
#define be begin()
#define en end()
#define se second

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  ll H,W;
  cin>>H>>W;
  if (H%3 == 0 || W % 3==0){
    cout << 0 << endl;
    return 0;
  }
  ll ans(1e18);
  for (int i(1);i<H;i++){
    ll tmp = i*W;
    ll tmp2,tmp3;
    if (W%2==0){
      tmp2 = (H-i)*(W/2);
      tmp3 = (H-i)*(W/2);
    }else{
      tmp2 = (H-i)*(W-1)/2;
      tmp3 = (H-i)*(W+1)/2;
    }
    ll maxi = max(tmp,max(tmp2,tmp3));
    ll mini = min(tmp,min(tmp2,tmp3));
    ans = min(ans,maxi - mini);
    //cout << ans << endl;
  }
  for (int i(1);i<W;i++){
    ll tmp = i*H,tmp2,tmp3;
    if (H%2==0){
      tmp2 = (W-i)*(H/2);
      tmp3 = (W-i)*(H/2);
    }else{
      tmp2 = (W-i)*(H-1)/2;
      tmp3 = (W-i)*(H+1)/2;
    }
    ll maxi = max(tmp,max(tmp2,tmp3));
    ll mini = min(tmp,min(tmp2,tmp3));
    ans = min(ans,maxi - mini);
  }
  ans = min(ans,min(H,W));
  cout << ans << endl;
  return 0;
}



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

int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	vector<pair<ll,ll> > v1(n);
	vector<ll> a(n),b(n),c(n),d(n);
	for(ll i=0;i<n;i++)
	{
		cin>>v1[i].first>>v1[i].second;
		a[i]=v1[i].first+v1[i].second;
		b[i]=v1[i].first-v1[i].second;
		c[i]=-v1[i].first+v1[i].second;
		d[i]=-v1[i].first-v1[i].second;
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	sort(d.begin(),d.end());
	cout<<max(a[n-1]-a[0],max(b[n-1]-b[0],max(c[n-1]-c[0],d[n-1]-d[0])));
	return 0;
}


Measured memory_bytes: 12672
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int32_t N, M;
  cin >> N >> M;
  int32_t low_end = 1;
  int32_t high_end = N;
  for (int32_t i = 1; i <= M; ++i) {
    int32_t L, R;
    cin >> L >> R;
    low_end = max(low_end, L);
    high_end = min(high_end, R);
  }
  int32_t count = max(0, high_end - low_end + 1);
  cout << count << endl;

  return 0;
}


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

int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int l,r,d; cin>>l>>r>>d;
	int ans=0;
	for(int i=l;i<=r;i++){
		if(i%d==0){
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3604
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vikas.k
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String s = in.nextLine();

            int[] cnt = new int[26];

            for (int i = 0; i < s.length(); i++) {
                cnt[s.charAt(i) - 'a']++;
            }

            for (int i = 0; i < 26; i++) {
                if (cnt[i] > 1) {
                    out.print("no");
                    return;
                }
            }
            out.print("yes");
        }

    }

    static class FastScanner {
        private BufferedReader bufferedReader;

        public FastScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String nextLine() {
            String ret = "";
            try {
                ret = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }

    }
}



Measured memory_bytes: 21460
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=100000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
//void swap(ll a,ll b){
//	ll d;
//	d=a;
//	a=b;
//	b=d;
//	return;
//}
ll mypow(ll x,int m){
	if(m==0)return 1;
	if(m%2==0){
		int x2=mypow(x,m/2);
		return x2*x2;
	}else{
		int x2=mypow(x,m/2);
		return x2*x2*x;
	}
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
//    	cout<<b<<endl;
        long long 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 ans=0;
ll total=0;
int m;
ll d[200003],c[200003];

int main() {
	string str;
	cin>>str;
	if(str=="SAT")cout<<1<<endl;
	if(str=="FRI")cout<<2<<endl;
	if(str=="THU")cout<<3<<endl;
	if(str=="WED")cout<<4<<endl;
	if(str=="TUE")cout<<5<<endl;
	if(str=="MON")cout<<6<<endl;
	if(str=="SUN")cout<<7<<endl;
		return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>b;
		if(i==0){
			c=b;
			d=b;
		}else if(c<b){
			c=b;
		}else if(d>b){
			d=b;
		}
	}
	cout<<c-d<<endl;
	return 0;
}

Measured memory_bytes: 256
import itertools
n,m,q = map(int,input().split())
array = []
A = [i for i in range(1,m+1)]
A_list = list(itertools.combinations_with_replacement(A,n))
max_sum = [0]*len(A_list)

for i in range(q):
    a,b,c,d = map(int,input().split())
    for j in range(len(A_list)):
        if A_list[j][b-1]-A_list[j][a-1] == c:
            max_sum[j] += d
print(max(max_sum))

Measured memory_bytes: 25244
n = int(input())
d,x = map(int,input().split())
a = []
for i in range(n):
    a.append(int(int(input())))

num = []
for i in range(n):
    num.append(0)

for i in range(n):
    num[i] = (d - 1) // a[i] + 1
#print(num)

ans = x
for i in range(n):
    ans += num[i]
print(ans)

Measured memory_bytes: 3064
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int K = int.Parse(str[1]);
        if(K == 1){
            sb.Append("1\n");
            return;
        }
        Fact F = new Fact(N*K);
        long[,] dp = new long[N+1,N+1];
        for(int i=0;i<N+1;i++){
            dp[i,0] = 1;
            for(int j=1;j<=i;j++){
                int L = N*K - i - j*(K-1) + K-1;
                dp[i,j] = ((dp[i,j-1]*F.GetConv(L-1,K-2)%Define.mod)+dp[i-1,j])%Define.mod; 
            }
        }
        sb.Append((dp[N,N]*F.GetFact(N)%Define.mod)+"\n");
    }
}
class Fact{
    public long[] f;
    public long[] rf;
    public Fact(int N){
        f = new long[N+1];
        rf = new long[N+1];
        for(int i=0;i<N+1;i++){
            if(i == 0){
                f[i] = 1;
            }
            else{
                f[i] = (f[i-1]*i)%Define.mod;
            }
        }
        for(int i=N;i>=0;i--){
            if(i == N){
                rf[i] = pow(f[N],Define.mod-2);
            }
            else{
                rf[i] = rf[i+1]*(i+1)%Define.mod;
            }
        }
    }
    public long pow(long N,long K){
        if(K == 0){
            return 1;
        }
        else if(K % 2 == 0){
            long t = pow(N,K/2);
            return t*t%Define.mod;
        }
        else{
            return N*pow(N,K-1)%Define.mod;
        }
    }
    public long GetFact(int N){
        return f[N];
    }
    public long GetConv(int N,int R){
        return ((f[N]*rf[R])%Define.mod*rf[N-R])%Define.mod;
    }
}
public static class Define{
    public const long mod = 1000000007;
}

Measured memory_bytes: 87760
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> a;
int main() {
  cin >> n;
  read_n(a, n);

  map<i64, i64> mp;
  i64 ans = 0;
  for (i64 i = 0; i < n; ++i) {
    auto it = mp.lower_bound(a[i]);
    if (i == 0 || it == begin(mp)) {
      mp[a[i]]++;
      ans++;
    } else {
      --it;
      i64 x = it->first;
      mp[x]--;
      if (mp[x] == 0) mp.erase(x);
      mp[a[i]]++;
    }
    /*
    for (auto p : mp) cerr << p.first << ' ';
    cerr << endl;
    */
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8704
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n,k;
  string s;
  cin >> n >> k >> s;

  char c = 'z';
  REP(i,n) c = min(c,s[i]);

  if(k>=14){
    REP(i,n) cout << c;
    cout << endl;
    return 0;
  }

  REP(_,k-1){
    string t = s; reverse(t.begin(),t.end());
    string u = s+t;
    reverse(u.begin(),u.end());
    string res = s;
    REP(i,n) res = min(res,u.substr(i+1,n));
    reverse(res.begin(),res.end());
    s = res;
  }

  string t = s; reverse(t.begin(),t.end());
  string u = s+t;
  string res = s;
  REP(i,n) res = min(res,u.substr(i+1,n));
  s = res;

  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
struct UnionFind {
  vector<int> data;
  UnionFind(int v) : data(v, -1) {}
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return -data[root(x)];
  }
  void merge(int x, int y) {
    x = root(x), y = root(y);
    if (x != y) {
      if (size(y) > size(x))
        swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }
};
signed main() {
  ios::sync_with_stdio(false);
  int N, M; cin >> N >> M;
  vector<bool> used_lang(M, false);
  UnionFind U(N + M);
  REP(i, N) {
    int K; cin >> K;
    REP(j, K) {
      int L; cin >> L;
      used_lang[L - 1] = true;
      U.merge(i, N + L - 1);
    }
  }
  int c = N;
  REP(i, M) {
    if(used_lang[i]) ++c;
  }
  if(U.size(0) == c) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

template <class T>void Sort(vector<T> & a) { sort(a.begin(), a.end()); }
template <class T>void ReSort(vector<T>& a) { sort(a.rbegin(), a.rend()); }
template <class T>void Reverse(vector<T>& a) { reverse(a.begin(), a.end()); }
template <class T>void Unique(vector<T>& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T>T Sum(vector<T> a, T init = 0) { return accumulate(a.begin(), a.end(), init); }

//INPUT//
void CINPUT() {}
template<class H, class ...T> void CINPUT(H&& h, T&& ...t) { cin >> h; CINPUT(forward<T>(t)...); }
#define in(...) int __VA_ARGS__; CINPUT(__VA_ARGS__);
#define In(T,...) T __VA_ARGS__; CINPUT(__VA_ARGS__);
#define Vin(T,name,n) int n; cin>>n; vector<T> name(n); rep(i,n)cin>>name[i];
#define VIn(T,name,n) vector<T> name(n); rep(i,n)cin>>name[i];

//OUTPUT//
void print() { cout << endl; }
template <class H> void print(H&& h) { cout << h << endl; }
template <class H, class... T> void print(H&& h, T&& ... t) { cout << h << " "; print(forward<T>(t)...); }
template<class T>void out(T n) { cout << n << endl; }
template<class T>void out(vector<T> a, string sep = " ", string end = "\n") { for (int i = 0; i < (int)a.size(); ++i)cout << a[i] << (i == (int)a.size() - 1 ? end : sep); }
void yes(bool f) { puts(f ? "yes" : "no"); }
void Yes(bool f) { puts(f ? "Yes" : "No"); }
void YES(bool f) { puts(f ? "YES" : "NO"); }
void poss(bool f) { puts(f ? "possible" : "impossible"); }
void Poss(bool f) { puts(f ? "Possible" : "Impossible"); }
void POSS(bool f) { puts(f ? "POSSIBLE" : "IMPOSSIBLE"); }

int main() {
	in(n);
	puts(n < 1000 ? "ABC" : "ABD");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
const int MOD = 1e9+7;
using namespace std;


int main(){
	int n, k, x;
	long long ans = 0;
	vector<int> h;
	cin >> n >> k;
	for (int i = 0; i < n; i++){
		cin >> x;
		h.push_back(x);
	}
	sort(h.begin(), h.end(), greater<int>());

	for (int i = k; i < n; i++) ans += h[i];

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


Measured memory_bytes: 1400
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,0,n-1) cin>>a[i];
    ll cnt = 1;
    ll ans = 0;
    rep(i,0,n-1){
        if(a[i]!=i+cnt){
            cnt--;
            ans++;
        }
    }
    if(ans==n) cout<<"-1"<<endl;
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
int calcBitLength(ll n) {
    ll x = n;
    ll ret = 0;
    while (x > 0) {
        ret++;
        x >>= 1;
    }
    return ret;
}
/* main */
int main(){
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> a(N), b(N);
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];

    int L = calcBitLength(K);
    int upper = 1 << (L-1);

    ll mx = 0LL;
    for (int i = 0; i < N; i++) {
        if ((K | a[i]) == K) mx += b[i];
    }

    int upperK = (1 << L) - 1;
    for (int l = 0; l < L; l++) {
        int d = 1 << (L-1 - l);
        if (K & d) {
            upperK -= d;
            ll sum = 0;
            for (int i = 0; i < N; i++) {
                if ((upperK | a[i]) == upperK) sum += b[i];
            }
            mx = max(mx, sum);
            upperK += d;
        }
        else upperK -= d;
    }

    cout << mx << '\n';
}


Measured memory_bytes: 4816
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
// #include <cmath>
// #include <string>
// #include <numeric>
// #include <set>
// #include <map>
// #include <iomanip>

// #define MOD 1000000007
#define INF 1000000001

using namespace std;
// typedef unsigned long long ull;
typedef long long ll;

void p_() {
    cout << "\n";
}
template<class Head, class... Body>
void p_(Head head, Body... body) {
    cout << head << ",";
    p_(body...);
}

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

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    for (const auto& i : v) {
        os << i << " ";
    }
    os << "]";
    return os;
}

using P = pair<ll, int>;

int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    vector<pair<ll, int>> x, y;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        x.push_back(make_pair(a, i));
        y.push_back(make_pair(b, i));
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    vector<int> x_idxs(N), y_idxs(N);
    for (int i = 0; i < N; i++) {
        x_idxs[x[i].second] = i;
        y_idxs[y[i].second] = i;
    }

    // cout << x << endl;
    // cout << y << endl;
    // cout << x_idxs << endl;
    // cout << y_idxs << endl;

    vector<ll> dist(N, INF);
    dist[0] = 0;
    vector<bool> used(N, false);
    used[0] = false;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(make_pair(0, 0));
    ll cost = 0;
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int idx = p.second;
        if (used[idx] || dist[idx] < p.first) continue;

        used[idx] = true;
        cost += dist[idx];
        // p_("idx", idx, " dist", dist[idx], " cost", cost);

        int ix = x_idxs[idx];
        int iy = y_idxs[idx];
        // p_("ix", ix, " iy", iy);

        vector<int> next_idxs;
        vector<ll> ds;
        if (ix > 0) {
            next_idxs.push_back(x[ix-1].second);
            ds.push_back(x[ix].first - x[ix-1].first);
        }
        if (ix < N-1) {
            next_idxs.push_back(x[ix+1].second);
            ds.push_back(x[ix+1].first - x[ix].first);
        }
        if (iy > 0) {
            next_idxs.push_back(y[iy-1].second);
            ds.push_back(y[iy].first - y[iy-1].first);
        }
        if (iy < N-1) {
            next_idxs.push_back(y[iy+1].second);
            ds.push_back(y[iy+1].first - y[iy].first);
        }

        for (int i = 0; i < next_idxs.size(); i++) {
            if (!used[next_idxs[i]] && dist[next_idxs[i]] > ds[i]) {
                dist[next_idxs[i]] = ds[i];
                // p_("add ", dist[next_idxs[i]], next_idxs[i]);
                que.push(make_pair(dist[next_idxs[i]], next_idxs[i]));
            }
        }
    }

    cout << cost << endl;

    return 0;
}


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

int main(){
  int n;
  int a[100];
  long long int dp[100][21];

  cin >> n;
  for(int i=0;i<n;i++)cin >> a[i];

  for(int i=0;i<n;i++){
    for(int j=0;j<21;j++)dp[i][j] = 0;
  }

  dp[0][a[0]] = 1;  

  for(int i=1;i<n;i++){
    for(int j=0;j<21;j++){
      if(dp[i-1][j]){
	if(j + a[i] <=20)dp[i][j+a[i]] += dp[i-1][j];
	if(j - a[i] >= 0)dp[i][j-a[i]] += dp[i-1][j];
      }
    }
  }

  cout << dp[n-2][a[n-1]] << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long A, long long B){
	cout << max(max(A+B, A-B),A*B) << endl;
}

int main(){	
	long long A;
	long long B;
	scanf("%lld",&A);
	scanf("%lld",&B);
	solve(A, B);
	return 0;
}



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

int main() {
  string s;
  cin >> s;

  string rev_array[4] = {"dream", "dreamer", "erase", "eraser"};

  for(int i=0; i<4; i++) {
    reverse(rev_array[i].begin(), rev_array[i].end());
  }
  int ptr_s=s.length();
  int ptr_s_preview = ptr_s;
  bool flag[4] = {false,false,false,false};

  while(1) {
    for(int j=0; j<4; j++) {
      for(int i=0; i<rev_array[j].length(); i++) {
	if(rev_array[j][i] != s[ptr_s-1-i])  {
	  break;
	}
	if(i == rev_array[j].length()-1) {
	  flag[j] = true;
	  ptr_s -= rev_array[j].length();
	}
      }
      if(ptr_s_preview != ptr_s) {
	break;
      }
    }
    if(flag[0] == false && flag[1] == false && flag[2] == false && flag[3] == false) {
      cout << "NO" << endl;
      return 0;
    }
    if(ptr_s == 0) {
      cout << "YES" << endl;
      return 0;
    }
    ptr_s_preview = ptr_s;
    for(int i=0; i<4; i++) 
      flag[i] = false;
  }

}
    


Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <vector>
using namespace std;
#define FOR(__I,__N) for (int __I = 0; __I < __N; ++__I)

typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64, int64> pll;
typedef double db;
typedef long double ldb;

const int INF = 0x3f3f3f3f;
const int64 INF64 = 0x3f3f3f3f3f3f3f3fLL;

const int MOD = 1000000007;


int solve(){

	int ret = 0;

	return ret;
}

const int MAX_N = 1000;

int p[MAX_N];
int main(){
	int N, K;	cin >> N >> K;
	FOR(i,N)	cin >> p[i];
	nth_element(p,p+K,p+N);
	int sum = 0;
	FOR(i,K)	sum += p[i];
    printf("%d\n",sum);
}





Measured memory_bytes: 3740
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = long long;
// using ll = boost::multiprecision::int128_t;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;


int main() {
  ll n, k; cin >> n >> k;

  if (2*k > n+1) {
    cout << -1 << "\n";
    return 0;
  }

  int cnt = 0;
  int a = k+n;
  int b = k + (n+1)/2 - 1;

  VVll ans(n, Vll(3));
  rep(i, (n+1)/2) {
    ans[i] = {a, b, k+2*n+i};
    a += 2;
    b -= 1;
  }
  a -= n;
  b += n;
  if (n%2 == 0) ++a;

  rep2(i, (n+1)/2, n) {
    ans[i] = {a, b, k+2*n+i};
    a += 2;
    b -= 1;
  }

  rep(i, n) cout << ans[i] << "\n";
  return 0;
}


Measured memory_bytes: 7808
#include<iostream>
#include<cstdio>
#include<map>

using namespace std;
typedef long long ll;

map< ll, int> num;

int main()
{
    int n;
    int a;
    int sum = 0;

    cin >> n;
    for( int i = 0; i < n; i++)
    {
        scanf("%d", &a);
        if(num[a])
        {
            num[a]--;
            sum--;
        }
        else
        {
            num[a]++;
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>

using namespace std;

#define int long long

int32_t main() {
	int res = 0;
	int n;
	cin >> n;
	int nb = n;
	while (nb) {
		res += (nb % 10);
		nb /= 10;
	}
	if (n % res == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main 
{

	public static void main(String[] args) 
	{
		long[] tet = new long[201];
		long[] tot = new long[1000001];
		long[] totodd = new long[1000001];
		
		long[] odd = new long[201];
		
		int filled = 0;
		PriorityQueue<Integer> pq = new PriorityQueue<>();
		PriorityQueue<Integer> pq2 = new PriorityQueue<>();

		int odds = 0;
		for(int i = 0; i <= 200; i++)
		{
			tet[i] = (i * (i+1) * (i+2)) / 6;
			
			if(tet[i] <= 1000000)
			{
				if(tet[i]%2 != 0)
				{
					odd[odds] = tet[i];
					odds++;
					pq2.add((int)tet[i]);
					totodd[(int)tet[i]] = 1;
				}
				
				tot[(int)tet[i]] = 1;
				filled++;
				pq.add((int)tet[i]);
			}
			else
				break;
		}
		
//		System.out.println(Arrays.toString(tet));
//		System.out.println(Arrays.toString(odd));

		
		int curt = 0;
		
		while(!pq.isEmpty())
		{
			int pos = pq.poll();
			
			for(int i = 0; i <= 200; i++)
			{
				if(pos + tet[i] <= 1000000)
				{
					int next = pos + (int)tet[i];
					if(tot[next] == 0 || tot[next] > tot[pos]+1)
					{
						tot[next] = tot[pos]+1;
						pq.add(next);
					}
				}
			}
		}
		while(!pq2.isEmpty())
		{
			int pos = pq2.poll();
			
			for(int i = 0; i <= 200; i++)
			{
				if(pos + odd[i] <= 1000000)
				{
					int next = pos + (int)odd[i];
					if(totodd[next] == 0 || totodd[next] > totodd[pos]+1)
					{
						totodd[next] = totodd[pos]+1;
						pq2.add(next);
					}
				}
			}
		}
//		System.out.println("DONE");
		
		Scanner sc = new Scanner(System.in);
		
		int in = sc.nextInt();
		while(in != 0)
		{
			System.out.println(tot[in] + " " + totodd[in]);
			in = sc.nextInt();
		}
	}

}



Measured memory_bytes: 134456
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   int a, b, c, x;
   cin >> a >> b >> c >> x;
   int cnt = 0;
   for(int i = 0; i <= a; i++){
      for(int j = 0; j <= b; j++){
         for(int k = 0; k <= c; k++){
            if(500*i + 100*j + 50*k == x){
               cnt++;
            }
         }
      }
   }
   cout << cnt << endl;

   return 0;
}

Measured memory_bytes: 256
K=int(input())
nums=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(nums[K-1])

Measured memory_bytes: 3060
program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n
    integer(8)::a,b,c,d,ans
    integer(8),allocatable::x(:),y(:)
  
    read(*,*) n
    allocate(x(n+1),y(n))
    read(*,*)x
    read(*,*)y
    a=0
    ans=0
    do i=1,n
        if(y(i)+a<=x(i))then
            ans=ans+y(i)+a
            a=0
        elseif(a>=x(i))then
            ans=ans+x(i)
            a=y(i)
        else
            ans=ans+x(i)
            a=y(i)+a-x(i)
        end if
    end do
    if(x(n+1)>a)then
        ans=ans+a
    else
        ans=ans+x(n+1)
    end if
    write(*,*)ans
    stop
end program sample
  



Measured memory_bytes: 4660
A,B,C,D,E,F = (int(T) for T in input().split())
SugM = 0
WatM = 100*A
for TC in range(0,F+1):
    for TD in range(0,F+1):
        Suger = C*TC+D*TD
        RestS = F-Suger
        if RestS>=0:
            for TA in range(0,(RestS//100)+1):
                for TB in range(0,(RestS//100)+1):
                    if TA==TB==0:
                        continue
                    else:
                        Water = TA*A*100+TB*B*100
                        RestW = RestS-Water
                        if RestW>=0 and Water>=(100*Suger)/E:
                            if SugM/(WatM+SugM)<Suger/(Water+Suger):
                                SugM = Suger
                                WatM = Water
                        else:
                            break
        else:
            break
print('{} {}'.format(WatM+SugM,SugM))

Measured memory_bytes: 9240
#include<bits/stdc++.h>
using namespace std;
int main(){
	double a,b;
	cin>>a>>b;
	for(double i=1;i<=1000;++i){
		if(floor(i*0.08)==a&&floor(i*0.1)==b){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<"-1";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;


public class Main {
    static int gcd(int x, int y) {
        int r = Math.max(x, y) % Math.min(x, y);
        if (r == 0) return Math.min(x, y);
        else return gcd(Math.min(x, y), r);
    }
    
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        int x1 = Integer.parseInt(s[0]);
        int y1 = Integer.parseInt(s[1]);
        int x2 = Integer.parseInt(s[2]);
        int y2 = Integer.parseInt(s[3]);
        int xdiff = x2-x1;
        int ydiff = y2-y1;
        int x3, y3, x4, y4;
        
        x3 = x2 - ydiff;
        y3 = y2 + xdiff;
        x4 = x3 - xdiff;
        y4 = y3 - ydiff;
        
        
        System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
    }
}





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

int main(){
    ll K; cin>>K;
    ll seven[K+1];
    seven[0]=7%K;
    for(ll i=1;i<K+1;i++){
        seven[i]=(seven[i-1]*10+7)%K;
    }
    for(ll i=0;i<K+1;i++){
        if(seven[i]==0){
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

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

int main() {
    int64_t N, K;
	cin >> N >> K;
	int64_t a;

	if (N >= K) {
		a = N % K;
		a = min(a, K - a);
	}
	else {
		a = min(N,K-N);
	}
	cout << a << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n, long long modvalue) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2, modvalue);
        return t * t % modvalue;
    } else {
        return modpow(m, n - 1, modvalue) * m % modvalue;
    }
}

long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k, ll modvalue) {
    ll numera = 1;
    for (int i = n; i > n - k; i--) {
        numera *= i;
        numera %= modvalue;
    }
    ll denomi = 1;
    REP(i, k) {
        denomi *= (i + 1);
        denomi %= modvalue;
    }
    return moddiv(numera, denomi, modvalue);
}

map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}

bool check(string s, string t){
	
    map<char, char> cnt;
    REP(i, s.size()) {
        if (cnt[s[i]] == 0) {
            cnt[s[i]] = t[i];
        } else if (t[i] != cnt[s[i]]) {
            return false;
        }
    }
  return true;
}
int main() {
    string s, t;
    cin >> s >> t;
  	if(check(s,t) && check(t,s))
	    cout << "Yes" << endl;
  	else 
     	cout << "No" << endl;
}


Measured memory_bytes: 4568
#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))
#define sz(v) ((int) v.size())

using namespace std;

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

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
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) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(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() {
  int n, m;
  cin >> n >> m;
  vi32 a(n);
  cin >> a;
  sort(all(a));
  reverse(all(a));
  int sum = 0;
  rep(i, n) sum += a[i];
  int x;
  if (sum % (4 * m) == 0) {
    x = sum / (4 * m) - 1;
  } else {
    x = sum / (4 * m);
  }
  if (a[m - 1] <= x) {
    no();
  } else {
    yes();
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<string.h>
#define ll long long 
#include<vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main(){
	IOS;
int n,m;
cin>>n>>m;
int votes=0;
vector<int> v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
votes+=v[i];}
sort(v.begin(),v.end(),greater<int>());
if(v[m-1]>=(votes+4*m-1)/(4*m))
cout<<"Yes";
else
cout<<"No";
	
	}

Measured memory_bytes: 3632
n,m=map(int, input().split())
a=[list(map(int, input().split())) for _ in range(m)]
c=[0]*-~n
id={}
for p,y in sorted(a,key=lambda x:x[1]):
    c[p]+=1
    id[y]=str(p).zfill(6)+str(c[p]).zfill(6)
for _,y in a:
    print(id[y])

Measured memory_bytes: 43856
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <deque>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using ll = long long;


int main() {
	int n;
	cin >> n;
	ll A[n];
	rep(i, n) cin >> A[i];
	rep(i, n) A[i] -= i+1;

	sort(A, A+n);
	ll res = 0;
	rep(i, n) {
		ll diff = abs(A[i] - A[n/2]);
		res += diff;
	}
	cout << res << endl;
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

using ll = long long;
using ull = unsigned long long;
using veci = vector<int>;
using vecll = vector<ll>;
using vecull = vector<ull>;

int main(void) {
    int N, K;
    cin >> N >> K;

    ll t1 = (N / K);

    ll ans = t1 * t1 * t1;

    if (K % 2 == 0) {
        ll t = 0;
        REP(i, 1, N + 1)
        {
            if (i % K == K / 2) t++;
        }

        ans += t * t * t;
    }

    cout << ans << endl;

    return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e5+23;
int inv[N], cnt[N];

void solve() {
  int n; scanf("%d", &n);
  for (int p, i = 0; i < n; ++i) {
    scanf("%d", &p);
    inv[--p] = i;
    cnt[i] = 1;
  }
  int ans = n-1;
  for (int i = n-2; i >= 0; --i) {
    if (inv[i] < inv[i+1]) {
      cnt[i] = 1+cnt[i+1];
      ans = min(n-cnt[i], ans);
    }
  }
  printf("%d", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 5364
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

S = input()

A = set(S)

for x in ascii_lowercase:
	if not x in A:
		print(S+x)
		break
else:
	for i in range(len(S)-2, -1, -1):
		if S[i] < S[i+1]:
			for char in sorted(S[i+1:]):
				if S[i] < char:
					print(S[:i]+char)
					break
			else:
				continue
			break
	else:
		print(-1)


Measured memory_bytes: 5200
import java.util.Scanner;

class Main{

	public static void main(String[] args) {




		Scanner scan = new Scanner(System.in);
		long A = scan.nextLong();
		long B = scan.nextLong();
		long ans = 0;
		if(A==1&B==1){
			ans = 1;
		}else if(A == 1 ||B == 1){
			ans = Math.max(A, B)-2;
		}else{
			ans = (A-2)*(B-2);

		}
		
			System.out.println(ans);
		

	}


}


Measured memory_bytes: 23892
#include <set>
#include <map>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	char tmp;
	
	for(int i = 0; i < n; i++){
		cin >> tmp;
		if(tmp == 'a'){
			if(a > 0){
				a--;
				cout << "Yes" << endl;
			}else if(b > 0){
				b--;
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;	
			}
		}else if(tmp == 'b'){
			if(b > 0){
				b--;
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;
			}
		}else if(tmp == 'c'){
			cout << "No" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 640
from collections import Counter
n, m = map(int, input().split())
ns = list(map(int, input().split()))
a = Counter(ns)
for i in range(m):
    b, c = map(int, input().split())
    a[c] += b
ans = 0
cnt = 0
for num, count in sorted(a.items(), key=lambda x: x[0], reverse=True):
    ans += num * count
    cnt += count
    if cnt > n:
        break
ans -= (cnt - n) * num
print(ans)

Measured memory_bytes: 43296
N, A, B = map(int, input().split())
S = str(input())

count = 0
count_B = 0

for n in range(N):
  if S[n] == "c":
    print("No")
    
  elif S[n] == "a":
    if count < A+B:
      print('Yes')
      count += 1
    else:
      print('No')
      
  elif S[n] == "b":
    if count < A+B and count_B < B:
      print('Yes')
      count += 1
      count_B += 1
    else:
      print('No')

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

int main(){
    int H, W;
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0)break;
        for(int i=0;i < H;i++){
            for(int j=0;j < W;j++){
                if((i+j)%2==0){
                    cout <<"#";
                }
                else{
                    cout<<".";
                }
            }
        cout << endl;
        }
    cout << endl;
    }
}


Measured memory_bytes: 3116
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=3e5+10,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    string s;
    cin>>s;
    loop(sz(s),i,0)
        cout<<s[i++];
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3792
import java.util.*;

public class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt();
            if(n==0) break;

            int[] dp = new int[n+1];
            dp[0] = 1;
            for(int i=0; i<=n; i++){
                for(int j=1; j<=3; j++){
                    if(i-j>=0) dp[i] += dp[i-j];
                }
            }

            int ans = dp[n]/10;
            if(dp[n]%10>0) ans++;
            if(ans%365>0){
                ans /= 365;
                ans++;
            }else ans /= 365;

            System.out.println(ans);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 17188