akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    int n, d;
    int ans = 0;
    cin >> n >> d;

    for(int T = 0; T<n; T++){
        int x, y;
        cin >> x >> y;
        
        double eq = sqrt(pow(x, 2) + pow(y, 2));
        if(ceil(eq) <= d)
            ans+=1;
    }
    
    cout << ans << endl;;
    return 0;
}

Measured memory_bytes: 3668
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(n):
    if p[i] == i + 1:
        if i == 0:
            p[i], p[i + 1] = p[i + 1], p[i]
        elif i == n-1:
            p[i], p[i - 1] = p[i - 1], p[i]
        else:
            
             p[i], p[i + 1] = p[i + 1], p[i]
        cnt += 1

print(cnt)

Measured memory_bytes: 14008
#include<bits/stdc++.h>
#include<cstdio>
int main()
{
    int n;
    scanf("%d",&n);
    int ld = n%10;
    if(ld == 0||ld ==1||ld==8||ld==6)
        printf("pon");
    else if(ld == 2||ld ==4||ld==5||ld==7||ld==9)
        printf("hon");
    else
        printf("bon");
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;
using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void ioinit() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); }
inline i64 gcd(i64 a, i64 b) { if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline vi32 plist(i32 n) { vi32 f(n, 1); f[0] = f[1] = 0; repi(i, 2, n) for (int j = i * 2; j < n; j += i) f[j] = 0; return f; }
inline bool isprime(i32 n) { if (n < 2) return 0; for (i32 i = 2; i * i <= n; i++) if (n % i == 0) return 0; return 1; }
template<class T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<class T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<class T> inline bool amax(T &x, T y) { if (x >= y) return 0; x = y; return 1; }
template<class T> inline bool amin(T &x, T y) { if (x <= y) return 0; x = y; return 1; }
template<class T> inline i64 lbi(vector<T> &v, T e) { return lower_bound(all(v), e) - v.begin(); }
template<class T> inline i64 ubi(vector<T> &v, T e) { return upper_bound(all(v), e) - v.begin(); }
template<class T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }

int main() {
  ioinit();
  int n;
  cin >> n;
  vi32 a(n);
  rep(i, n) cin >> a[i];
  vi32 l(n), r(n);
  l[0] = a[0];
  r[n - 1] = a[n - 1];
  reps(i, n - 1) l[i] = gcd(l[i - 1], a[i]);
  rrep(i, n - 1) r[i] = gcd(r[i + 1], a[i]);
  i32 ans = 0;
  rep(i, n) {
    i32 res;
    if (i == 0) res = r[i + 1];
    else if (i == n - 1) res = l[i - 1];
    else res = gcd(l[i - 1], r[i + 1]);
    amax(ans, res);
  }  
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1408
(defun input (n)
  (let ((A (make-array n)))
    (loop for i below n do (setf (aref A i) (read)))
    A))

(defun solve (a)
  (sort a #'>)
  (let ((c 0)
        (p 0))
    (loop for x across a
          unless (= x p)
          do (incf c)
          do (setq p x))
    c))

(princ (solve (input (read))))

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

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

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n; cin >> n;
  LL a, b; cin >> a >> b;
  vector<LL> h(n);
  rep(i, n) cin >> h[i];

  LL ans = 1e9;
  LL left = 1, right = 1e9;
  LL mid, sum;
  while (left < right) {
    mid = (left + right) / 2;
    sum = 0;
    rep(i, n) {
      if (h[i] > b * mid) {
        sum += (h[i] - (b * mid) + (a - b - 1)) / (a - b);
      }
    }

    if (sum > mid) {
      left = mid + 1;
    } else {
      right = mid;
      ans = min(ans, mid);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int p[100005];
long long result(int n,int mod)
{
	int i;
	long long ans=1;
	for(i=1;i<=n;i++)
	{
		ans=ans%mod*2;
		ans%=mod;
	}
	return ans;
}
int main()
{
	int n,a[100005],count=0,b,flag=1;
	long long ans;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
		if(a[i]==0)
			count++;
		else
			p[a[i]]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=0&&p[a[i]]!=2)
			flag=0;
	}
		if(n%2!=0) //奇数 
		{
			for(int i=1;i<=n;i++)
			{
				if(a[i]%2!=0)
					flag=0;
			}
			if(count==1)
			{
				b=(n-1)/2;
				ans=result(b,1000000000+7);
			}
			else 
				flag=0;
		}
		else
		{
			for(int i=1;i<=n;i++)
			{
				if(a[i]%2==0)
					flag=0;
			}
			if(count==0)
			{
				b=n/2;
				ans=result(b,1000000000+7);
			}
			else
				flag=0;
		}
		if(flag)
			cout << ans;
		else
			cout << "0";

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb push_back
#define PI (4*atan(1))


int32_t main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	IOS;

    string s;
    cin >> s;

    int count(0);

    int left = 15-s.size();

    for(char i : s)
    {
    	if(i == 'o')
    		count++;
    }

    if(count+left >= 8)
    {
    	cout << "YES";
    }
    else
    {
    	cout << "NO";
    }

	return 0;
}

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

int main(){
    int n,m;
    int match[10]={ 0,2,5,5,4,5,6,3,7,6 };
    cin>>n>>m;
    
    vector<int> num(9,0);
    for(int i=0;i<m;i++){
        int a;
        cin>>a;
        num[match[a]]=max(num[match[a]],a);
    }
    
    vector<string> dp(n+1,"0");
    dp[0]="";
    for(int i=0;i<n;i++){
        for(int j=0;j<9;j++){
            if(i+j>n || num[j]==0 || dp[i]=="0"){
                continue;
            }
            string s=dp[i];
            s.push_back(num[j]+'0');
            if(dp[i+j]=="" || dp[i+j]<s || (int)(dp[i+j]).size()<(int)(s).size()){
                dp[i+j]=s;
            }
        }
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 45056
/*
    Author : Wasi Ur Rahman
*/
#include <bits/stdc++.h>
using namespace std;
// defines
#define ll long long int
#define ull unsigned long long int
#define MOD 100000
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sc scanf
#define pf printf
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min(d, min(a, min(b, c)))
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max(d, max(a, max(b, c)))
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 3.141592653589793238462643
#define no cout << "NO" << endl;
#define yes cout << "YES" << endl;
#define elif else if
/* important funct */
ll Int()
{
    ll c;
    cin >> c;
    return c;
}
#define Int Int()
void sortString(string &str)
{
    sort(str.begin(), str.end());
}
bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}
ll ManualGcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll ManualLcm(ll a,ll b)
{
    return((a)*(b)/gcd(a,b));
}
ll fact(ll n)
{
    ll res = 1;
    for(ll i = n;i>=1;i--)
        res *= i;
    return res;
}
ll nCr(ll n,ll r)
{
    return (fact(n)/(fact(r)*fact(n-r)));
}
ll nPr(ll n,ll r)
{
    return fact(n)/fact(n-r);
}
// Main
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll a=Int;
    ll b=Int;
    if(a <= b)
        cout << "Yes" << endl;
    else cout << "No" <<endl;
}


Measured memory_bytes: 256
x,K,D = map(int,input().split())
X = abs(x)
total_distance = D * K
if X >= total_distance:
    print(X - total_distance)
else:
    to_zero_times = X // D #0に近付くまでに使った回数
    from_zero_distance1 = X % D #０になるべく近付いた時の０からの距離
    from_zero_distance2 = D - from_zero_distance1
    left_times = K - to_zero_times #残り回数
    if left_times % 2 == 0:
        print(from_zero_distance1)
    else:
        print(from_zero_distance2)

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

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

/* define const */
const long long INF = (1LL << 60);
/* end defineing */

int main()
{
    char c;
    cin >> c;

    if (c == 'A')
        cout << "T" << endl;
    else if (c == 'C')
        cout << "G" << endl;
    else if (c == 'T')
        cout << "A" << endl;
    else if (c == 'G')
        cout << "C" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

vll dx = {0,1,0,-1};
vll dy = {1,0,-1,0};

pll f(ll n, ll val){
  ll x = (val-1) / n + 1;
  ll y = val % n;
  if(y == 0){
    y = n;
  }
  return {x,y};
}

void dfs(ll n, vvll& grid, vvll& exi, pll cur){
  ll x = cur.first;
  ll y = cur.second;
  ll val = grid[x][y] + exi[x][y];
  REP(i,0,3){
    ll nx = x + dx[i];
    ll ny = y + dy[i];
    if(val < grid[nx][ny]){
      grid[nx][ny] = val;
      dfs(n, grid, exi, {nx, ny});
    }
  }
}

int main(){
  ll n;
  cin >> n;
  vll a(n*n);
  REP(i,0,n*n-1){
    cin >> a[i];
  }
  vvll grid(n+2, vll(n+2, 1e9)), exi(n+1, vll(n+1, 1));
  REP(i,0,n+1){
    REP(j,0,n+1){
      grid[i][j] = min({i-1, j-1, n-i, n-j });
    }
  }
  ll ans = 0;
  REP(i,0,n*n-1){
    pll cur = f(n, a[i]);
    exi[cur.first][cur.second] = 0;
    ans += grid[cur.first][cur.second];
    dfs(n, grid, exi, cur);
  }
  cout << ans << endl;
}

Measured memory_bytes: 28516
ref=[63,6,91,79,102,109,125,39,127,111]
while 1:
	try:
		n=input()
		if n==-1:break
		e=0
		for i in range(n):
			a=ref[input()]
			print "{:07b}".format(a^e)
			e=a
	except:
		pass

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

int main(){

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

    int n,m;
    cin >> n >> m;
    vector<int> x(m);
    for(int i = 0;i < m;i ++){
        cin >> x.at(i);
    }

    if(n-m >= 0){
        cout << 0 << endl;
        return 0;
    }

    sort(x.begin(),x.end());
    vector<int> y(m-1);
    for(int i = 0;i < m-1;i ++){
        y.at(i) = x.at(i+1) - x.at(i);
    }

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

    int ans = 0;
    for(int i = 0;i< m-n;i ++){
        ans += y.at(i);
    }

    cout << ans << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){ 
    int N;
    cin >>N;
    vector<string> S(N);
    vector<int>    P(N);
    vector<tuple<string,int,int>> A(N);
    for(int i = 0;i < N;i++){
        cin >> S[i] >> P[i]; 
        A[i] = make_tuple(S[i],100-P[i],i+1);
    }
    sort(A.begin(),A.end());
    for(int i =0 ;i < N;i++){
        cout << get<2>(A[i]) << endl;
    }


}  

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    auto S = sread();
    solve(S[1 .. $], 0, S[0] - '0').writeln();
}

long solve(string s, long sum, long tmp)
{
    if (s.length == 0)
    {
        return sum + tmp;
    }
    long a = solve(s[1 .. $], sum, tmp * 10 + (s[0] - '0'));
    long b = solve(s[1 .. $], sum + tmp, s[0] - '0');
    return a + b;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int n;
	cin >> n;
	vector<int> s;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s.push_back(a);
	}
	int b = 1;
	for (int i = 0; i < n; i++) {
		if (s[i] == b) {
			b = b + 1;
		}
	}

	if (b == 1) {
		cout << -1;
	}
	else {
		cout << n - (b - 1);
	}
}

Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>

using namespace std;

long long computeComb(long long n) {
	return n * (n - 1) / 2;
}


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

	long long* count = new long long[N + 1]();
	long long* A = new long long[N];

	for (long long i = 0; i < N; i++) {
		cin >> A[i];


		count[A[i]]++;
	}

	long long sum = 0;
	for (long long i = 0; i < N + 1; i++) {
			sum += computeComb(count[i]);
		
	}

	for (long long i = 0; i < N; i++) {
		cout << sum - count[A[i]] + 1 << "\n";
	}
}


Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		
		if(a<=5) System.out.println(0);
		else if(a<=12)System.out.println(b/2);
		else System.out.println(b);
		
	}
}

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

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/


void Calc() {

  string s = in;
  if (s.find("YAKI") == 0) {
    cout << ("Yes") << endl;
  }
  else {
    cout << ("No") << endl;
  }
}


Measured memory_bytes: 768
#![allow(unused_imports)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};

fn main() {
    input! {
        n: usize,
        hs: [usize; n],
    }
    println!("{}", wrapper(hs));
}

fn wrapper(hs: Vec<usize>) -> usize {
    let mut ans = 0usize;
    solve(&mut ans, &hs);
    ans
}

fn solve(ans: &mut usize, hs: &[usize]) {
    match hs.iter().min() {
        Some(&m) => {
            if hs.iter().all(|h| *h == 0) {
                return;
            }
            *ans += m;
            let hss: Vec<_> = hs.iter().map(|h| h - m).collect();
            for hs in hss.split(|&h| h == 0) {
                solve(ans, hs);
            }
        },
        None => { return; },
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

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

    double r;
    cin >> r;

    double area = r * r * M_PI;
    double length = 2 * r * M_PI;

    printf("%.6f %.6f\n", area, length);
    return 0;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define endl "\n"
// #define int long long
#define F first
#define S second
#define B begin
#define E end
#define RB rbegin
#define RE rend
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 1e9 + 7;
const int Q = 47;
 
using namespace std;
 
void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}


signed main()
{
    hello();
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    for (auto val : s)
        if (val == '1')
            ++cnt;
    vector <int> st1(n + 1);
    vector <int> st2(n + 1);

    int st = 1;
    for (int i = 0; i <= n; ++i)
    {
        if (cnt > 1)
        {
            st1[i] = st % (cnt - 1);
            st = st * 2 % (cnt - 1);
        }
        else
            st1[i] = -1;
        
    }
    st = 1;
    for (int i = 0; i <= n; ++i)
    {
        st2[i] = st % (cnt + 1);
        st = st * 2 % (cnt + 1);
    }

    int val1 = 0;
    int val2 = 0;
    for (int i = 0; i < n; ++i)
        if (s[i] == '1')
        {
            val1 += st1[n - i - 1];
            val2 += st2[n - i - 1];
            if (cnt > 1)
                val1 %= (cnt - 1);
            val2 %= (cnt + 1);
        }
    // cout << val1 << " " << val2 << endl;
    for (int i = 0; i < n; ++i)
    {
        int ind = n - i - 1;
        int val = 0;
        int res = 1;
        if (s[i] == '1')
        {
            if (st1[ind] == -1)
            {
                cout << 0 << endl;
                continue;
            }
            val = (val1 - st1[ind] + (cnt - 1)) % (cnt - 1);
        }
        else
        {
            val = (val2 + st2[ind]) % (cnt + 1);
        }

        // cout << val << endl;

        while (val != 0)
        {
            ++res;
            val = val % __builtin_popcount(val);
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 5192
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define N 500055
//#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,a[N],b[N],d[N],q,x;
signed main(){
	n=read();d[0]=read();
	F(i,1,n) a[i]=read();
	F(i,1,n) d[i]=min(abs(d[i-1]-a[i]),d[i-1]);
	b[n+1]=1;
	D(i,n,0) 
	b[i]=((b[i+1]*2<=a[i])?b[i+1]:b[i+1]+a[i]);
	q=read();
	F(i,1,q){
		x=read();
		if (d[x-1]>=b[x+1]) puts("YES");
		else puts("NO");
	}
	return 0;
}

Measured memory_bytes: 7808
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
    
    int a;
    char s[9999];
    
    scanf("%d %s", &a, s);
    
    if(a>=3200){
        
        printf("%s", s);
        return 0;
        
    }
    
    printf("red");
    return 0;
    
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, 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; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int n, m;
	cin >> n >> m;

	vi h(n + 1);
	Rep(i, n + 1) cin >> h[i];

	vb ok(n + 1, true);
	rep(i, m) {
		int a, b;
		cin >> a >> b;

		if (h[a] <= h[b]) ok[a] = false;
		if (h[b] <= h[a]) ok[b] = false;
	}

	int cnt = 0;
	Rep(i, n + 1) {
		if (ok[i]) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3708
#include <iostream>
using namespace std;
int main(void){
    
    
    //あなたの手持ちの金額 「 m 」、Ａ君の手持ちの金額 「 f 」、本の値段 「 b 」と置く
    int m, f, b;
    
    //入力：Ａ君がもらった金額 「 a 」、Ｂ君がもらった金額 「 b 」を入力する
    cin >> m >> f >> b;
    
    //今回の条件は３つある以下に書く
    //⑴自分の手持ち金額で本を買うとき
    //⑵Ａ君の手持ちの金額を借りて本を買うとき
    //⑶本を買えないとき
    
    if(m + f < b) cout << "NA" << endl;
    else if(m > b) cout << 0 << endl;
    else cout << b - m << endl;
    
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <fstream>
#include <queue>
#include <cstdio>
#include <deque>
#include <map>
#define fol(i,n) for(int i=0;i<n;i++)
#define db(a) cout << a<< endl;
using namespace std;

int main(){
    string s;
    int K,n;
    vector < pair<int,int> > Val={};
    cin >>s>>K;
    fol(i,s.size()){
        n= (int)('{'-s[i])%26;
        if (n<=K) {s[i]='a';K-=n;}
        if (i==s.size()-1) s[i] = s[i]+K%26;
        if (K==0) break;
    }
    cout << s <<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)  
#define rep(i,n) for(long long int (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long int (i)=(a); (i)<=(b); ++(i))
#define INF 0xFFFFFF
#define endl '\n'
const unsigned int mod = 1e9+7;
const int maxInt = 2147483647;
const int mx=303;
int n;double dp[mx][mx][mx];
double calc(int i,int j,int k){
	if(!i && !j && !k)return 0.0;
	if(dp[i][j][k]>0)return dp[i][j][k];
	int l=i+j+k;
	double ret=1.0*n/l;
	if(i)ret+=1.0*i/l*calc(i-1,j,k);
	if(j)ret+=1.0*j/l*calc(i+1,j-1,k);
	if(k)ret+=1.0*k/l*calc(i,j+1,k-1);
	dp[i][j][k]=ret;
	return ret;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n;
    int cnt[4]={};
    rep(i,n){
    	int a;cin >> a;
    	++cnt[a];
    }
    rep(i,mx)rep(j,mx)rep(k,mx)dp[i][j][k]=0;
    cout <<fixed << setprecision(11)<< calc(cnt[1],cnt[2],cnt[3]) << endl;
    return 0;
}






























Measured memory_bytes: 217728
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int dm = 1 << 17;
char *dn = cn, * di = dn, * owad = dn + dm - 20;
inline void putint(int X) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	int dig = 1;
	if (X >= 10000) {
		if (X >= 100000) dig = 6;
		else dig = 5;
	}
	else {
		if (X >= 1000) dig = 4;
		else if (X >= 100) dig = 3;
		else if (X >= 10) dig = 2;
	}
	rep1(i, dig) {
		di[dig - i] = '0' + X % 10;
		X /= 10;
	}
	di[dig] = '\n';
	di += dig + 1;
}
const int bm = 500001;
int BIT[bm];
void add(int A) {
	while (A > 0) {
		BIT[A]++;
		A -= A & -A;
	}
}
int query(int A) {
	int ret = 0;
	while (A < bm) {
		ret += BIT[A];
		A += A & -A;
	}
	return ret;
}
int L[500001], R[500001], C[500001], ne[500001];
int are[500001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), Q = getint();
	rep1(i, N) C[i] = getint();
	rep1(i, Q) {
		L[i] = getint();
		int r = getint();
		ne[i] = R[r];
		R[r] = i;
	}
	rep1(i, N) {
		if (are[C[i]]) add(are[C[i]]);
		are[C[i]] = i;
		
		for (int r = R[i]; r; r = ne[r]) {
			L[r] = i - L[r] - query(L[r]) + 1;
		}
	}

	rep1(i, Q) putint(L[i]);
	fwrite(dn, 1, di - dn, stdout);


	Would you please return 0;
}

Measured memory_bytes: 14936
#include <iostream>
#include <cmath>

using namespace std;

int n;

double xa,xb,xc,xd,ya,yb,yc,yd,ta,tb,tc,td;

int main(){

	int i;

	cin >> n;

	for(i=0;i<n;i++){

		cin >> xa >> ya >> xb >> yb >> xc >> yc >> xd >> yd;

		ta = xa - xb;

		tb = ya - yb;

		tc = xc - xd;

		td = yc - yd;

		if(tc/td == ta/tb) cout << "YES" << endl;

		else if(ta == -tc && tb == -td) cout << "YES" << endl;
		else cout << "NO" << endl;

	}

	return 0;

}

Measured memory_bytes: 0
from sys import stdin
inp = lambda : stdin.readline().strip()

n = int(inp())
a = [0]*10**5
for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            a[i**2 + j**2 + k**2 + i*j + i*k + k*j] += 1
for i in a[1:n+1]:
    print(i) 

Measured memory_bytes: 75372
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,u,v;
  cin>>N>>u>>v;
  u--;v--;
  int log2N=int(log2(N))+1;
  // cerr<<log2N;
  vector<int> c[N];
  REP(i,N-1){
    int A,B;
    cin>>A>>B;
    A--;B--;
    c[A].push_back(B);
    c[B].push_back(A);
  }
  vector<int> d(N,-1);
  vector<vector<int> > parent(N,vector<int>(log2N,-1));
  queue<int> q;
  q.push(v);
  d[v]=0;
  while(!q.empty()){
    int p=q.front();
    q.pop();
    for(auto e:c[p]){
      if(d[e]==-1){
        d[e]=d[p]+1;
        parent[e][0]=p;
        FOR(i,1,log2N){
          if(parent[e][i-1]<0)parent[e][i]=-1;
          else parent[e][i]=parent[parent[e][i-1]][i-1];
        }
        q.push(e);
      }
    }
  }
  // REP(i,N)cerr<<d[i]<<" "<<endl;
  auto LCA=[=](int a,int b){
    if(d[a]>d[b])swap(a,b);
    int dif=d[b]-d[a];
    REP(i,log2N){
      if(dif==0)break;
      if(dif%2)b=parent[b][i];
      dif/=2;
    }
    
    if(a==b)return a;
    for(int i=log2N-1;i>=0;i--){
      if(parent[a][i]==parent[b][i])continue;
      a=parent[a][i];
      b=parent[b][i];
    }
    return parent[a][0];
  };
  set<int> s;
  REP(i,N)if(c[i].size()==1)s.insert(i);
  int ans=0;
  for(auto e:s){
    int ca=LCA(e,u);
    // cerr<<e<<" "<<ca<<endl;
    if(u==ca){
      ans=max(ans,d[e]-1);
    }
    else if(d[u]-d[ca]>=d[ca])continue;
    else{
      ans=max(ans,d[e]-1);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 29312
#include<bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
typedef long long ll;
typedef vector<int> VI;
typedef vector<set<int>> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef set<int> SI;
typedef map<string, int> MSI;
typedef map<int, int> MII;
typedef pair<ll, ll> PLL;
typedef pair<ll, pair<ll, ll>> PLLL;

#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MP make_pair
#define PB push_back
#define FF first
#define SS second
#define mod 1000000007
#define test ll t;cin>>t;while(t--)

void dfs(int n,VVI &al,VI &vis,int &c)
{
	vis[n]=1;c++;
	int s=al[n].size();
	auto it = al[n].begin();
	while(it!=al[n].end())
	{
		
		if(vis[*it]==0)
		{
			dfs(*it,al,vis,c);
		}
		it++;

	}
}
void solve()
{
	int n,m;
	cin >> n >> m;
	VVI al(n+1);
	VI vis(n+1);

	for(int i=0;i<m;i++)
	{
		int x,y;
		cin >> x >> y;
		al[x].insert(y);
		al[y].insert(x);
	}
	int ans=-1;
	for(int i=1;i<=n;i++)
	{
		
		int c=0;
		if(vis[i]==0)
		dfs(i,al,vis,c);
		
		ans=max(ans,c);
	}
	cout << ans;
	


	return;
}

int main()
{
	flash;

	// test
	// {
	// 	solve();
	// }
	solve();

	return 0;
}


Measured memory_bytes: 44624
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=3000+5;
int n,m,arr[N][N],k;
ll mem[N][N][5];
ll solve(int r,int c,int cnt){
     if(r==n-1&&c==m-1){

        if(cnt!=3)
            return arr[r][c];
        else
            return 0;
     }

     ll &ret=mem[r][c][cnt];
     if(ret!=-1) return ret;
     ll ans=0;
     if(c+1<m){

        ans=max(ans,solve(r,c+1,cnt));
        if(cnt!=3)
        ans=max(ans,arr[r][c]+solve(r,c+1,cnt+1));
     }
     if(r+1<n){
        ans=max(ans,solve(r+1,c,0));
        if(cnt!=3)
        ans=max(ans,arr[r][c]+solve(r+1,c,0));
     }
     return ret=ans;

}
int main(){
    GO();

    cin>>n>>m>>k;
    for(int i=0;i<k;i++){
        int r,c,vv;
        cin>>r>>c>>vv;
        r--;
        c--;
        arr[r][c]=vv;
    }
    clr(mem,-1);
    cout<<solve(0,0,0)<<"\n";
}





































































































































































































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

const int N = 100001;
long long arr[N];

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int k; cin >> k;
    for(int i = 0; i < k; ++i) cin >> arr[i];
    long long l = 2, r = 2, ll, rr; bool flag = true;
    for(int i = k - 1; ~i; --i){
        ll = ceil(1.0 * l / arr[i]) * arr[i];
        rr = floor(1.0 * r / arr[i]) * arr[i] + arr[i] - 1;
        if(r < ll) flag = false;
        l = ll, r = rr;
    }
    if(flag) cout << l << " " << r << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    string s;
    cin>>s;
    if(s[s.size()-1] == 's')
    {
        s += "es";
    }
    else s += "s";
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3636
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  ll N;
  cin >> N;
  vector<ll> h(N);
  for(int i=0;i<N;i++){
    cin >> h[i];
  }
  vector<ll> dp(N+10, INFL);
  dp[0]=0;

  for(int i=0;i<N;i++){
    dp[i+1]=min(dp[i+1],abs(h[i+1]-h[i])+dp[i]);
    dp[i+2]=min(dp[i+2],abs(h[i+2]-h[i])+dp[i]);
  }
  /*
  rep(i,N){
    cout << dp[i]<<endl;
  }*/
  cout << dp[N-1] <<endl;
}


Measured memory_bytes: 1792
n = int(input())
A = list(map(int,input().split()))

A.sort(reverse = True)

ans = A[0]
if n%2 == 0:
    ind = 1
    for i in range((n-2)//2):
        ans += 2*A[ind]
        ind += 1
else:
    ind = 1
    for i in range((n-2)//2):
        ans += 2*A[ind]
        ind += 1
    ans += A[ind]
print(ans)

Measured memory_bytes: 105116
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 100100100;

 
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  int ans=0;
  rep(i,n){
    while(i+1<n && a[i] == a[i+1]) i++;

    if(i+1 < n && a[i]<a[i+1]){
      while(i+1<n && a[i]<=a[i+1]) i++;
    }

    else if(i+1<n && a[i]>a[i+1]){
      while(i+1<n && a[i]>=a[i+1]) i++;
    }
    ans++;
  }
  cout << ans << endl;
}


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

int main(){
 
  string N;
  cin >> N;
  
  if(N.at(N.size() - 1) == '3'){
    cout << "bon" << endl;
    return 0;
  }else if(N.at(N.size() - 1) == '0' || N.at(N.size() - 1) == '1' || N.at(N.size() - 1) == '6' || N.at(N.size() - 1) == '8'){
    cout << "pon" << endl;
    return 0;
  }else{
    cout << "hon" << endl;
    return 0;
  }
  return 0;
}

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

using namespace std;

typedef vector<int> vec;
typedef vector<vec> Graph;

Graph G(110);
int T,In[110],Out[110];
bool used[110];

void dfs(int x)
{
	used[x]=true;
	In[x]=++T;
	for(int i=0;i<G[x].size();i++)
		if(!used[G[x][i]])
			dfs(G[x][i]);
	Out[x]=++T;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int u,t;
		scanf("%d%d",&u,&t);
		for(int j=0;j<t;j++)
		{
			int v;
			scanf("%d",&v);
			G[u].push_back(v);
		}
	}
	memset(used,false,sizeof(used));
	T=0;
	for(int i=1;i<=n;i++)
		if(!used[i])
			dfs(i);
	for(int i=1;i<=n;i++)
		printf("%d %d %d\n",i,In[i],Out[i]);
	return 0;
}

Measured memory_bytes: 3232
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <random>
 
using namespace std;

typedef long long ll;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()

mt19937 rnd(1337);

int main() {
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int a, b;
    cin >> a >> b;
    for (int i = b - a + 1; i <= b + a - 1; ++i)
        cout << i << ' ';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int N = 100010;
int n, val[N], res, cnt[20], Get, dp[1 << 17], st[20];
bool check(int s)
{
	int cnt = 0;
	while(s)
	{
		int t = s & 1;
		s >>= 1;
		if(st[cnt] == 0 && t) return false;
		cnt ++;
	}
	return true;
}
int Solve(int s)
{
	if(s == 0) return 0;
	if(dp[s] != 0x3f3f3f3f) return dp[s];
	for(int i=1;i<=15;i++)
	{
		for(int j=i+1;j<=15;j++)
		{
			if((s >> i & 1) && (s >> j & 1))
			{
				int t = i ^ j;
				int p = s ^ (1 << i) ^ (1 << j) ^ (1 << t);
				if(s >> t & 1) dp[s] = std:: min(dp[s], Solve(p) + 2);
				else dp[s] = std:: min(dp[s], Solve(p) + 1);
			}
		}
	}
	return dp[s];
}
int main() 
{
	scanf("%d", &n);
	for(int i=1;i<n;i++)
	{
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		val[u] ^= w; val[v] ^= w; 
	}
	for(int i=0;i<n;i++) cnt[val[i]] ++;
	for(int i=1;i<=15;i++) 
	{
		res += cnt[i] / 2;
		if(cnt[i] & 1) Get |= (1 << i), st[i] = 1;
	}
	memset(dp, 0x3f3f3f3f, sizeof(dp));
	printf("%d\n", res + Solve(Get));
	return 0;
}

Measured memory_bytes: 4732
#include<bits/stdc++.h>
#define MAX 5000
#define MOD 1000000007
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int n;
	cin>>n;
	vector<int> v(n);
	int ans = 0;
	for(int i=0;i<n;++i)
	{
		cin>>v[i];
		for(int j=i-1;j>=0;--j)
		{
			for(int k=j-1;k>=0;--k)
			{
				if(v[i]==v[k]||v[i]==v[j]||v[k]==v[j])
					continue;
				if(v[i]+v[k]>v[j]&&v[i]+v[j]>v[k]&&v[j]+v[k]>v[i])
					ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N, Q;
    string s;
    cin >> N >> Q >> s;
    vector<pair<char, char>> jumon;
    Rep (i, Q) {
        char t, d;
        cin >> t >> d;
        jumon.push_back({t, d});
    }

    s = 'x' + s + 'x';
    // cout << s << "\n";

    ll ans = N;

    ll ok = 0, ng = N+1;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        ll now = mid;
        Rep (i, Q) {
            if (s[mid] == jumon[i].first) {
                if (jumon[i].second == 'L') {
                    mid--;
                } else {
                    mid++;
                }
            }
        }
        if (mid == 0) {
            ok = now;
        } else {
            ng = now;
        }
    }

    // cout << ok << " " << ng << "\n";
    
    ans -= ok;

    ok = N+1, ng = 0;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        ll now = mid;
        Rep (i, Q) {
            if (s[mid] == jumon[i].first) {
                if (jumon[i].second == 'L') {
                    mid--;
                } else {
                    mid++;
                }
            }
        }
        if (mid == N+1) {
            ok = now;
        } else {
            ng = now;
        }
    }

    // cout << ok << " " << ng << "\n";

    ans -= N+1-ok;

    cout << ans << endl;
}

Measured memory_bytes: 1100
import java.util.Scanner;
class Main{
	public static void main(String[]args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		String str=sc.next();
		String ans[]=new String[a];
		int countJ=0;
		int countF=0;
		for(int i=0;i<a;i++) {
			char ch=str.charAt(i);
			if(ch=='c') {
				ans[i]="No";
			}
			if(ch=='a') {
				if(countJ+countF<b+c) {
					countJ++;
					ans[i]="Yes";
				}
				else {
					ans[i]="No";
				}
			}
			if(ch=='b') {
				if(countJ+countF<b+c) {
					if(countF<c) {
						countF++;
						ans[i]="Yes";
					}
					else {
						ans[i]="No";
					}
				}
				else {
					ans[i]="No";
				}
			}
		}
		for(int i=0;i<a;i++) {
			System.out.println(ans[i]);
		}
	}
}

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

using namespace std;


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int alice = 0, bob = 0;
    sort(a.rbegin(), a.rend());
    for(int i = 0; i < n; i++) {
        if(i % 2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }
    cout << alice - bob << "\n";
    return 0;
}

Measured memory_bytes: 3584
import scala.annotation.tailrec
object Main extends App {

  import scala.io.StdIn._

  solve
  @tailrec
  def solve: Unit = {
    val first = readLine
    if (first == null) return
    val (sets, suspects) = parseSet(first.split(' ').toList)
    implicit val set = sets
    val expression = readLine.trim match {
      case Expression(e) ⇒ println(suspects.filter(i ⇒ e(i)).let{
        case Nil ⇒ "NULL"
        case l ⇒ l.mkString(" ")
      })
      case _ ⇒ ???
    }
    solve
  }
  @tailrec
  def parseSet(line: List[String], sets: Map[Char, Int ⇒ Boolean] = Map.empty.withDefault(_ ⇒ _ ⇒ false), factors: List[Int] = Nil): (Char ⇒ Int ⇒ Boolean, List[Int]) = {
    line match {
      case "R"::_ => (sets, factors.distinct.sorted)
      case c::_ ⇒ val elements = readLine.trim.split(' ').map(_.toInt).sorted
        parseSet(readLine.trim.split(' ').toList, sets + (c.head, i ⇒ sortedContains(elements, i)), elements ++: factors)
      case _ ⇒ ???
    }
  }

  object Expression{
    def unapply(arg: String)(implicit set: Char => Int => Boolean): Option[Int ⇒ Boolean] = {
      arg.toList match {
        case s Second Nil ⇒ Some(s)
        case _ ⇒ ???
      }
    }
  }
  object First {
    def unapply(arg: List[Char])(implicit set: Char ⇒ Int ⇒ Boolean): Option[(Int ⇒ Boolean, List[Char])] = {
      arg match {
        case '('::(in Second ')'::t) ⇒ Some(in, t)
        case 'c'::(f First t) ⇒ Some(!f(_), t)
        case c::t if c.isUpper⇒ Some(set(c), t)
        case _ ⇒ None
      }
    }
  }
  object Second{
    def unapply(arg: List[Char])(implicit set: Char => Int => Boolean): Option[(Int ⇒ Boolean, List[Char])] = {
      arg match {
        case f First t ⇒ Some(parseAll(t, f))
        case _ ⇒ None
      }
    }
    @tailrec
    private def parseAll(arg: List[Char], left: Int ⇒ Boolean)(implicit set: Char ⇒ Int ⇒ Boolean): (Int ⇒ Boolean, List[Char]) = {
      arg match {
        case 'u'::(s First t) ⇒ parseAll(t, i ⇒ left(i) || s(i))
        case 'i'::(s First t) ⇒ parseAll(t, i ⇒ left(i) && s(i))
        case 'd'::(s First t) ⇒ parseAll(t, i ⇒ left(i) && !s(i))
        case 's'::(s First t) ⇒ parseAll(t, i ⇒ left(i) ^ s(i))
        case _ ⇒ (left, arg)
      }
    }
  }
  def sortedContains(array: Array[Int], target: Int): Boolean = {
    val i = lowerBound(array, target)
    if (array.indices.contains(i)) array(i) == target
    else false
  }
  def lowerBound(array: Array[Int], target: Int): Int = {
    var left = 0
    var right = array.length
    while(left < right){
      val mid = (left + right) / 2
      if (array(mid) < target){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }

  implicit class Extension[T](value :T){
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}


Measured memory_bytes: 44520
#include <iostream>
#include <cmath>
/*
100
105
111
117
123
130
*/
int main()
{
    int Debt = 100000;
    int Round = 1000;
    Debt /= Round;
    int week;
    std::cin >> week;
    for(int i = 0; i < week; ++i){
        Debt = std::ceil(Debt*1.05);
    }
    Debt *= Round;
    std::cout << Debt << std::endl;
    return 0;
}

Measured memory_bytes: 3088
#include <iostream>
using namespace std;
int main(){
string s;
cin >> s;
int ans;
if(s == "SUN")ans = 7;
else if(s == "MON")ans = 6;
else if(s == "TUE")ans = 5;
else if(s == "WED")ans = 4;
else if(s == "THU")ans = 3;
 else if(s == "FRI")ans = 2;
 else if(s == "SAT")ans = 1;
 cout << ans << endl;
 }

Measured memory_bytes: 256