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

int main()
{
    int n;
    cin>>n;
    int arr[n+5];
    for(int i=1;i<n;i++)cin>>arr[i];
    int frr[n+5]={0};

    for(int i=0;i<n;i++)
    {
        if(i==0)frr[i]=arr[i+1];
        else
        {
            if(max(frr[i-1],arr[i])==arr[i])
            {
                frr[i]=arr[i];
            }
            else
            {
                frr[i-1]=arr[i];
                frr[i]=arr[i];
            }
        }
    }
    int sum=0;
    for(int i=0;i<n;i++)sum+=frr[i];
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cctype>

int main(){
	while(true){
		char str[101], cmd[2];
		scanf("%100s %1s", str, cmd);
		if(cmd[0] == 'X'){ break; }
		bool isFirst = true, isPause = true;
		for(char *p = str; *p != '\0'; p++){
			if(!isFirst){
				if(!(*p & 0x20)){ isPause = true; }
				if(*p == '_'){
					isPause = true;
					if(*++p == '\0'){ break; }
				}
			}
			switch(cmd[0]){
			case 'U':
				if(isPause){
					putc(toupper(*p), stdout);
				}else{
					putc(tolower(*p), stdout);
				}
				break;
			case 'L':
				if(isPause && !isFirst){
					putc(toupper(*p), stdout);
				}else{
					putc(tolower(*p), stdout);
				}
				break;
			case 'D':
				if(isPause && !isFirst){
					putc('_', stdout); putc(tolower(*p), stdout);
				}else{
					putc(tolower(*p), stdout);
				}
			}
			isPause = false;
			isFirst = false;
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int> vx(n, 0), vy(n, 0), vh(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> vx[i] >> vy[i] >> vh[i];
	}
	for (int x = 0; x <= 100; x++) {
		for (int y = 0; y <= 100; y++) {
			int h1 = 1, h2 = 1e9 + 200;
			while (h1 <= h2) {
				int m = h1 / 2 + h2 / 2 + (h1 % 2 + h2 % 2) / 2;
				int flag = 0;
				for (int i = 0; i < n; i++) {
					int h = max(0, m - abs(vx[i] - x) - abs(vy[i] - y));
					if (h < vh[i]) {
						flag = 1;
					} else if (h > vh[i]) {
						flag = -1;
					}
				}
				if (flag == 0) {
					cout << x << " " << y << " " << m << endl;
					return 0;
				} else if (flag == 1) {
					h1 = m + 1;
				} else {
					h2 = m - 1;
				}
			}	
		}
	}
}


Measured memory_bytes: 3616
#include<iostream>
#include<cstdlib>

using namespace std;

int main(){
	int N, M;
	int a[50], b[50], c[50], d[50];
	cin >> N >> M;
	for(int i = 0; i < N; i++){
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i < M; i++){
		cin >> c[i] >> d[i];
	}
	for(int i = 0; i < N; i++){
		int min = abs(a[i] - c[0]) + abs(b[i] - d[0]);
		int minnum = 0;
		for(int j = 1; j < M; j++){
			int buff = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if(buff < min){
				min = buff;
				minnum = j;
			}
		}
		cout << minnum + 1 << endl;
	}
}

Measured memory_bytes: 256
from collections import deque
n,m=map(int,input().split())
road=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    road[a-1].append(b-1)
    road[b-1].append(a-1)

def bfs(u):
    queue=deque([u])
    d=[0]*n
    ans=[0]*n
    while queue:
        v=queue.popleft()
        for i in road[v]:
            if d[i]==0 and i!=0:
                d[i]=d[v]+1
                ans[i]=v+1
                queue.append(i)
    return d,ans

def main():
    d,ans=bfs(0)
    flg=1
    for i in range(1,n):
        if d[i]==0:
            flg=0
            break
    if flg==0:
        print("No")
    else:
        print("Yes")
        for i in range(1,n):
            print(ans[i])
if __name__=="__main__":
    main()

Measured memory_bytes: 37860
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	
	
	long long n,k; cin>>n>>k;
	long long x,co = 0;
	for(int i = 0; i < n; i++){
		cin>>x;
		if(x >= k)co++;
	}
	cout<<co<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,st,en) for(i=st;i<=en;i++)
#define repv(i,en,st) for(i=en;i>=st;i--)
#define fout cout<<fixed<<setprecision(7)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)


typedef long long ll;
typedef pair<int,int> pii;
const int N = 100010;
ll mod = 1e9+7;
ll fmod(ll b,ll exp){
    ll res =1;
    while(exp){if(exp&1ll)res=(res*b)%mod;
    b =(b*b)%mod;exp/=2ll;
    }
    return res;
}

int A[N];
int dp[N];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1,n,i,j,m;
    cin>>n;
    dp[1]=0;
    rep(i,1,n)cin>>A[i];
    dp[2]= abs(A[2]-A[1]);
    rep(i,3,n)dp[i]=min(dp[i-1]+abs(A[i]-A[i-1]),dp[i-2]+abs(A[i]-A[i-2]));
    cout<<dp[n]<<"\n";

    
    return 0;
}


Measured memory_bytes: 1024
N, L = list(map(int, input().split()))

work = 1e9
ans = -1
for i in range(1,N+1):
  al = N*L + N * (N-1) // 2 
  a = L + i - 1
  b = al - a
  #print(i,a,b,al)
  if abs(al - b) < work:
    work = abs(al - b)
    ans = b
    
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	long long A, B;
	double C;
	cin >> A >> C;
	B = (long long)(100.0 * C + 0.5);
	cout << A * B / 100LL << endl;
	return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());
  if(s < t)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3616
N,W=map(int,input().split())
P=[list(map(int, input().split())) for _ in range(N)]

mem=[[0]*(W+2) for _ in range(N+2)]

for i in range(N,0,-1):
    for w in range(0,W+1):
        value, weight=P[i-1]
        if w < weight:
            mem[i][w] =mem[i+1][w]
        else:
            mem[i][w]=max(mem[i+1][w], mem[i+1][w-weight]+value)
print(mem[1][W])


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

typedef long long ll;

using namespace std;

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

	int N, M, ans = 0; cin >> N >> M;
	vector<int> a(N);

	for (int i = 0; i < M; ++i) {
		int k; cin >> k;
		for (int j = 0; j < k; ++j) {
			int s; cin >> s;
			s--;
			a[s] |= 1 << i;
		}
	}

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

	for (int s = 0; s < (1 << N); s++) {
		int t = 0;
		for (int i = 0; i < N; i++)
		{
			if (s >> i & 1) { t ^= a[i]; }
		}
		if (t == p) { ans++; }
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var N int

func main() {
	fmt.Scan(&N)
	S := make([]string, N)
	xxx := make(map[string]int, N)

	for i := 0; i < N; i++ {
		fmt.Scan(&S[i])
		xxx[S[i]]++
	}

	if len(xxx) == 3 {
		fmt.Println("Three")
	} else {
		fmt.Println("Four")
	}
}

/*  ----------------------------------------  */

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

// type LR []int

// func (a SortBy) Len() int           { return len(a) }
// func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
// func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }


Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
  int a, b;
  int d, r;
  double f;

  scanf("%d %d", &a, &b);

  d = a/b;
  r = a%b;
  f = (double)a/b;

  printf("%d %d %f\n", d, r, f);

  return 0;
}

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

using namespace std;
typedef long long ll;
#define lp(x,q) for(ll i=x ;i<q;i++)
#define sor(v) sort(v.begin(),v.end())
#define rsor(v) sort(v.rbegin(),v.rend())
#define df vector<ll>
#define minn(v) *min_element(v.begin(),v.end())
#define maxx(v) *max_element(v.begin(),v.end())
#define MY_TORNADO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//Global variable :
#define rev(v) reverse(v.begin(),v.end())
#define print(v) for(auto f:v)cout<<f<<" ";
ll cou,ans=0,mx=INT_MIN,mn=INT_MAX,sum=0,modu=1e9+7;

//use scanf,printf,getline

int main(){MY_TORNADO;
int t;
cin>>t;
vector<pair<string,int>>v(t);
for(int x=0;x<t;x++)cin>>v[x].first>>v[x].second;
string a;
cin>>a;
int y=0;
sum=0;
for(int x=0;x<t;x++){
if(y)sum+=v[x].second;
if(a==v[x].first)y++;
}
cout<<sum;
return 0;}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>

const int INF = 1000000009;
const long LINF = 1123456789012345678;

long n;
long c;
long x[100000];
long v[100000];
long rcost[100000];
long lcost[100000];
long rmax[100000];
long lmax[100000];

int main(){
	scanf("%ld%ld", &n, &c);
	for(int i = 0; i < n; i++){
		scanf("%ld%ld", &x[i], &v[i]);
	}
	for(int i = 0; i < n; i++){
		if(i == 0){
			rcost[0] = v[0] - x[0];
		}else{
			rcost[i] = v[i] - (x[i] - x[i-1]) + rcost[i-1];
		}
	}
	for(int i = n-1; i >= 0; i--){
		if(i == n-1){
			lcost[n-1] = v[n-1] - (c - x[n-1]);
		}else{
			lcost[i] = v[i] - (x[i+1] - x[i]) + lcost[i+1];
		}
	}
	/*
	printf("right\n");
	for(int i = 0; i < n; i++){
		printf("	%ld\n", rcost[i]);
	}
	printf("left\n");
	for(int i = 0; i < n; i++){
		printf("	%ld\n", lcost[i]);
	}
	//*/
	rmax[0] = rcost[0];
	lmax[n-1] = lcost[n-1];
	for(int i = 1; i < n; i++){
		rmax[i] = std::max(rcost[i], rmax[i-1]);
	}
	for(int i = n-2; i >= 0; i--){
		lmax[i] = std::max(lcost[i], lmax[i+1]);
	}
	/*
	printf("right\n");
	for(int i = 0; i < n; i++){
		printf("	%ld\n", rmax[i]);
	}
	printf("left\n");
	for(int i = 0; i < n; i++){
		printf("	%ld\n", lmax[i]);
	}
	//*/
	long max = rmax[n-1];
	for(int i = 0; i < n-1; i++){
		max = std::max(max, rmax[i] + lmax[i+1] - x[i]);
	}
	max = std::max(lmax[0], max);
	for(int i = n-1; i > 0; i--){
		max = std::max(max, lmax[i] + rmax[i-1] - (c - x[i]));
	}
	if(max < 0){
		max = 0;
	}
	printf("%ld\n", max);
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9+1;
const int MOD = 2e9 + 9;
const ll LINF = 1e18;
using namespace std;

int two(int n) {
	int cnt = 0;
	int m = n;
	for (int i = 0; i < m; i++) {
		if (n % 2 == 0) {
			cnt++;
			n = n / 2;
		}
		else return cnt;
		
	}
	return cnt;
}
int main() {
	int n,k;
	int cnt = 0;
	int cnt2 = 0;
	int ans=0;
	cin >> n >> k;
	vector<int> a(n),b(n);

	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
		b.at(a.at(i)-1)++;
	}
	for (int i = 0; i < n; i++) {
		if (b.at(i) != 0)cnt++;
	}
	sort(b.begin(), b.end());
	for (int i = 0; i < n; i++) {
		if (b.at(0) == 0)b.erase(b.begin());
	}
	
	if (cnt <= k)ans = 0;
	else {
		for (int i = 0; i < cnt - k; i++) {
			ans += b.at(i);
		}

	}

	//for (int i = 0; i < b.size(); i++)cout << b.at(i) << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4728
N = int(input())
L = list(map(int,input().split()))
count = 1
min_num = L[0]

if N == 1:
    print(1)

else:
    for i in range(1,N):
        min_num = min(L[i-1],min_num)
        if L[i] <= min_num:
            count = count+1
    
    print(count)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

template<typename T>
class retroactive_array {
	vector<T> data;
	vector<pair<int, T>> hist;
public:
	retroactive_array(int N) : data(N) {}
	retroactive_array(int N, T val) : data(N, val) {}
	retroactive_array(const vector<T>& v) : data(v) {}
	retroactive_array(vector<T>&& v) : data(move(v)) {}
	void change(int k, T val) {
		hist.emplace_back(k, data[k]);
		data[k] = val;
	}
	T operator[](int k) const {
		return data[k];
	}
	int get_version() const {
		return hist.size();
	}
	void rollback(int ver) {
		assert(0 <= ver && ver <= (int)hist.size());
		int cnt = hist.size() - ver;
		while (cnt--) {
			data[hist.back().first] = hist.back().second;
			hist.pop_back();
		}
	}
};

class retroactive_UF {
	retroactive_array<int> data;
public:
	retroactive_UF(int n) : data(n, -1) {}
	int find(int a) const {
		return data[a] < 0 ? a : find(data[a]);
	}
	bool same(int a, int b) const {
		return find(a) == find(b);
	}
	void unite(int a, int b) {
		a = find(a);
		b = find(b);
		if (a == b) return;
		if (-data[a] > -data[b]) swap(a, b);
		data.change(b, data[a] + data[b]);
		data.change(a, b);
	}
	int size(int a) const {
		return -data[find(a)];
	}
	int get_version() const {
		return data.get_version();
	}
	void rollback(int ver) {
		data.rollback(ver);
	}
};

class DynamicConnectivity {
	const int v, n;
	vector<vector<pii>> data;
	vector<pii> q;
	int size(int x) {
		int res = 1;
		while (res < x) res <<= 1;
		return res;
	}
	void sub(int node, vector<int>& res, retroactive_UF& uuf) {
		int ver = uuf.get_version();
		for (auto& p : data[node]) uuf.unite(p.first, p.second);
		if (node >= n) {
			if (q[node - n] != pii(-1, -1)) {
				res.push_back(uuf.same(q[node - n].first, q[node - n].second));
			}
		}
		else {
			sub(node << 1, res, uuf);
			sub((node << 1) | 1, res, uuf);
		}
		uuf.rollback(ver);
	}
public:
	DynamicConnectivity(int v_, int n_) : v(v_), n(size(n_)), data(n * 2), q(n, pii(-1, -1)) {}
	void add_edge(int l, int r, int u, int v) {
		l += n, r += n;
		while (l < r) {
			if (l & 1) data[l++].emplace_back(u, v);
			if (r & 1) data[--r].emplace_back(u, v);
			l >>= 1, r >>= 1;
		}
	}
	void add_query(int p, int u, int v) {
		q[p].first = u;
		q[p].second = v;
	}
	vector<int> calc() {
		vector<int> res;
		retroactive_UF uuf(v);
		sub(1, res, uuf);
		return res;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> t(k), u(k), v(k);
	for (int i = 0; i < k; i++) {
		cin >> t[i] >> u[i] >> v[i];
	}
	map<pii, int> last;
	DynamicConnectivity dc(n, k);
	for (int i = 0; i < k; i++) {
		if (t[i] == 1) {
			last[pii(u[i], v[i])] = i;
		}
		else if (t[i] == 2) {
			dc.add_edge(last[pii(u[i], v[i])], i, u[i], v[i]);
			last.erase(pii(u[i], v[i]));
		}
		else {
			dc.add_query(i, u[i], v[i]);
		}
	}
	for (auto pp : last) {
		dc.add_edge(pp.second, k, pp.first.first, pp.first.second);
	}
	for (auto ans : dc.calc()) {
		puts(ans ? "YES" : "NO");
	}
	return 0;
}



Measured memory_bytes: 13272
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

ll A, B, C, K;
ll ans;

int main(){
	
	cin>>A>>B>>C>>K;
	
	if( K % 2 ){
		ans = B-A;
	}
	else{
		ans = A-B;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

int main() {
  string S;
  int count=0;
  cin >> S;
  char c[30];
  for(int i=0; i<S.size(); i++) {
    c[i]=S.at(i);
    for(int j=0; j<i; j++) {
      if(c[i]==c[j] && count==0) {
        cout << "no" << endl;
        count++;
      }
    else if(i==S.size()-1 && count==0) {
       cout << "yes" << endl;
      count++;
    }
    }
  }
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	int n; cin >> n;
	int dig = n % 10;
	if (dig == 2 or dig == 4 or dig == 5 or dig == 7 or dig == 9) cout << "hon";
	else if (dig == 0 or dig == 1 or dig == 6 or dig == 8) cout << "pon";
	else cout << "bon";

	return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int k = stdIn.nextInt();
    String s = stdIn.next();

    s = s.substring(0,k-1) + (s.substring(k-1,k)).toLowerCase() + s.substring(k,n);

    System.out.println(s);
  }
}

Measured memory_bytes: 21204
using System;
using System.Collections.Generic;
using System.Linq;

public class AtCoder
{

    public static int[] ReadArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m));
    }

    public static int ReadInt()
    {
        return Convert.ToInt32(Console.ReadLine());
    }

    public static string ReadStr()
    {
        return Console.ReadLine();
    }

    public static long ReadLong()
    {
        return Convert.ToInt64(Console.ReadLine());
    }

    public static long[] ReadLongArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m));

    }


    public static void Main()
    {
            var n = ReadInt();

	    int[] A = ReadArray();

            int[] dp = new int[n];

            dp[1] = Math.Abs(A[0] - A[1]);

	   for(int i = 2; i < n; i++)
		{
			dp[i] = Math.Min(dp[i-1] + Math.Abs(A[i] - A[i-1]),
					 dp[i-2] + Math.Abs(A[i] - A[i-2]));
		}

           Console.WriteLine(dp[n-1]);


 

      
       


    }


}


Measured memory_bytes: 19040
# D - Prediction and Restriction 
N,K = map(int,input().split())
RSP = tuple(map(int,input().split()))
T = input()

# じゃんけんの勝敗を返す関数
def judge(a,b):
    if a == 'r' and b == 2:
        return True
    elif a == 's' and b == 0:
        return True
    elif a == 'p' and b == 1:
        return True
    return False

# dp[i][j]: i 回目のじゃんけんで j を出したときの最大値
# グー:0, チョキ:1, パー:2
dp = [[0]*3 for _ in range(N+1)]

# 初期条件 v < K のときは全て勝つ
for i in range(1,K+1):
    for j in range(3):
        if judge(T[i-1],j):
            dp[i][j] = RSP[j]

# K 以下の数字について
for v in range(1,K+1):
    # w = v, v+K, v+2K,...
    for w in range(v+K,N+1,K):
        # w 回目に出した手
        for l in range(3):
            # w-K 回目に出した手 
            for m in range(3):
                if l == m:
                    continue
                # じゃんけんで勝ったとき
                if judge(T[w-1],l):
                    if w-K>=0:
                        dp[w][l] = max(dp[w][l],dp[w-K][m] + RSP[l])
                # じゃんけんで負けか引き分けたとき
                dp[w][l] = max(dp[w][l],dp[w-K][m])
                     
# K 個に分けた各グループの部分和の最大値の総和を求める
ans = 0
for a in range(1,K+1):
    ans += max(dp[-a])
print(ans)

Measured memory_bytes: 86320
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;

int main()
{
	int n,k,ans=0;
	cin >> n>> k;
	vector<int> h(n);

	for (int i = 0; i < n; i++) {
		cin >> h.at(i);
	}

	for (int i = 0; i < n; i++) {
		if(h.at(i) >= k) {
			ans += 1;
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 768
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, X: "List[int]"):
    if(N >= M):
        print(0)
        exit()
    X.sort()
    L = [X[i+1] - X[i] for i in range(M-1)]
    L.sort(reverse=True)
    ans = sum([L[i] for i in range(N-1)])
    print(X[M-1]-X[0] - ans)

    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    solve(N, M, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15652
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
// int dx[]={0,1,0,-1,1,1,-1,-1};
// int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int dx[]={-1,-1,0,0,1,1};
int dy[]={-1,0,-1,1,0,1};//RDLU
//nCr mod m
#define MOD 924844033
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
int main(){
	init();
	ll n,m;
	cin>>n>>m;
	
	vvi dp(n+1,vi(2));
	dp[0][1]=1;
	loop(i,1,m+1){
		ll t=(n-i)/m+1;
		rep(q,2){
			rep(j,t){
				for(int k=n;k>=0;k--)if(dp[k][0]||dp[k][1]){
					if(k!=n)(dp[k+1][1]+=dp[k][0])%=MOD;
					(dp[k][0]+=dp[k][1])%=MOD;
					dp[k][1]=0;
				}
			}
			rep(j,n+1){
				(dp[j][1]+=dp[j][0])%=MOD;
				dp[j][0]=0;
			}
		}
	}
	ll out=0;
	rep(i,n+1)(out+=(MOD+(i%2?-1:1)*(fact[n-i]*dp[i][1]%MOD))%MOD)%=MOD;
	cout<<out<<endl;
}
	
/*
int main(){
	int n,l,t,co=0;
	cin>>n>>l>>t;
	
	vvi in(n,vi(2));
	rep(i,n)rep(j,2)cin>>in[i][j];
	rep(i,n)if(in[i][1]==2)in[i][1]=-1;
	
	vvi g(n,vi(2));
	rep(i,n){
		if(in[0][1]!=in[i][1]){
			ll w=t;
			co+=w/l;
			w%=l;
			ll dis=(l+in[i][0]-in[0][0])%l;
			if(in[0][1]==-1)dis=(l+in[0][0]-in[i][0])%l;
			if(dis<=2*w)co++;
		}
		g[i]={(in[i][0]+t*in[i][1])%l,in[i][1]};
	}
	if(in[0][1]==-1)co=n-1-co%n;
	else co%=n;
	cout<<co<<endl;
	show2d(in);
	show2d(g);
}	
*/








Measured memory_bytes: 8192
e=input
a=[]
for _ in[0]*int(e()):
 X,z=e(),[]
 for y in e():
  s=i=0
  for k in z:
   t=X.find(y,s)+1
   if t<1:break
   if t<k:z[i]=t
   s=k;i+=1
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 a+=[len(z)]
print('\n'.join(map(str,a)))


Measured memory_bytes: 5624
#include<bits/stdc++.h>
#define PI             acos(-1.0)
#define IOS            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(a,b)         memset(a, b, sizeof(a))
#define filein      freopen("input.txt", "r", stdin);
#define fileout     freopen("output.txt", "w", stdout);
#define debug       cout<<"Hello, i am in here."<<endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
using namespace std;
const int MOD = (int)1e9+7;
void solve()
{
  ll n,k;
  ll mark[101]={0};
  cin>>n>>k;
  for(int i=1;i<=k;i++)
  {
    ll d;
    cin>>d;
    for(int j=1;j<=d;j++)
    {
      ll x;
      cin>>x;
      mark[x]=1;
    }
  }
  int Result=0;
  for(int i=1;i<=n;i++)
  {
    if(mark[i]==0)Result++;
  }
  cout<<Result<<endl;
}
int  main()
{
    IOS
        solve();
    return 0;
}



Measured memory_bytes: 3656
N = int(input())
A = list(map(int,input().split()))

cond = 1
for i in range(N):
	if A[i] % 2 == 0:
		if not((A[i] % 3 == 0) or (A[i] % 5== 0)):
			cond = 0
			break

if cond:
	print('APPROVED')
else:
	print('DENIED')

Measured memory_bytes: 3060
N = int(input())
p = list(map(float, input().split()))

dp = [[0.] * (N+1) for _ in range(N+1)]
dp[0][0] = 1.

for i in range(1, N+1):
    for j in range(i+1):
        prob = dp[i-1][j-1]*p[i-1]
        if i > 0:
            prob += dp[i-1][j]*(1.-p[i-1])
        dp[i][j] = max(dp[i][j], prob)
print(sum(dp[-1][N//2+1:]))

Measured memory_bytes: 144740
// https://atcoder.jp/contests/abc089/tasks/abc089_d
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, d, t, q;
    cin >> h >> w >> d;
    vector<pii> v(h * w + 1);
    vector<vector<int>> disp(h, vector<int>(w));
    REP(i, h) REP(j, w) {
        cin >> t;
        v[t] = {i, j};
        disp[i][j] = t;
    }
    vector<ll> memo(h * w + 1, 0);
    REP(i, d) {
        int start = i;
        ll sum = 0;
        while (start + d <= h * w) {
            pii posNow = v[start];
            pii posNext = v[start + d];
            int diff = abs(posNow.first - posNext.first) +
                       abs(posNow.second - posNext.second);
            sum += diff;
            start += d;
            memo[start] = sum;
        }
    }
    cin >> q;
    vector<pii> s(q);
    REP(i, q) cin >> s[i].first >> s[i].second;
    REP(i, q) cout << memo[s[i].second] - memo[s[i].first] << "\n";

    return 0;
}


Measured memory_bytes: 3712
N= int(input())
a = [input().split() for i in range(N)]

Is = []
for i in range(N):
    Ds = a[i]
    if Ds[0] == Ds[1]:
        Is.append(i)

Boooo = False
for i in range(len(Is)-2):
    if Is[i]+1 == Is[i+1] and Is[i+1]+1 == Is[i+2]:
        Boooo = True

if Boooo:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 9192
N, D = [int(x) for x in input().split(' ')]
X = []
Y = []
for _ in range(N):
  a, b = [int(x) for x in input().split(' ')]
  X.append(a)
  Y.append(b)

count = 0
for i in range(N):
  if X[i] ** 2 + Y[i] ** 2 <= D ** 2:
    count += 1
  
print(count)

Measured memory_bytes: 24840
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <time.h>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, cnt[111111];
bool pos=true;

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n; int i, x;
	for(i=1 ; i<=n ; i++)
	{
		cin>>x; cnt[x]++;
	}
	if(n%2==0)
	{
		for(i=1 ; i<=n ; i+=2) if(cnt[i]!=2) pos=false;
		if(!pos) cout<<0;
		else cout<<exp(2,n/2);
	}
	if(n%2==1)
	{
		if(cnt[0]!=1) pos=false;
		for(i=2 ; i<=n ; i+=2) if(cnt[i]!=2) pos=false;
		if(!pos) cout<<0;
		else cout<<exp(2,n/2);
	}
	return 0;
}

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

int main(void){
    
    int b,i,a=200001;
    char s[200001];
    
    scanf( "%s",s );
    
    int length = strlen(s);
    
    for( i = 0; i < length; i++ ){
        if( s[i] == 'A' ){
            if( a > i ) a = i;
        }
        if( s[i] == 'Z' ){
            b = i;
        }
    }
    
    printf( "%d\n",b-a+1 );
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   //中心1つ(1)の時が最大 (n-1)(n-2)/2
           //それ以下は全て可能？
           int n,k;
           cin>>n>>k;
           if(k>(n-1)*(n-2)/2){
            cout<<-1<<endl;
             return 0;
           }
           int m=0;
           int e=(n-1)*(n-2)/2;
           vector<P> ans(0);
           rep(i,0,n-1){
            ans.pb(mp(1,i+2));
            m++;
           }
           int to=3,from=2;
           while(k!=e){
            m++;
            e--;
            ans.pb(mp(from,to));
             to++;
             if(to==n+1){
               to=from+2;
               from++;
             }
           }
           cout<<m<<endl;
           rep(i,0,m){
            cout<<ans[i].first<<" "<<ans[i].second<<endl; 
           }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define TO(x,t,f) ((x)?(t):(f))
#define YesNo(a) cout<<((a)?"Yes":"No")<<endl;
#define YESNO(a) cout<<((a)?"YES":"NO")<<endl;

int main(){
	ll x;
	cin >> x;
	YESNO(x==3||x==5||x==7);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int a[56];
int main () {
  int N;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> a[i];
  }
  ll sum=0;
  for (int i=0; i<N; i++) {
    for (int j=i+1; j<N; j++) {
      sum+=a[i]*a[j];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ff first
#define ss second
#define ll long long
#define int long long
#define pii pair<ll,ll>
#define vi vector<ll>
#define mii map<ll,ll>
#define pb push_back
#define mp make_pair
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) ll x; cin>>x; while(x--)
#define endl '\n'
#define str string
#define all(v) v.begin(),v.end()
void kehsihba(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
	kehsihba();
	ll n,m;
	cin>>n;
	ll arr[n];
	ll ans[n+1]={0};
	for(int i=0;i<n-1;i++){
		cin>>arr[i];
		ans[arr[i]]+=1;
	}
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 6788
n,m=map(int,input().split())

order=[1]*n
ans=[""]*m
PY=[]
for i in range(m):
    p,y=map(int,input().split())
    PY.append((y,p,i))

PY.sort()
for y,p,i in PY:
    s_p=str(p).zfill(6)
    y_p=str(order[p-1]).zfill(6)
    order[p-1]+=1

    ans[i]=s_p+y_p

for i in ans:
    print(i)

Measured memory_bytes: 29720
N, X = map(int, input().split())

a, p = [1], [1]
for i in range(N):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)

def f(N, X):
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1)
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

int main(){
    int N,K; string S;
    cin >> N >> S >> K;
    K--;
    rep(i,N){
        if(S[K]!=S[i]) S[i] = '*';
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

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

    int n,m;
    cin >> n >> m;
    int arr[m];

    int sum=0;
    for (int i=0;i<=m-1;i++)
    {
        cin >> arr[i];
        sum=sum+arr[i];
    }

    if (sum>n)
    {
        cout << "-1" << endl;
    }
    else
    {
        cout << n-sum << endl;
    }

    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n-1; i >= 0; i--)
#define FOR(i, n, m) for(int i = n; i < (int)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18

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

ll MOD = 1000000007;

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main()
{
    string S;
    cin >> S;
    vector<ll> m(3);
    REP(i, S.length()) {
        if (S[i] == 'a') m[0] ++;
        else if (S[i] == 'b') m[1]++;
        else m[2]++;
    }
    sort(ALL(m));
    reverse(ALL(m));
    REP(i, S.length()) {
        m[i % 3]--;
        if (m[i % 3] < 0) {
            PRINT("NO");
            return 0;
        }
    }
    PRINT("YES");

    return 0;
}


Measured memory_bytes: 512
N,Y=map(int,input().split(' '))
c,b,a=-1,-1,-1
for A in range(Y//10000+1):
	B = (Y/1000 - 9*A - N)/4
	if int(B)==B and 0<=int(B)<=N-A:
		a,b=int(A),int(B)
		break
	else:
		continue
if a>=0:
	c = N-a-b
print(a,b,c)

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


ll memo[10000007];

void solve() {
    ll N; cin >> N;
	rep1(i, N){
		rep1(j, N){
			if((ll)i*j > N) break;
			memo[i*j]++;
		}
	}
	ll sum = 0;
	rep1(i, N){
		sum += i*memo[i];
	}
	cout << sum << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 85852
#include<stdio.h>

int main(void)
{
  int mountain[10];
  int i, j;
  int tmp;

  for(i = 0; i < 10; i++) {
    scanf("%d", &mountain[i]);
  }

  for(i = 0; i < 9; i++) {
    for(j = 9 ; j > i; j--) {
      if(mountain[j] > mountain[j-1]) {
	tmp = mountain[j];
	mountain[j] = mountain[j-1];
	mountain[j-1] = tmp;
      }
    }
  }

  for(i = 0; i < 3; i++) {
    printf("%d\n", mountain[i]);
  }

  return 0;
}

Measured memory_bytes: 600
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		b,c,i,j,k,n,m,x,y,ans = 0;
	cin >> n >> k;
	vector<ll> a(n+1);
	for(i=1;i<=n;i++) {
		cin >> a[i];
	}
	vector<ll>	dp(n+1 , -1);
	dp[1] = 0;
	ll pre = 1;
	ll cnt = 0;
	while(dp[a[pre]]==-1) {
		dp[a[pre]] = ++cnt;
		pre = a[pre];
	}
	ll lp = dp[a[pre]];
	ll end = cnt+1;
	/*
	cout << "DBG:" << lp << ' ' << end << endl << "DP:";
	for(i=1;i<=n;i++) cout << dp[i];
	cout << endl;
	*/
	ll lpcnt = end - lp;

	if (k >= lp) {
		k = (k-lp)%lpcnt + lp;
	}
	//cout << "DBG:" << k << endl;
	ans = 1;
	for(i=0;i<k;i++) {
		ans = a[ans];
	}

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


Measured memory_bytes: 6376
#include "bits/stdc++.h"
#include <boost/range/irange.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multi_array.hpp>
//#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::irange;

typedef long long           ll;
typedef pair<ll, ll>	    P;

#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
#define INF                 (ll)1e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846

const int mod = 1000000007;
class mint {
public:
	long long x;
	mint(long long x = 0) : x((x % mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const  mint& a) {	(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}
};

// 処理
void Solve()
{
	ll N;
	string S;
	cin >> N >> S;
	map<ll, ll> mp;
	mint ans = 1;
	for_each(ALL(S), [&](ll a){ mp[a - 'a']++; });
	for_each(ALL(mp), [&](P a){ ans *= (a.second + 1); });
	cout << ans.x - 1 << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#define N 110000
inline char gc(){
    static char now[1<<16],*T,*S;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
inline int read(){
    int x=0;char ch=gc();
    while (ch<'0'||ch>'9') ch=gc();
    while (ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
    return x;
}
int n,a[N],differ[N];
int main(){
    n=read();long long sum=0;long long sum1=0;
    if (n==1){printf("YES");return 0;}
    sum1=(long long)n*(n+1)>>1;
    for (int i=1;i<=n;++i) a[i]=read(),sum+=a[i];a[n+1]=a[1];
    for (int i=1;i<=n;++i) differ[i]=a[i+1]-a[i];int k=sum/sum1;
    if (sum%sum1){printf("NO");return 0;}
    for (int i=1;i<=n;++i){
        double x=(differ[i]-k)/(-1.0*n);
        if (x<0){printf("NO");return 0;}
        int xx=x;if (xx!=x){printf("NO");return 0;}
    }
    printf("YES");
    return 0;
}

Measured memory_bytes: 1024
import math
N,D = list(map(int,input().split()))
X = []
for i in range(N):
    X.append(list(map(int,input().split())))
c = 0
for i in range(N):
    for j in range(i+1,N):
        sum_d = 0
        for d in range(D):
            sum_d += (X[i][d] - X[j][d])**2
        if math.sqrt(sum_d) == int(math.sqrt(sum_d)):
            c += 1
print(c)



Measured memory_bytes: 38384