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

#define rep(i, N) for (int i = 0; i < N; i++)
const int intinf = numeric_limits<int>::max();

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main()
{
    int N;
    cin >> N;
    vector<int> S(1 << N);
    rep(i, 1 << N) cin >> S[i];

    multiset<int, greater<int>> ms_prenatal;
    rep(i, 1 << N) ms_prenatal.insert(S[i]);
    multiset<int> ms_alive;

    int M = *max_element(S.begin(), S.end());
    ms_prenatal.erase(ms_prenatal.find(M));
    ms_alive.insert(M);
    bool is_ok = true;
    rep(n, N)
    {
        for (int s : ms_alive)
        {
            auto it = ms_prenatal.upper_bound(s);
            if (it != ms_prenatal.end())
            {
                ms_alive.insert(*it);
                ms_prenatal.erase(it);
            }
            else
            {
                is_ok = false;
                break;
            }
        }
        if (!is_ok)
            break;
    }

    cout << (is_ok ? "Yes" : "No") << endl;
}


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

int main() {
	char c;
  	cin >> c;
  	if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    	cout << "vowel" << endl;
    }else{
    	cout << "consonant" << endl;
    }
}


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

int main()
{
	int n,r;
	cin>>n>>r;
	int ans = 0;
	if(n<10)
	{
		ans = r + 100 * (10-n);
	}
	else
		ans = r;
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;

#define REP(A, H) for(int A = 0; A < H; A++)

int main(void) {
    ll n;
    std::vector<ll> as(5);
    std::cin >> n;    

    REP(i, 5) std::cin >> as[i];

    ll q = n / *std::min_element(as.begin(), as.end());
    ll r = n %  *std::min_element(as.begin(), as.end());
    ll res = q + (r == 0 ? 0 : 1) + 4;

    std::cout << res << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int c;
  int d;
  for(int i = 0 ; i< S.size() ; i++){
    if(S.at(i) == 'A'){
      c = i;
      break;
    }
  }
   for(int i = S.size()-1 ; i> 0 ; i--){
     if(S.at(i) == 'Z'){
      d = i;
      break;
    }
  }
  cout << d-c+1 << endl;
 
}
   

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**6)

def dfs(v, graph):
    if visited[v]:
        if not calculated[v]: #visited and not calculated == loop
            return -1 
        return depth[v]
    visited[v] = True
    for e in graph[v]: # すべての辺をなめる
        res = dfs(e, graph) # 再帰
        if res == -1: 
            return -1 # ループを見つけたら-1を返す
        
        depth[v] = max(depth[v], res+1) #より深い経路を発見したか？
    calculated[v] = True 
    return depth[v]


if __name__ == '__main__':
    N = int(input())
    Ng = N*(N-1)//2
    graph = [[] for _ in range(Ng)]
    G_id = [[-1]*N for _ in range(N)]
    
    game_id = 0
    for i in range(N):
        row = list(map(int, input().split()))
        for d, r in enumerate(row):
            if G_id[i][r-1] == -1: #新しい試合の組み合わせ
                G_id[i][r-1] = game_id 
                G_id[r-1][i] = game_id
                
                if d != 0: # 行が更新されているかのチェック
                    graph[before].append(game_id)
                
                before = game_id # idの更新・一つ記録
                game_id += 1
            else: # 既存の組み合わせ
                if d != 0: # 行が更新されているかのチェック
                    graph[before].append(G_id[i][r-1])
                before = G_id[i][r-1] #現在の試合を記録
    
    depth = [1]*Ng # 頂点から出発したときの最長経路
    visited = [False]*Ng
    calculated = [False]*Ng
    flag = True
    ans = 1
    for i in range(Ng):
        res = dfs(i, graph)
        if res == -1:
            flag = False
        else:
            ans = max(ans, res)
    if flag:
        print(ans)
    else:
        print(-1)
    
    

Measured memory_bytes: 164480
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	vector<vector<int>>G(N, vector<int>(N, INF));
	rep(i, 0, N)G[i][i] = 0;
	vector<int> a(M), b(M), c(M); rep(i, 0, M) { cin >> a[i] >> b[i] >> c[i]; }
	rep(i, 0, M) {
		a[i]--, b[i]--;
		G[a[i]][b[i]] = G[b[i]][a[i]] = c[i];
	}
	rep(k, 0, N)rep(i, 0, N)rep(j, 0, N)
		chmin(G[i][j], G[i][k] + G[k][j]);

	int ans = M;
	rep(i, 0, M) {
		rep(j, 0, N)if (G[j][a[i]] + c[i] == G[j][b[i]]) {
			ans--; break;
		}
		dump(ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [-1]
a.extend(list(map(int, input().split())))
cnt = 0
ansID = []
ans = [-1]*(n+1)

for i in reversed(range(1, len(a))):
  tmp = a[i]
  j = i*2
  while j < len(ans):
    tmp += ans[j]
    j += i
  ans[i] = tmp%2
  cnt += tmp%2
  if tmp%2 == 1:
    ansID.append(i)
  
print(cnt)
for ans in ansID:
  print(ans, end=" ")


Measured memory_bytes: 16700
object Main extends App {
  def removeSignZero(z: Double) = if (math.abs(z) == 0) 0 else z
  Stream
    .continually(readLine)
    .takeWhile(_ != null)
    .map(_.split(" ").map(_.toInt))
    .map {
      case Array(a, b, c, d, e, f) =>
        val det = (a * e - b * d).toDouble
        Seq((c * e - b * f) / det, (a * f - c * d) / det).map(removeSignZero).map(d => f"$d%.3f").mkString(" ")
    }
    .foreach(println)
}



Measured memory_bytes: 44352
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int h,w;cin>>h>>w;
  vs s(h);
  rep(i,h)cin>>s[i];
  rep(i,h){
    rep(j,w){
      char now=s[i][j];
      if(now=='#')continue;
      int cnt=0;
      for(int ki=-1;ki<=1;ki++){
        if(ki+i<0||ki+i>=h)continue;
        for(int kj=-1;kj<=1;kj++){
          if(kj+j<0||kj+j>=w)continue;
          if(s[ki+i][kj+j]=='#')cnt++;
        }
      }
      s[i][j]='0'+cnt;
    }
  }
  rep(i,h)cout(s[i]);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define NIL -1
#define MAX 100005

typedef struct{
  int p,l,r;
}Node;

int getDepth(int,Node *);
void print(int ,Node *);

int D[MAX];
  
int main(){
  Node *T;
  int n,i,j;
  int id,c,nm,l;

  scanf("%d",&n);
  T=(Node *)malloc(n*sizeof(Node));
  for(i=0;i<n;i++) T[i].p=T[i].l=T[i].r=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d",&id,&nm);
    for(j=0;j<nm;j++){
      scanf("%d",&c);
      if(j==0) T[id].l=c;
      else     T[l].r=c;
      l=c;
      T[c].p=id;
    }
  }
  print(n,T);
  
  return 0;
}

int getDepth(int u,Node *T){
  int d=0;
  while(T[u].p!=NIL){
    u=T[u].p;
    d++;
  }
  return d;
}

void print(int n,Node *T){
  int i,j,c;
  
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,getDepth(i,T));
    if(T[i].p==NIL)      printf("root,");
    else if(T[i].l==NIL) printf("leaf,");
    else                 printf("internal node,");
    j=i;
    printf(" [");
    for(j=0,c=T[i].l;c!=NIL;j++,c=T[c].r){
      if(j) printf(", ");
      printf("%d",c);
    }
	printf("]\n");
  }
}



Measured memory_bytes: 2880
#include<iostream>
using namespace std;
int main(){
  long int a,b;
  int x[200];
  int n = 0;
  while(cin >> a >> b){
    x[n] = 1;
    a = a + b;
    while(1){
      a = a/10;
      if(a >= 1)
        x[n]++;
      else
        break;
    }
    n++;
  }

  for(int i = 0; i < n; i++)
    cout << x[i] << '\n';

  return 0;
}

Measured memory_bytes: 1160
import std.stdio, std.algorithm, std.conv, std.array, std.string;

void main()
{
    auto len = readln.chomp.to!long;
    auto as = readln.split;

    string[] ret;
    ret.length = len;
    size_t p = len / 2;
    auto v = len & 1 ? 1 : -1;

    foreach (i, a; as) {
        v = -v;
        p += i * v;
        ret[p] = a;
    }

    writeln(ret.join(" "));
}

Measured memory_bytes: 16496
N,K = map(int,input().split())
plst = []
nlst = []
p = 0
z = 0
n = 0
for i in map(int,input().split()):
    if i > 0:
        p += 1
        plst.append(i)
    elif i == 0:
        z += 1
    else:
        n += 1
        nlst.append(i)
plst.sort()
nlst.sort()
zp = (p+n)*z + z*(z-1)//2
np = p*n
if K <= np:
    l = -10**18-1
    r = 0
    while l+1 < r:
        m = (l+r)//2
        total = 0
        idx = 0
        for i in range(p):
            while idx < n:
                if plst[i] * nlst[idx] < m:
                    idx += 1
                else:
                    total += idx
                    break
            else:
                total += idx
        if total < K:
            l = m
        else:
            r = m
    ans = l
elif K <= np+zp:
    ans = 0
else:
    l = 0
    r = 10**18+1
    while l+1 < r:
        m = (l+r)//2
        total = np+zp
        tmp = 0
        idx = 0
        for i in range(p)[::-1]:
            while idx < p:
                if plst[i] * plst[idx] < m:
                    idx += 1
                else:
                    tmp += idx
                    break
            else:
                tmp += idx
            if plst[i] * plst[i] < m: tmp -= 1
        tmp //= 2
        total += tmp
        tmp = 0
        idx = 0 
        for i in range(n):
            while idx < n:
                if nlst[i] * nlst[-idx-1] < m:
                    idx += 1
                else:
                    tmp += idx
                    break
            else:
                tmp += idx
            if nlst[i] * nlst[i] < m: tmp -= 1
        tmp //= 2
        total += tmp
        if total < K:
            l = m      
        else:
            r = m
    ans = l
print(ans)

Measured memory_bytes: 91268
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main ()
{
	int n;
multitest_loop:
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		auto g = new int [] [n];
		foreach (i; 0..n - 1)
		{
			int u, v;
			readf (" %s %s", &u, &v);
			u -= 1;
			v -= 1;
			g[u] ~= v;
			g[v] ~= u;
		}
		if (n == 2)
		{
			writeln (a[0] == a[1] ? "YES" : "NO");
			continue multitest_loop;
		}
		int r = 0;
		while (g[r].length == 1)
		{
			r += 1;
		}

		long recur (int v, int p)
		{
			if (g[v].length == 1)
			{
				return a[v];
			}
			long total = 0;
			long highest = 0;
			foreach (u; g[v])
			{
				if (u == p)
				{
					continue;
				}
				long cur = recur (u, v);
				if (cur == -1)
				{
					return -1;
				}
				total += cur;
				highest = max (highest, cur);
			}
			// res * 1 + loop * 2 = total
			// res * 1 + loop * 1 = a[v]
			long loop = total - a[v];
			if (loop < 0 || loop > total - highest)
			{
				return -1;
			}
			long res = a[v] - loop;
			if (res < 0)
			{
				return -1;
			}
			return res;
		}

		writeln (recur (r, -1) == 0 ? "YES" : "NO");
	}
}


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

int main() {
  int a,b,c,sum;
  cin>>a>>b;
  vector<int> vec(a);
  c=1000;
  for(int i=b;i<b+a;i++){
  	sum += i;
    if(abs(c)>abs(i))
      c = i;
  }

  sum -= c;
  cout<<sum<<endl;
  return 0;
}
  

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n, m;
  cin >> n;
  int t[n];
  for(int i=0; i<n; i++){
    cin >> t[i];
  }
  cin >> m;
  int p[m], x[m];
  for(int i=0; i<m; i++){
    cin >> p[i] >> x[i];
  }

  int total;
  int henka;
  
  for(int i=0; i<m; i++){
    henka = t[p[i]-1]-x[i];
    total = 0;
    for(int j=0; j<n; j++){
      total = total + t[j];
    }
    cout << total - henka << endl;
  }
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
fn main() {
    let mut n = read();
    println!("{}", n / 3);
}

fn read() -> u32 {
    let s = stdin();
    let b = s.bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    b.parse::<u32>().ok().unwrap()
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

ll f(ll n)
{
    if(n < 2) return 1;
    return n * f(n-2);
}

void solve()
{
    ll N; cin >> N;
    if(N % 2 == 1)
    {
        cout << 0 << endl;
        return;
    }

    ll ans = 0;
    if(N % 5 == 2 || N % 5 == 4) N = max(N / 5 * 5, (ll)0);

    while(N > 1)
    {
        ans += N / 10;
        N /= 5;
    }

    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = int64_t;

int main() {
  ll K;
  cin >> K;
  if(K%7==0) {
    K/=7;
  }
  if(K%2==0 || K%5==0) {
    cout << -1 << endl;
    return 0;
  }

  // Now just want to check if K fits in 1,11,111,...
  ll p10 = 1%K;
  ll rep = 1%K;
  for(ll a=1;; a++) {
    if(rep == 0) {
      cout << a << endl;
      return 0;
    }
    p10 = (p10*10)%K;
    rep = (rep+p10)%K;
  }
  cout << -1 << endl;

  // a*K = 7*(10^b-1)/9
  // 9*a*K = 7*(10^b-1)
  // a*K = 10^b-1
  // a*K+1 = 10^b
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

int main(){

    while(true){
        ll N;
        cin >> N;
        if(N == 0) break;
        set<ll> S;
        if(N == 1){
            cout << "deficient number" << endl;
            continue;
        }
        for(ll d=1;d*d<=N;d++){
            if(N % d == 0){
                if(d == 1){
                    S.insert(d);
                }else{
                    S.insert(d);
                    S.insert(N/d);
                }
            }
        }
        ll a = accumulate(all(S),0);
        if(N == a){
            cout << "perfect number" << endl;
        }else if(N > a){
            cout << "deficient number" << endl;
        }else{
            cout << "abundant number" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1192
/*/-----


    Written By:- Sajal Agrawal
          (Have Patience)

/*/
#include<bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ll long long int
#define f(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define rf(i,a,b) for(ll (i)=(a);(i)>=(b);(i)--)
#define mod 1000000007
#define fi first
#define se second
#define pa pair <ll,ll>
#define mp make_pair
#define c(t) cout<<t<<"\n"
#define pb push_back
#define ln '\n'
#define forstl(i,v) for(auto &i: v)
#define PRI(x) cerr<<#x<<'='<<x<<endl;
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define all(con) con.begin(),con.end()
#define sz(x) ((long long)x.size())
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>

void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

int main(){




ll n;
cin>>n;

ll a[n+1],b[n+1],c[n+1];
f(i,1,n+1){
    cin>>a[i];
    cin>>b[i];
    cin>>c[i];
}
ll dp[n+1][3];
f(i,0,n+1){
    dp[i][0]=0;
    dp[i][1]=0;
    dp[i][2]=0;
}


f(i,1,n+1){
    dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
 //b   cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
}
cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));


}





Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
struct Node
{
    using Ptr = shared_ptr<Node>;
    int value = 0;
    vector<Ptr> c;
};
using Ptr = Node::Ptr;

string S;
int pos;
int number()
{
    int ans = 0;
    for (; pos < S.size() and isdigit(S[pos]); pos++) { ans = ans * 10 + S[pos] - '0'; }
    return ans;
}
Ptr parse()
{
    Ptr p = make_shared<Node>();
    if (isdigit(S[pos])) {
        return p->value = number(), p;
    } else {
        pos++;
        while (S[pos] != ']') { p->c.push_back(parse()); }
        return pos++, p;
    }
}
int accum(const Ptr& p)
{
    if (p->c.empty()) {
        return (p->value + 1) / 2;
    }
    vector<int> sub;
    for (const auto c : p->c) { sub.push_back(accum(c)); }
    sort(sub.begin(), sub.end());
    const int n = (p->c.size() + 1) / 2;
    return p->value = accumulate(sub.begin(), sub.begin() + n, 0);
}
int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> S, pos = 0;
        const auto t = parse();
        cout << accum(t) << endl;
    }
    return 0;
}



Measured memory_bytes: 3540
N = int(input())
H_l = list(map(int, input().split()))

# 左から順に次の操作を行う。直前のマスより今いるマスが1以上高いならば今いるマスの高さを1下げる。直前のマスより低ければその時点で終了してNoを出力する
former_height = H_l[0]

for idx in range(1,N):
    if H_l[idx] - former_height >= 1:
        H_l[idx] -= 1
        former_height = H_l[idx]
    elif H_l[idx] - former_height < 0:
        print("No")
        exit()

print("Yes")

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<typename T=int>inline T get(){
   char c=getchar(); bool neg=(c=='-');
   T res=neg?0:c-'0'; while(isdigit(c=getchar()))res=res*10+(c-'0');
   return neg?-res:res;
}
template<typename T=int>inline void put(T x,char c='\n'){
   if(x<0)putchar('-'),x*=-1; int d[20],i=0;
   do{d[i++]=x%10;}while(x/=10); while(i--)putchar('0'+d[i]);
   putchar(c);
}
//end

typedef pair<int,int> P;
typedef pair<P,int> T;
int n,a[201000];
vector<int> g[201000],dp;
int res[201000]; stack<P> st;
void dfs(int v,int p){
   int idx=lower_bound(ALL(dp),a[v])-dp.begin();
   int val=dp[idx];
   dp[idx]=a[v]; st.push({idx,val});
   res[v]=lower_bound(ALL(dp),inf)-dp.begin();
   for(int t:g[v])if(t!=p){
      dfs(t,v);
   }
   P q=st.top(); st.pop();
   idx=q.first,val=q.second;
   dp[idx]=val;
}

int main(){
   n=get(); dp.resize(201000,inf);
   rep(i,0,n)a[i]=get();
   rep(_,0,n-1){
      int x=get()-1,y=get()-1;
      g[x].push_back(y); g[y].push_back(x);
   }
   dfs(0,-1);
   rep(i,0,n)put(res[i]);
   return 0;
}

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

int main()
{
    ll l,r,ans=2018;
    cin>>l>>r;
    r=min(r,l+4038);
    for(ll i=l;i<=r;i++){
        for(ll j=i+1;j<=r;j++){
            ans=min(ans,i*j%2019);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3592
#include<stdio.h>

#define MAX 100
#define INFTY 1000000000

int n, d[MAX], M[MAX+1][MAX+1], queue[MAX], head=0, tail=0;

int dequeue()
{
  int x;
  x = queue[head];
  if( head + 1 == MAX + 1 ) head = 0;
  else head++;

  return x;
}

void enqueue( int x )
{
  queue[tail] = x;
  if( tail + 1 == MAX + 1) tail = 0;
  else tail++;
}

int empty()
{
  if( head == tail ) return 1;
  else return 0;
}

void dfs( int s )
{
  int i, u, v;

  enqueue(s);

  for( i=0; i<n; i++ )
    {
      d[i] = INFTY;
    }

  d[s] = 0;

  while( empty() != 1 )
    {
      u = dequeue();

      for( v=0; v<n; v++ )
	{
	  if( M[u][v] == 0 ) continue;
	  if( d[v] != INFTY ) continue;
	  d[v] = d[u] + 1;
	  enqueue(v);
	}
    }

  for( i=0; i<n; i++ )
    {
      printf("%d ", i+1);
      if( d[i] == INFTY )
	{
	printf("-1\n");
	continue;
      }
      printf("%d\n", d[i]);
    }

}

int main()
{
  int i, j, u, k, v;

  scanf("%d", &n);

  for( i=0; i<n; i++ )
    {
      for( j=0; j<n; j++ )
	{
	  M[i][j] = 0;
	}
    }

  for( i=0; i<n; i++ )
    {
      scanf("%d%d", &u, &k);
      u--;

      for( j=0; j<k; j++ )
	{
	  scanf("%d", &v);
	  v--;
	  M[u][v] = 1;
	}
    }

  dfs(0);

  return 0;

}



Measured memory_bytes: 2056
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=2000005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int n,m,q,c=0;
vector <int> v[N];

void create(int x)
{
    int l=v[x].size();
    //cout<<x<<" yo "<<l<<"\n";
    /**if(l==n){cout<<x<<": ";
    for(int j=0;j<l;j++)
    cout<<v[x][j]<<" ";
    cout<<"\n";}**/
    if(l==n)
    return;
    if(l==0)
    {
        for(int i=1;i<=m;i++)
        {
            v[c].pb(i);
            create(c);
            c++;
        }
        return;
    }
    int b=v[x][l-1];
    v[x].pb(b);
    create(x);
    for(int i=b+1;i<=m;i++)
    {
        c++;
        for(int j=0;j<l;j++)
        v[c].pb(v[x][j]);
        v[c].pb(i);
        create(c);
    }
    return;
}
int32_t main()
{
    IOS;
    cin>>n>>m>>q;
    int ans=0;
    int a[q],b[q],c[q],d[q];
    create(0);
    for(int i=0;i<q;i++)
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    for(int i=0;i<N;i++)
    {
        if(v[i].size()!=n)
        break;
        int temp=0;
        for(int j=0;j<q;j++)
        {
            if(v[i][b[j]-1]-v[i][a[j]-1]==c[j])
            temp+=d[j];
        }
        ans=max(temp, ans);
    }
    cout<<ans;
}

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

typedef unsigned long long ll;
typedef std::pair<int, int> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define All(i, x) for(typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define ReAll(i, x) for(typeof(x.end()) i = x.end(); i != x.begin(); i--)
#define pb push_back

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MAX = 100000;
const int INF = 1e9;
const int MOD = 1000000007;
const string END = "\n";

void solve(){
	int n; cin >> n;
	int x[n], y[n], h[n];
	Rep(i, n){
		cin >> x[i] >> y[i] >> h[i];
	}
	if(h[0] == 0){
		Rep(i, n-1){
			swap(x[0], x[i+1]);
			swap(y[0], y[i+1]);
			swap(h[0], h[i+1]);
			if(h[0] != 0) break;
		}
	}
	int X = 0, Y = 0, H = 1;
	bool flag = true;
	Rep(i, 101){
		Rep(j, 101){
			flag = true;
			bool first = true;
			int t = 0;
			For(k, 0, n){
				int tmp = h[k] + abs(i - x[k]) + abs(j - y[k]);
                if(first){
                    t = tmp; first = false;
                }else{
                    if(h[k] == 0){
                        if(t > tmp){
        					flag = false;
        					break;
                        }
    				}else if(t != tmp){
    					flag = false;
    					break;
    				}
                }
			}
			if(flag){
				X = i; Y = j; H = t;
				break;
			}
		}
		if(flag) break;
	}
	cout << X << " " << Y << " " << H << END;
}

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


Measured memory_bytes: 256
// finish date: 2018/01/21
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(),t.end());
    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	if(s == "ABC") puts("ARC");
	else puts("ABC");
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
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); }

int main() {
    int n; cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    FOR(i, 1, n) a[i] += a[i-1];
    ll ans = 1LL << 62;
    rep(i, n-1) {
        ll x = a[i];
        ll y = a.back() - a[i];
        chmin(ans, abs(x - y));
    }
    cout << ans << endl;
    return 0;
}


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

using LL = long long;

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

    LL N;

    cin >> N;
    LL res = 0;
    vector<LL> s(N);
    for (int i = 0; i < N; i++){
        cin >> s[i];
        res += s[i];
    }

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

    int i = 0;
    while(res % 10 == 0 && i < N){
        if(s[i] % 10 != 0){
            res -= s[i];
        }
        i++;
    }

    if(res % 10 == 0){
        cout << 0 << endl;
    }else{
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def main():
    S = list( map( int, list( input())))
    N = len(S)
    dp = [[0,0] for _ in range(N+1)]
    dp[0][1] = 2
    for i in range(N):
        s = S[i]
        dp[i+1][0] = min(dp[i][0] + s, dp[i][1]+s)
        dp[i+1][1] = min(dp[i][0] + 11-s, dp[i][1]+9-s)
        # dp[i+1][2] = min(dp[i][1], dp[i][2])+9-s
        # 11-sは、追加で支払うものと、お釣り
        # 9-sは、追加はすでに支払われていて、繰り下がりが起こっている
    print( min(dp[N][0], dp[N][1]))
if __name__ == '__main__':
    main()


Measured memory_bytes: 178240
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr __int128 MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr __int128 MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

inline __int128 mod(__int128 a, __int128 m) {
	return (a % m + m) % m;
}

// 拡張 Euclid の互除法
// ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします
__int128 extGcd(__int128 a, __int128 b, __int128 &p, __int128 &q) {
	if (b == 0) { p = 1; q = 0; return a; }
	__int128 d = extGcd(b, a%b, q, p);
	q -= a / b * p;
	return d;
}

// 中国剰余定理
// リターン値を (r, m) とすると解は x ≡ r (mod. m)
// 解なしの場合は (0, -1) をリターン
pair<__int128 ,__int128> ChineseRem(__int128 b1, __int128 m1, __int128 b2, __int128 m2) {
	__int128 p, q;
	__int128 d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
	if ((b2 - b1) % d != 0) return make_pair(0, -1);
	__int128 m = m1 * (m2 / d); // lcm of (m1, m2)
	__int128 tmp = (b2 - b1) / d * p % (m2 / d);
	__int128 r = mod(b1 + m1 * tmp, m);
	return make_pair(r, m);
}

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

	cin >> N;
	__int128 ans = N * 2;
	for (__int128 i = 1; i*(i * 1) / 2 <= N; i++) {
		if (i*(i + 1) / 2 % N == 0)ans = min(ans, i);
		if (2 * N%i == 0) {
			__int128 box = 2 * N / i;
			auto bag = ChineseRem(0, i, box-1, box);
			if(bag.first)ans = min(ans, bag.first);
			bag = ChineseRem(0, box, i - 1, i);
			if (bag.first)ans = min(ans, bag.first);
		}
	}
	long long int ret = ans;
	cout << ret << endl;
}

Measured memory_bytes: 3656
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	raw = input.split("\n")[1].split(' ');
    count = raw.reduce((acc, cur)=>{
            if(!acc[cur]){
                acc[cur] = 1;
            } else {
                acc[cur] ++;
            }
            return acc;
        },[]);
    sum = count.reduce((acc,cur)=>{
            return acc+(cur*(cur-1)/2);
        },0);
    raw.forEach(x=>{
        console.log(sum-(count[x]-1));
    });
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 44540
# coding: utf-8
# Your code here!

while True:
    n = int(input())
    if n == 0:
        break
    y = int(input())
    b = -1
    maxMoney = -1
    ans = -1
    for l in range(n):
        b,r,t = [float(i) for i in input().split()]
        money = -1
        if t == 1:
            money = 1.0 + y * r / 100.0
        else:
            money = (1.0 + (r / 100.0))**y
        if maxMoney < money:
            maxMoney = money
            ans = int(b)
        #print(money)
            
    print(ans)
            
            


Measured memory_bytes: 5708
#include<bits/stdc++.h>
using namespace std;
long long  n, k, ans, flag;
int main() {
	scanf("%lld%lld",&n, &k);
	long long MAX = n * 7 ;
	for(long long i = 8; i <= MAX ; i++) {
        if(i % 7 != 0 && i % 7 != 1 && (i * 9) % 11 == k ) {
            	 ans ++, flag = i;
                 break;
            }   
    }
	MAX -= flag + 7;
	ans = (MAX / 77) * 5;
	int yu = MAX % 77;
	flag %= 7;
	if(flag == 2) {
		if(yu >=  0 && yu < 11) ans += 0;
		if(yu >= 11 && yu < 22) ans += 1;
		if(yu >= 22 && yu < 33) ans += 2;
		if(yu >= 33 && yu < 44) ans += 2;
		if(yu >= 44 && yu < 55) ans += 3;
		if(yu >= 55 && yu < 66) ans += 3;
		if(yu >= 66 && yu < 77) ans += 4;
	}
	if(flag == 3) {
		if(yu >=  0 && yu < 11) ans += 0;
		if(yu >= 11 && yu < 22) ans += 0;
		if(yu >= 22 && yu < 33) ans += 1;
		if(yu >= 33 && yu < 44) ans += 1;
		if(yu >= 44 && yu < 55) ans += 2;
		if(yu >= 55 && yu < 66) ans += 3;
		if(yu >= 66 && yu < 77) ans += 4;
	}
	if(flag == 4) {
		if(yu >=  0 && yu < 11) ans += 0;
		if(yu >= 11 && yu < 22) ans += 0;
		if(yu >= 22 && yu < 33) ans += 1;
		if(yu >= 33 && yu < 44) ans += 2;
		if(yu >= 44 && yu < 55) ans += 3;
		if(yu >= 55 && yu < 66) ans += 4;
		if(yu >= 66 && yu < 77) ans += 4;
	}
	if(flag == 5) {
		if(yu >=  0 && yu < 11) ans += 0;
		if(yu >= 11 && yu < 22) ans += 1;
		if(yu >= 22 && yu < 33) ans += 2;
		if(yu >= 33 && yu < 44) ans += 3;
		if(yu >= 44 && yu < 55) ans += 3;
		if(yu >= 55 && yu < 66) ans += 4;
		if(yu >= 66 && yu < 77) ans += 4;
	}
	if(flag == 6) {
		if(yu >=  0 && yu < 11) ans += 0;
		if(yu >= 11 && yu < 22) ans += 1;
		if(yu >= 22 && yu < 33) ans += 1;
		if(yu >= 33 && yu < 44) ans += 2;
		if(yu >= 44 && yu < 55) ans += 2;
		if(yu >= 55 && yu < 66) ans += 3;
		if(yu >= 66 && yu < 77) ans += 4;
	}
	
	printf("%lld\n",ans + 1);
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    
    int n;
    
    cin >> n;
    
    int i,a[n+1];
    
    for(i=0;i<n;++i) cin >> a[i];
    
    int ans=0;
    bool hoge=false;
    while(true){
        
        for(i=0;i<n;++i){
            if(a[i]%2==1){
                hoge=true;
                break;
            }
        }
        
        for(i=0;i<n;++i){
            a[i]/=2;
        }
        
        if(hoge)break;
        ans++;
    }
    cout << ans;
    
    
    return 0;
}

Measured memory_bytes: 256
A,B,C,D,E,F = map(int,input().split())
m_d = 0
m_t = 100*A
m_s = 0
for a in range(F//100*A+1):
  for b in range((F-100*A*a)//(100*B)+1):
    for c in range((F-A*a*100-B*b*100)//C+1):
      d = 0
      while (100*A*a+100*B*b) > 0 and 100*A*a+100*B*b+C*c+D*d <= F and (C*c+D*d)/(100*A*a+100*B*b) <= E/100:
        dens = (C*c+D*d)/(100*A*a+100*B*b)
        if dens == E/100:
          print(100*A*a+100*B*b+C*c+D*d,C*c+D*d)
          exit()
        elif m_d < dens:
          m_d = dens
          m_t = 100*A*a+100*B*b+C*c+D*d
          m_s = C*c+D*d
        d += 1
print(m_t,m_s)



Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <deque>
#include <queue>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#define INF 10000000000
#define MOD 1000000007
using namespace std;
using ll = long long;
int main() {
    int n,k;
    cin >> n >> k;
    int ans = 0;
    for(int i=1;i<=n;i+=2 ){
        ans++;
    }
    if(ans>=k){
        cout << "YES" <<endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    for(int i=K; i<N; i++) {
        if(A[i] > A[i-K]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4048
function main(lines) {
    const input = lines.split(' ').map(Number)
    const A = input[0]
    const B = input[1]
    const order = input[2]
    
    var divisorA = []
    var divisorB = []
    for(var i=1; i<=A; i++){
        if(A%i === 0){
            divisorA.push(i)
        }
    }
        
    for(var i=1; i<=B; i++){
        if(B%i === 0){
            divisorB.push(i)
        }
    }
 

    var divisorAB = []
    for(var i=0; i<Math.max(divisorA.length,divisorB.length); i++){
      for(var k=0; k<Math.max(divisorA.length,divisorB.length); k++){
        if( divisorA[i] === divisorB[k]){
          divisorAB.push(divisorA[i])
          break;
        }
      }
    }
    
    console.log(divisorAB[divisorAB.length-(order)])
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
from math import factorial
MOD=10**9+7
#======================================================#
def main():
    s = II()
    dp = [0]*(s+1)
    dp[0] = 1
    for i in range(3, s+1):
        sumv = (sum(dp[0:i-2]))%MOD
        dp[i] = sumv
    print((dp[s])%MOD)




if __name__ == '__main__':
    main()

Measured memory_bytes: 9228
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt
  val bs = Array.fill(m)((sc.nextInt - 1, sc.nextInt - 1)).reverse
  val uf = new UnionFind(n)

  val result = bs.scanLeft(n.toLong * (n - 1) / 2){(z, b) =>
    if (uf.find(b._1) != uf.find(b._2)) {
      val inconvenience = uf.size(b._1).toLong * uf.size(b._2)
      uf.union(b._1, b._2)
      z - inconvenience
    } else z
  }.reverse.tail

  println(result.mkString("\n"))
}

class UnionFind(nodes: Int) {
  val parents = Array.tabulate(nodes)(identity)
  val sizes = Array.fill(nodes)(1)

  // @scala.annotation.tailrec
  /** @retrun (root, rank) */
  def findWithRank(x: Int, rank: Int = 0): (Int, Int) = {
    parents(x) match {
      case p if x == p => (p, rank)
      case p => {
        val (newRoot, newRank) = findWithRank(p, rank + 1)
        parents(x) = newRoot
        (newRoot, newRank)
      }
    }
  }

  def find(x: Int): Int = {
    parents(x) match {
      case p if x == p => p
      case p => {
        val newRoot = find(p)
        parents(x) = newRoot
        newRoot
      }
    }
  }

  def size(x: Int) = sizes(find(x))

  def union(x: Int, y: Int): Int = {
    val (xRoot, xRank) = findWithRank(x)
    val (yRoot, yRank) = findWithRank(y)
    val newRoot = if (xRank < yRank) yRoot else xRoot
    if (xRoot != yRoot) {
      parents(xRoot) = newRoot
      parents(yRoot) = newRoot
      sizes(newRoot) = sizes(xRoot) + sizes(yRoot)
    }
    parents(x) = newRoot
    parents(y) = newRoot
    newRoot
  }
}

Measured memory_bytes: 90596
const val THRESHOLD = 60

fun main(args: Array<String>){
    val input: Int = readLine()?.toInt() ?: return
    val hr  = translateToHr(input)
    val sec = translateToSec(input)
    val min = (input - (hr * THRESHOLD * THRESHOLD)) / THRESHOLD
    println("$hr:$min:$sec")
}

fun translateToHr(seconds: Int): Int  = seconds / (THRESHOLD * THRESHOLD)
fun translateToSec(seconds: Int): Int = seconds % THRESHOLD


Measured memory_bytes: 27244
n,w=map(int,input().split())
dp=[0]*(w+1)
for i in range(w+1):
	dp[i]=[0]*(n+1)
wt=[0]*n
val=[0]*n
for i in range(n):
	wt[i],val[i]=map(int,input().split())
for i in range(1,w+1):
	for j in range(1,n+1):
		if i-wt[j-1]>=0:
			# print(i,j)
			dp[i][j]=max(val[j-1]+dp[i-wt[j-1]][j-1],dp[i][j-1])
		else:
			dp[i][j]=dp[i][j-1]
print(dp[w][n])
# for i in range(w+1):
# 	print(dp[i])


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

#define rep(x,n) for(int x=0;x<n;x++)

int solve(int a, int b, int c){
	rep(i,60){
		if(c%(a+b)<=a)return c;
		c+=60;
	}
	return -1;
}

int main(){
	
	for(int a,b,c;cin>>a>>b>>c;)cout<<solve(a,b,c)<<endl;
	
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    for (int i = 0; i <= n; i++) cin >> a[i];
    vector<int> b(n);
    for (int i = 0; i < n; i++) cin >> b[i];
    long long ans = 0;
    for (int i = 0; i < n; i++){
        if (a[i] >= b[i]) ans += b[i];
        else {
            b[i] -= a[i];
            ans += a[i];
            if (a[i+1] >= b[i]){
                a[i+1] -= b[i];
                ans += b[i];
            }
            else {
                ans += a[i+1];
                a[i+1] = 0;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
n,k = map(int,input().split())
prr = list(map(int,input().split()))

if n>1:
    m = sum(prr[:k])
    cur = m
    for i in range(n-k):
        cur += -prr[i] + prr[k+i]
        m = max(m,cur)
else:
    m = prr[0]

print((m+k)/2.0)

Measured memory_bytes: 25060
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
#define INF 1e9
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1000000007;
ll dp[100005][13] = {0};
int main(){
    string s;
    cin >> s;
    int n = s.length();
    dp[0][0] = 1;
    rep(i,n){
        int c;
        if (s[i] == '?') c = -1;
        else c = s[i] - '0';
        rep(j,10){
            if (c != -1 && c != j) continue;
            rep(k,13){
                dp[i+1][(10*k + j)%13] += dp[i][k];
            }
        }
        rep(j,13) dp[i+1][j] %= MOD;
    }
    PRINT(dp[n][5]);
    return 0;
}

Measured memory_bytes: 10624
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var NK = ReadSplitLong();
            var ans = ReadSplitLong()
                .OrderByDescending(x => x)
                .Skip((int)NK[1])
                .Sum();

            Println(ans);
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}



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

const ll INF = 1LL << 60;

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

    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    cout << max(a*c,max(a*d,max(b*c,b*d))) << endl;
}

Measured memory_bytes: 3656
#include<iostream>
#include <cstdio>
#include<cstring>
#include<string>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define LEN 100005
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) {if (x % y == 0) return y;else return LGCD(y, x % y);}
ll LLCM(ll x, ll y) {return x * y / LGCD(x, y);}

int GCD(int x, int y) {if (x % y == 0) return y;else return GCD(y, x % y);}
int LCM(int x, int y) {return x * y / GCD(x, y);}
ll dpc[10000][10000];
ll combination(ll n, ll r) {
         if (n == r){dpc[n][n] = 1;}
	else if (r == 0) {return dpc[n][0] = 1;}
	else if (r == 1) {return dpc[n][1]=n;}
	else {dpc[n][r]=dpc[n - 1][r - 1] % 1000000007 + dpc[n - 1][r] % 1000000007;
	return dpc[n][r]=combination(n - 1, r - 1) % 1000000007 + combination(n - 1, r) % 1000000007;}
}
ll Combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else {
		//dpc[n][r] = dpc[n - 1][r - 1] % 1000000007 + dpc[n - 1][r] % 1000000007;
		return dpc[n][r] = combination(n - 1, r - 1) % 1000000007 + combination(n - 1, r) % 1000000007;
	}
}

bool chsK(string s) {
	int n = s.length();
	if (n % 2 == 0) {
		for (int i = 0;i <= n / 2;i++) {
			if (s[i] != s[n - i-1])return false;
		}
	}
	else {
		for (int i = 0;i <= n / 2;i++) {
			if (s[i] != s[n - i-1])return false;
		}
	}
	return true;
}

int main() {
	string S, S1, S2;
	cin >> S;
	int n = S.length();
	S1 = S.substr(0, (n - 1) / 2);
	S2 = S.substr((n + 1) / 2, (n - 1) / 2);
	
	//cout << S1 << endl;
	//cout << S2 << endl;
	if (chsK(S)==1&&chsK(S1)==1&&chsK(S2)==1)cout<<"Yes"<<endl;
	else cout << "No"<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
al=list(map(int,input().split()))
t=[]
for i in range(n):
    t.append(al[i]-(i+1))
t=sorted(t)
if n%2==0:
    v=(t[n//2-1]+t[n//2])//2
else:
    v=t[n//2]
ans=0
for i in t:
    ans+=abs(i-v)
print(ans)

Measured memory_bytes: 101332