akhauriyash/Code-Regression huggingface dataset:
# UnionFind に子どもの数を管理する機能を追加

# 上位ノードほど @rank が大きい数字となる
class Node
  attr_accessor :parent, :rank, :children

  # 親は自分自身、ランクは 0 として初期化する
  def initialize(n)
    @parent = n
    @rank = 0
    @children = 0
  end
end

class UnionFind
  # 0 から n までのノード（つまりn + 1個）を初期化する
  def initialize(n)
    @nodes = (0..n).map { |i| Node.new(i) }
  end

  # 再帰で最も上位の親を探して更新し、その値を返す
  def parent(x)
    return x if @nodes[x].parent == x
    return @nodes[x].parent = parent(@nodes[x].parent)
  end

  # a と b を仲間にする
  def unite(a, b)
    a_parent = parent(a)
    b_parent = parent(b)
    # a 及び b の親が同じ場合は何もしない
    if a_parent == b_parent
      @nodes[a_parent].children += 1
    # a親ランク < b親ランク の場合は、b親をa親の親とする
    # なお、ランクをいじる必要はなし
    elsif @nodes[a_parent].rank < @nodes[b_parent].rank
      @nodes[a_parent].parent = b_parent
      @nodes[b_parent].children += @nodes[a_parent].children + 1
    # その他の場合は、a親をb親の親とする
    else
      @nodes[b_parent].parent = a_parent
    # a親、及びb親のランクが同じ場合は、a親のランクを +1 する
      @nodes[a_parent].rank += 1 if @nodes[a_parent].rank == @nodes[b_parent].rank
      @nodes[a_parent].children += @nodes[b_parent].children + 1
    end
  end

  # a と b の親が同じかどうかを返す
  def same?(a, b)
    parent(a) == parent(b)
  end

  # 各ノードの親を全て出力する確認用
  def parents
    @nodes.map(&:parent)
  end

  def children(a)
    @nodes[a].children
  end
end

n, m = gets.split.map(&:to_i)
edges = []
m.times { edges << gets.split.map(&:to_i) }
tree = UnionFind.new(n)
convenients = [0]
# 後ろの橋から追加して、便利な組み合わせが何組あるかを確認していく
edges.reverse.each do |a, b|
  if tree.same?(a, b)
    convenients << convenients.last
  else
    convenients << convenients.last + (tree.children(tree.parent(a)) + 1) * (tree.children(tree.parent(b)) + 1)
    tree.unite(a, b)
  end
end
inconvenients = convenients.map { |i| (n * (n - 1)) / 2 - i }.reverse
inconvenients.delete_at(0)
inconvenients.each { |i| puts i }


Measured memory_bytes: 20016
#include <iostream>
#include <vector>
#include <string>

int main(void) {
	int i,n,co=0,ok=0;
	std::cin >> n;
	std::vector<int> num(n);
	for (i = 0; i < n; i++) {
		std::cin >> num.at(i);
		if (num.at(i) % 2 == 0) {
			co++;
			if (num.at(i) % 3 == 0 || num.at(i) % 5 == 0) {
				ok++;
			}
		}
	}
	if (co == ok) {
		std::cout << "APPROVED" << std::endl;
	}
	else { std::cout << "DENIED" << std::endl; }


	
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = input_int()
    a_list = input_to_int_tuple()
    q = input_int()
    bc = [input_to_int_tuple() for i in range(q)]

    from collections import defaultdict
    a_cnt = defaultdict(int)
    for i in a_list:
        a_cnt[i] += 1

    a_sum = sum(a_list)

    ret = a_sum
    for b, c in bc:
        sa = c - b
        b_cnt = a_cnt.get(b, 0)
        c_cnt = a_cnt.get(c, 0)
        a_cnt[b] = 0
        a_cnt[c] = b_cnt + c_cnt
        ret += (sa * b_cnt)
        print(ret)


if __name__ == "__main__":
    main()


Measured memory_bytes: 35360
X,N = (int(x) for x in input().split())
p = [int(x) for x in input().split()]

for i in range(100):
    if p.count(X-i) == 0:
        print(X-i)
        break
    elif p.count(X+i) == 0:
        print(X+i)
        break


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

int main() { /* ここに書く */

  int N,t,ans;
  cin >> N;
  
  vector<int>vec(N);
  
  
  
  for(int a = 1; a<=100 ; a++){
    for(int b = 1; b<=a ; b++){
      for(int c = 1; c<=b ; c++){
        
        t = a*a + b*b + c*c + a*b + b*c + c*a;
        t--;
        
        if(t < N){
          
          ans = vec.at(t);
        
        if(a ==c ){
          ans = ans + 1; 
        }
        else if(a==b || b==c){
          ans = ans + 3;
        }
        else{
          ans = ans + 6;
        }
          
          vec.at(t) = ans;
        
        
        }
      }
    }
  }
  
  for(int i = 0; i<N ; i++){
    
    ans = vec.at(i);
    cout <<ans << endl;
    
  }
  
}

Measured memory_bytes: 3592
#include<iostream>
#define _USE_MATH_DEFINES
#include<cmath>
using namespace std;
int main(){
	double err;
	while(cin>>err,err){
		int a=3,b=1;
		while(abs(1.*a/b-M_PI)>err)1.*a/b<M_PI?a++:b++;
		while(abs(1.*a/b-M_PI)>abs((1.+a)/b-M_PI))a++;
		cout<<a<<"/"<<b<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
/*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/

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

typedef long long ll;
const int root=0;
const int mx=1e5+5;
struct trie {
    int node[mx][2];
    bool isEnd[mx];
    int nnode;

    trie () {
        nnode=0;
        node[root][0]=node[root][1]=-1;
    }
    void insert (char *str) {
        int i,len,now=0;
        len=strlen(str);
        for (i=0;i<len;i++) {
            if (node[now][str[i]-'0']==-1) {
                node[now][str[i]-'0']=++nnode;
                node[nnode][0]=node[nnode][1]=-1;
            }
            now=node[now][str[i]-'0'];
        }
        isEnd[now]=true;
    }
} T;

ll mxln;
ll grundy (ll n)
{
    ll ans=1;
    for (ans=1;ans<=n;) {
        if (n%ans==0) ans*=2;
        else break;
    }
    return ans/2;
}
ll calc (int pos,int level)
{
    if (T.isEnd[pos]) return 0;
    ll ans1,ans2;
    if (T.node[pos][0]!=-1) ans1=calc(T.node[pos][0],level+1);
    else ans1=grundy(mxln-level);
    if (T.node[pos][1]!=-1) ans2=calc(T.node[pos][1],level+1);
    else ans2=grundy(mxln-level);
    //cout<<ans1<<' '<<ans2<<endl;
    return (ans1^ans2);
}
char str[mx];
int main ()
{
    int i,n;

    scanf ("%d %lld",&n,&mxln);
    for (i=0;i<n;i++) {
        scanf ("%s",str);
        T.insert(str);
    }
    if (calc(0,0)==0) printf ("Bob\n");
    else printf ("Alice\n");

    return 0;
}


Measured memory_bytes: 4224
#include <stdio.h>
int main(){
  int a,b,c;

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

  if(a == 1 &&b == 1 &&c ==0 || a==0 && b==0 && c==1){
    printf("Open\n");
  }

  else printf("Close\n");

  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
int H,W,D;
int Q,L,R;
int A[90001];
int B[90001];
int d[90001];
int main(void)
{
    cin>>H>>W>>D;
    int t;
    for(int i=1;i<=H;++i)
    {
        for(int j=1;j<=W;++j)
        {
            cin>>t;
            A[t]=i;
            B[t]=j;
        }
    }
    cin>>Q;
    for(int i=D+1;i<=H*W;i++)
    {
    	d[i]=d[i-D]+(abs(A[i]-A[i-D])+abs(B[i]-B[i-D]));
	}
    int sum;
    for(int i=0;i<Q;++i)
    {
        sum=0;
        cin>>L>>R;
        cout <<d[R]-d[L]<<endl;
//        if(L==R)
//        {
//            cout <<0<<endl;
//            continue;
//        }
//        else
//        {
//
//            for(int i=L+D;i!=R+D;i+=D)
//            {
//                sum+=(abs(A[i]-A[i-D])+abs(B[i]-B[i-D]));
//            }
//            cout <<sum <<endl;
//        }
    }
    return 0;
}


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

int main(void){
    int N, M;
    cin >> N;
    vector<string> blue(N);
    for(int i=0; i<N; i++){
        cin >> blue.at(i);
    }

    cin >> M;
    vector<string> red(M);
    for(int i=0; i<M; i++){
        cin >> red.at(i);
    }

    string s;
    int blueCounter = 0;
    int redCounter = 0;
    int max = 0;
    for(int i=0; i<N; i++){
        blueCounter = 0;
        redCounter = 0;
        s = blue.at(i);
        for(int j=0; j<N; j++){
            if(blue.at(j) == s) blueCounter++;
        }
        for(int j=0; j<M; j++){
            if(red.at(j) == s) redCounter++;
        }
        if(blueCounter - redCounter > max) max = blueCounter - redCounter;
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N ,A, B; 
ll h[(ll)1e5];
bool tobo(ll mid){
	ll po = 0;
	for(ll i = 0; i < N; ++i){
		ll yo = h[i] - mid * B;
		if(yo > 0) po += yo / (A - B) + (yo % (A - B) > 0);
	}
	return po <= mid;
}
int main(){
	cin >> N >> A >> B;
	for(ll i = 0; i < N; ++i) cin >> h[i];
	ll upper = 1e10, lower = 0;
	while(upper - lower > 1){
		ll mid = (upper + lower) / 2;
		if(!tobo(mid)) lower = mid;
		else upper = mid;
	}
	cout << (tobo(lower) ? lower : upper) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#include<unordered_set>
#include <random>
#include <ctime>
#include <chrono>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x,s) for(i=x;i>=s;i--)
#define fit(itr,s) for(itr=s.begin();itr!=s.end();itr++)
#define W while
#define pp pair<ll,ll>
#define ppi pair<int,int>
#define vl vector<ll>
#define vll vector<pp >
#define vi vector<int>
#define vii vector<ppi>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define boost  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const int MAX=2e5+1;
const ll MM=1e16;
const ll mod=1e9+7;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

ll expo(ll x,ll n,ll M=mod)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1){ans=(ans*x)%M;}
                x=(x*x)%M;
                n>>=1;
    }
    return ans;
}


void solve()
{
    ll n,m,i,j,k;
    cin>>n>>m;
    if(m%2)
    cout<<"No";
    else
    {
        ll x2=m/2-n;
        if(x2>=0 && x2<=n)
        cout<<"Yes"<<endl;
        else
        {
            cout<<"No"<<endl;
        }
        
    }
    
    
}

int main()
{
  boost;
  ll t=1;
 // cin>>t;
  while(t--)
  {
      solve();
  }
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <algorithm>
struct str{
	int x0;
	int y0;
}x[200010];
bool cmp1(str a, str b)
{
	if(a.x0==b.x0) return a.y0>b.y0;
	return a.x0<b.x0;
}
bool cmp2(str a, str b)
{
	if(a.y0==b.y0) return a.x0>b.x0;
	return a.y0<b.y0;
}

int main()
{
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++) scanf("%d%d",&x[i].x0,&x[i].y0);
	if(a%2==1)
	{
		std::sort(x+1,x+a+1,cmp1);
		int min = x[(a+1)/2].x0;
		std::sort(x+1,x+a+1,cmp2);
		int max = x[(a+1)/2].y0;
		printf("%d",max-min+1);
	}
	else
	{
		std::sort(x+1,x+a+1,cmp1);
		int min1 = x[a/2].x0, min2 = x[(a+2)/2].x0;
		std::sort(x+1,x+a+1,cmp2);
		int max1 = x[a/2].y0, max2 = x[(a+2)/2].y0;
		printf("%d",(max1+max2)-(min1+min2)+1);
	}
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for(int i=0; i<N; ++i){
    for(int j=0; j<D; ++j){
      cin >> X[i][j];
    }
  }
  
  int can=0;
  for(int i=0; i<N; ++i){
    for(int k=i+1; k<N; ++k){
      int sum = 0;
      for(int j=0; j<D; ++j){
        int diff = abs(X[i][j] - X[k][j]);
        sum += diff * diff;
      }
      for(int l=0; l<=sum; ++l){
        if(sum == l*l) ++can;
      }
    }
  }
  cout << can << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#define MAXN 200000
#define PRIME 998244353
using namespace std;
typedef pair<int, int> Pii;
bool visit[MAXN+1] = {0};
vector<int> edge[MAXN+1];
long long dfs(int r){
	long long ret = 1;
	visit[r] = 1;
	for(int c:edge[r])
		ret = ret * dfs(c) % PRIME;
	//cout << "dfs(" << r << ") = " << ret+1 << endl;
	return ret + 1;
}

int main(){
	int N;
	Pii r[MAXN];
	stack<Pii> stk;
	vector<int> roots;
	cin >> N;
	for(int i=0; i<N; i++)
		cin >> r[i].first >> r[i].second;
	sort(r, r+N);
	for(int i=0; i<N; i++){
		while(!stk.empty() && stk.top().second <= r[i].first)
			stk.pop();
		if(stk.empty())
			edge[MAXN].push_back(i);
		else
			edge[stk.top().first].push_back(i);
		stk.emplace(i, r[i].first+r[i].second);
	}
	cout << (dfs(MAXN) + PRIME - 1) % PRIME << endl;
}

	

			



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

int main(){
	int a;
	string input, output;
	getline(cin, input);
	for(int i=0;i<input.size();i++){
		a = input[i];
		if (a > 96){
			a -= 32;
		}
		output += a;
	}
	cout << output << endl;
	return 0;
}

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

int main(){
    ll a,b, n;
    cin >> a >>b >> n;

    ll ans;
    if(n<b){
        ans = floor(a*n/b)-a*floor(n/b);
    }else{
        ans = floor(a*(b-1)/b)-a*floor((b-1)/b);
    }

    cout << ans << endl;
}

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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 200179;

int main()
{
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    ll ans = 1;
    static int cnt[256];
    for (int i = 0; i < sz(s); ++i) {
        ans += i - cnt[s[i]];
        ++cnt[s[i]];
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;


int main() {
    int x,n;
    cin >> x >> n;
    set<int> s;
    rep(i,n){
        int f;
        cin >> f;
        s.insert(f);
    }
    rep(i,101){
        if (s.find(x-i)==s.end()){
            cout << x-i << endl;
            break;
        }
        if (s.find(x+i)==s.end()){
            cout << x+i << endl;
            break;
        }
    }
}


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

int main(int argc, const char * argv[]) {
    int N, M;
    
    cin >> N >> M;
    
    priority_queue<pair<long long, int>> A;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A.push(make_pair(a, 1));
    }
    for (int i = 0; i < M; i++) {
        int b, c;
        cin >> b >> c;
        A.push(make_pair(c, b));
    }
    
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        pair<long long, int> p = A.top();
        A.pop();
        ans += p.first;
        if (p.second > 1) {
            p.second--;
            A.push(p);
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 6384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP2(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)

int main(){
    string s;
    cin >> s;
    REP(i, s.length()/2){
        if(s[i] != s[s.length()-i-1]){
            cout << "No" << endl;
            return 0;
        }
    }
    if(s.substr(0,s.length()/2) != s.substr(s.length()-s.length()/2)){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, a, b);

  // a+b+c=6
  cout << 6 - a - b << endl;

  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>A>>B;
	cout<<min(B,N*A)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
/*
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
    cin>>n;
    cout<<n*(n+1)/2;
    return 0;
}       A
*/
/*
#include <bits/stdc++.h>
using namespace std;
int l,i,j,k;
char sir[110],x[110];
int main()
{
    cin>>sir;
    l=strlen(sir);
    for(i=0;i<l;i++)
    {
        if(sir[i]=='1')
            x[k++]='1';
        else if(sir[i]=='0')
            x[k++]='0';
        else
        {
            if(k==0)
                continue;
            x[k-1]=0;
            k--;
        }
    }
    cout<<x;
    return 0;
}           B
*/
#include <bits/stdc++.h>
using namespace std;
long long n,c,i,j,v[110],ma,ok;
int main()
{
    cin>>n;
    ok=1;
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
        ma+=v[i];
        if(v[i]!=v[1])
            ok=0;
    }
    if(ok==1)
    {
        cout<<0;
        return 0;
    }
    ma=round(double(ma)/double(n));
    for(i=1;i<=n;i++)
    {
        c=c+(v[i]-ma)*(v[i]-ma);
    }
    cout<<c;
    return 0;
}


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

int main(void){
    int n, pre = 0, f = 0;
    string rs = "Yes";
    cin >> n;
    vector<int > v(n);
    for (int i = 0; i< n; i++){
        cin >> v[i];
        if (pre - v[i] > 1){
            rs = "No";
            break;

        }
        else if (pre - v[i] == 1 && f == 0) f = 1;
        else if (pre - v[i] == 1 && f == 1){
            rs = "No";
            break;
        }
        else if (pre == v[i] && f == 1) f = 1;
        else f = 0;
        if (i != 0) pre = v[i];
    }

    cout << rs << endl;


}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll a,b,c,d,e,k;cin>>a>>b>>c>>d>>e>>k;
  	vector<ll> v={a,b,c,d,e};
  	sort(all(v));
    cout << (v[4]-v[0] <= k ? "Yay!" : ":(") << ednl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int i,j,n,x,y,h,w,f[6]={2,5,10,15,20,25},r;
	for(;scanf("%d",&n),n;)
	{
		for(i=r=0;i<n;i++)
		{
			scanf("%d%d%d%d",&x,&y,&h,&w);
			x+=y+h;
			for(j=0;j<6;j++)
				if(x<=60+20*j&&w<=f[j])
				{
					r+=600+200*j;
					break;
				}
		}
		printf("%d\n",r);
	}
	return 0;
}

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



int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif


    int n, k;
    while (scanf("%d%d", &n, &k) == 2) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) scanf("%d", &a[i]);

        sort(a.begin(), a.end());
        int g = a[0];
        for (int i = 1; i < n; i++) g = __gcd(g, a[i]);

        bool f = k % g == 0 && a[n - 1] >= k;
        string ans = f ? "POSSIBLE" : "IMPOSSIBLE";
        cout << ans << endl;
    }


#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<map>

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

using namespace std;

const int INF = 1000;

int N, M;

int d[100];

int A[100][100];

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

	cout << r * r << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll h(n);
    ll res = 0, tmp = 0;

    REP(i, n){
        cin >> h[i];
        if(i && h[i] <= h[i - 1]) {
            tmp++;
            res = max(res, tmp);
        }
        else {
            tmp = 0;
        }
    }
    cout << res << endl;

    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  int d,x;
  cin >> d >> x;
  
  int a[n];
  rep(i,n) cin >> a[i];
  
  int ans = 0;
  rep(i,n){
    int day = 1;
    while(day <= d){
      ans++;
      day += a[i];
    }
  }
  
  cout << ans + x << endl;
      
}

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

int main(){
    int k, t;
    cin >> k >> t;
    
    int max_a = 0;
    for(int i = 0; i < t; i++){
        int a;
        cin >> a;
        if(max_a < a) max_a = a;
    }

    if(k%2==1){
        if(max_a < k/2+2) cout << 0;
        else cout << 2*max_a-k-1;
    }
    else{
        if(max_a < k/2+1) cout << 0;
        else cout << 2*max_a-k-1;
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
	
	static List<binarySet> ls=new ArrayList<>();
	static char[] U;
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt(),k=in.nextInt();
		
		U=new char[n];
		Arrays.fill(U, '0');
		
		List<Integer> T=new ArrayList<>();
		for(int i=0;i<k;i++)T.add(in.nextInt());
		
		solveSet(new ArrayList<Integer>(),T);
		ls.sort(Comparator.comparingInt(binarySet::getDecimal));
		
		PrintWriter out=new PrintWriter(System.out);
		out.println("0:");
		for(int i=0;i<ls.size();i++) {
			List<Integer> A=ls.get(i).ls;
			out.print(ls.get(i).dec+":");
			
			for(int j=0;j<A.size();j++)out.print(" "+A.get(j));
			out.println();
			out.flush();
		}
		
		out.flush();
	}
	
	static void solveSet(List<Integer> A,List<Integer> S) {
		
		for(int i=0;i<S.size();i++) {
			if(A.isEmpty() || S.get(i)>A.get(A.size()-1)) {
				List<Integer> t=new ArrayList<>(A);
				t.add(S.get(i));
				ls.add(new binarySet(t,U));
				solveSet(t,S);
			}
		}
	}

}
class binarySet{
	List<Integer> ls;
	int dec;
	binarySet(List<Integer> A,char[] c){
		ls=A;
		char[] t=c.clone();
		for(int i=0;i<ls.size();i++) {
			t[c.length-1-A.get(i)]='1';
		}
		dec=Integer.parseInt(String.valueOf(t),2);
	}
	
	int getDecimal() {
		return dec;
	}
}



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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
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();}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (k == 0) return 1;
	return n * COM(n - 1, k - 1) / k;
}

int main(){
	ll pizza[3];
  rep(i,3) cin >> pizza[i];
	int x,y;
	cin >> x >> y;
	if(2*pizza[2] <= pizza[0]+pizza[1]){
		ll ans = 2 * pizza[2] * min(x,y);
		if(x < y) ans += min(pizza[1],2*pizza[2])*(y-x);
		if(x > y) ans += min(pizza[0],2*pizza[2])*(x-y);
		cout << ans << endl;
	}else{
		cout << pizza[0] * x + pizza[1] * y << endl;
		return 0;
	}
  return 0;
}


Measured memory_bytes: 256
/*
Jugemu Jugemu
Goko-no surikire
Kaijarisuigyo-no
Suigyomatsu Unraimatsu Furaimatsu
Kuunerutokoro-ni Sumutokoro
Yaburakoji-no burakoji
Paipopaipo Paipo-no-shuringan
Shuringan-no Gurindai
Gurindai-no Ponpokopi-no Ponpokona-no
Chokyumei-no Chosuke
*/

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

int n, w[20100], cnt = 0;
int main(){
	cin >> n;
	if (n == 3){
		cout << 2 << " " << 5 << " " << 63 << endl;;
		return 0;
	}
	if (n == 4){
		cout << 2 << " " << 5 << " " << 20 << " " << 63 << endl;
		return 0;
	}
	int pv1 = 2, pv2 = 3, pv3 = 6, ck = 1;
	if(n%2==1)w[++cnt] = 6, pv3 += 6;
	while (cnt < n && ck){
		ck = 0;
		if (pv1 + 2 <= 30000 && cnt+2 <= n){
			w[++cnt] = pv1;
			w[++cnt] = pv1 + 2;
			pv1 += 6;
			ck = 1;
		}
		if (pv2 + 6 <= 30000 && cnt+2 <= n){
			w[++cnt] = pv2;
			w[++cnt] = pv2 + 6;
			pv2 += 12;
			ck = 1;
		}
	}
	while (cnt < n){
		w[++cnt] = pv3;
		pv3 += 6;
	}
	for (int i = 1; i <= cnt; i++){
            cout << w[i] << " ";
    }
	cout << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

struct Edge{int to,weight; Edge(int t, int w) : to(t), weight(w) {}};
using DirectedGraph = vector<vector<Edge>>;
using UndirectedGraph = vector<vector<int>>;

ll gcd(ll x, ll y){
  return y ? gcd(y, x%y) : x;
}
ll lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll cd = lcm(c,d);
    ll num_a=(a-1)/c+ (a-1)/d - (a-1)/cd;
    ll num_b = b/c + b/d - b/cd;
    cout<<b - a + 1 - (num_b - num_a)<<endl;
    //cout<<num_a<<":"<<num_b<<endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      String ans = "NO";
      if(x==3||x==5||x==7){
        ans = "YES";
      }
      System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#include <stdio.h>

int nextInt() { int d; scanf("%d", &d); return d; }

int main() {
  int n = nextInt();
  
  int count = 0;
  
  for (int i = 0; i < n; i++) {
    int x = nextInt();
    if (x == 2 || x == 3) {
      count++;
      continue;
    }
    for (int j = 2; j * j <= x; j++) {
      if (x % j == 0) {
        break;
      }
      if ((j + 1) * (j + 1) > x) {
        count++;
      }
    }
  }
  printf("%d\n", count);
  
  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sax(x) cout << "!!!!!!!!!!! " << #x << " = " << x << '\n'
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)
#define one(x) x.insert(x.begin(), 0);
#define TCT template <class T>
#define TCT12 template <class T1, class T2>
#define IS istream
#define OS ostream
#define OP operator

//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
//tree_order_statistics_node_update> imsi;

TCT IS& OP>>(IS &I, vector<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT IS& OP>>(IS &I, deque<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, priority_queue<T> v) {while (!v.empty()) {O << v.top() << ' '; v.pop();} return O;}
TCT OS& OP<<(OS &O, stack<T> v) {while (!v.empty()) {O << v.top() << '\n'; v.pop();} return O;}
TCT OS& OP<<(OS &O, queue<T> v) {while (!v.empty()) {O << v.front() << ' '; v.pop();} return O;}
TCT12 IS& OP>>(IS &I, pair<T1,T2>& p) {return I >> p.first >> p.second;}
TCT12 OS& OP<<(OS &O, const pair<T1,T2>& p) {return O << '(' << p.first << ' ' << p.second << ')';}
TCT12 OS& OP<<(OS &O, const unordered_map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
TCT12 OS& OP<<(OS &O, const map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
typedef pair<int,int> pii;
typedef vector<int> vi;





void _main() {
        int n; cin >> n;
        string a, b; cin >> a >> b;
        for (int i = 0; i < n; i++) cout << a[i] << b[i];
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 384
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>*/
 
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 101;
int arr[mxN];
int n;
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    owo(i, 0, n) {
        cin>>arr[i];
    }
    sort(arr, arr+n);
    int ans = 0;
    owo(i, 0, n) owo(j, i+1, n) owo(k, j+1, n) {
        if(arr[i]==arr[j]||arr[j]==arr[k])continue;
        ans+=arr[k]<arr[i]+arr[j];
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3652
a,b,k = (int(i) for i in input().split())

ak = k-a

if 0 < ak :
  
  bk = b - ak 
  
  if 0 < bk :
    
    print(0,bk)
    
  elif bk < 0 :
    
    print(0,0)
  
  elif bk == 0 :
    
    print(0,0)
  
  
elif ak < 0 :
  
  print(a-k,b)
  
elif ak == 0 :
  
  print(0,b)


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

int main(){
    using namespace std;
    unsigned long N, K;
    cin >> N >> K;
    deque<unsigned long> A(K);
    for(auto&& i : A)cin >> i;
    for(unsigned long i{K}, a; i < N; ++i){
        cin >> a;
        puts(A[0] < a ? "Yes" : "No");
        A.pop_front();
        A.push_back(a);
    }
    return 0;
}

Measured memory_bytes: 5228
#include<bits/stdc++.h>
using namespace std;
class triplet{
	public:
	int x;
	int y;
	int z;
};
int maxJoy(triplet* arr,int n,int in,int mat[][4]){
	if(n==0) return 0;
	if(n==1){
		if(in==0) return arr[0].x;
		if(in==1) return arr[0].y;
		if(in==2) return arr[0].z;
	}
	if(mat[n][in]!=-1) return mat[n][in];
	int ans=0;
	if(in==0){
		int x=maxJoy(arr+1,n-1,1,mat);
		int y=maxJoy(arr+1,n-1,2,mat);
		 ans=arr[0].x+max(x,y);
	}
	else if(in==1){
		int x=maxJoy(arr+1,n-1,0,mat);
		int y=maxJoy(arr+1,n-1,2,mat);
		ans=arr[0].y+max(x,y);
	}
	else if(in==2){
		int x=maxJoy(arr+1,n-1,0,mat);
		int y=maxJoy(arr+1,n-1,1,mat);
		ans=arr[0].z+max(x,y);
	}
	mat[n][in]=ans;
	return ans;
}
int main(){
//	int t;
//	cin>>t;
//	while(t--){
		int n;
		cin>>n;
		triplet* arr=new triplet[n];
		for(int i=0;i<n;i++){
			cin>>arr[i].x>>arr[i].y>>arr[i].z;
		}
		int mat[n+1][4];
		memset(mat,-1,sizeof(mat));
		int ans1=maxJoy(arr,n,0,mat);
		int ans2=maxJoy(arr,n,1,mat);
		int ans3=maxJoy(arr,n,2,mat);
		cout<<max(ans1,max(ans2,ans3))<<endl;
	//}
}


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

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


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int main() {
  int N = in();
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    A[i] = in();
  }

  Int res = 0;
  int odds = 0;
  A.push_back(0);
  for (int i = 0; i <= N; ++i) {
    if (A[i] == 0) {
      res += odds / 2;
      odds = 0;
    } else {
      res += A[i] / 2;
      odds += A[i] % 2;
    }
  }

  printf("%lld\n", res);
  
  return 0;
}


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

using namespace std;

typedef long long ll;
#define endl "\n"
#define int ll
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define all( x ) x.begin(), x.end()
#define fast ios::sync_with_stdio(0);cin.tie(0);

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef unsigned long long ull;

const ll inf = 1e12;
const long double PI = 3.141592653589793;

/*//MODULAR EXP
l power(ll x, ll y, ll m)  
{  
    ll res = 1;
    x = x % m; 
    if (x == 0) return 0; 
    while (y > 0)  
    {
      if (y & 1)  
        res = (res*x) % m;  
      y = y>>1;
      x = (x*x) % m;  
    }  
    return res;  
} */ 
/*//CUSTOM HASH
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);
    }
};*/


void solve(){
    return;
}
signed main(){
  fast;
  int n;
  cin>>n;
  int h[n];
  for(auto& x:h)cin>>x;
  int dp[n];
  memset(dp, INT_MAX, sizeof(dp));
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  for(int i=2;i<=n;i++){
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
  }
  cout<<dp[n-1];
}
//g++ -std=c++17 -Wshadow -Wall -o a a.cpp -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g

Measured memory_bytes: 1792
from collections import defaultdict,deque
def f(List,n):
    D[n]=1
    if List[n]==[]:return
    else:
        for i in List[n]:
            if D[i]==1:pass
            else:f(List,i)
    
N,M=map(int,input().split())
L=deque([[] for _ in range(N)]for _ in range(M))
for i in range(M):
    a,b=map(int,input().split())
    for j in range(M):
        if i==j:pass
        else:
            L[j][a-1].append(b-1)
            L[j][b-1].append(a-1)

ans=0
for k in range(M):
    List=L.popleft()
    D=defaultdict(int)
    f(List,0)
    judge=0
    for l in range(N):
        if D[l]==0:judge+=1
        else:pass
    if judge!=0:ans+=1
print(ans)

Measured memory_bytes: 3564
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,i,j,k,flg,cnt,len;
	char s[11],y[30];
	scanf("%s %d",s,&n);
	len=strlen(s);
	cnt=0;
	for(i=0;i<n;i++){
		scanf("%s",y);
		for(j=0;j<10;j++){
			y[10+j]=y[j];
		}
		flg=0;
		for(j=0;j<10*2-1;j++){
			for(k=0;k<len;k++){
				if(y[j+k]!=s[k]){
					break;
				}
				if(k==len-1){
					cnt++;
					flg=1;
				}
			}
			if(flg==1){
				break;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
#define DIST(x1,x2, y1, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
#define CLR(a) a.clear()
#define VCLR(a, n) for(int i=0; i<=n+3; i++) a[i].clear()
#define SIZE(a) a.size()
#define ERASE(a, b) memset(a, b, sizeof a)
#define pb push_back
#define LL long long
#define ULL unsigned long long
#define DBG cout<<"I Am Here"<<endl
#define DBGA(a) cout<<a<<endl
#define DBGI(b,a) cout<<b<<' '<<a<<endl
#define DBGL(i,s,e,b) or(int i=s; i<=e; i++) cout<<b<<endl
#define INF 1e9
#define INV 1e-6
#define sc(a) scanf("%I64d", &a)
#define pr(a) printf("%I64d\n", a)
#define si(a) scanf("%d", &a)
#define pii pair<int,int>
#define PII pair<LL,LL>
#define MAX 600005
#define CASE(i) printf("Case %d:", i);
#define PI acos(-1)
#define piis pair<int, string>
#define fast1 ios_base::sync_with_stdio(false);
#define fast2 cin.tie(0)
#define CHECK_BIT(var,pos) ((var & (1 << pos)) == (1 << pos))

using namespace std;
//
LL MOD = 1000000007;
//
//LL bigmod(LL a, LL b){
//    LL x = 1, y = a%MOD;
//    while(b > 0) {
//        if(b%2 == 1) {
//            x=(x*y);
//            if(x>MOD) x%=MOD;
//        }
//        y = (y*y);
//        if(y>MOD) y%=MOD;
//        b /= 2;
//    }
//    return x;
//}
//
//LL MODINVERSE(LL a){
//    return bigmod(a, MOD-2);
//}

//LL dp[900][1000];
//LL NCR(int n, int r)
//{
//    if(r==1) return n;
//    else if(n==r) return 1;
//    else
//    {
//        if(dp[n][r]!=-1) return dp[n][r];
//        else
//        {
//            dp[n][r]=NCR(n-1,r) + NCR(n-1,r-1);
//            return dp[n][r];
//        }
//    }
//}

const int MAXN = 1050;
int status[(MAXN/32)+10];

bool check(int n, int pos) { return (bool)(n & (1<<pos)); }
int SET(int n, int pos){ return n=n|(1<<pos);}

void sieve()
{
    int sqrtN=int (sqrt(MAXN));
    status[1>>5]=SET(status[1>>5],1&31);
    for(int j=4; j<=MAXN; j=j+2)
        status[j>>5]=SET(status[j>>5],j&31);
    for(int i=3; i<=sqrtN; i=i+2)
    {
        if(check(status[i>>5],i&31)==0)
        {
            for(int j=i*i; j<=MAXN; j= j + (i<<1))
            {
                status[j>>5]=SET(status[j>>5],j&31);
            }
        }
    }
}

LL arr[100005];
LL num[55], dp[55][55][2505];
LL n, k;

LL solve(LL pos, LL cnt, LL wt)
{
    if(pos>n){
        if((double)wt/cnt==k)  return 1;
        else return 0;
    }
    if(dp[pos][cnt][wt]!=-1)  return dp[pos][cnt][wt];
    LL cst;
    cst = solve(pos+1, cnt+1, num[pos]+wt) + solve(pos+1, cnt, wt);

    return dp[pos][cnt][wt] = cst;
}

int main()
{

    scanf("%lld %lld", &n, &k);

    for(LL i=1; i<=n; i++)  scanf("%lld", num+i);
    memset(dp, -1, sizeof dp);
    printf("%lld", solve(1,0,0));
}


Measured memory_bytes: 59392
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())

int main() {

	string ans = "Yay!";
	int k;
	vector<int> a(5);
	FOR(i, 5)cin >> a[i];
	cin >> k;
	SORT(a);
	if (a[4] - a[0] > k)ans = ":(";
	cout << ans << endl;
	

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b,count=0;
    cin>>a;
    int select[a];
    for(int i=0;i<a;i++){
        cin>>b;
        select[i]=b;
    }
    for (int i=0;i<a-1;i++){
        int minj = i;
        for (int j= i ;j<a;j++){
            
            if (select[j] <select[minj]){
                minj = j;
            }
        }
        if(i!=minj){
            int n=select[i];
            int m=select[minj];
            select[i]=m;
            select[minj]=n;
            count++;
        }
        
            
        
    } 
    for(int p=0;p<a;p++){
        if(p<a-1){
            cout<<select[p]<<" ";
        }
        else if(p==a-1){
            cout<<select[p]<<endl;
        }
    }
    cout<<count<<endl;
    return 0;
}




Measured memory_bytes: 3104
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
int table[100000];
int main() {
	ll x, y;
	scanf("%lld%lld", &x, &y);
	printf("%lld\n", (x < y ? min(y - x, abs(y + x) + 1) : min(1 + x - y, abs(x + y)) + 1));
	return 0;
}

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

int main(){
  int p;
  int tmp;
  cin >> p;
  vector<int> A(p);
  for (int i=0;i<p;i++){
    cin >> tmp;
    A.at(i) = tmp;
  }
  vector<int> B(p);
  B.at(0) = A.at(0);
  for (int i=1;i<p;i++){
    A.at(i) -= A.at(0);
    if (A.at(i) < 0){
      A.at(i) += p;
    }
    A.at(i) %= p;
  }
  for (int i=1;i<p;i++){
    int S = 0;
    for (int j=1;j<p;j++){
      S += A.at(j);
    }
    B.at(p-i) = (p - S % p) % p;
    for (int j=1;j<p;j++){
      A.at(j) *= j;
      A.at(j) %= p;
    }
  }
  for (int i=0;i<p;i++){
    if (i != p-1){
      cout << B.at(i) << " ";
    }
    else{
      cout << B.at(i) << endl;
    }
  }
}

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

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

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);

ll gcd(ll a, ll b){
  if(b == 0)return a;
  return gcd(b,a%b);
}

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

int main(){
  ll a,b;
  cin >> a >> b;
  cout << lcm(a,b) << endl;
}



Measured memory_bytes: 256
from fractions import gcd
from math import ceil
lcm = lambda x, y: x * y // gcd(x, y)
def solve():
    a, b, c, d = map(int, input().split())
    if c == 1 or d == 1:
        return 0
    def f(x):
        return len(range(ceil(a / x) * x, b + 1, x))
    C = f(c)
    if c == d:
        return b - a + 1 - C
    D = f(d)
    cd = lcm(c, d)
    CD = f(cd)
    return b - a + 1 - (C + D - CD)
print(solve())


Measured memory_bytes: 5076
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

class Main{

    static boolean canSet(int x,List<Integer> list){
        Set<Integer> set = new HashSet<>();
        set.add(0);
        for(int i : list){
            Set<Integer> newSet = new HashSet<>();
            for(int j : set){
                newSet.add(j+i);
                newSet.add(j-i);
            }
            set = newSet;
        }
        return set.contains(x);
    }

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

        String s = scan.next() + 'T';
        int x = scan.nextInt();
        int y = scan.nextInt();
        
        List<Integer> hol = new ArrayList<>();
        List<Integer> ver = new ArrayList<>();
        int index = 0;
        while(s.charAt(index)!='T')++index;
        x -= index;

        int cnt=0;
        int vec=0;
        for(int i=index;i<s.length();++i){
            if(s.charAt(i)=='F')++cnt;
            else{
                ++vec;
                if(cnt>0){
                    if(vec%2==1)hol.add(cnt);
                    else ver.add(cnt);
                    cnt=0;
                }
            }
        }

        if(canSet(x, hol) && canSet(y, ver)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 91620