akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}

int main(){
  string S;
  cin>>S;
  ll cnt=0;
  REP(i,(ll)S.size()){
    cnt+=S[i]-'0';
  }
  
  if(cnt%9==0) COYe;
  else CONo;
  return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
int main(){
 int N;
 cin>>N;
 vector<int> p(N);
 for (int i=0; i<N; i++)
 cin>>p[i];
 int ans=0;
 int mx=p[0];
 for(int i=0;i<N;i++){
 ans+=p[i];
 mx=max(mx,p[i]);
 }
 mx /=2;
 ans-=mx;
 cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 256
N = int(input())
pt, px, py = 0, 0, 0
can = True
for i in range(N):
    t, x, y = map(int, input().split())
    T, X, Y = t - pt, abs(x - px), abs(y - py)
    if T < X + Y or T % 2 != (X + Y) % 2:
        can = False
    pt, px, py = t, x, y
print('Yes' if can else 'No')

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

int main()
{
    int N;
    cin >> N;
    vector<P> ab(N), cd(N);
    vector<bool> flag(N, true);

    rep(i, N) cin >> ab[i].first >> ab[i].second;
    rep(i, N) cin >> cd[i].first >> cd[i].second;

    sort(all(ab));
    sort(all(cd));

    int ans = 0;
    rep(i, N) {
        P blue = cd[i];
        int index = -1;
        rep(j, N) {
            P red = ab[j];
            if (flag[j]) {
                if (blue.first > red.first && blue.second > red.second) {
                    if (index != -1) {
                        if (ab[index].second < ab[j].second) index = j;
                    }
                    else index = j;
                }
            }
        }
        if (index != -1) {
            flag[index] = false;
            ans++;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

const ll b1 = 10000;
const ll b2 = 50000;
const ll m1 = 2147483647;
const ll m2 = 2111211121;

ll modpow(ll x, ll y, ll mod) {
	ll ans = 1;
	while (y) {
		if (y & 1)ans *= x;
		x *= x;
		ans %= mod;
		x %= mod;
		y /= 2;
	}
	return ans;
}

int main() {
	int N;
	cin >> N;
	vector<ll> A(N), B(N), AX(2 * N), BX(2 * N);
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}
	for (int i = 0;i < N;i++) {
		cin >> B[i];
	}

	for (int i = 0;i < 2 * N;i++) {
		AX[i] = A[i % N] ^ A[(i + 1) % N];
		BX[i] = B[i % N] ^ B[(i + 1) % N];
	}

	ll v1 = 0, v2 = 0;
	for (int i = 0;i < N;i++) {
		v1 *= b1;
		v2 *= b2;
		v1 += AX[i] + 1;
		v2 += AX[i] + 1;
		v1 %= m1;
		v2 %= m2;
	}

	vector<pair<ll, ll>> P(N);
	for (int i = 0;i < N;i++) {
		P[i] = { v1,v2 };
		v1 -= (AX[i] + 1) * modpow(b1, N - 1, m1) % m1;
		v2 -= (AX[i] + 1) * modpow(b2, N - 1, m2) % m2;

		v1 *= b1;v1 += AX[i + N] + 1;
		v2 *= b2;v2 += AX[i + N] + 1;

		v1 %= m1;v1 += m1;v1 %= m1;
		v2 %= m2;v2 += m2;v2 %= m2;
	}

	v1 = 0, v2 = 0;

	for (int i = 0;i < N;i++) {
		v1 *= b1;
		v2 *= b2;
		v1 += BX[i] + 1;
		v2 += BX[i] + 1;
		v1 %= m1;
		v2 %= m2;
	}

	ll x, y;
	for (int i = 0;i < N;i++) {
		tie(x, y) = P[i];
		if (P[i] == pair<ll,ll>(v1, v2)) {
			cout << i << " " << (A[i] ^ B[0]) << endl;
		}
	}
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

template<class T> inline T gcd(T a, T b) { return b==0? a:gcd(b,a%b); }

template<typename T>
struct Segtree {
    int n;
    T e; // default value
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input) {
        initialize(n_input, f_input, e_input);
    }

    void initialize(int n_input, Func f_input, T e_input) {
        f = f_input;
        e = e_input;
        n = 1;
        while(n < n_input) { n<<=1; }
        dat.resize(2*n-1, e);
    }

    void update(int k, T a) {
        k += n-1;
        dat[k] = a;
        while(k > 0) {
            k = (k-1)/2;
            dat[k] = f(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get(int k) {
        return dat[k+n-1];
    }
    // [a, b)
    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    // [a, b)
    T _query(int a, int b, int k, int l, int r) {
        if(r<=a || b<= l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = _query(a, b, 2*k+1, l, (l+r)/2);
        T vr = _query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};
/** Usage:
Segtree<int> seg(n, [](int a, int b) {return max(a,b);}, 0); // init
REP(i, n+1) st.update(i, i)
st.query(a, b)
*/

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n; cin >> n;
    int A[n];
    REP(i, n) cin >> A[i];
    Segtree<int> seg(n, [](int a, int b) {return gcd(a,b);}, 0);
    REP(i, n) seg.update(i, A[i]);
    
    int ans = 0;
    REP(i, n) {
        if(i==0) chmax(ans, seg.query(i+1, n));
        else if(i==n-1) chmax(ans, seg.query(0, n-1));
        else {
            chmax(ans, gcd(seg.query(0, i), seg.query(i+1, n)));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
//#include <iostream>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

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

    priority_queue<int> pq;
    int a;
    for (int i = 0; i < N; ++i) {
        cin>>a;
        pq.push(a);
    }

    for (int i = 0; i < M; ++i) {
        int tmp=pq.top();
        pq.pop();
        tmp/=2;
        pq.push(tmp);
    }

    ll ans=0ll;

    while(!pq.empty()){
        ans+=(ll)pq.top();
        pq.pop();
    }
    cout<<ans<<endl;
    return 0;
}


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

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

ll kaizyou(ll N){
  ll num=1;
  for(ll i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

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

 
int main(){
  string s;
  cin >> s;
  vector<int>ans(s.size());
  int n=s.size();
  rep(i,2){
    int cnt =0;
    rep(ii,n){
      if(s[ii]=='R')cnt++;
      else{
        ans[ii]+=cnt/2;
        ans[ii-1]+=(cnt+1)/2;
        cnt=0;
      }
    }
    reverse(ans.begin(),ans.end());
    reverse(s.begin(),s.end());
    rep(iii,n){
      if(s[iii]=='L')s[iii]='R';
      else s[iii] = 'L';
    }
  }
  rep(i,n){
    cout << ans[i] << endl;
  }
}
      
  
  
  

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

ll q, h, s, d, n;

int main() {
	cin >> q >> h >> s >> d >> n;
	h = min(h, 2*q);
	s = min(s, 2*h);
	d = min(d, 2*s);
	cout << n/2*d + (n&1)*s << endl;
}

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

using ll = long long;

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

    int N;
    cin >> N;
    ll ans = 0;
    for(int i = 1; i <= N; ++i) ans += (ll)i * (N - i + 1);
    for(int i = 0; i < N - 1; ++i){
        int L, R;
        cin >> L >> R;
        if(L > R)   swap(L, R);
        ans -= (ll)L * (N - R + 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string T;
    cin >> T;
    ll len = T.size();
    REP(i, 0, len) {
        if (T[i] == '?') {
            T[i] = 'D';
        }
    }
    cout << T << endl;
}


Measured memory_bytes: 3772
"use strict";
function I(t,i){this._s=t.split("\n"),this._c=0,this._l=0,this._f=i||Number}I.prototype.a=function(t){var i=this._s[this._l];if(i){var s=i.trim().split(" "),h=s[this._c];return this._c++,s.length===this._c&&(this._c=0,this._l++),t?t(h):this._f(h)}},I.prototype.l=function(t){var i=this._s[this._l];if(i)return this._c=0,this._l++,i.split(" ").map(t||this._f)},module.exports=I;
function Queue(e){this._queue=e?e.slice():[],this._tail=this._queue.length,this._head=0,this._maxLength=1000000000}Queue.prototype.enqueue=function(e){this._tail+1===this._head||0===this._head&&this._tail===this._maxLength-1?console.error("===queue overflow==="):(this._queue[this._tail]=e,this._tail+=1,this._tail===this._maxLength&&(this._tail=0))},Queue.prototype.dequeue=function(){if(this._tail!==this._head){var e=this._queue[this._head];return this._head+=1,this._head===this._maxLength&&(this._head=0),e}console.error("===queue underflow===")},Queue.prototype.size=function(){var e=this._tail-this._head;return e<0&&(e+=this._maxLength),e};

function main(input) {
  var o = new I(input);

  var n = o.a();
  var u = [];
  var v = [];
  var w = [];

  for (var i = 0; i < n - 1; i++) {
    u.push(o.a());
    v.push(o.a());
    w.push(o.a());
  }

  var adj = [];
  for (var i = 1; i <= n; i++) {
    adj[i] = [];
  }

  for (var i = 0; i < n - 1; i++) {
    adj[u[i]].push({
      v: v[i],
      w: w[i]
    });
    adj[v[i]].push({
      v: u[i],
      w: w[i]
    });
  }

  // console.log(adj);
  var queue = new Queue();
  var color = [, 0];
  queue.enqueue(1);
  while (queue.size() > 0) {
    var cur = queue.dequeue();
    // console.log(queue, color, {cur, adj: adj[cur]});
    adj[cur].forEach(x => {
      var v = x.v;
      if (color[v] === undefined) {
        var w = x.w;
        if (w % 2 === 0) {
          color[v] = color[cur];
        } else {
          color[v] = (color[cur] + 1) % 2;
        }
        queue.enqueue(v);
      }
    })
  }

  for (var i = 1; i <= n; i++) {
    console.log(color[i]);
  }
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

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

	vector<int> L(N);
	rep(i,N) cin >> L[i];

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

	int ans=0;
	rep(b,N)rep(a,b) {
		int ab = L[a] + L[b];
		int r = lower_bound(L.begin(),L.end(), ab) - L.begin();
		int l = b+1;
		ans += r-l;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

int main() {
	//std::cout << "HelloWorld" << std::endl;

	int flag = 0;
	int num[6] = {};

	for (int i = 0; i < 6; i++) {
		std::cin >> num[i];
	}

	for (int i = 0; i < 5; i++) {
		for (int j = 1; j < 5; j++) {
			if (num[j] - num[i] > num[5]) {
				std::cout << ":(" << std::endl;
				flag = 1;
				break;
			}
			else {

			}
		}
		if (flag == 1) {
			break;
		}
	}

	if (flag == 0) {
		std::cout << "Yay!" << std::endl;
	}


	

}

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



struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k ==u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);


}

Node treeSuccessor(Node x){
  Node y;
  
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else{
    if(y == y->parent->left) y->parent->left = x;
    else y->parent->right = x;
  }
  if(y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
    z->parent = y;
  

  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->left = z;
  else y->right = z;
  }
}




void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }

}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}





Measured memory_bytes: 25296
import java.util.*;

public class Main{
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n | m) == 0) break;
			int [][] cost = new int[m][m];
			int [][] time = new int[m][m];
			int INF = 1 << 24;
			for(int i = 0; i < m; i++){
				Arrays.fill(cost[i], INF);
				Arrays.fill(time[i], INF);
				cost[i][i] = 0;
				time[i][i] = 0;
			}
			for(int i = 0; i < n; i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				int c = sc.nextInt();
				int t = sc.nextInt();
				cost[a][b] = c;
				cost[b][a] = c;
				time[a][b] = t;
				time[b][a] = t;
			}
			for(int j = 0; j < m; j++){
				for(int i = 0; i < m; i++){
					for(int k = 0; k < m; k++){
						cost[i][k] = Math.min(cost[i][k], cost[i][j] + cost[j][k]);
					}
				}
			}
			
			for(int j = 0; j < m; j++){
				for(int i = 0; i < m; i++){
					for(int k = 0; k < m; k++){
						time[i][k] = Math.min(time[i][k], time[i][j] + time[j][k]);
					}
				}
			}
			
			int q = sc.nextInt();
			while(q-- > 0){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				int digit = sc.nextInt();
				System.out.println(digit == 0 ? cost[a][b] : time[a][b]);
			}
		}
	}
	
	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

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

Measured memory_bytes: 64308
n, m = map(int, input().split())
c = list(map(int, input().split()))
inf = 10 ** 7

dp = [inf for _ in range(n+1)]
dp[0] = 0
for i in range(1, n+1):
    for j in range(m):
        if i - c[j] >= 0:
            dp[i] = min(dp[i], dp[i-c[j]] + 1)

print(dp[n])


Measured memory_bytes: 7380
/**Which of the favors of your Lord will you deny ?**/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second
#define INF INT_MAX

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>
using indexed_set = tree<
                    TIn, null_type, less<TIn>,
                    rb_tree_tag, tree_order_statistics_node_update>;

/*
PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

*/

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;
const LL LINF = 1e17;

string to_str(LL x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

int ara[nmax];
int pos[nmax];

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

    for(int i=1;i<=n;i++)
        cin>>ara[i] , pos[ara[i]] = i;

//    for(int i=1;i<=n;i++)
//        cout<<pos[i]<<" ";

    int mx = 0 , cnt = 1;

    for(int i=1;i<n;i++)
    {
        if(pos[i+1]>pos[i])
            cnt++;
        else
            mx = max(mx,cnt) , cnt = 1;

    }

    mx = max(mx,cnt);

    cout<<n-mx<<endl;


    return 0;
}

/**

10
7 9 8 2 3 4 1 10 5 6

10
1 7 9 8 2 3 4 10 5 6

**/





Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<string> in(n);
  for(int i = 0;i< n;i++){
    cin >> in[i];
  }
  vector<int> check(n, 1);//ok
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      int A = j, B = i;
      for(int k = 0;k < n;k++){
	A = (A+1)%n;
	B = (B-1+n)%n;
	if (in[i][j] != in[A][B]){
	  check[k] = 0;
	}
      }
    }
  }
  int ans = count(begin(check), end(check), 1);

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


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	int K;
	cin >> K;

	int even = K / 2;
	int odd = K / 2 + K % 2;

	cout << even * odd << endl;

	return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    DList!char().pipe!((list) {
        readln.chomp.each!((c) {
            if (c=='B') {
                if (!list.empty) list.removeBack;
            } else {
                list.insertBack(c);
            }
        });
        return list;
    })[].writeln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

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

const int INF = 1e9 + 7;

int main()
{
	IO_OP;
	
	string s;
	cin >> s;
	int y = stoi(s.substr(0, 4)), m = stoi(s.substr(5, 2)), d = stoi(s.substr(8, 2));
	if(y > 2019 || (y == 2019 && m > 4) || (y == 2019 && m == 4 && d > 30)) {
		cout << "TBD" << endl;
	} else {
		cout << "Heisei" << endl;
	}
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]){
   long long A,B,C,_A,_B,_C,i;
   cin >> A >> B >> C;
   i = 0;
   while(A%2==0 && B%2==0 && C%2==0){
      if(A==B && B==C){
         cout << -1 << endl;
         return 0;
      }
      i++;
      _A = A;
      _B = B;
      _C = C;
      A = (_B+_C)/2;
      B = (_A+_C)/2;
      C = (_A+_B)/2;
   }
   cout << i << endl;
   return 0;
}

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

int main()
{
    long x,a,b;
    cin>>x>>a>>b;
    long sub;
    long m;
    sub=x-a;
    m=sub%b;
    cout<<m;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include <limits>
using namespace std;
// numeric_limits<double>::epsilon()
 
#define int int64_t
#define pr(x) cout << x << endl;
#define vi vector<int>
#define vii vector< vector<int> >
#define mp make_pair
#define f(i,n) for(i =0 ; i< n ; i++)
#define ff first
#define ss second
#define pb push_back
#define INF 1e9
#define SIZE 200001
#define mod 1000000007
void solve();


int power(int a, int b)
{
    if(b==0) return 1;
    else if(b&1) return a*power(a*a,b/2);
    else return power(a*a, b/2);
}
 


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}
bool AreSame(double a, double b) {
    return std::fabs(a - b) < std::numeric_limits<double>::epsilon();
}
 
int  j=1, n, t, m=0, dot=0, i, k, q, a, x, y, n1, m1;

void extendGcd(int m, int n)
{
    if(n==0)
    {
        x=1;
        y=0;
        dot=m;
    }
    else
    {
        extendGcd(n,m%n);
        q = x;
        x = y;
        y = q - (m/n)*y;
    }
    

}

string s1, s2,s3;
void solve()
{
    // cin >> t;while(t--)
    {
        cin >> n;
        cout << n*n*3;
    }
    
}

Measured memory_bytes: 256
#ifdef Rahul
#include "RAHUL.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

#include <atcoder/dsu>

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int n, q; cin >> n >> q;
  auto dsu = atcoder::dsu(n);
  while (q--) {
    int t, u, v; cin >> t >> u >> v;
    if (t == 0) {
      dsu.merge(u, v);
    } else {
      cout << (int) dsu.same(u, v) << '\n';
    }
  }
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int n;
LL pre=0,ans=0;
map <LL,int> occ;
int main()
{
	scan(n);
	occ[0]=1;
	for(int i=0;i<n;i++)
	{
		int input;
		scan(input);
		pre+=input;
		ans+=occ[pre];
		occ[pre]++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define maxn 110
#define LL long long 
#define INF 0x3f3f3f3f

int n,x,a[maxn];

int main(){
	//freopen("test.in","r",stdin);
	cin>>n>>x;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	int ans=x,cnt=0;
	for(int i=1;i<=n;i++){
		if(ans>=a[i]){
			ans-=a[i];
			cnt++;
		}
	}
	if(cnt==n&&ans) cnt--;
	cout<<cnt<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   string s; cin>>s;
   sort(s.begin(),s.end());
   if(s=="abc") cout<<"Yes"<<endl;
   else cout<<"No"<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N;
int boss[1000],height[1000];
bool is_Integrated[1000];

int get_boss(int id){
	if(boss[id] == id)return id;
	else{
		return boss[id] = get_boss(boss[id]);
	}
}

int is_same(int x,int y){
	return get_boss(x) == get_boss(y);
}

void unite(int x,int y){
	int boss_x = get_boss(x);
	int boss_y = get_boss(y);

	if(boss_x == boss_y)return;

	if(height[x] > height[y]){

		boss[boss_y] = boss_x;

	}else if(height[x] < height[y]){

		boss[boss_x] = boss_y;

	}else{ //height[x] == height[y]

		boss[boss_y] = boss_x;
		height[x]++;
	}
}


int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	for(int i = 0; i < N; i++){
		boss[i] = i;
		height[i] = 0;
		is_Integrated[i] = false;
	}

	int a,b;

	for(int loop = 0; loop < M; loop++){
		scanf("%d %d",&a,&b);
		a--;
		b--;
		unite(a,b);
		is_Integrated[a] = true;
		is_Integrated[b] = true;
	}

	int city_num = 0,village_num = 0;

	for(int i = 0; i < N; i++){
		if(is_Integrated[i] == true && get_boss(i) == i){
			city_num++;
		}else if(is_Integrated[i] == false){
			village_num++;
		}
	}

	printf("%d\n",abs(city_num-village_num));

	return 0;
}

Measured memory_bytes: 3220
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N, D;
    cin >> N >> D;

    D *= D;

    int cnt = 0;
    REP(i, N) {
        ll x, y; cin >> x >> y;

        if (x * x + y * y <= D) cnt++;
    }

    print(cnt);

    
}


Measured memory_bytes: 3668
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
#define ll long long
const int maxn = 4010;
int N;
char s[maxn];
vector<int> g[3];
vector<pair<int, int> > p;

int main(){
    scanf("%d", &N);
    scanf("%s", s+1);
    for (int i = 1; i <= N; i++){
        if (s[i] == 'R') g[0].push_back(i);
        else if (s[i] == 'G') g[1].push_back(i);
        else g[2].push_back(i);
    }
    ll ans = 0;
    for (int i = 0; i < g[0].size(); i++){
        for (int j = 0; j < g[1].size(); j++){
            int a = g[0][i], b = g[1][j];
            int d = b-a;
            if (a-d>0){
                int pos = lower_bound(g[2].begin(), g[2].end(), a-d)-g[2].begin();
                if (pos < g[2].size() && g[2][pos]==a-d) ans++;
            }
            if (b+d<=N){
                int pos = lower_bound(g[2].begin(), g[2].end(), b+d)-g[2].begin();
                if (pos < g[2].size() && g[2][pos]==b+d) ans++;
            }
            if ((b-a+1)%2){
                int pos = lower_bound(g[2].begin(), g[2].end(), (a+b)/2)-g[2].begin();
                if (pos < g[2].size() && g[2][pos]==(a+b)/2) ans++;
            }
        }
    }
    printf("%lld\n", g[0].size()*g[1].size()*g[2].size()-ans);
}


Measured memory_bytes: 3824
program main
	implicit none
	integer(8):: A,B,C,N,i,j,t,k
	read *, A
	B=A/1000
    C=A-B*1000
    if(C==0)then
	print'(I0)',0
    else
    print'(I0)',1000-c
    end if
    
end program main

Measured memory_bytes: 2924
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int n; cin>>n;
    vector<ll> a(n), b(n);
    for(int i=0; i<n; i++) cin>>a[i]>>b[i];
    ll sum = accumulate(all(a), 0LL);

    ll mi = INF;
    for(int i=0; i<n; i++){
        if(a[i] > b[i]) chmin(mi, b[i]);
    }

    if(mi == INF){
        cout << 0 << endl;
        return 0;
    }

    cout << sum - mi << endl;

    return 0;
}

Measured memory_bytes: 640
import math

takahashi_hp, t_atack, aoki_hp, a_attack = map(int, input().split())

t_atk_count = aoki_hp / t_atack
a_atk_count = takahashi_hp / a_attack

if math.ceil(a_atk_count) >= math.ceil(t_atk_count):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9116
#include<cstdio>
using namespace std;
long long int base[40];
int num[40]={0};
int s[200]={0};
int main(){
	long long int N;
	scanf("%lld",&N);
    base[0]=1;
    for(int i=1;i<40;i++){
    	base[i]=base[i-1]*2;
	}
	int k=39;
	while(N>0){
		while(N<base[k]) k--;
		num[k]=1;
		N=N-base[k];
	}
	for(k=39;k>=0;k--){
		if(num[k]!=0) break;
	}
	int length=2*k+2;
	for(int i=0;i<k;i++){
		if(num[i]!=0) length+=2;
	}
	printf("%d\n",length);
	for(int i=0;i<k;i++){
		if(num[i]!=0) printf("%d ",k+i+2);
		printf("%d ",i+1);
	}
	for(int i=0;i<k;i++){
		printf("%d ",i+1);
	}
	printf("%d %d",k+1,k+1);
	for(int i=k-1;i>=0;i--){
		if(num[i]!=0) printf(" %d",k+i+2);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define N 50
using namespace std;

string maxNum(string A,string B){

  if(A.size()>B.size()) return A;
  if(A.size()<B.size()) return B;

  for(int i=0;i<A.size();i++){
    if(A[i]>B[i]) return A;
    if(A[i]<B[i]) return B;
  }

  return A;
}

int main(){

  string s;
  cin>>s;

  //  s="L("+s+",0)";
  
  int slen=s.size();
  string dp[N][N];

  for(int i=0;i<slen;i++){

    string num;
    
    for(int j=i;j<slen;j++){
      
      if(('0'<=s[j]&&s[j]<='9')||s[j]=='?'){
	
	if(s[j]!='?') num+=s[j];
	else num+='9';

	if(num.size()>=2&&num[0]=='0') break;
	
	dp[i][j]=num;
	
      }else break;
      
    }
    
  }
  
  for(int w=6;w<=slen;w++){
    
    for(int i=0;i<=slen-w;i++){
      
      if(s[i]!='?'&&(s[i]!='L'&&s[i]!='R')) continue;

      if(s[i+1]!='?'&&s[i+1]!='(') continue;

      if(s[i+w-1]!='?'&&s[i+w-1]!=')') continue;
      
      for(int j=i+3;j<=i+w-3;j++){
	
	if(s[j]!='?'&&s[j]!=',') continue;
	if(dp[i+2][j-1]==""||dp[j+1][i+w-2]=="") continue;
	
	if(s[i]=='?'||s[i]=='L') dp[i][i+w-1]=maxNum(dp[i][i+w-1],dp[i+2][j-1]);
	
	if(s[i]=='?'||s[i]=='R') dp[i][i+w-1]=maxNum(dp[i][i+w-1],dp[j+1][i+w-2]);
	
      }
    
    }
    
  }
  
  if(dp[0][slen-1]!="") cout<<dp[0][slen-1]<<endl;
  else cout<<"invalid"<<endl;
  
  return 0;
}

Measured memory_bytes: 3308
# K = int(input())
# S = input()

# if len(S) > K:
#     print(S[:K] + '...')
# else:
#     print(S)

K = int(input())
S = input()

def answer(K: int, S: str) -> str:
    if len(S) <= K:
        return S
    else:
        return S[:K]+ '...'

print(answer(K, S))

Measured memory_bytes: 9156
use proconio::input;
use std::collections::HashMap;

/// 状態
#[derive(Hash, Eq, PartialEq, Ord, PartialOrd, Clone, Copy)]
struct State {
    /// 受理状態かどうか
    is_accept: bool,
    /// State間を比較できるように，IDをつけておく
    id: usize,
}

/// 有限オートマトンを表す構造体
struct Automaton {
    /// 状態の有限集合Q
    states: HashMap<String, State>,
    /// 遷移関数群
    transitions: HashMap<State, Box<dyn Fn(char) -> String>>,
    /// Stateにつける通し番号
    id: usize,
}

impl Automaton {
    /// ある状態qと, qからの遷移関数を登録する
    fn add_states(&mut self, name: &str, is_accept: bool, transition: fn(char) -> String) {
        let state = State {
            is_accept,
            id: self.id,
        };
        self.id += 1;
        self.states.insert(name.to_string(), state);
        self.transitions.insert(state, Box::new(transition));
    }

    /// 言語Lで記述された文字列sを受理するか判定
    fn run(&self, s: String) -> bool {
        let mut current_state = *self.states.get("q0").unwrap();
        for c in s.chars() {
            let transition = self.transitions.get(&current_state).unwrap();
            let next_state_name = transition(c);
            current_state = *self.states.get(&next_state_name).unwrap();
        }
        current_state.is_accept
    }
}

fn transition_q0(c: char) -> String {
    if c == 'A' {
        return "q1".to_string();
    }

    "q2".to_string()
}
fn transition_q1(c: char) -> String {
    if c == 'B' {
        return "q3".to_string();
    }

    "q1".to_string()
}
fn transition_q2(c: char) -> String {
    if c == 'A' {
        return "q3".to_string();
    }

    "q2".to_string()
}
fn transition_q3(_c: char) -> String {
    "q3".to_string()
}

fn main() {
    input! {
        s: String,
    }

    let mut m = Automaton {
        states: HashMap::new(),
        transitions: HashMap::new(),
        id: 0,
    };

    m.add_states("q0", false, transition_q0);
    m.add_states("q1", false, transition_q1);
    m.add_states("q2", false, transition_q2);
    m.add_states("q3", true, transition_q3);

    if m.run(s) {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 2168
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[i] != S[j]:
            x = 2 * j - i
            if x < N and S[i] != S[x] and S[x] != S[j]:
                ans -= 1

print(ans)


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

int main()
{
  int N;scanf("%d",&N);
  int a[N];
  for(int i=0;i<N;i++)scanf("%d",&a[i]);
  bool col[8];fill(col,col+8,false);
  sort(a,a+N);int minans=0,maxans=0;
  for(int i=0;i<N;i++)
  {
    if(a[i]>=3200)
    {
      if(minans==0)minans++;
      maxans++;continue;
    }
    if(!col[a[i]/400]){minans++;maxans++;}
    col[a[i]/400]=true;
  }
  printf("%d %d",minans,maxans);
}

Measured memory_bytes: 3840
#include <iostream>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 201;
i64 LIM = 1e13;
i64 dp[maxn][maxn];

i64 common_sub(vi s, vi t) {
    int n = s.size(), m = t.size();
    forn(i, n + 1) forn(j, m + 1) dp[i][j] = 0;
    dp[0][0] = 1;
    forn(i, n + 1) forn(j, m + 1) {
        if (i) dp[i][j] += dp[i - 1][j];
        if (j) dp[i][j] += dp[i][j - 1];
        if (i && j && s[i - 1] != t[j - 1]) dp[i][j] -= dp[i - 1][j - 1];
        if (dp[i][j] >= LIM) return LIM;
    }
    return dp[n][m];
}

int main() {
    i64 n;
    cin >> n;
/*    if (n == 1) {
        cout << "1\n1\n";
        return 0;
    }*/
    vi a;
    i64 ans = 0;
    int x = 1;
    while (ans < n) {
        int bi = -1;
        i64 bx = -1e9;
        forn(i, a.size() + 1) {
            i64 res = common_sub(vi(a.begin(), a.begin() + i), vi(a.begin() + i, a.end()));
            if (ans + res <= n && res > bx) bx = res, bi = i;
//            cerr << i << ' ' << res << '\n';
        }

        vi b;
        forn(i, a.size() + 1) {
            if (!i) b.pb(x);
            if (i == bi) b.pb(x);
            if (i < a.size()) b.pb(a[i]);
        }
        a = b;
        ans += bx;
        ++x;
    }
    cout << a.size() << '\n';
    forn(i, a.size()) cout << a[i] << " \n"[i + 1 == a.size()];
}


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

int main(){
	int n,l;
	cin>>n>>l;
	vector<int> V;
	for(int i=0; i<n; i++){
		V.push_back(l+i);
	}
	int d=abs(V[0]-0);
	int sum=0,p=V[0];
	for(int i=0; i<n; i++){
		if(d>abs(V[i]-0)){
			d=abs(V[i]-0);
			p=V[i];
		}
		sum+= V[i];
	}
	cout<<sum-p<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
int x[20],y[20];
int sx,sy,mx,my;
bool c[20];
bool f(int u,double d)
{
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(c[i])
		{
			cnt++;
			continue;
		}
		double a=hypot(x[u]-x[i],y[u]-y[i])+d;
		double b=hypot(mx-x[i],my-y[i]);
		if(b<=a)return false;
	}
	if(cnt==n)return true;
	for(int i=0;i<n;i++)
	{
		if(c[i])continue;
		double a=hypot(x[u]-x[i],y[u]-y[i])+d;
		double b=hypot(mx-x[i],my-y[i]);
		if(b>a)
		{
			c[i]=1;
			if(f(i,a))return true;
			c[i]=0;
		}
	}
	return false;
}
main()
{
	while(cin>>n>>sx>>sy>>mx>>my,n)
	{
		for(int i=0;i<n;i++)cin>>x[i]>>y[i];
		for(int i=0;i<n;i++)c[i]=0;
		bool fl=0;
		for(int i=0;!fl&&i<n;i++)
		{
			double a=hypot(sx-x[i],sy-y[i]);
			double b=hypot(mx-x[i],my-y[i]);
			if(a<b)
			{
				c[i]=1;
				fl|=f(i,a);
				c[i]=0;
			}
			else break;
		}
		cout<<(fl?"YES":"NO")<<endl;
	}
}



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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;


#define F first
#define S second

#define ERR 1e-9

#if !ONLINE_JUDGE && !EVAL
    #define dbg_var(x) cerr << #x << ": " << x << "\n";
    #define dbg_iter(x, y) cerr  << #x << ": " << print_iterable(x, y) << "\n";
#else
    #define dbg_var(x)
    #define dbg_iter(x, y)
#endif // ONLINE_JUDGE

template <typename T1, typename T2>
string print_iterable( T1 begin_iter, T2 end_iter){
    bool first = true;
    stringstream res;
    res << "[ ";
    for(; begin_iter != end_iter; ++begin_iter){
        if(!first) res << ", ";
        first = false;
        res << *begin_iter;
    }
    res << " ]";
    return res.str();
}

void aggMax(int & res, int x){ if(x > res)res = x; }
void aggMin(int & res, int x){ if(x < res)res = x; }

int II(){ int i; cin >> i; return i; }
void OI(int i){ cout << i; }

// constraints
#define MAXN 1000000

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N = II(), M = II();
    vector<pair<ll, int>> D(N);
    for(int i=0; i<N; i++){
        D[i] = {II(), II()};
    }
    sort(D.begin(), D.end());
    ll cost = 0;
    for(int i=0; i<N && M>0; i++){
        cost += ll(D[i].F * min(M, D[i].S));
        M -= D[i].S;
    }
    cout << cost << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 200000, z = maxn-1, maxk = 64;
int U = 100, p2[maxn], gar[3]{99, 98, 97}, pos[2][maxk];
unsigned long long a[maxn]{14102938400, 989823421}, S = a[0] * a[1];
int new_sp() {
	return U++;
}
vector<string> op;
int sum(int i, int j, int k = -1) {
	int p = (k==-1 ? new_sp() : k);
	a[p] = a[i] + a[j];
	op.pb("+ " + to_string(i) + " " + to_string(j) + " " + to_string(p));
	//cout << "+ " << i << ' ' << j << ' ' << p << endl;
	return p;
}
int cmp(int i, int j, int k = -1) {
	int p = (k==-1 ? new_sp() : k);
	a[p] = a[i] < a[j];
	op.pb("< " + to_string(i) + " " + to_string(j) + " " + to_string(p));
	//cout << "< " << i << ' ' << j << ' ' << p << endl;
	return p;
}
void mkp2() {
	p2[0] = sum(0, 1);
	cmp(z, p2[0], p2[0]);
	for (int i = 1;i < maxk;++i)
		p2[i] = sum(p2[i-1], p2[i-1]);
}
void mul01(int i, int j, int k) {
	sum(i, j, gar[0]);
	cmp(p2[0], gar[0], k);
}
void clear(int i) {
	cmp(i, i, i);
}
void up(int pos, int t) {
	while (t--) sum(pos, pos, pos);
}
void decomp(int v, int* pos) {
	int csum = gar[1];
	clear(csum);
	for (int i = maxk-1;i >= 0;--i) {
		int asum = sum(p2[i], csum), cp = sum(p2[0], v);
		pos[i] = cmp(asum, cp);
		sum(pos[i], z, gar[2]);
		up(gar[2], i);
		sum(csum, gar[2], csum);
	}
	//ll RV = a[v];
//	for (int i = 0;i < maxk;++i)
//		cerr << (RV>>i&1);
//	cerr << '\n';
//	for (int i = 0;i < maxk;++i)
//		cerr << a[pos[i]];
//	cerr << '\n';
}
void solve() {
	const int H = 1000, To = 3000, G = 4000;
	for (int i = 0;i < maxk;++i) {
		for (int j = 0;j <= i;++j) {
			int x = j, y = i-j;
			mul01(pos[0][x], pos[1][y], G);
			up(G, i);
			sum(To, G, To);
		}
	}
	clear(2);
	sum(2, To, 2);
}

signed main(){
	mkp2();
	decomp(0, pos[0]);
	decomp(1, pos[1]);
	solve();
	cout << op.size() << '\n';
	for (auto i : op) 
		cout << i << '\n';

//	for (int i = 0;i < 10;++i)
//		cerr << (1ll<<i) << ' ' << a[p2[i]] << '\n';




	cerr << "Ans should be " << S << ", Mine is " << a[2] << ' ' << (a[2] == S ? "AC " : "WA " ) << endl;
}



Measured memory_bytes: 10472
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // input 
  int A, B, M;
  cin >> A >> B >> M;
  
  vector <int> a(A, 0), b(B, 0);  
  for(int i=0; i<A; i++) cin >> a.at(i);
  for(int i=0; i<B; i++) cin >> b.at(i);
  
  vector <int> x(M, 0), y(M, 0), c(M, 0);
  for(int i=0; i<M; i++) cin >> x.at(i) >> y.at(i) >> c.at(i);
  
  // inputの確認
  // cout << a.at(1) << b.at(1) << endl;
  // cout << x.at(0) << y.at(0) << c.at(0) << endl;
  
  int total = 0;
  int min = *std::min_element(a.begin(), a.end()) + *std::min_element(b.begin(), b.end());
  for(int j=0; j<M; j++){
  	total = a.at(x.at(j)-1) + b.at(y.at(j)-1) - c.at(j);
    if(total < min) min = total;
  }
  
  cout << min << endl;
  
  return 0;
}

Measured memory_bytes: 2176
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	ll n;cin>>n;
	map<string,ll> cnt;
	rep(i,0,n)
	{
		string s;cin>>s;
		cnt[s]++;
	}

	ll mx = -1;
	all(it,cnt) mx=max(mx,it->S);
	vs a;
	all(it,cnt) if(it->S==mx) a.pb(it->F);
	sort(a.begin(), a.end());
	rep(i,0,sz(a)) cout<<a[i]<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}


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

int main(){
    int n; cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    
    vector<int> rev(n);
    rep(i,n) rev[a[i]-1]=i+1;
    rep(i,n) cout<<rev[i]<<endl;
    return 0;
}


Measured memory_bytes: 1664