akhauriyash/Code-Regression huggingface dataset:
module Weighted_UF
    
    integer, allocatable, dimension(:) :: par, rank, diff_weight

    contains

    subroutine init(N)
        integer :: N
        allocate(par(N), rank(N), diff_weight(N))
        do i = 1, N
            par(i) = i
            rank(i) = 0
            diff_weight(i) = 0
        end do
    end subroutine

    recursive function root(x) result (res)
        integer :: x, res
        if (par(x) == x)then 
            res = x
        else
            res = root(par(x))
            diff_weight(x) = diff_weight(x) + diff_weight(par(x))
            par(x) = res
        end if
    end function

    function weight(x) result (res)
        integer :: x, res, r
        res = diff_weight(x)
        r = root(x)
    end function

    function same(x, y) result (res)
        integer :: x, y
        logical :: res
        res = (root(x) == root(y))
    end function

    subroutine unite(x, y, w)
        integer :: x, y, w
        w = w + weight(x) - weight(y)
        x = root(x); y = root(y)
        if (x /= y) then
            if(rank(x) < rank(y)) then
                x = xor(x, y); y = xor(y, x); x = xor(x, y) !swap
                w = -w
            end if
            if(rank(x) == rank(y)) then
                rank(x) = rank(x) + 1
            end if
            par(y) = x
            diff_weight(y) = w
        end if
    end subroutine

    function diff(x, y) result (res)
        integer :: x, y, res
        res = weight(y) - weight(x)
    end function

    subroutine print_UF(N)
        integer :: N
        print"(a)", parents
        do i = 1, N
            print*, "Number :", i , " " , par(i)
        end do
    end subroutine

end module Weighted_UF

program main
    use Weighted_UF

    integer N, M, l, r, d
    read*,N, M

    call init(N)

    do i = 1, M
        read*, l, r, d
        if (same(l, r)) then
            if (diff(l, r) /= d) then
                print"(a)", "No"
                stop
            end if
        else
            call unite(l, r, d)
        end if
    end do

    print"(a)", "Yes"
end

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(register int i=a;i<=b;++i)
typedef long long ll;
signed main() {
	ll n,m;
	cin>>n>>m;
	ll l = 0, r = 0, ans = 0;
	f(i,1,n+1) {
		r += n - i + 1;
		if(i>=m) (ans += r - l + 1)%=1000000007;
		l += i;
	} cout<<ans;
}

Measured memory_bytes: 3648
s = input()
s_list = [int(x) for x in list(str(s))]


# 0101010... と変換
sum_1 = 0
# 1010101... と変換
sum_2 = 0

# 0101010...
for i in range(len(s_list)):
    if i % 2 == 0:
        if s_list[i] == 1:
            sum_1 += 1
    else:
        if s_list[i] == 0:
            sum_1 += 1

    
# 1010101...
for i in range(len(s_list)):
    if i % 2 == 0:
        if s_list[i] == 0:
            sum_2 += 1
    else:
        if s_list[i] == 1:
            sum_2 += 1

print(min(sum_1, sum_2))

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

using P = pair<int, int>;

struct Edge {
    int to, id;

    Edge(int to, int id) : to(to), id(id) {}
};

vector<Edge> g[55];

vector<int> es;

bool dfs(int v, int tv, int p = -1) {
    if (v == tv) {
        es = vector<int>(); // 終点に到達したらidを格納するvectorを用意する
        return true;
    }
    for (Edge e: g[v]) {
        if (e.to == p) continue;
        if (dfs(e.to, tv, v)) {
            es.push_back(e.id);
            return true;
        }
    }
    return false;
}

int bit_count(ll bits) {
    int cnt = 0;
    for (; bits != 0; bits >>= 1) cnt += bits & 1;
    return cnt;
}

int main() {
    int N, M;
    cin >> N;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }

    cin >> M;
    vector<ll> eset(M);
    rep(i, M) {
        // a=>b間の辺のidをbitで保持する
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        dfs(a, b);
        for (int e: es) {
            eset[i] |= 1ll << e;
        }
    }

    ll ans = 0;
    rep(i, 1 << M) { // bitが立っているesetを使う
        ll mask = 0;
        rep(j, M) if (i >> j & 1) mask |= eset[j];
        
        int white = bit_count(mask); // 白く塗る辺の個数
        ll now = 1ll << (N - 1 - white); // 2^(n-1-white)
        if (bit_count(i) % 2 == 0) ans += now;
        else ans -= now;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline

    def init(init_val):
        #set_val
        for i in range(n):
            seg[i+num-1]=init_val[i]    
        #built
        for i in range(num-2,-1,-1) :
            seg[i]=gcd(seg[2*i+1],seg[2*i+2]) 
        
    def update(k,x):
        k += num-1
        seg[k] = x
        while k+1:
            k = (k-1)//2
            seg[k] = gcd(seg[k*2+1],seg[k*2+2])
        
    def query(p,q):
        if q<=p:
            return ide_ele
        p += num-1
        q += num-2
        res=ide_ele
        while q-p>1:
            if p&1 == 0:
                res = gcd(res,seg[p])
            if q&1 == 1:
                res = gcd(res,seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = gcd(res,seg[p])
        else:
            res = gcd(gcd(res,seg[p]),seg[q])
        return res



    n = int(input())
    a = tuple(map(int,input().split()))

    #####単位元######
    ide_ele = 0

    #num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    seg=[ide_ele]*2*num
    init(a)

    ans = -1
    for i in range(n):
        ans = max(ans,gcd(query(0,i),query(i+1,n)))
    print(ans)

if __name__ == '__main__':
    main()

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

_Bool Kaibun(char* s) {
  int n, i;
  n = strlen(s);
  if(n == 0 || n == 1) {
    return 1;
  }
  else {
    for(i=0; i<n/2; i++) {
      if(s[i] != s[n-1-i]) {
        return 0;
      }
    }
  }
  return 1;
}
int main(void) {
  char s[100];
  char* t;
  scanf("%s", s);
  int n = strlen(s);
  t = &s[(n-1)/2 + 1];
  s[(n-1)/2] = '\0';
  if(Kaibun(s) && strcmp(s, t) == 0) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAXN = 500005;

int n,k;
int a[MAXN];
int ans[MAXN];

bool mark[MAXN];

pair<int,int> node[MAXN << 2];

priority_queue<int> Q;

void buildtree(int o,int l,int r)
{
	if (l == r)
	{
		node[o] = make_pair(a[l],l);
		return;
	}
	int mid = l + r >> 1;
	buildtree(o << 1,l,mid);
	buildtree(o << 1 | 1,mid + 1,r);
	node[o] = max(node[o << 1],node[o << 1 | 1]);
}

void modify(int o,int l,int r,int p)
{
	if (l == r)
	{
		node[o] = make_pair(0,0);
		return;
	}
	int mid = l + r >> 1;
	if (mid >= p)
		modify(o << 1,l,mid,p);
	else
		modify(o << 1 | 1,mid + 1,r,p);
	node[o] = max(node[o << 1],node[o << 1 | 1]);
}

pair<int,int> query(int o,int l,int r,int x,int y)
{
	if (l >= x && r <= y)
		return node[o];
	int mid = l + r >> 1;
	if (mid < x)
		return query(o << 1 | 1,mid + 1,r,x,y);
	if (mid + 1 > y)
		return query(o << 1,l,mid,x,y);
	return max(query(o << 1,l,mid,x,y),query(o << 1 | 1,mid + 1,r,x,y));
}

bool check(int pos)
{
	return !mark[pos] && query(1,1,n,max(1,pos - k + 1),min(n,pos + k - 1)).first == a[pos];
}

void update(int id)
{
	pair<int,int> MX = query(1,1,n,(id - 1) * k + 1,min(id * k,n));
	if (MX.second && check(MX.second))
	{
		mark[MX.second] = 1;
		Q.push(MX.second);
	}
}

int main()
{
	scanf("%d%d",&n,&k);
	for (int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	buildtree(1,1,n);
	for (int i = 1;(i - 1) * k + 1 <= n;i++)
		update(i);
	for (int i = n;i >= 1;i--)
	{
		int cur = Q.top();
		Q.pop();
		ans[cur] = i;
		a[cur] = 0;
		modify(1,1,n,cur);
		int bel = (cur - 1) / k + 1;
		if (bel > 1)
			update(bel - 1);
		update(bel);
		if (bel * k + 1 <= n)
			update(bel + 1);
	}
	for (int i = 1;i <= n;i++)
		printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 21616
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;

template <class T> using V = vector<T>;

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;
}

const long long INF = 1LL << 60;

using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;



#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define pb(a) push_back(a);




ll Sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}



const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


#define comuse Comuse()

ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll perm(int n,int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] % MOD) % MOD;
}


ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}


vll div(ll n){
  vll ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  SORT(ret);
  return (ret);
}


ll modpow(ll a,ll n,ll mod){
  ll ans=1;
  while(n>0){
    if(n&1){
      ans=ans*a%mod;
    }

    a=a*a%mod;
    
    n>>=1;
  }

  return ans;
}


ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}

void Solve();


const int MAX_N = 131072;
//segment tree 
int NN;
int seg[MAX_N*2-1];
void seguse(){
  for(int i=0;i<2*NN-1;i++){
    seg[i]=INT_MAX;
  }
}



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



/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
//segtreeの葉の先頭の添え字はn-1
void Solve(){
  //ll N=262144;
  //vll segtree(2*N-1);
  int n,k;
    cin>>n>>k;
  cout<<1+int(log(n)/log(k))<<"\n";
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W;
    int h, w;
    cin >> H >> W >> h >> w;
    cout << (H-h) * (W-w) << endl;
    return 0;
}


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

int H,W;
int A[102][102] = {};
int dx_even[6] = {-1,-1,0,0,1,1},dy_even[6] = {-1,0,-1,1,-1,0};
int dx_odd[6] = {-1,-1,0,0,1,1},dy_odd[6] = {0,1,-1,1,0,1};
int visited[102][102] = {};

bool in(int x,int y){
	return 0<=x && x<=H+1 && 0<=y && y<=W+1;
}

void dfs(int x,int y){
	visited[x][y] = 1;
	if(x%2==1){
		for(int k=0;k<6;k++){
			int nx = x+dx_odd[k],ny = y+dy_odd[k];
			if(in(nx,ny) && A[nx][ny]==0 && visited[nx][ny]==0) dfs(nx,ny);
		}
	}else{
		for(int k=0;k<6;k++){
			int nx = x+dx_even[k],ny = y+dy_even[k];
			if(in(nx,ny) && A[nx][ny]==0 && visited[nx][ny]==0) dfs(nx,ny);
		}
	}
}

int main(){
	cin >> W >> H;
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			cin >> A[i][j];
		}
	}
	int ans = 0;
	dfs(0,0);
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			if(A[i][j]==1){
				if(i%2==0){
					for(int k=0;k<6;k++){
						if(A[i+dx_even[k]][j+dy_even[k]]==0) ans++;
					}
				}else{
					for(int k=0;k<6;k++){
						if(A[i+dx_odd[k]][j+dy_odd[k]]==0) ans++;
					}
				}
			}else if(visited[i][j]==0){
				if(i%2==0){
					for(int k=0;k<6;k++){
						if(A[i+dx_even[k]][j+dy_even[k]]==1) ans--;
					}
				}else{
					for(int k=0;k<6;k++){
						if(A[i+dx_odd[k]][j+dy_odd[k]]==1) ans--;
					}
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3376
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	k := scanInt()

	cnt := map[int]int{}
	for i := 0; i < k; i++ {
		d := scanInt()
		for j := 0; j < d; j++ {
			cnt[scanInt()]++
		}
	}
	ans := 0
	for i := 0; i < n; i++ {
		if cnt[i+1] == 0 {
			ans++
		}
	}
	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String a = scanner.next();
		String b = scanner.next();
		String ans;
		if (a.equals("H")) {
			ans = b;
		} else {
			if (b.equals("H")) {
				ans = "D";
			} else {
				ans = "H";
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21588
/*
Author: Xjrjyy
LANG: C++
PROG: agc011_a.cpp
Mail: admin@xjrjyy.com
Blog: https://blog.xjrjyy.cn/
*/

#include <cstdio>
#include <cctype>
#include <vector>
#include <iostream>
#include <algorithm>

#define MAXN (100000 + 5)

int n, c, k;
int t[MAXN * 2];
int ans;

int main()
{
    scanf("%d%d%d", &n, &c, &k);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &t[i]);
    }
    std::sort(t, t + n);
    for (int i = 0, j = 0; i < n; i = j)
    {
        for (; j < i + c && t[j] <= t[i] + k; ++j);
        ++ans;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

ll a[100005];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n;
  cin>>n;
  forn(i,0,n) cin>>a[i];
  a[0]-=1;
  forn(i,1,n){
    if(a[i]>=a[i-1]+1) a[i]-=1;
  }
  bool f=1;
  forn(i,1,n){
    if(a[i]<a[i-1]) {f=0;break;}
  }
  if(f) cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  
  int cnt = 0;
  for(int i = 0; i <= 25; i++){
    for (int j = 0; j <= 14; j++){
      if(4*i + 7*j == N) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}

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

int main() {
  int n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  --a, --b, --c, --d;

  bool jump = true;
  if (c > d) {
    int cnt = 0, tmp = 0;
    for (int i = b - 1; i < min(d + 2, c); ++i) {
      if (s[i] == '#') {
        tmp = 0;
        continue;
      }
      ++tmp;
      cnt = max(cnt, tmp);
    }
    if (cnt < 3)
      jump = false;
  }

  vector<bool> va(n);
  va[a] = true;
  for (int i = a; i < n; ++i) {
    if (s[i] == '#')
      continue;
    if (i > 0)
      va[i] = va[i] || va[i - 1];
    if (i > 1)
      va[i] = va[i] || va[i - 2];
  }

  vector<bool> vb(n);
  vb[b] = true;
  for (int i = b; i < n; ++i) {
    if (s[i] == '#')
      continue;
    if (i > 0)
      vb[i] = vb[i] || vb[i - 1];
    if (i > 1)
      vb[i] = vb[i] || vb[i - 2];
  }

  if (c != d && va[c] && vb[d] && jump)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 640
def cal(x):
  Manzoku=0
  l=[0]*26
  for d in range(D):
    l[x[d]-1]=d
    Manzoku+=s[d][x[d]-1]
    for i in range(26):
      Manzoku-=c[i]*(d-l[i])
  return Manzoku

D=int(input())
c=list(map(int,input().split()))
s=[]
t=[]
for i in range(D):
  s.append(list(map(int,input().split())))
l=[0]*26


max=0
target=0
deg=0
#初期t生成
for d in range(D):
  for i in range(26):
    deg=c[i]*(d-l[i])
    if max < deg:
      max=deg
      target=i
  t.append(target+1)
  l[target]=d



for i in range(D):
  print(t[i])


Measured memory_bytes: 9264
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>


using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }



int main()
{
    using namespace std;

    int n;
    cin >> n;

    vec<int> q(n);

    for (auto& e : q)
        cin >> e;

    sort(q.begin(), q.end());

    cout << accumulate(q.begin(), q.end(), 0) - q.back() / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int h,w,i=0,i2=0;
while(1){
	cin >>h >>w;
	if(h==0 && w==0) break;
	for(i=0; i<h; i++)
		{for(i2=0; i2<w; i2++)
			{if(i2==0 || i==0 || i==h-1 ||i2==w-1) { cout<<"#";}
			else {cout<<".";};
			}
		cout<<"\n";
		}
	cout<<"\n";
	}
return 0;
}


Measured memory_bytes: 3060
import Control.Applicative

main :: IO ()
main = getLine >> solve <$> f >>= print
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> Int
solve xs = f 0 xs
  where
    f h [x] = h + x
    f h (x:y:ys)
      | x > y = f (h + x - y) (y:ys)
      | otherwise = f h (y:ys)


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

#define endl     '\n'

using namespace std;

typedef long long ll;

const int dx[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
const int dy[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
const char dir[] = {'D', 'U', 'R', 'L'};

void Fast() { cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); }
void File()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    #endif
}

const int N = 1e5 + 9, M = 2e5 + 9, oo = 0x3f3f3f3f;

/**----------------->>  Quality Over Quantity  <<----------------**/

int Head[N], Next[M << 1], To[M << 1], signpost[N], ne, n, u, v, m;

void addEdge(int from, int to)
{
    Next[++ne] = Head[from];
    Head[from] = ne;
    To[ne] = to;
}

void BFS(int src)
{
    memset(signpost, 0x3f, sizeof signpost);
    queue <int> Q;
    Q.push(src);

    int node;
    while(Q.size())
    {
        node = Q.front(); Q.pop();
        for(int i = Head[node]; i; i = Next[i]) if(signpost[To[i]] == oo)
        {
            signpost[To[i]] = node;
            Q.push(To[i]);
        }
    }
}

void Solve()
{
    cin >> n >> m;

    while(m--)
    {
        cin >> u >> v;
        addEdge(u, v);
        addEdge(v, u);
    }

    BFS(1);

    auto isConnected = [&] () -> bool {
        for(int i = 2; i <= n; ++i)
            if(signpost[i] == oo) return false;
        return true;
    };

    if(!isConnected()) cout << "No" << endl;
    else
    {
        cout << "Yes" << endl;
        for(int i = 2; i <= n; ++i)
            cout << signpost[i] << endl;;
    }
}

void MultiTest(bool Tests = 0)
{
    int tc = 1; (Tests) && (cin >> tc);
    for(int i = 1; i <= tc; ++i)
        Solve();
}

/**------------------------->>  Main  <<-------------------------**/

int main()
{
    Fast();  MultiTest();
}


Measured memory_bytes: 7560
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n=o.a();
  var t=o.m(n);
  var graph=xArray("{from:[],to:[]}",n*(n-1)/2);
  for(var i=0;i<n;i++){
    var b=f(t[i][0]-1,i);
    for(var j=1;j<n-1;j++){
      var a=f(t[i][j]-1,i);
      graph[b].to.push(a);
      graph[a].from.push(b);
      b=a;
    }
  }
  var g=topologicalSort(graph);
  if(g===-1)return -1;
  return g[g.length-1][1]+1;
}

function f(a,b){
  var mx=Math.max(a,b);
  return (mx*(mx-1)>>1)+Math.min(a,b);
}

function topologicalSort(g){
  var n=g.length;
  var a=Array(n).fill(0);
  var q=[];
  for(var i=0;i<n;i++){
    if(g[i].from.length)a[i]=g[i].from.length;
    else q.push([i,0]);
  }
  for(i=0;i<q.length;i++){
    var v=g[q[i][0]].to;
    for(var j=0;j<v.length;j++){
      if(--a[v[j]]===0)q.push([v[j],q[i][1]+1]);
    }
  }
  return q.length<n?-1:q;
}

Measured memory_bytes: 411168
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    if(s[k-1] == 'A') s[k-1] = 'a';
    if(s[k-1] == 'B') s[k-1] = 'b';
    if(s[k-1] == 'C') s[k-1] = 'c';
    cout << s << endl;

}

Measured memory_bytes: 256
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// solution 
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        a: [usize; N],
        b: [usize; N],
        c: [usize; N],
    }
    a.sort();
    b.sort();
    c.sort();

    let mut counta = vec![0; N];
    let mut aind = 0;
    for bind in 0..N {
        loop {
            if aind >= N { break }
            else if b[bind] <= a[aind] { break }
            else { aind += 1; }
        }
        counta[bind] = aind;
    }

    let mut sumb = vec![0; N+1];
    for bind in 0..N {
        sumb[bind+1] = sumb[bind] + counta[bind];
    }

    let mut countc = vec![0; N];
    let mut bind = 0;
    for cind in 0..N {
        loop {
            if bind >= N { break }
            else if c[cind] <= b[bind] { break }
            else { bind += 1; }
        }
        countc[cind] = sumb[bind];
    }
    println!("{}", countc.iter().sum::<usize>());
}


Measured memory_bytes: 10492
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int MAX_N = 1000001;

bool isp[MAX_N];

void make_prime(){
  REP(i, MAX_N) isp[i] = true;
  isp[0] = isp[1] = false;
  FOR(i, 2, MAX_N){
    if(!isp[i]) continue;
    for(int j = i + i; j < MAX_N; j += i) isp[j] = false;
  }
}

int main() {
  make_prime();
  int N;
  while(cin >>N && N){
    int cnt = 0;
    FOR(i, 2, N / 2) if(isp[i] && isp[N - i]) ++cnt;
    if(isp[N / 2]) ++cnt;
    cout <<cnt <<endl;
  }
  return 0;
}

Measured memory_bytes: 2136
#include <stdio.h>
#include <math.h>
int isPrime(int);
int main(){
  int i,n=0,count=0;
  while(scanf("%d",&n)!=EOF){
    if(isPrime(n)==1) count++;
  }
  printf("%d\n",count);
  return 0;
}
int isPrime(int x){
  int i=3;
  if(x==2) return 1;
  if(x<2||x%2==0) return 0;
  while(i<=sqrt(x)){
    if(x%i==0) return 0;
    i+=2;
  }
  return 1;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int A, B, C; cin >> A >> B >> C;
    string res = "NO"; 
    for (int i = 1; i <= 100; i++)
    {
        if ((B*i+C) % A == 0)
        {
            res = "YES";
            break;
        }
    }
    cout << res << endl;
	return 0;
}

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

int main(){
	int N;
	cin >> N;
	int X[N];
	int tmp[N];
	for(int i=0;i<N;i++) {
		cin >> X[i];
		tmp[i] = X[i];
	}
	sort(X,X+N);

	for(int i=0;i<N;i++){
		
		if(tmp[i]<=X[N/2-1]) cout << X[N/2] << endl;
		else cout << X[N/2-1] << endl;

	}
	return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n, m;
	cin >> n >> m;
	
	vector<int> a(n);
	int point = 0;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		point += a[i];
	}
	
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if( 4 * m * a[i] >= point ) ans++;
	}
	
	if( ans >= m ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 3576
#B - Shiritori(ABC109)
N=int(input())
W=[]
s=True
for i in range(N):
    W.append(input())
if len(set(W))==N:
    for i in range(N-1):
        if W[i][-1]!=W[i+1][0]:
            print("No")
            s=False
            break   
else:
    print("No")
    s=False
if s:
    print("Yes")

Measured memory_bytes: 3060
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static final int INF = 0x3f3f3f3f;
	void main() {
		int n = sc.nextInt();
		int ma = sc.nextInt();
		int mb = sc.nextInt();
		int n_ = n * 10;
		int[][] dp = new int[n_ + 1][n_ + 1];
		for (int i = 0; i <= n_; i++)
			for (int j = 0; j <= n_; j++)
				dp[i][j] = INF;
		dp[0][0] = 0;
		while (n-- > 0) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			for (int i = n_ - a; i >= 0; i--)
				for (int j = n_ - b; j >= 0; j--) {
					int x = dp[i][j];
					if (x != INF)
						dp[i + a][j + b] = Math.min(dp[i + a][j + b], x + c);
				}
		}
		int ans = INF;
		for (int i, j, k = 1; (i = k * ma) <= n_ && (j = k * mb) <= n_; k++)
			ans = Math.min(ans, dp[i][j]);
		println(ans == INF ? -1 : ans);
	}
}


Measured memory_bytes: 37948
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

bool isPrime(int x){
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
int main() {
    string s; cin >> s;
    string t; cin >> t;
    int hantei=0;
    for(int i=0; i<s.length(); i++){
        if(s[i]!=t[i]){
            hantei = 1;
        }
    }
    int len = t.length();
    int  len2 = s.length()+1;
    if(len!=len2)hantei=1;
    if(hantei==1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

const int N = 1e6 + 10;
long long cnt;
int l;
int a[N];
int n;
vector<int> G;

void insertionSort(int a[], int n, int g){
	for (int i = g; i < n; i++) {
		int v = a[i];
		int j = i - g;
		while (j >= 0 && a[j] > v) {
			a[j + g] = a[j];
			j = j - g;
			cnt++;
		}
		a[j + g] = v;
	}
}

void shellSort(int a[], int n) {
	//????????????G={1,4,13,40,121,364,1093,...}
	int h = 1;
	while(1)
	{
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	for (int i = G.size() - 1; i >= 0; i--) {
		insertionSort(a, n, G[i]);
	}
}

int main(){
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	cnt = 0;
	
	shellSort(a, n);

	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--) {
		cout << G[i];
		if (i) cout << " ";
	}
	cout << endl << cnt << endl;
	for (int i = 0; i < n; i++) {
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 7024
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

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

void solve(int n, int k) {
    vector<string> card(n);
    set<string> S;
    for(auto &i : card) cin >> i;

    sort(ALL(card));
    do {
        string t;
        rep(i,k) t += card[i];
        S.insert(t);
    } while(next_permutation(ALL(card)));

    cout << S.size() << "\n";

    return ;
}

int main() {
    int n, k;
    while(cin>>n>>k && n) solve(n,k);

    return 0;
}

Measured memory_bytes: 3404
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
  string s1, s2; cin >> s1 >> s2;
  cout << (s1[0] == s2[2] and s1[1] == s2[1] and s1[2] == s2[0] ? "YES" : "NO");
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;

void test_case(){
    
}

int main() {
    fastio
    int n;
    cin >> n;
    string s;
    cin >> s;
    int res = 0;
    
    for(int i = 0; i<=n-3; i++){
		if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C' ){
			res++;
		}
	}
    cout<<res<<endl;
	return 0;
}






Measured memory_bytes: 256
Ps = set()
M = [False]*100001
p = 2
while p <= 100000:
  if not(M[p]):
    Ps.add(p)
    for i in range(p, 100000, p):
      M[i] = True
  p += 1
#print(sorted(Ps))
r = 0
Ss = [0]*100001
for i in range(100000):
  if i%2 == 1 and i in Ps and (i+1)//2 in Ps:
    r += 1
  Ss[i] = r
Q = int(input())
for i in range(Q):
  l, r = map(int, input().split())
  re = Ss[r]-Ss[l-1]
  print(re)


Measured memory_bytes: 5736
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] WHN = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long W = WHN[0];
            long H = WHN[1];
            long N = WHN[2];
            Boolean[,] color = new Boolean[W, H];

            for (int j = 0; j < N; j++)
            {
                long[] xya = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
                long x = xya[0];
                long y = xya[1];
                long z = xya[2];
                if (z == 1)
                {
                    //xの左側
                    for (int f = (int)x; 0 < f; f--)
                    {
                        for (int k = 0; k < H; k++)
                        {
                            color[f - 1, k] = true;
                        }
                    }
                }
                else if (z == 2)
                {
                    //xの右側
                    for (int f = (int)x; f < W; f++)
                    {
                        for (int k = 0; k < H; k++)
                        {
                            color[f, k] = true;
                        }
                    }
                }
                else if (z == 3)
                {
                    //yの下
                    for (int k = (int)y; 0 < k; k--)
                    {
                        for (int f = 0; f < W; f++)
                        {
                            color[f, k - 1] = true;
                        }
                    }
                }
                else if (z == 4)
                {
                    //yの上
                    for (int k = (int)y; k < H; k++)
                    {
                        for (int f = 0; f < W; f++)
                        {
                            color[f, k] = true;
                        }
                    }
                }
            }
            int cnt = 0;
            for(int f = 0; f < W; f++)
            {
                for(int k = 0; k < H; k++)
                {
                    if (!color[f, k])
                    {
                        cnt++;
                    }
                }
            }
            Console.WriteLine(cnt);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


//Console.WriteLine(ans);


Measured memory_bytes: 28072
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias Path = Tuple!(int, "to", long, "d");

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    Path[][] G;
    G.length = N;
    foreach (_; 0..M) {
        auto lrd = readln.split.to!(int[]);
        auto L = lrd[0]-1;
        auto R = lrd[1]-1;
        auto D = lrd[2];
        G[L] ~= Path(R, D);
        G[R] ~= Path(L, -D);
    }
    auto ds = new long[](N);
    auto fs = new bool[](N);
    bool ng;
    void solve(int i, int p, long d) {
        if (fs[i]) {
            if (ds[i] != d) ng = true;
        } else {
            ds[i] = d;
            fs[i] = true;
            foreach (n; G[i]) if (n.to != p) solve(n.to, i, d + n.d);
        }
    }
    foreach (i; 0..N) if (!fs[i]) solve(i, -1, 0);
    writeln(ng ? "No" : "Yes");
}

Measured memory_bytes: 44412
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int N = 1e5+10;
map<string,int> mp;
int main(){
    int n;
    cin >> n;
    string s;
    for(int i=1;i<=n;++i){
        cin >> s;
        mp[s]++;
    }
    int ml = 0;
    for(auto i:mp){
        ml = max(ml,i.second);
    }
    set<string> ans;
    for(auto i:mp){
        if(i.second == ml){
            ans.insert(i.first);
        }
    }
    for(auto i:ans){
        cout << i << '\n';
    }
    return 0;
}

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

int main() {

    long a, b, x;
    cin >> a >> b;
    
    for(int i = b - a + 1; i <= b + a - 1; i++){
    	cout << i << " ";
    }
    cout << endl;
}


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

int main(void){

  int act,ctt;
  int activi[1000] = {0};
  int res[1000] = {0};
  int buff,idxbf=0;

  cin >> act >> ctt;
  for(int i = 0;i<act;i++) cin >> activi[i];

  for(int i = 0;i<ctt;i++){
    cin >> buff;
    for(int j = 0;j<act;j++){
      if(activi[j] <= buff){
        res[j]++;
        break;
      }
    }
  }

  buff = res[0];
  for(int i = 0;i<act;i++){
    if(buff < res[i]){
      buff = res[i];
      idxbf = i;
    }
  }

  cout << idxbf + 1<< endl;

  return 0;
}

Measured memory_bytes: 3092
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A = LI()

    print(max(A) - min(A))

if __name__ == '__main__':
    resolve()


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
int n; string s;
const ll mod = 1e9+7;


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

  cin>>s;
  n=s.length();
  vector<ll> dp(13, 0);
  dp[0]=1;
  for (int i=0; i<n; i++) {
    vector<ll> _dp(13);
    set<ll> st;
    if (s[i]=='?') {
      for (int d=0; d<=9; d++) st.insert(d);
    } else {
      st.insert(s[i]-'0');
    }

    for (int d: st) {
      for (int x=0; x<13; x++) {
	_dp[(x*10+d)%13] += dp[x];
	_dp[(x*10+d)%13] %= mod;
      }
    }

    swap(dp, _dp);
  }

  ll ans = dp[5];
  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e5;
int N,p[MAX_N];
int main(){
	cin>>N;
	REP(i,N){
		cin>>p[i];
	}
	int ans=0;
	REP(i,N){
		if(p[i]==i+1){
			ans++;
			i++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll a[135];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<ll>v;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        v.push_back(a);
    }
    ll res=0;
    for(int i=1;i<n-1;i++){
        vector<int>v1;
        v1.push_back(v[i-1]);
        v1.push_back(v[i]);
        v1.push_back(v[i+1]);
        sort(v1.begin(),v1.end());
        if(v[i]==v1[1])res++;

    }
    cout<<res<<endl;
    return 0;
    }


Measured memory_bytes: 256
N,K=map(int,input().split())
N = N+1
a = N - K
ans = 0

MM = 10**9 +7

for i in range(K,K+a):
  start = int( ( (i)*(i-1)/2 ) % MM )
  fin = int( ( (N+(N-1)-i)*(i)/2+1 ) % MM )
  ans = int( ( ans + (fin - start) ) % MM )

ans += 1
print(ans)


Measured memory_bytes: 9196
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <complex>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
//#define test
using namespace std;
typedef long long ll;
bool p(string s)
{
  if (s[0]!='A') return 0;
  int i=2;
  for (;i<=s.size()-2;i++)
    if (s[i]=='C') break;
  if (i>s.size()-2) return 0;
  for (int j=1;j<s.size();j++)
    if (j!=i&&isupper(s[j])) return 0;
  return 1;
}
int main()
{
#ifdef test
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  string s;
  cin>>s;
  if (p(s))
    puts("AC");
  else puts("WA");
  //system("pause");
  return 0;
}


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

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;
using ld = long double;

void solve(bool);

int main() {
#ifdef YA
    auto s = clock();
    assert(freopen("input.txt", "r", stdin));
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    cout << fixed << setprecision(20);

    solve(true);

#ifdef YA1
    while (true) solve(false);
#endif

#ifdef YA
    cout << endl << endl << "time = " << (clock() - s) / (double)CLOCKS_PER_SEC << endl;
#endif

    return 0;
}

void solve(bool __attribute__((unused)) read) {
    string s;
    cin >> s;
    li ans = 0;
    li cnta = 0;
    for (int i = 0; i < (int)s.size() - 1; ++i) {
        if (s[i] == 'A') {
            ++cnta;
            continue;
        }
        if (s[i] == 'B') {
            if (s[i + 1] == 'C') {
                ans += cnta;
                ++i;
                continue;
            }
            cnta = 0;
            continue;
        }
        if (s[i] == 'C') {
            cnta = 0;
            continue;
        }
    }
    cout << ans << "\n";
}

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

int main() {
    int n,a;
    cin >> n;
    int ans = 0;
    map<ll,ll> m;
    for(int i=0; i<n; i++){
        cin >> a;
        m[a]++;
    }
    for(auto x : m){
        ans += x.second%2;
    }
    cout << ans;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  if(s[2]==s[3]&&s[4]==s[5]) puts("Yes");
  else puts("No");
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	int k , x ;
	cin>> k >> x ;
	if(500*k >= x){
		coY();
	}else coN();
}


Measured memory_bytes: 256
use proconio::input;

const A: usize = 1000_000;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut ac = vec![0; A + 1];
    for &a in &a {
        ac[a] += 1;
    }

    let mut pc = true;
    for i in 2..=A {
        let mut c = 0;
        for j in (0..=A).skip(i).step_by(i) {
            c += ac[j];
        }
        if c > 1 {
            pc = false;
            break;
        }
    }

    println!("{} coprime", if pc {
        "pairwise"
    } else {
        let mut v = a[0];
        for i in 1..n {
            v = num_integer::gcd(a[i], v);
        }
        if v == 1 {
            "setwise"
        } else {
            "not"
        }
    });
}


Measured memory_bytes: 20528
import java.util.*;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }


    // int N = Integer.parseInt(scanner.nextLine());
    // int N = scanner.nextInt(), M = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    // long[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToLong(Long::parseLong).toArray();
    static void solve(Scanner scanner) {
        long N = scanner.nextLong(), K = scanner.nextLong();
        scanner.nextLine();
        long[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToLong(Long::parseLong).toArray();
        long[] cnt = new long[60];
        for (int i = 59; i >= 0; i--) {
            long mask = 1L << i;
            for (long j: n) {
                if ((j & mask) > 0L) {
                    cnt[i]++;
                }
            }
        }

        // 0: same, 1: small
        long[][] dp = new long[60][2];
        for (long[] d: dp) {
            Arrays.fill(d, -1);
        }
        dp[59][0] = 0;
        for (int i = 58; i >= 0; i--) {
            long mask = 1L << i;
            long max = Math.max(cnt[i], N - cnt[i]);
            if (dp[i + 1][0] >= 0) {
                if ((K & mask) > 0L) {
                    dp[i][0] = dp[i + 1][0] + mask * (N - cnt[i]);
                    dp[i][1] = dp[i + 1][0] + mask * cnt[i];
                } else {
                    dp[i][0] = dp[i + 1][0] + mask * cnt[i];
                }
            }
            if (dp[i + 1][1] >= 0) {
                dp[i][1] = Math.max(dp[i][1], dp[i + 1][1] + mask * max);
            }
        }

        System.out.println(Math.max(dp[0][0], dp[0][1]));
    }

}


Measured memory_bytes: 59064