akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){

	string s;
	int k;
	cin >> s >> k;

	vector<string> subb;

	for (int i = 0; i < s.size(); i++) {
		for (int j = 1; j < 6; j++) {
			subb.push_back( s.substr(i, j));
		}
	}

	sort(subb.begin(), subb.end());
	
	int counter = 1;
	if (k == 1) {
		cout << subb[0] << endl;
	}
	else {
		for (int i = 1; i < subb.size(); i++) {
			if (subb[i] != subb[i - 1]) {
				counter++;
				if (counter == k) {
					cout << subb[i] << endl;
				}
			}
		}

	}

}

Measured memory_bytes: 1660
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/

void Calc() {
  int n = in;
  string s1, s2;
  char tmp, tmp2;
  char c[] = { '.', '#' };
  bool isRight = true;

  for (;;) {
    bool ok = false;
    rep(i, 2)rep(j, 2) {
      tmp = c[i], tmp2 = c[j];
      if (isRight) {
        cout << (s1) << tmp << endl;
        cout << (s2) << tmp2 << endl;
      } else {
        cout << tmp << (s1) << endl;
        cout << tmp2 << (s2) << endl;
      }
      string res = in;
      if (res == "end")return;
      if (res[0] == 'T') {
        ok = true;
        if (isRight) {
          s1 += tmp;
          s2 += tmp2;
        } else {
          s1.insert(s1.begin(), tmp);
          s2.insert(s2.begin(), tmp2);
        }
        break;
      }
    }
    if (ok == false) {
      isRight = false;
    }
  }

}


Measured memory_bytes: 596
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0; i<(lli)(n); i++)
#define repf(i, n) for(lli i=1; i<(lli)(n+1); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, k;
    cin >> n >> k;
    vector<bool> a(n, false);

    rep(i, k){
        lli d;
        cin >> d;
        rep(j, d){
            lli snk;
            cin >> snk;
            a[snk-1] = true;
        }
    }

    lli cnt = 0;
    for(auto p: a) if(!p) cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

char grid[110][110];
signed main()
{
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < 100; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            if(i<50){
                grid[i][j] = '.';
            }
            else{
                grid[i][j] = '#';
            }
        }
    }
    a--, b--;
    for (int i = 0; i < 49; i+=2)
    {
        for (int j = 0; j < 100; j++)
        {
            if((i+j)%2==0 && b>0) {
                grid[i][j] = '#';
                b--;
            }
            
        }
        
    }
    for (int i = 51; i < 100; i+=2)
    {
        for (int j = 0; j < 100; j++)
        {
            if ((i + j) % 2 == 1 && a > 0)
            {
                grid[i][j] = '.';
                a--;
            }
        }
        
    }
    cout << 100 << " " << 100 << endl;
    for (int i = 0; i < 100; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            cout << grid[i][j];
        }
        cout << endl;
    }

    return 0;
}

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

int main() {

	string s; cin >> s;	
	string a = "dream";
	string b = "dreamer";
	string c = "erase";
	string d = "eraser";
	reverse(s.begin(), s.end());
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	reverse(c.begin(), c.end());
	reverse(d.begin(), d.end());
	int na = a.size(); // 5
	int nb = b.size(); // 7
	int nc = na;       // 5
	int nd = d.size(); // 6
	string tmp_s = s;
	bool can = true;
	while (true) {
	//while (na <= tmp_s.size()) {
	//while (tmp_s != "") {
		if (nb <= tmp_s.size()) {
			if (tmp_s.substr(0, na) == a || tmp_s.substr(0, nc) == c) {
				tmp_s = tmp_s.substr(na);
			}
			else if (tmp_s.substr(0, nb) == b) {
				tmp_s = tmp_s.substr(nb);
			}
			else if (tmp_s.substr(0, nd) == d) {
				tmp_s = tmp_s.substr(nd);
			}
			else {
				can = false;
				break;
			}
			if (tmp_s.size() == 0) break;
		}
		else if (tmp_s.size() == nd) {
			if (!(tmp_s == d)) {
				can = false;
			}
			break;
		}
		else if (tmp_s.size() == na) {
			if (!(tmp_s == a || tmp_s == c)) {
				can = false;
			}
			break;
		}
		else {
			can = false;
			break;
		}
	}
	if (can) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

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

int min_steiner_tree(mat d, vector<int> t){
  int n = d.size(), m = t.size();
  if(m<=1)return 0;

  rep(k,n)rep(i,n)rep(j,n)d[i][j] = min(d[i][j],d[i][k]+d[k][j]);

  mat dp(1<<m,vec(n,INF));
  rep(i,m)rep(j,n)dp[1<<i][j] = d[t[i]][j];

  rep(s,1<<m){
    if(!(s & (s-1)))continue;
    rep(p,n){
      int sub = s;
      do{
	dp[s][p] = min(dp[s][p], dp[sub][p] + dp[s-sub][p]);
	sub = (sub-1)&s;
      }while(sub!=s);
    }

    rep(p,n)rep(q,n){
      dp[s][p] = min(dp[s][p], dp[s][q] + d[p][q]);
    }
  }

  int ans = INF;
  rep(s,1<<m)rep(p,n){
    ans = min(ans, dp[s][p] + dp[(1<<m)-1-s][p]);
  }

  return ans;
}

int main(){
  int h,w;
  while(cin >> h >> w,h){
    mat d(h*w,vec(w*w,INF));
    vector<int> t;
    int a;
    rep(i,h)rep(j,w){
      cin >> a;
      int p = i*w+j;
      if(a)t.push_back(p);
      rep(k,4){
	int ny = i+dy[k], nx = j+dx[k];
	if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
	d[p][ny*w+nx] = 1;
      }
      d[p][p] = 0;
    }

    if(t.empty())cout << h*w << endl;
    else cout << h*w-1-min_steiner_tree(d,t) << endl;
  }
}

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

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

    for (int i = 0; i < m; i++)
    {
        int ai;
        cin >> ai;
        n -= ai;
    }

    if (n < 0)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << n << endl;
    }
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <algorithm> // sort
#include <map> // pair
using namespace std;


int main(){
  int n,k;
  cin >> n >> k;
  if(k==1){
    cout << 0;
  }else{
    cout << n-k;
  }
}


Measured memory_bytes: 768
import math
def is_prime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False

    for p in range(3, int(math.sqrt(n))+1, 2):
        if n % p == 0:
            return False

    return True

x = int(input())
for i in range(x, 10**10):
    if is_prime(i):
        print(i)
        break


Measured memory_bytes: 9164
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main(void)
{
	int n, l;
	int min;
	int num;
	int sum = 0;
	int ans = 0;
	cin >> n >> l;
	int i;
	for (i = 0; i < n; i++)
	{
		sum = sum + l + i;
	}
	if (l < 0)
	{
		if (abs(l) < n)
		{
			cout << sum << endl;
		}
		else
		{
			cout << sum - (l + n - 1) << endl;
		}

	}
	else
	{
		cout << sum - l << endl;
	}
	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;
int main() {
  string a,b;
  cin >> a >> b;
  vector<pair<int,string> > s;
  s.push_back(make_pair(a.length(),a));  s.push_back(make_pair(b.length(),b));
  sort(s.begin(),s.end());
  if(s[0].second == s[1].second) puts("EQUAL");
  else if(s[0].second == b) puts("GREATER");
  else if (s[0].second == a) puts("LESS");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
string yes = "Yes\n";
string no = "No\n";

int  main()
{
	int a, b; cin >> a >> b;
	if (a+b < 10)
		cout << a + b;
	else
		cout << "error";
	return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    int d = max(n-k,0);
    int res = x*min(n,k)+y*d;
    cout<<res<<endl;
}

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



public class Main{
  
 public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] as = new int[N];
        int sum = 0;
        for(int i = 0; i < N;i++){
            as[i]=scanner.nextInt();
            sum += as[i];
        }
        sum -= N;
        System.out.println(sum);
    } 
  
  
  
  
  
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

string key = "keyence";

void solve()
{
  string s; cin >> s;
  // vector<ll> a(n); REP(i, n) cin >> a[i];
  // ll ans = 0;
  bool ok = false;
  REP(i, 7) {
    //    if(s[i] == key[i])
  }
  if(key == s.substr(0, 7)) ok = true;
  else if(key == s.substr(s.size()-7, 7)) ok = true;
  else {
    int l = 0, r = 0;
    for(l = 0; key[l] == s[l]; l++);
    for(r = 0; key[7-r-1] == s[s.size()-r-1]; r++);
    if(r + l >= 7) ok = true;
  }
  // cout << ans << endl;
  cout << (ok?"YES":"NO") << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Mmax = 1e5;
const int INF = 1e9;
int N, M, U[Mmax], V[Mmax], S, T;


int main(){
	cin >> N >> M;
	for(int i=0; i<M; i++){
		cin >> U[i] >> V[i];
		U[i]--;
		V[i]--;
	}
	cin >> S >> T;
	S--;
	T--;

	vector<vector<int> > graph(N);
	for(int i=0; i<M; i++){
		graph[U[i]].push_back(V[i]);
	}

	vector<vector<int>> dist(N, vector<int>(3, INF));
	dist[S] = {0, INF, INF};
	queue<pair<int, int> > que;
	que.push({S, 0});
	while(!que.empty()){
		int u = que.front().first;
		int r = que.front().second;
		//cout << u+1 << " " << r << endl;
		que.pop();
		for(int v: graph[u]){
			if(dist[u][r] + 1 < dist[v][(r+1)%3]){
				dist[v][(r+1)%3] = dist[u][r]+1;
				que.push({v, (r+1)%3});
			}
		}
	}

	if(dist[T][0] < INF){
		cout << dist[T][0] / 3 << endl;
	} else {
		cout << -1 << endl;
	}

	return 0;
}


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

ll MOD = 1000000007;

int main(){
  int N, M;
  cin >> N >> M;
  int a[M];
  for(int i = 0; i < M; i++) cin >> a[i];

  bool st[N + 1];
  fill(st, st + N + 1, true);
  for(int i = 0; i < M; i++) st[a[i]] = false;

  ll dp[N + 1];
  dp[0] = 1;
  for(int i = 1; i <= N; i++){
    if(i == 1){
      if(st[i]) dp[i] = 1;
      else dp[i] = 0;
      continue;
    }

    if(st[i]){
      dp[i] = dp[i - 1] + dp[i - 2];
      dp[i] %= MOD;
    }
    else{
      dp[i] = 0;
    }
  }

  cout << dp[N] << endl;
  return 0;

}


Measured memory_bytes: 1536
#include <stdio.h>

#define n 100000
#define q 50000

int main(){

  int a,b,i,left,right,mid;

  int count = 0;
  
  int S[n],T[q];
  
  scanf("%d",&a);

  for(i=0;i<a;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&b);

  for(i=0;i<b;i++){
    scanf("%d",&T[i]);
    
    left = 0;
    right = a;

    while(left < right){
      
      mid = (left + right) / 2;
      if(S[mid] == T[i]){
	count++;
	break;
      }

      if(S[mid] < T[i]){
	left = mid + 1;
      }

      else if(S[mid] > T[i]){
	right = mid;
      }

    }
  }

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

  return 0;
}



Measured memory_bytes: 2380
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define vpll vector <pll>
#define pb push_back

int main()
{
    ll int a=100,x;
    cin>>x;
    int c=0;
    while(a<x)
    {
        a=a*1.01;
        c++;
    }
    cout<<c;
   return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[]) {

	long long S;
	int cnt = 1;
	int flg1 = 2;
	int flg2 = 2;
	int flg4 = 2;

	cin >> S;

	if (S==1){
		flg1--;
	}
	if (S==2){
		flg2--;
	}
	if (S==4){
        flg4--;
	}


	while (flg1 > 0 && flg2 > 0 && flg4 > 0 ) {

		if (S % 2 == 0) {
			S /= 2;
		}
		else {
			S = 3 * S + 1;
		}

		if (S == 4) {
			flg4--;
		}

		if (S == 2) {
			flg2--;
		}

		if (S == 1) {
			flg1--;
		}

		cnt++;
	}

	cout << cnt << endl;

	return 0;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int q,n,cnt,d,max;
	cin >> q;
	for(int i = 0; i < q; i++){
		cin >> n;
		cnt = 0;
		while(n >= 10){
			max = (n % 10) * (n / 10);
			for(d = 100; d < n; d *= 10){
				int x,y;
				x = n % d;
				y = n / d;
				if(max < x * y) max = x * y;
			}
			n = max;
			cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;

int N;

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

int day = 0, month = 0;

void input(void) {
	CI month >> day;
	return;
}


int main(void) {
	int weekday = 0;
	int y = 2004;

	string dayname[] = { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };
	while (true) {
		input();
		if (day == 0) {
			break;
		}
		if (month < 3) {
			y--; month += 12;
		}
		weekday =  (y + (y / 4) - (y / 100) + (y / 400) + (13 * month + 8) / 5 + day) % 7;
		y = 2004;
		CO dayname[weekday] E
	}
	
	return 0;
}

Measured memory_bytes: 3152
N = int(input())
A = list(map(int, input().split()))
X = [0 for i in range(N)]
Y = [0 for i in range(N)]

def gcd(a,b):
    x = max(a, b)
    y = min(a, b)
    if y == 0:
        return x
    if x % y == 0:
        return y
    else:
        return gcd(y, x%y)

for i in range(1,N):
    X[i] = gcd(X[i-1], A[i-1])

for i in range(N-1)[::-1]:
    Y[i] = gcd(Y[i+1], A[i+1])

Z = [gcd(X[i], Y[i]) for i in range(N)]

print(max(Z))

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

signed main(){
	int A,B,K,now;
	cin>>A>>B>>K; now=0;
	for(int i=min(A,B);i>0;i--){
		if(A%i==0 && B%i==0)now++;
		if(now==K){
			now=i;
			break;
		}
	}
	cout<<now<<endl;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())

int main() {
	cin.sync_with_stdio(false);
	double A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;
	A *= 100; B *= 100;
	double ans=0, ansx=0, ansy=0;
	rep(i, F/A+2) {
		rep(j, F/B+2) {
			double w = A*i + B*j;
			rep(k, F/C+2) {
				rep(l, F/D+2) {
					double x = w + k*C + l*D;
					double y = C*k + D*l;
					if (x <= F&&y / x <= E / (100 + E)) {
						if (ans < y / x ) {
							ansx = x;
							ansy = y;
							ans = y / x;
						}
					}
				}
			}
		}
	}
	if (ans == 0)cout << A << " " << 0 << endl;
	else {
		cout << ansx << " " << ansy << endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;

namespace moff2 {
    class MainClass {
        public static void Main(string[] args) {

            // logic
            var five00Num = int.Parse(Console.ReadLine());//10
            var one00Num = int.Parse(Console.ReadLine());//2
            var five0Num = int.Parse(Console.ReadLine());//1
            var total = int.Parse(Console.ReadLine());

            // 500円から試行する
            var cnt = 0;
            for (int i = five00Num; i >= 0; i--) {
                var red = total - 500 * i;
                if (red == 0) {
                    cnt++;
                    continue;
                } else {
                    for (int j = one00Num; j >= 0; j--) {
                        var red2 = red - 100 * j;
                        if (red2 == 0) {
                            cnt++;
                            continue;
                        } else {
                            for (int k = five0Num; k >= 0; k--) {
                                var red3 = red2 - 50 * k;
                                if (red3 == 0) {
                                    cnt++;
                                    continue;
                                }
                            }
                        }
                    }
                }
            }

            Console.WriteLine(cnt);
        }
    }
}


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

#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
#define DEBUG(x) cerr << #x << " = " << x << endl

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> inline T tabs(T a) { return (a > 0) ? a : -a; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

const int N = 2000005;
ll dp[N];

ll mod_pow(ll x, int y = MOD - 2) {
    ll res = 1;
    while (y > 0) {
        if (y & 1) res = res * x % MOD;
        x = x * x % MOD;
        y >>= 1;
    }
    return res;
}

inline ll comb(int n, int k) {
	ll ans = dp[n] * mod_pow(dp[k]) % MOD;
	ans = (ans * mod_pow(dp[n - k])) % MOD;
	return ans;
}

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);
	
	dp[0] = dp[1] = 1;
	REPU(i, 2, N) dp[i] = dp[i - 1] * i % MOD;

	int h, w, a, b;
	ll ans = 0;

	cin >> h >> w >> a >> b;
	REPU(i, 1, h - a + 1) {
		ans += comb(i + b - 2, i - 1) * comb(h + w - b - i - 1, h - i) % MOD;
	}
	ans %= MOD;
	cout << ans << endl;
	
	return 0;
}

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

int main(){
  
  while(true){
    int H,W;
    cin >> H >> W;
    if(H==0 && W==0)break;

    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        cout << '#';
      }
      cout << endl;
    }

    cout << '\n';
  }

  return 0;

}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MOD 1000000007

int N,Q;
string S;
char c[202020],p[202020],d[202020];

int simulation(int pos){
  for(int i = 1; i <= Q; i++){
    if(pos == 0) return 1;
    if(pos == N+1) return 3;
    if(d[pos] == c[i]){
      if(p[i] == 'L') pos--;
      else pos++;
    }
  }
  if(pos == 0) return 1;
  if(pos == N+1) return 3;
  return 2;
}

int main(){
  cin >> N >> Q >> S;
  for(int i = 1; i <= N; i++) d[i] = S[i-1];
  for(int i = 1; i <= Q; i++) cin >> c[i] >> p[i];

  int L1 = 1, R1 = N + 1, M1, maxn = 0;

   for(int i = 0; i < 25; i++){
     M1 = (L1+R1) / 2;
     int z = simulation(M1);
     if(z == 1){
       maxn = max(maxn,M1);
       L1 = M1;
     }else{
       R1 = M1;
     }
   }
   int L2 = 1, R2 = N+1, M2, minx = N + 1;
   for(int i = 0; i < 25; i++){
     M2 = (L2 + R2) / 2;
     int z = simulation(M2);
     if(z == 3){
       minx = min(minx,M2);
       R2 = M2;
     }else{
       L2 = M2;
     }
   }

   cout << minx - maxn - 1 <<endl;
   return 0;
}

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

    ll a = min({v[0] * 4, v[1] * 2, v[2]});
    ll b = min(2 * a, v[3]);

    ll ans = (N / 2) * b + ((N % 2) ? a : 0);
    cout << ans << '\n';
}


Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)

# 初期化 全ての頂点を繋いだ状態（片方の頂点からのみ）とする
graph = Array.new(n) { Array.new }
(1...n).each do |i|
  graph[i] += (1..i).to_a
end

# 辺を 1 つずつ外していく、外した頂点同士の距離が 2 となる
# ただし、全ての頂点が 1 と繋がった状態を保つ
graph.each do |r|
  while r.size > 1 && k > 0
    r.pop
    k -= 1
  end
  break if k == 0
end

# 距離が 2 の組み合わせを全て作れた場合
if k == 0
  puts graph.flatten.size
  graph.each_with_index do |r, from|
    r.each do |to|
      puts "#{from + 1} #{to}"
    end
  end
  # 作れなかった場合
else
  puts -1
end


Measured memory_bytes: 1916
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
)

func Solve() {
  var N int
  var A []int
  NextInt(&N)
  NextIntSlice(&A)
  sort.Sort(sort.Reverse(sort.IntSlice(A)))
  ans := 0
  for i := 1; i < N; i++ {
    ans += A[i / 2]
  }
  Write(ans)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  Write(B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 13420
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

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

    int N;
    string s;
    cin >> N >> s;

    vector<int> w(N + 1), b(N + 1);
    if (s[0] == '.') {
        w[1] = 1;
    } else {
        b[1] = 1;
    }

    FOR(i, 1, N + 1) {
        if (s[i - 1] == '.') {
            w[i] = w[i - 1] + 1;
            b[i] = b[i - 1];
        } else {
            w[i] = w[i - 1];
            b[i] = b[i - 1] + 1;
        }
    }
    int ans = INF32;

    REP(i, N + 1) {
        int towhite = b[i];
        int toblack = w[N] - w[i];
        int sum     = towhite + toblack;
        chmin(ans, sum);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2196
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

apple_value = p + q + r
apple_type = [0] * A + [1] * B + [2] * C

tmp = zip(apple_value, apple_type)
tmp = sorted(tmp, reverse=True)
apple_value, apple_type = zip(*tmp)
ans = 0
type_list = [0, 0, 0]
max_list = [X, Y, 0]
green_num = 0

for a_value, a_type in zip(apple_value, apple_type):
    if sum(type_list) >= X + Y:
        break
    if type_list[a_type] < max_list[a_type] or a_type == 2:
        ans += a_value
        type_list[a_type] += 1
print(ans)

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

int main(){
  
  string s,t;
  cin>>s>>t;
  
  bool f =true;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
    f=false;
    }
  }
  
  if(f){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

typedef long long int ll;
#define f(a, b) for(auto i = a;i < b;i++)
#define ent cout << "\n"

bool sortbysec(const pair<ll, ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 
void solve()
{
	ll n, sum = 0;
	cin >> n;
	f(1, n + 1)
	{
		// if(i % 3 == 0 && i % 5 == 0)
		// 	break;
		if(i % 3 != 0 && i % 5 != 0)
			sum += i;

	}
	ent;
	cout << sum << "\n";
	return;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);	

	solve();

}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    static int f(int a, int b, int c, int k) {
        if (k <= a) return k;
        if (k <= a + b) return a;
        return a - (k - a - b);
    }
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), k = in.nextInt();
        System.out.println(f(a, b, c, k));
    }
}


Measured memory_bytes: 35696
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	string s[n];
	for(int i=0;i<n;i++)	cin >> s[i];
	sort(s,s+n);
	int ans=1,c=1;
	for(int i=0;i<n-1;i++){
		if(s[i]==s[i+1])	c++;
		else{
			ans++;
			c=1;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9844
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int K = sc.nextInt();
    /*
    int[] A = new int[M];
    int[] B = new int[M];
    for (int i = 0; i < M; i++) {
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
    }
    int[] C = new int[K];
    int[] D = new int[K];
    for (int i = 0; i < K; i++) {
      C[i] = sc.nextInt();
      D[i] = sc.nextInt();
    }
    sc.close();
    */

    @SuppressWarnings("unchecked")
    Set<Integer>[] g = new Set[N + 1];
    int[] fc = new int[N + 1];
    for (int i = 0; i < M; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      if (g[a] == null && g[b] == null) {
        Set<Integer> set = new HashSet<>();
        set.add(a);
        set.add(b);
        g[a] = set;
        g[b] = set;
      } else if (g[a] == null) {
        Set<Integer> set = g[b];
        set.add(a);
        g[a] = set;
      } else if (g[b] == null) {
        Set<Integer> set = g[a];
        set.add(b);
        g[b] = set;
      } else if (g[a] != g[b]) {
        Set<Integer> setL = g[a];
        Set<Integer> setS = g[b];
        if (setL.size() < setS.size()) {
          Set<Integer> temp = setL;
          setL = setS;
          setS = temp;
        }
        setL.addAll(setS);
        for (int c : setS) g[c] = setL;
      }
      fc[a]++;
      fc[b]++;
    }

    int[] bc = new int[N + 1];
    for (int i = 0; i < K; i++) {
      int c = sc.nextInt();
      int d = sc.nextInt();
      if (g[c] == g[d]) {
        bc[c]++;
        bc[d]++;
      }
    }
    sc.close();

    int[] ans = new int[N + 1];
    for (int i = 1; i < N + 1; i++)
      if (g[i] != null)
        ans[i] = g[i].size() - 1 - fc[i] - bc[i];

    StringBuilder buf = new StringBuilder();
    for (int i = 1; i < N + 1; i++)
      buf.append(ans[i]).append(' ');
    System.out.println(buf);
  }
}

Measured memory_bytes: 128812
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, k = map(int, input().split())
a = list(map(int, input().split()))

def bs(ok, ng, cond):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if cond(mid):
            ok = mid
        else:
            ng = mid
    return ok

def cond(upper):
    ans = 0
    for v in a:
        if v <= upper:
            continue
        if v % upper == 0:
            ans += ((v // upper) - 1)
        else:
            ans += v // upper
    return ans <= k

print(bs(max(a), 0, cond))


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

char w[11];
char t[1010];

int main(){
	int ans = 0;
	scanf("%s", w);
	while(true) {
		scanf("%s", t);
		if(strcmp(t, "END_OF_TEXT") == 0) break;
		for(int i = 0; i < strlen(t); i++)
			if(isupper(t[i])) t[i] = tolower(t[i]);
		if(strcmp(w, t) == 0)
			ans++;
	}
	printf("%d\n", ans);
}



Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

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



ll fast_pow(ll x,ll n,ll mod){
    if (n==0) return 1;
    ll res=fast_pow(x*x %mod,n/2,mod);
    if (n&1) res=res*x%mod;
    return res;
}

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;


const int mod=1e9+7;
vector<int> to[100005];
ll ans[100005][2];
//0が白塗り、１が黒塗り


void dfs(int v,int p=-1){
    ans[v][0]=ans[v][1]=1;
    for(auto u:to[v]){
        if (u==p) continue;
        
        dfs(u,v);
        ans[v][0]*=(ans[u][0]+ans[u][1])%mod;
        ans[v][1]*=ans[u][0];
        ans[v][0]%=mod;ans[v][1]%=mod;
    }
    
}

int main(){
    int n;
    cin>>n;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    dfs(0);
    
    int ans1=(ans[0][0]+ans[0][1])%mod;
    cout<<ans1<<endl;
    return 0;
}


Measured memory_bytes: 14208
package main

import (
	"fmt"
)

func minint(a int, b int) int {
	if a > b {
		return b
	}
	return a
}
func main() {
	prev := 0
	current := 1
	var n, limit, w, v, i, j int
	fmt.Scan(&n, &limit)
	var dp [][]int
	dp = append(dp, make([]int, 100000+1))
	dp = append(dp, make([]int, 100000+1))
	for i = 1; i <= 100000; i++ {
		dp[prev][i] = limit + 1
	}
	for i = 0; i < n; i++ {
		fmt.Scan(&w, &v)
		for j = 0; j <= v; j++ {
			dp[current][j] = dp[prev][j]
		}
		for j = v; j <= 100000; j++ {
			dp[current][j] = minint(dp[prev][j-v]+w, dp[prev][j])
		}
		prev, current = current, prev
	}
	for i = 100000; i >= 0; i-- {
		if dp[prev][i] <= limit {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(0)
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(f) (f).begin(),(f).end()
#define allr(f) (f).rbegin(),(f).rend()
const int mod = 1e9+7, A = 1e2+5;
using namespace std;
ll GCD (ll x, ll y) {
	return (!y) ? x : GCD(y, x % y);
}
ll LCM (ll x, ll y) {
	return x * y / GCD(x, y);
}
ll num2 (ll x) {
	ll cnt = 0;
	while (x % 2 == 0)
		cnt++, x /= 2;
	return cnt;
}
int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n, m;
	cin >> n >> m;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i], a[i] /= 2;
	ll d = num2(a[0]), lcm = a[0];
	for (int i = 1; i < n; i++) {
		if (d != num2(a[i]) || (lcm > m))
			return cout << 0, 0;
		lcm = LCM(lcm, a[i]);
	}
	ll cnt = 0, x = 1;
	while (lcm*x <= m)
		cnt++, x += 2;
	cout << cnt;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
const ll mod = 1000000007;


int main(){
  int a,b;
  cin>>a>>b;

  if(a<10 and b<10)cout<<a*b<<endl;
  else cout<<-1<<endl;

  return 0;
}


Measured memory_bytes: 256
# coding: utf-8


def main():
    S = input()
    K = int(input())
    ans = '1'
    tmp = -1
    for i, s in enumerate(S):
        if s != '1':
            ans = s
            break
        else:
            tmp = i

    if K - 1 <= tmp:
        ans = '1'

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
x = int(input())

#√nまでの素数の配列を返す関数
def primes(n):
    if n < 4:
        return []
    else:
        pri = [2]
        k = 3
        while k*k <= n:
            for i in pri:
                if k%i == 0:
                    break
                elif i == pri[-1]:
                    pri.append(k)
            k += 2
        return pri

prime = primes(x)
if x == 2:
    print(2)
else:
    x = (x//2)*2 + 1
    while True:
        flag = True
        for i in prime:
            if x%i == 0:
                x += 2
                flag = False
                break
        if flag:
            break
    print(x)


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

using namespace std;

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

int main()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;
    int n = (X - Z) / (Y + Z);
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, a, b) for(int i = (a); i >= (b); --i)
#define debug(x) cerr << #x << ' ' << x << endl;
using namespace std;

typedef long long ll;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int a[MAXN], ord[MAXN];
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    rep(i, 1, n)    cin >> a[i], ord[a[i]] = i;;
    rep(i, 1, n)    cout << ord[i] << ' ';
    return 0;
}

Measured memory_bytes: 1664
import Data.Ratio

main :: IO ()
main = do
  [x,k,d] <- map read . words <$> getLine
  print $ solve x k d

-- |
-- >>> solve 6 2 4
-- 2
--
-- >>> solve 7 4 3
-- 1
--
-- >>> solve 10 1 2
-- 8
--
-- >>> solve 1000000000000000 1000000000000000 1000000000000000
-- 1000000000000000
--
-- prop> k >= 1 && d >= 1 ==> solve x k d >= 0
--
-- prop> k >= 1 && d >= 1 ==> solve (-x) k d == solve x k d
--
-- prop> k >= 1 && d >= 1 && x > 0 ==> solve (x+d) (k+1) d == solve x k d
--
solve :: Integer -> Integer -> Integer -> Integer
solve x k d
  | x < 0     = solve (-x) k d
  | x0 >= 0   = x0
  | k == 0    = x
  | k == 1    = abs (x - d)
  | otherwise = solve (x - k0 * d) ((k - k0) `mod` 2) d
 where
  x0 = x - k * d
  k0 = floor (x % d)


Measured memory_bytes: 4092
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    h,w = LI()
    d = LIR(10)
    for k in range(10):
        for i in range(10):
            for j in range(10):
                nd = d[i][k]+d[k][j]
                if nd < d[i][j]:
                    d[i][j] = nd
    a = LIR(h)
    ans = 0
    for i in a:
        for j in i:
            if j < 0:
                continue
            ans += d[j][1]
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 40284
s=input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
import sys
for i in range(8):
    j_list=[]
    op=(i>>0)&1
    if op:
        ans=a+b
        j_list.append('+')
    else:
        ans=a-b
        j_list.append('-')
    op=(i>>1)&1
    if op:
        ans+=c
        j_list.append('+')
    else:
        ans-=c
        j_list.append('-')
    op=(i>>2)&1
    if op:
        ans+=d
        j_list.append('+')
    else:
        ans-=d
        j_list.append('-')
    if ans==7:
        print(s[0]+j_list[0]+s[1]+j_list[1]+s[2]+j_list[2]+s[3]+'=7')
        sys.exit()
    
        


Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<string>
#include<unordered_map>
#include<cstring>

using namespace std;

struct Resto
{
	int id;
	string city;
	int score;

	bool operator<(const Resto& another) const
	{
		if (strcmp(city.c_str(), another.city.c_str()) < 0)
		{
			return true;
		}
		else if (strcmp(city.c_str(), another.city.c_str()) == 0)
		{
			return score > another.score;
		}
		else {
			return false;
		}
	}
};

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

	vector<Resto> data(n);


	for (int i = 0; i < n; i++)
	{
		data[i].id = i + 1;
		cin >> data[i].city >> data[i].score;
	}

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

	for (int i = 0; i < n; i++)
	{
		cout << data[i].id << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int a[4];
	char s[4];
	for (int i = 0; i < 4; ++i) {
		cin >> s[i];
		a[i] = (int)(s[i] - '0');
	}
	for (int bit = 0; bit < (1 << 3); ++bit) {
		vector<bool>op(3, false);
		for (int i = 0; i < 3; ++i) {
			if (bit & 1 << 2-i)op[i] = true;
		}int sum = a[0];
		for (int i = 1; i < 4; ++i) {
			if (op[i - 1] == true)sum += a[i];
			else sum -= a[i];
		}
		if (sum == 7) {
			vector<char>c(3);
			for (int i = 0; i < 3; ++i) {
				if (op[i]==true)c[i] = '+';
				else c[i] = '-';
			}
			for (int i = 0; i < 3; ++i)cout << a[i] << c[i];
			cout << a[3] << "=7" << endl;
			return 0;
		}
	}
}

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

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

    for(int tmp=0;tmp<n;tmp++){
        if(tmp!=n-1){
            cout << a[tmp] << " ";
        }
        else{
            cout << a[tmp] << endl;
        }
    }
    for(int i=1;i<n;i++){
        int j=i;
        while(true){
            if(a[j-1]<a[j]){
                break;
            }
            swap(a[j-1],a[j]);
            j--;
            if(j==0){
                break;
            }
        }
        for(int tmp=0;tmp<n;tmp++){
            if(tmp!=n-1){
                cout << a[tmp] << " ";
            }
            else{
                cout << a[tmp] << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power_mod(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
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) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define outaa(a, m, n) rep(i, m) {rep(j, n) cout << a[i][j] << " "; cout << endl;} cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl

//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always
//product of minimum 9 prime numbers is above 1e9


int main() {
    
    
    
    
    int N, W; cin >> N >> W;
    ll dp[100007]; fill_n(dp, 100007, inf);
    dp[0] = 0;
    
    rep(i, N) {
        int w, v; cin >> w >> v;
        for (int j = 100000; j >= v; --j) {
            if (dp[j - v] + w > W) continue;
            chmin(dp[j], dp[j - v] + w);
        }
    }
    
    for (int i = 100000; i >= 0; --i) if (dp[i] != inf) {out(i); return 0;}
    
    
}

/*
 dp[30] = 3
 
 dp[50] = 4
 dp[80] = 7
 
 dp[60] = 5
 
 
 */


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		try{
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int[] a = new int[N+1];
			for(int i = 1; i < N+1; i++){
				a[i] = sc.nextInt();
			}
			int result = 0;
			int i = 1;
			while(a[i] != 0){
				if(i == 2){
					a[i] = 0;
					break;
				}
				result ++;
				int temp = i;
				i = a[i];
				a[temp] = 0;
			}
			if(a[2] != 0){
				result = -1;
			}
			System.out.println(result);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 51404
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
long long int c(long long int n){
  long long int re=1;
  for(int i=0; i<2; i++){
    re*=n-i;
  }
  re/=2;
  return re;
}
int main(void){
  long long int n;
  cin>>n;
  vector<string> s(n);
  for(int i=0; i<n; i++){
    cin>>s.at(i);
    sort(s.at(i).begin(),s.at(i).end());
  }
  sort(s.begin(),s.end());
  long long int count=1;
  long long int ans=0;
  for(long long int i=0; i<n-1; i++){
    if(s.at(i)==s.at(i+1)){
      count++;
    }else{
      if(count>1){
        ans+=c(count);
        count=1;
      }
    }
  }
  if(count>1){
    ans+=c(count);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 7296
/* https://atcoder.jp/contests/abc081/tasks/arc086_a */

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

/* {{{ Variables */
int N, K;
std::map<int, int> cnt;
/* }}} */

int main(int argc, char *argv[])
{
  /* {{{ Input */
  std::cin >> N >> K;

  for (int i = 0; i < N; ++i) {
    int a;

    std::cin >> a;
    cnt[a]++;
  }
  /* }}} */

  /* {{{ Output */
  int cnt_len = cnt.size();
  std::vector<int> v;

  for (auto p: cnt) {
    int c = p.second;

    v.emplace_back(c);
  }

  std::sort(v.begin(), v.end());

  int num = 0;
  auto ite = v.begin();
  for (int i = 0; i < cnt_len - K; ++i) {
    num += *ite++;
  }

  std::cout << num << std::endl;
  /* }}} */

  return 0;
}


Measured memory_bytes: 10748
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
a = [int(i) for i in input().split()]

cnt = 1
ans = 0
for i in range(n):
	if a[i] == cnt:
		cnt += 1
	else:
		ans += 1
if cnt == 1:
	print(-1)
else:
	print(ans)


Measured memory_bytes: 32296