akhauriyash/Code-Regression huggingface dataset:
#if 0
date +%Y.%m.%d

对每个 a[i] = x 记 b[x] = i ，那么 a 交换的条件在 b 上就是：
交换两个相邻且权值差不小于 K 的 b 。
当 b 字典序最小时对应的 a 字典序一定最小。

那么对于权值差小于 K 的 b[i], b[j] ，它们的相对位置是不会变的。
根据这个关系建图，从 i 连边连向 j ，那么问题转换为求拓扑序。
然而边数是 O(N K) 的，无法接受。

事实上暴力连边连了许多无用边，例如 a -> b -> c 且 a -> c 中，
a -> c 这条边就毫无意义。
每个点考虑出边，假设 x 在 (x, x + k) 能连向 y1, y2, ... yy ，
那么 y1 一定能连向 y2, y3, ... yy 。
所以 x 只向 y1 连边，即向可连边集合中的最小值连边即可。
用线段树维护这个最小值。
#endif
#include <cstdio>
#include <algorithm>
#include <queue>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef std::pair<int, int> Par;

inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 500005;
int a[maxn], b[maxn];
int val[maxn << 2];
int head[maxn], nxt[maxn << 1], to[maxn << 1], hp;
int in[maxn];

inline void add(int u, int v) {
	/* debug("%d -> %d\n", u, v); */
	nxt[++ hp] = head[u];
	head[u] = hp;
	to[hp] = v;
	in[v] ++;
}

void modify(int now, int l, int r, int p, int x) {
	if(l == r) {
		val[now] = x;
		return ;
	}
	int mid = (l + r) >> 1;
	if(p <= mid)
		modify(now << 1, l, mid, p, x);
	else
		modify(now << 1 | 1, mid + 1, r, p, x);
	val[now] = std::min(val[now << 1], val[now << 1 | 1]);
}

int query(int now, int L, int R, int l, int r) {
	if(r < L or l > R)
		return maxn;
	if(l <= L and R <= r)
		return val[now];
	int mid = (L + R) >> 1;
	return std::min(query(now << 1, L, mid, l, r),
			query(now << 1 | 1, mid + 1, R, l, r));
}

int main() {
	int n = input(), k = input();

	int len = 1;
	while(len < n)
		len <<= 1;

	for(int i = 1; i <= n; i ++)
		b[a[i] = input()] = i;

	for(int i = 1; i <= len; i ++)
		modify(1, 1, len, i, maxn);

	for(int i = n; i; i --) {
		int j;
		j = query(1, 1, len, b[i] - k + 1, b[i]);
		if(j < maxn)
			add(b[i], b[j]);
		j = query(1, 1, len, b[i], b[i] + k - 1);
		if(j < maxn)
			add(b[i], b[j]);
		modify(1, 1, len, b[i], i);
	}

	std::priority_queue<int> que;

	for(int i = 1; i <= n; i ++)
		if(not in[i])
			que.push(- i);

	int p = 0;
	while(not que.empty()) {
		int u = - que.top();
		que.pop();
		b[++ p] = u;
		for(int i = head[u]; i; i = nxt[i]) {
			in[to[i]] --;
			if(not in[to[i]])
				que.push(- to[i]);
		}
	}

	for(int i = 1; i <= n; i ++)
		a[b[i]] = i;

	for(int i = 1; i <= n; i ++)
		printf("%d\n", a[i]);
}


Measured memory_bytes: 25716
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int h, w;
	cin >> h >> w;
	vector<vector<char>> c(h, vector<char>(w));
	rep(i, h) rep(j, w) cin >> c[i][j];
	vector<vector<int>> ans(h, vector<int>(w, INF));
	if (c[0][0] == '.') ans[0][0] = 0;
	else ans[0][0] = 1;
	rep(i, h) {
		rep(j, w) {
			if (i != 0) {
				int d = 0;
				if (c[i][j] == '#'&&c[i - 1][j] == '.') d++;
				chmin(ans[i][j], ans[i - 1][j] + d);
			}
			if (j != 0) {
				int d = 0;
				if (c[i][j] == '#'&&c[i][j - 1] == '.') d++;
				chmin(ans[i][j], ans[i][j - 1] + d);
			}
		}
	}
	cout << ans[h - 1][w - 1] << endl;
}

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

int n,x;
ll sol=0;
int A[200005];
map<int,int> M; //diff

int main() {
    cin >> n;
    for (int i=1;i<=n;i++) {
        cin >> A[i];
        M[i-A[i]]++;
    }

    for (int i=1;i<=n;i++) {
        x=i+A[i];
        sol+=M[x];
        if (A[i]==0) sol--;
    }
    cout << sol;
}



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

const int maxn = 1e5 + 10, lg = 20;
int par[maxn][lg], maxh[maxn], h[maxn], dp[maxn];
vector <int> adj[maxn];

int get_par(int v, int d){
	for (int i = 0; i < lg; i ++){
		if (d & (1 << i))
			v = par[v][i];
	}
	return v;
}

int lca(int v, int u){
	if (h[v] > h[u]){
		swap(v, u);
	}
	u = get_par(u, h[u] - h[v]);
	if (v == u)
		return v;
	for (int i = lg - 1; i >= 0; i --){
		if (par[v][i] != par[u][i]){
			v = par[v][i];
			u = par[u][i];
		}
	}
	return par[v][0];
}

void dfs(int v, int p = -1){
	fill(par[v], par[v] + lg, -1);
	par[v][0] = p;
	for (int i = 1; i < lg; i ++){
		if (par[v][i - 1] == -1)
			break;
		par[v][i] = par[par[v][i - 1]][i - 1];
	}
	maxh[v] = 0;
	for (auto u: adj[v]){
		if (u != p){
			h[u] = h[v] + 1;
			dfs(u, v);
			maxh[v] = max(maxh[v], 1 + maxh[u]);
		}
	}
}

void dfs2(int v, int p = -1){
	int mx1 = -1e5, mx2 = -1e5;
	for (auto u: adj[v]){
		if (u != p){
			if (maxh[u] >= mx1){
				mx2 = mx1;
				mx1 = maxh[u];
			}
			else{
				mx2 = max(mx2, maxh[u]);
			}
		}
	}
	for (auto u: adj[v]){
		if (u != p){
			dp[u] = dp[v] + 1;
			if (mx1 == maxh[u]){
				dp[u] = max(dp[u], mx2 + 2);
			}
			else{
				dp[u] = max(dp[u], mx1 + 2);
			}
			dfs2(u, v);
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	h[0] = 0;
	int n, x, y;
	cin >> n >> x >> y;
	for (int i = 0; i < n - 1; i ++){
		int v, u;
		cin >> v >> u;
		v --;
		u --;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	dfs(0);
	dfs2(0);
	x --;
	y --;
	swap(x, y);
	int z = lca(x, y);
	int d = h[x] + h[y] - 2 * h[z];
	int d2 = (d - 1) / 2;
	if (x == y) {
		cout << 0;
		return 0;
	}
	int ans = 0;
	if (h[y] >= h[x]){
		y = get_par(y, d2);
		ans = maxh[y] + d - d2;
	}
	else{
		y = get_par(x, d - d2 - 1);
		ans = dp[y] + d - d2 - 1;
	}
	ans--;
	cout << ans;
}


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

int main(){
    int k, t;
    cin >> k >> t;

    int max_a = 0;
    for (auto i = 0; i < t; i++) {
        int a; cin >> a; max_a = max(max_a, a);
    }
    cout << max(max_a - 1 - (k - max_a), 0) << endl;
    return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <climits>

long long int solve(std::vector<long long int>& B)
{
    std::reverse(B.begin(), B.end());
    long long int sum = 0;
    for(int i = 0; i < B.size()-1; i++)
    {
        long long int temp = std::min(B[i], B[i+1]);
        sum += temp;
    }
    
    return sum;
}

int main()
{
    int N; std::cin >> N;
    std::vector<long long int> B(N+1, 0);
    B[0] = INT_MAX; B[N] = INT_MAX;
    
    for(int i = 1; i < N; i++)
    {
        std::cin >> B[i];
    }
    
    long long int ans = solve(B);

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

Measured memory_bytes: 3608
N = int(input())
S = [int(input()) for _ in range(N)]

S.sort()
ans = sum(S)
if ans%10 != 0:
    print(ans)
    exit()
for x in S:
    if (ans-x)%10 != 0:
        print(ans-x)
        exit()
print("0")

Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
f=[]
od=[]
ev=[]

for i in range(n):
  if a[i]%4==0:
    f.append(a[i])
  elif a[i]%2==1:
    od.append(a[i])
  else:
    ev.append(a[i])
if len(f)>=len(od) and ev!=[]:
  print('Yes')
elif len(f)<len(od) and ev!=[]:
  print('No')
elif ev==[] and len(f)>=len(od)-1:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 14252
def reduce_num(x, y):
  if x>=y:
    string_num.insert(0, x%y)
    reduce_num(x//y, y)
  else:
    string_num.insert(0, x)

N, K = map(int, input().split())
string_num = []
reduce_num(N, K)
print(len(string_num))

Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int asort(const void *A,const void *B){
    return *(long long*)A>*(long long*)B?1:0;
}

int dsort(const void *A,const void *B){
    return *(long long*)A<*(long long*)B?1:0;
}

long long gcd(long long A,long long B){
    return B?gcd(B,A%B):A;
}

long long min(long long A,long long B){
    return A<B?A:B;
}

int main(void){
    char s[100500];
    scanf("%s",s);
    int count0=0,count1=0,ans=0;
    for (int i=0; i<strlen(s); i++){
        if (s[i]=='1'){
            if (count0==0){
                count1++;
            } else {
                count0--;
                ans+=2;
            }
        } else {
            if (count1==0){
                count0++;
            } else {
                count1--;
                ans+=2;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
string s;
int a[27]; 
int main()
{
	int i,cnt=0;
	cin>>s;
	for(i=0;i<s.size();i++)
	{
		a[s[i]-'A']++;
	}
	for(i=0;i<26;i++)
	{
		if(a[i]==2)
		{
			cnt++;
		}

	}
	if(cnt==2)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

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

#define long long long int
using namespace std;


#ifdef JUDGE
std::ifstream cin("input.txt");
std::ofstream cout("output.txt");
#else
using std::cin;
using std::cout;
#endif




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    long res = 0;
    for (int i = 0; i <= n; ++i) {
        if (i % 15 == 0 || i % 5 == 0 || i % 3 == 0) {
            continue;
        }
        res += i;
    }

    cout << res;
    return 0;
}








Measured memory_bytes: 3608
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,t;cin>>n>>t;
    vector<int>c(n),t1(n);
    for(int i=0;i<n;i++)
        cin>>c[i]>>t1[i];
    int ans=INF;bool abc=false;
    for(int i=0;i<n;i++)
        if(t1[i]<=t){
            chmin(ans,c[i]);
            abc=1;
        }
            
    
    if(abc==1)
    cout<<ans<<endl;
    else
        cout<<"TLE"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


/*  AGC ACG GAC ATGC AGGC ACGC AGAC AGTC AGGC  */


Measured memory_bytes: 256
from collections import Counter 
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
import bisect
import sys
#import sympy
sys.setrecursionlimit(10**6)


def bfs(s,n,node):
    #頂点が探索済みかどうかのチェック配列
    check=[False for _ in range(n)]
    check[s]=True
    #次見る頂点を格納するキュー
    queue=deque([s])
    visited_num=1

    #問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color=[-1 for _ in range(n)]
    color[s]=0
    
    while visited_num<n:
        #グラフが全連結ではない場合
        if len(queue)==0:
            #空配列を返す
            #現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex=queue.popleft()
        #インデックスがない場合は
        for next_vertex in node[now_vertex]:


            if check[next_vertex]==True:
                continue

            queue.append(next_vertex)
            check[next_vertex]=True

            #問題固有の計算
            color[next_vertex]=color[now_vertex]+1
            visited_num+=1

    return color

#n=int(input())z
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))



n=int(input())
#n,m=input_list()
a=input_list()
f_num=60
z_arr=[0 for _ in range(f_num)]
o_arr=[0 for _ in range(f_num)]
#a=[bin(i)[2:].zfill(f_num) for i in tmp]
for each in a:
    cal=bin(each)[2:].zfill(f_num)
    for i in range(f_num):
        if (cal[i])=="0":
            z_arr[i]+=1
        else:
            o_arr[i]+=1
mod=10**9+7
ans=0



for keta_i in range(f_num):
    cal=((z_arr[keta_i]*o_arr[keta_i])%mod*pow(2,f_num-keta_i-1,mod))%mod
    ans+=cal
    ans%=mod

ans%=mod
print(ans)

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

#define ll long long
#define ld long double
#define ii pair<int ,int >
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);

map<int ,int >mp;

int main(){
    SPEED
    string s;
    cin>>s;
    for(auto a : s){
        mp[a]++;
    }
    for(auto x : mp){
        if(x.S&1){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

count = 0
for i in range(n):
    if a[i] >= b[i]:
        a[i] = a[i] - b[i]
        count = count + b[i]
        b[i] = 0
    else:
        b[i] = b[i] - a[i]
        count = count + a[i]
        a[i] = 0
        count = count + min(a[i + 1], b[i])
        a[i + 1] = a[i + 1] - min(a[i + 1], b[i])

print(count)

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

int main() {
  int N;
  cin >> N;
  vector<int> s(N);
  for (int i=0; i<N; i++) 
    cin >> s.at(i);
  
  sort(s.begin(), s.end());
  reverse(s.begin(), s.end());
  int x=1;
  int f=s.at(0);
  for (int i=0; i<N; i++) {
    if (f > s.at(i)) {
      f = s.at(i);
      x += 1;
    }
  }
  cout << x << endl;
}


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

int main(){
    string s;
    cin >> s;
    int n=0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i]=='+') n++;
        else n--;  
    }
    cout << n << endl;

    return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())

ans = 10**20

if (b-a)%2==0:
    ans = min((b-a)//2, n-a, b-1)
else:
    ans = min(n-b+((b-a)+1)//2,a+(b-a-1)//2)

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define erep(i, n) for (int i = 0; i <= (int)(n); i++)

int main() {
    string s; cin >> s;
    map<char, int> m;
    rep (i, 4) m[s[i]]++;
    bool flag = true;
    for (auto v : m) {
        if (v.second != 2) flag = false;
    }
    cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
n=int(input())
vlis=[int(i) for i in input().split()]
odd=vlis[0::2]
even=vlis[1::2]
import collections 
odd_=collections.Counter(odd).most_common(2)
even_=collections.Counter(even).most_common(2)
 
if odd_[0][0]==even_[0][0]:
    if len(odd_)==1 and len(even_)==1:
        print(int(len(vlis)/2))
    elif len(even_)==1:
        print(len(vlis)-even_[0][1]-odd_[1][1])
    elif len(odd_)==1:
        print(len(vlis)-odd_[0][1]-even_[1][1])
    else:
        if odd_[0][1]+even_[1][1]>=odd_[1][1]+even_[0][1]:
            print(len(vlis)-odd_[0][1]-even_[1][1])
        else:
            print(len(vlis)-odd_[1][1]-even_[0][1])
else:
    print(len(vlis)-odd_[0][1]-even_[0][1])

Measured memory_bytes: 15844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		double firstinput;
		double secondinput;
		double product;
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()){
			firstinput = scanner.nextDouble();
			secondinput = scanner.nextDouble();
			product = firstinput * secondinput;
			while(true){
				double tmpdouble = firstinput % secondinput;
				if(tmpdouble == 0){
					break;
				}
				firstinput = secondinput;
				secondinput = tmpdouble;
			}
			System.out.println((int)secondinput + " " + (int)(product / secondinput));
		}
	}
}

Measured memory_bytes: 20292
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int>a(n),b(n),c(n);
    for(int i=0;i<n;i++)
      cin>>a[i]>>b[i]>>c[i];
    vector<vector<int> >dp(3,vector<int>(n,0));
    dp[0][0]=a[0];
    dp[1][0]=b[0];
    dp[2][0]=c[0];
	for(int i=1;i<n;i++)
	{
          dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
          dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
          dp[2][i]=max(dp[1][i-1],dp[0][i-1])+c[i];       
	}
  cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<"\n";
  }


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

int main() {
	int N, M;

	cin >> N >> M;

	int x;
	for (int i = 0; i < M; i++) {
		cin >> x;
		N -= x;
	}

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

Measured memory_bytes: 3196
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B;
    cin>>A>>B;
    if(A+B >= A-B && A+B >= A*B)
    cout<<A+B<<endl;
    else if(A-B >= A+B && A-B >= A*B)
    cout<<A-B<<endl;
    else
    cout<<A*B<<endl;
    return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
const int N=1000,M=1000;
int n,m;
char a[N+1][M+5];
int dp[N+1][M+1];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i]+1;
	dp[1][1]=1;//边界 
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(i!=1||j!=1)//转移 
		if(a[i][j]=='.')dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
	cout<<dp[n][m];//目标 
	return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

set<ll>s;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
        s.insert(n);
        s.insert(m);
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}

bool is_prime(int64_t x) {
  for(int64_t i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}
template<typename T>
vector<T>divisor(T n){//約数列挙
    vector<T>v;
    for(T i=1;i*i<=n;++i){
        if(n%i==0){
            v.push_back(i);
        if(i*i!=n)v.push_back(n/i);
        }
    }
    sort(v.begin(),v.end());
    return v;
}
map< ll, int > prime_factor(int64_t n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}



 
void solve(){
    ll a,b;
    cin>>a>>b;
    ll ans=gcd(a,b);
    ll cnt=0;
    map<ll,int>mp=prime_factor(ans);
    cout<<mp.size()+1<<"\n";
}
 
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 256
def f(n):
    a=0
    while n%2==0:
        n//=2
        a+=1
    return a    
n,m,*a=map(int,open(0).read().split())
c=[f(i) for i in a]
if sum(c)!=c[0]*n:
    print(0)
    exit()
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a=list(set(a))
a=[i//(2**c[0]) for i in a]
b=a[0]
for i in a:
    b=lcm(i,b)
    if b*(2**c[0])>2*m:
        print(0)
        exit()
b*=2**c[0]    
print(0 if b//2>m else (m-b//2)//b+1)  

Measured memory_bytes: 14476
var
 s:string;
 ch:char;
 i:longint;
 a:array['a'..'z'] of longint;
begin
 readln(s);
 for i:=1 to length(s) do inc(a[s[i]]);
 for ch:='a' to 'z' do if a[ch]>1 then begin writeln('no');exit; end;
 writeln('yes');
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
using namespace std::chrono;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#ifdef LL
const ll inf = 1e9;
#else 
const ll inf = 1e18;
#endif

const int mod = 1e9 + 7;
const int mod2 = 998244353;

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

high_resolution_clock::time_point curTime() { return high_resolution_clock::now(); }
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);} //Just add this as a third argument to sort() while sorting an array of pairs; NO NEED FOR ANY ARGUMENTS;
template <typename T>
T fact(T a, T mod){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=mod;} return res; }
template <typename T>
ll powmod(T a,T b,ll m){ ll ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
ll power(T a, T b){ ll ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}
template <typename T>
T gcd(T a,T b){ return (b?__gcd(a,b):a); }
template <typename T>
T lcm(T a, T b){ return (a*(b/gcd(a,b))); }
template <typename T>
T cl(T a, T b){ return (a+b-1)/b; }
template <typename T>
T set_bits(T a)
{ return __builtin_popcount(a); }
template <typename T>
T add_self(T& a, T b, T mod){ a+=b; if(a>=mod){ a-=mod; } }
template <typename T>
T to_upper(T s){ transform(s.begin(), s.end(), s.begin(), ::toupper); return s; }
template <typename T>
T to_lower(T s){ transform(s.begin(), s.end(), s.begin(), ::tolower); return s; }



int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    auto startTime = curTime();

    int n;
    cin>>n;

    vi a(n),b(n),c(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }

    vvi dp(n+1, vi(3));
    dp[1][0] = a[0];
    dp[1][1] = b[0];
    dp[1][2] = c[0];

    for(int i=2;i<=n;i++)
    {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i-1];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i-1];
        dp[i][2] = max(dp[i-1][1], dp[i-1][0]) + c[i-1];
    }

    cout<<max(max(dp[n][0],dp[n][1]), dp[n][2])<<endl;

    auto stopTime = curTime();
    auto duration = duration_cast<microseconds>(stopTime - startTime);
    //cout<<"Program ran for "<<(ld)duration.count()/1e6<<" "<<"seconds"<<endl;
}


Measured memory_bytes: 11088
#include<bits/stdc++.h>
#define N 200050
#define M 200
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N
#define MOD mod
using namespace std;
int ar[N];
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    int n; cin>>n;
    int ans = 0;
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                ar[(i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(i*k)]++;
            }
        }
    }
    for(int i=1;i<=n;i++)
        cout<<ar[i]<<" ";
  	return 0;
}



Measured memory_bytes: 4076
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  if (A%2==0||B%2==0||C%2==0) cout << 0 << endl;
  else {
    ll num = max(A, max(B, C)), ans;
    if (num==A) ans = B*C;
    else if (num==B) ans = C*A;
    else ans = A*B;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n, m;
    cin >> n >> m;
    if (n % 2 == 1) {
    	for (int i = 1; i <= m; i++)
    		cout << i << " " << n - i << endl;
    	return 0;
    }
    int mx = (n - 1) / 2;
    for (int i = 1; i <= m; i++) {
    	if (i <= mx / 2)
	    	cout << i << " " << n - i << endl;
	    else cout << i << " " << n - i - 1 << endl;
	}
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[114514],cnt[114514];
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
			cin>>a[i];
			cnt[a[i]]++;
	}
	ll ans=1,mod=998244353;
	if(a[0]==0||cnt[0]>1){
		for(int i=1;i<n;i++){
			ans*=cnt[a[i]-1];
			ans%=mod;
		}
	}else ans=0;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] taps = sc.next().toCharArray();
        List<Character> odd = Arrays.asList('R', 'U', 'D');
        List<Character> even = Arrays.asList('L', 'U', 'D');
        for (int i = 0; i < taps.length; i++) {
            if ((i + 1) % 2 == 1) {
                if (!odd.contains(taps[i])) {
                    System.out.println("No");
                    return;
                }
            } else {
                if (!even.contains(taps[i])) {
                    System.out.println("No");
                    return;
                }
            }
        }

        System.out.println("Yes");
    }
}

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

using namespace std;

bool comp(string s,string t){
	bool ret=true;
	
	if(s.size()!=t.size()){
		ret=false;
		cout<<"ERROR "<<s<<" "<<t<<endl;
	}
	
	for(int i=0;i<s.size();i++){
		if(s.at(i)!='?' && s.at(i)!=t.at(i)){
			ret=false;
			break;
		}
	}
	
	return ret;
}

int main(){
	string s,t;
	cin>>s>>t;
	priority_queue<string> hoge;
	
	if(s.size()<t.size()){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	
	for(int l=0;l<=s.size()-t.size();l++){
		int r=l+t.size();
		
		if(comp(s.substr(l,t.size()),t)){
			hoge.push(s.substr(0,l)+t+s.substr(r,s.size()-r));
		}
	}
	
	if(hoge.size()==0){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	
	priority_queue<string,vector<string>,greater<string>> ans;
	
	while(!hoge.empty()){
		string pre=hoge.top();
		hoge.pop();
		
		for(int i=0;i<pre.size();i++){
			if(pre.at(i)=='?') pre.at(i)='a';
		}
		
		ans.push(pre);
	}
	
	cout<<ans.top()<<endl;
	
	return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ITP1_4_C
//
//  Created by ??±??°?????? on 2015/09/27.
//  Copyright ?? 2015??´ HamadaShogo. All rights reserved.
//

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    int a, b;
    char op;
    
    while (1){
        cin >> a >> op >> b;
        switch (op) {
            case '+':
                cout << a+b << '\n';
                break;
            case '-':
                cout << a-b << '\n';
                break;
            case '*':
                cout << a*b << '\n';
                break;
            case '/':
                cout << a/b << '\n';
                break;
            default:
                break;
        }
        if (op == '?') {
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(void)
{

  int i,mountain[10],max[3];

  max[0] = max[1] = max[2] = 0 ;
  
  for(i=0;i<10;i++){
    scanf("%d",&mountain[i]);
    if(mountain[i]>max[0]){
      max[2] = max[1] ;
      max[1] = max[0] ;
      max[0] = mountain[i] ;
    }
    else if(mountain[i]>max[1]){
      max[2] = max[1] ;
      max[1] = mountain[i] ;
    }
    else if(mountain[i]>max[2])
      max[2] = mountain[i] ;
  }

  printf("%d\n%d\n%d\n",max[0],max[1],max[2]);

  return 0;
}

Measured memory_bytes: 600
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

h,n = MI()
ab = LI(n)

# dp[i][j]:i番目までの魔法の中から削る体力がj以上になるように選んだ時の消耗魔力の最小値
dp = [ [INF]*(h+1) for _ in range(n+1) ]
dp[0][0] = 0

for i in range(n):
    a = ab[i][0]
    b = ab[i][1]
    for j in range(h+1):
        if j<a:
            dp[i+1][j] = min( dp[i][j], b )
        else:
            dp[i+1][j] = min( dp[i][j], dp[i+1][j-a]+b )
# print(dp)
print(dp[n][h])

Measured memory_bytes: 233308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll x[5]; zep(i, 0, 5)cin >> x[i];
	
	zep(i, 0, 5){
		if(x[i] == 0){
			print(i + 1)
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3568
// finish date: 2019/2/22

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;

//足し算
int add(int a, int b) {
    return (int) (((ll) a + b + bigmod) % bigmod);
}

//引き算
int sub(int a, int b) {
    return (int) (((ll) a - b + bigmod) % bigmod);
}

//掛け算
int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}


int main() {
    int H, W;
    cin >> H >> W;
    vvc a(H, vc(W));
    rep(i, H) {
        rep(j, W) {
            cin >> a[i][j];
        }
    }

    vvi dp(H, vi(W, 0));
    dp[0][0] = 1;
    FOR(i, 1, H) if (a[i][0] == '.') dp[i][0] = dp[i - 1][0];
    FOR(i, 1, W) if (a[0][i] == '.') dp[0][i] = dp[0][i - 1];
    FOR(i, 1, H) {
        FOR(j, 1, W) {
            if (a[i][j] == '.') dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]);
        }
    }

    cout << dp[H - 1][W - 1] << endl;
    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

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

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint Q, H, S, D; cin >> Q >> H >> S >> D;
    lint N; cin >> N;
    lint res;
    if (N % 2 == 0) {
        res = N * min({8 * Q, 4 * H, 2 * S, D}) / 2;
    } else {
        res = (N - 1) / 2 * min({8 * Q, 4 * H, 2 * S, D}) + min({4 * Q, 2 * H, S});
    }
    cout << res << "\n";
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int h,w;
char c[100][100];
bool isw[100];
int main()
{
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++)
	{
		bool tf=false;
		for(int j=0;j<w;j++)
		{
			scanf(" %c",&c[i][j]);
			if(!tf || !isw[j])
				if(c[i][j]=='#')
					tf=isw[j]=true;
		}
		if(!tf)
		{
			i--;
			h--;
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
			if(isw[j])
				printf("%c",c[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
# MOD = 10 ** 9 + 7
MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n = ni()
    a = na()

    ans = 0
    tmp_max = 0

    for ai in a:
        if ai > tmp_max:
            tmp_max = ai
        else:
            ans += tmp_max - ai

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 33948
#include <stdio.h>
#define A '0'
int main(void){
    char s[10];
    int n,m;
    scanf("%s",s);
    n=(s[0]-A)*10+(s[1]-A);
    m=(s[2]-A)*10+(s[3]-A);
    if((n>12)+(m>12)+(n<1)+(m<1)>=2){
        puts("NA");
    }else if(n>12||n<1){
        puts("YYMM");
    }else if(m>12|m<1){
        puts("MMYY");
    }else{
        puts("AMBIGUOUS");
    }
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef priority_queue<int> P_QI;
typedef priority_queue<string> P_QS;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector< int > :: iterator $$;

#define $ vector< int > :: iterator

#define m_p make_pair
#define p_b push_back
#define rep(i, n) for(auto i=0; i<(n); i++)
#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)

#define forv(i,v) rep(i,SZ(v))
#define forit(i,s) for(auto i=(s).begin();i!=(s).end();++i)

#define Boost ios_base::sync_with_stdio(0); cin.tie(0)
#define all(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define _ <<" "<<

const int MOD = 1e9+7;
const int inf = 1e9+9;
const long long INF = 1e18+3;
const ld eps = 1e-9;
const ld PI=acos(-1.0);


int main() {
 Boost;
 int n,a,f=1,ans=0;
 cin>>n;
 rep(i,n) {
    cin>>a;
    if(i+1==a){
        ans++;
        f--;
        if(f==-1) ans--,f=1;
    }
    else f=1;
 }
 cout<<ans<<endl;

 return 0;
}


Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val MOD = 1e9.toInt + 7

  // 素数modulo `p` の世界での割り算
  // (x ^ n) % mod
  def repeatSquares(x: Long, n: Int, mod: Int): Long = {
    if(n == 0)
      1
    else if(n % 2 == 0)
      repeatSquares(x*x % mod, n/2, mod)
    else
      (x * repeatSquares(x*x % mod, n/2, mod)) % mod
  }


  // a / b
  def modDiv(a: Int, b: Int, p: Int): Long = {

    val numer = a % p
    val denom = repeatSquares(b, p-2, p)

    (numer * denom) % p
  }

  val N = in.next().toInt
  val X = in.next().toInt
  val _S = new Array[Int](N)

  for (i <- 0 until N)
    _S(i) = in.next().toInt


  //
  val S = 0 +: _S.sorted.reverse
  val dp = Array.ofDim[Long](N+1, X+1)
  for (n <- 0 to N; x <- 0 to X)
    dp(n)(x) = -1L

  def calc(i: Int, X: Int): Long = {
    if(i == N)
      X % S(i)
    else if(dp(i)(X) != -1L)
      dp(i)(X)
    else {
      val r1 = (modDiv(1, N+1-i, MOD) * calc(i+1, X % S(i))) % MOD
      val r2 = (modDiv(N-i, N+1-i, MOD)) * calc(i+1, X) % MOD
      dp(i)(X) = (r1 + r2) % MOD
      dp(i)(X)      
    }
  }

  def fact(n: Long, acc: Long): Long =
    if(n == 1)
      acc
    else
      fact(n-1, (n*acc) % MOD)

  val expected = calc(1, X) % MOD
  val ans = expected * fact(N, 1L)
  println(ans % MOD)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



Measured memory_bytes: 224560
#include<iostream>
#include<cmath>
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
#include<cstring>
#include<vector>
#define MAXN 100005
using namespace std;
int a[2*MAXN],n;
bool check(int mid)
{
	for(int i=0;i<n-1;i++)
	{
		if((a[n-i]>mid&&a[n-i-1]>mid)||(a[n+i]>mid&&a[n+i+1]>mid))
			return false;
		if((a[n-i]<=mid&&a[n-i-1]<=mid)||(a[n+i]<=mid&&a[n+i+1]<=mid))
			return true;
	}
	return a[1]<=mid;
}
int ef(int l,int r)
{
	int mid;
	while(l<r)
	{
		mid=(l+r)>>1;
		if(check(mid))
			r=mid;
		else
			l=mid+1;
	}
	return l;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=2*n-1;i++)
		scanf("%d",&a[i]);
	printf("%d",ef(1,2*n-1));
    return 0;
}


Measured memory_bytes: 1024
n, m = map(int, input().split())
road = [[] for _ in range(n)]
for _ in range(m):
    i, j = map(int, input().split())
    road[i-1].append(j-1)
    road[j-1].append(i-1)

# BFS
from collections import deque
ans = [-1] * n
todo = deque()
todo.append(0)
while len(todo) > 0:
    i = todo.popleft()
    for j in road[i]:
        if ans[j] > -1:
            continue
        ans[j] = i
        todo.append(j)

print('Yes')
for i in range(1, n):
    print(ans[i] + 1)

Measured memory_bytes: 34052
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:


const int CONTEST_TYPE = 26;
int D;
int c[CONTEST_TYPE], s[365][CONTEST_TYPE];

void input() {
	cin >> D;

	rep(i, CONTEST_TYPE) {
		cin >> c[i];
	}

	rep(i, D) rep(j, CONTEST_TYPE) {
		cin >> s[i][j];
	}
}

int score(const vector<int> &type) {
	const int DAY = type.size();
	vector<int> last(CONTEST_TYPE, 0);

	int ret = 0;
	rep(i, DAY) {
		const int day = i + 1;
		const int type_idx = type[i] - 1;

		ret += s[i][type_idx];
		last[type_idx] = day;

		rep(j, CONTEST_TYPE) {
			ret -= c[j] * max(day - last[j], 0);
		}
	}

	return ret;
}


int main(void){
	input();
	vector<int> t;
	rep(i, D) {
		int elem;
		cin >> elem;
		t.push_back(elem);
		cout << score(t) << endl;
	}
	return 0;
}

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int memo[1000010];
int all[1000010];

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

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

	for(int i = 1;i <= 1000000;i++){
		for(int j = i;j <= 1000000;j+=i){
			all[j] += memo[i]; 
		}
	}

	int ans = 0;
	for(int i = 0;i < n;i++){
		if(all[a[i]] == 1) ans++;
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first
#define psi pair<string,int>

int n,m;
int k[15],p[15];
vector<int> s[15];

bool check(ll x){
 for(int i=0;i<m;++i){
    ll sum=0;
    for(int j=0;j<k[i];++j){
       if((x & (1<<s[i][j]))!=0){
        ++sum;
       }
    }
    if(sum%2!=p[i]){
        return false;
    }
 }
 return true;
}

int main(){
  cin >> n >> m;
  for(int i=0;i<m;++i){
    cin >> k[i];
    for(int j=0;j<k[i];++j){
        int y;
        cin >> y;
        s[i].push_back(y-1);
    }
  }
  for(int i=0;i<m;++i){
    cin >> p[i];
  }
  ll x=0;
  ll num=0;
  for(x;(x < ( 1 << n ) );++x){
   // cout << endl;
    num+=check(x);
  }
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
const int MAX_V = 999999;
int main(){
int prime[MAX_V+1]={0};
int sum[MAX_V+2]={0};
int i, k, v ,n;
  for(i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for(i = 2; i*i <= MAX_V; i++) {
    if(prime[i]) {
      for(k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  for(i=0 ;i<=MAX_V+1 ;i++){
    sum[i+1] += sum[i] + prime[i];
  }

  while(scanf("%d" ,&n)!=EOF){
     printf("%d\n" ,sum[n+1]);
  }
  return 0;
}

Measured memory_bytes: 10444