akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

vector<int> graph[100010];

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

        int a, b;
        for(int i = 0;i < n-1;i++){
                cin >> a >> b;
                a--; b--;
                graph[a].push_back(b);
                graph[b].push_back(a);
        }


        queue<pair<int, int> > que;
        que.push(make_pair(0, 1));
        que.push(make_pair(n-1, 2));

        int dist[100010] = {};

        while(!que.empty()){
                int idx = que.front().first;
                int num = que.front().second;
                que.pop();

                if(dist[idx] != 0) continue;

                dist[idx] = num;

                for(int i = 0;i < graph[idx].size();i++){
                        que.push(make_pair(graph[idx][i], num+2));
                }
        }

        int f = 0;
        int s = 0;
        for(int i = 0;i < n;i++){
                if(dist[i] % 2 == 1){
                        f++;
                }else{
                        s++;
                }
        }

        if(f > s){
                cout << "Fennec" << endl;
        }else{
                cout << "Snuke" << endl;
        }

        return 0;
}



Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

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




ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}

template<typename T>
ll com(T n, T m, T mod){
  ll a = 1, b = 1, ans;
  if(n == m || m == 0){
    ans = 1;
  }else{
    for(ll i = 0;i < m; i++){
      a *= n-i;
      a %= mod;
      b *= i+1;
      b %= mod;
    }
    ans = (a * powmod(b, mod-2, mod)) % mod;
  }
  
  return ans;
}

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

  vector<int> ans(N, -1);
  vector<set<int>> que(N);
  rep(i, 0, M){
    int Ai, Bi;
    cin >> Ai >> Bi;

    que[Ai-1].insert(Bi-1);
    que[Bi-1].insert(Ai-1);
  }

  // 幅優先探索
  queue<int> detect;
  detect.push(0);

  while(!detect.empty()){
    int now = detect.front();
    detect.pop();
    
    for(auto& node : que[now]){
      if(ans[node] != -1) continue;

      ans[node] = now;
      detect.push(node);
    }
  }

  cout << "Yes" << endl;
  rep(i, 1, N){
    cout << ans[i]+1 << endl;
  }







  // cout << setprecision(20) << ans << endl;  // For double
}

Measured memory_bytes: 27608
N = int(input())
left = []
right = []
last = None
for i in range(N):
	s = input()
	l = len(s)
	r_needed = 0
	l_needed = 0
	for j in range(l):
		if s[j] == "(":
			r_needed += 1
		elif s[j] == ")" and r_needed > 0:
			r_needed -= 1

		if s[l-1 - j] == ")":
			l_needed += 1
		elif s[l-1 - j] == "(" and l_needed > 0:
			l_needed -= 1
	if r_needed < l_needed:
		right.append((-r_needed, l_needed))
	else:
		left.append((l_needed, -r_needed))

left.sort()
right.sort()
rest_l = 0
for l in left:
	l_needed = l[0]
	r_needed = -l[1]
	if rest_l < l_needed:
		print("No")
		exit()
	rest_l += r_needed - l_needed
for r in right:
	l_needed = r[1]
	r_needed = -r[0]
	if rest_l < l_needed:
		print("No")
		exit()
	rest_l -= l_needed
	rest_l += r_needed
if rest_l != 0:
	print("No")
else:
	print("Yes")


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> d(n);
    REP(i,n)cin >> d[i];
    int64 ans = 0;
    REP(i,n-1)FOR(j,i+1,n){
        ans += d[i] * d[j];
    }
    ANS(ans);
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e3+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}

vector<string>s(MAXN);
int sx, sy, ex, ey, h, w;
vector<vector<bool>>vis(MAXN, vector<bool>(MAXN,0));

void bfs()
{
    priority_queue<tuple<int,int,int>>q;
    q.push({0,sx,sy});

    auto good = [&]( int x, int y ) -> bool
    {
        if( x < 0 || x >= h || y < 0 || y >= w || s[x][y] == '#' )
            return 0;
        return 1;
    };

    int ans = MOD;
    while( !q.empty() )
    {
        int x, y, magic;
        tie(magic,x,y) = q.top();
        magic *= -1;
        q.pop();

        if( vis[x][y] )
            continue;
        vis[x][y] = 1;

        if( x == ex && y == ey )
        {
            ans = min( ans, magic );
        }

        for(int nx=x-2;nx<=x+2;nx++)
        {
            for(int ny=y-2;ny<=y+2;ny++)
            {
                if( good(nx,ny) )
                {
                    int nmagic = magic;
                    if( abs(x-nx) + abs(y-ny) != 1 )
                        nmagic++;
                    q.push({-nmagic,nx,ny});
                }
            }
        }
    }
    if( ans == MOD )
        ans = -1;
    cout<<ans,nl;
}

int main() 
{
    fastio();

    cin>>h>>w;
    cin>>sx>>sy>>ex>>ey;
    sx--,sy--,ex--,ey--;
    for(int i=0;i<h;i++)
        cin>>s[i];
    bfs();

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 6196
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

//for loop関係
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//定数
const int INF = 1<<30;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

//Degree <-> Radian
double toRad(double d){ double rad; rad=d*PI/180; return rad; }
double toDegree(double rad){ double d; d=rad*180/PI; return d; }
//The least common multiple : lcm
ll lcm(int a,int b){ return a*b/__gcd(a,b); }
//素数判定
bool isPrime(int n){
    int i; 
    if(n<2) return 0;
    else if(n==2) return 1;
    if(n%2==0) return 0;
    for(i=3;i*i<=n;i+=2) if(n%i==0) return 0;
    return 1;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin >> n >> k;
    int count=0;
    rep(i,0,n){
        int a;
        cin >> a;
        if(a>=k) count++;
    }
    cout << count ENDL;
    
    return 0;
}

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

int main(void){
    int N, W; cin >> N >> W;
    vector<int> w(N), v(N); rep(i, N) cin >> w[i] >> v[i];
    
    vector<vector<ll>> dp(N+10, vector<ll>(W * 2, 0));
    for(int i = 0; i < N; i++){
        for(int sum_w = 0; sum_w <= W; sum_w++){
            
            if (sum_w - w[i] >= 0){
                dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i]);
            }
            
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }
    
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 173824
#include <iostream>
#include <string>

using namespace std;
int main(){
  string a,b,c;
  cin>>a>>b>>c;
  if(a[a.length()-1]==b[0]&&b[b.length()-1]==c[0]){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
/*
 * MatrixVectorMultiplication.cpp
 *
 *  Created on: 2014/07/25
 *      Author: WanWan1985
 */
#include <iostream>
#include <vector>
using namespace std;

// for util
#define FOR(i, a, b) 	for(int i = (a); i < (b); i++)
#define REP(i, n)		FOR(i, 0, n)
#define PB				push_back
#define MP				make_pair

class C_Matrix {
private:
	vector<vector<int> > m_val;
public:
	C_Matrix(int n, int m) {
		vector<int> vecZeros;
		REP(i, m) vecZeros.PB(0);
		REP(i, n) m_val.PB(vecZeros);
	}

	int GetRow() const {
		return m_val.size();
	}

	int GetCol() const {
		return m_val.at(0).size();
	}

	C_Matrix operator* (const C_Matrix a_Matrix) {
		const int n = this->GetRow();
		const int l = this->GetCol();
		const int m = a_Matrix.GetCol();
		C_Matrix RetMatrix(n, m);
		REP(i, n)REP(j, m)REP(k, l)
				RetMatrix.m_val[i][j] += this->m_val[i][k] * a_Matrix.m_val[k][j];
		return RetMatrix;
	}

	void SetMatrixElement(const vector<vector<int> > a_val) {
		m_val = a_val;
	}

	vector<vector<int> > GetMatrixElement() {
		return m_val;
	}

};

int main(void) {
	int n, m;
	cin >> n >> m;

	vector<vector<int> > vecMatrix1;
	vector<int> InputVal1;
	REP(i, n) {
		REP(j, m) {
			int a = 0;
			cin >> a;
			InputVal1.PB(a);
		}
		vecMatrix1.PB(InputVal1);
		InputVal1.clear();
	}
	C_Matrix Matrix(n, m);
	Matrix.SetMatrixElement(vecMatrix1);

	vector<vector<int> > vecMatrix2;
	vector<int> InputVal2;
	REP(i, m) {
		REP(j, 1) {
			int b = 0;
			cin >> b;
			InputVal2.PB(b);
		}
		vecMatrix2.PB(InputVal2);
		InputVal2.clear();
	}
	C_Matrix Vector(m, 1);
	Vector.SetMatrixElement(vecMatrix2);

	C_Matrix RetMatrix = Matrix * Vector;
	vector<vector<int> > MatrixVal = RetMatrix.GetMatrixElement();

	REP(i, RetMatrix.GetRow()) {
		vector<int> tmp = MatrixVal.at(i);
		REP(j, RetMatrix.GetCol()) {
			cout << tmp.at(j);
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1348
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    x1, y1, x2, y2 = MAP()
    print(x2 - (y2 - y1), y2 + (x2 - x1), x1 - (y2 - y1), y1 + (x2 - x1))


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int(i) = 0;(i) < (n); (i)++)
typedef long long ll;
 
int main(){
  int R;
  cin >> R;
    cout << 2*R*3.14 <<endl; 
 
    }

Measured memory_bytes: 3772
#include <iostream>

int main(){
   int R, G, B, N;
   std::cin >> R >> G >> B >> N;

   int ans = 0;
   for(int i=0; i<=N/R; ++i){
      for(int j=0; j<=N/G; ++j){
	 int k= N - R*i - G*j;
	 if(k>=0 && k%B==0) ++ans;
      }
   }
   std::cout << ans << std::endl;
   return 0;

}


Measured memory_bytes: 256
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
// https://atcoder.jp/contests/abc173/tasks/abc173_c
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll h,w,k;
    cin >> h >> w >> k;
    char c[6][6] ={0,};
    for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            cin >> c[i][j];
        }
    }

    ll ans=0;
    for(int R = 0;R<(1 << h);R++){
        for(int C = 0; C<(1 << w);C++){
            ll black = 0;
            for(int i = 0;i<h;i++){
                for(int j = 0;j<w;j++){
                    if((R >> i)%2==0 && (C >> j)%2 == 0 && c[i][j] == '#')
                        black++;
                }
            }
            if(black == k) ans++;
        }
    }

    cout << ans;

	return 0;
}


Measured memory_bytes: 3656
#include<iostream>

using namespace std;

typedef struct{
  int x;
  int y;
}Point;

int main(){

  int x,y;

  while(cin >> y >> x && x+y){
    char data[y][x];
    int come[y][x];
    for(int i = 0; i < y; i++){
      for(int j = 0; j < x; j++){
	cin >> data[i][j];
	come[i][j] = 0;
      }
    }

    Point point;
    point.x = point.y = 0;
    int status = 0;
    while(1){
      come[point.y][point.x] = 1;
      if(data[point.y][point.x] == '^') point.y--;
      else if(data[point.y][point.x] == 'v') point.y++;
      else if(data[point.y][point.x] == '>') point.x++;
      else if(data[point.y][point.x] == '<') point.x--;
      else if(data[point.y][point.x] == '.') break;
      if(come[point.y][point.x]){
	status = 1;
	break;
      }
    }
    if(status) cout << "LOOP" << endl;
    else cout << point.x << " " << point.y << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
int dp[10100], n, m, pntr[10100];
vector<int>digits;
const int costs[10] = {0,2,5,5,4,5,6,3,7,6};
bool reachable[10100];

int main() {
    cin>>n>>m;
    int x;
    for(int i=1;i<=m;i++) {
        cin>>x;
        digits.pb(x);
    }
    sort(digits.begin(), digits.end());

    reachable[0] = true;
    for(int i=1;i<=n;i++) {
        for(int j=digits.size()-1;j>=0;j--) {
            if(i - costs[digits[j]] >= 0) {
                if(dp[i-costs[digits[j]]] + 1 > dp[i] && reachable[i-costs[digits[j]]]) {
                    pntr[i] = digits[j];
                    dp[i] = dp[i-costs[digits[j]]] + 1;
                    reachable[i] = true;
                }
            }
        }
    }

    vector<int>result;
    x = n;
    while(pntr[x] != 0) {
        result.pb(pntr[x]);
        x -= costs[pntr[x]];
    }

    sort(result.rbegin(), result.rend());
    for(int i:result) {
        cout<<i;
    } cout<<"\n";

    return 0;
}

Measured memory_bytes: 384
_, m = gets.split(' ').map(&:to_i)

ac = {}
wa = {}
wa_count = 0

m.times {
  i, s = gets.strip.split(' ')

  if ac[i]
    next
  elsif s == 'WA'
    wa[i] = (wa[i] || 0) + 1
  elsif s == 'AC'
    ac[i] = 'AC'
    wa_count += wa[i].to_i
  end
}


puts "#{ac.size} #{wa_count}"

Measured memory_bytes: 21244
N, Q=map(int,input().split())
S=input()
t=[0]*(N+1)
for i in range(N):
    t[i+1]=t[i]+(1 if S[i : i+2] == 'AC' else 0)
for i in range(Q):
    l, r=map(int,input().split())
    print(t[r-1]-t[l-1])

Measured memory_bytes: 7748
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>

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

using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(c >= a && c <= b) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        int a=scn.nextInt();
        int b=scn.nextInt();
        int answer =n*a;
        if(answer>b) answer=b;
        System.out.println(answer);
    }
}

Measured memory_bytes: 24276
import fractions
N = int(input())
a = list(map(int, input().split()))
c = a[0]
b = 1
if N > 1:
  for i in range(1, N):
    d = fractions.gcd(c, a[i])
    b = b * a[i] // d + c // d
    b %= (10 ** 9 + 7)
    c = c * a[i] // d
print(b)

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

typedef long long ll;

int main() {
	int n;
	string s;
	cin >> n >> s;
	for (char c: s) {
		n %= 26;
		if (char(c + n) > 'Z')
			cout << char(c + n - 26);
		else
			cout << char(c + n);
	}
}


Measured memory_bytes: 384
n, m = map(int, input().split())
edges = [[] for i in range(n+1)]
for i in range(m):
  a, b = map(int, input().split())
  edges[a].append(b)
  edges[b].append(a)

ans = [0 for i in range(n+1)]
import queue
q = queue.Queue()
q.put(1)
while not q.empty():
  node = q.get()
  for e in edges[node]:
    if ans[e] == 0:
      ans[e] += node
      q.put(e)

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

Measured memory_bytes: 37040
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define mii map<int, int>

void show(auto a){
  int i = 0;
  while(i < a.size()){
    cout<<a[i]<<" ";
    i++;
  }
  cout<<endl;
}


int main(){
  ios_base::sync_with_stdio(false);
  int n, k;
  cin>>n>>k;
  vi stones(n); for(int i = 0; i < n; i++) cin>>stones[i];

  vb dp(k+1, false);
  //dp[i] => who will win if i stones are chosen
  for(int i = 0; i <= k; i++){
  	for(int j = 0; j < stones.size(); j++){
  		if(stones[j]<=i && !dp[i-stones[j]]){
  			dp[i] = true;
  		}
  	}
  }

  string ans = (dp[k])?"First":"Second";
  cout<<ans<<endl;
}

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


Graph G(100010);
vector<bool> seen(100010, false);
vector<int> prenum(100010), parent(100010), lowest(100010);

int id;

void dfs(int now, int prev){
    prenum[now] = lowest[now] = id;
    id++;
    seen[now] = true;

    rep(i, G[now].size()){
        int next = G[now][i];
        if(!seen[next]){
            parent[next] = now;
            dfs(next, now);
            lowest[now] = min(lowest[next], lowest[now]);
        }
        else if(next != prev){
            lowest[now] = min(lowest[now], prenum[next]);
        }
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    rep(i, M){
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    id = 1;
    dfs(0, -1);

    set<int> ans;
    int root_p = 0;
    for(int i = 1; i < N; i++){
        int p = parent[i];
        if(p == 0) root_p++;
        else if(prenum[p] <= lowest[i]) ans.insert(p);
    }

    if(root_p >= 2) ans.insert(0);

    for(set<int>::iterator it = ans.begin(); it != ans.end(); it++){
        cout << *it << endl;
    }
}


Measured memory_bytes: 10892
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define int long long 
#define ld long double
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define loop(i,l,r) for(int i=l;i<r;i++)
#define rloop(i,r,l) for(int i=r;i>=l;i--)
#define watch(x) cerr<<(#x)<<"= "<<(x)<<endl;
#define watcharr(a) cerr<<(#a)<<"("<<sz(a)<<")= ";rep(i,sz(a))cerr<<a[i]<<",";cerr<<'\n';
#define inf 2000000000000000000LL
#define mod 1000000007
#define mod1 998244353
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;

int dp[100005][105];

signed main() {
    FASTIO;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    //     freopen("stderr.txt", "w", stderr);
    // #endif

    // int tt=1;
    // cin>>tt;
    // while(tt--){
        int n,k=2;
        cin>>n>>k;
        vi a(n);
        vi dp(n,inf);
        rep(i,n) cin>>a[i];
        dp[0]=0;
        loop(i,1,n){
            loop(j,1,k+1){
                if(i-j<0) continue;
                dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
            }
        }
        cout<<dp[n-1]<<endl;
        
        
    // }
    cerr<<"Time Elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" sec";
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 1e6 + 5, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18, MOD = 1e15 + 37;
const ld PI = acos(-1);

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

    //////////////////////////////////////////
    //////////////////////////////////////////

    int d, t, s;
    cin >> d >> t >> s;
    cout << ((d + s - 1) / s <= t ? "Yes" : "No") << "\n";
}


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

int bit[200005];
void add(int i, int x){
  i++;
  while(i<200005){
    bit[i]+=x;
    i+=i&-i;
  }
}
int sum(int i){
  i++;
  int ret=0;
  while(i){
    ret+=bit[i];
    i-=i&-i;
  }
  return ret;
}

string str;
int nxt[26];
int main(){
  int k;
  cin >> str >> k;
  int n=str.length();
  fill(bit, bit+200005, 0);
  for(int i=0; i<n; i++) add(i, 1);
  fill(nxt, nxt+26, 0);
  for(int i=0; i<26; i++){
    while(nxt[i]<n && str[nxt[i]]!='a'+i) nxt[i]++;
  }
  for(int i=0; i<n; i++){
    for(int j=0; j<26; j++){
      if(nxt[j]==n) continue;
      int cnt=sum(nxt[j]-1);
      if(cnt<=k){
        k-=cnt;
        add(nxt[j], -1);
        cout << (char)('a'+j);
        nxt[j]++;
        while(nxt[j]<n && str[nxt[j]]!='a'+j) nxt[j]++;
        break;
      }
    }
    //for(int j=0; j<26; j++) printf("%c ", 'a'+j); printf("\n");
    //for(int j=0; j<26; j++) printf("%d ", nxt[j]);printf("\n");
  }
  cout << endl;
}

Measured memory_bytes: 4080
#include<stdio.h>
#include<string.h>
int main(){
  int n,N,b,B;
  char s[1000];
  scanf("%d ",&n);
  for(N=0;N<n;N++){
    gets(s);
    b=strlen(s);
    for(B=b-1;B>0;B--){
      if(s[B]=='o' && s[B-1]=='n' && s[B-2]=='i' && s[B-3]=='h' && s[B-4]=='s' && s[B-5]=='o' && s[B-6]=='H'){
	s[B]='a';
      }
    }
    printf("%s\n",s);
  }
  return (0);
}

Measured memory_bytes: 580
#import<vector>
#import<set>
#import<cstdio>
using namespace std;
int main(){
	long long H,W;
	int N,h,w,h0,w0,z;
	scanf("%lld%lld%d",&H,&W,&N);
	vector<long long>v(10);
	set<pair<int,int>>points;
	v[0]=(H-2)*(W-2);
	for(;N--;){
		scanf("%d%d",&h,&w);h--,w--;
		points.emplace(h,w);
		for(h0=-1;h0<2;h0++)for(w0=-1;w0<2;w0++)
			if(1<=h+h0&&h+h0<H-1 && 1<=w+w0&&w+w0<W-1){
				int t=0;
				for(z=0;z<9;z++)t+=points.find({h+h0+z/3-1,w+w0+z%3-1})!=points.end();
				v[t-1]--;
				v[t]++;
			}
	}
	for(auto &e:v)printf("%lld\n",e);
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
	string S;
	cin >> S;
	string a = "";
	for(char c : S){
		if(c != '/'){
			a += c;
		}
	}
	string result = 20190430 >= atoi(a.c_str()) ? "Heisei" : "TBD";
	cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		List<int[]> list = new ArrayList<>();
		for(int i=0;i<m;i++) {
			int[] a = new int[2];
			a[0] = in.nextInt();
			a[1] = in.nextInt();
			list.add(a);
		}
		list.sort((a1,a2)->a1[1]-a2[1]);
		int latest = 0;
		int count = 0;
		for(int[] a : list) {
			if(a[0]<=latest && latest<a[1]) continue;
			latest = a[1]-1;
			count++;
		}
		System.out.println(count);
		in.close();
	}

}


Measured memory_bytes: 86584
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    int N;
    ll A[50],cnt = 0;
    cin >> N;
    for(int i = 0;i < N;i++)cin >> A[i];
    while(1){
        ll dif = 0,maxi = 0;
        for(int i = 0;i < N;i++){
            ll num = A[i]/N;
            A[i] -= num*(N+1);
            dif += num;
        }
        for(int i = 0;i < N;i++){
            A[i] += dif;
            maxi = max(maxi,A[i]);
        }
        cnt += dif;
        if(maxi < N)break;
    }
    cout << cnt << endl;
}

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

int main(void)
{	
	int A, B, C, X, Y, a, b, p1, p2, p3;

	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);
	scanf("%d", &X);
	scanf("%d", &Y);

	if(X>Y)
	{
		a = 1;
		b = 0;
	}
	else
	{
		a = 0;
		b = 1;
	}

	p1 = A*X + B*Y;
	p2 = 2*C*fmin(X,Y) + (a*A + b*B)*abs(X-Y);
	p3 = 2*C*(fmin(X,Y) + abs(X-Y));

	printf("%d\n", (int)fmin(fmin(p1,p2),p3));
	return 0;
}

Measured memory_bytes: 128
b1,b2,b3=map(int,input().split())
if b1==1 and b2==0 and b3==0:
    print('Close')
elif b1==0 and b2==1 and b3==0:
    print('Close')
elif b1==1 and b2==1 and b3==0:
    print('Open')
elif b1==0 and b2==0 and b3==1:
    print('Open')
elif b1==0 and b2==0 and b3==0:
    print('Close')


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
const int inf = 1000000000; 

int GCD (int  x, int y){
  int a = max(x,y);
  int b = min(x,y);
  if(a%b == 0) return b;
  return GCD(b,a%b);
}

int main(){
    int k;
    cin >> k;
    ll ans = 0;
    rep(i,k){
        rep(j,k){
            rep(l,k){
                ans += ll(GCD(GCD(i,j),l));
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let (n, c) = get!(usize, usize);
    let mut l = vec![vec![0; c]; 100_001];
    for _ in 0..n {
        let (s, t, c) = get!(usize, usize, usize);
        l[s-1][c-1] += 1;
        l[t][c-1] -= 1;
    }
    for i in 0..100_000 {
        for j in 0..c {
            l[i+1][j] += l[i][j];
        }
    }
    println!("{}", l.into_iter().map(|t| t.into_iter().map(|x| cmp::min(1, x)).sum::<i32>()).max().unwrap());
}

Measured memory_bytes: 16836
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    long long n, m;
    cin >> n >> m;
    if(m < n) swap(n, m);
    if(n == 1){
        if(m == 1){
            cout << 1 << "\n";
        }else{
            cout << m - 2 << "\n";
        }
        return 0;
    }
    cout << (n - 2) * (m - 2) << "\n";
}

Measured memory_bytes: 256
N=int(input())
if N%10==2 or N%10==4 or N%10==5 or N%10==7 or N%10==9:
    print("hon")
elif N%10==0 or N%10==1 or N%10==6 or N%10==8:
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9112
from functools import lru_cache
import sys

sys.setrecursionlimit(2000)

s = int(input())
mod = 10 ** 9 + 7


@lru_cache(maxsize=None)
def dfs(n):
    if n <= 2:
        return 0
    elif n==3:
        return 1
    else:
        count = 1
        for i in range(3, n + 1):
            count += dfs(n - i)
            count %= mod

        return count % mod


ans = dfs(s)
print(ans)


Measured memory_bytes: 10320
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(void){
	long n, cnt = 0;
	cin >> n;
	vector<long> a(n + 1);
	long c[n];
	for (int i = 0; i < n; i++){
		c[i] = 0;
	}
	a[0] = -1;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	for (int i = 1; i <= n; i++){
		if (a[i - 1] == a[i]){
			c[cnt] = a[i];
			cnt++;
			a[i] = -1;
		}
	}
	if ((c[0] == 0 && c[1] == 0) || c[0] == 0){
		cout << 0 << endl;
		return 0;
	}
	cout << c[cnt - 1] * c[cnt - 2] << endl;

	return 0;

}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    ll N;
    ll K;
    read(N, K);
    vector<ll> A(N);
    for(ll i = 0; i < N; i++){
        read(A[i]);
        A[i]--;
    }
    map<ll, ll> mp;
    mp[0] = 1;
    ll p = A[0];
    ll i = 2;
    while(mp[p] == 0){
        mp[p] = i;
        p = A[p];
        i++;
    }
    ll s = mp[p] - 1;
    ll r = i - mp[p];
    ll ans = 0;
    if(K < s) {
        for(ll i = 0; i < K; i++){
            ans = A[ans];
        }
    }
    else{
        ans = p;
        K -= s;
        K %= r;
        for(ll i = 0; i < K; i++){
            ans = A[ans];
        }
    }
    write(ans + 1);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 17096
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

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


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

    int n; cin >> n;
    string s; cin >> s;

    vector<int> a(n, 0);

    a[0] = (s[0]=='('? 1:-1);
    int minv=a[0];

    repr(i, 1, n){
        if(s[i]=='(') a[i]=a[i-1]+1;
        else a[i]=a[i-1]-1;
        chmin(minv, a[i]);
    }

    if(minv<0){
        rep(i, abs(minv)) s = '('+s;
        a[n-1]-=minv;
    }

    rep(i, a[n-1]) s += ')';
    cout << s << endl;

    return 0;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
typedef long long ll;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 300 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    ll s;
    cin >> s;
    ll x1, x2, x3, y1, y2, y3;
    x1 = y1 = 0;
    y2 = ceil(sqrt(s));
    x3 = ceil(sqrt(s));
    x2 = x3 * y2 - s;
    y3 = 1;
    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char a[53][53];
int b[53][53];
int main()
{
	int h, w;
	cin >> h >> w;

	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			cin >> a[i][j];
		}
	}
	
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			if (a[i][j] == '#') continue;
			int cnt = 0;
			if (a[i+1][j] == '#') cnt++;
			if (a[i+1][j+1] == '#') cnt++;
			if (a[i+1][j-1] == '#') cnt++;
			if (a[i][j+1] == '#') cnt++;
			if (a[i][j-1] == '#') cnt++;
			if (a[i-1][j] == '#') cnt++;
			if (a[i-1][j-1] == '#') cnt++;
			if (a[i-1][j+1] == '#') cnt++;
			b[i][j] = cnt;
		}
	}
	
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			if (a[i][j] == '#') putchar('#');
			else cout << b[i][j];
		}
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  string s;
  map<char,int> mp;
  
  while(getline(cin,s)){
    for(int i=0;i<s.size();i++)mp[s[i]]++;
  }
  for(int i=0;i<26;i++){
    int x='a'+i;
    putchar(x);
    cout<<" : "<<mp['a'+i]+mp['A'+i]<<endl;
  }
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;} 
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a,b) << ' ' << ((a + b >= n) ? a + b - n : 0) << '\n';
    return 0;
}


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

const unsigned long long int N = 1e+5;

int main() {
    using namespace std;
    unsigned long long int a[N], n;

    cin >> n;

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

    vector<unsigned long long int> vec(a, a+n);
    sort(vec.begin(), vec.end());
    unsigned long long int old, cnt, cnt2;
    old = *vec.begin();
    cnt = 0;
    cnt2 = 0;
    for (vector<unsigned long long int>::iterator it = vec.begin(); it != vec.end(); ++it) {
        // cout << *it << ' ' << old;
        if (*it != old) {
            if (cnt % 2) {
                ++cnt2;
            }
            cnt = 0;
        }
        ++cnt;
        // cout << ' ' << cnt << ' ' << cnt2 << endl;
        old = *it;
    }
    if (cnt % 2) {
        ++cnt2;
    }

    cout << cnt2 << endl;

    return 0;
}


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

int main() {
    set<int> S, T;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        S.insert(a);
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a;
        cin >> a;
        T.insert(a);
    }
    set<int> isec;
    set_intersection(S.begin(), S.end(), T.begin(), T.end(), inserter(isec, isec.end()));
    cout << isec.size() << endl;
}


Measured memory_bytes: 3144
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N, K;
    scan(N, K);
    auto a = readln.split.to!(int[]);

    auto dp = new bool[](K + 1);
    foreach (i ; 1 .. K + 1) {
        foreach (j ; 0 .. N) {
            if (i - a[j] >= 0 && !dp[i - a[j]]) {
                dp[i] = true;
            }
        }
    }

    writeln(dp[K] ? "First" : "Second");
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 2428
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
sat=0
for i in range(N):
  sat+=B[A[i]-1]
  if(i+1!=N and A[i+1]-A[i]==1):
    sat+=C[A[i]-1]
print(sat)

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

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

int main()
{
  int x, y;
  while (cin >> x >> y){
    while (y != 0){
      x = x % y;
      swap(x, y);
    }
    cout << x << endl;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int W,H,N;
  cin>>W>>H>>N;
  vector<int> xi(N);
  vector<int> yi(N);
  vector<int> ai(N);
  int x1=0;
  int x2=W;
  int y3=0;
  int y4=H;
  for(int i=0;i<yi.size();i++)
  {
    cin>>xi.at(i)>>yi.at(i)>>ai.at(i);
    if(ai.at(i)==1)
    {
      if(x1<=xi.at(i))
      {
        x1=xi.at(i);
      }
    }
    if(ai.at(i)==2)
    {
      if(x2>=xi.at(i))
      {
        x2=xi.at(i);
      }
    }
    if(ai.at(i)==3)
    {
      if(y3<=yi.at(i))
      {
        y3=yi.at(i);
      }
    }
    if(ai.at(i)==4)
    {
      if(y4>=yi.at(i))
      {
        y4=yi.at(i);
      }
    }
  }
  if(x2>=x1 & y4>=y3)
  {
  cout<<(x2-x1)*(y4-y3)<<endl;
  }
  else
  {
    cout<<0<<endl;
  }
}
    
 

Measured memory_bytes: 256
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 'APPROVED'
    for a in A:
        if a % 2 == 0:
            if a % 3 != 0 and a % 5 != 0:
                return 'DENIED'

    return ans

print(solve())

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	int S = 0;
	int seq = 0;
	int p;
	for(int i = 1; i <= N; i++) {
		cin >> p;
		if(i != p) {
			S += seq / 2 + seq % 2;
			seq = 0;
		}
		if(i == p) seq++;
	}
	S += seq / 2 + seq % 2;
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>){

    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val heights = readLine()!!.split(" ").map{it.toInt()}
    val bad = BooleanArray(n)

    repeat(m){
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        if(heights[b-1] > heights[a-1]){
            bad[a-1] = true
        } else if(heights[a-1] > heights[b-1]){
            bad[b-1] = true
        }
        else {
            bad[a-1 ] = true
            bad[b-1] = true
        }
    }

    println(bad.filter { !it }.count())
}



Measured memory_bytes: 62336
n=input()
INF=1e100000
R=[[INF]*n for i in range(n)]
for i in range(n):
    connect=map(int,raw_input().split())
    for i in connect[2:]:
        R[connect[0]-1][i-1]=1
for k in range(n):
    for i in range(n):
        for j in range(n):
            R[i][j]=min(R[i][j],R[i][k]+R[k][j])
p=input()
for i in range(p):
    s1,d1,v1=map(int,raw_input().split())
    d=R[s1-1][d1-1]+1
    if v1>=d:
        print d
    else:
        print "NA"

Measured memory_bytes: 4372
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int N, M;
vector<int> G[1005];
vector<int> ret;

bool is_valid(const vector<int>& path){
  map<int,int> visited;
  rep(i,path.size()){
    visited[path[i]] = 1;
  }

  vector<int> in(1005, 0);
  rep(i,path.size()){
    int x = path[i];
    rep(j,G[x].size()){
      if(visited[G[x][j]] == 1){
        in[G[x][j]]++;
      }
    }
  }

  rep(i,path.size()){
    int x = path[i];
    if(in[x] > 1) return false;
  }
  return true;
}



void solve(int st){
  vector<int> path;
  
  vector<int> parent(1005, -1);
  parent[st] = st;
  queue<int> que;
  que.push(st);
  while(!que.empty()){
    int v = que.front(); que.pop();
    rep(i,G[v].size()){
      if(G[v][i] == st){
        int x = v;
        while(x != st){
          path.push_back(x);
          x = parent[x];
        }
        path.push_back(st);
        if(!is_valid(path)) return;
        break;
      }else{
        if(parent[G[v][i]] != -1){
        }else{
          parent[G[v][i]] = v;
          que.push(G[v][i]);
        }
      }
      if(path.size() > 0) break;
    }
  }



  if(path.size() == 0) return;
  if(ret.size() == 0 || path.size() < ret.size()){
    ret = path;
  }
}

int main(){
  cin >> N >> M;
  rep(i,M){
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
  }


  
  REP(i,1,N+1){
    solve(i);
  }

  if(ret.size() == 0) cout << -1 << endl;
  else {
    cout << ret.size() << endl;
    rep(i,ret.size()){
      cout << ret[i] << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 384
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    ans = 0
    for i in range(1, n + 1):
        for j in range(1, i):
            for k in range(1, j):
                if i + j + k == x:
                    ans += 1
    print(ans)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int main(){
  int n,l;
  cin>>n>>l;
  vector<int> len(n+2,0);
  rep(i,n) cin>>len[i+1];

  // ??????????????°??????????????£??????????????????????????????
  vector<int> arr;
  vector<vector<int>> vec(n+1);
  repl(i,1,n+1){
    if(len[i-1]<len[i] && len[i]>len[i+1]) continue;
    if(len[i-1]>len[i] && len[i]<len[i+1]){
      vec[i-1].pb(i);
      vec[i+1].pb(i);
    } else if(len[i-1] < len[i]){
      vec[i+1].pb(i);
    } else {
      vec[i-1].pb(i);
    }
  }
  vector<bool> visited(n+1, false);
  function<void(int)> dfs = [&](int d){
    visited[d]=true;
    for(auto to : vec[d]) if(!visited[to]) dfs(to);
    arr.pb(d);
  };
  repl(i,1,n+1) if(!visited[i]) dfs(i);
  reverse(all(arr));

  // arr?????????????????????????????????????????????
  long ans = 0;
  vector<long> inits(n+1,0); // ???????????????????§?????????????
  rep(i,n){
    int d = arr[i];
    for(auto to : vec[d]) inits[to] = max(inits[to], inits[d] + l - len[d]);
    ans = max(ans, inits[d] + l - len[d]);
  }
//dbg(arr);dbg(inits);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 8924
#include <iostream>
using namespace std;
int main(void){
  
 int N;
 int C0 = 0;
 int C1 = 0;
 int C2 = 0;
 int C3 = 0;
 cin >> N;
 for (int i = 0; i < N; i++){
 string S;
 cin >> S;

    if (S == "AC"){
        C0++;
    }
    if (S == "WA"){
        C1++;
    }
    if (S == "TLE"){
        C2++;
    }
    if (S == "RE"){
        C3++;
    }
 }
 cout << "AC" << " " << "x" << " " << C0 << endl;
 cout << "WA" <<  " " << "x" << " " <<  C1 << endl;
 cout << "TLE" <<  " " << "x" << " " <<  C2 << endl;
 cout << "RE" <<  " " << "x" << " " <<  C3 << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 1e9;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
int main() {
    int N, M;
    cin >> N >> M;
    vector<P> lr(M);
    REP(i, M){
        int l_tmp, r_tmp;
        cin >> l_tmp >> r_tmp;
        lr[i].first = l_tmp;
        lr[i].second = r_tmp;
    }
    sort(lr.rbegin(), lr.rend());
    int ml = lr[0].first;
    int mr = lr[0].second;
    bool can = true;
    FOR(i, 1, M) {
        if(lr[i].second < ml){
            can = false;
            break;
        }
        if(lr[i].first > ml) {
            ml = lr[i].first;
        }
        if(lr[i].second < mr) {
            mr = lr[i].second;
        }
    }
    if(can) cout << mr - ml + 1 << endl;
    else cout << 0 << endl;
}

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

int main()
{
  ios::sync_with_stdio(false);
  int x;
  cin >> x;

  if (x == 7 or x == 5 or x == 3)
    cout << "YES\n";
  else
    cout << "NO\n";

  return 0;
}

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

int main(){
  while(1){
  int n,m;
  cin>>n>>m;
  if(n==0&&m==0)break;
  vector<int> t(n);
  vector<int> h(m);
  int tsum=0;
  int hsum=0;
  for(int i=0;i<n;i++){
    cin>>t[i];
    tsum+=t[i];
  }
  for(int i=0;i<m;i++){
    cin>>h[i];
    hsum+=h[i];
  }
  int ans=0;
  int anss=tsum-hsum;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if((t[i]-h[j])*2==anss){
        ans=1;
        cout<<t[i]<<" "<<h[j]<<endl;
        break;
      }
    }
    if(ans==1)break;
  }
if(ans==0)cout<<-1<<endl;
}
  return 0;
}

Measured memory_bytes: 2980
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
char Array[1001][1001];
int dp[1001][1001];

int main(){
    int H , W , i , j;
    char ch;
    scanf( "%d%d" , &H , &W );

    for( i = 1 ; i <= H ; ++i ){
        for( j = 1 ; j <= W ; ++j ){
            scanf( "%c" , &ch );

            while( ch != '.' && ch != '#' )
                scanf( "%c" , &ch );
            
            Array[i][j] = ch;
        }
    }

    dp[1][1] = 1;

    for( i = 1 ; i <= H ; ++i ){
        for( j = 1 ; j <= W ; ++j ){
            if( i == 1 && j == 1 ) continue;
            if( Array[i][j] == '#' ) dp[i][j] = 0;
            else dp[i][j] = ( dp[i][j - 1] + dp[i - 1][j] ) % MOD;
        }
    }

    printf( "%d\n" , dp[H][W] );
    return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

int a, b, c, d, e;
main(){
    scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
    printf("%d\n", c*60+d-a*60-b-e);
    return 0;
}

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

int main(){
    long long n, k, d, e, res = 1;
    cin >> n >> k;
    d = n/k;
    e = (n+k/2)/k;
    if(k%2 == 0){
        res = d * d * d + e * e * e;
    }else{
        res = d * d * d;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256