akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        System.out.println(baseNeg2(n));
    }

    public static String baseNeg2(int n) {
        final StringBuilder res = new StringBuilder();
        while (n != 0) {
            res.append(n & 1);
            n = -(n >> 1);
        }
        return res.length() > 0 ? res.reverse().toString() : "0";
    }

    static final class Util {
        public static void shuffleSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffleSort(long[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void shuffle(long[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            final int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        public static void swap(long[] x, int i, int j) {
            final long t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


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

int main(){
    long long n, k;
    cin >> n >> k;

    long long tmp1 = n % k;
    long long tmp2 = abs(tmp1 - k);

    long long ans = min(tmp1, tmp2);

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
inline bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }


struct BIT{
	vector<ll> a;
	int N;

	void bit(int n){
		N = n;
		a.resize(n + 1);
	}
	
	void init(vector<int>& a){
		rep(i,N){
			add(i + 1, a.at(i));
		}
	}
	
	ll sum(int x){
		ll ret = 0;
		while(x >= 1){
			ret += a.at(x);
			x -= x & -x;
		}
		return ret;
	}
	
	void add(int x, int y){
		while(y <= N){
			a.at(y) += x;
			y += y & -y;
		}
	}
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	string s;cin >> s;
	vector<BIT> b(26);
	rep(i,26){
		b[i].bit(n);
	}
	rep(i,n){
		b[s[i] - 'a'].add(1,i + 1);
	}
	int q;cin >> q;
	vector<int> ans(0);
	rep(i,q){
		int a;cin >> a;
		if(a == 1){
			int iq;cin >> iq;
			char cq;cin >> cq;
			if(s[iq - 1] != cq){
				b[s[iq - 1] - 'a'].add(-1, iq);
				b[cq - 'a'].add(1, iq);
				s[iq - 1] = cq;
			}
		}
		else{
			int l,r;cin >> l >> r;
			int res = 0;
			rep(j,26){
				if(b[j].sum(r) - b[j].sum(l - 1) > 0) res++;
			}
			ans.pb(res);
		}
	}
	rep(i,ans.size()){
		cout << ans[i] << endl;
	}
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
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 MOD = 1000000007;

int main() {
    string s, t;
    cin >> s >> t;
    int c = 0;
    REP(i, 3) {
        if (s[i] == t[i]) {
            c++;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    IOS
    ll a,b;
    cin>>a>>b;
    map<ll,bool> mp1;
    map<ll,bool> mp2;
    if (a%2==0)
    mp1[2]=1;
    while (a%2==0)
    a/=2;
    for (ll i=3;i*i<=a;i+=2)
    {
        if (a%i==0)
        mp1[i]=1;
        while (a%i==0)
        a/=i;
    }
    if (a>2)
    mp1[a]=1;
    if (b%2==0)
    mp2[2]=1;
    while (b%2==0)
    b/=2;
    for (ll i=3;i*i<=b;i+=2)
    {
        if (b%i==0)
        mp2[i]=1;
        while (b%i==0)
        b/=i;
    }
    if (b>2)
    mp2[b]=1;
    int cnt=0;
    for (auto x: mp1)
    {
        if (mp2[x.first]==1)
        cnt++;
    }
    printf("%lld\n",(cnt+1));
    return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r, d, x;
    cin >> r >> d >> x;

    REP(i, 10) {
        int tmp = r * x - d;
        cout << tmp << '\n';
        x = tmp;
    }
    return 0;
}


Measured memory_bytes: 256
from heapq import heappop, heappush, heapify

N, M = map(int, input().split())
A = [-int(i) for i in input().split()]
heapify(A)
for i in range(M):
  x = -heappop(A)
  x //= 2
  heappush(A,-x)
ans = (-sum(A))
print(ans)

Measured memory_bytes: 72088
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  int n;  cin >> n;
  string s,t;  cin >> s >> t;
  string ans = "";
  rep0(i,n){
    ans += s[i];
    ans += t[i];
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long n, k;
    cin >> n >> k;
    map<long, long> l;
    for(int i = 0; i < n; i++){
        long a;
        cin >> a;
        l[a]++;
    }
    vector<pair<long,long>> m;
    for(auto i : l){
        m.push_back(make_pair(i.first, i.second));
    }
    sort(m.begin(), m.end(), [](auto const& l, auto const& r){
        return l.second < r.second;
    });
    long cnt = 0;
    for(int i = 0; i < m.size() && k < m.size() - i; i++){
        cnt += m[i].second;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 18800
using System;
using System.Collections.Generic;
using System.Linq;

namespace _1165
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Dictionary<int,int[]> dic = new Dictionary<int,int[]>();
                dic[0] = new int[] { 0,0 };
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                int maxa = 0; int mina = 0;
                int maxb = 0; int minb = 0;
                for (int i = 1; i < n; i++)
                {
                    int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    int a = dic[x[0]][0]; int b = dic[x[0]][1];
                    switch (x[1])
                    {
                        case (0): { a--; break; }
                        case (1): { b++; break; }
                        case (2): { a++; break; }
                        case (3): { b--; break; }
                    }
                    dic[i] = new int[] { a,b };
                    maxa = Math.Max(maxa,a); mina = Math.Min(mina,a);
                    maxb = Math.Max(maxb,b); minb = Math.Min(minb,b);
                }
                Console.WriteLine((maxa - mina + 1) + " " + (maxb - minb + 1));
            }
        }
    }
}


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

using namespace std;

#define int long long
#define LL long long
#define ULL unsigned long long

const int LL_INF = ~(ULL)0 >> 1;

signed main() {
    int m, n, a[102], point[102] = {0};
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
    }

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            int temp;
            cin >> temp;
            if (temp == a[i])
                point[j]++;
            else
                point[a[i] - 1]++;
        }
    }

    for (int i = 0; i < n; ++i) {
        cout << point[i] << endl;
    }

    return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int WWW = 0;WWW < (n);WWW++)cerr << v[WWW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


typedef long long ll;
typedef pair<ll,ll> P;

bool ok[222222];
bool deta[222222];
int n;
vector<int> v;

int main(){
	cin >> n;
	REP(i,n){
		int tmp;cin >> tmp;
		tmp--;
		v.PB(tmp);
	}
	
	REP(i,n){
		if(deta[v[i] - 1]){
			ok[v[i]-1] = true;
		}
		deta[v[i]] = true;
	}
	
	DBG(
	cout << "ok" << endl;SHOW1d(ok,n);
	cout << "V" << endl;SHOW1d(v,n);
	)
	
	int cou = 0;
	int ans = 0;
	REP(i,n){
		if(ok[i]){
			cou++;
		}
		else{
			ans = max(ans,cou+1);
			cou = 0;
		}
	}
	
	DBG(cout << "cou " << cou << endl;)
	
	ans = max(ans,cou);
	
	cout << n - ans << endl;
		
	return 0;
}


Measured memory_bytes: 1524
import java.util.*
     
    fun main(args: Array<String>) {
        val (N, K) = readLine()!!.split(" ").map {it.toInt()}
     
        if (K > (N - 1) * (N - 2) / 2) {
            println(-1)
            return
        }
     
        val edges = ArrayList<Pair<Int, Int>>()
     
        for (i in 2 .. N) {
            edges.add(Pair(1, i))
        }
     
        var k = (N - 1) * (N - 2) / 2
     
        for (i in 2 .. N) {
            for (j in i + 1 .. N) {
                if (k > K) {
                    edges.add(Pair(i, j))
                    k--
                }
            }
        }
     
        println(edges.size)
     
        for (e in edges) {
            println("${e.first} ${e.second}")
        }
    }

Measured memory_bytes: 37736
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

int main(){
    ll N,M;
    cin >> N >> M;
    vector<vector<ll>> G(N);
    map<ll,ll> mp;
    ll a,b;
    rep(i,M){
        cin >> a >> b;
        mp[a]++;
        mp[b]++;
    }
    for(auto& e:mp){
        if(e.second%2){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 7936
import sys
import collections
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
count = collections.Counter(a)
sm = {}
sm2 = {}
for key, value in count.items():
    sm[key] = value * (value - 1) // 2
    sm2[key] = (value - 1) * (value - 2) // 2
total = sum(sm.values())

for num in a:
    print(total - sm[num] + sm2[num])


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

using namespace std;

int DP[101][4][4][4];


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

	DP[0][1][1][1] = 1;

	int mod = 1000000007;

	//文字列の文字数
	for (int len = 0; len < N; len++)
	{
		//len -1文字目
		for (int i = 0; i < 4; i++)
		{
			//len-2文字目
			for (int j = 0; j < 4; j++)
			{
				//len-3文字目
				for (int k = 0; k < 4; k++)
				{
					if (DP[len][i][j][k] == 0) continue;

					//新しく追加する文字(len文字目)
					for (int l = 0; l < 4; l++) {
						if (l == 3 && i == 2 && j == 0) continue;
						if (l == 3 && i == 0 && j == 2) continue;
						if (l == 2 && i == 3 && j == 0) continue;
						if (l == 3 && i == 2 && k == 0) continue;
						if (l == 3 && j == 2 && k == 0) continue;

						DP[len + 1][l][i][j] += DP[len][i][j][k];
						DP[len + 1][l][i][j] %= mod;
					}
				}
			}
		}
	}
	long long ans = 0;
	//i-1文字目
	for (int i = 0; i < 4; i++)
	{
		//i-2文字目
		for (int j = 0; j < 4; j++)
		{
			//i-3文字目
			for (int k = 0; k < 4; k++)
			{
				ans += DP[N][i][j][k];
			}
		}
	}
	ans %= mod;

	cout << ans << endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;


long calc(long k, long[] a, long[] b) {
    long ans;
    foreach(i; iota(a.length)) {
        if((a[i] | k) == k) {
            ans += b[i];
        }
    }
    return ans;
}

void main(){
    long n, k;
    readlnTo(n, k);
    long[] a, b;
    foreach(i; iota(n)) {
        auto l = readLongs();
        a ~= l[0];
        b ~= l[1];
    }

    long ans = calc(k, a, b);
    foreach(i; iota(64).retro()) {
        if((k & (1L << i)) > 0) {
            ans = max(ans, calc((k & ~(1L << i)) | ((1L << i) - 1), a, b));
        }
    }
    writeln(ans);
}



Measured memory_bytes: 5372
import fileinput


def chose_action_prev(current_action, last_best_rewards):
    return max((v, idx) for idx, v in enumerate(last_best_rewards) if idx != current_action)[1]


def vacation(action_values):
    last_best_rewards = [0, 0, 0]
    current_best_rewards = [0, 0, 0]

    for vals_for_day in action_values:
        for action, rev in enumerate(vals_for_day):
            prev_action = chose_action_prev(action, last_best_rewards)
            current_best_rewards[action] = last_best_rewards[prev_action] + rev

        last_best_rewards = current_best_rewards
        current_best_rewards = [0, 0, 0]

    return max(last_best_rewards)


inp = fileinput.input()
line_count = int(inp.readline())

action_vals = []
for _ in range(line_count):
    action_vals.append([int(v) for v in inp.readline().split(" ")])

print(vacation(action_vals))


Measured memory_bytes: 24436
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int64 INF = 1LL << 40 - 1;
constexpr int64 LINF = 1LL << 60 + 1;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;
    
// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;
    
// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;
    
// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
    
    
signed main() {
    INIT;
    VAR(int, n);
    map< int, int > mp;
    vector< int > a;
    REP(i, n) {
        VAR(int, j);
        a.push_back(j);
        mp[j]++;
    }
    
    sort(ALL(a));
    
    int ans = 0;
    RREP(i, a.size()) {
        int64_t sum = 1;
        while (sum <= a[i]) { sum <<= 1; }

        int64_t target = sum - a[i];
        if (target == a[i]) {
            int tmp = mp[target] / 2;
            mp[target] -= tmp * 2;
            ans += tmp;
        } else {
            int tmp1 = mp[target];
            int tmp2 = mp[a[i]];
            mp[target] -= min(tmp1, tmp2);
            mp[a[i]] -= min(tmp1, tmp2);
            ans += min(tmp1, tmp2);
        }
    }
    
    OUT(ans)BR;
    
    return 0;
}

Measured memory_bytes: 26864
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e5+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int tot=3,tmp[MAXN],Pow[MAXN],A,B,wA[MAXN],wB[MAXN];
inline int Add(int x,int y){return ++tot,cout<<"+ "<<x<<" "<<y<<" "<<tot<<"\n",tot;}
inline int Min(int x,int y){return ++tot,cout<<"< "<<x<<" "<<y<<" "<<tot<<"\n",tot;}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	puts("32863"),puts("+ 0 1 3"),puts("< 2 3 3");A=0,B=1,Pow[0]=3;
	Rep(i,1,30)Pow[i]=Add(Pow[i-1],Pow[i-1]);
	int tA=Add(A,Pow[0]),tB=Add(B,Pow[0]),A0=++tot,A1=++tot,B0=++tot,B1=++tot;
	Red(i,30,0){
		A1=Add(Pow[i],A0),wA[i]=Min(A1,tA);
		tmp[0]=wA[i];Rep(j,1,i)tmp[j]=Add(tmp[j-1],tmp[j-1]);
		A0=Add(A0,tmp[i]);
	}
	Red(i,30,0){
		B1=Add(Pow[i],B0),wB[i]=Min(B1,tB);
		tmp[0]=wB[i];Rep(j,1,i)tmp[j]=Add(tmp[j-1],tmp[j-1]);
		B0=Add(B0,tmp[i]);
	}
	Rep(i,0,30)Rep(j,0,30){
		tmp[0]=Add(wA[i],wB[j]),tmp[0]=Min(Pow[0],tmp[0]);
		Rep(k,1,i+j)tmp[k]=Add(tmp[k-1],tmp[k-1]);
		cout<<"+ 2 "<<tmp[i+j]<<" 2\n";
	}
	return 0;
}




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

typedef long long ll;

int n, m, q, ret = 0;
int a[51], b[51], c[51], d[51];

void construct(int curr_val, vector<int> curr_set) {
	curr_set.push_back(curr_val);
	if ((int) curr_set.size() >= n) {
		int temp = 0;
		for (int i = 0; i<q; i++) {
			if (curr_set[b[i] -1] - curr_set[a[i] - 1] == c[i]) temp += d[i];
		}
		ret = max(ret, temp);
	}
	else  {
		for (int val = curr_val; val <= m; val++) construct(val, curr_set);
	}
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> q;
	for (int i = 0; i<q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	for (int val = 1; val <= m; val++) construct(val, {});
	cout << ret << '\n';
}



Measured memory_bytes: 3656
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<unordered_set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include <cstring>
#include <climits>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a == 1) a = 14;
	if (b == 1) b = 14;
	if (a > b) { cout << "Alice" << endl; }
	else if (a < b) { cout << "Bob" << endl; }
	else cout << "Draw" << endl;

	return 0;
}

Measured memory_bytes: 256
s=input()
t=input()
n=len(s)
import bisect
import collections
Chk=[False]*26
Fst=collections.defaultdict(int)
Pos=collections.defaultdict(list)
for i in range(n):
  ss=s[i]
  ns=ord(ss)-97
  if not Chk[ns]:
    Fst[ss]=i+1
    Chk[ns]=True
  Pos[ss]+=[i+1]
ans=0
prev=0
for i in range(len(t)):
  tt=t[i]
  if Fst[tt]==0:
    ans=-1
    break
  else:
    f,l=Fst[tt],Pos[tt][-1]
    if prev>=l:
      ans+=n-prev+f
      prev=f
    else:
      P=Pos[tt]
      next=P[bisect.bisect_right(P,prev)]
      ans+=next-prev
      prev=next
print(ans)

Measured memory_bytes: 8044
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1e18;

int main(void) {
    ll K;
    string S;
    cin >> K >> S;
    if (S.size() <= K) {
        cout << S << endl;
    } else {
        for (int i = 0; i < K; i++) {
            cout << S[i];
        }
        cout << "..." << endl;
    }
    return 0;
}



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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

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

	int N;
	cin >> N;
	vector<int> A(N), B(N);
	rep(i, 0, N)cin >> A[i];
	rep(i, 0, N)cin >> B[i];

	int cnt = 0;
	rep(i, 0, N)
	{
		if (A[i] >= B[i])
		{
			cnt -= A[i] - B[i];
		}
		else
		{
			cnt += (B[i] - A[i]) / 2;
		}
	}

	if (cnt >= 0)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

list = [a, b, c]
max = max(list)
index_max = list.index(max)

result = max * 2 ** k
for i in range(3):
	if i != index_max:
		result += list[i]

print(result)


Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

static const int INF = 1e9;

int main(){
    int n, m;
    cin >> n >> m;
    vector< vector<int> > v;
    v = vector< vector<int> >(n+1, vector<int>(n+1, INF));
    REP(i, n+1) v[i][i] = 0;

    vector<int>a, b, c;
    a.push_back(0), b.push_back(0), c.push_back(0);
    REP(i, m) {
        int ai, bi, ci;
        cin >> ai >> bi >> ci;
        v[ai][bi] = ci;
        v[bi][ai] = ci;
        a.push_back(ai);
        b.push_back(bi);
        c.push_back(ci);
    }
    vector< vector<int> > edges;
    edges = v;


        for (int k = 0; k < n+1; k++) {
            for(int i = 0; i < n+1; i++) {
                for(int j = 0; j < n+1; j++)
                    v[i][j] = min(v[i][j], v[i][k]+v[k][j]);
            }
        }
        int cnt = m;
        for(int i= 1;i< m+1;i++) {
            bool flag = false;
            for(int j= 1;j< n+1;j++) {
                for(int k = 1;k<n+1;k++) {
                    ll temp = v[j][a[i]]+c[i]+v[b[i]][k];
                    if(temp == v[j][k]) flag = true;
                }
            }
            if(flag)
                cnt--;
        }


        cout << cnt << endl;

}


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

const ll INF=1E18+7;
const ll N=1E5+7;
ll n,m;
struct stu{
    ll a,b;
    bool friend operator <(const stu &x,const stu &y){
        return x.b>y.b;
    }
};
vector <stu >ve[N];
bool mark[N];
ll dp[N];
void djstrea(){
    priority_queue<stu>que;
    que.push({1,0});
    dp[1]=0;
    while(que.size()){
        stu x=que.top();
        que.pop();
        if(mark[x.a]) continue ;
        mark[x.a]=1;
        for(ll i=0;i<ve[x.a].size();i++){
            ll dx=ve[x.a][i].a;
            ll dy=ve[x.a][i].b;
            if(dp[dx]>dp[x.a]+dy){
                dp[dx]=dp[x.a]+dy;
                que.push({dx,dp[dx]});
            }
        }
    }
}
int main(){
    cin>>n>>m;
    ll x,y,z;
    for(ll i=1;i<=n;i++) {
        ve[i].push_back({i-1,0});
    }
    for(ll i=0;i<=n;i++) dp[i]=INF;
    for(ll i=1;i<=m;i++){
        cin>>x>>y>>z;
        ve[x].push_back({y,z});
    }
    djstrea();
    if(dp[n]==INF)   cout<<-1<<endl;
    else cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 10232
import java.util.*;

public class Main {

    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String n = sc.nextLine();
            boolean check =false;
      		
      		for(int i=0;i<3;i++)
      		if(n.charAt(i)=='7')check=true;

            System.out.println(check?"Yes":"No");
          }
        }


Measured memory_bytes: 35560
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++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 ALL(x) (x).begin(), (x).end()
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = 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; }

int ctoi(const char c)
{
    if ('0' <= c && c <= '9') return {c - '0'};
    else return -1;
}

int DigitSum(int num)
{
    int sum = 0;
    while (!(num == 0))
    {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}

int main()
{
    optimize_cin();
    int N;

    cin >> N;

    int f_x = DigitSum(N);

    if (N % f_x == 0)
    {
        cout << "Yes" << "\n";
    }
    else
    {
        cout << "No" << "\n";
    }

    return 0;
}


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

#define INF 1001001001
#define MAX_DIGIT 1000000+1
char s[MAX_DIGIT+5];
int dp[MAX_DIGIT+5][2];

int min(int a, int b){
	return (a < b) ? a : b;
}

int main(){
	int len;
	int i, j, ni, nj;
	int x, a, b;

	s[0] = '0';
	scanf("%s", s+1);
	len = strlen(s);
	for(i=0; i<len+1; i++){
		for(j=0; j<2; j++){
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	for(i=0; i<len; i++){
		for(j=0; j<2; j++){
			x = s[len-1-i] - '0';
			x += j;
			for(a=0; a<10; a++){
				ni = i + 1;
				nj = 0;
				b = a - x;
				if(b < 0){
					nj = 1;
					b += 10;
				}
				dp[ni][nj] = min(dp[ni][nj], dp[i][j]+a+b);
			}
		}
	}

	printf("%d", dp[len][0]);

	return 0;
}


Measured memory_bytes: 8960
tList = input().strip()

buffer = 0
ans = 0
for t in tList:
    if(buffer > 0):
        if(t == "g"):
            ans += 1
            buffer -= 1
        if(t == "p"):
            buffer -= 1
    else:
        if(t == "p"):
            ans -= 1
            buffer += 1
        if(t == "g"):
            buffer += 1
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
    ll n, ans, sum;
    ll a[200000];
    map<ll, ll> used;

    sum = 0;
    ans = 0;
    used[0] = 1;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
        if (used[sum] != 0)
            ans += used[sum];

        used[sum]++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
	int t;
    cin>>t;
	vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout<<v[--t];
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct song{
	int len;
	string name;
};
typedef struct song song;
song songs[50];
int main(){
	int n,ans=0,x;
	string s;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>songs[i].name>>songs[i].len;
	}
	cin>>s;
	for(int i=0;i<n;i++){
		if(s==songs[i].name){
			x=i;
		}
	}
	for(int i=x+1;i<n;i++)ans+=songs[i].len;
	cout<<ans<<'\n';
} 

Measured memory_bytes: 256
N,K,*P = map(int,open(0).read().split())
P = [(P[i]+1)/2 for i in range(N)]
M = m = sum(P[:K])

for i in range(N-K):
  if M < m-P[i]+P[i+K]:
    M = m-P[i]+P[i+K]
  m= m-P[i]+P[i+K]

print(M)



Measured memory_bytes: 25036
#include<bits/stdc++.h>
#define N 200010
#define ll long long
using namespace std;
ll a[20];
ll solve(int l,int r,int T1,int T2){
	if(l>r)return 0;
	ll SS=1e18;
	for(int i=l;i<=r;i++){
		SS=min(SS,solve(l,i-1,T1,T1+T2)+solve(i+1,r,T1+T2,T2)+(T1+T2)*a[i]);
	}
	return SS;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	printf("%lld\n",solve(2,n-1,1,1)+a[1]+a[n]);
	return 0;
}

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

int main() {
	int H, W;
	cin >> H >> W;
	
	while (H > 0 && W > 0) {
		for (int i=1; i<=H; i=i+1) {
			for (int j=1; j<=W; j=j+1) {
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;
	}

	return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  string s;
  cin >> s;
  s.at(3) = '8';
  cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
const int P=1e9+7;
int fac[N],inv[N],F[N];
int n,L,R,x,i,m;
int Pow(int a,int b){
	int ret=1;
	for (;b;b>>=1,a=1ll*a*a%P)
		if (b&1) ret=1ll*ret*a%P;
	return ret;
}
int C(int n,int m){
	if (n<m) return 0;
  return 1ll*fac[n]*inv[m]%P*inv[n-m]%P;
}
int main(){
	scanf("%d",&n);
	for (i=1;i<=n+1;i++){
		scanf("%d",&x);
		if (F[x]) L=F[x],R=i;
		F[x]=i;
	}
	for (fac[0]=i=1;i<=n+1;i++) 
	  fac[i]=1ll*fac[i-1]*i%P;
	for (inv[n+1]=Pow(fac[n+1],P-2),i=n;i>=0;i--)
		inv[i]=1ll*inv[i+1]*(i+1)%P;
	m=n-R+L;
	for (i=1;i<=n+1;i++)
		printf("%d\n",(C(n+1,i)-C(m,i-1)+P)%P);
}

Measured memory_bytes: 2432
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
  
public class Main
{ 
    //By shwetank_verma
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    static int mod=1000000007;
    static boolean primes[]=new boolean[1000007];
    
    static boolean seive(int n){
        Arrays.fill(primes,true);
        primes[0]=primes[1]=false;
        for(int i=2;i*i<=n;i++){
            if(primes[i]==true){
                for(int p=i*i;p<=n;p+=i){
                    primes[p]=false;
                }
            }
        }
        if(n<1000007){
            return primes[n];
        }
        return false;
        
    }
    static int gcd(int a,int b){
        if(b==0)
        return a;
        return gcd(b,a%b);
    }
    static long GCD(long a,long b){
        if(b==0)
        return a;
        return GCD(b,a%b);
    }
    
  
    public static void main(String[] args) 
    { 
        FastReader sc=new FastReader(); 
        try{
           
                
                int n=sc.nextInt();
                
                int a[]=new int[n];
                int xor=0;
                for(int i=0;i<n;i++){
                    a[i]=sc.nextInt();
                    xor=xor^a[i];
                }
                
                for(int i=0;i<n;i++) {
                	System.out.print((xor^a[i])+" ");
                }
                
           
            
        }catch(Exception e){
            return;
        }
    } 
}


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

int combi(int h, int k) {
  if (h == k || k == 0)
    return 1;
  else {
    return combi(h - 1, k - 1) + combi(h - 1, k);
  }
}
int main(void){
    int n, m;
    cin >> n >>m ;
    int ans = 0;
    if(n >= 2) ans += combi(n, 2);
    if(m >= 2) ans += combi(m, 2);
    cout << ans;
    
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

O = input()
E = input()

ans = ""
for x, y in zip(O, E):
	ans += x+y
if (len(O)-len(E))%2==1:
	ans += O[-1]
print(ans)


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

const int MOD = 1e9 + 7;
const int N = 1e4 + 50;
const int D = 100 + 10;

string k;
int d;
int n;
int dp[N][D][2];

int sum2(int a, int b) {
	int c = a + b;
	if(c >= MOD) c -= MOD;
	
	return c;
}

int rek(int ind, int sum, int tight) {
	if(ind >= n) 
		return !sum;
	if(dp[ind][sum][tight] != -1) 
		return dp[ind][sum][tight];
	
	int ret = 0;
	int x = 9;
	if(tight) x = int(k[ind]) - 48;
	
	for(int i = 0; i <= x; i++) {
		ret = sum2(ret, rek(ind + 1, (sum + i) % d, (tight && i == x)));
	}
	
	dp[ind][sum][tight]=ret;
	//cout <<ind<<" "<<sum<<" "<<tight<<" "<<ret<<endl;
	return ret;
}
int main() {
	memset(dp, -1, sizeof dp);
	cin >> k >> d;
	n = k.size();
	
	cout << (rek(0, 0, 1) - 1 + MOD) % MOD;
	/*for(int i=0;i<k.size();i++) {
		for(int j=0;j<20;j++) {
			cout <<dp[i][j][1]<<" ";
		}
		cout <<endl;
	}*/
	return 0;
}

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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<vector<int>> edges;
vector<int> dp;

void dfs(int i) {
    if (edges[i].size() == 0) return;
    for (int j : edges[i]) dfs(j);
    vector<int> a;
    for (int j : edges[i]) a.push_back(dp[j]);
    sort(a.begin(),a.end(),greater<int>());
    for (int j = 0;j < a.size();++j) a[j] += j+1;
    dp[i] = *max_element(a.begin(),a.end());
}

int main() {
    int n;
    cin >> n;
    edges.resize(n);
    dp = vector<int>(n,0);
    for (int i = 1;i < n;++i) {
        int a;
        cin >> a;--a;
        edges[a].push_back(i);
    }
    dfs(0);
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 13952
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>


#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

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; }
void SWAP(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void SWAP(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

class C {
	ll n, m;
public:
	C()
	{
		cin >> n >> m;
	}
	void solve()
	{
		if (n == 1 || m == 1)
		{
			if (n == 1 && m == 1)
			{
				cout << 1 << endl;
				return;
			}
			else
			{
				cout << max(n, m) - 2 << endl;
				return;
			}
		}

		else
		{
			ll area{ n * m };
			ll ans{ 0 };
			
			// corner
			area -= 4;

			// edge
			area -= 2 * ((n - 2) + (m - 2));

			// inside
			if (area > 0)
				ans += area;

			cout << ans << endl;

		}

	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
#define ll long long 
const int MAXN=1e6; 
using namespace std;
int ans,n;
int a[MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		if(a[i+1]!=a[i]) continue ;
		else
		{
			int now=i,num=0;
			while(now<=n )
			{
				if(a[now]!=a[i]) break;
				else num++;
				now++;
			}
			if(num&1) ans+=((num-1)/2);
			else ans+=(num)/2;
			i+=num-1;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
class Main {
 
  static int INF = (int) 1e9 + 7;
 
  public static void main(String[] args) {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    
    int n = in.nextInt();
    int[][] can = new int[n][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        can[i][j] = in.nextInt();
      }
    }

    
    int[] dp = new int[1 << n];
    dp[0] = 1;
    for (int mask = 0; mask < 1 << n; mask++) {
      int a = countSetBit(mask);
      for (int b = 0; b < n; b++) {
        if ((mask & 1 << b) == 0 && can[a][b] == 1){
          add(dp, mask | 1 << b, mask);
        } 
      }
    }
   
    System.out.println(dp[(1<<n) - 1]);
  }

  static void add(int[] a, int i, int j) {
    a[i] += a[j];
    if (a[i] >= INF) {a[i] -= INF;}
  }

  static int countSetBit(int a) {
    int count = 0; 
    while (a > 0) {
      count += (a & 1);
      a = a >> 1;
    }
    return count;
  }

 
}

Measured memory_bytes: 32468
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    bool flag = false;
    for(int i = 0;i < N;i++){
        string s;
        cin >> s;
        if(s == "Y")flag = true;
    }
    cout << (flag?"Four":"Three") << endl;
}

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

int64_t n, k;

void solve() {
   int64_t pos = n / k;
   int64_t neg = pos + 1;
   cout << min(abs(n - pos * k), abs(n - neg * k)) << endl;
}

int main() {
    cin >> n >> k;
    solve();
}

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

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

  long long ans = 0; // 答えが大きくなることが予想されるので、long longで持っておく
  int MaxNum = 0;
  for (int i = 0; i < N; i++)
  {
    //MaxNumを使い回すことで計算を抑える。この処理の仕方はroopで最大値(最小値)を保持する際によく使用するので覚えておく
    MaxNum = max(MaxNum, A[i]);
    int Bi = MaxNum;  // i番目より前で、最も大きい値を取得する。
    ans += Bi - A[i]; // BiとA[i]の差分分、台を追加すればよいので、この差をansに追加する
  }

  cout << ans << endl;
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;


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

    cout << (N+999)/1000 * 1000 - N << endl;

}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define deb(a) cout<<#a<<" "<<a<<endl
#define WW 100000
#define INF 1000000000000000000 //1e18
#define EPS 0.000000001 //1e-9
//get<a>(t) gives ath element of tuple named t, numbering starts from 0
//max({_,......,_}) can give maximum of any number of elements. Similarly min also.
//don't forget to initialise freq arrays
//reverse(all(v)) would reverse a vector  
//pow(10.0, 2.0) can give exactly 100.0, slightly greater, or slightly less. 
//Therefore use(int)(pow(10.0,zz)+EPS)
int32_t main()
{
    IOS;
    int n,k; cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    int dp[n]={};
    for(int &x:dp)x=INF;
    dp[0]=0;
    if(n==1)
        {cout<<"0"; return 0;}
    //dp[1]=abs(h[1]-h[0]);
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
        	if(i-j>=0)
        		dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1792