akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


signed main(void) 
{
    ll a, b, c;
    cin >>a >>b >>c;
    ll r = 0;
    bool po = false;
    while(true) {
        if (po == false && c > 0) {
            c--;
            r++;
            po = true;
        }else if (b > 0) {
            b--;
            r++;
            po = false;
        } else if (a > 0) {
            a--;
            po = false;
        } else break;
            
        
    }
    mes(r);
  	re0;
   
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int k = sc.nextInt();
    char[][] map = new char[h][w];
    for(int i = 0; i < h; i++){
      String line = sc.next();
      for(int j = 0; j < w; j++){
        map[i][j] = line.charAt(j);
      }
    }
    int answer = 0;

    for(int sh = 0; sh < (1 << h); sh++) {
      for (int sw = 0; sw < (1 << w); sw++) {
        int count = 0;
        for(int idxh = 0; idxh < h; idxh++){
          if((1 & (sh >> idxh)) == 1) continue;
          for(int idxw = 0; idxw < w; idxw++){
            if((1 & (sw >> idxw)) == 1) continue;
            if(map[idxh][idxw] == '#') count++;
          }
        }
        if(count == k){
          answer++;
        }
      }
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 36236
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  [x, a, b] <- map readInt . BS.words <$> BS.getLine
  putStrLn $ solve x a b

solve :: Int -> Int -> Int -> String
solve x a b = if abs (x - a) < abs (x - b) then "A" else "B"

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt


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


//SHORTCUTS

#define ll long long
#define endl '\n'
#define i1(a) cin>>a
#define i2(a,b) cin>>a>>b
#define i3(a,b,c) cin>>a>>b>>c
#define o1(a) cout<<a<<endl
#define o2(a,b) cout<<a<<" "<<b<<endl
#define o3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define f(i,a,b) for(int i = a;i<b;i++)
#define fe(i,a,b) for(int i = a;i<=b;i++)
#define fi(i,a,b) for(i=a;i<b;i++)
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair


// DEBUG CODE & FAST OUTPUT

#define printv(a) for (int i = 0; i < a.size(); i++) cout << a[i] << ' ';
#define printvl(a) for (int i = 0; i < a.size(); i++) cout << a[i] << endl;
#define printa(a, n) for (int i = 0; i< n; i++) cout << a[i] << ' ';
#define printal(a, n) for (int i = 0; i < n; i++) cout << a[i] << endl;


//DATA STRUCTURES

#define pq priority_queue
#define ms multiset
// #define y0 _y0_
// #define y1 _y1_
// #define div divi

typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;


//IMP CONSTANT
const int mod = 1e9 + 7, inf = 1e9 + 7;
const ll infll = 1e18 + 7;
bool google_contest = false;

//MODULAR OPERATIONS
ll myadd(ll a,ll b){
    ll ans = a+b;
    ans-= ans>=mod ? mod : 0;
    return ans; 
}
ll mysub(ll a, ll b){
    return (a-b+mod)%mod;
}
ll mymul(ll a,ll b){
    return (a*b)%mod;
}
ll mypow(ll a, ll b){
    ll ans = 1;
    while(b>0)
        if(b&1) ans = mymul(ans,a),b--;
        else a = mymul(a,a),b >>= 1;
    return ans;
}
ll nCr(ll n,ll r){
    if(r==0)return 1;
    if(r==1)return n;
    if(n==0)return 0;
    return mymul(n,mymul(nCr(n-1,r-1),mypow(r,mod-2)));
}




const int dx[4] = {1, -1, 0,  0};
const int dy[4] = {0, 0,  1, -1};
//    /\    |  |\  /|                      
//   /__\   |  | \/ |           
//  /    \  |  |    | 



int main(){

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

int t,tt;
t=1;
// i1(t);
if(google_contest)tt=1;

while(t--){

int x;
i1(x);

int l = (x*360)/__gcd(x,360);
int ans = l/x;
o1(ans);


if(google_contest){
    cout<<"Case "<<tt++<<": ";
}
}

return 0;   
}


//    /\    |  |\  /|                      
//   /__\   |  | \/ |           
//  /    \  |  |    |   OVER!!!!


Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long;

int main() {
	int N;
	cin >> N;
	int K;
	cin >> K;
	int total = 1;

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

		if (total <= K) {

			total *= 2;
		}

		else {

			total += K;

		}

	}


	cout << total << endl;

}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define MAX_N 1000
#define MAX_V 1000
#define INF 1e9
using namespace std;
int N,K;
bool can[MAX_N][MAX_N]; //can[i][j]:=???????????\??????i?????????j??????????????????
struct edge{int to, cap, rev;};
vector<edge> G[MAX_V]; //??°???????????£??\?????????
bool used[MAX_V];      //DFS??§?????§??????????????????????????°

//from??????to??????????????????cap???????????°?????????????????????
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});  
}

//?¢?????????????DFS??§??¢???
int dfs(int v,int t,int f){
  if(v == t)return f;
  used[v]=true;
  for(int i=0; i<G[v].size() ;i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to ,t , min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

//s??????t???????????§???????±???????
int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)return flow;
    flow += f;
  }
}


int Biparite_Matching(){
  //0??????N-1: ???????????\???????????????????????????
  //N??????N+K-1: ???????????????????????????
  int s = N+K, t = s+1;
  
  //s??¨???????????\??????????????¶
  for(int i=0; i<N; i++) add_edge(s,i,1);
  
  //????????¨t?????????
  for(int i=0; i<K; i++) add_edge(N+i,t,1);
  
  //???????????\????????¨??????????????¶
  for(int i=0;i<N;i++)
    for(int j=0;j<K;j++)
      if(can[i][j]) add_edge(i, N+j , 1);

  return max_flow(s,t);
}

int main(){
  int E;
  cin>>N>>K>>E;
  for(int i=0; i<E ;i++){
    int x,y;
    cin>>x>>y;
    can[x][y]=1;
  }
  cout<<Biparite_Matching()<<endl;
}

Measured memory_bytes: 3460
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<set>
using namespace std;
#define PI acos(-1.0)
typedef long long ll;
typedef pair<int,int> P;
const int maxn=1e5+100,maxm=1e5+100,inf=0x3f3f3f3f,mod=1e9+7;
const ll INF=1e13+7;
priority_queue<P,vector<P>,greater<P> >q;
struct edge
{
    int from,to;
    int cost;
};
int main()
{
    ll n,a,b,c,d;
    scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
    for(int i=0;i<n;i++)
    {
        ///[a+i*c,a+i*d],[(n-1-i)*c,(n-1-i)*d];
        if(((a+i*c)-(n-1-i)*d)<=b&&((a+i*d)-((n-1-i)*c))>=b)
        {
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int N;
//エラトステネスの篩
bool is_prime[ 1000000 ];
vector<int> P;
void Eratosthenes( const int N )
{
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//初期化
    }    
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
}
int main()
{
  	int aaa;
    cin >>aaa;
    
    Eratosthenes(1000000);
    for(int i=0;i<1000000;i++){
      if(P.at(i)==aaa){
		cout<<aaa<<endl;
        break;
      }
      if(P.at(i)>aaa){
		cout<<P.at(i)<<endl;
        break;
      }
    } 
}

Measured memory_bytes: 1916
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int h,w,d; cin>>h>>w>>d;
  int n = h*w, x[n], y[n];
  rep(i,h){
    rep(j,w){
      int a; cin>>a;
      x[a] = i; y[a] = j;
    }
  }
  int c[n+1]; CLR(c);
  for(int i=d+1; i<=n; i++){
    c[i] = c[i-d] + abs(x[i]-x[i-d]) + abs(y[i]-y[i-d]);
  }
  int q; cin>>q;
  rep(i,q){
    int l,r; cin>>l>>r;
    cout << c[r]-c[l] << endl;
  }
  return 0;
}


Measured memory_bytes: 2176
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int N =scan.nextInt();
		int[] L=new int[2*N];

		for(int i =0;i<2*N;i++){
			L[i]=scan.nextInt();
		}
		Arrays.sort(L);
		int ans=0;
		for(int i=0;i<N;i++){
			ans+=L[2*i];
		}
		System.out.println(ans);
	}

}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 24;

#define F first
#define S second

int main(void){
    for(int n, m, p, a, b; cin >> n >> m >> p >> a >> b, n;){
        a--, b--;

        vi t(n); for(auto && tt : t) cin >> tt;

        // (先，距離)
        vector<vector<pii>> edge(m);
        rep(i, p){
            int x, y, z; cin >> x >> y >> z; x--, y--;

            edge[x].pb(mp(y, z));
            edge[y].pb(mp(x, z));
        }

        vector<vector<double>> min_dist(m, vector<double>(1 << n, (double)inf));

        // (コスト，(都市，馬車チケのパターン))
        typedef pair<double, pii> State;
        priority_queue<State, vector<State>, greater<State>> q;
        q.push(mp(0.0, mp(a, (1 << n) - 1)));

        while(!q.empty()){
            double cur_cost = q.top().F;
            int cur_v = q.top().S.F;
            int cur_t = q.top().S.S;
            q.pop();

            if(min_dist[cur_v][cur_t] < inf - eps) continue;

            min_dist[cur_v][cur_t] = cur_cost;

            rep(i, n){
                if(((cur_t >> i) & 1) == 0) continue;

                int next_t = (cur_t & ~(1 << i));
                for(auto && ee : edge[cur_v]){
                    int next_v = ee.F;
                    if(min_dist[next_v][next_t] < inf - eps) continue;

                    double next_cost = cur_cost + (double)ee.S / t[i];
                    q.push(mp(next_cost, mp(next_v, next_t)));
                }
            }
        }

        double res = *min_element(all(min_dist[b]));
        if(res < inf - eps) printf("%.6f\n", res);
        else cout << "Impossible" << endl;
    }

	return 0;
}

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

int main() {
    int x, ans = 1;
    cin >> x;
    vector<int> v;
    v.push_back(1);
    for(int i = 2; i <= x; i++) {
        for(int j = 2; j <= 10; j++) {
            if(pow(i, j) <= x) v.push_back(pow(i, j));
            else break;
        }
    }
    sort(v.begin(), v.end());
    cout << v.back() << '\n';

    return 0;
}


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

int main() {
  int N,B = 1000;
  cin >> N;  
  
  for (int i = 0 ; i < N ; i++) {
    int x,A;
    cin >> x;
    
    for (int j = 0 ; ; j++) {
      if (x % 2 == 1) {
        A = j;
        break;
      }
      else
        x /= 2;
    }
    if (A < B)
      B = A;
  }
  cout << B << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#define PI 3.14159265358979323846
using namespace std;

int main()
{
	double r;	
	cin>>r;	
	cout<<setiosflags(ios::fixed)<<setprecision(6)<<PI*r*r<<" "<<2*PI*r<<endl;
	return 0;
}


Measured memory_bytes: 3288
n = int(input())
a = list(map(int, input().split()))
if a.count(1) == 0:
    print(-1)
    exit()
cnt = 1
for i in range(a.index(1), n):
    if a[i] == cnt + 1:
        cnt += 1
        
print(len(a) - cnt)

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

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

    ll A, B, N;
    cin >> A >> B >> N;

    ll x = min(B-1, N);
    ll a = (A*x/B) - A*(x/B);
    cout << a << endl;
}


Measured memory_bytes: 3648
s = []
while True:
    try:
        s.append(input())
    except:
        break

for e in range(len(s)):
    st = list(map(str,s[e]))
    t = []
    for c in st:
        t.append(ord(c))    

    for i in range(26):
        string = ''
        for j in range(len(st)):
            if t[j] >= 97 and 122 >= t[j]:
                l = 97 + ((t[j] - 97 + i) % 26)
                string += chr(l)
            
            else:
                string += chr(t[j])
        if 'this' in string or 'the' in string or 'that' in string:
            print(string)

Measured memory_bytes: 7360
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
 
#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
typedef long long ll;
using namespace std;

int n,m,a,b,ev,od,g[100000];
vector<int>v[100000];

int dfs(int x){
	if(g[x]==1)ev++;
	else od++;
	lp(v[x].size()){
		if(g[v[x][i]]==g[x])
			return -1;
		else if(g[v[x][i]]==0) {
			g[v[x][i]]=-g[x];
			if(dfs(v[x][i])==-1)
				return -1;
		}
	}
	return 0;
}

int main(){
	cin>>n>>m;
	lp(m){
		cin>>a>>b;
		v[a-1].push_back(b-1);
		v[b-1].push_back(a-1);
	}
	lp(n)
		g[i]=0;
	g[0]=1;
	od=0;
	ev=0;
	if(dfs(0)==-1){
		cout<<ll(n)*ll(n-1)/2-m<<endl;
	}
	else {
		cout<<ll(od)*ll(ev)-m<<endl;
	}
	return 0;
}

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

int main() {
    int n, v[55], c[55];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < n; i++) cin >> c[i];

    int ans[55] = {0};
    for (int i = 0; i < n; i++) ans[i] = v[i] - c[i];
    
    sort(ans, ans + n);
    int mx = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (ans[i] >= 0) mx += ans[i];
    }

    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
   
    #endif
}

int dp[200005][2];
void solve()
{
  
  string s;
  cin >> s;
  
  int n = sz(s),an=-1;

  
  if(s[0]=='D')dp[0][1]=1,an=1;
  else if(s[0]=='?')s[0]='D',dp[0][1]=1;  
  forf(i,1,n)
  {
    if(s[i]=='P')
    {
       dp[i][0] = max(dp[i-1][0],dp[i-1][1]);
       an = max(an,dp[i][0]);

    }else if(s[i]=='D')
    {
       if(s[i-1]=='P') dp[i][1] = dp[i-1][0]+2;
       else if(s[i-1]=='D') dp[i][1] = dp[i-1][1]+1;
       else dp[i][1] = max(dp[i-1][0]+2,dp[i-1][1]+1); 
       
       an = max(dp[i][1],an);
    }else
    {
      dp[i][0] = max(dp[i-1][0],dp[i-1][1]);
      dp[i][1] = max(dp[i-1][0]+2,dp[i-1][1]+1);
      if(dp[i][0] > dp[i][1]) s[i]='P';
      else s[i]='D';
    }
  }

  cout<<s;

}

int32_t main()
{
  pr_init();
  fastio;
  solve();

 }
      

Measured memory_bytes: 6900
import heapq
from itertools import accumulate

v, e = map(int, input().split())
g = [[] for _ in range(v)]
for i in range(e):
    s, t, d = map(int, input().split())
    g[s].append((d, t))#(重み, 次の頂点)
    g[t].append((d, s))#(重み, 次の頂点)

visitedv = [False] * v
visitedv[0] = True
#visitede = []
visitede = 0
candidate = []
for i in g[0]:
    heapq.heappush(candidate, i)
while len(candidate):
    #まだ使われていない頂点から最小のものを探す
    minedge = heapq.heappop(candidate)#(重み, 頂点)
    if visitedv[minedge[1]]:
        continue
    c = minedge[1]
    visitedv[c] = True
    #visitede.append(minedge[0])
    visitede += minedge[0]
    for i in g[c]:
        if not visitedv[i[1]]:
            heapq.heappush(candidate, i)

#print(list(accumulate(visitede))[-1])
print(visitede)


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

using namespace std;

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

  map<int, int> m;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    m[a]++;
  }

  int sum = 0;
  for( auto i = m.begin(); i != m.end() ; ++i ) {
    if(i->first == i->second) {
      continue;
    }
    if(i->first < i->second) {
      sum += i->second - i->first;
    } else {
      sum += i->second;
    }
  }

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;
  int n=S.size();
  if(S=="AKIHABARA"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="KIHABARA"){
    cout << "Yes" << endl;
    return 0;
  }
  else if(S=="AKIHBARA"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="AKIHABRA"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="AKIHABAR"){
    cout << "YES"<< endl;
    return 0;
  }
  else if(S=="KIHBARA"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="KIHABRA"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="KIHABAR"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="AKIHBRA"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="AKIHBAR"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="AKIHABR"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="AKIHBR"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="KIHABR"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="KIHBAR"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="KIHBRA"){
    cout << "YES" << endl;
    return 0;
  }
  else if(S=="KIHBR"){
    cout << "YES" << endl;
    return 0;
  }
  else{
    cout << "NO" << endl;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

S = list(S)
T = list(T)

result = len(T)
x = 0

for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] != T[j]:
            x += 1
    if result > x:
        result = x
    x = 0

print(result)


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

int main(){
  int N,M,ans=0;
  cin>>N>>M;
  Graph G(N);
  REP(i,M){
    int X,Y,Z;
    cin>>X>>Y>>Z;
    X--,Y--;
    G[X].PB(Y);
    G[Y].PB(X);
  }
  
  bool SEEN[N];
  REP(i,N) SEEN[i]=false;
  REP(i,N){
    if(SEEN[i]) continue;
    ans++;
    
    queue<int> Q;
    Q.push(i);
    SEEN[i]=true;
    
    while(!Q.empty()){
      int v=Q.front();
      Q.pop();
      FORE(nv,G[v]){
        if(SEEN[nv]) continue;
        SEEN[nv]=true;
        Q.push(nv);
      }
    }
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 6648
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n,m,x,y,a,b;
	cin>>n>>m>>x>>y;
	cin>>a;
	while(--n){
		int c;
		cin>>c;
		a=max(a,c);
	}
	cin>>b;
	while(--m){
		int c;
		cin>>c;
		b=min(b,c);
	}
	int f=0;
	for(int i=x+1;i<=y;i++){
		if(i>a &&i<=b){
			f=1;
			break;
		}
	}
	if(f==1)
		cout<<"No War"<<endl;
	else 
		cout<<"War"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N;cin>>N;

    cout<<N*800 - (N/15)*200<<endl;
    return 0;
}


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

int main() {
  int A, B, K;
  int j = 0;
  int hokanko[101] = {0};
  
  cin >> A >> B >> K;
  
  for (int i = 1; i < 101; ++i) {
    if (A % i == 0 && B % i == 0) {
      hokanko[j] = i;
      j++;
    }
  }
  
  sort(hokanko, hokanko + 100, greater<int>());

  cout << hokanko[K - 1] << endl;  

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n;
long long int a;
bool ok = true;

int main()
{
    cin >> n;
    while (n--)
    {
        cin >> a;
        if (a % 2 == 1)
        ok = false;
    }
    if (ok)
        cout << "second";
    else
        cout << "first";
}


Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    print(s[0]+str(len(s)-2)+s[-1])
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i=0;i<(n); ++i)
#define log(i,n) log(n)/log(i);
using namespace std;
typedef long long ll;


int main()
{
	ll n;
	cin >> n;
	cout << pow(n, 3) << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
	int A, P;
	int murakawarie;
	if (scanf("%d%d", &A, &P) != 2) return 1;
	murakawarie = 3 * A + P;
	printf("%d\n", murakawarie / 2);
	return 0;
}


Measured memory_bytes: 128
###==================================================
### import
import bisect
from collections import Counter, deque, defaultdict
from copy import deepcopy
from fractions import gcd
from functools import reduce
from heapq import heappush, heappop
import itertools
import math
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout

### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
###---------------------------------------------------


a, b = iInM()
ans = math.ceil((a + b) / 2)
print(ans)



Measured memory_bytes: 77448
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
 
int main() {
  ll n,count=1;
  cin>>n;
  ll ans=0;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  a.push_back(0);
  rep(i,n+1){
    if(a[i]==1){
      count++;
      if(i==n+1){
        ans=count;
      }
    }
    else {
      ans=max(ans,count);
    
    
    
      count=1;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3144
#include "bits/stdc++.h"
#define hhh printf("hhh\n")
#define see(x) (cerr<<(#x)<<'='<<(x)<<endl)
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 1e6+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

int N, s, t;
int head[maxn], to[maxn], nxt[maxn], tot;
int ans=0, mx[maxn], dp[maxn];

void add_edge(int u, int v) {
    ++tot; to[tot]=v; nxt[tot]=head[u]; head[u]=tot;
    ++tot; to[tot]=u; nxt[tot]=head[v]; head[v]=tot;
}

int dfs(int u, int f, int d) {
    dp[u]=d; mx[u]=d; int cost=(u==t?0:inf);
    for(int i=head[u]; i; i=nxt[i]) {
        int v=to[i]; if(v==f) continue;
        cost=min(cost,dfs(v,u,d+1)); mx[u]=max(mx[u],mx[v]);
    }
    if(dp[u]>cost) ans=max(ans,mx[u]-1);//, see(dp[u]), see(cost), see(mx[u]);
    return cost+1;
}

int main() {
    N=read(), t=read(), s=read();
    for(int i=1; i<N; ++i) add_edge(read(),read());
    dfs(s,0,0);
    cout<<ans<<endl;
}

Measured memory_bytes: 21376
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
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; }
//#define int long long

void solve() {
	int n; cin >> n;
    deque<int> a[1010];
    rep(i, n) {
        rep(j, n - 1) {
            int x; cin >> x; --x;
            a[i].push_back(x); 
        }
    }
    //探索対象を減らす
    //可能性のあるものしか調べない
    queue<int> que;
    rep(i, n) {
        que.push(i);
    }
    int cnt = 0;
    while(que.size()) {
        queue<int> que2;
        vector<bool> used(n, 0);
        cnt ++;
        while(que.size()) {
            int x = que.front(); que.pop();
            if(a[x].empty()) continue;
            int y = a[x].front();
            if(!used[x] && !used[y] && a[y].size() && a[y].front() == x) {
                a[x].pop_front(); a[y].pop_front();
                used[x] = 1, used[y] = 1;
                if(a[x].size()) que2.push(x);
                if(a[y].size()) que2.push(y);
            }
        }
        swap(que2, que);
    }
    bool check = true;
    rep(i, n) {
        if(a[i].size()) check = false;
    }
    if(!check) cout << -1 << endl;
    else cout << cnt << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    string S;
    unordered_map <string, long > map;

    for(int i=0; i<N; i++){
        cin >> S;
        sort(S.begin(),S.end());
        map[S] += 1;
    }

    long ans=0;

    for(auto x:map){
        long tmp = x.second;
        ans += tmp*(tmp-1)/2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10660
fun main(args: Array<String>) {
    val (n, d) = readInputLine().split(" ").map { it.toInt() }
    
    println(n / (d * 2 + 1) + if (n % (d * 2 + 1) == 0) 0 else 1)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37740
import sys
bingo = [list(map(int, input().split())) for i in range(3)]
N = int(input())

for i in range(N):
    b = int(input())
    for j in range(len(bingo)):
      for k in range(len(bingo[j])):
            if b == bingo[j][k]:
                bingo[j][k] = 0

for i in range(len(bingo)):
    if sum(bingo[i]) == 0:
        print('Yes')
        sys.exit()
    if (bingo[0][i] + bingo[1][i] + bingo[2][i]) == 0:
        print('Yes')
        sys.exit()

for i in [0]:
  if (bingo[i][i] + bingo[i+1][i+1] + bingo[i+2][i+2]) == 0:
    print('Yes')
    sys.exit()
  if (bingo[i][i+2] + bingo[i+1][i+1] + bingo[i+2][i]) == 0:
    print('Yes')
    sys.exit()
  else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[52];
int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll ans=0;
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			if(i==j){
				continue;
			}
			ans+=a[i]*a[j];
		}
	}
	cout <<ans/2;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

typedef long long LL;

int main() {
	LL n, res = 2;
	cin >> n;
	if (n == 2) res = 1;
	for (LL k = 2, i = n; k * k <= n; k++, i = n) {
		while (i >= k) i % k ? i %= k : i /= k;
		if (i == 1) res++;
		if ((n - 1) % k == 0 && k * k != (n - 1)) res++;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

import itertools

# DEBUG = True
DEBUG = False

N = int(readline())

class Interactive:
    def __init__(self):
        self.ques_cnt = 0
        self.create_data()
        
    def create_data(self):
        import random
        self.upper = ''.join(random.choice('.#') for _ in range(N))
        self.lower = ''.join(random.choice('.#') for _ in range(N))
        print('created upper:', self.upper)
        print('created lower:', self.lower)
        
    def resp_ques(self, *args):
        self.ques_cnt += 1
        if len(args) != 1:
            raise ValueError('不正な質問', args)
        S,T = args[0].split()
        L = len(S)
        for i in range(N):
            if S == self.lower[i:i+L] and T == self.upper[i:i+L]:
                if len(S) == N:
                    return 'end\n'
                else:
                    return 'T\n'
        return 'F\n'
            
    def resp_ans(self, *args):
        pass
            
if DEBUG:
    interactive = Interactive()
    
def question(*args, offset=None):
    if offset is None:
        print(*args, flush=True)
    else:
        print(offset, *args, flush=True)
    if DEBUG:
        resp = interactive.resp_ques(*args)
        print(resp)
        return resp
    else:
        return readline()
    
def answer(*args, offset=None):
    if offset is None:
        print(*args, flush=True)
    else:
        print(offset, *args, flush=True)
    if DEBUG:
        interactive.resp_ans(*args)
    else:
        exit()

col_patterns = tuple(itertools.product('.#', repeat=2))

def find_some_col():
    for S,T in col_patterns:
        resp = question(S + '\n' + T).rstrip()
        if resp == 'T':
            return S,T
        if resp == 'end':
            exit()

def extend_left(S,T):
    while True:
        flag = False
        for s,t in col_patterns:
            resp = question(s + S + '\n' + t + T).rstrip()
            if resp == 'T':
                flag = True
                S = s + S
                T = t + T
                break
            elif resp == 'end':
                exit()
        if not flag:
            return S,T

def extend_right(S,T):
    while True:
        flag = False
        for s,t in col_patterns:
            resp = question(S + s + '\n' + T + t).rstrip()
            if resp == 'T':
                flag = True
                S = S + s
                T = T + t
                break
            elif resp == 'end':
                exit()
        if not flag:
            return S,T

S,T = find_some_col()
S,T = extend_left(S,T)
S,T = extend_right(S,T)

Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int dp[1001][1001]; // minimum edit distance
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s1;
    string s2;

    cin >> s1;
    cin >> s2;

    // init. dp table
    for(int i=0; i<=s1.length(); i++){
        dp[i][0] = i;
    }
    for(int j=0; j<=s2.length(); j++){
        dp[0][j] = j;
    }

    for(int i=1; i<=s1.length(); i++){
        for(int j=1; j<=s2.length(); j++){
            int RepCost = s1[i-1] == s2[j-1] ? 0:1;
            dp[i][j] = min(min(dp[i][j-1] + 1,  // insertion
                           dp[i-1][j] + 1),  // deletion
                           dp[i-1][j-1] + RepCost  // replacement
                           );
        }
    }

/*
    for(int i=0; i<=s1.length(); i++){
        for(int j=0; j<=s2.length(); j++){
            cout << dp[i][j] << " ";
        }
        cout << "\n";
    }
*/
    cout << dp[s1.length()][s2.length()] << "\n";

    return 0;

}

Measured memory_bytes: 7132
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

int main()
{
    boost;
    ll n,i,j,x;
    cin>>n;
    ll a[n];
    rep(i,0,n-1) cin>>a[i];
    x=1;
    ll ans=0;
    rep(i,0,n-1){
        if(a[i]==x){
            x++;
        }
        else{
            ans++;
        }
    }
    if(x==1){
        cout<<"-1";
    }
    else
    cout<<ans;
}

Measured memory_bytes: 1792
//    .------------------------------------------------------------.
//    |   _  __   ___    ___    ___   _  _    ___     _     _  _   |
//    |  | |/ /  / _ \  |   \  |_ _| | \| |  / __|   /_\   | \| |  |
//    |  | ' <  | (_) | | |) |  | |  | .` | | (_ |  / _ \  | .` |  |
//    |  |_|\_\  \___/  |___/  |___| |_|\_|  \___| /_/ \_\ |_|\_|  |
//    |             ___    ___     _     _  _    ___               |
//    |            / _ \  | _ \   /_\   | \| |  / __|              |
//    |           | (_) | |   /  / _ \  | .` | | (_ |              |
//    |            \___/  |_|_\ /_/ \_\ |_|\_|  \___|              |
//    |                 ___   ___    ___    ___                    |
//    |                | _ ) | __|  / __|  / _ \                   |
//    |                | _ \ | _|  | (_ | | (_) |                  |
//    |                |___/ |___|  \___|  \___/                   |
//    |                                                            |
//    |------------------------------------------------------------|
//    |                      .------------.                        |
//    |                      | KerakTelor |                        |
//    |                      |------------|                        |
//    |                      | 2019-10-08 |                        |
//    |                      '------------'                        |
//    '------------------------------------------------------------'

#include <bits/stdc++.h>

#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("tune=native")

#define vec vector
#define prq priority_queue
#define fi first
#define se second

using namespace std;

using ll=long long;
using ld=long double;

//    .-----------------------------------------.
//    |        ___   _   _    ___   ___         | 
//    |       | _ ) | | | |  / __| / __|        | 
//    |       | _ \ | |_| | | (_ | \__ \        | 
//    |       |___/  \___/   \___| |___/        | 
//    |  ___   ___    ___    ___    _  _   ___  | 
//    | | _ ) | __|  / __|  / _ \  | \| | | __| |
//    | | _ \ | _|  | (_ | | (_) | | .` | | _|  | 
//    | |___/ |___|  \___|  \___/  |_|\_| |___| |
//    |                                         | 
//    '-----------------------------------------'

vec<ld> c;
vec<vec<ld>> dp;

ld solve(int n,int p)
{
    if(!n)
        return 1;
    if(p<0)
        return 0;
    if(dp[n][p]>=0)
        return dp[n][p];
    return dp[n][p]=c[p]*solve(n-1,p-1)+(1-c[p])*solve(n,p-1);
}

int main()
{
    int n;
    scanf("%d",&n);
    c.assign(n,0);
    dp.assign((n>>1)+2,vec<ld>(n,-1));
    for(auto &i:c)
        scanf("%Lf",&i);
    printf("%.12Lf\n",solve((n>>1)+1,n-1));
}



Measured memory_bytes: 70912
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    cin>>n>>m;
    vector<vector<ll> > v(m);
    for(ll i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        if(a>m){continue;}
        v[a-1].pb(b);
    }
    priority_queue<ll> q;
    ll ans=0;
    for(ll i=0;i<m;i++)
    {
        for(auto x:v[i])
        {
            q.push(x);
        }
        if(!q.empty())
        {
            ans+=q.top();
            q.pop();
        }
    }
    cout<<ans;
    return 0;
}



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

int main () {
  int n, a, b;
  int ans = 0;
  int sum;
  int x;

  cin >> n >> a >> b;

  for (int i=1; i<=n; i++) {
    x = i;
    sum = 0;
    while (true) {
      sum += x % 10;
      x /= 10;
      if (x == 0) break;
    }

    if (a <= sum && sum <= b) ans += i;
  }

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

Measured memory_bytes: 256
n=int(input())
ss=[input() for _ in range(n)]

samedic={}
for s in ss:
  sort_s=''.join(sorted(list(s)))
  if sort_s in samedic:
    samedic[sort_s]+=1
  else:
    samedic[sort_s]=1

ans=0
for v in samedic.values():
  ans+=((v-1)*1)*(v/2)
print(int(ans))

Measured memory_bytes: 24980
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	string S;
	cin >> S;
	ll cnt = 0;
	for (ll i = 0; i < S.size()-1; i++) {
		if (S[i] != S[i + 1])cnt++;
	}
	cout << cnt << endl;
	}








Measured memory_bytes: 512