akhauriyash/Code-Regression huggingface dataset:
# from collections import defaultdict
import sys, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, M = read_int()

jobs = [[] for _ in range(M + 1)]
for i in range(N):
    d, r = read_int()
    if d <= M:
        jobs[d].append(-r)


hq = []
heapq.heapify(hq)

def solve():
    ans = 0
    for i in range(1, M + 1):
        for j in jobs[i]:
            heapq.heappush(hq, j)
        if hq:
            ans += - heapq.heappop(hq)
    return ans

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 67120
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll ans = 1;
vector<vector<pair<ll, ll>>> edges; //{node: {node1, index1}, {node2, index2}}
vll colors;

void dfs(ll node, ll color, ll pre) {
    ll new_color = 0;
    if (color == 0) new_color = 1;

    for (auto e : edges[node]) {
        if (e.first == pre) continue;

        if (ans < edges[node].size()) ans = edges[node].size();
        colors[e.second] = new_color;
        dfs(e.first, new_color, node);
        new_color++;
        if (new_color == color) new_color++;
    }
}

int main()
{
    ll N; cin >> N;
    colors.resize(N - 1, -1);
    edges.resize(N);
    rep(i, N - 1) {
        ll a, b; cin >> a >> b; a--, b--;
        edges[a].push_back({b, i});
        edges[b].push_back({a, i});
    }

    dfs(0, -1, -1);
    cout << ans << endl;
    rep(i, N - 1) cout << colors[i] + 1 << endl;
    return 0;
}

Measured memory_bytes: 9728
def main(str):
    input = str.split()
    n = int(input[0])
    l = int(input[1])
    apples = [l + i for i in range(n)]
    abs_apples = list(map(lambda x: abs(x), apples))
    return sum(apples) - apples[abs_apples.index(min(abs_apples))]


if __name__ == "__main__":
    str = input()
    print(main(str))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(void){

  int month;
  int day;
  int day2;

  while(1){

    day2 = 0;

    cin >> month >> day;
    if( month == 0 && day == 0 )break;

    for( int i = 1 ; i < month ; i++ ){
      switch(i){
      case 1:
      case 3:
      case 5:
      case 7:
      case 8:
      case 10:
      case 12:
	day2 += 31;
	break;
      case 2:
	day2 += 29;
	break;
      case 4:
      case 6:
      case 9:
      case 11:
	day2 += 30;
	break;
      }
    }
    day2 += day;
      switch(day2 % 7){
      case 1:
	cout << "Thursday" << endl;
	break;
      case 2:
	cout << "Friday" << endl;
	break;
      case 3:
	cout << "Saturday" << endl;
	break;
      case 4:
	cout << "Sunday" << endl;
	break;
      case 5:
	cout << "Monday" << endl;
	break;
      case 6:
	cout << "Tuesday" << endl;
	break;
      case 0:
	cout << "Wednesday" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1152
def main():
    n = int(input())
    s = list(input())
    
    arr = []
    cnt = 1
    for i in range(1, n):
        if s[i] == s[i - 1]:
            cnt += 1
        else:
            arr.append(cnt)
            cnt = 1
    arr.append(cnt)
    
    if s[0] == '.':
        arr = [0] + arr
    if s[-1] == '#':
        arr += [0]
    
    for i in range(len(arr) - 3, -1, -2):
        arr[i] += arr[i + 2]
    for i in range(2, len(arr), 2):
        arr[i] += arr[i - 2]
    
    arr += [0, 0]
    
    ans = arr[1]
    for i in range(1, len(arr) - 2, 2):
        ans = min(ans, arr[i - 1] + arr[i + 2])
    
    print(ans)
    return 0

main()

Measured memory_bytes: 12804
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
#include<string.h>
typedef long long int ll;
using namespace std;
ll d[100];
int mod=1e9+7;
int main()
{
	int n,m;
	cin>>n>>m;
	if(n==m)
	printf("Yes\n");
	else
	printf("No\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define x first
#define y second
#define size(a) (ll)(a).size()

typedef long long ll;
typedef long double ld;

using namespace std;
int n;
string s;


int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");


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

    cin >> n;

    ld summ = 0;

    for (int i = 0; i < n; i++)
    {
        ld num;
        cin >> num;
        summ += 1 / num;
    }

    ld res = (ld)(1) / (summ);

    cout.precision(10);
    cout << fixed << res << "\n";

}


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

int main() {
  int h1, m1, h2, m2, k, num;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  num = (h2*60 + m2) - k - (h1*60 + m1);
  cout << num << endl;
}


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

#define ll long long
#define pii pair <int, int>
#define x first
#define y second

using namespace std;

string s;
int dp[301][301][301];

inline int solve(int l, int r, int k) {
    if (k < 0)
        return INT_MIN;
    if (r - l < 1)
        return r - l + 1;
    if (dp[l][r][k] != -1)
        return dp[l][r][k];
    return dp[l][r][k] = max(solve(l + 1, r - 1, k - (s[l] != s[r])) + 2, max(solve(l + 1, r, k), solve(l, r - 1, k)));
}

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

	int k;
    cin >> s >> k;
    memset(dp, -1, sizeof(dp));
    return cout << solve(0, s.length() - 1, k), 0;
}


Measured memory_bytes: 106880
#54c
import itertools
N,M = map(int, input().split())

from_to_dict = dict()

for i in range(M):
    a,b = map(int, input().split())
    
    if a in from_to_dict:
        from_to_dict[a].add(b)
    else:
        from_to_dict[a] = set([b])
        
    if b in from_to_dict:
        from_to_dict[b].add(a)
    else:
        from_to_dict[b] = set([a])
        
#候補は全部で8! = 40320通り。総当たりでOK
candidate_list = [i+1 for i in range(N)]
ans = 0

for candidate in list(itertools.permutations(candidate_list)):
    if candidate[0] == 1:
        for i in range(len(candidate)-1):
            from_node = candidate[i]
            to_node = candidate[i+1]

            if to_node not in from_to_dict[from_node]:
                break
        else:
            ans += 1
                          
print(ans)

Measured memory_bytes: 8052
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int n;cin >> n;
    vector<int>p(n);
    int sum=0;
    rep(i,n){
        cin >> p[i];
        sum+=p[i];
    }
    int max=*max_element(p.begin(),p.end());
    max/=2;
    sum-=max;
    out(sum);
    return 0;
}





Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353 
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
double x[10],y[10],ans;
int main(){
	cin>>n;
	rep(i,n) cin >> x[i] >> y[i];
	rep(i,n) rep(j,n){
		if(i >= j) continue;
		ll d1 = x[i]-x[j];
		ll d2 = y[i]-y[j];
		ans += sqrt(d1*d1+d2*d2);
	}
	ans /= (double)(n);
	ans *= 2.;

	printf("%.12f\n",ans);
}

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

int main () {
	string s, t;
	cin >> s >> t;
	int count = 0;
	for (int i = 0; i < (int) s.length(); i++) {
		if (s[i] != t[i]) {
			count++;
		}
	}
	cout << count;
	
	
	return 0;
}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>

using namespace std;

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

    int A, B, C, K;
    cin >> A >> B >> C >> K;

    if (K <= A) {
        cout << K << endl;
        return 0;
    }
    K -= A;
    if (K <= B) {
        cout << A << endl;
        return 0;
    }
    K -= B;
    cout << A - K << endl;

    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf long double
#define vi vector<int>
#define vl vector<long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define in insert
#define all(x) x.begin(),x.end()
#define zapp ios::sync_with_stdio(false);cin.tie(0)
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll inv(ll x) {return power(x, MOD - 2);}
const int MAXN = 1e5 + 5;
//const bool is_in = container.find(element) != container.end();
int main()
{
	zapp;
	string s, t;
	cin >> s;
	cin >> t;
	ll i, n = t.length();
	string ans = "";
	for (i = 0; i < n - 1; i++)
		ans += t[i];
	if (ans == s)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}



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

int main () {
  int N ;
  cin >> N ;
  int nul[4][3][10] = {} ;
  for(int i = 0 ; i < N ; i++ ) {
    int a , b , c , d ;
    cin >> a >> b >> c >> d ;
    nul[a-1][b-1][c-1] += d ;
  }
  for(int i = 0 ; i < 4 ; i++){
    for(int j = 0 ; j < 3 ; j++ ){
      cout << " " ;
      for(int k = 0 ; k < 10 ; k++) {
        cout << nul[i][j][k] ;
        if(k!=9) cout << " " ;
        else cout << endl ;
      }
    }
    if(i!=3) {
      cout << "####################" ;
      cout << endl ;
    }
  }
}


Measured memory_bytes: 3060
/*=============================================================================================================================/*
                                               Bismillahir Rahmanir Rahim

      _     ____  ___  ____   _   _  _         ___  ____   _         _     __  __
     / \   / ___||_ _|| __ ) | | | || |       |_ _|/ ___| | |       / \   |  \/  |
    / _ \  \___ \ | | |  _ \ | | | || |        | | \___ \ | |      / _ \  | |\/| |
   / ___ \  ___) || | | |_) || |_| || |___     | |  ___) || |___  / ___ \ | |  | |
  /_/   \_\|____/|___||____/  \___/ |_____|   |___||____/ |_____|/_/   \_\|_|  |_|

   _   __           __  __  __
  |_) (_  _  o__   /   (_  |_
  |_)o__)(_  || |  \__ __) |__

    ___                    _   _      _                _ _               __   ___                 _         _        _
   / __|_ _ ___ ___ _ _   | | | |_ _ (_)_ _____ _ _ __(_) |_ _  _   ___ / _| | _ ) __ _ _ _  __ _| |__ _ __| |___ __| |_
  | (_ | '_/ -_) -_) ' \  | |_| | ' \| \ V / -_) '_(_-< |  _| || | / _ \  _| | _ \/ _` | ' \/ _` | / _` / _` / -_|_-< ' \
   \___|_| \___\___|_||_|  \___/|_||_|_|\_/\___|_| /__/_|\__|\_, | \___/_|   |___/\__,_|_||_\__, |_\__,_\__,_\___/__/_||_|
                                                            |__/                           |___/


   FB: https://facebook.com/SIAsibul
   Gmail: asibulislam8@gmail.com

/*=============================================================================================================================*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;
typedef vector<pll> vll;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,n) for(int i=0;i<(n);i++)
#define f1(i,n) for(int i=1;i<=(n);i++)
#define f2(i,a,n) for(int i=(a);i<=(n);i++)
#define fr(i,n,a) for(int i=(n);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define nl "\n"


const int INF = 1e9 + 5;
const int MXN = 2e5 + 5;


int main(){
    string inp,weeks[7];
    weeks[0]="MON";
    weeks[1]="TUE";
    weeks[2]="WED";
    weeks[3]="THU";
    weeks[4]="FRI";
    weeks[5]="SAT";
    weeks[6]="SUN";
    cin>>inp;
    int n;
    for(int i=0;i<7;i++){
        if(weeks[i]==inp){
            n=i;
        }
    }
    int res = 6-n;
    if(res==0){
        res=7;
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 3596
main = do
  [_,x] <- map read . words <$> getLine
  as <- map read . words <$> getLine
  print (candies x as)

candies x = fst . foldl (eat x) (0,0)

eat x (acc,rest) a = let n = max 0 (rest+a-x) in (acc+n, a-n)

Measured memory_bytes: 85372
main = do
  s <- getLine
  print . sum . map (score 0) . words . separate . bctos $ s

bctos ('B':'C':xs) = 'S' : bctos xs
bctos (x:xs) = x : bctos xs
bctos [] = []

separate (x:xs)
  | x == 'B' || x == 'C' = ' ' : separate xs
  | otherwise = x : separate xs
separate [] = []

score _ [] = 0
score as (x:xs)
  | x == 'A' = score (as+1) xs
  | otherwise = as + score as xs

Measured memory_bytes: 16252
#include <bits/stdc++.h>
#define fname "B"
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define bug(x) cerr << (#x) << " = " << (x) << '\n'
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define X first
#define Y second

using namespace std;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<float, float> ff;
typedef pair<double, double> dd;

int main()
{
	if (fopen(fname".INP", "r")) {
		freopen(fname".INP", "r", stdin);
		freopen(fname".OUT", "w", stdout);
	}
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n, l;
	cin >> n >> l;
	vector<string> arr(n);
	REP0(i, n) cin >> arr[i];
	sort(arr.begin(), arr.end());
	REP0(i, n) cout << arr[i];
	return 0;
}

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

int main(){
    int n, a[100];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int j = n - 1; j >= 0; j--){
        cout << a[j];
        if(j != 0) cout << " ";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n, x;
    int L[110];
    cin >> n >> x;
    REP(i, n)
        cin >> L[i];
    vector<int> v;
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        v.push_back(sum);
        sum += L[i];
    }
    v.push_back(sum);
    ll cnt = 0;
    for (int i = 0; i <= n; i++)
    {
        if(v[i]<=x)
            cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--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 F			first
#define S			second
 
int main(int argc, char **argv) {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (min(abs(a - b) + abs(b - c), min(abs(a - c) + abs(c - b), abs(b - a) + abs(a - c)))) << endl;
	return 0;
}
 

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var wl string
	fmt.Scanf("%s", &wl)

	var lc int

	// wc = strings.Count(wl, "o")
	lc = strings.Count(wl, "x")

	if lc <= 7 {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}

}


Measured memory_bytes: 640
import java.util.*;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        long N = sc.nextLong();
        long A;
        long B;
        long max = 0;

        if(N==1){
            System.out.println(1);
            return;
        }
        for(long i=1; i<=N; i++){
            A = i;
            B = N / A;
            if(A>B){
                System.out.println(String.valueOf(max).length());
                break;
            }
            else{
                if(N%A==0){
                    max = 0;
                    max = Math.max(A, B);
                }
            }
        }
    }
}

Measured memory_bytes: 21972
"use strict";
const Main = function(input){
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let tax =1.08;
   let ans1=Math.floor(xs[0]/tax);  
   if(Math.floor(ans1*tax)==xs[0]||Math.floor((ans1+1)*tax)==xs[0]){
   console.log(Math.ceil(xs[0]/tax));
   }else{
   console.log(":(");
   }  
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 11468
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
using namespace std;

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

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> vec(H);
    for(int i = 0; i < H; ++i){
        cin >> vec[i];
    }
    if(H == 1 && W == 1 && vec[0][0] == '#'){
        cout << "No" << endl;
        return 0;
    }
    bool check = true;
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            if(vec[i][j] == '#'){
                bool black = false;
                for(int k = 0; k < 4; ++k){
                    int ny = i + dy[k];
                    int nx = j + dx[k];
                    if(0 <= nx && nx < W && 0 <= ny && ny < H && vec[i][j] == vec[ny][nx]){
                        black = true;
                        break;
                    }
                }
                if(!black){
                    check = false;
                }
            }
        }
    }

    cout << (check ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

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

	map<ll, ll> MP;

	rep(i, N) {
		ll tmp;
		cin >> tmp;
		MP[tmp]++;
	}

	ll ans = 0;

	for (auto itr = MP.begin(); itr != MP.end(); itr++) {

		pair<ll, ll> P = *itr;

		if (P.first == P.second) {
		}
		else if (P.first > P.second) {
			ans += P.second;
		}
		else {
			ans += P.second - P.first;
		}

	}

	cout << ans;


}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    int n; cin >> n; std::vector<int> a(n,0);
    rep(i,n) cin >> a[i];

    std::vector<int> left(n,0), right(n,0);

    rep(i,n){
        if(n!=0){
            left[i] = max(left[i-1],  a[i-1]);
            right[n-i-1] = max(right[n-i], a[n-i]);
        }
    }
    
    rep(i,n){
        cout << max(left[i], right[i]) << endl;
    }
    return 0;
}

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

int main(){
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  int sum1, sum2, sum3;

  sum1 = A * X + B * Y;

  if(X > Y){
    sum2 = 2 * C * Y + A * (X - Y);
    sum3 = 2 * C * X;
  }else{
    sum2 = 2 * C * X + B * (Y - X);
    sum3 = 2 * C * Y;
  }

  int sum[3] = {sum1, sum2, sum3};

  sort(sum, sum + 3);

  cout << sum[0] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 100003
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::floatfield );std::cout.precision(15)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define br "\n"
#define sp " "
#define zero (ll)0
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
void READ(vll &v, ll n)
{
    ll a ;
    for(ll i=0 ; i<n ; i=i+1)
    {
        cin>>a ;
        v.pb(a) ;
    }
}
void PRINT(vll &v , ll a = 0)
{
    //ll a ;
    for(ll i=a ; i<v.size() ; i=i+1)
    {
        v[i] = max((ll)0,v[i]);
        cout<<v[i]<<" " ;
    }
    cout<<"\n" ;
}
/*vbool isprime(N,true);
vll spf(N,0);
vll prime;
void sieve()
{
    isprime[0] = isprime[1] = false;
    for(ll i = 2 ; i<N ; i++)
    {
        if(isprime[i])
        {
            for(ll j=2*i ; j<N ; j+=i)
            {
                isprime[j] = false;
                if(spf[j]==0)
                {
                    spf[j] = i;
                }
            }
            prime.pb(i);
        }
    }
}*//*
ll nck(ll n , ll k ,ll m=1e18+7)
{
    ll i , j,b=1,c=1 ;
    if(n-k<k)
    {
        k = n-k ;
    }
    while(k)
    {
        b*=n ;
        c*=k ;
        ll g = __gcd(b,c) ;
        b/=g ;
        c/=g ;
        n--;
        k-- ;
    }
    return(b) ;
}*//*
long long power(long long k , long long n , long long m=mod)
{
    long long res = 1;
    while(n)
    {
        if(n%2!=0)
        {
            res = (res*k)%m ;
        }
        k = (k*k)%m ;
        n = n/2 ;
    }
    return(res) ;
}*/
ll n,m,k,l,r;
bool ok = false;
int main()
{
    FastIO ;
    PRECISION ;
    ll a,b,c,d,i,j,t,x,y,z;//,x1,y1,z1,e,f;
    ll p,q,r,u,w ;
    char ch,chr ;
    string str,st,str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,a,b,ans=0; 
    cin>>n>>a>>b;
    if (b<a or ((n==1) and (a!=b))) ans=0;
    else {
        n-=2;
        int l=n*a,r=n*b;
        ans = max(1LL,r-l+1);
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			String a = scanner.next();
			if (a.charAt(0) == '0')
				break;
			char[][] line = new char[3][];
			line[0] = a.toCharArray();
			line[1] = scanner.next().toCharArray();
			line[2] = scanner.next().toCharArray();
			for (char[] c : line) {
				int ac = 0;
				int bc = 0;
				for (int i = 1; i < c.length; i++) {
					if (c[i] == 'A') {
						ac++;
					} else {
						bc++;
					}
				}
				if (ac > bc) {
					System.out.println(ac + 1 + " " + bc);
				} else {
					System.out.println(ac + " " + (bc + 1));
				}
			}
		}
	}
}

Measured memory_bytes: 17292
while True:
  m, f, r = map(int,input().split())
  score = m + f
  
  if m == f == r == -1:
    break
  elif m == -1 or f == -1 :
    print('F')
  elif score >= 80:
    print('A')
  elif score >= 65:
    print('B')
  elif score >= 50 or ( score >= 30 and r >= 50 ) :
    print('C')
  elif score >= 30:
    print('D')
  else:
    print('F')


Measured memory_bytes: 5592
s = list(input())
q = int(input())
rev = False
fwd =[]

for i in range(q):
    t = input()
    if len(t) == 1:        
        if rev:
            rev = False
        else:
            rev = True
    else:
        q2, f, c = t.split()
        if f == "1":
            if rev:
                s.append(c)
            else:
                fwd.append(c)
        if f == "2":
            if rev:
                fwd.append(c)
            else:
                s.append(c)

s = list(reversed(fwd)) + s

if rev:
    s = "".join(list(reversed(s)))
else:
    s = "".join(s)

print(s)
            

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()

struct pii {
	int a, b;
	pii(int _a, int _b) : a(_a), b(_b) {}
};
bool operator < (const pii& a, const pii& b) { return (a.a == b.a) ? a.b < b.b : a.a < b.a; }

typedef vector< pii > PArray;

int n, m;

void solve() {
	int cnt[110] = { 0 };
	for_(i,0,n) for_(j,0,m) {
		int c; scanf("%d", &c), cnt[j] += c;
	}
	
	PArray vp;
	for_(i,0,m) vp.push_back(pii(cnt[i], -(i + 1)));
	sort(allof(vp));
	
	for_rev(i,m-1,0) {
		if (i > 0) printf("%d ", -vp[i].b);
		else printf("%d\n", -vp[i].b);
	}
}

int main() {
	while (scanf("%d %d", &n, &m), n) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,x,y,z,l,n,m,a,r,f,c;
  long long min,max,sum;
  //vector<vector<int>> A(n, vector<int>(m, 0));
  string s;

  while(1){
    getline(cin,s);
    if(s == "0")break;
    sum = 0;
    for(int i=0;i<s.length();i++){
  	  sum += s[i] - '0';
    }
    cout << sum << endl;
  }
}


Measured memory_bytes: 3156
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		
        int b = sc.nextInt();
		int c = sc.nextInt();
        int d = 0;
        if(a>b){d=c/a;if(c%a!=0){d++;}}else{d=c/b;if(c%b!=0){d++;}}
		System.out.println(d);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
 
const int MOD = 1000000007;
 
 
int main(){
    ll K; cin >> K;
 
    ll seven = 0;
    ll ans = -1;
    ll count = 0;
    set<ll> mods;
    while (true){
        seven = (seven*10 + 7) % K;
        if (seven == 0){
            ans = count+1;
            break;
        }
        else{
            auto it = mods.find(seven);
            if (it != mods.end()){
                break;
            }
            else{
                mods.insert(seven);
            }
        }
        
        count++;
    } 
    cout << ans << endl;
}

Measured memory_bytes: 50372
#include <stdio.h>
#include <string.h>

#define N (1000 + 10)

#define max(a, b) (a < b ? b : a)

int A[N][N];
char a[N], b[N];

int LCS(void);

int main(void){
  int n, i;
  scanf("%d\n", &n);
  for ( i = 0; i < n; i++ ){
    fgets(a, N, stdin);
    fgets(b, N, stdin);
    printf("%d\n", LCS());
  }
  return 0;
}

int LCS(void){
  const int a_size = strlen(a) - 1;
  const int b_size = strlen(b) - 1;
  int i, j;

  memset(A, 0, sizeof(A));

  for (i = 1; i < a_size + 1; ++i) {
    for (j = 1; j < b_size + 1; ++j) {
      int mx = max(A[i][j - 1], A[i - 1][j]);
      if (a[i - 1] == b[j - 1]) {
        mx = max(mx, A[i - 1][j - 1] + 1);
      }
      A[i][j] = mx;
    }
  }

  return A[a_size][b_size];
}



Measured memory_bytes: 5752
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        int[] s = new int[m];
        int[] c = new int[m];
        for (int i = 0; i < m; i++) {
            s[i] = in.nextInt() - 1;
            c[i] = in.nextInt();
        }
        for (int i = 0; i < 1000; i++) {
            String t = String.valueOf(i);
            if (t.length() == n) {
                boolean can = true;
                for (int j = 0; j < m; j++) {
                    can &= t.charAt(s[j]) - '0' == c[j];
                }
                if (can) {
                    out.println(i);
                    return;
                }
            }
        }
        out.println(-1);
    }

    public static void main(String[]$) {
        new Main().solve();
        out.flush();
    }
}

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private static PrintWriter out = new PrintWriter(System.out);

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 22868
#include<stdio.h>
void merge(int *,int,int,int);
void mergeSort(int *,int,int);
int S[500000],count=0;
int main(){
  int i,j,n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);
  mergeSort(S,0,n);
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",S[i]);
  }
  printf("\n%d\n",count);
  return 0;
}
 
void merge(int A[],int left,int mid,int right){
  int n1=mid-left,n2=right-mid,i,L[n1+1],R[n2+1],j,k;
  for(i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<=n2-1;i++){
    R[i]=A[mid+i];
  }
  L[n1]=1000000000;
  R[n2]=1000000000;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
     
    else{
      S[k]=R[j];
      j=j+1;
    }
    count++;
  }
}
void mergeSort(int S[],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(S,left,mid); 
    mergeSort(S,mid,right);
    merge(S,left,mid,right);
  }
}
     

Measured memory_bytes: 4504
#include <stdio.h>
#include <iostream>
using namespace std;

int main() {
	int N;
	int M;

	cin >> N;
	cin >> M;

	int a = N * (N - 1) / 2;
	int b = M * (M - 1) / 2;

	int c = a + b;
	cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
vvl G;
ll dfs(int v){
  ll res=1;
  for(auto nv:G[v]){
    res+=dfs(nv);
  }
  return res;
}
    
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  ll n,k;
  cin >> n >> k;
  vector<ll>h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(),h.end());
  ll ans=INF;
  rep(i,n-k+1){
    chmin(ans,h[i+k-1]-h[i]);
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 13056
#include<iostream>
#include<queue>
using  namespace std;
int main(void){
	int n, q, s;
	cin >> n >> q;
	string m;
	queue<string> name;
	queue<int> time;  
	for(int i = 0; i < n; i++){
		cin >> m >> s;
		name.push(m);
		time.push(s);
	}
	int t = 0; 
	while(!name.empty()){
		string a = name.front();
		int b = time.front();
		if(b <= q){
			t += b;
			cout << a << ' ' << t << endl;
			name.pop();
			time.pop();
		}
		else{
			t += q;
			name.pop();
			time.pop();
			name.push(a);
			time.push(b-q);
		}
	}
	return 0;

}


Measured memory_bytes: 6104
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int n = sc.nextInt();
		int m = sc.nextInt();
		int count=0;
		for(int i=0;m>i;i++) {
			int a = sc.nextInt();
			count=count+a;
		}
		if(n>=count)
			System.out.println(n-count);
		else
			System.out.println(-1);
	}
}

Measured memory_bytes: 46272
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> p(N);
  int count = 0;
  rep(i,N) 
  {
    cin >> p[i];
    p[i] --;
  }
  rep(i,N-1)
  {
    if(p[i]==i)
    {
      swap(p[i],p[i+1]);
      count ++;
    }
  }
  if(p[N-1]==N-1)
  {
    swap(p[N-1],p[N-2]);
    count ++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

ll gcd(ll i, ll j) { return i % j ? gcd(j, i % j) : j; }

int main() {

	int n, m;
	cin >> n >> m;
	int p = 0;
	ll lcm = 1;
	vi a(n);
	rep(i, n)cin >> a[i];
	
	rep(i,n){
		int p2 = 0;
		int aa = a[i];
		while (!(aa & 1)) {
			aa /= 2;
			p2++;
		}

		aa = a[i] / 2;
		
		if (i == 0) {
			p = p2;
			lcm = aa;
		}
		else if (p2 != p) {
			cout << 0 << endl;
			return 0;
		}
		else {
			lcm = aa / gcd(lcm, aa) * lcm;
			if (lcm > m) {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	cout << (m - lcm) / (2 * lcm) + 1 << endl;

}

Measured memory_bytes: 3728
using System;

namespace AtCoder.ABC._124
{
    class a
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            var spl = line.Split(' ');
            var A = int.Parse(spl[0]);
            var B = int.Parse(spl[1]);
            if (A == B)
            {
                Console.WriteLine(A*2);
            }
            else
            {
                Console.WriteLine(Math.Max(A,B) * 2 - 1);
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, w; cin >> n >> w;
  vector<long long> f(w + 1);
  for(int i = 0; i < n; i++){
    int wi, vi; cin >> wi >> vi;
    for(int j = w - wi; j >= 0; j--)
      f[j+wi] = max(f[j+wi], f[j] + vi);
  }
  cout << f[w] << endl;
  return 0;
}


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

int main() {
  int r, D, thisYear;
  cin >> r >> D >> thisYear;
  int nextYear;
  for (int i = 0; i < 10; i++) {
    nextYear = r * thisYear - D;
    cout << nextYear << endl;
    thisYear = nextYear; 
  }
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  if(S == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int w = sc.nextInt();
        if(s>w){
            System.out.println("safe");
        }else{
            System.out.println("unsafe");
        }
    }
}

Measured memory_bytes: 35520
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int a,b,K;
  cin>>a>>b>>K;
  vector<int> A,B;
  int atmp=a,btmp=b,sz=0; 
  while(atmp){
    A.push_back(atmp%10);
    B.push_back(btmp%10);
    atmp/=10;
    btmp/=10;
    sz++;
  }
  int dp[15][2][15];
  fill_n(**dp,15*2*15,-1);
  dp[0][0][0]=0;
  for(int i=0;i<sz;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<=K;k++){
	if(dp[i][j][k]==-1)continue;
	if(A[i]-j>=B[i]){
	  int cost=(A[i]-j-B[i])*pow(10,i);
	  dp[i+1][0][k]=max(dp[i+1][0][k],dp[i][j][k]+cost);
	}else{
	  int cost=(A[i]-j+10-B[i])*pow(10,i);
	  dp[i+1][1][k]=max(dp[i+1][1][k],dp[i][j][k]+cost);
	  dp[i+1][0][k+1]=max(dp[i+1][0][k+1],dp[i][j][k]+cost);
	}
      }
    }
  }
  int ans=0;
  for(int i=0;i<2;i++)
    for(int j=0;j<=K;j++)
      ans=max(ans,dp[sz][i][j]);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
const int INF = 1e9;

int main() {
    while (1) {
        int n, p;
        cin >> n >> p;
        if (n == 0 && p == 0)
            break;

        vector<int> cnt(n);
        int man = 0, now = p;
        while (1) {
            if (now == 0) {
                now = cnt[man];
                cnt[man] = 0;
            } else {
                ++cnt[man];
                --now;
            }
            if (cnt[man] == p) {
                cout << man << "\n";
                break;
            }

            man = (man + 1) % n;
        }
    }

    return 0;
}


Measured memory_bytes: 3072
using System;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		string ans="No";
		if(s[2]%s[0]==0||s[2]%s[1]==0){ans="Yes";}
		else{
			for(int i=1;i<=s[0]/2;i++){
				for(int j=1;j<s[1];j++){
					if(s[2]==s[1]*i+s[0]*j-i*j*2){
						ans="Yes";
						break;
					}
				}
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140