akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, int> P;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
ll a[100100];
int x[100100], y[100100];

vector<int> G[100100];
int g[100100];

void dfs(int v, int prev, int c) {
    g[v] = c;
    for (int u : G[v]) {
        if (u == prev)
            continue;
        dfs(u, v, c);
    }
}

string solve() {
    for (int i = 0; i < m; i++) {
        G[x[i]].push_back(y[i]);
        G[y[i]].push_back(x[i]);
    }
    int c = 0;
    for (int i = 0; i < n; i++) {
        if (g[i] == 0) {
            c++;
            dfs(i, -1, c);
        }
    }

    if (2*c-2 > n)
        return "Impossible";
    if (c == 1)
        return "0";

    vector<P> vec(n);
    for (int i = 0; i < n; i++) {
        vec[i] = make_pair(a[i], g[i]);
    }
    sort(ALL(vec));
    set<int> s;
    stack<ll> st;
    ll res = 0;
    for (int i = 0; i < 2*c-2; i++) {
        P p = vec[i];
        res += p.first;
        if (s.count(p.second) == 0) {
            s.insert(p.second);
        } else {
            st.push(p.first);
        }
    }
    for (int i = 2*c-2; i < n; i++) {
        if ((int)s.size() >= c)
            break;
        P p = vec[i];
        if (s.count(p.second) > 0)
            continue;
        s.insert(p.second);
        ll v = st.top(); st.pop();
        res += p.first - v;
    }
    return to_string(res);
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> x[i] >> y[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


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

using namespace std;

const int MOD = 2019;

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

	int L, R;
	cin >> L >> R;

	int dist = R - L;
	if (dist >= 2019)
	{
		cout << 0;
		return 0;
	}

	L %= MOD;
	R = (L + dist) % MOD;
	int result = MOD;
	for (int i = L; i <= R; i++)
	{
		for (int j = i + 1; j <= R; j++)
		{
			result = min(result, (i * j) % MOD);
		}
	}

	cout << result;

	return 0;
}


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    string s; cin >> s;
    int a, z;
    a = (int)s.find('A');
    z = (int)s.rfind('Z');
    cout << z - a + 1<< '\n';
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;cin>>n;
  while(n!=0)
  {
    int i,j;
    vector<int> taro(n);
    vector<int> hana(0);
    rep(i,n)cin>>taro[i];
    for(i=1;i<=n*2;i++)
    {
      bool found=false;
      rep(j,n)
      {
        if(taro[j]==i)
        {
          found=true;
        }
      }
      if(!found)
      {
        hana.emplace_back(i);
      }
    }
    sort(all(taro));
    sort(all(hana));
    vector<bool> uset(n,false);
    vector<bool> useh(n,false);
    int leftt=n;
    int lefth=n;
    int turn=1;
    int val=0;
    int nowt=0;
    int nowh=0;
    while(leftt>0&&lefth>0)
    {
      if(turn==1)
      {
        while(nowt<n&&(taro[nowt]<=val||uset[nowt]))
        {
          nowt++;
        }
        if(nowt==n)
        {
          turn=2;
          val=0;
          nowt=0;
          nowh=0;
          continue;
        }
        uset[nowt]=true;
        leftt--;
        val=taro[nowt];
        nowt++;
        turn=2;
      }
      else if(turn==2)
      {
        while(nowh<n&&(hana[nowh]<=val||useh[nowh]))
        {
          nowh++;
        }
        if(nowh==n)
        {
          turn=1;
          val=0;
          nowt=0;
          nowh=0;
          continue;
        }
        useh[nowh]=true;
        lefth--;
        val=hana[nowh];
        nowh++;
        turn=1;
      }
    }
    if(leftt>0)
    {
      cout<<0<<endl;
      cout<<leftt<<endl;
    }
    else if(lefth>0)
    {
      cout<<lefth<<endl;
      cout<<0<<endl;
    }
    cin>>n;
  }
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>

int main(void) {
    u_int N;
    std::vector<std::vector<u_long>> dp;
    std::vector<u_int> seq;

    std::cin >> N;
    seq.reserve(N);
    dp.resize(N);
    for (u_int i = 0; i < N; ++i) {
        u_int tmp;
        std::cin >> tmp;
        seq.push_back(std::move(tmp));
        dp[i].resize(21, 0);
    }

    dp[0][seq[0]] = 1;
    for (u_int i = 1; i < N - 1; ++i) {
        for (u_int j = 0; j < 21; ++j) {
            if (dp[i - 1][j] > 0) {
                if (j + seq[i] <= 20) {
                    dp[i][j + seq[i]] += dp[i - 1][j];
                }
                if (j >= seq[i]) {
                    dp[i][j - seq[i]] += dp[i  -1][j];
                }
            }
        }
    }
    std::cout << dp[N - 2][seq[N - 1]] << std::endl;

    return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

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

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(string S)
{
  int n = S.size();

  vector<int> cnt(2019, 0);
  cnt[0] = 1;
  int cur = 0;
  int base = 1;
  int mod = 2019;
  for (int i = n - 1; i >= 0; i--)
  {
    int num = S[i] - '0';
    cur += base * num;
    cur %= mod;
    base *= 10;
    base %= mod;
    cnt[cur]++;
  }
  LL ans = 0;
  for (auto c : cnt)
  {
    ans += (LL)c * (LL)(c - 1) / 2;
  }
  cout << ans << endl;
}

int main()
{
  cout << setprecision(10);
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 3764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] lines=br.readLine().split(" ");
        int a=Integer.parseInt(lines[0]);
        int b=Integer.parseInt(lines[1]);
        System.out.printf("%d %d %f",a/b,a%b,(double)a/(double)b);
    }
}

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

int main(){
    string S,T;
    cin >> S >> T;
    bool ok = true;
    map<char,char> ma,ima;
    for(int i = 0; i < S.size();i++){
        char s = S[i], t = T[i];
        if(ma.count(s))if(ma[s]!=t)ok = false;
        if(ima.count(t))if(ima[t]!=s)ok = false;
        ma[s]=t;ima[t]=s;
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
 
}



Measured memory_bytes: 776
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}

	public Main() {
		
		solve();
		
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			System.out.println(dp[0][n] +" " +dp[1][n]);
		}
	}

	int[][] dp = new int[2][1000001];
	public void solve() {
		int[] tetra = new int[200];
		for(int i=1;i<tetra.length;i++){
			tetra[i] = i*(i+1)*(i+2)/6;
		}
		
		
		Arrays.fill(dp[0], 10000);
		Arrays.fill(dp[1], 10000);
		dp[0][0] = dp[1][0] =0;
		for(int i=1;i<tetra.length;i++){
			int t = tetra[i];
			for(int j=0;j<dp[0].length-t;j++){
				dp[0][j+t] = Math.min(dp[0][j+t], dp[0][j]+1);
				if(t%2==0)
					continue;
				dp[1][j+t] = Math.min(dp[1][j+t], dp[1][j]+1);
			}
		}
	}

}

Measured memory_bytes: 29400
from itertools import groupby

S = input()

G = [(k, len(tuple(v))) for k, v in groupby(S)]

INF = float("inf")

ans = 0
pre_k, pre_v = "", INF
for k, v in G:
    ans += v * (v + 1) // 2
    if pre_k == "<" and k == ">":
        ans -= min(pre_v, v)
    pre_k, pre_v = k, v

print(ans)


Measured memory_bytes: 23728
def solve():
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())

    if A1 < B1 and A2 < B2:
        return 0
    elif A1 > B1 and A2 > B2:
        return 0

    C1, C2 = B1-A1, B2-A2

    if C1 < 0:
        C1, C2 = -C1, -C2

    dist = C1*T1 + C2*T2
    if dist == 0:
        return 'infinity'
    elif dist > 0:
        return 0

    diff = C1*T1
    num = diff // abs(dist) * 2

    if diff % abs(dist):
        num += 1

    return num


print(solve())


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<pair<int, pair<int, int>>> ts;
    ts.push_back({0, {0, 0}});
    for (int i = 0; i < n; ++i) {
        int t, x, y;
        cin >> t >> x >> y;
        ts.push_back({t, {x, y}});
    }
    sort(ts.begin(), ts.end());
    for (int i = 1; i < (int)ts.size(); ++i) {
        int dt = ts[i].first - ts[i - 1].first;
        int dx = ts[i].second.first - ts[i - 1].second.first;
        int dy = ts[i].second.second - ts[i - 1].second.second;
        if (abs(dx) + abs(dy) > dt) {
            cout << "No"
                 << "\n";
            return 0;
        }
        if (dt % 2 != (abs(dx) + abs(dy)) % 2) {
            cout << "No"
                 << "\n";
            return 0;
        }
    }
    cout << "Yes"
         << "\n";
    return 0;
}

Measured memory_bytes: 1912
n = int(input())
l_before = input()

l = l_before.split(' ')



i = 0
j = 0
k = 0

count = 0

for ic in range(n):
    for jc in range(n-ic-1):
        for kc in range(n-ic-jc-2):
            i = ic
            j = i + jc + 1
            k = j + kc + 1
            if int(l[i]) != int(l[j]):
                if int(l[j]) != int(l[k]):
                    if int(l[i]) != int(l[k]):
                        if int(l[i]) >= int(l[j]):
                            if int(l[k]) >= int(l[i]):
                                if int(l[k]) < int(l[i]) + int(l[j]):
                                    count = count + 1
                            else:
                                if int(l[i]) < int(l[k]) + int(l[j]):
                                    count = count + 1
                        else:
                            if int(l[k]) > int(l[j]):
                                if int(l[k]) < int(l[i]) + int(l[j]):
                                    count = count + 1
                            else:
                                if int(l[j]) < int(l[k]) + int(l[i]):
                                    count = count + 1

print(count)


Measured memory_bytes: 69732
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n;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(a) sort(a.begin(),a.end())
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll>>
#define INF 999999999999

int main(){
  int N,K,h[100000],count=0;
  cin>>N>>K;
  rep(i,N){
    cin>>h[i];
    if(h[i]>=K) count++;
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 640
n = int(input())
S = [input() for _ in range(n)]

dic = {}
for i in range(len(S[0])):
    if S[0][i] in dic:
        dic[S[0][i]] += 1
    else:
        dic[S[0][i]] = 1

for i in range(1, n):
    for key in dic:
        if dic[key] == 0:
            continue
        dic[key] = min(dic[key], S[i].count(key))

L = []
for key in dic:
    for _ in range(dic[key]):
        L.append(key)

L.sort()
print("".join(L))

Measured memory_bytes: 3064
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++i)
const int N = 1007;
int n;
double T, A;
int main() {
	scanf("%d", &n);
	scanf("%lf%lf", &T, &A);
	int ans = 0; double mn = 1e18;
	rep(i, 1, n) {
		double x; scanf("%lf", &x);
		double num = T - x * 0.006;
		if (fabs(num - A) < mn) {
			mn = fabs(num - A);
			ans = i;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
/*
    Author : Simanta Deb Turja
    Created On: 21/06/20
    Atcoder Beginner Contest 171
*/

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

#define Professor

using ll = long long;
using i64 = unsigned long long;
using ld = long double;

template <typename T> inline T Min (T a, T b, T c) { 
    return min(a, min(b, c)); 
}
template <typename T> inline T Min (T a, T b, T c, T d) { 
    return min(a, min(b, min(c, d))); 
}
template <typename T> inline T Max (T a, T b, T c) { 
    return max(a, max(b, c)); 
}
template <typename T> inline T Max (T a, T b, T c, T d) { 
    return max(a, max(b, max(c, d))); 
}

template <typename T> inline T Ceil(T a, T b) { 
    return ((a % b == 0) ? (a / b) : (a / b + 1)); 
} 
template <typename T> inline T Floor(T a, T b) { 
    return a / b; 
}

template <typename T> inline T Power (T a, T p) { 
    T res = 1, x = a; 
    while ( p ) { 
        if ( p & 1 ) res = ( res * x ); 
        x = ( x * x ); p >>= 1;
    }
    return res; 
}
template <typename T> inline T BigMod (T a,T p,T M) { 
    a %= M; T ret = (T)1; 
    while (p) { 
        if (p & 1) ret = (ret * a) % M; 
        a = (a * a) % M;  p = p >> 1;
    } 
    return ret;
}
template <typename T> inline T InverseMod (T a,T M) { 
    return BigMod (a, M - 2, M); 
}

template <typename T> inline T gcd ( T a, T b ) { 
    a = abs(a); b = abs(b); 
    while ( b ) { 
        a = a % b; swap ( a, b ); 
    } 
    return a;
}
template <typename T> inline T lcm(T x,T y) { 
    return (((x)/gcd((x),(y)))*(y)); 
}


template< typename T1, typename T2, typename T3 > struct Pair { 
    T1 first; T2 second; T3 third; 
};
template< typename T1, typename T2, typename T3, typename T4 > struct Pair4 { 
    T1 first; T2 second; T3 third; T4 fourth; 
};


using ii = pair <int, int>;
using iii = Pair <int, int, int>;
using iiii = Pair4 <int, int, int, int>;

#define endl '\n'

const double EPS = 1e-7;
const double PI = acos(-1.0);
const ll LLINF = (ll)1e18+1;
const int INF = (int)1e9+1;
const int MOD = (ll)1e9 + 7;
const int N = (int)4e5 + 10;


//++++++++++++++++++Template Ends Here++++++++++++++++++

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector <int> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    int total = 0;
    for (int i = 0; i < k; ++i) {
        total += arr[i];
    }
    cout << total << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

main()
{
        int a,b,c; cin>>a>>b>>c;
        int cnt;
        if(a+b>=c)cnt=b+c;
        else cnt=b*2+a+1;
        cout<<cnt<<endl;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        //int[] inputs = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        //int[,] map = new int[Math.Abs(inputs[1]), Math.Abs(inputs[2])];

        string input = Console.ReadLine();

        Console.WriteLine(input.Substring(0,3));

        return;
    }

}

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

int main() {
	int n; cin >> n;
	pair<pair<string, int>, int> guidebook[n];

	for (int i = 0; i < n; ++i) {
		string s; cin >> s;
		int p; cin >> p;

		guidebook[i] = make_pair(make_pair(s, -p), i + 1); // 点数を降順にするため負にする
	}
	sort(guidebook, guidebook + n);

	for (int g_i = 0; g_i < n; ++g_i) {
		cout << guidebook[g_i].second << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)

typedef long long LL;
const int MOD=998244353;
const int N=2000005;

LL fac[N],inv[N];

void upd(LL &x,LL v) {
	x+=v; (x>=MOD)?(x-=MOD):0;
}

void pre() {
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	rep(i,2,N-1) {
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
	}
	rep(i,2,N-1) inv[i]=inv[i]*inv[i-1]%MOD;
}

LL ksm(LL x,LL dep) {
	LL res=1;
	for (;dep;dep>>=1) {
		(dep&1)?(res=res*x%MOD):0;
		x=x*x%MOD;
	}
	return res;
}

LL C(int n,int m) {
	return fac[n]*inv[m]%MOD*inv[n-m]%MOD;
}

int main(void) {
	pre(); int n,m;
	scanf("%d%d",&n,&m);
	if (n>m) std:: swap(n,m);
	LL ans=0;
	rep(i,1,n) upd(ans,C(i+i,i)*C(n+m-i*2,n-i)%MOD);
	ans=ans*ksm(C(n+m,n)*2%MOD,MOD-2)%MOD;
	upd(ans,m); printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 31488
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	for i := 0; i < 2; i++ {
		M := nextInt()
		M++
		D := nextInt()
		if i == 1 {
			if D == 1 {
				fmt.Println(1)
			} else {
				fmt.Println(0)
			}
		}
	}
}


Measured memory_bytes: 640
import java.util.*;

class Main {
	  static long mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
      long A = sc.nextLong();
      long B = sc.nextLong();
      long ans = 0;
      long cnt = 1;
      
      for (ans=0;B>cnt;ans++) {
    	cnt=cnt+A-1;  
      }

      
	  System.out.println(ans);
  }
  
 
}


Measured memory_bytes: 21716
use petgraph::unionfind::UnionFind;
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        m: usize,
        p: [Usize1; n],
        g: [(Usize1, Usize1); m],
    }

    let mut uf = UnionFind::new(n);
    for &ng in &g {
        uf.union(ng.0, ng.1);
    }

    let mut count = 0;
    for (i, np) in p.iter().enumerate() {
        if uf.equiv(i, *np) {
            count += 1;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 6716
#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
#include <cmath>
using namespace std;
typedef pair<string,int>P;
int dx[] = {-1,1,-4,4};
map<string,int> mp;

void bfs(){
  queue<string> que;

  que.push("01234567");

  while(!que.empty()){
    string p = que.front();
    que.pop();
    string next;
    int pos;
    for(int i = 0 ;  i < 8 ; i++ )if(p[i] == '0')pos = i;

    for(int i = 0 ; i < 4 ; i++ ){
      next = p;
      if(0 <= pos + dx[i] && pos + dx[i] < 8 && !(pos == 3 && i == 1) 
	 && !(pos == 4 && i == 0 )){
	swap(next[pos],next[pos + dx[i]]);
	if(mp[next] == 0 ){
	  que.push(next);
	  mp[next] = mp[p] + 1;
	}
      }
    }
  }
}

int main(){
  string puzzle;
  char c;

  mp["01234567"] = 1;
  bfs();

  while(cin >> c){
    puzzle = "";
    puzzle += c;
    for(int i = 1; i < 8 ; i++){
      cin >> c;
      puzzle += c;
    }
    cout << mp[puzzle]-1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3440
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	count := 0
	flg := false
	for i := 1; i < n + 1; i++ {
		var tmp int
		fmt.Scan(&tmp)
		if flg && i == tmp {
			flg = false
		} else if i == tmp {
			count++
			flg = true
		} else {
			flg = false
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 5504
using System;
class AOJ
{
    public static void Main()
    {
        String st1 = Console.ReadLine();
        int a = int.Parse(st1);
        int min = 1000000000;
        int max = -1000000000;
        long sum = 0;

        String[] st =Console.ReadLine().Split(' ');
        for (int b = 0; b < a; b++)
        {
            int c = int.Parse(st[b]);
            if (min > c)
                min = c;
            if (max < c)
                max = c;
            sum +=(long) c;
        }
        Console.WriteLine("{0} {1} {2}", min, max, sum);
    }

}

Measured memory_bytes: 9824
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,n=0,w=0;
  std::cin >> x;
  std::vector<int> v(x);
  rep(i,x){
    std::cin >> v[i];
    z+=v[i];
  }
  sort(rall(v));
  rep(i,x){
    y+=v[i];
    i++;
  }
  std::cout << abs(z-y-y) << '\n';
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<vector<int>> dp(2, vector<int>(k + 1));
  dp[1][0] = 1;
  for (char c : s) {
    vector<vector<int>> ndp(2, vector<int>(k + 1));
    for (int f : {0, 1}) {
      for (int i = 0; i <= k; ++i) {
        for (int d = 0; d < 10; ++d) {
          if (f and d > (c - '0')) {
            continue;
          }
          if (d and i == k) {
            continue;
          }
          ndp[f and d == (c - '0')][i + !!d] += dp[f][i];
        }
      }
    }
    swap(dp, ndp);
  }
  cout << dp[0][k] + dp[1][k] << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N;
int s[MAX_N];
string str;

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

  cin >> str;
  N = _size(str);

  rep(i, N) {
      if (str[i] == '0') {
          s[i] = 0;
      } else {
          s[i] = 1;
      }
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
      if (s[i] == (i%2)) {
          ++ans;
      }
  }

  int tmp_ans = 0;
  for (int i = 0; i < N; ++i) {
      if (s[i] != (i%2)) {
          ++tmp_ans;
      }
  }

  ans = min(ans, tmp_ans);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 832
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<numeric>
#include<climits>
#include<queue>
 
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= i;
	}
	nth_element(a.begin(), a.begin() + n / 2, a.end());
	long long ans = 0;
	for (int i = 0; i < n / 2; i++) {
		ans += a[n - 1 - i] - a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
//#include<math.h>
//#include<queue>
//#include<iostream>
using namespace std;

int n;
#define maxn 200011
char s[maxn];

struct BIT
{
	int a[maxn];
	void add(int x,int v) {for (;x<=n;x+=x&-x) a[x]+=v;}
	int query(int x) {int ans=0; for (;x;x-=x&-x) ans+=a[x]; return ans;}
}t;

int pos[26][maxn],lp[26],now[26]; bool vis[maxn];
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	for (int i=1;i<=n;i++) t.add(i,1);
	for (int i=1;i<=n;i++)
	{
		int id=s[i]-'a';
		lp[id]++; pos[id][lp[id]]=i;
	}
//	for (int i=1;i<=26;i++) {for (int j=1;j<=lp[i];j++) cout<<pos[i][j]<<' ';cout<<endl;}
	int cnt=0;
	for (int i=0;i<26;i++) if (lp[i]&1) cnt++;
	if (cnt>1) {puts("-1"); return 0;}
	#define LL long long
	LL ans=0;
	for (int i=1;i<=n;i++) if (!vis[i])
	{
//		cout<<i<<endl;
		int id=s[i]-'a'; if (!lp[id]) continue;
		if (now[id]==(lp[id]+1)>>1) continue;
		now[id]++;
		int x=pos[id][now[id]],y=pos[id][lp[id]-now[id]+1];
//		cout<<x<<' '<<y<<endl;
		if (x!=y)
		{
			t.add(x,-1); t.add(y,-1);
			ans+=t.query(n)-t.query(y);
		}
		else t.add(x,-2),ans+=(t.query(n)-t.query(x))>>1;
		vis[x]=vis[y]=1;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
	int n; scanf("%d", &n);
	int sum = (999 / 3) * 200 + (999 - 999 / 3) * 195 + 1;
	rep(i, n) {
		int y, m, d; scanf("%d%d%d", &y, &m, &d);
		int ans = sum; y--; m--;
		ans -= (y / 3) * 200 + (y - y / 3) * 195;
		if ((y + 1) % 3)ans -= (m / 2) * 19 + (m - m / 2) * 20;
		else ans -= m * 20;
		ans -= d;
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 3216
#include<stdio.h>

int main(void)
{
	int A,B,C,D,E;
	scanf("%d%d%d%d%d",&A,&B,&C,&D,&E );

	if (A != 1)
	{
		printf("1");
	}
	if (B != 2)
	{
		printf("2");
	}
	if (C != 3)
	{
		printf("3");
	}
	if (D != 4)
	{
		printf("4");
	}
	if (E != 5)
	{
		printf("5");
	}
	return 0;
}

Measured memory_bytes: 1620
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr>void dump(Itr begin, Itr end) {
  for(;begin != end; ++begin) clog << ' ' << *begin;
  clog << LF;
}

signed main()
{
  int N;
  int a[100100];
  priority_queue<int, vector<int>, greater<int>> pq;

  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    pq.push(a[i]);
  }

  while(pq.size() >= 2) {
    const int small = pq.top(); pq.pop();
    const int large = pq.top(); pq.pop();
    const int next = (large - small*(large/small));
    pq.push(small);
    if (next > 0) {
      pq.push(next);
    }
  }

  cout << pq.top() << endl;

  return 0;
}



Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n;
string k;
long long q[6],ans;
int main()
{
	cin>>n;
	while(n--)
	{
		cin>>k;
		if(k[0]=='M')
		{
			q[1]++;
		}
		if(k[0]=='A')
		{
			q[2]++;
		}
		if(k[0]=='R')
		{
			q[3]++;
		}
		if(k[0]=='C')
		{
			q[4]++;
		}
		if(k[0]=='H')
		{
			q[5]++;
		}
	}
	for(int i=1;i<=5;i++)
	{
		for(int j=i+1;j<=5;j++)
		{
			for(int k=j+1;k<=5;k++)
			{
				ans+=q[i]*q[j]*q[k];
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define multitest
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
inline ll add(ll a, ll b, ll m)
{
	return (((a % m + b % m) % m + m) % m);
}
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

void bfs(int src, int n, vector<v32> &g, v64 &dist)
{
	v32 vis(n + 1, 0);
	vis[src] = 1;
	dist[src] = 0;
	queue<int> Q;
	Q.push(src);
	while (sz(Q))
	{
		int u = Q.front();
		Q.pop();
		vis[u] = 1;
		for (auto itr : g[u])
		{
			if (!vis[itr] && dist[u] + 1 < dist[itr])
			{
				dist[itr] = dist[u] + 1;
				Q.push(itr);
			}
		}
	}
	return;
}

void solve()
{
	int n, x, y;
	cin >> n >> x >> y;
	vector<v32> g(n + 1, v32());
	for (int i = 1; i < n; i++)
	{
		g[i].push_back(i + 1);
		g[i + 1].push_back(i);
	}
	g[x].push_back(y);
	g[y].push_back(x);
	v64 ans(n, 0);
	for (int i = 1; i < n + 1; i++)
	{
		v64 dist(n + 1, 1e9);
		bfs(i, n, g, dist);
		//print_container(dist);
		for (int j = i + 1; j < n + 1; j++)
			if (dist[j] < n)
				ans[dist[j]]++;
	}
	for (int i = 1; i < n; i++)
		cout << ans[i] << ln;
	cout << ln;
	return;
}

int main()
{
	FASTIO;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#define MAX 25
#define NIL -1

typedef struct {
  int parent;
  int left;
  int right;
} Binary;

int depth;
Binary T[MAX];

void PreOrder(int);
void InOrder(int);
void PostOrder(int);


int main() {
  int n, i, p, l, r, root;
  
  scanf( "%d" , &n );
  for ( i=0; i<n; i++ ) T[i].parent = T[i].left = T[i].right = NIL;
  for ( i=0; i<n; i++ ) {
    scanf("%d%d%d", &p, &l, &r);
    T[l].parent = T[r].parent = p;
    T[p].left = l;
    T[p].right = r;
  }

  for ( i=0; i<n; i++ ) if ( T[i].parent == NIL ) root = i;
  
  printf( "Preorder\n" );
  PreOrder(root);
  printf( "\nInorder\n" );
  InOrder(root);
  printf( "\nPostorder\n" );
  PostOrder(root);
  printf( "\n" );
  
  return 0;
}


void PreOrder(int u) {
  if ( u == NIL ) return;
  printf( " %d" , u );
  PreOrder(T[u].left);
  PreOrder(T[u].right);
}

void InOrder(int u) {
  if ( u == NIL ) return;
  InOrder(T[u].left);
  printf( " %d" , u );
  InOrder(T[u].right);
}

void PostOrder(int u) {
  if ( u == NIL ) return;
  PostOrder(T[u].left);
  PostOrder(T[u].right);
  printf( " %d" , u );
}



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

int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    int count = 0;
    for(int i=0;i<s.length();i++){
        if(s[i] == 'C' && count == 0) count++;
        else if(s[i]=='F' && count == 1){
            count++;
        }
    }
    if(count == 2){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}


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

int main() {
  int A, B, C, X, Y;
  long long Min=1000000000;
  cin >> A >> B >> C >> X >> Y;
  rep(i, 2*max(X,Y)+1) if(Min>=C*2*i+A*max(0,X-i)+B*max(0,Y-i)) Min=C*2*i+A*max(0,X-i)+B*max(0,Y-i);
  cout << Min << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool solve() {
    int A, B;
    char S[12];
    cin >> A >> B >> S;
    for (int i = 0; i < A; i++) if (S[i] == '-') return false;
    if (S[A] != '-') return false;
    for (int i = A + 1; i < A + B + 1; i++) if (S[i] == '-') return false;
    return true;
}
int main() {
    cout << (solve() ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n = int(input())
hli = list(map(int,input().split()))

f_inf = float('inf')
dp = [f_inf] * (10**5+10)

def chooseMin(a,b):
    if(a<b):
        return a
    else:
        return b
# 初期条件
dp[0] = 0
for i in range(1,n):
    dp[i] = chooseMin(dp[i], dp[i-1] + abs(hli[i]-hli[i-1]))
    #一番目の足場ではひとつ前しか存在しない
    if (i>1):
        dp[i]=chooseMin(dp[i], dp[i-2]+abs(hli[i]-hli[i-2]))

print(dp[n-1])


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

using namespace std;

const int N=4004;

struct node{int to,next;}num[N];

int cnt=1,n,m,u,v,ans,Cnt[N],st[N],ed[N],head[N],vis[N],sure[N];
vector<int> vec[N],pass[N]; 

void add(int x,int y){num[++cnt].to=y;num[cnt].next=head[x];head[x]=cnt;}

int dfs(int x,int fa,int aim,int id)
{
	if(x==aim) return 1;
	for(int i=head[x];i;i=num[i].next)
	    if(num[i].to!=fa)
	    {
	  	    Cnt[i/2]++;pass[i/2].push_back(id);
	  	    vec[id].push_back(i);
	  	    if (dfs(num[i].to,x,aim,id)==1) return 1;	
		    Cnt[i/2]--;pass[i/2].pop_back();vec[id].pop_back();
	    }
	return 0;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++) scanf("%d%d",&u,&v),add(u,v),add(v,u);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&st[i],&ed[i]);
		dfs(st[i],-1,ed[i],i);
	}
	for(int i=1;i<n;i++) ans+=min(Cnt[i],2);
	printf("%d\n",ans);
	while (1==1)
	{
		int p=0,q;
		for(int i=1;i<n;i++)
		    if(Cnt[i]==1&&vis[i*2]!=vis[i*2+1]) {p=i;break;} 
		if(!p) for(int i=1;i<n;i++) if(Cnt[i]>=2) {p=i;break;}
	    if(!p) break;
		for(int i=0;i<pass[p].size();i++)
		    if(!sure[pass[p][i]]) {q=pass[p][i];break;}
		int x=st[q],y=ed[q];sure[q]=1;
		for(int i=0;i<vec[q].size();i++)
		{
			int t=vec[q][i];
			if(t/2==p)
			{
				if(vis[t])
				{
				   for(int j=0;j<vec[q].size();j++) vec[q][j]^=1;
				   swap(st[q],ed[q]);
				}
				for(int j=0;j<vec[q].size();j++)
				    Cnt[vec[q][j]/2]--,vis[vec[q][j]]=1;
				break;
			}
		}
	}
	for(int i=1;i<=m;i++) printf("%d %d\n",st[i],ed[i]);
	return 0;
}

Measured memory_bytes: 15744
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;
bool isPalin( int N ){
    int rev = 0 ;
    int temp = N ;
    while( N > 0 ){
        int d = N % 10 ;
        rev = rev * 10 + d ;
        N /= 10 ;
    }
    return rev == temp ;
}
int main(){
    bigint N , K ; cin >> N >> K ;
    if( K == 0 ){
        cout << N * N << endl ;
        return 0 ;
    }
    bigint ans=0;
    for(int i=1; i<= N-K ;i++ ){
        bigint B = K + i ;
        ans += ( N / B ) * i ;
       if( N % B >= K )
           ans += N % B - K + 1 ;
    }
    cout << ans << endl ;
    return 0 ;
}


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

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(Q), B(N);
    
    for (int i = 0; i < Q; i++) {
        cin >> A.at(i);
    }
    for (int i = 0; i < Q; i++) {
        B.at(A.at(i) - 1) += 1;
    }

    for (int i = 0; i < N; i++) {
        if (K - Q + B.at(i) > 0){
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <limits>
#include <cstdlib>
#include <regex>
using namespace std;

double inf = numeric_limits<double>::infinity();

#define REP(i,n) for(int i=0;i<n;i++)
using LL = long long int;
LL GCD(LL a,LL b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LL LCM(LL a,LL b){ return (a/GCD(a,b))*b; }


int main() {
    LL n;
    cin >> n;
    for (LL i = 1; i <= 3500; i++) {
        for (LL j = 1; j <= 3500; j++) {
            if (4 * i * j - n * (i + j) > 0 && n * i * j % (4 * i * j - n * (i + j)) == 0) {
                cout << i << " " << j << " " << n * i * j / (4 * i * j - n * (i + j)) << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;

#define MAX 30
#define NIL -1

struct Node{
    int parent,left,right;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
    if( u == NIL){
        return;
    }
    D[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}

int setHeight(int u){
    int h1 = 0, h2=0;
    if(T[u].left != NIL){
        h1 = setHeight(T[u].left) + 1;
    }
    if(T[u].right != NIL){
        h2 = setHeight(T[u].right) + 1;
    }
    return H[u] = h1 > h2 ? h1:h2;
}

int getSibling(int u){
    if(T[u].parent == NIL){
        return NIL;
    }
    if(T[T[u].parent].left != u and T[T[u].parent].left != NIL){
        return T[T[u].parent].left;
    }
    if(T[T[u].parent].right != u and T[T[u].parent].right != NIL){
        return T[T[u].parent].right;
    }
    return NIL;
}

void print(int u){
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "sibling = " << getSibling(u) << ", ";
    int deg = 0;
    if(T[u].left != NIL){
        deg++;
    }
    if(T[u].right != NIL){
        deg ++;
    }
    cout << "degree = " << deg << ", ";
    cout << "depth = " << D[u] << ", ";
    cout << "height = " << H[u] << ", ";
    if(T[u].parent == NIL){
        cout << "root" << endl;
    }else if (T[u].left != NIL or T[u].right != NIL){
        cout << "internal node" << endl;
    }else{
        cout << "leaf" << endl;
    }
}

int main() {
   
    int v,l,r, root = 0;
    cin >> n;
    for (int i=0;i<n;i++){
        T[i].parent = NIL;
    }
    for (int i=0;i<n;i++){
        cin >> v >> l >> r;
        T[v].left = l;
        T[v].right = r;
        if(l!= NIL){
            T[l].parent = v;
        }
        if(r != NIL){
            T[r].parent = v;
        }
    }

    for(int i=0;i<n;i++){
        if(T[i].parent == NIL){
            root = i;
        }
    }

    setDepth(root,0);
    setHeight(root);

    for (int i=0;i<n;i++){
        print(i);
    }

}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int n;
int sum;
int main(){
	scanf("%d",&n);
	int l,r;
	while(n--){
		scanf("%d%d",&l,&r);
		sum+=r-l+1;
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[25],b[25],c[25];
int main(){
  int n; cin >> n;
  for(int i=1;i<=n;++i){
    cin >> a[i];
  }
  for(int i=1;i<=n;++i){
    cin >> b[i];
  }
  for(int i=1;i<=n-1;++i) cin >> c[i];
  int ans=0;
  for(int i=1;i<=n;++i) ans += b[i];
  for(int i=2;i<=n;++i){
    if(a[i]==a[i-1]+1) ans += c[a[i-1]];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
N,M,Q = map(int,input().split())
num = [[0 for i in range(N)] for j in range(N)]
lr = [list(map(int,input().split())) for i in range(M)]
for l,r in lr:
    num[l-1][r-1] += 1

for j in range(N):
    for i in range(N-1,0,-1):
        num[i-1][j] += num[i][j]
for i in range(N):
    for j in range(N-1):
        num[i][j+1] += num[i][j]
pq = [list(map(int,input().split())) for i in range(Q)]
ans = []
for p,q in pq:
    ans.append(num[p-1][q-1])
print(*ans,sep='\n')

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;

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

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60, lmod = 1e9+7;

const int MAX_N = 100005;

ll p[MAX_N],q[MAX_N],psum[MAX_N];

int main(){
  int W,H; cin >> W >> H;
  rep(i,W) scanf("%lld",p+i);
  rep(i,H) scanf("%lld",q+i);
  sort(p,p+W);
  psum[0] = p[0];
  REP(i,1,W) psum[i] = psum[i-1] + p[i];
  ll ans = 0LL;
  ans += psum[W-1];
  rep(i,H){
    int ind = int(upper_bound(p,p+W,q[i]) - p);
    ans += q[i];
    if(ind!=0) ans += psum[ind-1] + q[i] * (W-ind);
    else ans += q[i] * W;
  }
  cout << ans << endl;
  return 0;
}

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

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

  if (a <= 9 && b <=9) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 10000000000000;
const double PI = acos(-1);

int main() {
	int N, M;
	cin >> N >> M;
	bool cl[100001] = {};
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		cl[a] = !cl[a];
		cl[b] = !cl[b];
	}
	for (int i = 0; i < N; i++) {
		if (cl[i]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

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

int main () {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(A+B>C+D) {
        cout << "Left" << endl;
    } else if(A+B == C+D) {
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define LINF 1E17
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }


int main() {
	ll n, sum = 0,b,in;
	vl v;
	cin >> n;
	rep(i,n) {
		cin >> in;
		v.push_back(in);
		sum += in;
	}
	b = ((n + 1)*n )/ 2;
	if (sum%b!=0)cout << "NO" << endl;
	else if(n==1)cout << "YES" << endl;
	else{
		vl sub;
		ll count = 0;
		sum /= b;
		rep(i, n-1) {
			sub.push_back(v[i+1] -v[i]);
		}
		sub.push_back(v[0] - v[n-1]);
		bool sw = true;
		rep(i, n) {
			//cout << sum - sub[i] << " ";
			if ((sum - sub[i]) % n != 0|| sum - sub[i]<0) {
				sw = false;
			}
			else count += (sum - sub[i]) / n;
		}
		if(sw&&count==sum)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
}


Measured memory_bytes: 2548
n = int(input())
a = list(map(int,input().split()))
ans = 0

uf,df = True,True
x = a[0]
for ai in a:
    
    if x > ai:
        uf = False
    if x < ai:
        df = False
    if (uf or df) is False:
        ans += 1
        uf,df, = True,True
    x = ai
print(ans+1)

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N, M, X; scanf("%d %d %d", &N, &M, &X);
  vector<int> row(N + 5, 0);
  for (int i = 0; i < M; ++i) {
    int a; scanf("%d", &a);
    row[a] = 1;
  }
  int ans = min(accumulate(row.begin(), row.begin() + X, 0),
                accumulate(row.begin() + X + 1, row.end(), 0));
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <cstring>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll calb(ll a){
  ll b = 0;
  while(a){
    b += a % 10;
    a /= 10;
  }
  return b;
}

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

  ll a = 1;
  ll b;
  ll p = 1;
  while(k){
    b = calb(a);
    if(a-b*p <= 0){
      cout << a << endl;
      k--;
      a+=p;
    }else{
      p *= 10;
      a = a / p * p + p - 1;
    }
  }


  return 0;
}


Measured memory_bytes: 256
use v5.18;
use warnings;
use List::Util qw( sum );
sub read_line { chomp(my $str = <STDIN>); $str }
sub splited_read_line { split / /, read_line }

my ($donut_num, $sweets_base_gram) = splited_read_line;
my @consume_grams = sort { $a <=> $b } map { read_line } 0 .. $donut_num - 1;
$sweets_base_gram -= sum @consume_grams;
my $min_consume_donut_num = int $sweets_base_gram / $consume_grams[0];
say $min_consume_donut_num + @consume_grams;


Measured memory_bytes: 896