akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_b

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef ll _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1e9 + 7ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ll n,k;
    cin>>n>>k;
    vl a(n);
    REP(i,n) cin>>a[i];

    ll ans1 = 0;
    ll ans2 = 0;

    FORR(i,0,n){
        FORR(j,0,i){
            if(a[i] < a[j]) ans1++;
        }
    }

    FOR(i,0,n){
        FOR(j,0,n){
            if(a[i] < a[j]) ans2++;
        }
    }

    ans1 = ans1 * (k%MOD);
    ans2 = ans2 * ((k*(k-1)/2ll)%MOD);

    cout << (ans1+ans2)%MOD << endl;

    return 0;
}

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


signed main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int mx = 0;
  rep(i,n) mx = max(mx, a[i]);

  vector<int> c(mx+1);
  rep(i,n) {
    for(int j=1; j * a[i] <= mx; j++) {
      if(c[j*a[i]]>1) continue;
      c[j*a[i]]++;
    }
  }
  int ans = 0;
  rep(i,n) ans += (c[a[i]]==1);
  cout << ans << endl;
}


Measured memory_bytes: 7884
/*#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC target("avx2")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <random>
#include <deque>
#include <bitset>
#include <string>
#include <queue>
#include <complex>

//#define int long long

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

#define endl '\n'


using namespace std;
typedef long long ll;
typedef long double ld;

mt19937 mrand(random_device{}());

const double PI = acos((double)-1);
const double eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;

void solve();
void scan();

signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	cout << fixed; cout.precision(15);
	solve();
	return 0;
}

struct T {
	vector<int>  t, u;
	int n;
	T() {}
	T(int n) : n(n) {
		t.assign(4 * n,  0);
	}
	void upd(int v, int l, int r, int i, int d) {
		if (l > i || r <= i) return;
		if (r - l == 1) {
			t[v] = d;
			return;
		}
		upd(2 * v + 1, l, l + r >> 1, i, d);
		upd(2 * v + 2, l + r >> 1, r, i, d);
		t[v] = max(t[2 * v + 1], t[2 * v + 2]);
	}
	int get(int v, int l, int r, int vl, int vr) {
		if (vl >= r || l >= vr) return -1;
		if (vl <= l && r <= vr) {
			return t[v];
		}
		return max(get(2 * v + 1, l, l + r >> 1, vl, vr), get(2 * v + 2, l + r >> 1, r, vl, vr));
	}
};

T t;
const int N = 2e5 + 7;
vector<int> g[N];
int a[N];
int ans[N];

void dfs(int v, int last = -1) {
	ans[v] = t.get(0, 0, N, 0, a[v]) + 1;
	int x = t.get(0, 0, N, a[v], a[v] + 1);
	t.upd(0, 0, N, a[v], ans[v]);
	ans[v] = t.get(0, 0, N, 0, N);
	for (int u : g[v]) {
		if (u == last) continue;
		dfs(u, v);
	}
	t.upd(0, 0, N, a[v], x);
}

void solve() {
	int n; cin >> n;
	t = T(N);
	vector<int> kek(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	map<int, int> jopa;
	for (int i = 0; i < n; i++) {
		kek[i] = a[i];
	}
	sort(all(kek));
	kek.erase(unique(all(kek)), kek.end());
	for (int i = 0; i < kek.size(); i++)
		jopa[kek[i]] = i + 1;
	for (int i = 0; i < n; i++) {
		a[i] = jopa[a[i]];
	}
	for (int i = 1; i < n; i++) {
		int u, v; cin >> u >> v; u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0);	
	for (int i = 0; i < n; i++)
		cout << ans[i] << endl;
	return;
}

Measured memory_bytes: 38552
def add_memo(tate,yoko):
    global memo
    if 2 <= tate <= h-1:
        if 2 <= yoko <= w-1:
            memo.append([tate,yoko])

h,w,n = map(int,input().split())
#print(s)
memo = []
for i in range(0,n):
    x,y = map(int,input().split())
    add_memo(x-1,y-1)
    add_memo(x-1,y)
    add_memo(x-1,y+1)
    add_memo(x,y-1)
    add_memo(x,y)
    add_memo(x,y+1)
    add_memo(x+1,y-1)
    add_memo(x+1,y)
    add_memo(x+1,y+1)

memo.sort()
ans = [0] * 10
ans[0] = (h-2)*(w-2)
tmp_x = 0
tmp_y = 0
count = 0
for i in range(0,len(memo)):
    if tmp_x == memo[i][0] and tmp_y == memo[i][1]:
        ans[count] -= 1
        count += 1
        ans[count] += 1
    else:
        ans[0] -= 1
        count = 1
        ans[count] += 1
    tmp_x = memo[i][0]
    tmp_y = memo[i][1]
#    print(memo[i],count)

for i in range(0,10):
    print(ans[i])


Measured memory_bytes: 135604
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var w = Console.ReadLine().Split().Select(int.Parse).ToArray();
		Console.WriteLine(Enumerable.Range(1, n - 1).Min(i => Math.Abs(w.Take(i).Sum() - w.Skip(i).Sum())));
	}
}


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

const int SIZE = 1e5 + 5;

int N;
int M;
int required_days;
int reward;
vector<int> job_list[SIZE];

int main() {
  scanf("%d%d", &N, &M);

  for (int i = 0; i < N; i++) {
    scanf("%d%d", &required_days, &reward);
    if (M - required_days >= 0) {
      // 0-M日後の期限内に実行できる仕事であれば候補とする
      // 添字が 0     -> 初日にのみ行える仕事
      // 添字が M - 1 -> 期限の一日前に行っても良い仕事
        job_list[M - required_days].push_back(reward);
    }
  }

  priority_queue<int> pq;

  long long ans = 0;
  for (int i = M - 1; i >= 0; i--) {
    // 期日の後ろから仕事を決定していく
    for (int j = 0; j < job_list[i].size(); j++) {
      // 優先順位付きキューにより報酬の降順に、実行可能な仕事を追加する
      pq.push(job_list[i].at(j));
    }

	if(pq.size()){
      // 実行可能な仕事のうち、最も報酬の高い仕事を取りだす
	  ans += pq.top();
	  pq.pop();
	}
  }
  
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 5632
#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 Sq(x) (x)*(x)
#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 Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#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;

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}

int main(){
    Cin(string, s);
    string t = "";
    int n = (int)s.size();
    for(int i = 0; i < n; i ++){
        if(s[i] == 'A') t += 'A';
        else{
            if(i == n-1) break;
            if(s[i] == 'B' && s[i+1] == 'C'){
                t += 'O';
                i ++;
            }
            else t += 'X';
        }
    }
    // Cout(t);
    auto v = split(t, 'X');

    ll ans = 0;
    for(const string &s : v){
        // Cout(s);
        ll k = 0;
        for(int i = 0; i < (int)s.size(); i ++){
            if(s[i] == 'O'){
                ans += i-k;
                k ++;
            }
        }
    }
    Cout(ans);
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    string s;cin>>s;
    int res;
    for(int i=1;2*i < s.size();i++){
        if (s.substr(0,i)==s.substr(i,i)){
            res = 2 * s.substr(0,i).size();
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=85;
//↑templete
signed main(){
	ll A, B, K;
	cin>>A>>B>>K;
	ll temp=min(A, K);
	A-=temp;
	K-=temp;
	B-=min(B, K);
	cout<<A<<" "<<B<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>//accumulate(v.begin(), v.end(), 0);
#include <algorithm>//sort(v.begin(),v.end());
#include <string>//
#include <cmath>
#include <iomanip> //setprecision(2)
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
        
        int a,b;
        cin >> a >> b;
        int x = a+b;
        if(x%2==0){  
        cout << x/2 << endl;
        }else{
          cout << x/2+1 << endl;
        }

        return 0;
}


Measured memory_bytes: 256
# n = 3, m = 2, l = 3
#     1 3
# a = 2 2
#     3 1

#     1 3 5
# b = 2 4 6

#         c00 ... c02
# a * b =
#         c20 ... c22

#       2
# c22 = Σ a2kbk2
#     k = 1
#     = a21b12 + a22b22
#     = (2 * 3) + (2 * 4)
#     = 14

require 'matrix'

n, m, l = gets.split.map(&:to_i)
ary1 = []
ary2 = []

n.times do
  ary1 << gets.split.map(&:to_i)
end

m.times do
  ary2 << gets.split.map(&:to_i)
end

ma = Matrix[*ary1]
mb = Matrix.rows(ary2)
mc = ma * mb

mc.row_vectors.each{ |row| puts row.to_a.join("\s") }

Measured memory_bytes: 7440
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> vec;
    for(int i = 0;i < n;i++) {
        int x;
        cin >> x;
        vec.push_back(x);
    }
    int count = 1;
    for(int i = 0;i < n;i++) {
        if(vec[i] == count) count++;
    }
    if(count == 1) cout << -1 << endl;
    else cout << n-count+1 << endl;
}

Measured memory_bytes: 1400
#include <stdio.h>

int main(){
  int a,b,d,r;
  double f;
  scanf("%d %d",&a,&b);
  d = a/b;
  r = a%b;
  f = (double)a/(double)b;
  printf("%d %d %f\n",d,r,f);
  return 0;
}

Measured memory_bytes: 636
w =list(input())
ans = "Yes"
if len(w)%2 !=0:
    ans = "No"
else:
    w.sort()
    for i in range(len(w)//2):
        if w[2*(i-1)] == w[2*i-1]:
            continue
        else:
            ans ="No"
            break
        print
print(ans)

Measured memory_bytes: 2940
import std.stdio;
import std.conv;
import std.array;

void main()
{
    int[] T = new int[5];
    foreach (i; 0..5){
        T[i] = readln.split[0].to!int;
    }

    int ans = 0;
    int minMod = 0;
    foreach (t; T){
        if (t % 10 == 0){
            ans += t;
        } else {
            if (minMod == 0 || t % 10 < minMod){
                minMod = t % 10;
            }

            ans += (t / 10 + 1) * 10;
        }
    }

    if (minMod != 0){
        ans -= (10 - minMod);
    }

    writeln(ans);
}



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

int main(){
    cout<<fixed<<setprecision(12);
    while(1){
        int n;
        double s[1000];
        double sum=0;
        cin>>n;
        if(n==0){
            break;
        }
        for(int i=0;i<n;i++){
            cin>>s[i];
        }
        for(int i=0;i<n;i++){
            sum+=s[i];
        }
        double avg=sum/n;
        double ans=0;
        for(int i=0;i<n;i++){
            ans+=pow(s[i]-avg,2);
        }
        ans=sqrt(ans/n);
        cout<<ans<<endl;
    }
    return 0;
}


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

#include <math.h>
#include <stdlib.h>


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

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll N; cin >> N;

    ll a, b;
    for(ll i = 1; i*i <= N; i++){
        if(N%i == 0){
            a = i;
            b = N/i; 
        }
    }

    cout << a + b - 2 << endl;

    return 0;
}


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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    for (int i = 0; i < n; i++) cin >> m[i];

    int sum = 0;
    for (int i = 0; i < n; i++){
        sum += m[i];
    }
    int rest = x - sum;
    int res = 100000;
    for (int i = 0; i < n; i++){
        if (res > m[i]) res = m[i];
    }
    cout << rest / res + n << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <cmath>
#include <complex>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

using std::complex;
typedef complex<double> P;

const double EPS = 1e-9;

class Line{
public:
  P p; /* position */
  P d; /* direction */
  Line(){}
  Line(P pos, P dir){p=pos; d=dir/abs(dir);}
};

inline double outp(const P &a, const P &b){
  return (conj(a)*b).imag();
}

inline double inp(const P &a, const P &b){
  return (conj(a)*b).real();
}

inline double sign(double a){ return a > 0.0 ? 1 : 0; }

int main(){
  while(true){
    int n = getInt();
    int m = getInt();
    
    if(n + m == 0) break;

    vector<P> w(n);
    vector<P> b(m);

    REP(i,n){ w[i].real() = getInt(); w[i].imag() = getInt(); }
    REP(i,m){ b[i].real() = getInt(); b[i].imag() = getInt(); }

    bool ans = false;
    const P dang[2] = {
      P(cos(EPS), sin(EPS)),
      P(cos(EPS), -sin(EPS))
    };

    REP(i,n) REP(j,m){
      P mid = (w[i] + b[j]) / 2.0;
      P dir = b[j] - mid;

      REP(k,2){
	P dir2 = dir * dang[k];
	Line l = Line(mid, dir2);

	int expw = sign(outp(l.d, w[i] - l.p));
	int expb = sign(outp(l.d, b[j] - l.p));

	REP(ii,n) if(sign(outp(l.d, w[ii] - l.p)) != expw) goto next;
	REP(ii,m) if(sign(outp(l.d, b[ii] - l.p)) != expb) goto next;

	ans = true;
	goto fin;
      next:;
      }
    }
  fin:;
    puts(ans ? "YES" : "NO");
  }

  return 0;
}

Measured memory_bytes: 800
#include<stdio.h>
int main(void)
{
	int A,B;
	scanf("%d %d",&A,&B);
	if(A==1){
		A=14;
	}
	if(B==1){
		B=14;
	}
	if(A>B){
		printf("Alice\n");
	}
	else if(B>A){
		printf("Bob\n");
	}
	else{
		printf("Draw\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

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

Node *root, *NIL;   // 宣言時ポインタにはNULL(0x0)が入っているため, 木の根が設定されていなければroot == NILとなる.

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        }
        else {
            y->right = z;
        }
    }
}

Node * find(Node *u, int k) {
    while (u != NIL && k != u->key) {
        if (k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

void deleteNode(int k) {
    Node *x;
    Node *y;
    Node *z = find(root, k);
    if (z->left == NIL && z->right == NIL) {
        if (z->parent->left == z) z->parent->left = NIL;
        else z->parent->right = NIL;
        free(z);
    } else if (z->left != NIL && z->right == NIL) {
        if (z->parent->left == z) z->parent->left = z->left;
        else z->parent->right = z->left;
        z->left->parent = z->parent;
        free(z);
    } else if (z->left == NIL && z->right != NIL) {
        if (z->parent->left == z) z->parent->left = z->right;
        else z->parent->right = z->right;
        z->right->parent = z->parent;
        free(z);
    } else {
        y = z->right;
        while (y->left != NIL) y = y->left;
        x = y->right;
        z->key = y->key;
        if (y->parent->left == y) y->parent->left = x;
        else y->parent->right = x;
        
        if (x != NIL) x->parent = y->parent;
        free(y);
    }
}

void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        cin >> com;
        if (com == "insert") {
            scanf("%d", &x);
            insert(x);
        } else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } else if (com == "find") {
            scanf("%d", &x);
            Node *t = find(root, x);
            if (t != NIL) printf("yes\n");
            else printf("no\n");
        } else {
            scanf("%d", &x);
            deleteNode(x);
        }
    }

    return 0;
}


Measured memory_bytes: 22016
stc = input()

chars = {}

for char in stc:
    if char in chars:
        chars[char] += 1
    else:
        chars[char] = 1

if len(chars) == 2:
    for num in chars.values():
        if num != 2:
            print('No')
            exit()

    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
import java.util.*;
import java.io.*;
public class Main {
	
	static final int NONUM=-1;
	public static void main(String[] args)throws IOException{
		final Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		NODE[] n = new NODE[a];
	
		for(int i=0;i<n.length;i++){
			int id=sc.nextInt();
			n[id]=new NODE();
			n[id].id = id;
			n[id].l = sc.nextInt();
			n[id].r = sc.nextInt();
			n[id].p = -1;
			n[id].s = -1;
			n[id].d = 0;
			n[id].t = "leaf";
			if(n[id].l != -1){
				n[id].d++;
				n[id].t = "internal node";
			}
			if(n[id].r != -1){
				n[id].d++;
				n[id].t = "internal node";
			}
		}
	     for(int i=0; i<a; i++){
	    	 if(n[i].l != -1){
	                n[n[i].l].p = n[i].id;
	            }
	            if(n[i].r != -1){
	                n[n[i].r].p = n[i].id;
	            }
	            if(n[i].l != -1 && n[i].r != -1){
	                n[n[i].l].s = n[i].r;
	                n[n[i].r].s = n[i].l;
	            }
	     }
		
	        for(int i=0; i<a; i++){
	            if(n[i].p == -1){
	                n[i].t = "root";
	                if(n[i].l != -1){
	                    getdepth(n, n[i].l, 1);
	                }
	                if(n[i].r != -1){
	                    getdepth(n, n[i].r, 1);
	                }
	            }
	            if(n[i].d == 0){
	                if(n[i].p != -1){
	                    getheight(n, n[i].p, 1);
	                }
	            }
	        }
		
		for(int i=0;i<a;i++){
			System.out.println("node "+n[i].id+": parent = "+n[i].p+", sibling = "+n[i].s+", degree = "+n[i].d+", depth = "+n[i].dep+", height = "+n[i].h+ ", "+n[i].t);
		}
	}
	
	static void getdepth(NODE[] n,int i,int d){
	     n[i].dep = d;
	        d++;
	        if(n[i].l != -1){
	            getdepth(n, n[i].l, d);
	        }
	        if(n[i].r != -1){
	            getdepth(n, n[i].r, d);
	        }
	        
	}	
	
	static void getheight(NODE[] n,int i, int h){
        if(h < n[i].h) h = n[i].h;
        else           n[i].h = h;
        h++;
        if(n[i].p != -1){
            getheight(n, n[i].p, h);
        }
	}
}
	
class NODE{
	int id;
	int r;
	int l;
	int p;
	int d;
	int dep;
	int h;
	int s;
	String t; 
}

Measured memory_bytes: 18076
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


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

    int ans = count(s.begin(),s.end(),'R');

    if(ans == 2 && s[1] == 'S')ans-=1;
    cout << ans << endl;

}



Measured memory_bytes: 3624
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    res = []
    while n:
        n, r = divmod(n - 1, 26)
        res.append(chr(ord('a') + r))
    res.reverse()
    print(''.join(res))
resolve()

Measured memory_bytes: 61932
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<unordered_map>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>

using namespace std;
int gcd(int a, int b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
#define INF 99999999999 
#define pb push_back
#define mt make_tuple
#define ll long long
ll lncr(ll n, ll r)
{
	ll i, ans = 1, k = 0;
	if (r == 0)
		return 1;
	else if (n < r)
		return 0;
	for (i = n; i >= n - r + 1; i--)
	{
		ans *= i;
		ans /= n - i + 1;
	}


	return ans;

}
bool visited[6] = { false };
int n = 6;
vector<int> adj[6];


void max_heapify(int a[100], int i)
{
	int l, r, largest = i;
	l = 2 * i + 1;
	r = 2 * i + 2;
	if (l<n && a[l]>a[i])
		largest = l;
	if (r<n && a[r]>a[l])
		largest = r;
	if (largest != i)
	{
		int k;
		k = a[i];
		a[i] = a[largest];
		a[largest] = k;
		max_heapify(a, largest);
	}

}
int power(ll x, ll y, ll p)
{
	int res = 1;
	x = x % p;

	while (y > 0)
	{

		if (y & 1)
			//res = (res * x) % p;


		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

bool square(ll n)
{
	double x;
	x = sqrt(n);
	if (x == floor(x))
		return true;
	else return false;
}


bool prime(ll n)
{
	ll i;
	for (i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}
void dfs(ll a, ll b, vector<pair<ll, ll>>adj[][1001], bool visited[][1001])
{
	visited[a][b] = true;
	for (auto u : adj[a][b])
	{
		if (!visited[get<0>(u)][get<1>(u)])
		{
			visited[get<0>(u)][get<1>(u)] = true;
			dfs(get<0>(u), get<1>(u), adj, visited);
		}
	}
}
ll day(ll d, ll m, ll y)
{
	static int t[] = { 0, 3, 2, 5, 0, 3,
				   5, 1, 4, 6, 2, 4 };
	y -= m < 3;
	return (y + y / 4 - y / 100 +
		y / 400 + t[m - 1] + d) % 7;
}
bool leap(int year)
{
	if (year % 400 == 0)
		return true;
	if (year % 100 == 0)
		return false;
	if (year % 4 == 0)
		return true;
	return false;
}
int main()
{
	ll n, arr[100001][3],i, k, j;
	ll dp[100001][3];
	cin >> n;
	for (i = 1; i <= n; i++) {
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
	}
	dp[1][0] = arr[1][0];
	dp[1][1] = arr[1][1];
	dp[1][2] = arr[1][2];
	for (i = 2; i <= n; i++) {
		dp[i][0] = arr[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = arr[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = arr[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
		
	}
	sort(dp[n], dp[n] + 3);
	cout << dp[n][2];
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using VL = vector<ll>;
using VPL = vector<PL>;

VPL PF(ll num){
	VPL vpl;
	ll cnt;
	for(ll i=2;i*i<num;i++){
		if(num%i!=0){
			continue;
		}
		cnt=0;
		while(num%i==0){
			num/=i;
			cnt++;
		}
		vpl.push_back(PL(i,cnt));
	}
	if(num>1){
		vpl.push_back(PL(num,1));
	}
	return vpl;
} 
int main(void){
	VPL v;
	ll n;
	ll ans=0;
	cin>>n;
	v=PF(n);
	for(auto p:v){
		for(int i=1;i<=p.second;i++){
			ans++;
			p.second-=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}	

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
typedef long long ll;

ll MOD = 1000000007;
ll A[1048576];
ll C[1048576];
ll arr[1048576][2];
int zero_update[1048576];

ll power_mod(ll a,ll n){
	if(n == 0){
		return 1;
	}
	ll x = power_mod(a,n/2);
	x = x*x;
	x %= MOD;
	return (n%2 == 0 ? x : (a*x)%MOD);
}

int main(){
	int zero_cnt = 0;
	int U = 1048576;
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i];
		if(i == 0){
			C[i] = A[i];
		} else {
			C[i] = C[i-1] ^ A[i];
		}
	}
	for(int i=0;i<U;i++){
		arr[i][0] = 1;
	}
	
	for(int i=0;i<N;i++){
		int c = C[i];
		if(c == 0){
			zero_cnt++;
			continue;
		}
		ll n = zero_cnt - zero_update[c];
        zero_update[c] = zero_cnt;
		ll a = arr[c][0];
		ll b = arr[c][1];
		ll x = a + n*b;
		ll y = b;
		a = x;
		b = a+b;
		a %= MOD;
		b %= MOD;
		arr[c][0] = a;
		arr[c][1] = b;
	}
	ll answer = 0;
	ll final = C[N-1];
	if(final != 0){
		answer = arr[final][0];
	} else {
		answer = 0;
		for(int i=1;i<U;i++){
			answer += arr[i][1];
			answer %= MOD;
		}
		answer += power_mod(2,zero_cnt-1);
		answer %= MOD;
	}
	cout << answer << endl;
}


Measured memory_bytes: 28928
#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;
vector<vector<int>> arr(10);
bool C(int x,int y,int i){
  return y<arr[i][x];
}
int upper(int l,int r,int y,int i){//条件を満たす中で最小のものを返す
  int lb=l-1,ub=r;
  while(ub-lb>1){
    int mid=(lb+ub)/2;
    if(C(mid,y,i)) ub=mid;
    else lb=mid;
  }
  return ub;
}

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

  rep(i,10){
    arr[i].push_back(-1);
  }
  rep(i,n){
    int num=s[i]-'0';
    arr[num].push_back(i);
  }
  const int inf=1e+9;
  rep(i,10){
    arr[i].push_back(inf);
  }


  int cnt=0;
  rep(i,10){
    rep(j,10){
      rep(k,10){
	if(arr[i].size()==2||arr[j].size()==2||arr[k].size()==2) continue;
	int ii=upper(0,arr[i].size()-1,-1,i);
	if(arr[i][ii]==inf) continue;
	int jj=upper(0,arr[j].size()-1,arr[i][ii],j);
	if(arr[j][jj]==inf) continue;
	int kk=upper(0,arr[k].size()-1,arr[j][jj],k);
	if(arr[k][kk]!=inf){
	  cnt++;
	}
      }
    }
  }

  cout << cnt << "\n";
  
  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <vector>

using namespace std;

int main() {
    int n, ans = 0;
    scanf("%d", &n);
    vector<int> a(n), b(n + 1), c(n + 1);
    for (int i = 0; i < n; ++i) scanf("%d", &a.at(i));
    for (int i = 1; i <= n; ++i) scanf("%d", &b.at(i));
    for (int i = 1; i < n; ++i) scanf("%d", &c.at(i));
    for (int i = 0; i < n; ++i) ans += b.at(a.at(i));
    for (int i = 0; i < n - 1; ++i) if (a.at(i) + 1 == a.at(i + 1)) ans += c.at(a.at(i));
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> D(N);
  vector<vector<int>> A(K, vector<int>(101));
  for(int i = 0; i < N; i++) {
    cin >> D.at(i);
    for(int j = 0; j < D.at(i); j++) {
      cin >> A.at(i).at(j);
    }
  }
  vector<int> R(N);
  for(int i = 0; i < N; i++) {
    R.at(i) = i + 1;
  }
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < D.at(i); j++) {
      R.at(A.at(i).at(j) - 1) = 0;
    }
  }
  int count = 0;
  for(int i = 0; i < N; i++) {
    if(!(R.at(i) == 0)) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

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


int main() {
	int W, a, b;
	cin >> W >> a >> b;
	
	int bw = b + W;
	int aw = a + W;
	
	if (aw < b)
		cout << b - aw << endl;
	else if (a > bw)
		cout << a - bw << endl;
	else
		cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, K;
    cin >> N >> K;
    int sum = 0;

    vector<int> x(N);
    for (int i=0; i < N; i++) {
        cin >> x.at(i);
        if (x.at(i) <= K-x.at(i)) {
            sum += x.at(i)*2;
        }
        else if (x.at(i) > K-x.at(i)) {
            sum += (K-x.at(i))*2;
        }
    }

    cout << sum <<endl;
}

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

const int INF = 1000000;

int w, h;
int f, m, o;
vector<vector<int>> cell;

enum {Y, X};
const int NEXT[3][2] {{1, 0}, {0, -1}, {0, 1}};

vector<vector<vector<vector<int>>>> memo;

int dfs(int y, int x, int air, int used, int cost) {
    if(memo[y][x][air][used] <= cost) return INF;
    memo[y][x][air][used] = cost;
//     if(y == h) return cost;
//     if(air == 0) return INF;

//     cout<<""<<y<<","<<x<<"    air:"<<air<<"    cost:"<<cost<<""<<endl;

    int result = INF;
    for(const auto &d: NEXT) {
        int ny = y + d[Y];
        int nx = x + d[X];
        int nair = air - 1;
        int nused = y == ny ? 0 : used;

        if(h < ny || nx < 0 || w <= nx) continue;
        if(ny == h) {
            result = min(result, cost);
            continue;
        }
        if(nair == 0) continue;

        if(cell[ny][nx] == 0)     result = min(result, dfs(ny, nx, nair, nused, cost));
        else if(cell[ny][nx] < 0) result = min(result, dfs(ny, nx, nair, nused, cost - cell[ny][nx]));
        else {
            if((nused & (1 << nx)) == 0) {
                nair = min(nair + cell[ny][nx], m);
                nused |= 1 << nx;
            }
            result = min(result, dfs(ny, nx, nair, nused, cost));
        }
    }
    return result;
}

int main() {
    while(cin >> w >> h, w | h) {
        cin >> f >> m >> o;
        cell = vector<vector<int>>(h, vector<int>(w));
        for(auto &line: cell) for(auto &v: line) cin >> v;
        cell.push_back(vector<int>(w, 0));

        int answer = INF;
        for(int x = 0; x < w; ++x) {
// cout<<"go"<<endl;
            int y = 0;
            int cost = 0;
            int air = o - 1;
            int used = 0;
            memo = vector<vector<vector<vector<int>>>>(h + 1, vector<vector<vector<int>>>(w, vector<vector<int>>(51, vector<int>(1 << 10, INF))));
            if(air < 1) continue;
            if(cell[y][x] < 0) cost -= cell[y][x];
            if(cell[y][x] > 0) {
                air = min(air + cell[y][x], m);
                used |= 1 << x;
            }
            answer = min(answer, dfs(y, x, air, used, cost));
        }
        if(answer > f) cout << "NA" << endl;
        else           cout << answer << endl;
    }
}

Measured memory_bytes: 48740
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<utility>
#include<numeric>
#include<functional>
#include<algorithm>
#include<queue>
#include<map>
#include<string>


#define FOR(i, a, b) for(int i=a; i<b; i++)
#define COUT(a) cout << a << endl;

using namespace std;
using Int = long long;
using P = pair<Int, Int>;

int main(){
    Int A[3];

    cin >> A[0] >> A[1] >> A[2];
    int cost = 300;

    FOR(i, 0, 3){
        FOR(j, 0, 3){
            FOR(k, 0, 3){
                if (i == j || j==k || k==i){
                    continue;
                }
                int tsk  = abs(A[i] - A[j]) + abs(A[j]-A[k]);
                if (cost > tsk){
                    cost = tsk;
                }
            }
        }
    }

    COUT(cost);

}


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

using ll = long long;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)

ll dp_min[500010];
ll dp_cur[500010];

ll nextD( ll cur, ll d )
{
    if( cur >= d ) return cur - d;
    if( 2 * cur >= d ) return d - cur;
    return cur;
}

int main()
{
    int n, d_init;
    cin >> n >> d_init;
    VEC(ll, n, d, 0);
    REP(i, n) cin >> d[i];
    int qN;
    cin >> qN;
    VEC(ll, qN, q, 0);
    REP(i, n) cin >> q[i];

    dp_cur[0] = d_init;
    REP(i,n)
    {
        dp_cur[i+1] = nextD( dp_cur[i], d[i] ); 
    }
    dp_min[n] = 0;
    BREP(i,n)
    {
        dp_min[i] = d[i] > 2 * dp_min[i+1] + 1 ?
            dp_min[i+1] :
            dp_min[i+1] + d[i];
    }

    REP(i, qN)
    {
        ll& q_ = q[i];
        if( dp_min[q_] >= dp_cur[q_-1] )
            cout << "NO" << endl;
        else cout << "YES" << endl;
    }

    return 0;
}

Measured memory_bytes: 17536
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	n <- readInt
	s <- getLine
	let
		h = n `div` 2
		s1 = take h s
		s2 = drop h s
	putStrLn $ which "Yes" "No" $ h + h == n && s1 == s2

Measured memory_bytes: 508
#include "bits/stdc++.h"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define SIZE(a) int((a).size())
int main(){
  int n;cin>>n;ll sum=0;
  rep(i,1,n+1){
    if(i%3!=0&&i%5!=0){sum+=i;}
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main()	{
  int n;
  cin>>n;
  map<string,int>dic;
  string s;
  rep(i,n){
    cin>>s;
    dic[s]++;
  }
  int cnt=0;
  for(auto m:dic){
    if(cnt<m.second)cnt=m.second;
  }
  for(auto m:dic){
    if(cnt==m.second)
      cout<<m.first<<endl;
  } 
}


Measured memory_bytes: 25216
#include <iostream>
#include <cmath>
#include <string>
#include <queue>
#include <map>
using namespace std;

#define N 3
#define N2 9

//?§???¨??????
static const int dx[4]={0,-1,0,1};
static const int dy[4]={1,0,-1,0};
static const char dir[4]={'u','l','d','r'};

//Puzzle{????????????????????????}
struct Puzzle
{ 
	int f[N2], space;
	string path;
	
	bool operator < (const Puzzle &p) const
	{
		for(int i=0;i<N2;i++)
		{
			if(f[i]==p.f[i])continue;
			return f[i]<p.f[i];
		}
		return false;
	}
};

bool isTarget(Puzzle p)
{
	for(int i=0;i<N2;i++)
		if(p.f[i]!=(i+1))return false;
	return true;
}

string bfs(Puzzle s)
{
	queue<Puzzle>Q;
	map<Puzzle,bool> V;
	Puzzle u,v;
	s.path="";
	Q.push(s);
	V[s]=true;
	
	while(!Q.empty())
	{
		u=Q.front();Q.pop();
		if(isTarget(u))return u.path;
		int sx=u.space/N;
		int sy=u.space%N;
		for(int r=0;r<4;r++)
		{
			int tx=sx+dx[r];
			int ty=sy+dy[r];
			if(tx<0||ty<0||tx>=N||ty>=N)continue;
			v=u;
			swap(v.f[u.space],v.f[tx*N+ty]);
			v.space=tx*N+ty;
			if(!V[v])
			{
				V[v]=true;
				v.path+=dir[r];
				Q.push(v);
			}
		}
	}
	return "unsolveable";
}

int main()
{
	Puzzle in;
	
	for(int i=0;i<N2;i++)
	{
		cin>>in.f[i];
		if(in.f[i]==0)
		{
			in.f[i]=N2;
			in.space=i;
		}
	}
	string ans=bfs(in);
	cout<<ans.size()<<endl;
	//cout<<ans;
}

Measured memory_bytes: 30540
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n,a[100010],ans,cur,sum[100010];
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n+1)cin>>a[i];
    if(a[0]==1){
        if(n==0)cout<<1<<endl;
        else cout<<-1<<endl;
        return 0;
    }
    if(a[0]>1){
        cout<<-1<<endl;
        return 0;
    }
    rep(i,n)sum[i+1]=sum[i]+a[i+1];
    ans=1;
    cur=1;
    for(int i=1;i<=n;i++){
        cur=min(cur*2,sum[n]-sum[i-1]);
        ans+=cur;
        if(cur>=a[i])cur-=a[i];
        else{
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5220
import java.util.*;

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

    int N = sc.nextInt();
    double sum = 0;
    for (int i = 0; i < N; i++) {
      double x = sc.nextDouble();
      String s = sc.next();
      if (s.equals("JPY")) sum += x;
      else sum += x * 380000.0;
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 23124
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>

using namespace std;


int main() {

	
	long long int n, k;
	cin >> n >> k;
	int x[100005] = {};
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		x[a] += b;
	}
	long long int r = 0,ans=100000;
	for (int i = 0; i < 100002; i++) {
		if (x[i] + r >= k) {
			ans = i; break;
		}
		r += x[i];
	}

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


Measured memory_bytes: 640
//ITP1_8_C
main(){
    int a[26]={0};
    char c;

    for (;c!=-1;c=getchar()) {
        a[c>96?c-97:c-65]++;
    }

    for (char i = 0; i<26; i++){
        printf("%c : %d\n", i+97, a[i]);
    }
}



Measured memory_bytes: 2128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#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(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int f(int n) {
    if (n%2 == 0) return n/2;
    else return 3*n+1;
}

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

    int s;
    cin >> s;

    int i = 1;
    vi v {s};
    while (i<1000001){
        int a = f(v[i-1]);
        i++;
        for (int num : v) {
            if (num == a) {
                cout << i << endl;
                return 0;
            }
        }
        v.emplace_back(a);

    }

    return 0;
}

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

using namespace std;

int main()
{
    int t;
    
    // scanf("%d",&t);
    
    t=1;
    
    while(t--)
    {
        long long s,c,ans=0;
        
        scanf("%lld%lld",&s,&c);
        
        ans=min(s,c/2);
        
        c-=(ans*2);
        
        s-=ans;
        
        ans+=c/4;
        
        long long rem=c%4;
        
        ans+=min(s,rem/2);
        
        printf("%lld",ans);
    }

    return 0;
}

Measured memory_bytes: 3764
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

ll a[1010010];
ll b[1010010];

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

  int n; cin >> n;
  REP(i, n+1) cin >> a[i];
  REP(i, n) cin >> b[i];

  ll ans = 0LL;

  REP(i, n) {
    //倒せる数が少ない
    if(a[i] > b[i]) {
      ans += b[i];
    } else {
      //
      if(a[i+1] > (b[i]-a[i])) {
        ans += b[i];
        a[i+1] -= (b[i]-a[i]);
      } else {
        ans += (a[i] + a[i+1]);
        a[i+1] = 0;
      }
    }
    //cerr << ans << endl;
  }    

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5120
ARGF.each_line do |line|
  h, w = line.split.map(&:to_i)
  break if h == 0 && w == 0
  1.upto(h) { |i|
    case i
    when 1, h
      puts '#' * w
    else
      print "#", ("." * (w - 2)), "#\n"
    end
  }
  puts
end

Measured memory_bytes: 6100
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S, T = readline().decode('utf8').split()
A, B = map(int, readline().split())
U = readline().decode('utf8').strip()
if S == U:
    A -= 1
if T == U:
    B -= 1

print(A, B)


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

int main(){
  string S;
  cin >> S;
  int L = S.size();
  int ans=1000;
  for(int i=0; i<L-2; i++){
    int num;
    num=(S.at(i)-'0')*100+(S.at(i+1)-'0')*10+S.at(i+2)-'0';
    ans = min(ans, abs(num-753));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<bool> v(1000000001, false);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v[a] = !v[a];
  }
  int ans = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] == true) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 122368
#include <stdio.h>
int main(){
    int matrixA[100][100] = {0};
    int matrixB[100][100] = {0};
    long long int matrixC[100][100] = {0};
    int n, m ,l;
    scanf("%d %d %d",&n, &m, &l); //行列A,Bの大きさを入力
    
    for(int i=0; i<n; i++){
        for(int k=0; k<m; k++){
            scanf("%d",&matrixA[i][k]);  //行列A(n*m)の要素を入力
        }
    }
    
    for(int k=0; k<m; k++){
        for(int j=0; j<l; j++){
            scanf("%d",&matrixB[k][j]);  //行列B(m*l)の要素を入力
        }
    }
    
    for(int i=0; i<n; i++) {
        for(int j=0; j<l; j++) {
            for(int k=0; k<m; k++){
                matrixC[i][j] += matrixA[i][k] * matrixB[k][j];
            }
        }
    }
    
    for(int i=0; i<n; i++) {
        for(int j=0; j<l; j++) {
            printf("%lld", matrixC[i][j]);
            if(j!=l-1){
              putchar(' ');
            }
        }
        putchar('\n');
    }
    return 0;
}



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

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

  vector<double> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());

  
  double a=0;
  for (int i = 0; i < N-1; i++) {
    A.at(i+1) = (A.at(i)+A.at(i+1))/2.0;
  }  
 
  cout << A.at(N-1);
  
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
s = 0

for i in range(N):
    s = A[i]-s
    
s = s//2
ans = [s*2]
for i in range(1,N):
    s = A[i-1] - s
    ans.append(s*2)
    
for i in range(N):
    print(ans[i], end = " ")

Measured memory_bytes: 14028
#include <stdio.h>
#include <math.h>

int main(){
    long n,i,r=1;
    while(scanf("%ld",&n)==1){
    if(n<=20){
        for(i=1;i<=n;i++){
            r=r*i;

        }



    }
      printf("%ld\n",r);

}
return 0;
}

Measured memory_bytes: 592