akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,x;cin >> n >> x;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	ll ans=0;
	rep(i,n-1){
		if(a.at(i)+a.at(i+1)>x){
			int b=a.at(i)+a.at(i+1)-x;
			ans+=b;
			if(a.at(i+1)<b){
				b-=a.at(i+1);
				a.at(i+1)=0;
				a.at(i)-=b;
			}
			else a.at(i+1)-=b;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    int N, W;
    cin >> N >> W;

    vs32 w(N), v(N);
    int vmax = 0;
    rep (i, N)
    {
        cin >> w[i] >> v[i];
        vmax = MAX(vmax, v[i]);
    }

    s64 dp[N * vmax + 1];
    rep (i, N * vmax + 1) dp[i] = 1e18;
    dp[0] = 0;

    rep (i, N)
    {
        for (int j = N * vmax; j >= 0; --j)
        {
            if (j >= v[i])
            {
                dp[j] = MIN(dp[j], dp[j - v[i]] + w[i]);
            }
        }
    }

    s64 ans = 0;
    rep (i, N * vmax + 1)
    {
        if (dp[i] <= W) ans = MAX(ans, i);
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <stack>
#define INF -1
#define MAX 26
using namespace std;
struct BinNode
{
    int parent;

    int left_child;
    int right_child;

};
BinNode nodes[MAX];
void print(int u)
{
    cout<<" "<<u;
}
//?????????????????£??????
void visit_Along_Left_Branch(int u,stack<int>& S)
{
    while(u!=INF)
    {
        print(u);
        S.push(nodes[u].right_child);
        u=nodes[u].left_child; //??§?????±??\
    }
}

void PreOrder(int r)
{
    stack<int> S;
    while(true)
    {
        visit_Along_Left_Branch(r,S);
        if(S.empty()) break;
        r=S.top();S.pop();
    }
}

void InOrder(int r)
{
    stack<int> S;
    while(true)
    {
        if(r!=INF)
        {
            S.push(r);
            r=nodes[r].left_child;
        }
        else if(!S.empty())
        {
            r=S.top();S.pop();
            print(r);
            r=nodes[r].right_child; //??¬????????????
        }
        else
            break;
    }
}

void gotoHLVFL(stack<int>& S)
{
    int x;
    while((x=S.top())!=INF)
    {
        if(nodes[x].left_child!=INF) //?°?????????????
        {
            if(nodes[x].right_child!=INF)
                S.push(nodes[x].right_child); //???????????\???
            S.push(nodes[x].left_child); //??¶??????????????\???
        }
        else
            S.push(nodes[x].right_child); //?????¨??????????????????????????\????????????????????????????????????????????\?????????????°±????????????
    }
    S.pop(); //???????????????
}

void PostOrder(int r)
{
    stack<int> S; //?????????
    if(r!=INF) S.push(r); //???????????\???
    while(!S.empty())
    {
        if(S.top()!=nodes[r].parent) //??\?????¶????????????????????¶
            gotoHLVFL(S); //?????¶?????\??¨??\??¶????????????????????????????????°HLVFL
        r=S.top();S.pop();
        print(r);
    }
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) nodes[i].parent=nodes[i].left_child=nodes[i].right_child=INF;
    for(int i=0;i<n;i++)
    {
        int j,lc,rc;
        cin>>j>>lc>>rc;
        //?????????
        nodes[j].left_child=lc;nodes[j].right_child=rc;
        //??????
        if(lc!=INF) nodes[lc].parent=j;
        if(rc!=INF) nodes[rc].parent=j;
    }
    //?????°?????????
    int root;
    for(int i=0;i<n;i++)
        if(nodes[i].parent==INF)
        {
            root=i; break;
        }
    cout<<"Preorder"<<endl;
    PreOrder(root);
    cout<<endl;
    cout<<"Inorder"<<endl;
    InOrder(root);
    cout<<endl;
    cout<<"Postorder"<<endl;
    PostOrder(root);
    cout<<endl;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
int main() {
  ll n,m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i,n) cin >> h.at(i);
  ll good = n;
  vector<ll> memo(n);
  rep(i,m){
    ll a,b;
    cin >> a >> b;
    if(h.at(a-1)<=h.at(b-1)){
      if(memo.at(a-1) == 0){
        memo.at(a-1) ++;
        good --;
      }
    }
    if(h.at(a-1)>=h.at(b-1)){
      if(memo.at(b-1) == 0){
        memo.at(b-1) ++;
        good --;
      }
    }
  }
  cout << good << endl;
  return 0;
}

Measured memory_bytes: 4852
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 

#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)

void ayush(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

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

ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1) res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}
ll mulmod(ll a, ll b, ll mod) 
{ 
    ll res = 0; 
    a = a % mod; 
    while (b > 0) 
    { 
        if (b % 2 == 1) res = (res + a) % mod; 
        a = (a * 2) % mod; 
        b /= 2; 
    }  
    return res % mod; 
} 

int main(){
    ayush();
    fastio;

    ll t; t=1;
    while(t--){
        ll n=2;
        ll a[2]; ll b[2];
        rep(i,n){
            cin>>a[i];
        }
        rep(i,n){
            cin>>b[i];
        }
        bool p=true;
        while(1){
            if(p){
                b[0]-=a[1];
                if(b[0]<=0) break;
                p=false;
            }
            else{
                a[0]-=b[1];
                if(a[0]<=0) break;
                p=true;
            }
        }
        if(p) cout<<"Yes";
        else cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        String[] s = new String[n];
        for(int i = 0; i < n; i++) s[i] = scan.next();
        int m = scan.nextInt();
        String[] t = new String[m];
        for(int i = 0; i < m; i++) t[i] = scan.next();
        int max = 0;
        for(int i = 0; i < n; i++){
            int out = 0;
            for(int j = 0; j < n; j++){
                if(s[i].equals(s[j])) out++;
            }
            for(int j = 0; j < m; j++){
                if(s[i].equals(t[j])) out--;
            }
            max = Math.max(max, out);
        }
        System.out.println(max);
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}

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

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

  ll N; cin >> N;
  vector<ll> A(N, 0);
  for (ll i = 0; i < N; i++) {
    double X; cin >> X;
    A[i] = (X * 1e10 + 1) / 10;
  }

  vector<vector<ll>> cnt(50, vector<ll>(20, 0));
  // 2のべきと5のべきを数える
  for (ll i = 0; i < N; i++) {
    ll t = A[i];
    ll cnt2 = 0, cnt5 = 0;
    for (ll j = 0; j < 100; j++) {
      if (t % 2 != 0) break;
      cnt2++;
      t /= 2;
    }
    for (ll j = 0; j < 100; j++) {
      if (t % 5 != 0) break;
      cnt5++;
      t /= 5;
    }
    cnt[cnt2][cnt5]++;
  }

  ll ans = 0;
  for (ll i = 0; i < 50; i++) {
    for (ll j = 0; j < 20; j++) {
      for (ll i2 = 0; i2 < 50; i2++) {
        for (ll j2 = 0; j2 < 20; j2++) {
          if (min(i + i2, j + j2) >= 18) {
            ll temp = cnt[i][j] * cnt[i2][j2];
            if (i == i2 && j == j2) temp -= cnt[i][j];
            ans += temp;
          }
        }
      }
    }
  }
  ans /= 2;

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

Measured memory_bytes: 4672
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := getInt(), getInt()

	out(lcm(a, b))
}


Measured memory_bytes: 1772
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(void) {
  int n, a, b;
  cin >> n >> a >> b;
  int l, r;
  cin >> l;
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    cin >> r;
    ans += min(1LL * (r - l) * a, 1LL * b);
    l = r;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define de puts("#")
#define bug(x) cout<<#x<<" : "<<x<<endl
#define cha1 printf("L : %d,R : %d,x : %d,l : %d,r : %d,rt : %d\n",L,R,x,l,r,rt)
#define cha2 printf("L : %d,R : %d,l : %d,r : %d,rt : %d\n",L,R,l,r,rt)
#define cha3 printf("pos : %d,x : %d,l : %d,r : %d,rt : %d\n",pos,x,l,r,rt)
#define lcha1 printf("L : %lld,R : %lld,x : %lld,l : %lld,r : %lld,rt : %lld\n",L,R,x,l,r,rt)
#define lcha2 printf("L : %lld,R : %lld,l : %lld,r : %lld,rt : %lld\n",L,R,l,r,rt)
#define lcha3 printf("pos : %lld,x : %lld,l : %lld,r : %lld,rt : %lld\n",pos,x,l,r,rt)
#define huge(n,m,a) for(int i=1; i<=n; i++) {for(int j=1; j<=m; j++)printf("%d ",a[i][j]);puts("");}puts("")
#define lhuge(n,m,a) for(int i=1; i<=n; i++) {for(int j=1; j<=m; j++)printf("%lld ",a[i][j]);puts("");}puts("")
#define lowbit(x) (x&(-x))
#define IN freopen("in.txt","r",stdin)
#define OUT1 freopen("out1.txt","w",stdout)
#define OUT2 freopen("out2.txt","w",stdout)
#include<iostream>
#include<stdio.h>
#define int long long
using namespace std;
const int N=55;
const int M=2500;
const int P=5105;
const int mod=1e9+7;
int dp[N][N][P];

void add(int &a,int b) {
	a+=b;
	while(a>=mod)a-=mod;
}

signed main() {
	int n,m;
	scanf("%lld %lld",&n,&m);
	dp[1][0][M]=1;
	for(int i=1; i<=n; i++)
		for(int k=0; k<=2*M; k++)
			for(int j=i-1; j>=0; j--) {
//				printf("%d\n",dp[i][j][k]);
				if(!dp[i][j][k])continue;
				add(dp[i+1][j][k],dp[i][j][k]%mod);//放自己
				add(dp[i+1][j][k],dp[i][j][k]*j%mod);//放后面，前面填补
				if(k-2*i)add(dp[i+1][j+1][k-2*i],dp[i][j][k]%mod);//放后面，后面填补
				add(dp[i+1][j][k],1LL*dp[i][j][k]*j%mod);//放前面，后面填补
				if(j)add(dp[i+1][j-1][k+2*i],dp[i][j][k]*j%mod*j%mod);//放前面，前面填补
			}
	printf("%lld\n",dp[n+1][0][M+m]);
	return 0;
}

Measured memory_bytes: 112896
//ITP1_6_A
//????????????  6???

using System;
using System.Collections.Generic;

class ITP1_6_A
{
    static void Main(string[] args)
    {
        //n???int?????????????????????????????£??\

        int n = int.Parse(Console.ReadLine());

        //iarray???????????????a?????£??\

        int[] iarray = Array.ConvertAll<string, int>((Console.ReadLine().Split(' ')), delegate (string value)
        {
            return int.Parse(value);
        });

        //??????????????????????????????
        for(int i = n-1;i >= 0; i--)
        {
            Console.Write(iarray[i]);
            if (i != 0)
                Console.Write(" ");
        }

        Console.Write("\r\n");

    }
}

Measured memory_bytes: 9104
inf = float('inf')
n = int(input())
a = []

for i in range(n):
    line = list(map(int, input().split()))
    for i in range(len(line)):
        if line[i] == -1:
            # infinity weight if not connected
            line[i] = inf
    a.append(line)

checked = [False] * n
d = [inf] * n
checked[0] = True
ans = 0
nxt = 0

for i in range(n - 1):
    for j in range(n):
        if a[nxt][j] < d[j]:
            d[j] = a[nxt][j]

    min_n = 0
    min_w = inf

    for j in range(n):
        if not checked[j] and d[j] < min_w:
            min_n = j
            min_w = d[j]

    checked[min_n] = True
    nxt = min_n
    ans += min_w

print(ans)

Measured memory_bytes: 5892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	vector<int > v;
	int a,b,c;
	cin >> a >> b >> c;
	int cnt5 = 0;
	int cnt7 = 0;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	int p = v.size();
	for(int i=0;i<p;++i){
		if(v[i]==5){
			cnt5++;
		}
		else if(v[i]==7){
			cnt7++;
		}
	}
	if(cnt5==2 && cnt7 ==1){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}	
	return 0;
}


Measured memory_bytes: 3508
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//トポロジカルソートの結果を返す関数.graphは隣接リスト.0-origin.
//閉路がある場合，空のvectorを返す.
vector<int> tsort(const vector<vector<int>> &graph){
	const int v = graph.size();
	vector<int> indeg(v, 0);
	vector<int> s;
	for (auto out : graph)
	{
		for (auto x:out){
			indeg[x]++;
		}
	}
	for (int i = 0; i < v; i++){
		if(indeg[i] == 0){
			s.push_back(i);
		}
	}
	vector<int> res;
	while(s.size()){
		int u = s.back();
		s.pop_back();
		res.push_back(u);
		for(auto x:graph[u]){
			indeg[x]--;
			if(indeg[x] == 0){
				s.push_back(x);
			}
		}
	}
	if (res.size() != v)
		return vector<int>();
	return res;
}

int main(){
	int v, e;
	cin >> v >> e;
	vector<vector<int>> graph(v);
	rep(i,e){
		int s, t;
		cin >> s >> t;
		graph[s].push_back(t);
	}
	vector<int> ans = tsort(graph);
	if(ans.size())
		puts("0");
	else
		puts("1");

	return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <cstring>

using namespace std;

int n, k, a[105], dp[100005][2];

int rek(int x, bool pl){
	if(!x)
		return (pl ^ 1);
	int &ret = dp[x][pl];
	if(ret != -1)
		return ret;
	ret = pl ^ 1;
	for(int i = 1 ; i <= n ; ++i){
		if(x - a[i] >= 0){
			int t = rek(x - a[i], pl ^ 1);
			if(t == pl){
				ret = pl;
			}
		}
	}
	return ret;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(int i = 1 ; i <= n ; ++i){
	cin >> a[i];
}
memset(dp, -1, sizeof(dp));
int t = rek(k, 0);
if(!t){
	cout << "First" << endl;
}
else{
	cout << "Second" << endl;
}

return 0;
}



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

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<vector<int>> e(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  vector<int> prev(n, -1);
  queue<int> q;
  q.push(n - 1);
  while (true) {
    int v = q.front(); q.pop();
    if (v == 0) break;
    for (auto&& i : e[v]) {
      if (prev[i] == -1) {
        prev[i] = v;
        q.push(i);
      }
    }
  }
  vector<int> path(1, 0);
  while (true) {
    path.push_back(prev[path.back()]);
    if (path.back() == n - 1) break;
  }
  int f = path[(path.size() - 1) / 2], s = path[(path.size() + 1) / 2];
  int sum = 0;
  q = queue<int>();
  vector<int> memo(n, 0);
  memo[f] = 1; q.push(f);
  while (not q.empty()) {
    int v = q.front(); q.pop();
    if (v == s) continue;
    else sum++;
    for (auto&& i : e[v]) {
      if (memo[i] == 0) {
        memo[i] = 1;
        q.push(i);
      }
    }
  }
  cout << (sum > n - sum ? "Fennec" : "Snuke") << '\n';
  return 0;
}

Measured memory_bytes: 7032
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a,b,c;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		
		if(a < b && b < c)System.out.println("Yes");
		else System.out.println("No");
	}

}

Measured memory_bytes: 26332
//ABC 062 B - Picture Frame
#include <iostream>
#include <vector>
using namespace std;

//for drawing the upper and footer frames.
void drawSharpSymbol(int width){
  for(int i = 0 ; i<(width+2) ; i++){
    cout << "#";
  }
  cout << endl;
}

//create the Two dimensinal matrix.
vector< vector<char> > create2dimArray(int H, int W){
  
  vector< vector<char> > ary;
  ary.resize(H);
  for(int i=0 ; i<H ; i++){
    ary[i].resize(W);
  }

  for(int i=0 ; i<H ; i++){
    for(int j=0 ; j<W ; j++){
      char k;
      cin >> k;
      ary[i][j] = k;
    }
  }
  return ary;
}

//draw matrix with sharp.
void drawMatrixwithSharp(vector< vector<char> > ary){
  
  //get the size of Matrix.
  int H = ary.size();
  int W = ary.front().size();
  
  for(int i = 0 ; i<H ; i++){
    cout << "#";
    for(int j = 0 ; j<W ; j++){
      cout << ary[i][j];
    }
    cout << "#" << endl;
  }
}

int main(void){
  int H,W;
  cin >> H >> W;

  vector< vector<char> > ary;
  ary = create2dimArray(H,W);

  //draw header
  drawSharpSymbol(W);

  //draw matrix
  drawMatrixwithSharp(ary);
  
  //draw footer
  drawSharpSymbol(W);

  return 0;
}

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

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

    vector<int> A(M);

    for(int i = 0; i < M; i++) cin >> A[i];
    sort(A.begin(), A.end());
    ll sum = 0;
    for(int i = 0; i < M; i++) {
        sum += A[i];
    }

    if(sum > N) { cout << -1 << endl; return 0;}
    
    cout << N - sum;
    return 0;
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, a, c=0;
  cin >> n;
  map <ll, ll> m;
  forll(i, 0, n){
	cin >> a;
	m[a]++;
  }
  for(auto i=m.begin(); i!=m.end(); i++){
	if(i->second > i->first)
	  c += i->second - i->first;
	else if(i->second < i->first)
	  c += i->second;
  }
  cout << c << endl;
}


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

#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int   mod   = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  string S;
  cin >> S;

  string f = S.substr(0, 2), l = S.substr(2, 2);

  auto uku = [&](string Y, string M) {
    if ("00" <= Y && Y <= "99" && "01" <= M && M <= "12") return true;
    else return false;
  };

  if (uku(f, l) && uku(l, f)) cout << "AMBIGUOUS" << endl;
  if (uku(f, l) && !uku(l, f)) cout << "YYMM" << endl;
  if (!uku(f, l) && uku(l, f)) cout << "MMYY" << endl;
  if (!uku(f, l) && !uku(l, f)) cout << "NA" << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define long long long
#define ull unsigned long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define upadj(i,adj) if (adj.size()>0) up(i,0,adj.size()-1)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define V vector
#define debug(X) cerr<< #X << "=" <<X << endl
#define debug2(X,Y)  cerr<< #X << "=" <<X << ", " << #Y << "=" <<Y << endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar
using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }
long n,x;
void input()
{
    cin>>n>>x;
}

void solve()
{
    long res= n;
    long y= n-x;
    if (x<y) swap(x,y);
    while (y!=0)
    {
        res+= x/y * 2*y;
        long q= x% y;
        x= y; y= q;
    }
    cout<<res-x;

}

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

    #ifdef I_Love_Pork
    #define TASK "tmp"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
    #endif

    input();
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int n;cin>>n;
  list<int>l;

  for(int t=1;t<=n;t++){
    int a;cin>>a;

    if(t==1){
      l.push_front(a);
    }else if(t%2==0){
      l.push_back(a);
    }else if(t%2==1){
      l.push_front(a);
    }

  }
  if(n%2==0)reverse(l.begin(),l.end());
  for(auto x:l)cout<<x<<" ";
  cout<<"\n";
  return 0;
}


Measured memory_bytes: 8448
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<assert.h>
#include<numeric>
#define rep(i,a,b) for(int (i)=(a);i<(b);i++)
using namespace std;

using ll = long long;

ll N, Y;

int main() {
	cin >> N >> Y;
	int n = Y / 10000;
	int m = Y / 5000;
	rep(i, 0, n+1) {
		rep(j, 0, m+1) {
			if (Y == i * 9000 + j * 4000 + N * 1000 && N-i-j >=0) {
				cout << i << " " << j << " " << N - i - j;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1";
	return 0;
}

Measured memory_bytes: 256
import math

def findDivisor(n):
    divisor = []
    for i in range(1, int(math.sqrt(n))+1):
        if n % i == 0:
            divisor.append(i)
            divisor.append(n//i)
    return divisor

n = int(input())

div = findDivisor(n)

c = 0
for d in set(div)-{1}:
    if n//(d-1) == n%(d-1):
        c += d-1

print(c)

Measured memory_bytes: 4052
#include<iostream>
#include<list>
#include<queue>
#include<stdio.h>
using namespace std;
struct Node {
	//int id;
	int indegree;
	list<int> next;
};
Node graph[10002];
int visit[10002];
int n, m;
queue<int> answer;
void bfs(int beginNodeId) {
	queue<int> Q;
	Q.push(beginNodeId);
	while (!Q.empty()) {
		int id = Q.front(); Q.pop();
		visit[id] = 1;
		answer.push(id);

		list<int>::iterator it = graph[id].next.begin();
		for (it; it != graph[id].next.end(); it++) {
			int nextid = *it;
			graph[nextid].indegree--;
			if (graph[nextid].indegree == 0 && visit[nextid] == 0) {
				Q.push(nextid);
			}
		}
	}

}
void topologicalSort() {
	for (int i = 0; i < n; i++) {
		if (graph[i].indegree == 0 && visit[i]==0) {
			bfs(i);
		}
	}
}
int main() {
	scanf("%d %d", &n, &m);
	int a, b;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &a, &b);
		graph[a].next.push_back(b);
		graph[b].indegree++;
	}
	topologicalSort();
	while (!answer.empty()) {
		int ans = answer.front(); answer.pop();
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 4892
A,B,C,D = map(int, input().split())

k = B - A + 1

if A%C == 0:
    sc = B//C -A//C +1
else:
    sc = B//C -A//C

if A%D == 0:
    sd = B//D -A//D +1
else:
    sd = B//D -A//D    
    

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

cd = C*D//gcd(C,D)

if A%cd == 0:
    scd = B//cd -A//cd +1
else:
    scd = B//cd -A//cd    

print(int(k + scd -sc -sd))

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

bool Judge(int m, int index, vector<int> &A)
{
	if(m == 0){
		return true;
	}
	if(index == A.size() - 1){
	    if(m == A[index]){
	        return true;
	    }
	}else{
		int l = m - A[index];
		index++;
		if(Judge(m, index, A) || Judge(l, index, A)){
			return true;
		}
	}
	return false;
}

int main()
{ 
	int n, q; //n:??´??°???????????? q:???????????° 
	cin >> n;
	vector<int> A, M;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		A.push_back(a);
	}
	cin >> q;
	for(int i = 0; i < q; i++){
		int m;
		cin >> m;
		M.push_back(m);
	}
	for(int i = 0; i < q; i++){
		if(Judge(M[i], 0, A)){
			cout << "yes" << endl;
		}else{
			cout << "no"  << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3160
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
const long long MOD = 1e9 + 7;
using namespace std;

//main
int main(){
    int N; cin >> N;
    vector<int> L(N);
    rep(i,N) cin >> L[i];
    sort(ALL(L));
    int ans = 0;
    rep(i,N){
        for(int j=i+1; j<N-1; j++){
            auto it = lower_bound(L.begin(),L.end(),L[i]+L[j]);
            int index = it - (L.begin()+j+1);
            ans += index;
        }
    }
    cout << ans << endl;
}



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

using namespace std;

int main(){
  int r;
  cin >> r;
  if(r<2800){
    if(r<1200){
      cout << "ABC" << endl;
    }
    else{
      cout << "ARC" << endl;
    }
  }
  else{
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
def f_sugoroku(INF=float('inf')):
    from collections import deque
    N, M = [int(i) for i in input().split()]
    S = input()

    dp = [INF] * (N + 1)  # [v]: 頂点 v からゴール到達までに最低何回かかるか
    dp[N] = 0

    q = deque([0])
    for i in range(N - 1, -1, -1):
        while True:
            if len(q) == 0:
                return '-1'

            if q[0] != INF and len(q) <= M:
                break
            q.popleft()

        if S[i] == '0':
            dp[i] = q[0] + 1
        q.append(dp[i])

    ans = []
    current = 0
    rest = dp[0]  # ゴールまであと何回ルーレットを回すか
    while current < N:
        # dp の値が rest から 1 減るまでインデックスを進める
        i = 1
        rest -= 1  # ルーレットを回した
        while dp[current + i] != rest:
            i += 1

        # ルーレットの出目を答えに追加し、現在位置を進める
        ans.append(i)
        current += i
    return ' '.join(map(str, ans))

print(f_sugoroku())

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

using namespace std;

int main() {
    int A, B, C, K;

    cin >> A >> B >> C >> K;

    // int n1 = 1*A;
    // int n0 = 0*B;
    // int n01 = (-1)*C;

    int sum;

    if (A>K) {
        sum = 1*K;
        K = 0;
    }
    if (K==A) {
        sum = A;
        K -= A;
    }
    if (A<K) {
        sum = 1*A;
        K -= A;
    }

    if (K==B) K -= B;
    if (B<K) {
        K -= B;
    }

    if (0<K) {
        sum += (-1)*K;
    }



    // for (int i=0; i<K; i++) {
    //     if (A==K) {
    //         sum = A;
    //         break;
    //     }
    //     if (i<A) {
    //         sum++;
    //         continue;
    //     }
    //     if (i==A) i += (B==0) ? 0 : (B-1);

    //     sum--;
    // }

    cout << sum << endl;
}


Measured memory_bytes: 3624
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = int(readline())
    if N % 500 <= A:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9108
from itertools import accumulate
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    N, K = map(int, input().split())
    Ps = list(map(lambda x: int(x)-1, input().split()))
    Cs = list(map(int, input().split()))

    cycless = [[] for _ in range(N)]
    useds = [0] * N
    for no in range(N):
        if useds[no]: continue
        x = no
        while True:
            useds[x] = 1
            cycless[no].append(Cs[x])
            x = Ps[x]
            if x == no:
                break

#    for no in range(N):
#        print('# no:', no, '/ cycless[no]:', cycless[no], file=sys.stderr)

    ans = -float('inf')
    for no in range(N):
        if not cycless[no]: continue
        L = len(cycless[no])
        accCycles = list(accumulate([0]+cycless[no]+cycless[no]+cycless[no]))
        sumC = sum(cycless[no])
#        print('\n# no:', no, '/ sumC:', sumC, file=sys.stderr)
        if sumC > 0:
            num = K//L
            if num > 1:
                num -= 1
                score = -float('inf')
#                print('# K:', K, file=sys.stderr)
                for M in range(0, L + K%L+1):
                    for st in range(L):
                        s = accCycles[st+M] - accCycles[st]
                        if s > score:
                            score = s
                score += sumC * num
            else:
                score = -float('inf')
                for M in range(1, K+1):
                    for st in range(L):
                        s = accCycles[st+M] - accCycles[st]
                        if s > score:
                            score = s
        elif sumC == 0:
            num = K//L
            if num > 1:
                score = -float('inf')
                for M in range(0, 2*L+1):
                    for st in range(L):
                        s = accCycles[st+M] - accCycles[st]
                        if s > score:
                            score = s
            else:
                score = -float('inf')
                for M in range(1, K+1):
                    for st in range(L):
                        s = accCycles[st+M] - accCycles[st]
                        if s > score:
                            score = s
        else:
            score = -float('inf')
            for M in range(1, (K if K <= L else L)+1):
                for st in range(L):
                    s = accCycles[st+M] - accCycles[st]
                    if s > score:
                        score = s
        if score > ans:
            ans = score
#        print('# no:', no, '/ score:', score, file=sys.stderr)

    print(ans)


solve()


Measured memory_bytes: 75176
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<int> H(N);
    for(int i = 0; i < N; i++)
        cin >> H.at(i);

    bool t = true;
    int ans = 0;
    for(int i = 0;i < N; i++){
        for(int j = 0; j < i; j++){
            if(H[i] < H[j])
                t = false;
        }
        if(t) ans++;
        t = true;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

class DisjointSet
{
public:
    DisjointSet(int n)
    : p(vs32(n, -1))
    {}
    ~DisjointSet() {}

    bool same(int x, int y)
    {
        x = parent(x);
        y = parent(y);
        return x == y;
    }

    void unite(int x, int y)
    {
        int rx = parent(x);
        int ry = parent(y);

        if (rx == ry) return;

        if (p[rx] > p[ry]) swap(rx, ry);
        p[rx] += p[ry];
        p[ry] = rx;
    }

    int parent(int x)
    {
        int ret;
        if (p[x] < 0)
        {
            ret = x;
        }
        else
        {
            p[x] = parent(p[x]);
            ret = p[x];
        }
        return ret;
    }

    vs32 p;
};

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

    int n, q;
    cin >> n >> q;

    DisjointSet ds(n);
    char com;
    int x, y;
    rep (i, q)
    {
        cin >> com >> x >> y;
        if (com == '0')
        {
            ds.unite(x, y);
        }
        else if (com == '1')
        {
            cout << (ds.same(x, y) ? 1 : 0) << "\n";
        }
    }
    return 0;
}



Measured memory_bytes: 3268
#include <stdio.h>
#include <stdlib.h> 
#define NIL NULL


struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;


Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left, k);
  else return treeSearch(u->right, k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right); 
		       
  y = x->parent;
  while((y != NIL) && x == y->right ){
    x = y;
    y = y->parent;
    return y;         
  }

  
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if( (z->left == NIL) || z->right ==NIL )   y = z ;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL)x->parent = y->parent;
  if(y->parent == NIL)root =x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if( z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }

  z->parent = y;

  if(y == NIL)    root = z ;
  else if(z->key < y->key) y->left = z;
  else  y->right = z;


}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
  
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      
      inorder(root);
      // if(i != n-1)printf(" ");//空白処理
       printf("\n");
       
      preorder(root);
      // if(i != n-1) printf(" ");//空白処理
      printf("\n");
      
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20484
n=int(input())
v= list(map(int,input().split()))#価値
c= list(map(int,input().split()))#コスト
x=0#価値
y=0#コスト
for i in range(n):
    if v[i] > c[i]:
        x+=v[i]
        y+=c[i]
print(x-y)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
using namespace std;
int main(void){
    int N; cin >> N;
    vector<int> h(N);
    vector<int> f(N,0);
    int i = 0;
    int ans = 0;
    while(N > i){
        cin >> h[i];
        i++;
    }
    while(true){
        i = 0;
        int flag = false;
        int first = true;
        while(i < N) {
            if (f[i] == h[i] && flag) {
                flag = 0;
            } else if (flag == 0 && f[i] < h[i]) {
                flag = 1;
                f[i]++;
                ans++;
            } else if (h[i] > f[i]) {
                f[i]++;
            }
            i++;
        }
        int j = 0;
        int bflag = 1;
        while (j < N) {
            if (h[j] != f[j]) bflag = 0;
            j++;
        }
        if (bflag)  {
            cout << ans << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int main(){
    ll n;
    cin >> n;
    vvec<ll> a(n, vec<ll>(n));
    rep(i, n) rep(j, n) cin >> a[i][j];
    bool flag = true;
    ll ans = 0;
    vvec<int> cnct(n, vec<int>(n, 1));
    rep(i, n) cnct[i][i] = 0;
    rep(k, n) rep(i, n) rep(j, n) {
        if (a[i][j] > a[i][k] + a[k][j]) flag = false;
        else if (a[i][j] == a[i][k] + a[k][j] && i!=k && j!=k) cnct[i][j] = 0;
    }
    rep(i, n) rep(j, i) if(cnct[i][j]) ans += a[i][j];
    if (flag == false) cout << -1 << endl;
    else cout << ans << endl;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int N,M;

struct SCC{
    int N; // 頂点数
    vector<vi> e;  //辺（有向）
    vector<vi> re; //逆辺
    vector<bool> used; //探索フラグ
    vector<int> vs; //帰りがけ順序

    int K; // SCC後頂点数
    vector<int> cmp; //SCC前頂点->SCC後の頂点変換
    vector<set<int>> se;  //SCC後辺

    SCC( int N ) : N(N){
        e.resize(N);
        re.resize(N);
        used.resize(N);
        vs.resize(0);
        cmp.resize(N);
    }
    void add_edge( int v, int w ){
        e[v].push_back(w);
        re[w].push_back(v);
    }
    void dfs( int v ){
        used[v] = true;
        for( int to : e[v] ){
            if( !used[to] ) dfs(to);
        }
        vs.push_back(v);
    }
    // k = SCC後の扱いメモ
    void rdfs( int v, int k ){
        used[v] = true;
        cmp[v] = k;
        for( int to : re[v] ){
            if( !used[to] ) rdfs(to,k);
        }
    }
    // 返り値=強連結成分数
    int build(){
        vs.clear();
        used.assign(N,0);
        for( int i = 0; i < N; i++ ) if( !used[i] ) dfs(i);
        used.assign(N,0);
        K = 0;
        for( int i = N-1; i >= 0; i-- ) if( !used[vs[i]] ) rdfs(vs[i],K++);

        se.resize(K);
        for( int i = 0; i < N; i++ ){
            for( int to : e[i] ) if( cmp[i] != cmp[to] ) se[cmp[i]].insert(cmp[to]);
        }
        return K;
    }
};

int main() {

    Scd2(N,M);

    SCC scc(N);

    int v,w;
    Rep(i,M){
        Scd2(v,w);
        scc.add_edge(v,w);
    }

    int K = scc.build();

    vi dimin(K,0);
    vi dimout(K,0);
    for( int i = 0; i < K; i++ ){
        for( int j : scc.se[i] ){
            dimin[j]++;
            dimout[i]++;
            // printf ("%d,%d ", i, j);
        }
        // printf ("\n");
    }

    int inm = 0, outm = 0;
    Rep(i,K){
        if( !dimin[i] ) inm++;
        if( !dimout[i] ) outm++;
    }
    if( K == 1 ) inm = outm = 0;
    printf ("%d\n", max(inm,outm) );



    return 0;
}





Measured memory_bytes: 10160
#include <iostream>
#include <algorithm>
#include <vector>


#define MOD 1000000007
#define INTMAX 0x7fffffff
#define INTMIN 0x80000000
#define LLMAX 0x7fffffffffffffffLL
#define LLMIN 0x8000000000000000LL

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

using namespace std;
using ll = long long;

int main(){
    int A, B, C, D, E, F;
    int a, b, c, d, e, f;

    cin >> A >> B >> C >> D >> E >> F;

    int max_a = F / ( 100 * A ) + 10;
    int max_b = F / ( 100 * B ) + 10;
    int max_c = F * E / ( 100 * C ) + 10;
    int max_d = F * E / ( 100 * D ) + 10;

    int rw = 0, rs = 0;

    for (int a = 0; a <= max_a; ++a) {
        for (int b = 0; b <= max_b; ++b) {
            for (int c = 0; c <= max_c; ++c) {
                for (int d = 0; d <= max_d; ++d) {
                    int w = 100 * ( a * A + b * B ) + c * C + d * D;
                    int s = c * C + d * D;

                    if ( w > F )continue;
                    if ( s * ( 100 + E ) > E * w)break;
                    
                    if ( w == 0 )continue;
                    double p = (double)s / w;

                    if (rs * (w + s) < s * (rw + rs) || rw == 0 ){
                        rw = w;
                        rs = s;
                    }
                }
            }
        }
    }

    cout << rw << " " << rs << endl;
}


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

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    for (int i = 0; i < N; i++) {
      cin >> P[i];
    }
    for (int i = 0; i < N; i++) {
      cin >> Q[i];
    }

    vector<int> v(N);
    for (int i = 0; i < N; i++) {
      v[i] = i + 1;
    }

    int cnt = 0;
    int a = 0;
    int b = 0;
    do {
      if (P == v) {
        a = cnt;
      }
      if (Q == v) {
        b = cnt;
      }
      cnt ++;
    } while(std::next_permutation(v.begin(),v.end()));
    cout << abs(a - b) << endl;

    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int x = 0;
    while (true) {
        int y = n - x * 4;
        if (y < 0) {
            cout << "No" << endl;
            return 0;
        }
        if (y % 7 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
        x++;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int k;
ll now; 
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>k;
	rep(i,k)
	{
		now*=10;
		now+=7;
		now%=k;
		if(now==0)
		{
			cout<<i+1<<endl;
			return 0;
			}	
	}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 3604