akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int H, W;
        cin >> H >> W;
        vector<vector<char>> S(H + 2, vector<char>(W + 2, '#'));
//        vector<string> S(H);
        for (int i = 1; i <= H; ++i) {
            for (int j = 1; j <= W; ++j) {
                cin >> S[i][j];
            }
        }

        auto conv = [&](Int h, Int w) -> Int {
            return h * (W + 2) + w;
        };

        Int sz = (H + 2) * (W + 2);
        vector<vector<Int>> dist(sz, vector<Int>(sz, INFl));
        for (int i = 0; i < sz; ++i) {
            dist[i][i] = 0;
        }

        for (int i = 1; i <= H; ++i) {
            for (int j = 1; j <= W; ++j) {
                int di[4] = {0, 1, 0, -1};
                int dj[4] = {-1, 0, 1, 0};

                for (int k = 0; k < 4; ++k) {
                    int ni = i + di[k];
                    int nj = j + dj[k];

                    if (S[i][j] == '.' && S[ni][nj] == '.') {
                        Int from = conv(i, j);
                        Int to = conv(ni, nj);
                        dist[from][to] = 1;
                    }

                }
            }
        }

        for (int k = 0; k < sz; ++k) {
            for (int i = 0; i < sz; ++i) {
                for (int j = 0; j < sz; ++j) {
                    chmin(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }

        Int ans = 0;
        for (int i = 0; i < sz; ++i) {
            for (int j = 0; j < sz; ++j) {
                if (dist[i][j] != INFl) {
                    chmax(ans, dist[i][j]);
                }
            }
        }
        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


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

int main()
{
	int n;
	cin>>n;
	cin.get();
	for(int i=0;i<n;i++){
		string s;
		getline(cin,s);
		for(int j=0;j<s.size();j++){
			if(s.substr(j,7)=="Hoshino")
				s[j+6]='a';
		}
		cout<<s<<endl;
	}
	return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n, m, x_cap, y_cap;
	cin >> n >> m >> x_cap >> y_cap;
	int x[n], y[m];
	for(int i=0; i<n; i++) cin >> x[i];
	for(int i=0; i<m; i++) cin >> y[i];
	sort(x, x+n);
	sort(y, y+m);
	int x_max=x[n-1], y_min=y[0];
	if(y_min<=x_max || y_min<=x_cap || y_cap<=x_max) cout << "War" << endl;
	else cout << "No War" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

vector<int> Zalgo(const string &S) {
    int N = (int)S.size();
    vector<int> res(N);
    res[0] = N;
    int i = 1, j = 0;
    while (i < N) {
        while (i+j < N && S[j] == S[i+j]) ++j;
        res[i] = j;
        if (j == 0) {++i; continue;}
        int k = 1;
        while (i+k < N && k+res[k] < j) res[i+k] = res[k], ++k;
        i += k, j -= k;
    }
    return res;
}



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

    int res = 0;
    for (int i = 0; i < N; ++i) {
        string T = S.substr(i);
        auto lcp = Zalgo(T);

        for (int j = 0; j < T.size(); ++j) {
            int l = min(lcp[j], j);
            res = max(res, l);
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	ll n, k;
	cin >> n >> k;
	ll c;
	c = n / k;
	n = n - c * k;
	while (n >= k) {
		n = n - k;
	}
	ll ans,n2;
	//cout << n << endl;
	n2 = abs(n - k);
	//cout << n2 << endl;
	ans = min(n, n2);
	cout << ans;

	return 0;
}

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

int main()
{
	int Mid, Final, Ex;
	while(cin >> Mid >> Final >> Ex && Mid >= 0 || Final >= 0 || Ex >= 0)
	{
		if(Mid < 0 || Final < 0)
		{
			cout << "F" << endl;
		}
		else if(Mid + Final >= 80)
		{
			cout << "A" << endl;
		}
		else if(Mid + Final >= 65)
		{
			cout << "B" << endl;
		}
		else if(Mid + Final >= 50)
		{
			cout << "C" << endl;
		}
		else if(Mid + Final >= 30)
		{
			if(Ex >= 50)
			{
				cout << "C" << endl;
			}
			else
			{
				cout << "D" << endl;
			}
		}
		else
		{
			cout << "F" << endl;
		}
	}

    return 0;
}



Measured memory_bytes: 3080
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

int main() {
    int N, X;
    std::cin >> N >> X;

    std::vector<int> m(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> m[i];
    }

    const int min = *std::min_element(m.cbegin(), m.cend());

    const int remaining = X - std::accumulate(m.cbegin(), m.cend(), 0);
    const int ret = N + remaining / min;

    std::cout << ret << std::endl;
}


Measured memory_bytes: 384
a = input()
c = list(a)

c.reverse() 

if c[0] == '1':
  print("pon")
elif c[0] == '2':
  print("hon")
elif c[0] == '3':
  print("bon")
elif c[0] == '4':
  print("hon")
elif c[0] == '5':
  print("hon")
elif c[0] == '6':
  print("pon")
elif c[0] == '7':
  print("hon")
elif c[0] == '8':
  print("pon")
elif c[0] == '9':
  print("hon")
elif c[0] == '0':
  print("pon")

Measured memory_bytes: 9020
#include<bits/stdc++.h>
#define Mx 1000000000005 
#define ll long long  
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll,ll>
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define vii vector<pair<ll,ll> > 
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a,x) memset(a,x,sizeof(a))
using namespace std;
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
  return a.second<b.second;
}
/*vi b=v;
   sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  ll t; cin>>t; fr(f,0,t){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 */
int main()
{
  ll n; cin>>n;
  ll a[n][3],dp[n+1][3];
  fill(dp,0);

  fr(i,0,n)
    cin>>a[i][0]>>a[i][1]>>a[i][2];
    
  fr(i,1,n+1)
  {
    fr(j,0,3)
    {
      dp[i][j]=a[i-1][j]+max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]);
    }
  }

  cout<<max(dp[n][0], max(dp[n][1], dp[n][2]));
}

Measured memory_bytes: 8224
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s, n) for(int i = s; i < n; ++i)
#define rep(i, n)		 REP(i, 0, n)
#define SORT(c)			 sort((c).begin(), (c).end())
#define IINF					INT_MAX
#define LLINF					LLONG_MAX
#define DEBUG					false
 
typedef long long				ll;
typedef pair <int, int> ii;

int main() {
	
	vector<int>a(4);
	rep(i, 4) cin >> a[i];
	SORT(a);
	
	if(a[0] == a[1] && a[2] == a[3]) cout << "yes" << endl;
	else cout << "no" << endl;
	
	return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl;
#define rep(i,n) for(ll i = 0;i < n;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0);

const ll INF = 1e9+7;

// 各桁の和
template<typename T>
T digit(T num){
  T sum = 0;
  while(num){
    sum += num % 10;
    num /= 10;
  }
  return sum;
}

template<typename T>T gcd(T a,T b){
  if(b == 0)
    return a;
  return gcd(b,a%b);
}
template<typename T>T lcm(T a, T b){
  T g = gcd(a,b);
  return a/g*b; 
}

template<typename T>T power(T a,T b){
  T tmp = 1;
  rep(i,b){
    tmp *= a;
  }
  return tmp;
}

int main(){
  ll d,n;cin>>d>>n;
  ll tmp = power(100ll,d);
  ll ans = tmp * n;
  if(n == 100)print(101*tmp)
  else print(ans)
  return 0;
}


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

const int MI = 0;

class Segtree {
public:
    int n;
    vector<int>data;
public:
    Segtree(int _n,int MIN) {
        n = 1;
        while (n < _n) n *= 2;
        for (int i = 0; i < 2 * n - 1; i++) {
            data.push_back(MIN);
        }
    }

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

    int query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return MI;
        if (a <= l && r <= b) return data[k];
        else {
            int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }

    int query(int s, int t) {
        return query(s, t + 1, 0, 0, n);
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int>a(n);
    rep(i, n) cin >> a[i];
    Segtree seg(300001, MI);
    rep(i, n) {
        int index = a[i];
        int value = seg.query(max(MI, index - k), min(300000, index + k));
        seg.update(index, value + 1);
    }
    int ans = 0;
    rep(i, 300001) {
        ans = max(ans, seg.data[i + n - 1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8636
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}


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

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}







/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,cnt=0;
  bool flag=false;
  cin>>n;
  vector<ll> v(n);
  rep(i,n){
    cin>>v[i];
    if(v[i]<0) cnt++;
    else if(v[i]==0) flag=true;
    v[i]=abs(v[i]);
  }
  ll ans=Svec(v);
  if(flag || cnt%2==0){
    cout<<ans<<endl;
    return 0;
  }
  sort(ALL(v));
  cout<<ans-2*v[0]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<double,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

ll dp[410][410];
vector<ll>a;
ll solve(int l,int r){
    if(dp[l][r]>0)return dp[l][r];
    if(l==r)return 0;
    ll res = INF;
    for(int k = l;k<r;k++){
        chmin(res,solve(l,k)+solve(k+1,r));
    }
    for(int i=l;i<=r;i++){
        res += a[i-1];
    }
    dp[l][r]=res;
    return dp[l][r];
}
int main(){
    ll n;
    cin >> n;
    a.resize(n);
    rep(i,n)cin>>a[i];
    cout << solve(1,n) << endl;

    return 0;
}


Measured memory_bytes: 1536
ansList = []
for i in range(1,33):
    for j in range(2,33):
        judge = i ** j
        if(judge <=1000 and judge not in ansList):
            ansList.append(judge)
ansList = sorted(ansList)
#print(ansList)
X = int(input())
temp = 0
for l in ansList:
    if(X >= l):
        temp = l

print(temp)


Measured memory_bytes: 3060
#include <stdio.h>
#define inf 100000000
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
int w[100][100];
int d[100];

void dijkstra()
{

  int i, mincost, u;
  int color[100];

  for(i=0;i<n;i++){
    d[i] = inf;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
   
  while(1){
    mincost = inf;
    for(i=0;i<n;i++){
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if(mincost == inf){
      break;
    }
    color[u] = BLACK;
    for(i=0;i<n;i++){
      if(color[i] != BLACK && d[u] + w[u][i] < d[i]){
	color[i] = GRAY;
	d[i] = d[u] + w[u][i];
      }
    }
  }

}

int main()
{

  int i, j, u, k, v, c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      w[i][j] = inf;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      w[u][v] = c;
    }
  }

  dijkstra();

  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i] == inf) printf("%d\n",NIL);
    else printf("%d\n",d[i]);
  }

  return 0;

}
  
    



Measured memory_bytes: 2108
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int c[501],d[500][500][10][3][2],m;
bool e;
int fi(int p,int q,int r,int s,bool t){
	int i;
	if(p<0){
		if(t&&!q)
			e=true;
		return !q;
	}
	if(d[p][q][r][s][t?1:0]>=0)
		return d[p][q][r][s][t?1:0];
	int ct=0;
	if(s==0||s==2){
		for(i=r+1;i<=(t?c[p]:9);++i)
			ct=(ct+fi(p-1,(q*10+i)%m,i,1,t&&i==c[p]))%10000;
	}
	if(s==1||s==2){
		for(i=0;i<=min(t?c[p]:9,r-1);++i)
			ct=(ct+fi(p-1,(q*10+i)%m,i,0,t&&i==c[p]))%10000;
	}
	return d[p][q][r][s][t?1:0]=ct;
}
int main(){
	int i,j;
	char a[502],b[502];
	scanf("%s%s%d",a,b,&m);
	int aln=strlen(a),bln=strlen(b);
	int ct=0;
	memset(d,-1,sizeof(d));
	for(i=0;b[i];++i)
		c[bln-i-1]=b[i]-'0';
	for(i=aln;i<=bln;++i)
		for(j=1;j<=(i==bln?c[bln-1]:9);++j)
			ct=(ct+fi(i-2,j%m,j,2,i==bln&&j==c[bln-1]))%10000;
	memset(d,-1,sizeof(d));
	for(i=0;a[i];++i)
		c[aln-i-1]=a[i]-'0';
	e=false;
	for(j=1;j<=c[aln-1];++j)
		ct=(ct-fi(aln-2,j%m,j,2,j==c[aln-1])+10000)%10000;
	if(e)
		ct=(ct+1)%10000;
	printf("%d\n",ct);
	return 0;
}

Measured memory_bytes: 59692
#import <Foundation/Foundation.h>
#define MOD 1000000007LL
#define MAXSIZE 2000000LL

typedef long long INT;

@interface NSNumber (Extension)
-(NSMutableArray*)primeFactors;
@end

@implementation NSNumber (Extension)
-(NSMutableArray*)primeFactors
{
	NSMutableArray *array = [NSMutableArray array];
	INT factor = 0;
	INT factorCount = 0;
	INT n = [self longLongValue];
	INT q = n;
	
	if (n == 1) {
		return [NSMutableArray arrayWithArray: @[@{@"factor": @1, @"exponent": @1}]];
	}
	for(INT i=2;i*i<=n;){
		if (q % i == 0) {
			if (i != factor) {
				factor = i;
				factorCount = 1;
			} else {
				factorCount++;
			}
			q /= i;
		} else {
			if (factor > 0) {
				[array addObject: @{@"factor": @(factor), @"exponent": @(factorCount)}];
				factor = 0;
			}
			i++;
		}
	}
	if (q > 1) {
		[array addObject: @{@"factor": @(q), @"exponent": @1}];
	}
	return array;
}
@end

INT fac[MAXSIZE], finv[MAXSIZE], inv[MAXSIZE];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (INT i = 2; i < MAXSIZE; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
INT COM(INT n, INT k){
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
	@autoreleasepool {
		COMinit();

		INT N,M;
		scanf("%lld %lld",&N,&M);
		if (M==1) {
			puts("1");
			return 0;
		}
		NSArray *primeFactors = [@(M) primeFactors];
		INT ans = 1;
		for (NSDictionary *factor in primeFactors){
			INT e = [[factor objectForKey:@"exponent"] longLongValue];
			INT c = COM(e+N-1,N-1);
			ans *= c % MOD;
			ans %= MOD;
		}
		printf("%lld",ans);
	}
}


Measured memory_bytes: 56352
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

if 1 not in a:
    print(-1)
    exit()

a = deque(a)
i = 1
ans = 0
while a != deque():
    if a[0] == i:
        a.popleft()
        i += 1
        ans += 1
    else:
        a.popleft()

print(n - ans)

Measured memory_bytes: 25588
get_string(String) :-
  current_input(Input),
  read_string(Input, ' \n', '', _, String).
 
get_number(Number) :-
  get_string(String),
  number_string(Number, String).

main :-
  get_number(A),
  get_number(B),
  get_number(C),
  get_number(D),
  X is (A+D-1)//D,
  Y is (C+B-1)//B,
  (X>=Y -> writeln('Yes');writeln('No')).


Measured memory_bytes: 7996
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

typedef long long ll;

int gcd(ll a, ll b)
{
    if(b==0)
        return a;
    if(a<b) gcd(b,a);
    int r;
    while(r=a%b)
    {
        a = b;
        b = r;
    }

    return b;
}

int main()
{
    int N;
    std::vector<ll> A;

    std::cin >> N;
    A.resize(N);

    for(int i=0; i<N; ++i)
        std::cin >> A[i];

    std::vector<ll> L;
    std::vector<ll> R;
    L.resize(N+1);
    R.resize(N+1);

    L[0] = 0;
    R[N] = 0;

    for(int i=0; i<N; ++i)
    {
        L[i+1] = gcd(L[i], A[i]);
        R[N-i-1] = gcd(R[N-i], A[N-1-i]);
    }

    ll max = 0;
    for(int i=0; i<N; ++i)
    {
        int tmp = gcd(L[i], R[i+1]);
        if(tmp > max)
            max = tmp;
    }

    std::cout << max << std::endl;

    return 0;
}


Measured memory_bytes: 2560
import sys
sys.setrecursionlimit(10**8)

N = int(input())

def sft(p) :
    if int(p) > N :
        return 0
    co = 0
    if "7" in p and "5" in p and "3" in p :
        co = 1
    co += sft(p+"7") + sft(p+"5") + sft(p+"3")
    return co

print(sft("0"))

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

bool sankaku(int a, int b, int c) {
	if((a<b+c) && (b<c+a) && (c<a+b)){
		return true;
	}else{
		return false;
	}
}

int main() {
	int n; cin >> n;
	int l[2005];
	int ans = 0;
	for(int i=0;i<n;i++){
		cin >> l[i];
	}
	sort(l, l+n);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int k=j+1;k<n;k++){
				if(sankaku(l[i], l[j], l[k])){
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

#define len length()
#define sz size()
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort(v.begin(), v.end())
#define veci(a, n) vector<int> a(n)
#define vecs(a, n) vector<string> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define sp(n) cout << setprecision(n) << fixed

int main(){
    int N;
    cin >> N;
    int d=0;
    rep(i, to_string(N).len){
        d += int(to_string(N).at(i)-'0') ;
    }
    
    if(N%d == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int a, b;
    int i;
    for(i=0; i<10000; i++){
        scanf("%d %d", &a, &b);
        if(a == 0 && b ==0){
            break;
        }else if(b<=a){
            printf("%d %d\n", b, a);
        }else{
            printf("%d %d\n", a, b);
        }
    }
    return 0;
}


Measured memory_bytes: 1968
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(r: R) -> Scanner<R> {
        Scanner { reader: r }
    }
    fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut vv = vec![0;n];
    for _ in 0..k {
        let d: usize = sc.read();
        for _ in 0..d {
            let a: usize = sc.read();
            vv[a-1] += 1;
        }
    }
    let res = vv.iter().filter(|v| {**v == 0 }).count();
    println!("{}", res);
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

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

    cout<<"AC x "<<s["AC"]<<endl;
    cout<<"WA x "<<s["WA"]<<endl;
    cout<<"TLE x "<<s["TLE"]<<endl;
    cout<<"RE x "<<s["RE"]<<endl;

}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

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



Measured memory_bytes: 3644
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
ans ='War'
for i in range(X+1, Y+1):
  if max(x) < i and min(y) >= i:
    ans = 'No War'

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<pair<int, int> > a(n), b(m);
        for(int i=0; i< n; i++){int p; cin >> p; a[i] = make_pair(0, p);}
        for(int i=0; i< m; i++){int p; cin >> p; b[i] = make_pair(0, p);}
 
        for(int i=0; i< n; i++)for(int j=0; j < m; j++){
            if(__gcd(a[i].second, b[j].second) != 1){a[i].first++; b[j].first++;}
        }
        sort(a.begin(), a.end()); sort(b.begin(), b.end());
 
        bool ba[500] = {false}, bb[500] = {false};
        int ret = 0;
        for(int i=0; i< n; i++)for(int j=0; j< m; j++){
            if(!ba[i] && !bb[j] && __gcd(a[i].second, b[j].second) != 1){
                ret++;
                ba[i] = true; bb[j] = true;
                break;
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 3104
n,m = map(int,input().split())
a=[0 for i in range(m)]
b=[0 for i in range(m)]
for i in range(m):
    a[i],b[i]= map(int,input().split())
ans=[0 for i in range(n)]
for i in range(m):
    ans[a[i]-1]+=1
    ans[b[i]-1]+=1

for i in range(n):
    print(ans[i])

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <complex>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
typedef complex<double> P;

int bitcount(int b) { int c = 0; while(b) { b &= b-1; c++; } return c; }

int n, x[64], y[64], r[64], c[64], g[64][64];
bool vis[1<<24];

int solve() {
    memset(vis, 0, sizeof(vis));
    rep(i, n) for(int j=i+1; j<n; j++) {
        const double d = abs(P(x[i], y[i])-P(x[j], y[j]));
        g[i][j] = d<r[i]+r[j];
    }
    int ans = 0;
    queue<int> q;
    q.push(0);
    vis[0] = true;
    while(!q.empty()) {
        int x = q.front();
        q.pop();
        ans = max(ans, bitcount(x));
        int can = ~x;
        rep(i, n) if((x&(1<<i))==0) {
            for(int j=i+1; j<n; j++) if(g[i][j]) can &= ~(1<<j);
        }
        rep(i, n) if(can&(1<<i)) rep(j, i) if(can&(1<<j) && c[i]==c[j]) {
            const int nx = x|(1<<i)|(1<<j);
            if(!vis[nx]) q.push(nx), vis[nx] = true;
        }
    }
    return ans;
}

int main() {
    for(;;) {
        scanf("%d", &n);
        if(n==0) return 0;
        rep(i, n) scanf("%d%d%d%d", x+i, y+i, r+i, c+i);
        printf("%d\n", solve());
    }
}

Measured memory_bytes: 0
//	ZapZu's code hohoho
//	#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef double db;
typedef long long li;
typedef long double ld;

typedef pr<int, int> ii;
typedef pr<ld,ld> dd;

typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;

typedef set<int> s_i;
typedef set<char> s_c;

const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
int dp[2005][2005];
signed main()
{
//	freopen(".inp", "r", stdin);
//	freopen(".out", "w", stdout);
	int n;
	cin>>n;
	vii v;
	for(int i=1; i<=n; i++)
	{
		int t;
		cin>>t;
		v.eb(t, i);
	}
	sort(begin(v), end(v));
	reverse(begin(v), end(v));
	dp[0][n+1]=0; 
	int ans=0;
	for(int i=0; i<=n; i++)
	{
		for(int l=0; l<=i; l++)
		{
			int r=n+1-(i-l);
			if(l<r-1)
			{
				dp[l+1][r]=max(dp[l+1][r], dp[l][r]+abs(l+1-v[i].se)*v[i].fi);
				dp[l][r-1]=max(dp[l][r-1], dp[l][r]+abs(r-1-v[i].se)*v[i].fi);
			}
			else ans=max(ans, dp[l][r]);
		}
	}
	cout<<ans;
}




Measured memory_bytes: 26296
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	//(nw + hw + hn)*N = nhw*4
	for n := 1; n <= 3500; n++ {
		for h := 1; h <= 3500; h++ {
			y := N * h * n
			x := 4*n*h - N*(n+h)
			if x > 0 && y*x > 0 && y%x == 0 {
				fmt.Println(n, h, y/x)
				return
			}
		}
	}
}


Measured memory_bytes: 512
n = int(input())
d = {}
for i in range(n):
    s = input()
    if s not in d:d[s] = 1
    else:d[s]+=1
m = int(input())
for i in range(m):
    s = input()
    if s not in d:continue
    else:d[s]-=1
ans = 0
for x in d:
    ans = max(ans,d[x])
print(ans)
    

Measured memory_bytes: 3060
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# MOD = 998244353


L = int(sys.stdin.buffer.readline())
# 2べきなら2個ずつ辺を張ればOK
V = L.bit_length()
ans = []
for v in range(V - 1):
    ans.append((v, v + 1, 0))
    ans.append((v, v + 1, 2 ** v))

pos = V - 2
w = 1 << L.bit_length() - 1
while pos >= 0:
    if L & (1 << pos):
        ans.append((pos, V - 1, w))
        w |= L & (1 << pos)
    pos -= 1
E = len(ans)
print(V, E)
for r in ans:
    v, u, w = r
    v += 1
    u += 1
    print(v, u, w)


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi v(n);
	REP(i, n)cin >> v[i];
	vi dp(n, INF);
	dp[0] = 0;
	REP(i, n) {
		if (i + 1 < n) {
			dp[i + 1] = min(dp[i + 1], dp[i] + abs(v[i] - v[i + 1]));
		}
		if (i + 2 < n) {
			dp[i + 2] = min(dp[i + 2], dp[i] + abs(v[i + 2] - v[i]));
		}
	}
	cout << dp[n-1] << endl;
	
}

Measured memory_bytes: 1024
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(a+b==c||b+c==a||c+a==b) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define For(I,A,B) for(int I=(A); I < (B); ++I)
int c[1005][1005];
int main()
{
int t;
string p;
cin>>t;
getline(cin,p);
while(t--){

int x,y,z,k=0,l,i,j;
string a,b;

 For(i,0,1005)
 For(j,0,1005)
 c[i][j]=0;

 getline(cin,a);
 getline(cin,b);
 x=a.length();
 y=b.length();

 For(i,1,x+1)
 For(j,1,y+1)
 {
     if(a[i-1]==b[j-1]) c[i][j]=c[i-1][j-1]+1;
     else  c[i][j]=max(c[i-1][j],c[i][j-1]);
 }
    cout<<c[x][y]<<endl;

}

    return 0;
}

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

// Debug {{{
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

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

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


// macro {{{
#define rep(i,n) for (int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i,n) for (int i=1, i##_len=(n); i<=i##_len; ++i)

#define SZ(x) ((int)(x).size())

#define all(x) begin(x),end(x)
// }}}


// chmax, chmin {{{
template<class T>
bool chmax(T& a, const T& b) {
    if (a < b) { a = b; return true; }
    return false;
}
template<class T>
bool chmin(T& a, const T& b) {
    if (b < a) { a = b; return true; }
    return false;
}
// }}}


// type {{{
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
// }}}


// constants {{{
template<typename T>
T inf() { return numeric_limits<T>::max(); }

const ll MOD = 1e9+7;
const ld EPS = 1e-9;
// }}}


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

    for (;;) {
        int n; cin >> n;
        if (n == 0) break;

        int ans = 0;
        reps (i, n-1) {
            int sum = 0;
            for (int j = i; sum + j <= n; ++j) {
                sum += j;
            }
            ans += sum == n;
        }
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3032
#include <iostream>
#include <deque>

using namespace std;

int d[114514];

int main()
{
	int k;
	cin >> k;
	d[1] = 1;
	deque<int> q;
	q.push_back(1);
	while (q.front()) {
		int u = q.front();
		q.pop_front();
		for (int i = 0; i < 2; i++) {
			int v = (i ? u + 1 : u * 10) % k;
			if (d[v] && d[v] <= d[u] + i)
				continue;
			d[v] = d[u] + i;
			i ? q.push_back(v) : q.push_front(v);
		}
	}
	cout << *d << endl;
	return 0;
}


Measured memory_bytes: 896
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define reps(i,n) for(int i=1;i<=int(n);i++)
#define sint(i) scanf("%d",&i);
#define sintt(i,j) scanf("%d%d",&i,&j);
#define sinttt(i,j,k) scanf("%d%d%d",&i,&j,&k);
#define sintttt(i,j,k,m) scanf("%d%d%d%d",&i,&j,&k,&m);

#define INF 1010000000
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int cost[101];
vector<int> haigo[101];

int saiki(int n){
	if(haigo[n].size()==0){
		return cost[n];
	}
	
	int sum=0;
	rep(i,haigo[n].size()){
		sum+=saiki(haigo[n][i]);
	}
	return min(cost[n],sum);
}

int main(){
	while(1){
		int n;
		sint(n);
		if(n==0)break;
		
		rep(i,101){
			haigo[i].clear();
		}
		
		map<string,int> sina;
		rep(i,n){
			string str;
			int a;
			cin>>str>>a;
			sina[str]=i;
			cost[i]=a;
		}
		
		int m;
		sint(m);
		
		
		rep(i,m){
			string a;
			int b;
			cin>>a>>b;
			rep(j,b){
				string c;
				cin>>c;
				haigo[sina[a]].push_back(sina[c]);
			}
		}
		
		string toi;
		cin>>toi;
		
		printf("%d\n",saiki(sina[toi]));
	}
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	static int cnt[][];
	static int obs[][][][];
	static int a,b,ob;
	static int res;
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int I=in.nextInt();
		while(I-->0)
		{
			a=in.nextInt();b=in.nextInt();ob=in.nextInt();
			obs=new int[a+1][b+1][a+1][b+1];
			cnt=new int[a+1][b+1];
			int ans=0;
			for(int i=0;i<ob;i++)
			{
				int x1=in.nextInt(),y1=in.nextInt();
				int x2=in.nextInt(),y2=in.nextInt();
				obs[x1][y1][x2][y2]=1;
				obs[x2][y2][x1][y1]=1;
			}
			res=0;
			ans=count(0,0);
			System.out.println(ans==0?"Miserable Hokusai!":ans);
		}
	}
	static int count(int x,int y)
	{
		if (cnt[x][y]>0)  //already-count!
			return cnt[x][y];
		if (x==a&&y==b)
			return 1;
		res=0;
		if (x+1<=a&&obs[x][y][x+1][y]!=1)
			res+=count(x+1,y);
		if(y+1<=b&&obs[x][y][x][y+1]!=1)
			res+=count(x,y+1);
		return cnt[x][y] = res;	
	}
}

Measured memory_bytes: 30540
N,M = map(int, input().split())
ps = []
AC = [0]*N
WA = [0]*N
WA_sum = 0
for _ in range(M):
  ps.append(list(input().split()))
for i in range(M):
  if ps[i][1] == 'AC' and AC[int(ps[i][0])-1] == 0:
    AC[int(ps[i][0])-1] = 1
  if ps[i][1] == 'WA' and AC[int(ps[i][0])-1] == 0:
    WA[int(ps[i][0])-1] += 1
for i in range(N):
  if AC[i] == 1:
    WA_sum += int(WA[i])
print(sum(AC), WA_sum)


Measured memory_bytes: 27444
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,k;
    cin>>n>>k;
    for(int i=1;i<=(n+1)/2;i++)
    {
        //cout<<2*k+n/2+2*n+1<<'\n';
        if(2*k+n/2+2*n-1>k+(3*n-1))
        {

            cout<<"-1"<<'\n';
            return 0;
        }
        cout<<k+2*n+1-2*i<<' '<<k+n/2+i-1<<' '<<k+3*n-i<<'\n';
    }
    for(int i=1;i<=n/2;i++)
        cout<<k+2*n-2*i<<' '<<i+k-1<<' '<<k+3*n-i-(n+1)/2<<'\n';
}


Measured memory_bytes: 2304
//itp1_topic4_b

#include <bits/stdc++.h>

using namespace std;


int main(){

	
	cout<<fixed<< setprecision(12);

	double r;

	cin>>r;


	double PI = acos(-1); 

	double area = r * r * PI;

	double cir = ( r + r )* PI;

	cout<<area<<" "<<cir<<endl;


	return 0;

}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C=0,D=0,E=0,F=INF,G=INF,H=0,N,M,K,sum=0;
  cin >> N;
  Vec(AA,int,N,0);Vec(CC,int,N-1,0);
  rep(i,0,N)cin >> AA[i];
  rep(i,0,N){
    cin >> B;sum+=B;
  }
  rep(i,0,N-1)cin >> CC[i];
  rep(i,1,N)if(AA[i]==AA[i-1]+1)sum+=CC[AA[i-1]-1];
  Out(sum);
}
  

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 22;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int digit(ll n) {
  int ans = 0;
  while(n > 0) {
    ans++;
    n /= 10;
  }
  return ans;
}

ll pow(int a, int b) {
  ll ans = 1;
  REP(i, b) {
    ans *= a;
  }
  return ans;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  ll n; cin >> n;

  ll tmp = (digit(n) - 1);
  bool nine = true;
  REP(i, tmp) {
    if(n%10 != 9) nine = false;
    n /= 10;
  }
  if(!nine) n--;
  cout << 9 * tmp + n << endl;

}


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

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

    int n, m, c;
    cin >> n >> m >> c;

    int b[m];
    for (int i = 0; i < m; i++) cin >> b[i];

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int tmp = 0;
        for (int j = 0; j < m; j++) {
            int a;
            cin >> a;
            tmp += a * b[j];
        }
        if (tmp + c > 0) ans++;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 888
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	D := readInt()
	G := readInt() / 100
	p := make([]int, D)
	c := make([]int, D)
	for i := range p {
		p[i] = readInt()
		c[i] = readInt() / 100
	}

	ans := 10000
	var rec func(b []int)
	rec = func(b []int) {
		if len(b) == D {
			var score, solved int
			for i := range p {
				score += (i+1)*p[i]*b[i] + c[i]*b[i]
				solved += p[i] * b[i]
			}
			if G <= score {
				ans = min(ans, solved)
				return
			}
			for i := range p {
				if b[i] == 1 {
					continue
				}
				for j := p[i] - 1; 0 < j; j-- {
					score2 := score + (i+1)*j
					if score2 < G {
						break
					}
					ans = min(ans, solved+j)
				}
			}
			return
		}
		rec(append(b, 0))
		rec(append(b, 1))
	}
	rec(nil)
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
import sys,collections,math,random;sys.setrecursionlimit(10**7)
from fractions import gcd
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n =I()
lis = Is()
i = 1
for e in lis:
    if e == i:
        i += 1
if i == 1:
    print(-1)
else:
    print(n-i+1)


Measured memory_bytes: 27360
N,M = map(int,input().split())
L = sorted(list(map(int,input().split())))
X = []
for i in range(M):
    l = list(map(int,input().split()))
    X.append(l)
X = sorted(X,key=lambda x:x[1])[::-1]
imagin = []
flag = 0
for i in range(len(X)):
    if flag == 1:
        break
    for _ in range(X[i][0]):
        if len(imagin) > 10**5+10:
            flag = 1
            break
        imagin.append(X[i][1])
ans = []
for i in range(N):
    try:
        if L[i] > imagin[i]:
            ans.append(L[i])
        else:
            ans.append(imagin[i])
    except:
        ans += L[i:]
        break
print(sum(ans))


Measured memory_bytes: 90220
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using lint = long long;
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n,k;cin>>n>>k;
  vector<int> h(n);
  rep(i,n)cin>>h[i];
  sort(h.begin(),h.end());
  lint res=inf;
  rep(i,n){
      if(i+k-1==n)break;
      res=min(res,h[i+k-1]-h[i]);
  }
  cout<<res<<"\n";
  return 0;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
/*
дружочек, ты видимо не понял с кем общаешься.
вот эта манера речи "клоунская" меня не впечатляет.
давай встретимся и я объясню на понятном тебе языке - языке боли.
*/
int mod = 1e9+7;
int main(){
int n;
cin >> n;
string s;
cin >> s;
vector<int> a(30);
for(int i = 0;i<s.size();i++){
    a[s[i]-'a']++;
}
long long q = 1;
for(int i = 0;i<30;i++){
    if(a[i]){
        q = (q*(a[i]+1))%mod;
    }
}
cout << q-1;


}


Measured memory_bytes: 512
N,Y = map(int,input().split())

Y = Y//1000

for i in range(N+1):
    for j in range(N-i+1):
        k = N - i - j

        if 10*i + 5*j + 1*k == Y:
            print(i,j,k)
            exit()

print(-1,-1,-1)


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

int main() {
    int N;
    cin >> N;
    string S;
    string S2 = "YYY";
    for (int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        if (a == b){
            S = S + 'Y';
        }
        else {
            S = S + 'N';
        }
    }
    if (strstr(S.c_str(), S2.c_str())){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632