akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
#define MOD 1000000007
using namespace std;

int n, k;
int d[10];

bool judge(int a) {
	while (a>0) {
		int num = a % 10;
		REP(i, k) {
			if (num == d[i]) {
				return false;
			}
		}
		a /= 10;
	}
	return true;
}

int main() {
	cin >> n >> k;
	REP(i, k) {
		cin >> d[i];
	}
	int ans = n;
	while (1) {
		if(judge(ans)){
			cout << ans << endl;
			break;
		}
		ans++;
	}
	return 0;
}

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

const int MAX = 999999;//nCrのnの最大値っぽい
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int x, y;
  int a, b;
  
  cin >> x >> y;
  b = (2*y-x)/3;
  a = y - 2*b;
  if((2*y-x)%3 != 0 || a < 0 || b < 0){
    cout << 0;
    return 0;
  }
  
  //cout << a << " " << b << endl;
  // 前処理
  COMinit();
  cout << COM(a+b, a) << endl;
  
  return 0;
}

Measured memory_bytes: 23680
n, q = map(int, input().split())  # n:num of string，q:num of question
s = input()  # string
cnt = [0] * n  # cnt list of 'AC'

for i in range(n-1):
    if s[i: i + 2] == 'AC':
        cnt[i + 1] += 1

for i in range(1, n):
    cnt[i] += cnt[i - 1]  # 累積和

for i in range(q):
    l, r = map(int, input().split())  # question
    l, r = l - 1, r - 1
    print(cnt[r] - cnt[l])

Measured memory_bytes: 7668
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-10;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/* Coding space */
int main(){
  int n; cin >> n;
  vt<string> in(n);
  vt<string> out(n);
  rep(i,n)  cin >> in[i],out[i] = in[i];
  ll ans = 0;
  rep(i,n){
    rep(k,n)rep(j,n) out[k][j] = in[k][(j+i)%n];
    [&](){
    rep(j,n)rep(k,n){
      if(k != j && out[k][j] != out[j][k]){return;}
      if(k == n-1 && j == n-1)  ans++;
    }
    }();
  }
  cout << ans * n << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    double r = Double.parseDouble(sc.next());
    double area = Math.PI*r*r;
    double length = Math.PI*2*r;
    System.out.printf("%f %f\n", area, length);
  }
}


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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N+1);
    vector<long long> B(N);

    for (int i=0; i<=N; i++) cin >> A.at(i);
    for (int i=0; i<N; i++) cin >> B.at(i);
    long long ans=0;
    for (int i=0; i<N; i++) {
        ans += min(A.at(i), B.at(i));
        B.at(i) -= min(A.at(i), B.at(i));
        ans += min(A.at(i+1), B.at(i));
        A.at(i+1) -= min(A.at(i+1), B.at(i));

        /*
        if (A.at(i) < B.at(i)) {
            ans += A.at(i);
            B.at(i) -= A.at(i);
            if (A.at(i+1) < B.at(i)) {
                ans += A.at(i+1);
                A.at(i+1) = 0;
            }
            else {
                ans += B.at(i);
                A.at(i+1) -= B.at(i);
            }
        }
        else {
            ans += B.at(i);
            A.at(i) -= B.at(i);
        }
        */
    }
    cout << ans << endl;
}

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


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

    if(s[0]==s[2]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


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

int main(){
    int n,a,b,c;
    cin >> n >> a >> b >> c;
    int l[n];
    rep(i, n){
        cin >> l[i];
    }
    
    int g[n] = {0};
    int mp = 0;
    int at=0, bt=0, ct=0;
    int MIN = 3000;
    rep(i, pow(4, n)){
        mp = 0;
        at = 0;bt = 0; ct = 0;
        int ii = i;
        int j=0;
        while(j<n){
            g[j] = ii%4;
            ii = ii/4;
            j+=1;
        }
        int c0=0, c1=0, c2=0, c3=0;
        rep(k, n){
            if(g[k]==0){
                c0++;
            }else if(g[k]==1){
                c1++;
            }else if(g[k]==2){
                c2++;
            }else{
                c3++;
            }
        }
        if(c0==0 || c1==0 || c2==0) continue;

        rep(k, n){
            if(g[k]==0){
                at += l[k];
                mp += 10;
            }else if(g[k]==1){
                bt += l[k];
                mp += 10;
            }else if(g[k]==2){
                ct += l[k];
                mp += 10;
            }
        }
        mp -= 30;
        mp = mp + abs(a-at) + abs(b-bt) + abs(c-ct);
        
        MIN = min(MIN, mp);
    }

    cout << MIN << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
 
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
  ll N; cin >> N;
  vector<ll> A(N); for(auto& in:A) cin >> in;
for(int i=0;i<N;i++)A[i] -= (i+1);
sort(A.begin(),A.end());
int idx = N/2;
ll b = A[idx];
ll ans =0;
for(auto v:A) ans += abs(v-b);
cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
s = input()
k = int(input())

n = len(s)
if n == 1 or k == 1: print(s[0])
else:
  for i in range(n):
    if s[i] == "1":
      k -= 1
      if k == 0: 
        print(s[i])
        break
    else:
      print(s[i])
      break

Measured memory_bytes: 8992
#include <stdio.h>
#include <iostream>
#include <algorithm>
using ll = long long;
using namespace std;

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

    int a, b;
    cin >> a;
    cin >> b;

    cout << b * 2 - a << "\n";
    return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        while(tan.hasNext()){
            int n,k,sum=0;
            n=tan.nextInt();
            k=tan.nextInt();
            int []a=new int[n];
            for (int i = 0; i < n; i++) {
                a[i]=tan.nextInt();
            }
            Arrays.sort(a);
            for (int i = 0; i < k; i++) {
                sum=sum+a[i];
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 38896
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        s: chars,
        k: [usize],
    }
    for k in k {
        let mut d: i64 = 0;
        let mut m = 0;
        let mut dm = 0;
        let mut tot = 0;
        for i in 0..n {
            if i >= k {
                match s[i - k] {
                    'D' => {
                        d -= 1;
                        dm -= m;
                    }
                    'M' => m -= 1,
                    _ => (),
                }
            }
            match s[i] {
                'C' => tot += dm,
                'M' => {
                    m += 1;
                    dm += d;
                }
                'D' => d += 1,
                _ => (),
            }
        }
        puts!("{}\n", tot);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 17656
// Created by: WeirdBugsButOkay

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ff first
#define ss second
#define PI 3.14159265358979323846
#define endl '\n'

using namespace std;

void solve()
{
	int n, k;
	cin >> n >> k;
	int p[n];
	for(int i = 0; i < n; i++)
		cin >> p[i];
	sort(p, p + n);
	int ans = 0;
	for(int i = 0; i < k; i++)
		ans += p[i];
	cout << ans << endl;
}

int main()
{
	int q = 1;
	//scanf("%d", &q);
	for(int i = 1; i <= q; i++)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3600
#ifndef BZ
#ifndef __clang__
#pragma GCC optimize "-O3"
#endif
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n, k;
map<int, int> mm;
vector<int> vv;

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		++mm[a];
	}
	for (auto e: mm) {
		vv.push_back(e.second);
	}
	sort(ALL(vv));
	reverse(ALL(vv));
	int ans = 0;
	while (vv.size() > k)
		ans += vv.back(), vv.pop_back();
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 10744
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint N, M;
	cin >> N >> M;

	if (N > 2 && M > 2) cout << N * M - 2 * (M + N) + 4 << "\n";
	else if (N == 2 || M == 2) cout << 0 << "\n";
	else if (N == 1 && M == 1)cout << 1 << "\n";
	else cout << N * M - 2 << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(string, s);
    if(s.size() < 26){
        for(char c = 'a'; c <= 'z'; c ++){
            if(Contains(s, c)) continue;
            Cout(s, c); return 0;
        }
    }
    else{
        string t = "";
        for(int i = 25; i >= 0; i --){
            sort(s.begin() + i+1, s.end());
            auto itr = find_if(s.begin() + i+1, s.end(), [k = s[i]](auto c){ return c > k; });
            if(itr != s.end()){
                Cout(string(s.begin(), s.begin() + i), *itr);
                return 0;
            }
        }
        Cout("-1");
    }
    
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        class PriorityQueue<T>
        {
            public readonly List<T> m_list;
            private readonly Func<T, T, int> m_compare;
            private int m_count;
            public PriorityQueue(int capacity, Func<T, T, int> compare)
            {
                m_list = new List<T>(capacity);
                m_compare = compare;
                m_count = 0;
            }
            private int Add(T value)
            {
                if (m_count == m_list.Count)
                {
                    m_list.Add(value);
                }
                else
                {
                    m_list[m_count] = value;
                }
                return m_count++;
            }
            private void Swap(int a, int b)
            {
                T tmp = m_list[a];
                m_list[a] = m_list[b];
                m_list[b] = tmp;
            }
            public void Enqueue(T value)
            {
                int c = Add(value);
                while (c > 0)
                {
                    int p = (c - 1) / 2;
                    if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; }
                    c = p;
                }
            }
            public T Dequeue()
            {
                T value = m_list[0];
                m_list[0] = m_list[--m_count];
                int p = 0;
                while (true)
                {
                    int c1 = p * 2 + 1;
                    int c2 = p * 2 + 2;
                    if (c1 >= m_count) { break; }
                    int c = (c2 >= m_count || m_compare(m_list[c1], m_list[c2]) < 0) ? c1 : c2;
                    if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; }
                    p = c;
                }
                return value;
            }
        }

        static long Solve(int N, int M, int[] A)
        {
            var q = new PriorityQueue<long>(N, (a, b) => b.CompareTo(a));
            foreach (int a in A) { q.Enqueue(a); }
            for (int i = 0; i < M; ++i)
            {
                long a = q.Dequeue();
                q.Enqueue(a / 2);
            }
            return q.m_list.Sum();
        }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int[] A = ReadInts();
            Console.WriteLine(Solve(V[0], V[1], A));
        }
    }
}


Measured memory_bytes: 25948
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};


int main(void){
	char X,Y;
	cin>>X>>Y;
	if(X<Y) print("<");
	else if(X>Y) print(">");
	else print("=");
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

std::string s;

int main(void){
	int n,m=1,r,i;
	std::cin >> n;
	while(m*(m+1)/2<n){
		++m;
	}
	r = m*(m+1)/2-n;
	for(i=1; i<=m; ++i){
		if(i==r){
			continue;
		}
		std::cout << i << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC144x
{
	public class A
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine();
			Console.WriteLine(new A(input).GetResult());
		}

		public A(string input)
		{
			this._input = input;
		}

		public int GetResult()
		{
			var inputs = _input.Split(' ').ToArray();
			foreach (var input in inputs)
			{
				if (int.Parse(input) >= 10) return -1;
			}

			return int.Parse(inputs[0]) * int.Parse(inputs[1]);
		}

		private string _input;
	}
}

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

vector<vector<int>> G;

int rec(int v) {
    vector<int> children;
    for (int i = 0; i < G[v].size(); i++) {
        children.push_back(rec(G[v][i]));
    }
    
    sort(children.begin(), children.end(), greater<int>());
    int ret = 0;
    for (int i = 0; i < children.size(); i++) {
        ret = max(i+1+children[i], ret);
    }
    return ret;
}

int main(void){
    int N; cin >> N;
    G.resize(N);
    for (int i = 1; i < N; i++) {
        int a; cin >> a;
        a--;
        G[a].push_back(i);
    }
    
    cout << rec(0) << endl;
}


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

int main(){
  int cost, number;
  int coin[21];
  int T[21][50001];
  cin >> cost >> number;
  for(int i = 1; i <= number; i++){
    cin >> coin[i];
  }
  for(int i = 0; i <= number; i++){
    T[i][0] = 0;
  }
  for(int j = 0; j <= cost; j++){
    T[0][j] = 50000;
  }
  for(int i = 1; i <= number; i++){
    for(int j = 1; j <= cost; j++){
      if(j < coin[i]){
	T[i][j] = T[i-1][j];
      }
      else{
	T[i][j] = min(T[i-1][j], T[i][j-coin[i]]+1);
      }
    }
  }
  cout << T[number][cost] << endl;
}

#if 0
10????¨??????§????£????????????¨?????§?????????
AOJ????????????????§£??¬?????????????????????????????????????????´?????????????£????????????¨?????§????????????????????????????\?????????§????§£???????????£?????¢?????´?????????????????§?§£???????¬?????????¨???????°??????????
#endif

  

Measured memory_bytes: 7124
#include <stdio.h>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int one=0,nine=0,four=0,seven=0;
    for(int i=0;i<4;i++)
    {
        int x;
        cin>>x;
        if(x==1)
        one++;
        if(x==4)
        four++;
        if(x==7)
        seven++;
        if(x==9)
        nine++;
    }
    if(one==1 && nine==1 && four==1 && seven==1)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	s := ""
	fmt.Scan(&s)
	a := []byte("A")[0]
	z := []byte("Z")[0]

	i := 0
	for i = 0; i < len(s); i++ {
		if s[i] == a {
			break
		}
	}

	j := 0
	for j = len(s) - 1; j >= 0; j-- {
		if s[j] == z {
			break
		}
	}

	fmt.Println(j - i + 1)

}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int ans = (a+b) % 24;
   // cout << ans << endl;
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    a = list(map(int, input().split()))
    d = c
    for j in range(m):
        d += b[j]*a[j]
    if d>0:
        ans += 1

print(ans)


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  char c[3];
  rep(i,3) cin >> c[i];
  if(c[1] == 'R') c[1] = 'B';
  else c[1] = 'R';
  rep(i,3) cout << c[i];
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3620
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

const int MAX_N = 40 + 5;
const int MAX_M = 10 + 5;
int P[MAX_M * MAX_N + 10][MAX_M * MAX_N + 10][MAX_N];
int N, Ma, Mb;
VI A, B, C;


void solve() {
    REP(i, MAX_M * MAX_N) {
        REP(j, MAX_M * MAX_N) {
            REP(n, MAX_N) {
                P[i][j][n] = INF;
            }
        }
    }
    P[0][0][0] = 0;
    REP(n, N) {
        REP(i, MAX_M * MAX_N) {
            REP(j, MAX_M * MAX_N) {
                if (i >= A[n] and j >= B[n]) {
                    P[i][j][n + 1] = min(P[i][j][n], P[i - A[n]][j - B[n]][n] + C[n]);
                } else {
                    P[i][j][n + 1] = P[i][j][n];
                }
            }
        }
    }
    int ans = INF;
    for (int i = 1; ; i++) {
        int ma = Ma * i; int mb = Mb * i;
        if (ma >= MAX_M * MAX_N or mb >= MAX_M * MAX_N) {
            break;
        }
        //cout << ma << " " << mb << " " << P[ma][mb][N] << endl;
        ans = min(ans, P[ma][mb][N]);
    }
    if (ans == INF) {
        ans = -1;
    }
    cout << ans << endl;
}

int main(int argc, char const* argv[])
{
    cin >> N >> Ma >> Mb;
    REP(i, N) {
        int a, b, c;
        cin >> a >> b >> c;
        A.PB(a); B.PB(b); C.PB(c);
    }
    solve();
    return 0;
}


Measured memory_bytes: 82176
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
m = 0

for i in range(n - 1):
    if a[i] + 1 == a[i + 1]:
        m += b[a[i] - 1] + c [a[i] - 1]
    else:
        m += b[a[i] - 1]
        
m += b[a[n - 1] - 1]
        
print(m)


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

int dsum(int n) {
    int ans = 0;
    while (n > 0) {
        ans += n%10;
        n /= 10;
    }
    return ans;
}

int main() {
    int N; cin >> N;
    if (N%dsum(N) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

vector<int> X, Y;
vector<vector<int>> T;

bool dfs(auto u) {
  if(T[u].empty()) return true;
  auto sum = 0;
  vector<bool> dp(5000+1);
  dp[0] = true;
  for(auto v: T[u]) {
    if(!dfs(v)) return false;
    sum += X[v] + Y[v];
    vector<bool> nex(5000+1);
    for(auto i=0; i<=5000; ++i) if(dp[i]) {
      if(i+X[v] <= 5000) nex[i+X[v]] = true;
      if(i+Y[v] <= 5000) nex[i+Y[v]] = true;
    }
    swap(dp, nex);
  }
  for(auto i=X[u]; 0<=i; --i) if(dp[i]) {
    Y[u] = sum - i;
    return true;
  }
  return false;
}

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

  T.resize(N);
  for(auto i=1; i<N; ++i) {
    int P;
    cin >> P;
    T[P-1].emplace_back(i);
  }

  X.resize(N);
  Y.assign(N, 0);
  for(auto& i: X) cin >> i;

  cout << (dfs(0) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] bArr = new int[n];
		int total = 0;
		int prev = Integer.MAX_VALUE;
		for (int i = 1; i < n; i++) {
		    int x = sc.nextInt();
		    total += Math.min(prev, x);
		    prev = x;
		}
		total += prev;
		System.out.println(total);
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n; cin >> n;
  for(int i = 1; i <= n; i++){
    if(floor((double)i*1.08) == n){
      cout << i << endl;
      system("pause");
      return 0;
    }
  }
  cout << ":(" << endl;
  system("pause");
}

Measured memory_bytes: 504
def judge1(lst):
    flag = False
    if lst[-1] == lst[-2]:
        flag = True
    return flag


def main():
    lst = list(map(int, input().split()))
    lst.sort()
    count = 0

    while True:
        if judge1(lst):
            break

        lst[0] += 1
        lst[1] += 1
        count += 1

    while lst[2] - lst[0] >= 2:
        lst[0] += 2
        count += 1

    if lst[2] - lst[0] == 1:
        count += 2

    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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


int main(){
    int n,k; cin>>n>>k;
    vector<int> h(n);
    rep(i,n) cin>>h[i];
    int ans=0;
    
    rep(i,n){
        if(h[i]>=k){
            ans++;
        }
        
    }
    cout << ans << endl;
    
    
    
}


Measured memory_bytes: 640
//Problem *
#include<bits/stdc++.h>
using namespace std;
const int N=3005;
int n,m,dp[N][N];
char a[N][N];
int main(){
	scanf("%d%d",&n,&m);dp[1][1]=1;
	for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(a[i][j]=='.'&&!dp[i][j])dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
	printf("%d",dp[n][m]);
	return 0;
}

Measured memory_bytes: 18688
n = int(input())
tbl = [[0 for i in range(n)] for j in range(5)]
for i in range(2):
    a = list(map(int,input().split()))
    for j in range(n):
        tbl[i][j] = a[j]
D_1 = 0
d_2 = 0
d_3 = 0
for k in range(n):
    tbl[2][k] = abs(tbl[0][k]-tbl[1][k])
    tbl[3][k] = (abs(tbl[0][k]-tbl[1][k]))**2
    tbl[4][k] = (abs(tbl[0][k]-tbl[1][k]))**3
    D_1 += tbl[2][k]
    d_2 += tbl[3][k]
    d_3 += tbl[4][k]
M = max(tbl[2])
print(f'{D_1:.6f}')
print(f'{(d_2)**(1/2):.6f}')
print(f'{(d_3)**(1/3):.6f}')
print(f'{M:.6f}')


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

void solve () {
    int n;
    cin >> n;
    vector<int> a(n + 2);
    int ans = 0;
    for (int i = 1; i < n + 1; i++) {
        cin >> a[i];
        if (a[i] - a[i - 1] > 0) {
            ans += a[i] - a[i - 1];
        }

    }
    cout << ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N + 2);
    for(int i = 0; i < N; ++i) cin >> A[i + 1];
    for(int _ = 0; _ < K; ++_) {
        vector<int> add(N + 2);
        for(int i = 1; i < N + 1; ++i) {
            int l = max(0, i - A[i]);
            int r = min(N + 1, i + A[i] + 1);
            add[l]++;
            add[r]--;
        }
        for(int i = 0; i <= N; ++i) add[i + 1] += add[i];
        swap(add, A);
        bool e = true;
        for(int i = 1; i <= N; ++i) {
            if(A[i] != N) {
                e = false;
                break;
            }
        }
        if(e) {
            for(int i = 1; i <= N; ++i) cout << A[i] << " ";
            cout << '\n';
            return 0;
        }
    }
    for(int i = 1; i <= N; ++i) cout << A[i] << " ";
    cout << '\n';
    return 0;
}


Measured memory_bytes: 5180
N = int(input())
times = list(map(int, input().split()))
M = int(input())
probrems = []

for i in range(M):
    probrems.append([int(i) for i in input().split()])
                         
sum_times = []
                    
for p in range(M):
    init_time = times.copy()
    init_time[probrems[p][0]-1] = probrems[p][1]
    sum_times.append(sum(init_time))

for t in sum_times:
    print(t)

Measured memory_bytes: 3064
using namespace std;
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define w(x) int x;cin>>x;while(x--)

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define ll long long

void abc()
{
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int mod = 1000000007;
vector<int> dp;
vector<int> v;


int go( int i, int k) {


	if (i == v.size() - 1) return 0;
	if (dp[i] != -1) return dp[i];

	int x = INT_MAX ;


	for (int j = 1; j <= k; j++) {
		if (i + j < v.size()) {
			int y = abs(v[i] - v[i + j]) + go(i + j, k);
			x = min(x, y);
		}
	}

	return dp[i] = x;



}



int main()
{
	abc();


	int n; int k;
	cin >> n >> k;
	v.resize(n);
	dp.resize(n, -1);

	for (int i = 0; i < n; i++) cin >> v[i];

	cout << go(0, k) << endl;










}

Measured memory_bytes: 11912
function Main(input) {
  let tmp = input.split("\n");
  let n = parseInt(tmp[0], 10);
  let a = tmp[1].split(" ").map((x) => parseInt(x, 10));

  let ans = 100000;
  for (let i = 0; i < n; i++) {
    let cnt = 0;
    while (a[i] % 2 == 0) {
      cnt++;
      a[i] /= 2;
    }
    ans = Math.min(ans, cnt);
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
fun main(arr: Array<String>) {
    println(if(solve()) "Yes" else "No")
}

fun solve():Boolean {
    val n = readLine()!!.toInt()
    for(i in (0..n)) {
        val diff = n - i*7
        if(diff < 0) {
            break
        }
        if(diff % 4 == 0) {
            return true
        }
    }
    return false
}

Measured memory_bytes: 34384
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define NMAX 1001

int compare(const void *a, const void *b);
int compress (int *x1, int *x2, int w, int n);
int main(void)
{
  while (1) {
    int i, x, y, w, h, n, res = 0;
    int x1[NMAX], x2[NMAX], y1[NMAX], y2[NMAX];
    char fld[2*NMAX][2*NMAX];
    scanf("%d%d", &w, &h);
    if (!w && !h) break;
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d%d%d%d", &x1[i], &y1[i], &x2[i], &y2[i]);
    w = compress(x1, x2, w, n) - 1;
    h = compress(y1, y2, h, n) - 1;
    memset(fld, 0, sizeof(fld));
    for (i = 0; i < n; i++) {
      for (x = x1[i]; x < x2[i]; x++) {
        for (y = y1[i]; y < y2[i]; y++) {
          fld[x][y] = 1;
        }
      }
    }
    for (x = 0; x < w; x++) {
      for (y = 0; y < h; y++) {
        if (!fld[x][y]) {
          int top = 0, tail = 0, queue[4 * NMAX * NMAX][2];
          res++;
          fld[x][y] = 1;
          queue[tail][0] = x;
          queue[tail++][1] = y;
          while (top != tail) {
            int sx = queue[top][0], sy = queue[top++][1], dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
            for (i = 0; i < 4; i++) {
              int tx = sx + dx[i], ty = sy + dy[i];
              if (tx >= 0 && tx < w && ty >= 0 && ty < h && !fld[tx][ty]) {
                queue[tail][0] = tx;
                queue[tail++][1] = ty;
                fld[tx][ty] = 1;
              }
            }
          }
        }
      }
    }
    printf("%d\n", res);
  }
}

int compare(const void *a, const void *b) {
  int ta = *(int*)a, tb = *(int*)b;
  if (ta > tb) return 1;
  else if (ta < tb) return -1;
  return 0;
}

int compress (int *x1, int *x2, int w, int n)
{
  int i, sz = 0, xscount = 0, xs[2*NMAX+3];
  xs[xscount++] = 0;
  for (i = 0; i < n; i++) {
    xs[xscount++] = x1[i];
    xs[xscount++] = x2[i];
  }
  xs[xscount++] = w;
  xs[xscount] = -1;
  qsort(xs, xscount, sizeof(int), compare);
  for (i = 0; i < xscount; i++) {
    xs[sz++] = xs[i];
    while (xs[sz-1] ==  xs[i+1]) i++;
  }
  for (i = 0; i < n; i++) {
    int l = 0, r = sz - 1, m, x = x1[i];
    while (l <= r) {
      m = (l + r) / 2;
      if (xs[m] > x) r = m - 1;
      else l = m + 1;
    }
    x1[i] = r;
    l = 0;
    r = sz - 1;
    x = x2[i];
    while (l <= r) {
      m = (l + r) / 2;
      if (xs[m] > x) r = m - 1;
      else l = m + 1;
    }
    x2[i] = r;
  }
  return sz;
}


Measured memory_bytes: 7072
#include<bits/stdc++.h>
#define N 55
using namespace std;

int h, w, d, n, r[N];
string s[N];
int cnt[N][N];
bool used[N][N];

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

void dfs(int y, int x){

  if(used[y][x]) return;
  
  used[y][x]=true;

  for(int i=0;i<4;i++){

    int ny=y+dy[i], nx=x+dx[i];

    if(ny<0||nx<0||h<=ny||w<=nx) continue;

    if(s[ny][nx]=='#') continue;
    
    dfs(ny, nx);
  }
  
}

void draw(int sy, int gy, int sx, int gx, int value){
  
  for(int i=sy;i<=gy;i++){

    for(int j=sx;j<=gx;j++){

      if(i<0||j<0||h<=i||w<=j) continue;
      
      cnt[i][j]+=value;
      
    }
    
  }
  
}

int main(){

  cin>>h>>w>>d>>n;
  
  int sy, sx;
  
  for(int i=0;i<h;i++){
    
    cin>>s[i];
    
    for(int j=0;j<w;j++)

      if(s[i][j]=='D'){
	sy=i;
	sx=j;
      }
        
  }

  for(int i=1;i<=d;i++) cin>>r[i];
  
  for(int i=0;i<n;i++){
    
    int x, y, s;

    cin >> x >> y >> s;
    
    if(!s) draw(y-r[1],y+r[1],x-r[1],x+r[1],1);
    else if(s==d){
      draw(y-N,y+N,x-N,x+N,1);
      draw(y-r[d],y+r[d],x-r[d],x+r[d],-1);
    }
    else{
      draw(y-r[s+1],y+r[s+1],x-r[s+1],x+r[s+1],1);
      draw(y-r[s],y+r[s],x-r[s],x+r[s],-1);
    }
    
  }
  
  int ncnt=0;
  
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      
      if(s[i][j]!='#'&&cnt[i][j]==n) ncnt++;
	
  if(ncnt>=1){
    
    dfs(sy,sx);
    
    int yescnt=0, nocnt=0;

    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	if(s[i][j]!='#'&&cnt[i][j]==n&&used[i][j]) yescnt++;
	if(s[i][j]!='#'&&cnt[i][j]==n&&!used[i][j]) nocnt++;
      }
    
    if(yescnt==ncnt) cout<<"Yes"<<endl;
    else if(nocnt==ncnt) cout<<"No"<<endl;
    else cout<<"Unknown"<<endl;
    
  }
  else cout<<"Broken"<<endl;
  
  return 0;
}

Measured memory_bytes: 3296
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
vi p, r, ssi; 
void initialize(int N) 
{
		r.assign(N, 0);
		ssi.assign(N, 1);
		p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; 
}
int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
void unionSet(int i, int j)
{
	if (!isSameSet(i, j))
	{
		int x = findSet(i), y = findSet(j);
		if (r[x] > r[y]) 
		{
			p[y] = x; 
			ssi[x] +=ssi[y];
		}
		else 
		{
			p[x] = y;
			ssi[y] += ssi[x];
			if (r[x] == r[y]) r[y]++;
		}
	}
}
int sizeOfSet(int i){return ssi[findSet(i)];}
ll num_in_set[100005] = {};
vector< set< ll > > xco(100005), yco(100005);
int main()
{
    she_told_me_dont_worry
    int n;
    cin>>n;
    int i;
    initialize(100000+1);
    FOR0(i, n)
    {
        int x, y;
        cin>>x>>y;
        xco[x].insert(y);
        yco[y].insert(x);
    }
    FOR(i, 1, 100001)
    {
        if(yco[i].size() > 1)
        {
            int j , si = yco[i].size();
            set< ll >::iterator it = yco[i].begin();
            ll first = *it;
            it++;
            while(it != yco[i].end())
            {
                unionSet(first, *it);
                it++;
            }
                
        }
    }
    FOR(i, 1, 100001)
        num_in_set[findSet(i)] += xco[i].size();
    FOR(i, 1, 100001)
    {
        int j, si = xco[i].size();
        set< ll> ::iterator it = xco[i].begin();
        while(it!=xco[i].end())
        {
            xco[findSet(i)].insert(*it);
            it++;
        }
    }
    ll ans = 0;
    FOR(i, 1, 100001)
    {
        if(findSet(i) != i) continue;
        if(xco[i].size() == 0) continue;
        ans += ((1LL*sizeOfSet(i)*xco[i].size()) - (1LL*num_in_set[i]));
    }
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 23296
Scanf.scanf "%d" (fun n ->
    let x = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x)) in 

    let extgcd x y =
        let rec eg r0 r1 a0 a1 b0 b1 =
            if r1 = 0 then a0 else
                let q1 = r0 / r1 in
                eg r1 (r0 mod r1) a1 (a0 - q1 * a1) b1 (b0 - q1 * b1)
        in
        eg x y 1 0 0 1
    in
    let inv x y = (* 1/x in mod y *)
        let c = extgcd x y in
        if c < 0 then c + y else c
    in
    let z = 1_000_000_000 + 7 in
    let ( -@) a b = (((a - b) mod z) + z) mod z in
    let ( +@) a b = (a + b) mod z in
    let ( *@) a b = (a * b) mod z in
    let ( /@) a b = a *@ inv b z in

    let fact n =
        let rec loop i acc =
            if i > n then acc else loop (i + 1) (acc *@ i)
        in
        loop 1 1
    in

    let f = fact (n - 1) in

    let rec loop i r acc =
        if i = n - 1 then acc +@ r *@ x.(i) else
            let d = f /@ (i + 1) in
            loop (i + 1) (r +@ d) (acc -@ d * x.(i))
    in
    loop 0 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 6668
/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

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

class DAlterAltar {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {
        int n;
        cin>>n;
        string s;
        cin>>s;
        int cnt=0;
        int l=0,r=n-1;
        while (l<r){
            if (l>=n || r<0) break;
            if (s[r]=='W'){
                r--;
            }
            if (s[l]=='R')l++;
            if (l>=n || r<0) break;
            if (s[l]=='W' && s[r]=='R'){
                cnt++;
                l++;
                r--;
            }
            if (l>=n || r<0) break;
        }
        cout<<cnt;
	}
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    DAlterAltar solver;
    solver.solve(in, out);
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		int n = Integer.parseInt(input.readLine( ));
		int i = 1;
		int sum = 0;
		while(sum < n){
			sum = sum + i;
			i++;
		}
		System.out.println(i-1);
	}

}


Measured memory_bytes: 23380
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
		
		if(a < b && b < c) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 17160
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9 + 7;


ll A, B, K;
string S;
bool flag;

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

	cin >> K >> A >> B;

	FOR(i, A, B + 1) {
		if (i%K == 0)flag = true;
	}
	if (flag)cout << "OK" << endl;
	else cout << "NG" << endl;



	return 0;
}


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

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

    int x, a, b;
    cin >> x >> a >> b;

    if (abs(x - a) < abs(x - b)) {
        cout << "A" << endl;
    } else {
        cout << "B" << endl;
    }
}


Measured memory_bytes: 256
//コンパイラ最適化用
#pragma GCC optimize("O3")
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

signed main(){
  long n;
  cin >> n;
  long a[n];
  long ans = 0, dai = 0;
  for(int i = 0; i < n; i++)  cin >> a[i];
  for(int i = 0; i + 1 < n; i++){
    //cout << dai + a[i]<< ',';
    if(a[i+1] < (a[i] + dai)){
      dai =  a[i] + dai - a[i+1];
      ans += dai;
      //cout << dai << endl;
    }else{
      dai = 0;
    }
  }
  cout <<  ans;
}



Measured memory_bytes: 5184