akhauriyash/Code-Regression huggingface dataset:
#include <string.h>
#include <iostream>

using namespace std;

int main()
{
	const int MAX_DATAS = 1000;

	int N[MAX_DATAS], M[MAX_DATAS], CHECK[1099], ANS[MAX_DATAS], C1 = 0, C = 1, D = 1, E = 0;
	
	while (true)
	{
		memset(CHECK, -1, sizeof(CHECK)); // -1

		C = 1; D = 1; E = 0;

		cin >> N[C1] >> M[C1];

		if (M[C1] == 1) { ANS[C1] = N[C1]; goto Exit2; }

		if (N[C1] == 0 && M[C1] == 0) { goto Exit3; }

		while (true)
		{
			if (CHECK[C] % M[C1] != 0)
			{
				CHECK[C] = D;

				if (D % M[C1] == 0) { E++; }

				D++;
			}

			C++;

			if (C > N[C1]) { C -= N[C1]; }

			if (E == N[C1]) { goto Exit1; }
		}

	Exit1:;

		for (int i = 1; i <= N[C1]; i++)
		{
			CHECK[i] /= M[C1];
		}

		for (int i = 1; i <= N[C1]; i++)
		{
			if (CHECK[i] == N[C1]) { ANS[C1] = i; }
		}

	Exit2:;

		C1++;
	}

Exit3:;

	for (int i = 0; i < C1; i++)
	{
		cout << ANS[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a,b;
	cin>>a>>b;
	if(a=='H'&&b=='H')
	cout<<'H';
	else if(a=='D'&&b=='D')
	cout<<'H';
	else
	cout<<'D';
 return 0;

}


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

using namespace std;

typedef long long int ll;

vector <pair <ll,ll> > veca;
int main()
{
    ll n,a,b,b1,c,c1,i,j,k,p,q,minn;
    cin >> a >> b;
    cout << max((a+b),max((a-b),(a*b))) << endl;
}



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

int main(){
  int N,M;
  cin >> N >> M;
  int d[2*M];
  for(int i = 0; i < 2*M; i++) cin >> d[i];
  
  int num[N+1] = {0};
  for(int i = 0; i < 2*M; i++){
    num[d[i]]++;
  }
  for(int i = 1; i <= N; i++){
    cout << num[i] << endl;
  }
}

Measured memory_bytes: 256
/*********************************************JMD**********************************************/
//                                  |\  |     | |   |   /\                                   //
    //                              | \ |     | |---|  /--\                              //
        //                          |  \| |___| |   | /    \1999                     //
/*******************************************************************************************/
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define mem(x,val) memset(x,val,sizeof(x))
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define f(i,n) forr(i,0,n)
#define sz(x) ll((x).size())
#define all(x) ((x).begin(),(x).end())
#define asc(x) ((int)(x))
#define precision(x) cout<<fixed<<setprecision((x));

const ll mod=1e9 + 7;

/*******************************************************************************************/

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

    ll a[n+1];
    a[0]=0;
    f(i,n) cin>>a[i+1];

    vector<ll> ans;

    for(ll i=n;i>=1;i--)
    {
        if(a[i])
        {
            ans.pb(i);
            ll d = sqrt(i+1);

            for(ll k=1;k<=d;k++)
            {
                if(i%k==0)
                {
                    ll j=i/k;

                    if(j<k) break;
                    if(k==j)
                    {
                        a[k]^=1;
                    }
                    else
                    {
                        a[k]^=1;
                        a[j]^=1;
                    }
                }
            }
        }
    }

    cout<<ans.size()<<"\n";
    for(auto x:ans) cout<<x<<" ";

    return;
}

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

    ll t=1;
    //cin>>t;
    clock_t launch=clock();

    while(t--)
    {
        solve();
    }

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    string S;
    cin >> S;
    if(S.at(2) == S.at(3) && S.at(4) == S.at(5)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define pb push_back
#define mp make_pair

typedef long long LL;
typedef pair<int,int> pii;

const int N = 2e5 + 10;
const int M = 1e6 + 10;

int n, a[N];
bool vis[M];

int main(){
	scanf("%d", &n);
	memset(vis, 0, sizeof(vis));
	for(int i=0; i<n; i++){
		scanf("%d", a+i);
		vis[a[i]] = 1;
	}
	if(n == 1){
		puts("1");
		return 0;
	}
	sort(a, a+n);
	if(a[0] == 1){
		if(a[1] == 1){
			puts("0");
		} else {
			puts("1");
		}
		return 0;
	}

	for(int i=0; i<n; i++){
		if(i && a[i] == a[i-1]){
			vis[a[i]] = 0;
			continue;
		}
		for(int j=a[i]<<1; j<M; j+=a[i]){
			vis[j] = 0;
		}
	}

	int ans = 0;
	for(int i=0; i<n; i++){
		if(vis[a[i]]){
			ans++;
		}
	}

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

	return 0;
}

Measured memory_bytes: 5548
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

#include <inttypes.h>
using namespace std;

int main()
{
	int32_t N;
	string S;
	cin >> N >> S;

	bool updated = true;
	int32_t sum;
	while (updated) {
		updated = false;
		sum = 0;
		for (size_t i = 0; i < S.size(); i++) {
			if (S[i] == '(') {
				sum++;
			} else {
				sum--;
			}
			if (sum < 0) {
				S = '(' + S;
				updated = true;
				break;
			}
		}
		if (sum > 0) {
			S = S + ')';
			updated = true;
		}
	}

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vs = vector<string>;
using vvs = vector<vs>;
using pli = pair<long long, int>;
using vpli = vector<pli>;

int main() {
  int N, P, Q, a = 1, b = 1, cnt = 0, tmp = 0;
  cin >> N;
  vector<bool> X(N, false);
  vector<bool> Y(N, false);
  
  for (int i = 0; i < N; i++) {
    cin >> P;
    X.at(P-1) = true;
    for (int j = 0; j < P - 1; j++) {
      if (X.at(j) == false) cnt++;
    }
    tmp = cnt;
    for (int k = N - 1 - i; k > 0; k--) {
      tmp *= k;
    }
    a += tmp;
    cnt = 0;
    tmp = 0;
  }
  for (int i = 0; i < N; i++) {
    cin >> Q;
    Y.at(Q-1) = true;
    for (int j = 0; j < Q - 1; j++) {
      if (Y.at(j) == false) cnt++;
    }
    tmp = cnt;
    for (int k = N - 1 - i; k > 0; k--) {
      tmp *= k;
    }
    b += tmp;
    cnt = 0;
    tmp = 0;
  }
  
  if (a > b) cout << a - b << endl;
  else cout << b - a << endl;
  
}

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

int main(){
	int N;
	cin>>N;
	
	int h[101],m[101];
	for(int i=0;i<N;i++)
		cin>>h[i]>>m[i];
	h[N]=24; m[N]=0;
	
	int M;
	cin>>M;
	
	int k[101],g[101];
	for(int i=0;i<M;i++)
		cin>>k[i]>>g[i];
	k[M]=24; g[M]=0;

	for(int i=0,j=0;i<N||j<M;){
		if(h[i]==k[j]&&m[i]==g[j]){
			cout<<h[i]<<':'<<m[i]/10<<m[i]%10;
			i++; j++;
		}
		else if(h[i]<k[j]||(h[i]==k[j]&&m[i]<g[j])){
			cout<<h[i]<<':'<<m[i]/10<<m[i]%10;
			i++;
		}	
		else{
			cout<<k[j]<<':'<<g[j]/10<<g[j]%10;
			j++;
		}
		
		if(i==N&&j==M)
			cout<<endl;
		else
			cout<<' ';
	}

	return 0;
}

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> vec(N, vector<int>(D));
  rep (i, N)  rep (j, D) cin >> vec[i][j];// vec[i]=i点におけるXの座標.N種類
  int sum = 0;
  
  rep (i, N-1) {
    for (int j = i+1; j < N; j++) {
      int distance = 0;
      rep (k, D) {
        int x = (vec[i][k] - vec[j][k]);
        distance += x * x;
      }
      bool flag = false;
      rep (l, distance+1) {
        if (distance == l * l) flag = true;
      }
      if (flag) sum++;
    }
  }
  cout << sum << endl;

}


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

void solve() {
	int t;
	cin >> t;
	cout << (t >= 30 ? "Yes" : "No");
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	for (int i = 1; i <= t; i++) {
		solve();
	}
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

ll num(ll n)
{
  return n*(n+1)/2;
}

int main()
{
  int n;
  cin >> n;
  vector<string> s;
  for(int i = 0;i < n;i++)
  {
    string S;
    cin >> S;
    sort(S.begin(),S.end());
    s.push_back(S);
  }
  sort(s.begin(),s.end());
  vector<ll> ans;
  ll a = 0;
  for(int i = 1;i < n;i++)
  {
    if(s[i-1] == s[i]) a++;
    else
    {
      ans.push_back(a);
      a = 0;
    }
  }
  ans.push_back(a);
  ll b = 0;
  for(int i = 0;i < ans.size();i++)
  {
    b += num(ans[i]);
  }
  cout << b << endl;
}


Measured memory_bytes: 7284
#include<bits/stdc++.h> 
#define double long double
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=200005;
int n,K,a[N],cnt[N],ans;
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	scanf("%d%d",&n,&K);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		cnt[a[i]]++;
	}
	sort(cnt+1,cnt+n+1,cmp);
	for(int i=K+1;i<=n;i++)
	  ans+=cnt[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int a;
int main()
{
    cin >> a;
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            if(i*j == a){
                cout << "Yes" << endl;
                return 0;
            }
           // cout << i*j << endl;
        }
    }
    cout << "No" << endl;
    
}

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


int main(void)
{
  int n;
  cin >> n;
  vector<int> data(n);
  rep(i,n) cin >> data[i];
  bool flag =  true;
  int cnt = 0;
  while(flag)
  {
    flag = false;
    for(int j = n-1; j > 0; j--)
    {
      if(data[j] < data[j-1])
      {
        swap(data[j],data[j-1]);
        cnt++;
        flag = true;
      }
    }
  }
  //cout << data[0];
  rep(i, n) 
  {
    if(i > 0) cout << " ";
    cout << data[i];
  }
  cout << endl;
  cout << cnt << endl;
  return (0);
} 


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;

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

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n, a, b; cin >> n >> a >> b;

	ll d = abs(a - b);
	if (d & 1)
	{
		ll tmp1 = a + abs(1 - (b - a))/2;
		ll tmp2 = (n - b + 1) + abs((n-b+1)+a-n)/2;
		
		std::cout << min({tmp1, tmp2, n-a, b-1}) << std::endl;
	}
	else
	{
		std::cout << min({d/2, n-a, b-1})<< std::endl;
	}
	return 0;
}


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

using namespace std;

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

typedef long long ll;

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

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int l = -1, r = -1;
    rep (i, s.size() - 1) {
        if (s[i] == s[i + 1]) {
            l = i + 1, r = i + 2;
        }
    }
    rep (i, s.size() - 2) {
        if (s[i] == s[i + 2] && s[i] != s[i + 1]) {
            l = i + 1, r = i + 3;
        }
    }
    cout << l << " " << r << endl;
    
    
    return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    int n;
    cin>>n;
    vc<pi> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first>>a[i].second;
        if(a[i].first>a[i].second) swap(a[i].first,a[i].second);
    }
    int mxl=-1,mil=0x3f3f3f3f,mir=0x3f3f3f3f,mxr=-1;
    for(int i=0;i<n;i++)
    {
        mxl=max(mxl,a[i].first);
        mxr=max(mxr,a[i].second);
        mil=min(mil,a[i].first);
        mir=min(mir,a[i].second);
    }
    ll ans=1LL*(mxr-mir)*(mxl-mil);
    int mx=max(mxl,mxr),mi=min(mil,mir);
    sort(a.begin(),a.end());
    mil=0x3f3f3f3f;
    multiset<int> rd;
    for(int i=0;i<n;i++) rd.insert(a[i].first);
    for(int i=0;i<n;i++)
    {
        mxl=max(mxl,a[i].second);
        rd.erase(rd.find(a[i].first));
        rd.insert(a[i].second);
        mil=*rd.begin();
        ans=min(ans,1LL*(mx-mi)*(mxl-mil));
    }

    cout<<ans<<'\n';

}

Measured memory_bytes: 11136
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i=0; i<n; i++)
#define repi(i, n, iv) for (int i=iv; i<n; i++)
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

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

	int N;
	cin >> N;

	vector<ll> A(N);
	rep(i, N) cin >> A[i];
  std::sort(A.begin(), A.end());

  if (A[0] == 0) {
    cout << 0 << endl;
    exit(0);
  }

  double result = 1;
  for (int i=0; i<N; i++) result *= A[i];

  if (result >= 2000000000000000000) {
    cout << -1 << endl;
    exit(0);
  }

  ll r = 1;
  for (int i=0; i<N; i++) r *= A[i];
   if (r > 1000000000000000000) {
     cout << -1 << endl;
   } else {
     cout << r << endl;
   }
}


Measured memory_bytes: 4372
#define _GNU_SOURCE // use memmem(3)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int N;
char S[10000];

int judge(int slen)
{
    int l1;
    char *result;
    if (slen == 0)
        return 1;
    for (l1=0; l1 < N+1-2*slen; l1++) {
        result = memmem(S+l1+slen, N-l1-slen, S+l1, slen);
        //printf("slen %d l1 %d subst %s result %s\n", slen, l1, subst, result?"Yes":"No");
        if (result != NULL) {
            return 1;
        }
    }
    return 0;
}

int find_min_false(int n)
{
    int i = 0;
    int j = n;
    while (i < j) {
        int h = (i+j) >> 1;
        if (judge(h))
            i = h + 1;
        else
            j = h;
    }
    return i;
}

int main()
{
    int ans;
    int _ = scanf("%d %s", &N, S);
    ans = find_min_false(N/2+1);
    if (ans == 0) {
        printf("0\n");
    } else {
        printf("%d\n", ans-1);
    }
}

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

int main() {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  vector<vector<int>> ans(H, vector<int>(W));
  for (int i = 0; i < H - B; i++) {
    for (int j = 0; j < W - A; j++) {
      ans[i][j] = 1;
    }
  }
  for (int i = H - B; i < H; i++) {
    for (int j = W - A; j < W; j++) {
      ans[i][j] = 1;
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<double> X(N), Y(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
  }
  vector<vector<double>> D(N, vector<double>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      D[i][j] =
          sqrt((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]));
    }
  }
  vector<int> M;
  for (int i = 0; i < N; i++) {
    M.emplace_back(i);
  }
  double res = 0;
  do {
    for (int i = 0; i < N - 1; i++) {
      res += D[M[i]][M[i + 1]];
    }
  } while (next_permutation(M.begin(), M.end()));
  for (int i = 0; i < N; i++) {
    res /= (i + 1);
  }
  cout << setprecision(10) << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve(){
	float d,t,s;
	cin>>d>>t>>s;
	if(d/s<=t)cout<<"Yes";
	else cout<<"No";
}
int main()
{
	Start;

	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
		cout << "\n";
	}
	return 0;
} 

Measured memory_bytes: 3736
#include <stdio.h>
#pragma warning(disable : 4996)
#define mod 1000000007
int H, W, A, B, i, fact[200009], inv[200009], factinv[200009], ret;
inline int ncr(int xx, int yy) {
	if (xx < 0 || yy < 0 || xx < yy) return 0;
	return 1LL * fact[xx] * factinv[yy] % mod * factinv[xx - yy] % mod;
}
int main() {
	fact[0] = 1;
	for (i = 1; i <= 200009; i++) fact[i] = 1LL * fact[i - 1] * i % mod;
	inv[1] = 1;
	for (i = 2; i <= 200009; i++) inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
	factinv[0] = 1;
	for (i = 1; i <= 200009; i++) factinv[i] = 1LL * factinv[i - 1] * inv[i] % mod;
	scanf("%d%d%d%d", &H, &W, &A, &B);
	for (i = 0; i < W - B; i++) ret = (ret + 1LL * ncr(A + i - 1, i) * ncr(W - i + H - A - 2, H - A - 1)) % mod;
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;

int main(){
  string s,t;
  cin>>s>>t;
  int flag=0;
  int ind=0;
  int ans=0;
  //cout<<s.size()-t.size()<<endl;
  for(int i=0;i+t.size()<=s.size();i++){
    if(s[i]==t[0]||s[i]=='?'){
      flag=0;
      //cout<<i<<endl;
      for(int j=0;j<t.size();j++){
        if(s[i+j]==t[j]||s[i+j]=='?'){
          flag=1;
        }else{
          flag=0;
          break;
        }
      }
      if(flag==1){
        ind=i;
        ans=1;
      }
    }
  }

  //cout<<ind<<endl;

  if(ans==1){
    for(int i=0;i<s.size();i++){
      if(i<ind||i>=ind+t.size()){
        if(s[i]=='?'){
          cout<<"a";
        }else{
          cout<<s[i];
        }
      }else if(i==ind){
        for(int j=0;j<t.size();j++){
          cout<<t[j];
        }
        i=ind+t.size()-1;
      }
    }
    cout<<endl;
  }else{
    cout<<"UNRESTORABLE"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    n = min(n, b - 1);
    cout << a * n / b - a * (n / b) << "\n";
    return 0;
}

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (((bit >> i) & 1) > 0)

typedef long long LL;
template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a, Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}    // C++14
template<typename T,typename V> typename std::enable_if<std::is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename std::enable_if<std::is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

template<class T> inline std::vector<T> unique(std::vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}
// 初項s, 交差dのn個の数列の和
long long sum_of_arithmetic_progression(long long s, long long d, long long n) {
    return n * (2 * s + (n - 1) * d) / 2;
}

const int INF = 1 << 30;
const double EPS = 1e-9;
const long double PI = acos(-1.0);
//const std::vector<int> dy4 = {0, -1, 0, 1}, dx4 = {1, 0, -1, 0};
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };


using namespace std;


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

    int N;
    while (cin >> N) {
        LL ans = 0;
        FOR(a, 0, 10) {
            FOR(b, 0, 10) {
                FOR(c, 0, 10) {
                    FOR(d, 0, 10) {
                        ans += (a + b + c + d == N);
                    }
                }
            }
        }
        print(ans);
    }
    return 0;
}




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

static const int MAX = 200000;
int main()
{
	int R[MAX], n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> R[i];
	}

	int maxv = R[1] - R[0];
	int minv = R[0];
	for (int i = 1; i < n; i++)
	{
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	cout << maxv << endl;
	
	return 0;
}

Measured memory_bytes: 3860
s = gets.chomp.reverse

dream = "dream".reverse
dreamer = "dreamer".reverse
erase = "erase".reverse
eraser = "eraser".reverse

while not s.empty? do
    
    k = s.size
    next if s.sub!(eraser,  "")
    next if s.sub!(erase,   "")
    next if s.sub!(dreamer, "")
    next if s.sub!(dream,   "")
    
    if k == s.size
        puts "NO"
        exit
    end
end

puts "YES"

Measured memory_bytes: 77596
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PI 3.141592653589793238
int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("F:/cpp/input.txt", "r", stdin);
    // freopen("F:/cpp/output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, v, w, t, d, s;
    cin >> a >> v >> b >> w >> t;
    if (b-a == 0)
    cout << "YES\n";
    else if (w >= v)
    cout << "NO\n";
    else
    {
        d = abs(a - b);
        s = v - w;
        if (ceil((double)d/(double)s) <= t)
        cout << "YES\n";
        else
        cout << "NO\n";
    }
    return 0;
}

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

using namespace std;

int main() {
    int n,k;

    cin >> n >> k;

    int array[n];
    double e[n]={0};
    double e_sum[n+1]={0};

    for(int i = 0; i < n; i++) {
        cin >> array[i];
        for(int j = 0; j < array[i]; j++) {
            e[i]+=(double)(j+1)/array[i];
        }
        //cout << i << ":" << e[i] <<endl;
    }

    e_sum[0]=0;

    for(int i = 1; i < n+1; i++) {
        e_sum[i]=e[i-1]+e_sum[i-1];
        //cout << i << ":" << e_sum[i] << endl;
    }


    double max=0;
    for(int i = 0; i <= n-k; i++) {
        double tmp = e_sum[i+k]-e_sum[i];
        if(max < tmp) {
            max = tmp;
        }

    }

    cout << fixed << setprecision(15) << max << endl;
    return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define endl enjoy_codeforces
int main(){
    std::string s;std::cin>>s;
    int now=0,min=0;
    for(char c:s){
        now+=c=='S'?+1:-1;
        if(now<min)min=now;
    }
    std::cout<<now-2*min<<'\n';
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"


const int N = 1e6 + 5;
const int M = 1e9 + 7;

int mod( int m ,int mod = M) {
   m %= mod;
   return (m + mod) % mod;
}

int power(int x,int y) {
   int res = 1;
   x = mod(x);
   while (y > 0) {
      if (y & 1)
         res =mod(res * x);
      y = y / 2;
      x = mod(x * x);
   }
   return mod(res);
}

int f[N],invf[N];
void fact() {
   f[0] = f[1] = 1;
   for(int i=2;i<N;i++)
      f[i] = mod(f[i-1] * i);

   invf[N-1] = power(f[N-1],M-2);
   for(int i=N-1;i>0;i--)
      invf[i-1] = mod(invf[i] * i);

}

int nCr(int n,int r) {
   if(r>n)
      return 0;
   int ans = f[n];
   ans = mod(ans*invf[n-r]);
   ans = mod(ans*invf[r]);
   return ans;
}

int nPr(int n,int r) {
   if(r>n)
      return 0;
   int ans = f[n];
   ans = mod(ans*invf[n-r]);
   return ans;
}


int32_t main(){
	boost;
	int n, m;
	cin >> n >> m;
	if((n + m) % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}

	int tot = (n + m ) / 3;
	int x = -1;
	for(int i = 0; i <= n; i++) {
		int cur = 2 * i + (tot - i);
		if(cur > n)
			break;
		if(cur == n) {
			x = i;
			break;
		}
	}
	if(x == -1 or x + 2 * (tot - x) != m) {
		cout << 0 << endl;
		return 0;
	}

	fact();
	int ans = nCr(tot, x);
	cout << ans << endl;
}

Measured memory_bytes: 19276
#include <iostream>

using namespace std;

int main()
{
    int n, minim = 100000, maxim = -1;
    cin >> n;
    for (int i = 1; i<=n; ++i)
    {
        int x;
        cin >> x;
        minim = min(minim, x);
        maxim = max (maxim, x);
    }
    cout << maxim-minim;
    return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

class comp{
public:
    bool operator()(ii a, ii b){
        return min(a.ff, a.ss) < min(b.ff,b.ss);
    }
};

int main()
{
    int i = 0, j = 0, cs = 0, in;
    int n; cin>>n;
    vi v(n);
    for(i = 0; i < n; i++) cin>>v[i];
    sort(all(v), greater<int>());
    priority_queue<ii, vii, comp> q;
    q.push({v[0], v[1]});
    q.push({v[0],v[1]});
    ll ans = v[0];
    for(i = 2; i < n; i++){
        ii a = q.top();
        q.pop();
        ans += min(a.ff,a.ss);
        q.push({a.ff, v[i]});
        q.push({a.ss, v[i]});
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6160
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int count=0,z=0;
	for(int j=0;j<=100;j++)
	for(int i=0;i<n;i++)
	{z=0;
		while(a[i]>0&&i<n)
		{  z++;
			a[i]--;
			i++;
		}
		if(z>0)
		count++;
	}
	cout<<count;
}

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

int main(){
  string s;
  cin >> s;
  const string alp="qwertyuiopasdfghjklzxcvbnm";
  map<char,int>al;
  for(int i=0;i<26;i++)
    al[alp.at(i)]=0;
  for(int i=0;i<s.size();i++)
    al[s.at(i)]++;
  string ans="None";
  for(pair<char,int> x:al){
    if(x.second==0){
      ans=x.first;
      break;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
    char s[55][55];
    int n,m;
    cin >> n >> m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
    {
        char c;
        scanf("%c",&c);
        if(c=='#'||c=='.') s[i][j]=c;
        else j--;
    }
    bool ans=true;
    if(n==1&&m==1&&s[0][0]=='#') ans=false;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            if(s[i][j]=='#')
            {

                bool k=false;
                if(i&&s[i-1][j]=='#') k=true;
                if(j&&s[i][j-1]=='#') k=true;
                if(i!=n-1&&s[i+1][j]=='#') k=true;
                if(j!=m-1&&s[i][j+1]=='#') k=true;
                if(!k) ans=false;
            }
    if(ans) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
def solve():
    N, M = map(int, input().split())
    edges = [[] for _ in [0]*N]
    r_edges = [[] for _ in [0]*N]

    for _ in [0]*M:
        a, b = map(int, input().split())
        edges[a].append(b)
        r_edges[b].append(a)

    c = kosaraju(edges, r_edges)
    group = [0]*N
    for i in range(len(c)):
        for v in c[i]:
            group[v] = i

    result = []
    append = result.append
    for _ in [0]*int(input()):
        a, b = map(int, input().split())
        append("1" if group[a] == group[b] else "0")

    print("\n".join(result))


def kosaraju(edges, reverse_edges):
    import sys
    sys.setrecursionlimit(10**7)
    v_count = len(edges)
    order = [0]*v_count
    k = [1]

    def get_order(v):
        order[v] = 1
        for dest in (_v for _v in edges[v] if order[_v] == 0):
            get_order(dest)
        order[v] = k[0]
        k[0] += 1

    def get_components(v):
        order[v] = 0
        return [v] + [_v for dest in reverse_edges[v] if order[dest] > 0 for _v in get_components(dest)]

    for v in (_v for _v in range(v_count) if order[_v] == 0):
        get_order(v)
    return [get_components(v) for v, _ in sorted(enumerate(order), key=lambda x: x[1], reverse=True) if order[v] > 0]

if __name__ == "__main__":
    solve()

Measured memory_bytes: 27612
#include <bits/stdc++.h>
using namespace std;
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))

// #undef LOCAL
#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N, L;
  cin >> N >> L;
  int ans = -1;
  int delta = INF;
  for (int i = 0; i < N; i++) {
    if (abs(i + L) < delta) {
      delta = abs(i + L);
      ans = i;
    }
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (i != ans) {
      sum += L + i;
    }
  }
  cout << sum << endl;
  return 0;
}


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

int main() {
  int N;
  int D;
  int X[11][11];
  cin >> N >> D;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X[i][j];
    }
  }

  int sum = 0;
  int cnt = 0;

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      sum = 0;
      for (int k = 0; k < D; k++) {
        sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
      }
      for (int l = 1; l * l < 17000; l++) {
        if (l * l == sum) {
          cnt++;
          break;
        }
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
#define fcout cout<<fixed<<setprecision(10)
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//template<typename T>void pp(T x){cout<<x<<endl;}

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<pair<int,int> > v(n);
    rep(i,0,n){
        v[i].fi=0;
        v[i].se=i+1;
    }

    rep(i,0,n*(n-1)/2){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        a--; b--;
        if(c>d)v[a].fi+=3;
        else if(c<d)v[b].fi+=3;
        else {
            v[a].fi++;
            v[b].fi++;
        }
    }

    Sort(v);
    vector<int> ans(n);
    int score=1;
    ans[v[v.size()-1].se-1]=1;
    for(int i=n-2;i>=0;i--){
        if(v[i].fi==v[i+1].fi)ans[v[i].se-1]=score;
        else {
            score=n-i;
            ans[v[i].se-1]=score;
        }
    }
    rep(i,0,n){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int n, a[100], ta = 0, wa = 0;
vector<int> mu = {};
bool rin = true;

signed main(){
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] /= 400;
	}
	for (int i = 0; i < n; i++) {
		rin = true;
		if (a[i] < 8) {
			for (int j = 0; j < mu.size(); j++) {
				if (mu[j] == a[i])rin = false;
			}
		}
		if (rin == true) {
			ta++;
			mu.push_back(a[i]);
			if (a[i] < 8)wa++;
		}
	}
	if (wa == 0)wa++;
	cout << wa << " " << ta << endl;
	return 0;
}

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

bool iseven(string s) {
	if (s.size() % 2 == 1)
		return false;
	return s.substr(0, s.size() / 2) == s.substr(s.size() / 2, s.size() / 2);
}

int main() {
	string s;
	cin >> s;
	for (int i = s.size() - 1;; i--) {
		if (iseven(s.substr(0, i))) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c=0,d=0,e=0,f=0,g=0,h=0,i,j=0,k=0,x=0,y=0,t;
    cin>>a;
  vector<int>v;
  for(i=0;i<a;i++){
    cin>>b;
    v.push_back(b);
  }
  for(i=0;i<a;i++){
    if(v[i]>=1 && v[i]<=399){
        if(c<1){
            c+=1;
        }
    }
   else if(v[i]>=400 && v[i]<=799){
        if(d<1){
            d+=1;
        }

    }
  else  if(v[i]>=800 && v[i]<=1199){
        if(e<1){
            e+=1;
        }

    }
 else   if(v[i]>=1200 && v[i]<=1599){
        if(f<1){
            f+=1;
        }

    }
  else  if(v[i]>=1600 && v[i]<=1999){
        if(g<1){
            g+=1;
        }

    }
   else if(v[i]>=2000 && v[i]<=2399){
        if(h<1){
            h+=1;
        }

    }
  else  if(v[i]>=2400 && v[i]<=2799){
        if(x<1){
            x+=1;
        }

    }
   else if(v[i]>=2800 && v[i]<=3199){
        if(y<1){
            y+=1;
        }

   }
   else if(v[i]>=3200){
            k=k+1;
        }




  }
  t=(c+d+e+f+g+h+x+y);
  if(k==0 && t>0){
   cout<<t<<" "<<t<<endl;
   return 0;

     }
else if(k>0 && t>0){
        cout<<t<<" "<<t+k<<endl;
     }
     else if(t==0 && k>0){
        cout<<1<<" "<<k<<endl;
     }
    return 0;
}


Measured memory_bytes: 256
<?php
$n = int();
$A = ints();
$min = 10**10;
for($i = 1; $i <= 100; $i++){
    $tmp = 0;
    foreach($A as $a){
        $tmp+=($a-$i)**2;
    }
    chmin($min, $tmp);
}
echo $min;


function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}
/**
 * 座圧対象の配列を渡すと以下の値を返す
 * ・圧縮された配列
 * ・復元用のMap
 * ・圧縮用のMap
 **/
function atsu($array){
    $a = array_flip($array);
    $fuku = array_flip($a);
    sort($fuku);
    $atsu = array_flip($fuku);
    foreach($array as $i => $val)$array[$i] = $atsu[$val];
    return [$array, $fuku, $atsu];
}
//配列の最大公約数
function gcdAll($array){
    $gcd = $array[0];
    for($i = 1; $i < count($array); $i++){
        $gcd = gcd($gcd, $array[$i]);
    }
    return $gcd;
}

//最大公約数
function gcd($m, $n){
    if(!$n)return $m;
    return gcd($n, $m % $n);
}

//配列の最小公倍数
function lcmAll($array){
    $lcm = $array[0];
    for($i = 1; $i < count($array); $i++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int t = 1;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a == t) {
      ++t;
    }
  }
  if (t == 1) {
    cout << -1 << '\n';
  } else {
    cout << n - t + 1 << '\n';
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = n / 2;
    for (int i = 0; i < 26; ++i) {
        int ma = 0, c = 0;
        for (int j = 0; j < n; ++j) {
            if (s[j] == i + 'a') {
                ma = max(ma, c);
                c = 0;
            }
            else ++c;
        }
        ma = max(ma, c);
        ans = min(ans, ma);
    }
    cout << ans << "\n";
    return 0;
}


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

int main(){
  char x,y;
  cin >> x >> y;
  if(x < y) cout << '<' << endl;
  else if (x > y) cout << '>' << endl;
  else cout << '=' << endl;
  
}

Measured memory_bytes: 256
h, w = map(int, input().split())

maze = []
for i in range(h):
    maze.append(input().rstrip())

dp = [[0] * w for _ in range(h)]
dp[0][0] = 1

mod = 10**9 + 7

for i in range(h):
    for j in range(w):
        if maze[i][j] == '.':
            if i > 0:
                dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod
            if j > 0:
                dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod

print(dp[-1][-1])


Measured memory_bytes: 43676
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, a[100010];
ll ans;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i < n - 1; i++) ans += 2LL * min(i + 1, n - i - 1)*(a[i + 1] - a[i]);
	if (n % 2)ans -= min(a[n / 2 + 1] - a[n / 2], a[n / 2] - a[n / 2 - 1]);
	else ans -= a[n / 2] - a[n / 2 - 1];
	cout << ans << endl;
}

Measured memory_bytes: 640
'use strict'

const exponential = (num) => {
    if(num === 1) return true

    for(let i = 2; i <= num; i++){
        let count = 0
        let num1 = num
        while(num1 % i === 0){
            count++
            num1 /= i
        }
        if(count >= 2 && num1 === 1){
            return true
        }
    }
    return false
}

const main = (input) => {
    const X = parseInt(input)
    const nums = Array(X).fill(0).map((v, i) => i + 1)
    const filterNums = nums.filter(v => exponential(v))
    console.log(filterNums.pop())
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7500
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long int
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  ll a[200000];
  REP(i,n){
    cin>>a[i];
  }
  for(int j=1;j<=n-1;j++){
    a[j]+=a[j-1];
  }
  ll mn=abs(a[n-1]-a[0]*2);
  for(int i=1;i<=n-2;i++){
    mn=(mn < abs(a[n-1]-a[i]*2))? mn:abs(a[n-1]-a[i]*2);
  }
  P(mn);
  return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramD
    {
        static void Main()
        {
            var s = Line;
            var array = Enumerable.Repeat(1L, s.Length).ToArray();
            for (int i = 1; i < s.Length; i++)
            {
                array[i] = array[i - 1] * 10 % 2019;
            }

            for (int i = 0; i < s.Length; i++)
            {
                array[i] = (s[s.Length - i - 1] - '0') * array[i] % 2019;
            }

            for (int i = 0; i < s.Length - 1; i++)
            {
                array[i + 1] = (array[i] + array[i + 1]) % 2019;
            }

            var memo = Enumerable.Repeat(0, 2019).ToArray();
            memo[0] = 1;
            for (int i = 0; i < s.Length; i++)
            {
                memo[array[i]]++;
            }

            System.Console.WriteLine(memo.Sum(x => (long)x * (x - 1) / 2));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 28776
#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
 int a,b,c;
 cin>>a>>b>>c;
 if(a==b && a==c)
  cout<<"1";
 else if((a==b && b!=c) || (b==c && b!=a) || (a==c && a!=b))
  cout<<"2";
 else
  cout<<"3";
 return 0;
}

Measured memory_bytes: 256
#input
N = int(input())
a = list(map(int, input().split()))

#output
import numpy as np
import bisect as bi

a = np.array(a)

#experiment
warm = 1

sum = 0
for i in range(N):
    if a[i] == warm:
        warm += 1 
        sum += 1

if sum == 0:
    print(-1)
else:
    print(N-sum)

Measured memory_bytes: 24744
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int M = scn.nextInt();
		Work[] W = new Work[N];
		for (int i = 0; i < N; i++) {
			W[i] = new Work(scn.nextInt(), scn.nextInt());
		}
		Arrays.sort(W);

		ArrayList<Integer> pos = new ArrayList<Integer>();
		for(int i = 1;i <=M;i++) {
			pos.add(i);
		}

		int num[] = new int[M+1];
		long ans = 0;
		for(Work w:W) {
			if(pos.size() ==0)break;
			int d = w.day;
			int j = check(d,pos);
			if(j!=-1) {
				num[pos.get(j)] = w.value;
				pos.remove(j);
			}
		}
		for(long a:num) {
			ans +=a;
		}
		System.out.println(ans);

	}

	static int check(int d, ArrayList<Integer> pos) {
		int l = 0;
		int r = pos.size()-1;
		if(pos.get(r) < d)return -1;
		if(pos.get(l) >= d) return 0;
		int mid;
		while(r-l > 1) {
			mid = (l+r)/2;
			if(pos.get(mid) < d) {l = mid;
			}else {
				r = mid;
			}
		}


		return r;
	}
}

class Work implements Comparable<Work> {
	int day;
	int value;

	public Work(int day, int value) {
		this.day = day;
		this.value = value;
	}

	@Override
	public int compareTo(Work o) {
		if (this.value > o.value) {
			return -1;
		}
		if (this.value < o.value) {
			return 1;
		}

		if (this.day < o.day) {
			return -1;
		}
		if (this.day > o.day) {
			return 1;
		}
		return 0;
	}

	public String toString() {
		return this.day + ":" + this.value;
	}
}


Measured memory_bytes: 90652