akhauriyash/Code-Regression huggingface dataset:
// Problem : C - Distinct or Not
// Contest : AtCoder Beginner Contest 154
// URL : https://atcoder.jp/contests/abc154/tasks/abc154_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
#define pb emplace_back
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inf LLONG_MAX
using namespace std;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
double pi=acos(-1.0);
int md=1000000007;
int abst(int a)
{return a<0?-a:a;}
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%md;n=(n*n)%md;x=x>>1;}
 return ans;}

 vi fact,inv;
void inverse(int n)
{inv.resize(n+1);inv[0]=1;
for(int i=1;i<=n;i++)inv[i]=Pow(fact[i],md-2);}
void factorial(int n)
{fact.resize(n+1);fact[0]=1;
for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i)%md;}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}

void solve()
{
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;cin>>n;int nt=n;
map<int,int> mp;
while(n--)
{
	int x;cin>>x;
	mp[x]++;
}
if(mp.size()==nt)
cout<<"YES";
else
cout<<"NO";
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
while(t--)
{
    solve();
}
}


Measured memory_bytes: 12800
x, n = gets.chomp.split(" ").map(&:to_i)
p = gets.chomp.split(" ").map(&:to_i)
if !p.include?(x)
  puts x
  exit
end
min = [p.min, x].min
max = [p.max, x].max
arr = ((min - 1)..(max + 1)).select { |n| !p.include?(n) }
m = arr.min_by { |n| (n - x).abs }
puts m


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

int main(){
  int n,limit;
  int cheapest=1001;
  int count = 0;
  cin>>n >>limit;
  vector<int> c(n);
  vector<int> t(n);
  
  for(int i=0;i<n;i++){
    cin>>c.at(i);
    cin>>t.at(i);
  }
  
  for(int i=0;i<n;i++){
    if(t.at(i) <= limit){
      cheapest = min(cheapest,c.at(i));
    }else{
      count++;
    }
  }
  if(count == n){
    cout<<"TLE"<<endl;
  }else{
    cout<<cheapest<<endl;
  }
}
  

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int s,k,x,y,z,ans=0;
  scanf("%d %d",&k,&s);
  for(x=0;x<=k;x++){
    for(y=0;y<=k;y++){
      if((0<=s-(x+y)) && (s-(x+y)<=k)) ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<float> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }

  sort(v.begin(), v.end());
  
  float ave = v.at(0);
  float sum;
  for (int i = 1; i < n; i++) {
    ave = (ave + v.at(i))/2;
  }
  cout << ave << endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N];
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=1;i<=n;i++) cin>>a[i];
        int cnt=0;
        for(int i=1;i<=n;i++){
            if(a[i]==i){
                cnt++;
                swap(a[i],a[i+1]);
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 640
S = input()

point = 0
can_p_cnt = 0
for i in range(len(S)):
  if S[i] == 'g':
    if can_p_cnt > 0:
      #p
      point += 1
      can_p_cnt -= 1
    else:
      #g
      can_p_cnt += 1
  else:
    if can_p_cnt > 0:
      can_p_cnt -= 1
    else:
      point -= 1
      can_p_cnt += 1
      
print(point)

Measured memory_bytes: 3316
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
typedef long long i64;
using namespace std;
void Minimization() {
	int N, K;
	cin >> N >> K;
	int t[100001];
	int res = 1;
	int start = 0;
	for (size_t i = 0; i < N; i++)
	{
		cin >> t[i];
	}
	for (size_t i = 0; i < N; i++)
	{	
		if (i == start + (K - 1)) {
			start += (K - 1);
			if(N - i > 1) res++;
		}
	}

	cout << res << "\n";
}

int main() {
	Minimization();
	return 0;
}

Measured memory_bytes: 640
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]

from collections import Counter

c = Counter(s)
keys, values = zip(*c.most_common())
#print(keys)
#print(values)
ans = 0
n = 0
for i in range(len(values)):
    if values[i] > 1:
        n = values[i]
        ans += n*(n-1)//2
        
print(ans)

Measured memory_bytes: 31788
#include <stdio.h>
#include <stdlib.h>
int i,n,m,a[101],sum,c;
double x;

int main()
{

    scanf("%d %d",&n ,&m);

    for(i=1;i<=n;i++){
        scanf("%d",& a[i]);
        sum=sum+a[i];
    }
     x=sum/(4.0*m);
        for(i=1;i<=n;i++){
        if(a[i]>=x){
            c++;
        }
    }
    if(c>=m)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}





Measured memory_bytes: 128
package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

var cmap [][]int

func count(i, j int) {

}

func main(){
	hw := scanIntSplit(2)
	H, W := hw[0], hw[1]
	cmap := make([][]int, H+2)
	for i:=0; i<H+2; i++ {
		cmap[i] = make([]int, W+2)
	}
	arr := scanStringLine(H)
	for i:=0; i<H; i++ {
		for j, v := range strings.Split(arr[i], "") {
			if v == "#" {
				for di:=0; di<3; di++ {
					for dj:=0; dj<3; dj++{
						cmap[i+di][j+dj]++
					}
				}
				cmap[i+1][j+1] = -100
			}
		}
	}
	for i:=0; i<H; i++ {
		for j:=0; j<W; j++ {
			if cmap[i+1][j+1] < 0 {
				fmt.Print("#")
			} else {
				fmt.Print(cmap[i+1][j+1])
			}
		}
		fmt.Print("\n")
	} 
}

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

using namespace std;
typedef long long ll;

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

    vector<ll> h(n);
    ll cntMax = 0, cntTmp = 0;
    cin >> h[0];

    for(int i=1; i<n; i++){
        cin >> h[i];
        cntMax = max(cntMax, cntTmp);
        if(h[i-1] >= h[i]){
            cntTmp++;
        }else{
            cntTmp = 0;
        }
    }

    cntMax = max(cntMax, cntTmp);
    cout << cntMax << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
bool sortDescByFirst(const pair<int,int>&a, const pair<int,int>&b){
    return a.first>=b.first;
}
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    char ch;
    while(cin>>ch){
        if(ch=='A')cout<<'T';
        else if(ch=='T')cout<<'A';
        else if(ch=='C')cout<<'G';
        else cout<<'C';
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
from collections import deque
h,w = [int(i) for i in input().split()]
n = int(input())
a0= [int(i) for i in input().split()]
a = []
for i,j in enumerate(a0):
  a.extend([str(i+1) for _ in range(j)])
a.sort()

f=True
for i in range(h):
  n=[]
  for j in range(w):
    n.append(a.pop())
  n.sort(reverse=f)
  print(*n)
  f=not f

Measured memory_bytes: 4524
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#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 ALL(a) (a).begin(), (a).end()

int main() {
    ll N, P;
    cin >> N >> P;

    map<ll, ll> factor;
    for (ll i = 2; i * i <= P; i++) {
        while (P % i == 0) {
            factor[i]++;
            P /= i;
        }
    }
    if (P > 1) factor[P]++;

    ll ans = 1;
    for (pair<ll, ll> p : factor) {
        while (p.second >= N) {
            ans *= p.first;
            p.second -= N;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int N, K;
// int A[(int)2e5];
map<int, int> mp;

int main() {
    cin >> N >> K;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        mp[tmp]++;
    }
    if (mp.size() <= K) {
        cout << 0 << endl;
        return 0;
    }

    vector<pair<int, int>> pairs;
    for (auto iter = mp.begin(); mp.end() != iter; iter++) {
        pairs.push_back(make_pair(iter->second, iter->first));
    }

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

    int size = mp.size();
    int ans = 0;
    int idx = 0;
    while (size > K) {
        ans += pairs[idx].first;
        size--;
        idx++;
    }

    // rep(i, pairs.size()) {
    //     printf("%d-%d\n", pairs[i].first, pairs[i].second);
    // }
    cout << ans << endl;
}

Measured memory_bytes: 11768
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    int w, a, b;
    cin >> w >> a >> b;
    cout << max(abs(a-b) - w, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

#include <complex>
typedef complex<double> P;

// 内積 (dot product) : a・b = |a||b|cosΘ
double dot(P a, P b) {
 return (a.real() * b.real() + a.imag() * b.imag());
}

// 外積 (cross product) : a×b = |a||b|sinΘ
double cross(P a, P b) {
 return (a.real() * b.imag() - a.imag() * b.real());
}

// 進行方向
// 与えられた三点 a, b, c を a → b → c と進むとき，
// a → b で時計方向に折れて b → c
// a → b で半時計方向に折れて b → c
// a → b で逆を向いて a を通り越して b → c
// a → b でそのまま b → c
// a → b で逆を向いて b → c ( または b == c )
int ccw(P a, P b, P c) {
 b -= a; c -= a;
 if (cross(b, c) > 0)   return +1;       // counter clockwise
 if (cross(b, c) < 0)   return -1;       // clockwise
 if (dot(b, c) < 0)     return +2;       // c--a--b on line
 if (norm(b) < norm(c)) return -2;       // a--b--c on line
 return 0;                               // a--c--b on line
}

int main(){
	int n,m,w,h,s;
	while(cin>>n>>m>>w>>h>>s,n|m|w|h|s){
		vi l(m),r(m);
		REP(i,m){
			cin>>l[i]>>r[i];
		}
		vector<double> x(n),y(n);
		REP(i,n){
			cin>>x[i]>>y[i];
		}

		vi almond(m);
		REP(i,n){
			int lb=-1,ub=m;
			while(ub-lb>1){
				int mid=(lb+ub)/2;
				if(ccw(P(0,l[mid]),P(w,r[mid]),P(x[i],y[i]))!=1){
					ub=mid;
				}else{
					lb=mid;
				}
			}
			almond[ub]++;
		}
		vi total_almond(m+1);
		REP(i,m){
			total_almond[i+1]=total_almond[i]+almond[i];
		}

		vi total_area(m+1);
		REP(i,m){
			total_area[i+1]=(l[i]+r[i])*w/2;
		}

		int ans_almond=INT_MAX;
		REP(i,m){
			int lb=i-1,ub=m;
			while(ub-lb>1){
				int mid=(lb+ub)/2;
				if(total_area[mid+1]-total_area[i]>total_area[m]-s){
					ub=mid;
				}else{
					lb=mid;
				}
			}
			ans_almond=min(ans_almond,total_almond[m]-(total_almond[ub]-total_almond[i]));
		}
		cout<<ans_almond<<endl;
	}
}

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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> L(N);
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
    }
    sort(L.begin(), L.end());
    int sum = 0;
    for (int i = 0; i < K; i++)
    {
        sum += L[N - 1 - i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int MAXN = 1e5+5;
int n;
char vis[MAXN];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),vis[0]=1;
	for(ri i=0;i<=n;++i){
		for(ri j=100;j<=105;++j){
			if(i+j>n)
				break;
			vis[i+j]|=vis[i];
		}
	}
	print(vis[n]?1:0);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>
#include <stack>

using namespace std;

const long long MOD = 998244353;
long long dp[200001];

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

	int N;
	cin >> N;

	vector<pair<int, long long>> vlist(N, make_pair(0, 0));
	for (int i = 0; i < N; i++)
	{
		cin >> vlist[i].first >> vlist[i].second;
	}

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

	dp[N] = 1;

	stack<pair<int, long long>> s;
	s.push(make_pair(N, numeric_limits<int>::max()));

	for (int i = N - 1; i >= 0; i--)
	{
		while (s.top().second < vlist[i].first + vlist[i].second) s.pop();
		dp[i] = (dp[s.top().first] + dp[i + 1]) % MOD;
		s.push(make_pair(i, vlist[i].first));
	}

	cout << dp[0];

	return 0;
}

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

long long k, x;
string ans;

void in();
void solve();
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> k >> x;
}

void solve(){
    ans = "No";
    if(k * 500 >= x)
       ans = "Yes";
}

void out(){
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
#define ll long long int
#define ld long double

int main()
{
	ll l;
	cin>>l;
	ld d;
	d=l/3.0;
	d=d*d*d;
	cout<<fixed<<setprecision(12)<<d<<endl;

	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> V(N);
  while (K--) {
    int D;
    cin >> D;
    while (D--) {
      int A;
      cin >> A;
      V.at(--A)++;
    }
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (!V.at(i)) cnt++;
  }
  cout << cnt << "\n";
}

Measured memory_bytes: 3628
"use strict";

function Main(input) {
	let textNum = input.split('\n')[0]*1;
  	let text = input.split('\n')[1];
  	let ans = 0;
  	for(let i =0; i< textNum - 2; i++){
    	if(text[i]== "A" 
           && text[i + 1]== "B"
           && text[i + 2]== "C"
        ){
        	ans++;
        }
    }
  	console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto s = readln().chomp();
    auto r = "AKIHABARA";
    string t;
    foreach(si; s) {
        if(r.startsWith(t ~ si)) {
            t ~= si;
            continue;
        }
        if(r.startsWith(t~"A")) {
            t ~= "A";
        }
        if(r.startsWith(t ~ si)) {
            t ~= si;
            continue;
        }
        writeln("NO");
        return;
    }
    if(t == "AKIHABAR" || t == "AKIHABARA") {
        writeln("YES");
    } else {
        writeln("NO");
    }
}



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

using namespace std;

using ll = long long;

int main() {
    string s;
    cin >> s;

    int n = s.size();
    map<string, int> ss;

    int cnt[26] = {};
    for (char c : s) {
        cnt[c - 'a']++;
    }

    ll ans = 1;
    for (int i = 0; i < n; i++) {
        ans += n - 1 - i - (--cnt[s[i] - 'a']);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s;
	cin>>s;
	s = "#"+s;
	int n=sz(s)-1;
	if(s[n]=='1' || s[1]=='0')
	{
		cout<<"-1\n";
		return 0;
	}
	for(int i=1;i<n;i++)
	{
		if(s[i]!=s[n-i])
		{
			cout<<"-1\n";
			return 0;
		}
	}
	for(int i=1;i<=n-1;i++)
	{
		if(s[i]=='0')
			continue;
		int j=i+1;
		while(j<n-1 && s[j]=='0')
			j++;
		for(int k=i;k<j;k++)
		{
			cout<<j<<" "<<k<<"\n";
		}
	}
}

Measured memory_bytes: 1664
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CPrison solver = new CPrison();
        solver.solve(1, in, out);
        out.close();
    }

    static class CPrison {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            int l = 1, r = n;

            for (int i = 0; i < m; i++) {
                int x = in.nextInt(), y = in.nextInt();

                l = Math.max(l, x);
                r = Math.min(r, y);
            }

            int answer = r - l + 1;
            answer = Math.max(0, answer);

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 41304
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        flag = True
        for y in range(M):
            for x in range(M):
                if A[i+y][j+x] != B[y][x]:
                    flag = False
                    break
            if flag == False:
                break
        if flag:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

int K,X;

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

    cin>>K>>X;
    FOR(i,-1000000, 1000000)
    {
        if( i>=X-K+1 && i<=X+K-1 )cout<<i<<' ';
    }
    cout<<'\n';

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int data[200];
int main(){
	int n,q;
	while(1){
		cin >> n >> q;
		if(n==0&&q==0) return 0;
		REP(i,200) data[i] = 0;
		REP(i,n){
			int tmp;
			cin >> tmp;
			REP(j,tmp){
				int t2;
				cin >> t2;
				data[t2]++;
			}
		}
		int ans = 0;
		int pnum = 0;
		REP(i,200){
			if(data[i]>=q){
				if(pnum<data[i]){
					ans = i;
					pnum = data[i];
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <queue>
#include <set>
#include <stdio.h>
#include <climits>
#include <map>
#include <time.h>
#include <random>
//#include "rubo.h"

#define dbl long double
#define pb push_back
#define mp make_pair
#define SQ(x) (x)*(x)
#define ll long long
#define ull unsigned long long
#define vc vector
#define X first
#define Y second
//#define in ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt...) (0)
//#define puts(fmt...) (0)

//#include "rubo.h"

using namespace std;

const int N = 33;


int main() {
	string s;
	cin >> s;
	loop(i, s.length() - 8)
		cout << s[i];
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using L=int;
using namespace std;
#define R for(L i=H;i>=0;i--)
#define P for(L j=0;j<N;j++)



L H,N,A[1005],B[1005],d[30004]={};
int main(){
	cin>>H>>N;
	P cin>>A[j]>>B[j];
	R d[i]=1e9;
	d[H]=0;
	R P d[max(i-A[j],0)]=min(d[max(i-A[j],0)],d[i]+B[j]);
	cout<<d[0];
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
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;}

int n;  
bool used[110];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vector<Pii> red(n), blue(n);
    rep(i, 0, n) {
        int x, y; cin >> x >> y;
        red[i] = mp(x, y);
    }
    rep(i, 0, n) {
        int x, y; cin >> x >> y;
        blue[i] = mp(x, y);
    }
    int ans = 0;
    sort(all(red)); sort(all(blue));
    rep(i, 0, n) {
        int dist = INF, itr = -1;
        rep(j, 0, n) {
            if (!used[j] && red[j].first < blue[i].first && red[j].second < blue[i].second) {
                if (dist > blue[i].second - red[j].second) {
                    itr = j;
                    dist = blue[i].second - red[j].second;
                }
            }
        }
        if (itr == -1) continue;
        else {
            used[itr] = true;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

word = {}

for i in range(N):
    s = input()
    if s in word:
        word[s] += 1
    else:
        word[s] = 1

M = int(input())

for i in range(M):
    t = input()
    if t in word:
        word[t] -= 1

money = max(word.values())

if money >= 0:
    print(money)
else:
    print(0)


Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			// l
			scanner.nextInt();
			System.out.println(
					IntStream.range(0, n).mapToObj(i -> scanner.next()).sorted().collect(Collectors.joining()));
		}
	}
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 998244353

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll dp[C+1][D+1], r[C+1][D+1], u[C+1][D+1];

  dp[A][B] = 1;
  r[A][B] = 0;
  u[A][B] = 0;

  repi(a, A+1, C+1){
    dp[a][B] = dp[a-1][B] * B % MOD;
    r[a][B] = (r[a-1][B]*(B-1) + dp[a-1][B]) % MOD;
    u[a][B] = 0;
  }
  repi(b, B+1, D+1){
    dp[A][b] = dp[A][b-1] * A % MOD;
    u[A][b] = (u[A][b-1]*(A-1) + dp[A][b-1]) % MOD; 
    r[A][b] = 0;
  }

  repi(a, A+1, C+1) repi(b, B+1, D+1){
    dp[a][b] = (dp[a-1][b] + dp[a][b-1] + (a-1)*(b-1)*dp[a-1][b-1] + (b-1)*r[a-1][b] + (a-1)*u[a][b-1]) % MOD;
    r[a][b] = (r[a-1][b]*(b-1) + dp[a-1][b]) % MOD;
    u[a][b] = (u[a][b-1]*(a-1) + dp[a][b-1]) % MOD;
  }

  cout << dp[C][D] << endl;
  return 0;
}



Measured memory_bytes: 214584
import java.util.*;

public class Main{
	public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
	    int n=sc.nextInt();
	    int[] a=new int[n+1];
	    
	    
	    int ans=0;
	    
	    for(int i=1;i<=n;i++) {
	    	a[i]=sc.nextInt();
	    }
	
	   
	    for(int i=1;i<=n;i++) {
	    	if((i%2==1) &&(a[i]%2==1))ans++;
	    }
	

	    System.out.println(ans);
	}
}


Measured memory_bytes: 35696
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, l;
vector<string> s;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>l;
    s.resize(n);
    rep(i,n)cin>>s[i];
    sort(ALL(s));
    string ans="";
    rep(i,n)ans+=s[i];
    cout<<ans<<"\n";
}


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

using ll = long long;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SIZE(a) ((int)(a).size())

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

	int n, a, b;
	cin >> n >> a >> b;
	if (a > b) {
		cout << 0 << '\n';
		return 0;
	}

	if (n == 1) {
		if (a != b) {
			cout << 0 << '\n';
		} else
		cout << 1 << '\n';
		return 0;
	}

	cout << 1LL*(n-2)*(b-a)+1 << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int N;
    cin >> N;
    vector<int> input(N);
    rep0(i, N)
    {
        cin >> input[i];
    }
    int res = input[0];
    rep0(i, N)
    {
        res = gcd(res, input[i]);
    }
    cout << res;
}


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

	int x, h;
	double xd, hd, s;
	while(scanf("%d%d",&x,&h) != EOF){
		if(x == 0 && h == 0){break;}
		xd = x;
		hd = h;
		s = xd * (2 * sqrt(hd*hd + xd*xd / 4) + xd);
		printf("%.6lf\n",s);
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

static const int MAX = 500;
static const int INFTY = (1<<21);

int main(){
  int n, i, j, e, sum,u,m;
  /*
    
    your code
    

  */
  int M[MAX][MAX];
  int d[MAX];
  int k[MAX],p[MAX];
  
  scanf("%d", &n);
  
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }
  
  /*

    your code
    
  */
  for(i=0;i<n;i++){
    p[i]=-1;
    k[i]=INFTY;
    d[i]=0;
  }
  k[0]=0;
  
  while(1){
    u=-1;
    m=INFTY;
    
    for(i=0;i<n;i++){
      if( d[i]==0 && m>k[i] ){
	u=i;
	m=k[i];
      }
    }
    if(u==-1)break;
    d[u]=1;
    for(i=0;i<n;i++){
      if(k[i]>=M[u][i]&&d[i]==0){
	p[i]=u;
	k[i]=M[u][i];
      }
    }
  }
    
    sum = 0;
    
    for ( i = 0; i < n; i++ ){
      if ( p[i] != -1 ) sum += M[i][p[i]];
    }
  
  printf("%d\n", sum);
  
  return 0;
}

Measured memory_bytes: 808
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	
//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
	
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(max(a*c,a*d),max(b*c,b*d))<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

ll dp[100100][13]={};

int main(void){
    string s;
    cin>>s;
    ll n=s.size();
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        if(s[i]=='?'){
            for(int a=0;a<=9;a++){
                for(int j=0;j<13;j++){
                    dp[i+1][(10*j+a)%13]+=dp[i][j];
                    dp[i+1][(10*j+a)%13]%=mod;
                }
            }
        }
        else{
            int a=s[i]-'0';
            for(int j=0;j<13;j++){
                dp[i+1][(10*j+a)%13]+=dp[i][j];
                dp[i+1][(10*j+a)%13]%=mod;
            }
        }
    }
    cout<<dp[n][5]<<endl;
}

Measured memory_bytes: 13896
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    const int INF = 1e6;
    LLONG N, K; cin >> N >> K;
    vector<int> as(N);
    for (auto &ai : as)
    {
        cin >> ai; --ai;
    }
    vector<bool> hasArrived(N, false);
    vector<int> steps(N, INF);
    hasArrived[0] = true;
    steps[0] = 0;
    // K回移動するか，同じ街に戻ってくるまでテレポート
    int prev = 0;
    LLONG preLoopSize = 0;
    LLONG loopSize = 0;
    deque<int> loop{ 0 };
    for (LLONG step = 1; step <= K; ++step)
    {
        int next = as[prev];
        if (hasArrived[next])
        {
            preLoopSize = steps[next];
            loopSize = step - steps[next];
            break;
        }
        else
        {
            hasArrived[next] = true;
            steps[next] = step;
            loop.push_back(next);
            prev = next;
        }
    }
    if (loopSize == 0)
    {
        cout << prev + 1 << endl;
        return 0;
    }
    vector<int> preLoop;
    for (int i = 0; i < preLoopSize; ++i)
    {
        preLoop.push_back(loop.front());
        loop.pop_front();
    }
    K -= preLoopSize;
    cout << loop[K % loopSize] + 1 << endl;
}

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

int main() {
  int64_t n;
  cin >> n;
  if(n % 2 == 1) cout << 0 << endl;
  else{
    int64_t c = 0, p = 1, q = 1;
    for(int i = 0; i < 30; ++i){
      q *= 5;
      if(n / q < 2) break;
      c += (n / q) / 2;
    }
    cout << c << endl;
  }
}



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

using namespace std;

int main(){
    string s;
    cin >> s;
    if('a' <= s[0] && s[0] <= 'z') cout << "a";
    else if('A' <= s[0] && s[0] <= 'Z') cout << "A";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int a,v;
    int b,w;
    int t;
    cin >> a >> v;
    cin >> b >> w;
    cin >> t;
    int dis = abs(a-b);
    if(v-w > 0 && (dis+v-w-1)/(v-w)<=t)cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

using namespace std;

const int N = 100010;
int n, m;
int arr[N], par[N], sz[N], vis[N];

void make_set(int v) {
  par[v] = v;
  sz[v] = 1;
}

int find_set(int v) {
  if (v == par[v]) return v;
  return find_set(par[v]);
}

void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (sz[a] < sz[b]) swap(a, b);
    par[b] = a;
    sz[a] += sz[b];
  }
}

vector<int> pos[N], v[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> arr[i];
  for (int i = 1; i <= n; ++i) make_set(i);
  while (m--) {
    int x, y;
    cin >> x >> y;
    union_sets(x, y);
  }
  for (int i = 1; i <= n; ++i) {
    v[find_set(i)].push_back(arr[i]);
    pos[find_set(i)].push_back(i);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int x = find_set(i);
    if (!vis[x]) {
      vis[x] = 1;
      sort(v[x].begin(), v[x].end());
      for (auto p: pos[x]) ans += (int)binary_search(v[x].begin(), v[x].end(), p);
    }
  }
  cout << ans << '\n';
}

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

using namespace std;

const int maxn=1e4+5;

int n,s1[maxn];

int linearsearch(int key)
{
    s1[n]=key;
    int i=0;
    while(s1[i]!=key){
        i++;
    }
    return i!=n;
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&s1[i]);
    }
    int cnt,key,sum=0;
    scanf("%d",&cnt);
    for(int i=0;i<cnt;i++){
        scanf("%d",&key);
        if(linearsearch(key)){
            sum++;
        }
    }
    printf("%d\n",sum);
    return 0;
}
/*
5
1 2 3 4 5
3
3 4 1
*/



Measured memory_bytes: 3188
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  string s, t, t_check;
  cin >> s;
  cin >> t;
  int s_len = s.length();
  t_check = t.substr(0, s_len);
  if (s == t_check){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
} 

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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        _i64 n; string n_str; cin >> n;
        _for(i, 1, n + 1) {
            if(i % 3 == 0) { cout << " " << i; }
            else {
                n_str = to_string(i);
                if(n_str.find("3") != string::npos) { cout << " " << i; }
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3284
#include<iostream>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;

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

  int T[N], t = 0;
  rep(i,0,N-1) cin >> T[i], t += T[i];

  int M;
  cin >> M;
  rep(i,0,M-1) {
    int p, x;
    cin >> p >> x;
    cout << t + x - T[p-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using LLpair = pair<LL, LL>;
using ULL = uint64_t;
using mypair = pair<LL, vector<LL>>;
//#define DEBUG

int main() {
  LL n, m, x;
  cin >> n >> m >> x;

  vector<mypair> a(n);
  for (LL i = 0; i < n; ++i) {
    LL c;
    cin >> c;

    vector<LL> aa(m);
    for (LL j = 0; j < m; ++j) {
      cin >> aa[j];
    }

    a[i] = make_pair(c, aa);
  }

  LL cost_min = -1;
  for (ULL i = 0; i < (2u << (n - 1)); ++i) {
    vector<LL> rikai_sum(m, 0);
    LL cost_sum = 0;
    for (LL j = 0; j < n; ++j) {
      if ((i >> j) % 2u == 1) {
        // Use j-th book.
        #ifdef DEBUG
        cout << "i = " << i << ": "  << j << "-th book used.\n";
        #endif
        for (LL k = 0; k < m; ++k) {
          rikai_sum[k] += a[j].second.at(k);
        }
        cost_sum += a[j].first;
      }
    }
    // check rikai-do
    bool ok = true;
    for (LL k = 0; k < m; ++k) {
      if (rikai_sum[k] < x) {
        ok = false;
        break;
      }
    }

    if (ok && (cost_min == -1 || cost_sum < cost_min)) {
      cost_min = cost_sum;
    }
  }
  cout << cost_min << endl;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int>a(n-1);
  vector<int>cnt(n);
  for(int i = 0;i<n-1;i++){
    cin >> a.at(i);
    cnt.at(a.at(i)-1)++;
  }
  for(int i = 0;i<n;i++){
    cout << cnt.at(i) << endl;
  }
}

Measured memory_bytes: 4780
#include <iomanip>
#include <iostream>

using namespace std;

const double rate = 380000.0;

int main(int argc, char* argv[])
{
    int N; cin >> N;

    double total = 0;
    for (int i = 0; i < N; i++) {
        double x; cin >> x;
        string cur; cin >> cur;

        if (cur == "JPY") {
            total += x;
        } else {
            total += x*rate;
        }
    }

    cout << fixed << setprecision(9) << total << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main()
{
    int n,i;
    double xa ,ya ,ra ,xb ,yb ,rb ,dist;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%lf %lf %lf %lf %lf %lf", &xa ,&ya ,&ra ,&xb ,&yb ,&rb);
        dist = sqrt((xb-xa)*(xb-xa)+(yb-ya)*(yb-ya));
        if(dist>ra+rb) puts("0");
        else if(dist<ra-rb) puts("2");
        else if(dist<rb-ra) puts("-2");
        else puts ("1");
    }
    return 0;
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
using namespace std;
// 7903247656
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define eb emplace_back
#define pb push_back
#define mk make_pair
#define mt make_tuple

#define Umap unordered_map
#define graph vector<vector<int>>

#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl

#define INF 1e9+5
#define N 40001
#define MAXN   100001


bool sortbysec(const tuple<int, int, int>& a,  
               const tuple<int, int, int>& b) 
{ 
    return (get<1>(a) < get<1>(b)); 
}
// void dfs(int s, graph &g, bool vis[], int path){
// 	vis[s] = true;
	
// 	for(int i=0;i<g[s].size();i++){
// 		if(!vis[g[s][i]]) {dfs(g[s][i],g,vis); }
// 	}

// }

string common_prefix(vector<string>& strings){
	string prefix;
	for(string s : strings){
		for(int i=0;i<s.size() && s[i]!='*';++i){
			if(i<prefix.size()){
				if(s[i]!=prefix[i]) return "*";
			}
			else prefix+=s[i];
		}
	}
	return prefix;
}

void reverse(vector<string>& strings){
	for(string& s : strings){
		reverse(s.begin(),s.end());
	}
}

int spf[0];
void sieve(){
	spf[1] = 1;
	for(int i=2;i<MAXN;i++) spf[i] = i;

	for(int i=4;i<MAXN;i+=2) spf[i] = 2;

	for(int i=3; i*i<MAXN;i++){
		if(spf[i]==i){
			for(int j=i*i;j<MAXN;j+=i){
				if(spf[j]==j) spf[j] = i;
			}
		}
	}
}
vector<int> getFactorization(int x){

	vector<int> primeFactors;
	while(x>1){
		primeFactors.pb(spf[x]);
		x /= spf[x];
	}
	return primeFactors;
}


#define ll long long
void max_self(int& a, int b) {
    a = max(a, b);
}
int dfs(int s, graph& g, vector<bool>&vis){
	vis[s] = true;
	
	int path = 0;

	for(auto& vertex : g[s]){
		if(!vis[vertex]){
			
			max_self(path,dfs(vertex,g,vis)+1);
		}
	}
	return max(path,1);
}

void B(){
	// sieve(); 
	int n,k;  cin>>n>>k;
	vector<int>num(n); set<int>st;
	for(int i=0;i<n;i++) {cin>>num[i]; st.insert(num[i]);}

	int size = st.size();
	if(size > k) {cout<<-1<<endl; return ;}

	cout<<n*k<<endl;
	for(int i=0;i<n; i++){
		for(auto& x : st) cout<<x<<" ";
		for(int j=0;j<k-size;j++) cout<<1<<" ";
	}
	cout<<endl;
}
void solve(){
	int n,k; cin>>n>>k;
	vector<int>height(n);
	for(int& x : height) cin>>x;

	vector<int>dp(n,INF);
	dp[0] = 0;
	for(int i=1;i<n;i++){
		for(int j=1;j<=k;j++){
			if(i-j<0) continue;
			dp[i] = min(dp[i],dp[i-j]+abs(height[i]-height[i-j]));
		}
	}
	cout<<dp[n-1]<<endl;
}

int main() {
IOS;
	int t=1; 
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 1024