akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i;
    cin>>n;
    int act[n][3];
    for(i=0;i<n;i++){
        cin>>act[i][0]>>act[i][1]>>act[i][2];
    }
    int dp[n][3]={0};
    dp[0][0]=act[0][0];
    dp[0][1]=act[0][1];
    dp[0][2]=act[0][2];
    for(i=1;i<n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+act[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+act[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+act[i][2];
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),max(dp[n-1][1],dp[n-1][2]));
    return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp[ohara],cmpp,m,h,w,x,y,sum=0,pos,k;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n>>k;
      ll ma=0;
      map<ll,ll> mp;
      rep(i,n){
        cin>>a;
        cmp[a]++;
        ma=max(ma,a);
      }
      sort(cmp,cmp+ma+1);
      rep(i,ma+1){
        if(cmp[i]>0)cnt++;
      }
      //Cout(cnt);
      cnt-=k;
      if(cnt>0){
      rep(i,ma+1){
        if(cmp[i]==0)continue;
        ans+=cmp[i];
        cnt--;
        if(cnt==0)break;
      }
      }
      Cout(ans);
     

       
return 0;
}


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

using ll=long long;

ll g(ll x){
    if(x==0) return 0;
    return 1LL<<(__builtin_ffs(x)-1);
}

struct Tree{
    bool checked;
    Tree* t0;
    Tree* t1;
    Tree(bool checked):checked(checked),t0(nullptr),t1(nullptr){};
};

void buildTree(Tree* tr,int idx,string& s){
    tr->checked=true;
    if(idx==s.size()) return;
    if(tr->t0==nullptr){
        tr->t0=new Tree(false);
        tr->t1=new Tree(false);
    }
    if(s[idx]=='0') buildTree(tr->t0,idx+1,s);
    if(s[idx]=='1') buildTree(tr->t1,idx+1,s);
    return;
}

void search(Tree* tr,int depth,vector<ll>& res){
    if(!tr->checked){
        res.push_back(depth);
    }
    if(tr->t0!=nullptr) search(tr->t0,depth+1,res);
    if(tr->t1!=nullptr) search(tr->t1,depth+1,res);
}

int main(){
    int n;
    cin>>n;
    ll l;
    cin>>l;
    vector<string> s(n);
    for(int i=0;i<n;i++) cin>>s[i];
    Tree* root=new Tree(false);
    for(int i=0;i<n;i++) buildTree(root,0,s[i]);
    vector<ll> dep;
    search(root,0,dep);
    ll res=0;
    for(int i=0;i<dep.size();i++){
        cerr<<l-dep[i]+1<<endl;
        res^=g(l-dep[i]+1);
    }
    
    cout<<(res ? "Alice" : "Bob")<<endl;
    
    return 0;
}

Measured memory_bytes: 12412
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;
 
int main(){
    long long n;
    cin >> n;
    long long ans = n-1;
    for(long long i = 2; i <= (long long)sqrt(n); i++){
         if(n%i == 0){
              if((i-1) + (n/i - 1) <= ans) ans = (i-1) + (n/i - 1);
         }
    }
    cout << ans << endl;
    
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 998244353ll;
const ll MAXN = (ll) 2e5 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-8;



int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	ll v, mx = -1, s = 0;
	for(int i = 0; i < n; i++){
		cin >> v;
		mx = max(mx, v);
		s+=v;
	}
	cout << s - (mx/2);
	return 0;
}


/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

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

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

int N,K;


int main()
{
  int N;
  cin >> N;
  int W[N];
  int sum = 0;
  REP(i, 0, N)
  {
    cin >> W[i];
    sum += W[i];
  }
  int mi = 1000000;
  int s = 0;
  REP(t, 0, N)
  {
    s += W[t];

    int l = sum - s;
    l = abs(l - s);
    mi = min(l, mi);


  }
  cout << mi << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct point point;
typedef struct connection con;

typedef struct connection{
	point *conPoint;
	long long distance;
	con *nextCon;
}con;

typedef struct point{
	con *connection;
	int color;
	long long count;
}point;

void cal(point *num,con *connection){

	if(connection->conPoint->count == -1){
		connection->conPoint->count = num->count + connection->distance;
		cal(connection->conPoint,connection->conPoint->connection);
	}

	if(connection->nextCon == NULL){
		return;
	}
	cal(num,connection->nextCon);
	
}

void insert(point *p,int tempD,int tempP,int tempP2){
	con *connection = malloc(sizeof(con));
	connection->distance = tempD;
	connection->nextCon = p[tempP - 1].connection;
	p[tempP - 1].connection = connection;
	connection->conPoint = &p[tempP2 - 1];
}

int main(int argc, char **argv){
	int n = 0;
	int i = 0;
	int tempP = 0;
	int tempP2 = 0;
	long long tempD = 0;
	scanf("%d",&n);
	point *node = malloc(sizeof(point) * n);

	for(i = 0;i < n;i++){
		node[i].color = 0;
		node[i].connection = NULL;
		node[i].count = -1;
	}

	for(i = 0;i < n-1;i++){
		scanf("%d%d%d",&tempP,&tempP2,&tempD);
		insert(node,tempD,tempP,tempP2);
		insert(node,tempD,tempP2,tempP);
	}

	
	node[0].count = 0;
	cal(&node[0],node[0].connection);
	
	
	
	for(i = 1;i < n;i++){
		if(node[i].count % 2 == 1){
			node[i].color = 1;
		}
	}
	

	for(i = 0;i < n;i++){
		printf("%d\n",node[i].color);
	}
}

Measured memory_bytes: 9856
from sys import stdin, setrecursionlimit
input = stdin.readline

setrecursionlimit(100000)

move = ((-1,-1),(-1,0),(-1,1),(0,1),(0,-1),(1,-1),(1,0),(1,1))
def DFS(x,y):
    if mapmatrix[j][i] == 1 and not checked[y][x]:
        checked[y][x] = True
        
        for dx, dy in move:
            X = x + dx; Y = y + dy
            if X >= 0 and X < W and Y >= 0 and Y < H:
                if mapmatrix[Y][X] == 1:
                    DFS(X,Y)
    
while True:
    W,H = map(int, input().split())
    if W == 0 and H == 0:
        break
    
    mapmatrix = [None]*H
    for i in range(H):
        mapmatrix[i] = list(map(int, input().split()))
    
    checked = [[False]*W for _ in range(H)]
    
    islandcnt = 0
    for j in range(H):
        for i in range(W):
            if mapmatrix[j][i] == 1 and not checked[j][i]:
                DFS(i,j)
                islandcnt += 1
    
    print(islandcnt)


Measured memory_bytes: 7972
H, W=map(int, input().split())
c=['.'*(W+2)]+['.'+input()+'.' for _ in range(H)]+['.'*(W+2)]
ans=[['0']*(W+2) for _ in range(H+2)]
for h in range(1, H+1):
  for w in range(1, W+1):
    if c[h][w]=='#':
      ans[h][w]='#'
    else:
      x=0
      if c[h-1][w-1]=='#':
        x+=1
      if c[h-1][w]=='#':
        x+=1
      if c[h-1][w+1]=='#':
        x+=1
      if c[h][w-1]=='#':
        x+=1
      if c[h][w+1]=='#':
        x+=1
      if c[h+1][w-1]=='#':
        x+=1
      if c[h+1][w]=='#':
        x+=1
      if c[h+1][w+1]=='#':
        x+=1
      ans[h][w]=str(x)
for i in range(1, H+1):
  print(''.join(ans[i][1:-1]))

Measured memory_bytes: 9224
from collections import deque
h, w = map(int, input().split())

field = [[c for c in input().strip()] for _ in range(h)]

dir_x = [0, 1, 0, -1]
dir_y = [-1, 0, 1, 0]
ans = 0
# 全部のマスをスタートにしてチェックする
for i in range(h):
    for j in range(w):
        if field[i][j] == '#':
            continue

        field_flag = [[0 for _ in range(w)] for _ in range(h)]
        field_step = [[0 for _ in range(w)] for _ in range(h)]
        # スタート地点を入れる
        d = deque()
        d.append([i, j])
        while (d):
            y, x = d.popleft()
            field_flag[y][x] = 1  # スタート地点のフラグを入れる
            for xx, yy in zip(dir_x, dir_y):
                if xx+x in range(w) and yy+y in range(h):
                    if field[yy+y][xx+x] == '.' and field_flag[yy+y][xx+x] == 0:
                        field_flag[yy+y][xx+x] = 1  # チェック済
                        # そこへたどり着く最小歩数
                        field_step[yy + y][xx + x] = field_step[y][x] + 1
                        ans = max(ans, field_step[yy + y][xx + x])  # 答えの更新
                        d.append([yy+y, xx+x])

print(ans)


Measured memory_bytes: 3316
def bin_search(lis, target, low, high):
    while high-low!=1:
        mid = (low+high) // 2
        #print(low, mid, high)
        if lis[mid] == target:
            return mid, 1
        elif lis[mid] > target:
            high = mid
        else:
            low = mid
    if lis[low] == target:
        return low, 1
    elif lis[high] < target:
        return high, 0
    else:
        return low, 0
    
    
n, m = map(int, input().split())
a = [int(i) for i in input().split(" ")]
bc = [[int(i) for i in input().split(" ")] for i in range(m)]
bc = sorted(bc, key=lambda x: x[1])
bc.reverse()
a = sorted(a)
ind = 0
ans = 0
flag = 0
for i in bc:
    if ind >= n:
        break
    if a[min(ind+i[0], n-1)] <= i[1]:
        ans += min(i[0], n-ind)*i[1]
        ind += i[0]
    elif a[ind] >= i[1]:
        ans += sum(a[ind:])
        flag = 1
        break
    else:
        tm = bin_search(a[ind:min(ind+i[0], n-1)], i[1], 0, min(i[0], n-ind))
        ans += i[1]*(tm[0]+1)
        ind += tm[0]+1
        ans += sum(a[ind:])
        flag = 1
        break
if flag == 0:
    ans += sum(a[ind:])
print(ans)

Measured memory_bytes: 27788
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  ll n,m;
  ll ans=0;
  cin>>n>>m;
  if(n*2 >= m){
    cout<<m/2<<endl;
    return 0;
  }
  else{
    ans+=n;
    m-=(n*2);
    n-=n;
 
    ans+=m/4;
  }
  cout<<ans<<endl;

  return 0;
}





Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


int main(void){
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;

	bool ok = true;
	for(int i = 0; i < s.size(); i++){
		if(i == a){
			if(s[i] == '-'){
				continue;
			} else {
				ok = false;
				break;
			}
		} else {
			if(s[i] != '-'){
				continue;
			} else {
				ok = false;
				break;
			}
		}
	}
	if(ok){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
 #include <map>
 
 using namespace std;
 
 int main() {
     long long int N;
     cin >> N;
 
     // 素因数分解
     map<long long int, long long int> primes;
     long long int n = N;
     for (long long int p = 2; (p * p) <= n; p++) {
         long long int k = 0;
         long long int tmpn = n;
 //cout << p << ":" << n << endl;
         while (tmpn % p == 0) {
             tmpn /= p;
             k++;
         }
         /*
         if(k >= 2){
             k = 1;
             n /= p;
         }else {
             n = tmpn;
         }
         */
         n = tmpn;
//cout << p << ":" << n << ":" << k << endl;   
         if (k > 0) {
             primes[p] = k;
         }
          
     }
     //cout << n << endl;
     if (n > 1) {
         primes[n] = 1;
     }

      // 結果を出力

     long long int i = 0;
     long long int itr = primes.size();
     map<long long int, long long int> primes2;
     for (auto& prime : primes) {
         long long int a = prime.first;
         long long int b = prime.second;
         long long int cnt = 1;
         //cout << "--- " << endl;
         while(1){
           //cout << a << "," << prime.first <<  "," << b << "," << cnt << endl;
           
           if(b > 2*cnt){
               primes2[a] = 1;
               a *= prime.first;
               b -= cnt;
               cnt++;
           }else{
               primes2[a] = b;
               break;
           }
         }
         //++prime;
         //if(prime == primes.end()) break;
         i++;
         if(i==itr) break;
     
     }
#if 0
     cout << N << " = ";
     for (auto& prime : primes2) {
         cout << prime.first << '^' << prime.second << ' ';

     }
     cout << endl;
 #endif
     cout << primes2.size() << endl;
     return 0;
 }

Measured memory_bytes: 3636
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;

            var cnt = 0;

            for (int i = A; i <= B; i++)
            {
                var original = i.ToString();
                var reverse = original.Reverse();

                if (original == reverse) cnt++;
            }

            WriteLine(cnt);
        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 15312
#include<iostream>

int a[6];
int c[6]={1,5,10,50,100,500};
int sum=0;

int main(){
    for(int i=0;i<6;++i){
        std::cin>>a[i];
        sum+=c[i]*a[i];
    }
    if(sum>=1000)
        std::cout<<1<<std::endl;
    else
        std::cout<<0<<std::endl;
    return 0;
}

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

int main() {
  int64 n, a, b;
  cin >> n >> a >> b;
  int64 ans = n / (a + b) * a + min(a, n % (a + b));
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int a, p; cin >> a >> p;
    p += 3 * a;
    cout << p / 2 << "\n";
}


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

class Nums {
public:
	int a, b, c;

	Nums(int _a, int _b, int _c) {
		a = _a;
		b = _b;
		c = _c;
	}

	bool operator<(const Nums& other) const {
		return a < other.a;
	}
};

int main() {
	int X, Y, Z;
	int K;
	cin >> X >> Y >> Z;
	cin >> K;
	vector<long long> A(X), B(Y), C(Z);
	for (int i = 0; i < X; i++) cin >> A[i];
	for (int i = 0; i < Y; i++) cin >> B[i];
	for (int i = 0; i < Z; i++) cin >> C[i];

	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	sort(B.begin(), B.end());
	reverse(B.begin(), B.end());
	sort(C.begin(), C.end());
	reverse(C.begin(), C.end());

	priority_queue<pair<long long, Nums>> pq;
	pq.push(make_pair(A[0] + B[0] + C[0], Nums(0, 0, 0)));
	//PriorityQueueに入れたかどうかを管理する
	set<int> s;
	s.insert(0);

	vector<long long> ans;

	while (ans.size() < K) {
		auto v = pq.top(); pq.pop();
		ans.push_back(v.first);

		if (v.second.a != X - 1) {
			int a = v.second.a + 1;
			int b = v.second.b;
			int c = v.second.c;
			//hashを作る
			int hash = (a << 20) + (b << 10) + c;
			if (s.find(hash) == s.end()) {
				s.insert(hash);
				pq.push(make_pair(A[a] + B[b] + C[c], Nums(a, b, c)));
			}
		}

		if (v.second.b != Y - 1) {
			int a = v.second.a;
			int b = v.second.b + 1;
			int c = v.second.c;
			//hashを作る
			int hash = (a << 20) + (b << 10) + c;
			if (s.find(hash) == s.end()) {
				s.insert(hash);
				pq.push(make_pair(A[a] + B[b] + C[c], Nums(a, b, c)));
			}
		}

		if (v.second.c != Z - 1) {
			int a = v.second.a;
			int b = v.second.b;
			int c = v.second.c + 1;
			//hashを作る
			int hash = (a << 20) + (b << 10) + c;
			if (s.find(hash) == s.end()) {
				s.insert(hash);
				pq.push(make_pair(A[a] + B[b] + C[c], Nums(a, b, c)));
			}
		}

	}

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

}



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

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 long long INF = 1LL << 60;

int main ()
{
    int h,n,c=0;
    cin >> h >> n;
    int a[n];

    for(int i=0;i<n;i++){
    cin >> a[i];
    c+=a[i];
    }
    if(h<=c)
    cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
    


    
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll INF=1000000000;
  ll i,j,k,n,m,r,a,b,c;
  ll x[10];
  cin >> n >> m >> r;
  for(i=0;i<r;i++){
    cin >> x[i];
    x[i]--;
  }
  ll dp[210][210];
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      dp[i][j]=INF;
    }
  }
  for(i=0;i<m;i++){
    cin >> a >> b >> c;
    a--,b--;
    dp[a][b]=c;
    dp[b][a]=c;
  }
  for(k=0;k<n;k++){
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
      }
    }
  }
  ll y[10];
  for(i=0;i<r;i++){
    y[i]=i;
  }
  ll ans=20000000000000000;
  do{
    ll sum=0;
    for(i=1;i<r;i++){
      sum+=dp[x[y[i-1]]][x[y[i]]];
    }
    if(ans>sum){
      ans=sum;
    }
  }while(next_permutation(y,y+r));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3884
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """30 100"""
        output = """100"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """12 100"""
        output = """50"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """0 100"""
        output = """0"""
        self.assertIO(input, output)
def resolve():
        (A,B)=(int(i) for i in input().split())
        if A>=13:
                print(B)
        elif A>=6:
                print(int(B/2))
        else:
                print(0)
        

if __name__ == "__main__":
    resolve()


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

using ld = double;
using ll = long long;
using ull = unsigned long long;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;

const int SZ = 1 << 13;
char buff[SZ], *pos = buff + SZ - 1;
#define getchar() (++ pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos)

inline ll read() {
	ll x = 0; int f = 1, c = getchar();
	for (;!isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x<<3) + (x<<1) + (c^48);
	return x * f;
}

const int N = 3005;
const int mod = 1e9 + 7;
int n;
char s[N];
// int dp[N][N];

void add(int &x, int y) {
	x += y;
	if (x >= mod) x -= mod;
}

struct Bit {
	int val[N];
	Bit() { memset(val, 0, sizeof val); }
	void upd(int i, int v) { for (++ i; i < N; i += i & -i) add(val[i], v); }
	void upd(int l, int r, int v) { upd(l, v); upd(r + 1, mod - v); }
	int qry(int i) { int ans = 0; for (++ i; i; i -= i & -i) add(ans, val[i]); return ans; }
} dp[N];

int main() {
	n = read();
	for (int i = 0; i < n - 1; ++ i) s[i] = getchar();
	for (int i = 1; i < n; ++ i)
//		dp[0][i] = 1;
		dp[0].upd(i, i, 1);
	for (int i = 1; i + 1 < n; ++ i) {
		for (int j = 1; j <= n - i; ++ j) {
			if (s[i - 1] == '<') {
				if (s[i] == '<')
//					for (int k = 1; k <= j; ++ k) add(dp[i][j - k], dp[i - 1][j]);
					dp[i].upd(0, j - 1, dp[i - 1].qry(j));
				else
//					for (int k = 1; k <= j; ++ k) add(dp[i][n - i - j + k - 1], dp[i - 1][j]);
					dp[i].upd(n - i - j, n - i - 1, dp[i - 1].qry(j));
			}
			else {
				if (s[i] == '<')
//					for (int k = 1; k <= j; ++ k) add(dp[i][n - i - k], dp[i - 1][j]);
					dp[i].upd(n - i - j, n - i - 1, dp[i - 1].qry(j));
				else
//					for (int k = 1; k <= j; ++ k) add(dp[i][k - 1], dp[i - 1][j]);
					dp[i].upd(0, j - 1, dp[i - 1].qry(j));
			}
		}
	}
	for (int j = 0; j <= n; ++ j) {
		for (int k = 1; k <= j; ++ k) {
			if (s[n - 2] == '<')
//				add(dp[n - 1][j - k], dp[n - 2][j]);
				dp[n - 1].upd(j - k, j - k, dp[n - 2].qry(j));
			else
//				add(dp[n - 1][k - 1], dp[n - 2][j]);
				dp[n - 1].upd(k - 1, k - 1, dp[n - 2].qry(j));
		}
	}
//	printf("%d\n", dp[n - 1][0]);
	printf("%d\n", dp[n - 1].qry(0));
	return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
#define _GLIBCXX_DEBUG
     
int main() {
  string s, t;
  cin >> s >> t;
  int a, b=1;
  a = s.size();
  rep(i,a) if (s[i] != t[i]) {
    b = 0;
    break;
  }
  if (b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b,c,ans=0;
    cin>>a>>b>>c;
    
    ll n=min(b,c);
    ans+=n*2;
    b-=n;
    c-=n;
    
    if(b){
        ans+=b;
    }
    
    if(c){
        n=min(a,c);
        c-=n;
        ans+=n;
        if(c) ans++;
    }
    cout1(ans)
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  string n;
  while(cin >> n,n!="0"){
    int ans = 0;
    REP(i,n.size()){
      ans += n[i]-'0';
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3164
class Dice():
    def __init__(self, a, b, c, d, e, f):
        """面の数字とindexを一致させるために0を挿入"""
        self.s = [0, a, b, c, d, e, f]

    def rotate(self, dir):
        if dir == "N":
            self.s[0] = self.s[1] #s[0]に一時的にs[1]を保持
            self.s[1] = self.s[2] 
            self.s[2] = self.s[6]
            self.s[6] = self.s[5]
            self.s[5] = self.s[0]
            return

        elif dir == "W":
            self.s[0] = self.s[1]
            self.s[1] = self.s[3] 
            self.s[3] = self.s[6]
            self.s[6] = self.s[4]
            self.s[4] = self.s[0]
            return

        elif dir == "S":
            self.s[0] = self.s[1]
            self.s[1] = self.s[5] 
            self.s[5] = self.s[6]
            self.s[6] = self.s[2]
            self.s[2] = self.s[0]
            return

        elif dir == "E":
            self.s[0] = self.s[1]
            self.s[1] = self.s[4] 
            self.s[4] = self.s[6]
            self.s[6] = self.s[3]
            self.s[3] = self.s[0]
            return
        
        elif dir == "R":
            self.s[0] = self.s[2]
            self.s[2] = self.s[3] 
            self.s[3] = self.s[5]
            self.s[5] = self.s[4]
            self.s[4] = self.s[0]
            return

        elif dir == "L":
            self.s[0] = self.s[2]
            self.s[2] = self.s[4] 
            self.s[4] = self.s[5]
            self.s[5] = self.s[3]
            self.s[3] = self.s[0]
            return

        else:
            return


dice = Dice(*list(map(int, input().split())))

for _ in range(int(input())):
    t, s = map(int, input().split())

    while dice.s[1] != t:
        dice.rotate("S")
        if dice.s[1] != t:
            dice.rotate("E")
    
    while dice.s[2] != s:
        dice.rotate("R")

    print(dice.s[3])


Measured memory_bytes: 5624
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;


int main(){
    int a[3];
    for(int i=0;i<=2;i++)cin>>a[i];
    sort(a,a+3);
    for(int i=0;i<=2;i++){cout<<a[i];
        if(i!=2)cout<<" ";}
    cout<<"\n";
    
    
    return 0;
}

Measured memory_bytes: 3092
N = int(input())

A = [None for _ in range(N)]
for i in range(N):
    A[i] = list(map(int, input().split()))

#ワーシャルフロイド法で条件を満たすものがあるか確認
for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()

ans = 0
for i in range(N-1):
    for j in range(i,N):
        is_edge = True
        for k in range(N):
            if i == k or j == k:
                continue
            if A[i][j] == A[i][k] + A[k][j]: # A[i][j]はiとjのノードを直接結ぶものではない
                is_edge = False
        if is_edge:
            ans += A[i][j]

print(ans) 

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n,m,q;cin>>n>>m>>q;
    vvi g(n);
    rep(i,m){
        int l,r;
        cin>>l>>r;
        l--;r--;
        g[l].PB(r);
    }
    rep(i,n){
        sort(all(g[i]));
    }
    rep(i,q){
        int P,Q;
        cin>>P>>Q;
        P--;Q--;
        int cnt=0;
        for(int j=P;j<=Q;++j){
            cnt+=upper_bound(all(g[j]),Q)-g[j].begin();
        }
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 5040
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 1e9;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;
    string ans;
    REP(i, dx) ans += 'R';
    REP(i, dy) ans += 'U';
    REP(i, dx) ans += 'L';
    REP(i, dy) ans += 'D';
    ans += 'D';
    REP(i, dx+1) ans += 'R';
    REP(i, dy+1) ans += 'U';
    ans += 'L';
    ans += 'U';
    REP(i, dx+1) ans += 'L';
    REP(i, dy+1) ans += 'D';
    ans += 'R';
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 110;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int m;
std::vector<int> v[maxn];
ll path[maxn];
void dfs(int x, int pre, ll num)
{
	path[x] = num;
	for (auto y : v[x])
	{
		if (y == pre)
		{
			continue;
		}
		dfs(y, x, num | (1ll << y));
	}
}
ll info[maxn];

int main()
{
	//freopen("D:\\code\\text\\input.txt","r",stdin);
	//freopen("D:\\code\\text\\output.txt","w",stdout);
	n = readint();
	repd(i, 1, n - 1)
	{
		int x = readint();
		int y = readint();
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1, 0, 0ll);
	m = readint();
	repd(i, 0, m - 1)
	{
		int x = readint();
		int y = readint();
		info[i] = (path[x] ^ path[y]);
	}
	int maxstate = (1 << m) - 1;
	ll ans = 0ll;
	repd(i, 0, maxstate)
	{
		ll num = 0ll;
		int cnt = 0;
		repd(j, 0, m - 1)
		{
			if (i & (1 << j)) {
				cnt++;
				num |= info[j];
			}
		}
		int free = n - 1 - __builtin_popcountll(num);
		ans += poww(2ll, free) * (cnt & 1 ? -1ll : 1ll);
	}
	printf("%lld\n", ans);
	return 0;
}




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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && a != c)
        OP("Yes");
    else if (a == c && a != b)
        OP("Yes");
    else if (b == c && b != a)
        OP("Yes");
    else
        OP("No");

    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = str(input())
dic = {'r':p, 's':r, 'p':s}
b = [1]*n
ans = 0
for i in range(n):
    if i > (k-1) and t[i]==t[i-k]:
        b[i] -= b[i-k]
    ans += dic[t[i]] if b[i]==1 else 0

print(ans)

Measured memory_bytes: 40816
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

void print(string A[],int n)
{
    for(int i=0;i<n;i++){
        if(i>0) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}
bool isCheck(string A[],string B[],int n)
{
    for(int i=0;i<n;i++){
        if(A[i] != B[i])
            return false;
    }
    return true;
}
void bublesort(string A[],int n)
{
    bool flg = true;
    for(int i=0;flg;i++){
        flg = false;
        for(int j=n-1;j>=i+1;j--){
            if(A[j][1] < A[j-1][1]){
                swap(A[j],A[j-1]);
                flg = true;
            }
        }
    }
}

void selectsort(string A[],int n)
{
    for(int i=0;i<n;i++){
        int mini = i;
        for(int j=i;j<n;j++){
            if(A[j][1] < A[mini][1])
                mini = j;
        }
        swap(A[i],A[mini]);
    }
}

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

    bublesort(A,n);
    print(A,n);
    cout << "Stable" << endl;
    selectsort(B,n);
    print(B,n);
    if(isCheck(A,B,n)){
        cout << "Stable" << endl;
    }
    else{
        cout << "Not stable" << endl;
    }
}


Measured memory_bytes: 3172
#include<stdio.h>
#include<math.h>

#define MAX_DATA_COUNT (1000)

int main(void)
{
        int student_count, student_index;
        double data[MAX_DATA_COUNT], standard, variance, variance_total, average, total;

        while(1){

                scanf("%d", &student_count);
                if(student_count == 0){
                        break;
                }

                total = 0;
                variance_total = 0;

                for(student_index=0; student_index < student_count; student_index++){
                        scanf("%lf", &data[student_index]);
                        total += data[student_index];
                }

                average = total / student_count;

                for(student_index=0; student_index < student_count; student_index++){
                        variance_total += pow(data[student_index] - average, 2);
                }

                variance = variance_total / student_count;
                standard = sqrt(variance);

                printf("%lf\n", standard);
        }


        return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  int cnt = 0;
  for(int i=0; i<N; i++){
    if(vec.at(i) == cnt+1){
      cnt++;
    }
  }
  
  if(cnt == 0){
    cout << -1 << endl;
  }
  else{
    cout << N - cnt << endl;
  }
  
}
  

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int x; std::cin >> x;
  if (x < 0) x *= -1;
  int val = 0, ans = 1;
  for (; val < x; ans++) {
    val += ans;
  }
  std::cout << ans - 1 << "\n";
}


Measured memory_bytes: 384
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

#define YES "Yes"
#define NO "No"

int h, w;
int cnt[256];

int main(int argc, char **argv) {
	cin >> h >> w;
	CLEAR(cnt);
	REP(i, h) {
		string s;
		cin >> s;
		REP(j, w) ++cnt[s[j]];
	}
	int c1 = 0, c2 = 0;
	REP(i, 256) {
		if (cnt[i] % 2 != 0) {
			++c1;
			--cnt[i];
		}
		if (cnt[i] % 4 != 0) {
			c2 += 2;
			cnt[i] -= 2;
		}
	}
	if (w % 2 == 0 && h % 2 == 0) {
		cout << (c1 == 0 && c2 == 0 ? YES : NO) << endl;
	}
	else if (w % 2 != 0 && h % 2 != 0) {
		cout << (c1 == 1 && c2 <= w + h - 2 ? YES : NO) << endl;
	}
	else if (w % 2 == 0) {
		cout << (c1 == 0 && c2 <= w ? YES : NO) << endl;
	}
	else {
		cout << (c1 == 0 && c2 <= h ? YES : NO) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL)

typedef long long ll;

using namespace std;

int main()
{
	FastIO;
	ll d, n;
	cin >> d >> n;

	if(n == 100){
		n++;
		while(d--) n *= 100;
	}
	else
		while(d--) n *= 100;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;

const int INF = 2000000000;
const double pi = 3.1415926;
const int base = 1000000007;

int n, r;


int main()
{
    //ifstream cin ("sysadmin.in");
    //ofstream cout ("sysadmin.out");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(20);
    cin >> n >> r;
    cout << r + 100 * max(0, 10 - n);
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import io
import sys
import math

def solve(n, a_lst,b_lst,c_lst):
    # implement process
    pre_a = -float('inf')
    satisfaction = 0
    for a in a_lst:
        a -= 1
        satisfaction += b_lst[a]
        if pre_a +1 == a:
            satisfaction += c_lst[a-1]
        pre_a = a
    
    return satisfaction
    
def main():
    # input
    n = int(input())
    a_lst = list(map(int, input().split()))
    b_lst = list(map(int, input().split()))
    c_lst = list(map(int, input().split()))

    # process
    ans = str( solve(n, a_lst,b_lst,c_lst ) )
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
2
1 2
50 50
50
"""
_EXPECTED = """\
150
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Measured memory_bytes: 9172
N = int(input())
*A, = map(int,input().split())
c = [0]*3
for a in A:
    if a%2:c[0]+=1
    elif a%4:c[1]+=1
    else:c[2]+=1
if c[1]==1: c[0:2] = [c[0]+1,0]
if c[1]==0:
    ans = c[2]>0 and c[0]<=c[2]+1
else:
    ans = c[0]<=c[2]
print("Yes" if ans else "No")

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    map<int,int> m;
    vector<int> l;
    rep(i,N){
        if(m[A[i]]==0){
            l.push_back(A[i]);
        }
        m[A[i]]++;
    }
    if(l.size()>3){
        cout << "No" << endl;
        return 0;
    }
    else if(l.size()==1){
        if(m[0]!=0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    else if(l.size()==2){
        if(N%3==0&&m[0]==N/3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    else if(l.size()==3){
        if(N%3==0&&m[l[0]]==N/3&&m[l[1]]==N/3&&m[l[2]]==N/3){
            int a = l[0]^l[1]^l[2];
            if(a==0){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 4472