akhauriyash/Code-Regression huggingface dataset:
import fractions
A, B, C, D = map(int, input().split())

print(
    B - A + 1
    - (B // C)
    - (B // D)
    + B // int(C * D / fractions.gcd(C, D))
    + (A - 1) // C
    + (A - 1) // D
    - ((A - 1) // int(C * D / fractions.gcd(C, D)))
)

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

  Mistakes -
   0) Dont rush to conclusion on seeing a question , keep yourself relaxed and go easy on ques .
   1) To see at each step if integer is not causing an error , best way is to use long long always.
   2) To see if my solution can be verified , if yes then do that .
   3) To see if my code can be simplified , if yes make it simple.
   4) If my code is wrong , dont be in a hurry to change to the code, first think for 2 min if any modification can be done to make it
      right.
   5) always typecast (int) arr.size() because   size_t does not support subtraction.
   6) Never use such expression   Int ct = max( ct ,left) ; (declartion should be done before assignment , absurd behaviour)
   7) Using long long for everything may cause Time Limit Exceeded some times , so better be sure
   8) appending at the end of the string takes too much time 339 Div2 - B
   9) n*n*log(n) doesnt wrk for n >1000 on codeforces
   10) read the question carefully and before submitting soln read ques , it will hardly take 1min and save u  time cost of 15-30 min
   11) Keep calm and Code.

 */
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define fill(ar, val) memset(ar, val, sizeof(ar))
#define PI 3.1415926535897932385
#define uint64 unsigned long long
#define Int long long
#define int64 long long
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define ff first
#define ss second
#define bit(n) (1<<(n))
#define Last(i) ( (i) & (-i) )
#define sq(x) ((x) * (x))
#define INF INT_MAX
#define mp make_pair


int main (  )
{
 string st ;
 cin >> st ;
 bool n   = false ;
 bool s   = false ;
 bool e   = false ;
 bool w   = false ;


 for( int i =0 ; i <  st.length() ; i ++ )
  {
     if( st[i] == 'N') n =  true ;
      if( st[i] == 'S') s =  true ;
       if( st[i] == 'E') e =  true ;
        if( st[i] == 'W') w =  true ;

  }

  if(  (n  || s) && !(n && s) ) {  cout<< "No"<<endl  ; return 0 ; }
  if(  (w  || e) && !(w && e) ) {  cout<< "No"<<endl  ; return 0 ; }

  cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
c1, c2 = [input() for _ in range(2)]


def answer(c1: str, c2: str) -> str:
    if c1[0] == c2[2] and c1[2] == c2[0] and c1[1] == c2[1]:
        return 'YES'
    else:
        return 'NO'

print(answer(c1, c2))

Measured memory_bytes: 9104
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
using namespace std;

int n;
double dp[302][302][302];
int total[302];

double dfs(int rem1, int rem2, int rem3) {
  if (dp[rem1][rem2][rem3] != -1) {
    return dp[rem1][rem2][rem3];
  }
  if (rem1 == 0 && rem2 == 0 && rem3 == 0) {
    return 0.0;
  }

  double res = 1.0;
  if (rem1 > 0) {
    res += dfs(rem1 - 1, rem2, rem3) * rem1 / n;
  }
  if (rem2 > 0) {
    res += dfs(rem1 + 1, rem2 - 1, rem3) * rem2 / n;
  }
  if (rem3 > 0) {
    res += dfs(rem1, rem2 + 1, rem3 - 1) * rem3 / n;
  }
  res *= (double)n / (rem1 + rem2 + rem3);

  return dp[rem1][rem2][rem3] = res;
}

int main() {
  while (cin >> n) {
    int cnt[3] = {0, 0, 0};
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      cnt[x - 1]++;
    }

    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        for (int k = 0; k <= n; k++) {
          dp[i][j][k] = -1;
        }
      }
    }

    printf("%.10f\n", dfs(cnt[0], cnt[1], cnt[2]));
  }
}


Measured memory_bytes: 215296
function main(){
	var n = scan();
	var m = scan();
	rep(n, function(){
		var x = scan('string');
		var y = [];
		var c = -1;
		rep(m, function(i){
			if(x.charAt(i) == 'c'){
				y.push(0);
				c = 1;
			}
			else{
				y.push(c != -1 ? c++ : -1);
			}
		});
		print(y.join(' '));
	});
}

function rep(n, func){
	for(var i = 0; i < n; ++i){
		func(i);
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf8');

var input = '';
var input_index = 0;

function scan(type){
	if(type === 'string'){
		return input[input_index++];
	}
	else{
		return +input[input_index++];
	}
}

function print(val){
	console.log(val);
}

process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.split(/\s+/);
	main();
});

Measured memory_bytes: 16972
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
 
int h,w;
char mp[52][52];
bool hid[52][52];
 
void solve(){
  scanf("%d%d",&h,&w);
  REP(i,h)scanf("%s",mp[i]);
  set<char> S;
  REP(i,h)REP(j,w)if(mp[i][j]!='.')S.insert(mp[i][j]);
  int n = S.size();
  if(n==0){
    puts("SAFE");
    return;
  }
  vector<int> p(n);
  REP(i,n)p[i] = i;
  vector<char> cc;
  for(char c : S){
    cc.push_back(c);
  }
  do{
    REP(i,h)REP(j,w)hid[i][j] = false;
    bool ok = true;
    REP(x,n){
      char c = cc[p[x]];
      int umost = h, dmost = 0, lmost = w, rmost = 0;
      REP(i,h)REP(j,w)if(mp[i][j]==c){
        umost = min(umost, i);
        dmost = max(dmost, i);
        lmost = min(lmost, j);
        rmost = max(rmost, j);
      }
      // printf("%d %d %d %d\n",umost,dmost,lmost,rmost);
      for(int i=umost; i<=dmost; i++){
        for(int j=lmost; j<=rmost; j++){
          if(mp[i][j] == c){
            hid[i][j] = true;
          }
          if(!hid[i][j]){
            ok = false;
          }
        }
      }
      if(!ok)break;
    }
    if(ok){
      puts("SAFE");
      return;
    }
    // break;
  }while(next_permutation(p.begin(), p.end()));
  puts("SUSPICIOUS");
  return;
}
 
int main(){
  int t;
  scanf("%d",&t);
  while(t--)solve();
  return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)

int main(){
 
 
  ll a;
  cin>>a;
  
  
  cout<<fixed<<setprecision(15) <<(a/3.0)*(a/3.0)*(a/3.0)<<endl;
  
  
 
}



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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long best = 1e18;
  vector<int> mi(n, 1e9);
  for (int y = 0; y <= n; ++y) {
    long long cur = (long long) x * y;
    for (int i = 0; i < n; ++i) {
      int j = (i + y) % n;
      mi[i] = min(mi[i], a[j]);
    }
    for (int i = 0; i < n; ++i) {
      cur += mi[i];
    }
    best = min(best, cur);
  }
  cout << best << endl;
  return 0;
}


Measured memory_bytes: 256
K,N=map(int,input().split())
A=list(map(int,input().split()))
B=[0 for a in A]
B[0]=K+A[0]-A[-1]
s=B[0]
t=B[0]
for n in range(N-1):
  B[n+1]=A[n+1]-A[n]
  s+=B[n+1]
  if t<B[n+1]:
    t=B[n+1]
print(s-t)

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

typedef long long ll;
typedef pair<int,int> pii;
int main(){
  int N;
  cin >> N;
  map<int,bool> m;
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    m[tmp] = true;
  }
  cout << m.size() << endl;
}
    

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int calc(int);

int main(){
  int i, n, *num;
  int count = 0;

  scanf("%d",&n);
  num = (int *)malloc(sizeof(int) * n);
  for(i=0; i<n; i++){
    scanf("%d",&num[i]);
  }

  for(i=0; i<n; i++){
    if( calc(num[i]) ) count++; 
  }

  printf("%d\n",count);

  free(num);
  
  return 0;
}

int calc(int num){
  /*
    return  1...素数である 
            0...素数でない
  */
int i, sqrtNum;

  if(num == 2) return 1;
  if(num % 2 == 0) return 0;

  sqrtNum = sqrt(num);
  
  for(i=3; i<=sqrtNum; i+=2){
    if(num % i == 0) return 0;
  }
  return 1;
}


Measured memory_bytes: 2056
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int N;
V<V<int>> v;
V<int> memo;

void bfs() {
    memo.resize(N+1);
    std::queue<tuple<int,int>> fennec;
    std::queue<tuple<int,int>> snuke;
    fennec.push(make_tuple(1,1));
    memo[1] = 1;
    snuke.push(make_tuple(N,1));
    memo[N] = 2;
    int st = 1;
    while(!fennec.empty() || !snuke.empty()) {
        queue<tuple<int,int>>& q = (st) ? fennec : snuke;
        int n, c;
        std::tie(n,c) = q.front();
        while(!q.empty()) {
            int a, b;
            std::tie(a,b) = q.front();
            if(c != b) break;
            q.pop();
            REP(i,v[a].size()) {
                if(memo[v[a][i]] == 0) {
                    memo[v[a][i]] = (st) ? 1 : 2;
                    q.push(make_tuple(v[a][i],b+1));
                }
            }
        }
        st ^= 1;
    }
}

int main(){
    INIT;
    cin >> N;
    v.resize(N+1);
    REP(i,N-1) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    bfs();
    int cnt1 = 0, cnt2 = 0;
    FOR(i,1,N+1) if(memo[i] == 1) cnt1++; else if(memo[i] == 2) cnt2++;

    if(cnt1 > cnt2) cout << "Fennec" << "\n";
    else cout << "Snuke" << "\n";
}

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

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

    int now_min;
    cin >> now_min;
    int ans = N;

    for(int i = 0; i < N-1; i++){
        int tmp;
        cin >> tmp;
        if(now_min <= tmp){
            ans --;
        }
        now_min = min(now_min, tmp);
    }
    cout << ans << endl;
}

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

int main() 
{
	int a, b,c,d;
	cin >> a >> b;
	cin >> c >> d;
	
	cout<<(a*b)-((a*d)+(b*c))+(d*c)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>
#include<math.h>
#define MAX_N 300000
using namespace std;


int main(){
 long long x,y;
 cin >>x>>y;
 long long a=x,i=0;
 while (a<=y) {
  i++;
 a=a<<1;
 }

 cout <<i<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
//i mi t
using namespace std;

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

    vector<vector<int>> to(N),cost(N);

    for(int i = 0;i < N - 1;i++){
        int a,b,w;
        cin >> a >> b >> w;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
        cost[a].push_back(w);
        cost[b].push_back(w);
    };
    
    vector<int> ans(N,-1);
    queue<int> q;
    ans[0] = 0;
    q.push(0);
    
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(int i = 0;i < to[v].size();i++){
            int u = to[v][i];
            int w = cost[v][i];
            if(ans[u] != -1) continue;
            ans[u] = (ans[v] + w) % 2;
            q.push(u);
        }
    }

    for(int i = 0;i < N;i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 11904
n = int(input())
s = list(input())
left = 0
right = 0
i = 0
while i < len(s):
    if s[i] == "(":
        left += 1
    else:
        right += 1
    if left < right:
        s.insert(0,"(")
        left += 1
        i += 1
    i += 1
for i in range(left-right):
    s.append(")")
for i in range(len(s)):
    if i != len(s)-1:
        print(s[i],end="")
    else:
        print(s[i])

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

typedef struct Dice {
	int north,south,east,west,top,bottom;
} Dice;

void turn_north(Dice* dp){
	int tmp;

	tmp = dp->top;
	dp->top = dp->south;
	dp->south = dp->bottom;
	dp->bottom = dp->north;
	dp->north = tmp;
}

void turn_south(Dice* dp){
	int tmp;

	tmp = dp->top;
	dp->top = dp->north;
	dp->north = dp->bottom;
	dp->bottom = dp->south;
	dp->south = tmp;
}

void turn_east(Dice* dp){
	int tmp;

	tmp = dp->top;
	dp->top = dp->west;
	dp->west = dp->bottom;
	dp->bottom = dp->east;
	dp->east = tmp;
}

void turn_west(Dice* dp){
	int tmp;

	tmp = dp->top;
	dp->top = dp->east;
	dp->east = dp->bottom;
	dp->bottom = dp->west;
	dp->west = tmp;
}

int main(int argc, char** argv){
	Dice d;
	unsigned char cmd[101];
	int i;

	// Input
	scanf("%d",&d.top);
	scanf("%d",&d.south);
	scanf("%d",&d.east);
	scanf("%d",&d.west);
	scanf("%d",&d.north);
	scanf("%d",&d.bottom);

	// Turn
	memset( cmd, 0, sizeof(cmd) );
	scanf("%100s",cmd);
	for(i=0; cmd[i]!='\0'; i++){
		switch(cmd[i]){
		case 'N':
			turn_north(&d);
			break;
		case 'S':
			turn_south(&d);
			break;
		case 'E':
			turn_east(&d);
			break;
		case 'W':
			turn_west(&d);
			break;
		default:
			break;
		}
	}

	// Output
	printf("%d\n",d.top);

	return 0;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> ans;
    if (n % 2)
    {
        for (int l = 1, r = n - 1; l < r; l++, r--)
        {
            ans.push_back(make_pair(l, r));
        }
    }
    else
    {
        bool flag = false;
        for (int l = 1, r = n - 1; l < r; l++, r--)
        {
            if (!flag && r - l <= n / 2)
            {
                --r;
                flag = true;
            }
            ans.push_back(make_pair(l, r));
        }
    }
    for (int i = 0; i < m; i++)
    {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 4148
import sys
from itertools import accumulate

sys.setrecursionlimit(10 ** 9)
INF = 1 << 60

N, M, Q = map(int, input().split())
G = [[0] * N for _ in range(N)]
for _ in range(M):
    l, r = map(int, input().split())
    G[l - 1][r - 1] += 1

csum = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(N):
        csum[i + 1][j + 1] = csum[i + 1][j] + csum[i][j + 1] - csum[i][j] + G[i][j]

ans = []
for _ in range(Q):
    p, q = map(int, input().split())
    ans.append(csum[q][q] - csum[q][p - 1] - csum[p - 1][q] + csum[p - 1][p - 1])

print(*ans, sep='\n')


Measured memory_bytes: 69720
lunlun = [[1,2,3,4,5,6,7,8,9],[],[],[],[],[],[],[],[],[],[]]
for i in range(1,10):
    for x in lunlun[i-1]:
        unit_digit = x % 10
        if unit_digit == 0:
            lunlun[i].append(x*10)
            lunlun[i].append(x*10 + 1)
        elif unit_digit == 9:
            lunlun[i].append(x*10 + 9)
            lunlun[i].append(x*10+8)
        else:
            lunlun[i].append(x*10+unit_digit)
            lunlun[i].append(x*10+unit_digit - 1)
            lunlun[i].append(x*10+unit_digit+1)
        
temp = []
for row in lunlun:
    temp = temp + row
temp.sort()
k = int(input())
print(temp[k-1])

Measured memory_bytes: 14812
<?php
$N = int();
for($i = 0; $i < $N-1; $i++){
  list($from, $to, $d) = array_map("intval", explode(" ", trim(fgets(STDIN))));
  $G[$from][$to] = $d;
  $G[$to][$from] = $d;
}
list($Q, $K) = ints();
$distance = array_fill(1, $N, PHP_INT_MAX);
$current[] = $K;
$distance[$K] = 0;
while($current){
    $f = array_pop($current);
    foreach($G[$f] as $next => $dd){
        if($distance[$next] == PHP_INT_MAX){
            $distance[$next] = $distance[$f] + $dd;
            $current[] = $next;
        }
    }
}

for($i = 0; $i < $Q; $i++){
    list($from, $to) = ints();
    $result[] = $distance[$from]+$distance[$to];
}
echo implode("\n", $result),"\n";


function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}
/**
 * 座圧対象の配列を渡すと以下の値を返す
 * ・圧縮された配列
 * ・復元用のMap
 * ・圧縮用のMap
 **/
function atsu($array){
    $a = array_flip($array);
    $fuku = array_flip($a);
    sort($fuku);
    $atsu = array_flip($fuku);
    foreach($array as $i => $val)$array[$i] = $atsu[$val];
    return [$array, $fuku, $atsu];
}
//配列の最大公約数
function gcdAll($array){
    $gcd = $array[0];
    for($i = 1; $i < count($array); $i++){
        $gcd = gcd($gcd, $array[$i]);
    }
    return $gcd;
}

//最大公約数
function gcd($m, $n){
    if(!$n)return $m;
    return gcd($n, $m % $n);
}

//配列の最小公倍数
function lcmAll($array){
    $lcm = $array[0];
    for($i = 1; $i < count($array); $i++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


Measured memory_bytes: 63088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main{
  public static void main(String args[]) throws IOException{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String input = br.readLine();
      int ans=0;
      String f[]=input.split(" ");
      int a[]=new int[2];
      for(int i=0;i<2;i++){
        a[i]=Integer.parseInt(f[i]);
      }
      if(a[0]-(a[1]*2) >= 0){
        ans = a[0]-(a[1]*2);
      }
      System.out.println(ans);
    }
}

Measured memory_bytes: 23252
fun main() {
    val s = nextString()
    val ans = solve(s)
    println(ans)
}


//A,C,G,T
fun solve(s: String): Int {
    val length = s.length
    var max = 0

    for (i in 0..length) {
        for (j in i..length) {
            val acgt = s.substring(i, j)
            val acgtLength = acgt.takeWhile {
                it == 'A' ||
                        it == 'C'
                        || it == 'G' ||
                        it == 'T'
            }.length
            if (acgtLength == acgt.length) {
                max = acgt.length.coerceAtLeast(max)
            }
        }
    }

    return max
}

fun nextInt(): Int {
    return readLine()!!.toInt()
}

fun nextIntList(): List<Int> {
    return readLine()!!.split(" ").map { it.toInt() }
}

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

Measured memory_bytes: 34688
N = int(input())
S = list(input())
R = []
G = []
B = []

cnt = 0

for i in range(N):
  if S[i] == "R":
    R.append(i)
  elif S[i] == "G":
    G.append(i)
  else:
    B.append(i)

B = set(B)
b = len(B)  

for i in R:
  for j in G:
    check = 0
    m = min(i, j)
    M = max(i, j)
    r = M - m
    left = m - r
    right = M + r
    if r % 2 == 0:
      center = m + r//2
      if center in B:
        check += 1
    if left in B:
      check += 1
    if right in B:
      check += 1
    cnt += b - check

print(cnt)

Measured memory_bytes: 9252
#include<bits/stdc++.h>
using namespace std;
#define de_x(x) cout<<"debug_val: "<<x<<endl;
#define de_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define rep_(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
std::mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x ; }
const ll MOD=1e9 +7;
ll ksm(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;}
int _;
/*
 *
 *
 *
 *
 */
int main(){
    int n;cin>>n;
    int cnt =0;
    for(int i =1;i<=n;i++){
        int x;cin>>x;
        if(i & 1  && x & 1) cnt++;
    }

    cout<<cnt<<endl;
}

Measured memory_bytes: 3608
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string s = Console.ReadLine();
        List<int> list = new List<int>();
        list.Add(0);
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') list.Add(list[i] + 1);
            else list.Add(0);
        }
        Console.WriteLine(list.Max());
    }
}

Measured memory_bytes: 13268
//#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;
const int N = (1 << 18) + 10;
int arr[N];
pair<int, pair<int, int>> memo[N];

int main() {
   // freopen("in.txt", "rt", stdin);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < (1 << n); ++i) {
        scanf("%d", arr + i);
        memo[i] = {arr[i], {arr[i], 0}};
    }
    for (int i = 0; i < n; ++i) {
        for (int msk = 0; msk < (1 << n); ++msk) {
            if (msk & (1 << i)) {
                vector<int> vec;
                vec.push_back(memo[msk].second.first);
                vec.push_back(memo[msk].second.second);

                vec.push_back(memo[msk ^ (1 << i)].second.first);
                vec.push_back(memo[msk ^ (1 << i)].second.second);
                sort(vec.rbegin(), vec.rend());
                pair<int, pair<int, int>> p = {vec[0] + vec[1], {vec[0], vec[1]}};
                memo[msk] = max(memo[msk], p);
            }
        }
    }
    for (int i = 1; i < (1 << n); ++i) {
        if (i > 1) memo[i].first = max(memo[i].first, memo[i - 1].first);
        printf("%d\n",memo[i].first);
    }
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define pob pop_back
#define mp make_pair
#define ff first
#define ss second
#define pi 3.14159265
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <ll, ll> pll;
const ll M=1e9+7;
ll inf=1e18;
int main()
{
    int l,r,d;
    cin>>l>>r>>d;
    int x=d-l%d;
    int y=l+x%d;
    int ans=0;
    while(y<=r){
        ans++;
        y+=d;
    }
    cout<<ans;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
#define pb push_back
#define eb emplace_back
const  int MAX=1000000;
ll m[MAX+10];

// Multiplies str1 and str2, and prints result.
string multiply(string num1, string num2)
{
    int len1 = num1.size();
    int len2 = num2.size();
    if (len1 == 0 || len2 == 0)
    return "0";

    // will keep the result number in vector
    // in reverse order
    vector<int> result(len1 + len2, 0);

    // Below two indexes are used to find positions
    // in result.
    int i_n1 = 0;
    int i_n2 = 0;

    // Go from right to left in num1
    for (int i=len1-1; i>=0; i--)
    {
        int carry = 0;
        int n1 = num1[i] - '0';

        // To shift position to left after every
        // multiplication of a digit in num2
        i_n2 = 0;

        // Go from right to left in num2
        for (int j=len2-1; j>=0; j--)
        {
            // Take current digit of second number
            int n2 = num2[j] - '0';

            // Multiply with current digit of first number
            // and add result to previously stored result
            // at current position.
            int sum = n1*n2 + result[i_n1 + i_n2] + carry;

            // Carry for next iteration
            carry = sum/10;

            // Store result
            result[i_n1 + i_n2] = sum % 10;

            i_n2++;
        }

        // store carry in next cell
        if (carry > 0)
            result[i_n1 + i_n2] += carry;

        // To shift position to left after every
        // multiplication of a digit in num1.
        i_n1++;
    }

    // ignore '0's from the right
    int i = result.size() - 1;
    while (i>=0 && result[i] == 0)
    i--;

    // If all were '0's - means either both or
    // one of num1 or num2 were '0'
    if (i == -1)
    return "0";

    // generate the result string
    string s = "";

    while (i >= 0)
        s += std::to_string(result[i--]);

    return s;
}

// Driver code
int main()
{


    ll n;

    cin>>n;

    bool f=true;

    string str1,s ;

    cin>>str1;

    for(ll i=0;i<n-1;i++)
    {
         string str2 ;

         cin>>str2;

         if(str2[0]=='0')
         {
             cout<<0<<endl;
             return 0;
         }

         if(f)
         {


          s=multiply(str1, str2);

   // cout<<s.size()<<" "<<s<<endl;
           if(s.size()>19)
           {
               f=false;

           }else if(s.size()==19)
           {

               if(s[0]!='1')
               {
                   f=false;

               }else {


               for(ll j=1;s[j];j++)
               {
                  // if(s[j]=='0')
                  if(s[j]!='0')
                   {
                       f=false;

                   }
               }

               }
           }


        str1=s;
         }

    }



   // string s=multiply(str1, str2);

   if(f)cout<<s<<endl;
   else cout<<-1<<endl;
    return 0;
}



Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int a, b, m; cin >> a >> b >> m;
	VI s(a), t(b);
	REP(i,a)cin >> s[i];
	REP(i,b)cin >> t[i];
	ll ans = INF;
	REP(i,m){
		int x,y,c;
		cin >> x >> y >> c;
		ans=min(ans,s[x-1]+t[y-1]-c);
	}
	sort(ALL(s));
	sort(ALL(t));
	ans=min(ans,s[0]+t[0]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);

        long tmpN = sc.nextLong();
        long mod = (long) (Math.pow(10, 9) + 7);
        long totals = powmod(10, tmpN, mod) - powmod(9, tmpN, mod) - powmod(9, tmpN, mod) + powmod(8, tmpN, mod);
        totals = totals % mod;

        System.out.println((totals + mod) % mod);

        sc.close();
    }

    public static long powmod(int x, long y, long mod) {
        long total = 1;
        for (long i = 0; i < y; i++) {
            total = (total * x) % mod;
        }
        return total;

    }
}

Measured memory_bytes: 35928
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<int> hou(n);
    for(int i=0;i<n;i++){
      cin>>hou[i];
    }
  sort(hou.begin(),hou.end());
  cout<<hou[n-1]-hou[0]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define rep(i, n) for (int i=0; i< (n); ++i)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;

int main() {
    int a, b;
    string s, t, u;

    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if (s == u) {
        cout << a-1 << " " << b << endl;
    } else if (t == u) {
        cout << a << " " << b-1 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

signed main(){
   IOS;
   int a,b; cin >> a >> b;
   cout << a*b << '\n';  
}

Measured memory_bytes: 3648
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        s: Chars,
    }
    let mut sum = 0;
    for c in s {
        sum += (c as u8 - b'0') as i64;
    }
    if sum % 9 == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 3020
//by sdfzchy
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int inf=(1<<30);
inline int in()
{
	char ch=getchar();
	int f=1,tmp=0;
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {tmp=(tmp<<1)+(tmp<<3)+(ch-'0');ch=getchar();}
	return tmp*f;
}

int n,m;
int A,B,C;
int main()
{
    A=in(),B=in(),C=in();
    int ret=0;
    if(A>B) swap(A,B);
    if(A>C) swap(A,C);
    if(B>C) swap(B,C);
    ret+=C-B;
    A+=C-B;
    if((C-A)&1) ret+=(C-A+1)/2+1;
    else ret+=(C-A)/2;
    cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007


signed main(){

	int A, B, C, K;
	cin >> A >> B >> C >> K;
	cout << (K%2==0 ? A-B : B-A) << endl;

	return 0;
}


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

int main()
{
    ll a,b,p;
    string x,y;
    ll n;
    cin>>x>>y;
    x=x+y;
    stringstream g(x);
    a=0;
    g>>a;
    //cout<<a<<endl;
    n=sqrt(a);
    //cout<<n<<endl;
    p=n;
    p=p*p;
    if(a==p)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


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

int main()
{
    long long int N, i, j, k, count = 0;
    cin>>N;
    vector<int> arr(N);
    for(i=0;i<N;i+=1)
    {
        cin>>arr[i];
    }
    for(i=0;i<N;i+=1)
    {
        for(j=i+1;j<N;j+=1)
        {
            for(k=j+1;k<N;k+=1)
            {
                if(arr[i]!=arr[j] and arr[j]!=arr[k] and arr[i]!=arr[k] and arr[i]+arr[j]>arr[k] and arr[i]+arr[k]>arr[j] and arr[j]+arr[k]>arr[i])
                {
                    count+=1;
                }
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		HashMap<String, Integer> m = new HashMap<>();

		int n = Integer.parseInt(sc.nextLine());

		String str = sc.nextLine();
		String sl[] = str.split(" ");
		int a[] = new int[200];

		for(int i = 0; i < n; i++)
		{
			a[i] = Integer.parseInt(sl[i]);
		}

		Arrays.sort(a);

		int s = 0;
		int t = 0;
		for(int i = 0; i < 200; i += 2)
		{
			s += a[i];
		}
		for(int i = 1; i < 200; i += 2)
		{
			t += a[i];
		}

		System.out.println(Math.abs(t - s));
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int a[3];
    for (int j = 0; j < 3; j++) {
        cin >> a[j];
    }

    int l[8];
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }

    int m = 1 << (n * 2);
    int r = 1 << 30;
    for (int k = 0; k < m; k++) {
        int t = k;
        int p[8];
        for (int i = 0; i < n; i++) {
            p[i] = t % 4; t /= 4;
        }
        int mp = 0, f = 0;
        for (int j = 0; j < 3; j++) {
            int s = 0;
            for (int i = 0; i < n; i++) {
                if (p[i] == j) {
                    if (s > 0) mp += 10;
                    s += l[i];
                }
            }
            if (s == 0) {
                f = 1;
                break;
            }
            mp += abs(s - a[j]);
        }
        if (f) continue;
        r = min(r, mp);
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
using namespace std;
main(){
    queue<pair<string,int> >v;
    int N,Q,T;
    string s;
    for(cin>>N>>Q;N--;)cin>>s>>T,v.push(make_pair(s,T));
    for(T=0;!v.empty();){
        pair<string,int>p=v.front();v.pop();
        if(p.second>Q)T+=Q,p.second-=Q,v.push(p);
        else T+=p.second,cout<<p.first<<' '<<T<<endl;
    }
}

Measured memory_bytes: 4404
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solution(String[] args) throws Exception{

		String s = nextString();
		String[] base = {"resare","remaerd","esare","maerd"};
		StringBuffer S = (new StringBuffer()).append(s).reverse();

		String ans = "NO";
		boolean flg = true;
		while(flg){
			flg=false;
			for(int i=0;i<base.length;i++){
				if(S.length()>=base[i].length()&&S.substring(0,base[i].length()).equals(base[i])){
					S.delete(0, base[i].length());
					flg=true;
					break;
				}
			}
		}
		if(S.length()==0){
			ans="YES";
		}

		pw.println(ans);

	}

	public static void dfs(int n,int cnt,ArrayList<Integer>[] tree,int parent,int[] set){
		if(n!=parent&&tree[n].size()==1){
			set[n]=cnt;
			return;
		}
		for(int x:tree[n]){
			if(x==parent){
				continue;
			}
			dfs(x,cnt+1,tree,n,set);
		}
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



Measured memory_bytes: 27732
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const double INF = 1e9;

struct edge{int to,cost;};
typedef pair<int,int> P;//firstは最短距離,secondは頂点番号


int main(){
	long n;cin>>n;
	LL sum=0;
	REP(i,n){
		long temp;
		cin>>temp;
		sum+=temp;
	}
	cout<<sum/n<<endl;
	return 0;
}

Measured memory_bytes: 1156
fun main(arr:Array<String>) {
    val itemCount = readLine()!!.toInt()
    val indexList = readLine()!!.split(" ").map { it.toInt() - 1 }
    val manzoku = readLine()!!.split(" ").map { it.toInt() }
    val manzokuPlus = readLine()!!.split(" ").map { it.toInt() }

    var prevIndex = -10
    var ans = 0
    for(i in indexList) {
        if(i - prevIndex == 1) {
            ans += manzokuPlus[i-1]
        }
        ans += manzoku[i]
        prevIndex = i
    }
    println(ans)
}



Measured memory_bytes: 37680
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

li = list('abcdefghijklmnopqrstuvwxyz')
cnt = [0 for i in range(26)]

w = list(input())


for i in range(len(w)):
    for j in range(26):
        if li[j] == w[i]:
            cnt[j] += 1
            break

for i in range(26):
    if cnt[i]%2 == 0 and i!=25:
        continue 
    elif cnt[i]%2 != 0:
        print("No")
        break
    else:
        print("Yes")
        break




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

int fl(int n)
{
	if (n % 10 == 0)
	{
		return n;
	}else{
		return n + 10 - n % 10;
	}
}

int main(){
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	
	int	last = min({
			(a-1) % 10,
			(b-1) % 10,
			(c-1) % 10,
			(d-1) % 10,
			(e-1) % 10,
			}
			)+1;

	int	t =
	 fl(a) + fl(b) + fl(c) + fl(d) + fl(e)	
		-10 +last;
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val (K,S) = readLine()!!.split(" ").map(String::toInt)
  var r=0
  for(x in 0..K){
    for(y in 0..K){
      if(0<=S-x-y && S-x-y<=K) r++
    }
  }
  println(r)
}

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

using namespace std;

int main(){
  //入力を配列に入れる(参照渡し)
  vector<int> ss(3);

  for(int &c : ss){
    cin >> c;
  }
  //識別用の変数用意Noで初期化
  string comment = "NO";
  //配列を小さい順に並べる

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

    //頭から5, 5, 7か調べる
  for(int i = 0; i < 3; i++){
    if(i < 2){
      if(ss.at(i) != 5) break;
      else continue;
    }
    else{
      if(ss.at(i) != 7) break;
    }

    comment = "YES";
  }

  //全てTrueならYes
  cout << comment << endl;
}


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

int main(){
    int K, X;
    cin >> K >> X;
    if(K*500 >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline LL read(){
    LL x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-10;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 2e5+10;
const int MAXM = (int) 1e5+10;

///--------------------START-------------------------
int n;
int p[MAXN];

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&p[i]);
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i!=p[i]) continue;
        ans++;
        if(i<n) swap(p[i],p[i+1]);
        else swap(p[i],p[i-1]);
    }
    printf("%d\n",ans);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}








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

const int INF=1e9;

int main(){
  int h,n;
  cin>>h>>n;
  vector<int> dp(h+1,INF);
  int a,b;
  dp[0]=0;
  rep(i,n){
    cin>>a>>b;
    rep(j,h){
      int nj=j+a;
      nj=min(nj,h);
      dp[nj]=min(dp[nj],dp[j]+b);
    }
  }
  cout<<dp[h]<<endl;
  return 0;
}

Measured memory_bytes: 256
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	ll := make([]int, n)
	for i := 0; i < n; i++ {
		ll[i] = getNextInt(scanner)
	}
	sort.Ints(ll)
	var ans int
	for i := 0; i < n; i++ {
		for j := 0; j < i; j++ {
			for k := 0; k < j; k++ {
				if ll[i] == ll[j] {
					continue
				}
				if ll[k] == ll[j] {
					continue
				}
				if ll[i] < ll[j]+ll[k] {
					ans++
				}
			}
		}
	}
	fmt.Fprintln(writer, ans)
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            var S = RL();
            var T = RL();
            var ret = 0;
            var length=S.Length;

            for (int i = 0; i < length; i++)
            {
                if (S[i] != T[i]) ret++;
            }
               
            Console.WriteLine(ret);
            Console.ReadLine();

        }

        static IEnumerable<int> RL2IE() { return spr(RL()).Select(x => (int)c2i(x)); }
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}


Measured memory_bytes: 27428
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using P = pair<ll, int>;
const ll INF = 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(n), co(n);
  rep(i, n-1) {
    to[i+1].push_back(i);
    co[i+1].push_back(0);
  }
  rep(i, m) {
    int l, r, c;
    cin >> l >> r >> c;
    --l, --r;
    to[l].push_back(r);
    co[l].push_back(c);
  }
  vector<ll> node(n, INF);
  priority_queue<P, vector<P>, greater<P>> que;
  node[0] = 0;
  que.push({0, 0});
  while (!que.empty()) {
    ll cost;
    int now;
    tie(cost, now) = que.top();
    que.pop();
    if (cost > node[now])
      continue;
    rep(i, to[now].size()) {
      if (chmin(node[to[now][i]], cost+co[now][i]))
        que.push({cost+co[now][i], to[now][i]});
    }
  }
  ll ans = node[n-1];
  if (node[n-1] == INF)
    ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13048
program sample
  implicit none
  integer(8) :: i,j,x,y,count
  integer(8) :: a(41)
    
  read(*,*) x

  a(1) =1
  
  
  do i=2,9
     a(i) = 2**i
  end do
    
  do i=10,14
     a(i) = 3**(i-8)
  end do

  do i=15,17
     a(i) = 5**(i-13)
  end do
  do i=18,19
     a(i) =6**(i-16)
  end do

  do i=20,21
     a(i) = 7**(i-18)
  end do

  do i=22,23
     a(i) = 10**(i-20)
  end do

  do i=24,28
     a(i) = (i-13)**2
  end do

  do i=29,36
     a(i) = (i-12)**2
  end do

  a(37) = 26**2
  
  do i=38,41
     a(i)=(i-10)**2
  end do

  do i=1,41
     do j=i,41
        if (a(i)>a(j)) then
           y=a(i)
           a(i)=a(j)
           a(j)=y
        end if
     end do
  end do

  do i=1,41
     if (a(i) <= x) then
        count=a(i)
     end if
  end do

  write(*,*) count
  
  stop
end program sample

Measured memory_bytes: 2836