akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <complex>
#include <vector>
using namespace std;
typedef complex<double> P;
const double PI=3.141592653589793238462643383279;

bool inC(P p, P c, double r){return abs(p-c)<r+1e-9;}

P getE(P p){return p/abs(p);}

double sq(double x){ return  x*x;}

int main(){
    int n,i,j,k,ans,cnt;
    double x, y;
    while(scanf("%d",&n)){
        if(n==0) break;
        ans=0;
        vector<P> ps(n);
        for(i=0; i<n; i++){
            scanf("%lf%lf",&x,&y);
            ps[i] = P(x,y);
        }
        for(i=0;i<n;i++)
            for(j=i+1;j<n;j++)if(abs(ps[i]-ps[j])<2){
                double d=sqrt(1-sq(abs(ps[j]-ps[i])*0.5));
                P c1=0.5*(ps[i]+ps[j])+getE(getE(ps[j]-ps[i]))*polar(d,PI/2);
                P c2=0.5*(ps[i]+ps[j])+getE(getE(ps[j]-ps[i]))*polar(d,-PI/2);
                cnt=0;
                for(k=0;k<n;k++)if(inC(ps[k],c1,1.0))cnt++;
                if(cnt>ans)ans=cnt;
                cnt=0;
                for(k=0;k<n;k++)if(inC(ps[k],c2,1.0))cnt++;
                if(cnt>ans)ans=cnt;
            }
        if(ans==0) ans++;
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 876
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N>>Q;
    vec a(0);
    rep(i,N) cin>>A, a.push_back(A);
    vec tak((N+1)/2,0);
    ll id = 0;
    Rrep(i,N){
        if((N - 1 - i)%2 == 0){
            tak[id] = a[i] + (id == 0 ? 0 : tak[id - 1]);
            ++id;
        }
    }
    vec sum(N);
    rep(i,N) sum[i] = a[N - 1 - i] + (i == 0 ? 0 : sum[i-1]);
    ll X;
    rep(i,Q){
        cin>>X;
        ll lb = 0, ub = 3e+9;
        while(ub - lb > 1){
            ll cen = (ub + lb)/2;
            auto left = lower_bound(ALL(a), X - (cen + 1)/2), right = upper_bound(ALL(a), X + cen/2);
            ll range = right - left, moreR = a.end() - right;
            if(range == moreR || range + 1 == moreR) {
                K = moreR;
                break;
            }
            (moreR > range ? lb : ub) = cen;
        }
        if(K != 0 && X < a[N - 2]) cout<<sum[K - 1] + tak[(N-1)/2] - tak[K - 1]<<endl;
        else cout<<tak[(N - 1)/2]<<endl;
        //cout<<K<<endl;
    }
    /*rep(i,N) cout<<sum[i]<<' ';
    cout<<endl;
    rep(i,(N+1)/2) cout<<tak[i]<<' ';
    cout<<endl;*/
}

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

int main()
{
    int n;

    cin >> n;

    vector<string> a(n);

    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());

    cout << a.size() << endl;
}

Measured memory_bytes: 9596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n; cin >> n;
    VI p(n); cin >> p;

    VI a(n), b(n), ar(n, 0), br(n, 0);
    FOR(i, 0, n) {
        a[i] = i + 1;
        b[i] = n - i;
    }

    FOR(i, 0, n) {
        ar[p[i] - 1] += i;
        br[p[i] - 1] += i;
    }
    FOR(i, 0, n - 1)ar[i + 1] += ar[i];
    rFOR(i, 1, n)br[i - 1] += br[i];

    FOR(i, 0, n)cout << a[i] + ar[i] << (i == n - 1 ? "\n" : " ");
    FOR(i, 0, n)cout << b[i] + br[i] << (i == n - 1 ? "\n" : " ");
    //FOR(i, 0, n)cout << a[i] + ar[i] + b[i] + br[i] << (i == n - 1 ? "\n" : " ");
}

Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>
#include <sstream>

using namespace std;

struct bills {
    int a = 0, b = 0, c = 0;
    int poss = 0;
};

class abc085_c {
public:
    void solve(istream& in, ostream& out) {
        int N, Y;
        in >> N >> Y;
        Y /= 1000;
        vector<bills> dp(Y + 1);
        dp[0].poss = 1;
        for (int i = 0; i < N; ++i) {
            vector<bills> nxt(Y + 1);
            for (int j = 0; j <= Y; ++j) {
                if (dp[j].poss) {
                    if (j + 1 <= Y) {
                        nxt[j + 1] = dp[j];
                        nxt[j + 1].c += 1;
                    }
                    if (j + 5 <= Y) {
                        nxt[j + 5] = dp[j];
                        nxt[j + 5].b += 1;
                    }
                    if (j + 10 <= Y) {
                        nxt[j + 10] = dp[j];
                        nxt[j + 10].a += 1;
                    }
                }
            }
            dp = nxt;
        }
        if (dp[Y].poss) {
            out << dp[Y].a << " " << dp[Y].b << " " << dp[Y].c << "\n";
        } else {
            out << "-1 -1 -1\n";
        }
    }
};


int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	abc085_c solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 896
@n=gets.to_i
def sitigo(s)
    return 0 if s.to_i>@n
    f=[false,false,false]
    s.chars.each{|c|f[(c.to_i-3)/2]=true}
    return ((f.all?)?1:0)+sitigo(s+'3')+sitigo(s+'5')+sitigo(s+'7')
end
p sitigo('')

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

int main () {
    string S;
    cin >> S;
    if (S[0] == S[1]) {
        cout << "Bad" << endl;
    }
    else if (S[1] == S[2]) {
        cout << "Bad" << endl;
    }
    else if (S[2] == S[3]) {
        cout << "Bad" << endl;
    }
    else {
        cout << "Good" << endl;
    }
}

Measured memory_bytes: 256
class Number:
    def __init__(self,number,qty):
        self.qty=qty
        self.number=number

n,k=map(int,input().split())
listn=[]
for a in range(n):
    b,c=map(int,input().split())
    listn.append(Number(b,c))
listn.sort(key=lambda x:x.number)
count=k
for a in listn:
    if a.qty>=count:
        print(a.number)
        break
    else:
        count-=a.qty


Measured memory_bytes: 28452
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
int main()
{
	int ans=0, x,n,min1=N;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		min1=min(min1,x);
		if(x<=min1)ans++;
	}
	cout<<ans;

    return 0;
}


Measured memory_bytes: 384
import copy
from collections import defaultdict
N, M = map(int, input().split())
ac = []

dp = defaultdict(lambda: 10 ** 5 + 1)
# dp = {}

for _ in range(M):
    # ab.append(tuple(map(int, input().split())))
    ac.append([int(input().split()[0]), frozenset(map(int, input().split()))])

ac.sort()
for a, cs in ac:
    if dp[cs] > a:
    # if cs not in dp or dp[cs] > a:
        dp[cs] = a
        dp2 = copy.copy(dp)
        for k, v in dp2.items():
            # if not cs <= k:
            k |= cs
            dp[k] = min(v + a, dp[k])


ans = dp[frozenset(range(1, N + 1))]
if ans == 10 ** 5 + 1:
    ans = -1
print(ans)

Measured memory_bytes: 50268
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a[] = new int[5];
    for(int i = 0;i<5;i++){
      a[i] = sc.nextInt();
    }
    int k = sc.nextInt();
    for(int i = 0;i<4;i++){
      for(int j = i+1;j<5;j++){
        if(a[j] - a[i] > k){
          System.out.println(":(");
          return;
        }
      }
    }
    System.out.println("Yay!");
  }
}


Measured memory_bytes: 21844
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer arrays[] = new Integer[n];
        int stepCnt  = 0;
        int stepSize = 101;

        for (int i = 0; i < arrays.length; i++) {
            arrays[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(arrays, Collections.reverseOrder());

        for(int size:arrays) {
            if(stepSize > size) {
                stepCnt++;
                stepSize = size;
            }
        }
        System.out.println(stepCnt);

    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a=0, b=0, c=0;
    char s[4];
    
    scanf("%s", s);
    rep(i, 3){
        if (s[i]=='a') {
            a++;
        } else if (s[i]=='b') {
            b++;
        } else if (s[i]=='c') {
            c++;
        }
    }
    
    if (a==1&&b==1&&c==1) {
        printf("Yes");
    } else {
        printf("No");
    }
    
    return 0;
}



Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
//#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    string s;cin>>s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}






Measured memory_bytes: 256
#
import sys
import math
import numpy as np
import itertools


# いくつか入力
n, m = (int(i) for i in input().split())  


# n行複数列の数をリストに
lr = [[int(i) for i in input().split()] for i in range(m)] 

l=1
r=n
for i in range(m):
    l=max(l,lr[i][0])
    r=min(r,lr[i][1])

#print(l,r)

a=r-l+1
if a < 0:
    a=0
print(a)



Measured memory_bytes: 30096
"use strict";

function main(input){
  const args = input.trim().split(' ').map(_=>parseInt(_, 10));
  const rects = [args[0]*args[1], args[2]*args[3]].sort((a,b)=>{return a-b;});
  console.log(rects[1]);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

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

namespace A.Add_Sub_Mul
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = AB[0];
            int B = AB[1];

            Console.WriteLine(Math.Max(A + B, Math.Max(A - B, A * B)));
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>

using namespace std;
int main(void){
  int X;
  int kyu;
  cin >> X;
  if (400 <= X && X <= 599) {
    kyu = 8;
  }
  else if (600 <= X && X <= 799) {
    kyu = 7;
  }
  else if (800 <= X && X <= 999) {
    kyu = 6;
  }
  else if (1000 <= X && X <= 1199) {
    kyu = 5;
  }
  else if (1200 <= X && X <= 1399) {
    kyu = 4;
  }
  else if (1400 <= X && X <= 1599) {
    kyu = 3;
  }
  else if (1600 <= X && X <= 1799) {
    kyu = 2;
  }
  else if (1800 <= X && X <= 1999) {
    kyu = 1;
  }
  cout << kyu << endl;
  return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
int W,a[100000],l[100000],r[100000],inf=1e8;
int main(){
	cin>>W;
	rep(i,W) cin>>a[i];
	int t=0;
	rep(i,W){
		if(a[i]==0){
			t=inf;
		}else if(a[i]<0){
			t=min(t-1,-a[i]);
		}else{
			t--;
			l[i]=max(0,min(a[i],t));
		}
	}
	t=0;
	for(int i=W-1;i>=0;i--){
		if(a[i]==0){
			t=inf;
		}else if(a[i]<0){
			t=min(t-1,-a[i]);
		}else{
			t--;
			r[i]=max(0,min(a[i],t));
		}
	}
	int ans=0;
	rep(i,W) ans+=max(l[i],r[i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 2336
N=int(input())
cnt=0
a=0
b=0
c=0
for i in range(N):
    S=input()
    if S[-1]=="A" and S[0]=="B":
        c+=1
    elif S[-1]=="A":
        a+=1
    elif S[0]=="B":
        b+=1
    cnt+=S.count("AB")
if a==0 and b==0:
    if c!=0:
        cnt+=c-1
else:
    cnt+=min(a,b)+c
print(cnt)

Measured memory_bytes: 3064
object Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import scala.collection.mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val A, B, C, K = sc.nextInt()
    val m = pow(2, K)
    val mx = max(max(A, B), C)

    val ans = A + B + C - mx + mx * m
    out.println(ans)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  def pow(x: Int, n: Int): Int = {
    n match {
      case 0 => 1
      case _ =>
        val r = pow(x * x, n / 2)
        if (n % 2 == 1) r * x else r
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

Measured memory_bytes: 25276
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            final int n = 5;
            int[] ar = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = in.nextInt();
            int k = in.nextInt();
            for (int i = 0; i < n - 1; i++)
                for (int j = i + 1; j < n; j++)
                    if (Math.abs(ar[i] - ar[j]) > k) {
                        out.println(":(");
                        return;
                    }
            out.println("Yay!");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}

Measured memory_bytes: 21460
import java.util.*;
import java.util.function.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int u = sc.nextInt();
    int v = sc.nextInt();
    int[] A = new int[N - 1];
    int[] B = new int[N - 1];
    for (int i = 0; i < N - 1; i++) {
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
    }
    sc.close();

    @SuppressWarnings("unchecked")
    List<Integer>[] tree = new List[N + 1];
    for (int i = 0; i < N - 1; i++) {
      if (tree[A[i]] == null) tree[A[i]] = new ArrayList<>();
      if (tree[B[i]] == null) tree[B[i]] = new ArrayList<>();
      tree[A[i]].add(B[i]);
      tree[B[i]].add(A[i]);
    }

    int[] du = dist(tree, N, u);
    int[] dv = dist(tree, N, v);
    int ans = 0;
    for (int i = 1; i < N + 1; i++)
      if (du[i] < dv[i]) ans = Integer.max(ans, dv[i]);
    System.out.println(ans - 1);
  }

  private static int[] dist(List<Integer>[] tree, int N, int s) {
    int[] d = new int[N + 1];
    Deque<Integer> q = new ArrayDeque<>();
    q.addLast(s);
    while (!q.isEmpty()) {
      int n = q.pollFirst();
      List<Integer> edge = tree[n];
      for (int e : edge)
        if (d[e] == 0 && e != s) {
          d[e] = d[n] + 1;
          q.addLast(e);
        }
    }
    return d;
  }
}

Measured memory_bytes: 80640
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    res = [0] * (n + 10)
    for x in range(1, int(pow(n, 0.5)) + 1):
        for y in range(1, int(pow(n, 0.5)) + 1):
            for z in range(1, int(pow(n, 0.5)) + 1):
                t = pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x
                if t <= n:
                    res[t] += 1

    for x in range(1, n + 1):
        print(res[x])


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 70104
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  swap(a, b);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << ((i < a) ^ (j < b));
    }
    cout << '\n';
  }
}


Measured memory_bytes: 1280
import itertools
n, q = map(int, input().split())
s = input()
cnt = [0] * n
for i in range(1, n):
    if s[i] == 'C' and s[i - 1] == 'A':
        cnt[i] = 1
cnt = list(itertools.accumulate(cnt))
for _ in range(q):
    l, r = map(int, input().split())
    print(cnt[r - 1] - cnt[l - 1])

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

int calc(int A) {
	string s = to_string(A);
	int res = 0;
	for(int i = 0; i < s.size(); ++i) {
		res += s[i] - '0';
	}
	return res;
}

void solve(long long N){
	int res = 100000;
	for(int A = 1; A < N; ++A) {
		res = min(res, calc(A) + calc(N - A));
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	solve(N);
	return 0;
}



Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  var input = input.split('\n');
  var N = parseInt(input[0]);
  // debug
  // console.log(inpu);
  var an = input[1].split(' ');
  an.map(e => Number(e));

  var total = 0;

  an.forEach(element => {
    total += parseInt(element);
  });

  var av = total / an.length;

  var dt = Math.abs(an[0] - av);
  var wk = dt;
  var idx = 0;
  for (var i = 0; i < an.length; i++) {
    dt = Math.abs(an[i] - av);
    if (dt === 0) {
      console.log('%d', i);
      return;
    }
    if (wk > dt) {
      wk = dt;
      idx = i; // 最小の添え字を保持
    }
  }

  console.log('%d', idx);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));




Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

int main() {
  int n, W;
  cin >> n >> W;
  vector<int> weight(n);
  vector<int> value(n);
  for (int i=0; i<n; i++) {
    cin >> weight[i] >> value[i];
  }
  int m = 100 * 300;
  m = accumulate(value.begin(), value.end(), 0);
  
  // dp[i+1][sumv]: i番目までの荷物の中での重さの最小値、価値がsumvのときの
  vector<vector<ll>> dp(n+5, vector<ll>(m+5, INT_MAX));
  
  // dp initialize
  for (int i=0; i<n+1; i++) {
    for (int sumv=0; sumv<=m; sumv++) {
      dp[i][sumv] = INT_MAX;
    }
  }

    
  dp[0][0] = 0;

  // dp loop
  for (int i=0; i<n; ++i) {
    for (int sumv=0; sumv<=m; ++sumv) {
      if (sumv >= value[i]) {
	dp[i+1][sumv] = min(dp[i][sumv-value[i]] + weight[i], dp[i][sumv]);
      } else {
	dp[i+1][sumv] = dp[i][sumv];
      }
    }
  }

  ll maxv = 0;
  for (int sumv=0; sumv<=m; ++sumv) {
    if (dp[n][sumv] <= W) {
      maxv = sumv;
    }
  }
  
  cout << maxv << endl;
  return 0;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    ll n, k, q; cin >> n >> k >> q;

    ll p[100010] = {0};

    for (ll i = 0; i < q; ++i) {
        ll a; cin >> a;
        a--;

        p[a]++;
    }

    for (ll i = 0; i < n; ++i) {
        if (k - (q - p[i]) > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    int n = s.size();
    if (n == 2) cout << s << endl;
    else {
        reverse(all(s));
        cout << s << endl;
    }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> data(n);
    rep(i,0,k){
        int d;
        cin >> d;
        rep(j,0,d){
            int a;
            cin >> a;
            data.at(a-1)++;
        }
    }
    int cnt=0;
    rep(i,0,n){
        if(data.at(i)==0){
            cnt++;
        }
    }
    cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long lld;
typedef long double llu;

vector<lld> C[256];
lld exist[256];

int main()
{
    std::ios::sync_with_stdio(false);
    lld t = 1;
    // cin >> t;
    while(t--) {
        string s, t;
        cin >> s >> t;

        for(lld i = 0; i < s.size(); i++) {
            lld id = s[i] - 'a';
            C[id].push_back(i);
            exist[id] = 1;
        }

        if(!exist[t[0] - 'a']) {
            cout << -1;
            return 0;
        }

        lld prev = 0;
        lld cnt = 0;
        for(lld i = 0; i < t.size(); i++) {
            lld id = t[i] - 'a';
            if(exist[id]) {
                auto it = lower_bound(C[id].begin(), C[id].end(), prev);
                if(it == C[id].end()) {
                    cnt++;
                    prev = 0;
                }
                prev = *lower_bound(C[id].begin(), C[id].end(), prev);
                prev++;

            } else {
                cout << -1;
                return 0;
            }
        }
        cout << (cnt * s.size()) + prev << "\n";
    }
}


Measured memory_bytes: 1736
import sys
input = sys.stdin.readline


def f(P, S, L, X, count):
    if L == 0:
        return count + P[0]

    if X == 1:
        return count
    elif X <= 1 + S[L-1]:
        return f(P, S, L-1, X-1, count)
    elif X == 1 + S[L-1] + 1:
        return count + P[L-1] + 1
    elif X <= 1 + S[L-1] + 1 + S[L-1]:
        return f(P, S, L-1, X-(1+S[L-1]+1), count+P[L-1]+1)
    else:
        return count + P[L]


def main():
    N, X = map(int, input().split())

    P = [0] * (N+1)
    S = [0] * (N+1)
    P[0] = 1
    S[0] = 1
    for i in range(N):
        P[i+1] = 2*P[i] + 1
        S[i+1] = 2*S[i] + 3

    ans = f(P, S, N, X, 0)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line;
        int i;
        int[] count = new int[26];
        while(sc.hasNextLine()) {
            line = sc.nextLine().toLowerCase();
            for (i = 0; i < line.length(); i++) {
                if (line.charAt(i) >= 'a' && line.charAt(i) <= 'z') count[line.charAt(i) - 'a'] += 1;
            }
        }
        for (i = 0; i < 26; i++) {
            System.out.print((char)(i + 'a'));
            System.out.println(" : " + count[i]);
        }
    }
}



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

int  main()
{
	int n; cin >> n;
	vector<int> a(n);
	vector<double> A(n);
	double sum = 0;
	rep(i, n)
	{
		cin >> a[i];
		A[i] = (double)1 / a[i];
		sum += A[i];
	}
	double ans = (double)1 / sum;
	printf("%.14f\n", ans);
	return (0);
}


Measured memory_bytes: 256
N, M = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(M)]

graph = [[False] * N for _ in range(N)]
for u, v in edges:
    graph[u - 1][v - 1] = True
    graph[v - 1][u - 1] = True

visited = [False] * N
visited[0] = True

def dfs(s):    
    if all(visited):
        return 1

    cnt = 0
    for i in range(N):
        if not graph[s][i]:
            continue
        
        if visited[i]:
            continue
            
        visited[i] = True
        cnt += dfs(i)
        visited[i] = False
        
    return cnt

print(dfs(0))

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int K; cin >> K;
  int A, B; cin >> A >> B;
  string result = "NG";
  rep(i,1000) if (A<=i*K&&B>=i*K) result = "OK";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3632
N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(M)]
es = [[] for i in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)

from collections import deque
mindist = N
opt = None
for g,tos in enumerate(es):
    for s in tos:
        q = deque([(s,0)])
        prev = [-1]*N
        dist = [N]*N
        dist[s] = 0
        while q:
            v,d = q.popleft()
            for to in es[v]:
                if to==g: break
                if d+1 >= dist[to]: continue
                dist[to] = d+1
                prev[to] = v
                q.append((to,d+1))
            else:
                continue
            break
        else:
            continue
        if d+1 >= mindist: continue
        mindist = d+1
        opt = [g,v]
        while prev[opt[-1]] >= 0:
            opt.append(prev[opt[-1]])
if opt:
    ans = [o+1 for o in opt]
    print(len(ans))
    print(*ans, sep='\n')
else:
    print(-1)

Measured memory_bytes: 3828
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	s := getInt64Sice(io.NextLine())
	n, a, b := s[0], s[1], s[2]
	sum := a + b
	div := n / sum
	amari := n % sum
	var over int64
	if a < amari {
		over = a
	} else {
		over = amari
	}
	total := div*a + over
	fmt.Println(total)
}

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt64() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintInt64(a []int64) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintFloat64(a []float64) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func getInt64Sice(arrStr string) []int64 {
	cols := strings.Split(arrStr, " ")
	a := make([]int64, len(cols))
	for i := 0; i < len(cols); i++ {
		v, err := strconv.ParseInt(cols[i], 10, 64)
		if err != nil {
			panic(err)
		}
		a[i] = v
	}
	return a
}

func getStrSice(arrStr string) []string {
	cols := strings.Split(arrStr, " ")
	a := make([]string, len(cols))
	for i := 0; i < len(cols); i++ {
		a[i] = cols[i]
	}
	return a
}

func getFloatSice(arrStr string) []float64 {
	cols := strings.Split(arrStr, " ")
	a := make([]float64, len(cols))
	for i := 0; i < len(cols); i++ {
		f, err := strconv.ParseFloat(cols[i], 64)
		if err != nil {
			panic(err)
		}
		a[i] = f
	}
	return a
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;

int main() {
	string s;
	while (cin >> s, s != "0") {
		int sum = 0;
		for (int i = 0; i < s.size(); ++i) {
			sum += s[i] - '0';
		}
		cout << sum << endl;
	}
	return 0;
}

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

const int MAX = 2100;
const int MOD = 1000000007;

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

void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

long long COM(int n, int k){
    if (n<k)return 0;
    if (n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
int main(){
    COMinit();
    int t;
    int a,b;
    cin >> a >> b;
    for(int i=1;i<=b;i++){
        if(i*2-1>a){
            cout << 0 << endl;
            continue;
        }
        if(i!=1)t=COM(b-1,i-1);
        else t=1;
        cout <<t*COM(a-b+1,a-b-i+1)%1000000007 << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1
typedef struct {
  int parent;
  int lchild;
  int rchild;
} Node;
Node t[25];
void preParse(int);
void inParse(int);
void postParse(int);
 
int main()
{
  int n,i,id,right,left;
  scanf("%d",&n);
  for(i=0; i<n; i++) t[i].parent=NIL;
  for(i=0; i<n; i++) {
    scanf("%d%d%d",&id,&left,&right);
    t[id].lchild=left; t[id].rchild=right;
    if(left!=NIL) t[left].parent=id;
    if(right!=NIL) t[right].parent=id;
  }
 
  for(i=0; ; i++) {
    if(t[i].parent==NIL) {
      printf("Preorder\n");
      preParse(i);
      printf("\nInorder\n");
      inParse(i);
      printf("\nPostorder\n");
      postParse(i);
      printf("\n");
      break;
    }
  }
  return 0;
}
 
void preParse(int u)
{
  if(u==NIL)  return;
  printf(" %d",u);
  preParse(t[u].lchild);
  preParse(t[u].rchild);
}
 
void inParse(int u)
{
  if(u==NIL) return;
  inParse(t[u].lchild);
  printf(" %d",u);
  inParse(t[u].rchild);
}
 
void postParse(int u)
{
  if(u==NIL) return;
  postParse(t[u].lchild);
  postParse(t[u].rchild);
  printf(" %d",u);
}

Measured memory_bytes: 616
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] s = new int[n];
		for(int i=0; i<n; i++){
			s[i] = in.nextInt();
		}
		Set<Integer> list = new HashSet<>();
		for(int i=1; i*i<=n; i++){
			if(n%i==0){
				list.add(i);
				list.add(n/i);
			}
		}
		list.remove(n);
		int max = 1;
		out:for(int t: list){
			for(int i=0; i<n-t; i++){
				if(s[i] != s[i+t]) continue out;
			}
			max = Math.max(n/t, max);
		}
		System.out.println(max);
	}
}

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

using namespace std;

vector<pair<long long, long long> > prime_fac(long long N){
    vector<pair<long long, long long> > res;

    for(long long i=2; i*i <= N; ++i){
        if( N%i != 0) continue;

        long long ex = 0;
        while( N%i == 0 ){
            ex++;
            N = N/i;
        }
        res.push_back({i, ex});
    }

    if( N != 1){
        res.push_back({N, 1});
    }
    return res;
}

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

    const auto &primes = prime_fac(n);
    long long ans = n;
    for(auto p: primes){
        ans *= (p.first -1.0);
        ans /= p.first;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
using namespace std;

int main (void) {
  int N;
  int ans=0;
  cin>> N;
  int A[N+2]={0};
  int B[N+2]={0};

  for (int i=1; i<=N; i++) {
    cin >> A[i];
  }
  for (int i=1; i<=N; i++) {
    cin >> B[i];
  }
  for (int i=1; i<=N; i++) {
    A[i]=A[i]+A[i-1];
  }
  for (int i=N; 1<=i; i--) {
    B[i]=B[i]+B[i+1];
  }

  for (int i=1; i<=N; i++) {  
    ans=max(ans,A[i]+B[i]);
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    int t = 0;
    bool flag = false;
    while (n--) {
        int d1, d2;
        cin >> d1 >> d2;
        if (d1 == d2) {
            t++;
        } else {
            t = 0;
        }
        if (t == 3) {
            flag = true;
        }
    }
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10**5)

class Node:
    # def __init__(self, val):
    def __init__(self):
        self.val = None
        self.color = None
        self.a = []

n = int(input())
nodes = []

for i in range(n):
    nodes.append(Node())
    # nodes.append(Node(i+1))

for i in range(n-1):
    u, v, w = map(int, input().split())
    node1 = nodes[u-1]
    node2 = nodes[v-1]
    node1.val = u
    node2.val = v
    node1.a.append([node2, w])
    node2.a.append([node1, w])

# for i in range(n):
#     node = nodes[i]
#     for pair in node.a:
#         print(pair[0])
#         print(pair[1])

root = nodes[0]
root.color = True
nodeSet = set()

def traverse(node, distance):
    if node in nodeSet:
        return
    else:
        nodeSet.add(node)
    # print('# traverse: ' + str(node.val))
    for pair in node.a:
        adjNode = pair[0]
        dis = pair[1]
        if (distance + dis) % 2 == 0:
            adjNode.color = root.color
        else:
            adjNode.color = not root.color
        traverse(adjNode, distance + dis)

traverse(root, 0)

for i in range(n):
    node = nodes[i]
    if node.color:
        print(1)
    else:
        print(0)


Measured memory_bytes: 101120
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

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

main = do
	[ w, h, n ] <- readInts
	queries <- replicateM n $ do
		[ x, y, a ] <- readInts
		return ( x, y, a )
	let	
		( x1, y1, x2, y2 ) = foldl solve ( 0, 0, w, h ) queries
	print $ ( max 0 $ x2 - x1 ) * ( max 0 $ y2 - y1 )

solve ( x1, y1, x2, y2 ) ( x, y, a )
	| a == 1 = ( ( max x1 x ), y1, x2, y2 )
	| a == 2 = ( x1, y1, ( min x2 x ), y2 )
	| a == 3 = ( x1, ( max y1 y ), x2, y2 )
	| a == 4 = ( x1, y1, x2, ( min y2 y ) )


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

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

const int INF = 1001001001;

int main()
{   
    int n;
    string s;
    cin >> n >> s;
    int r = 0, w = 0;
    rep(i, n) if(s[i]=='R') r++; 

    int ans = r;
    rep(i, n) {
        if(s[i]=='R') r--;
        else w++;
        int now = max(r, w);
        ans = min(ans, now);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int q;
ll x[100001];

void init() {
    for (int i = 1; i <= 100000; i++) x[i] = 1;
    for (int i = 1; i <= 100000; i++) {
        for (int j = i*2; j <= 100000; j += i) {
            if (x[j] > MOD) continue;
            x[j] *= i;
        }
    }
    for (int i = 1; i <= 100000; i++) {
        if (x[i] >= i*2) x[i] = 1;
        else x[i] = 0;
    }
    for (int i = 2; i <= 100000; i++) {
        x[i] += x[i-1];
    }
}

int main() {
    init();
    cin >> q;
    rep(i,q) {
        int a; cin >> a;
        cout << x[a]-x[1] << endl;
    }
}



Measured memory_bytes: 3892
#include <iostream>

using namespace std;
using LL = long long;

const LL INF = 1L << 32;

LL G[101][101];

int main() {

    int V, E;
    cin >> V >> E;

    //
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
            if (i == j) G[i][j] = 0;
            else G[i][j] = INF;
        }
    }

    for (int i = 0; i < E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        G[s][t] = d;
    }

    //
    bool negative_cycle = false;

    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            if (G[i][k] == INF) continue;
            for (int j = 0; j < V; j++) {
                if (G[k][j] == INF) continue;
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
                if (i == j && G[i][j] < 0) {
                    negative_cycle = true;
                    goto outer;
                }
            }
        }
    }
    outer:

    //
    if (negative_cycle) {
        cout << "NEGATIVE CYCLE" << endl;
    } else {
        for (int i = 0; i < V; i++) {
            int k = 0;
            for (int j = 0; j < V; j++) {
                if (k++) cout << " ";
                cout << (G[i][j] != INF ? to_string(G[i][j]) : "INF");
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3308
line=input()
line=line.split(" ")
 
a=int(line[0])
b=int(line[1])
c=int(line[2])
 
if a+b==c:
 print("Yes")
elif b+c==a:
 print("Yes")
elif c+a==b:
 print("Yes")
else:
 print("No")

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;

class Main {

    // Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        String S;
        S = sc.next();
        solve(S);
    }

    static void solve(String S){
        String ans = "";
        switch (S) {
            case "Sunny": ans = "Cloudy"; break;
            case "Cloudy": ans = "Rainy"; break;
            case "Rainy": ans = "Sunny"; break;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 20692
let split str delim =
  let rec doit s acc =
    match
      try Some (String.rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s1 (s2 :: acc)
  in
  doit str []

let () =
  let open Hashtbl in
  let n = read_int () in
  let tbl = create ~random:true n in
  let rec doit i =
    if i < n then begin
      match split (read_line ()) ' ' with
      | ["insert"; x] -> (add tbl x true; doit (i + 1))
      | ["find"; x] -> (print_endline (if mem tbl x then "yes" else "no"); doit (i + 1))
      | _ -> exit 1
    end
  in
  doit 0

Measured memory_bytes: 43884
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h=sc.nextInt();
        int w=sc.nextInt();
        System.out.println(charp(w+2));
        for(int i=0;i<h;i++){
            System.out.println("#"+sc.next()+"#");
        }
        System.out.println(charp(w+2));
    }
    static String charp(int input){
        String output="";
        for(int i=0;i<input;i++){
            output+="#";
        }
        return output;
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int gcd(int x, int y){int r;while((r=x%y)!=0)x=y,y=r;return y;}

int main(void){
    int i=0;
    int j=0;
    int n;
    scanf("%d",&n);
    int t[9<<14]={};
    int max=0;
    int scn=0;
    for(;i<n;i++){
        scanf("%d",&t[i]);
        if(t[i]>max)max=t[i];
    }
    for(;j<n;j++){
        if(abs(t[j]-max/2)<abs(scn-max/2))scn=t[j];
    }
    printf("%d %d\n",max,scn);
}

Measured memory_bytes: 2308