akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <random>
#include <iomanip>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

struct Edge {
  int from;
  int to;
  ll cost;
};

vector<ll> dijkstra(vector<vector<Edge>> &G, int start) {
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>> > Q;
  Q.push(mp(0, start));
  vector<ll> ret(G.size(), 1LL << 61);
  while(!Q.empty()) {
    pair<ll, int> P = Q.top(); Q.pop();
    int p = P.second;
    ll d = P.first;
    if (ret[p] <= d) continue;
    ret[p] = d;
    for(int i = 0; i < G[p].size(); i++) {
      int to = G[p][i].to;
      if (d + G[p][i].cost < ret[to]) {
        Q.push(mp(d + G[p][i].cost, to));
      }
    }
  }
  return ret;
}

int main() {
  int N, M, S, T;
  cin >> N >> M >> S >> T;
  S--, T--;
  vector<vector<Edge>> G1(N), G2(N);
  for(int i = 0; i < M; i++) {
    int u, v;
    ll a, b;
    cin >> u >> v >> a >> b;
    u--, v--;

    Edge e1 = {u, v, a};
    Edge e2 = {v, u, a};
    G1[u].push_back(e1);
    G1[v].push_back(e2);

    Edge e3 = {u, v, b};
    Edge e4 = {v, u, b};
    G2[u].push_back(e3);
    G2[v].push_back(e4);
  }
  vector<ll> d1 = dijkstra(G1, S);
  vector<ll> d2 = dijkstra(G2, T);

  vector<ll> ans(N);
  ll mi = 1LL << 61;
  for(int i = N - 1; i >= 0; i--) {
    mi = min(mi, d1[i] + d2[i]);
    ans[i] = mi;
  }

  for (int i = 0; i < N; i++) {
    cout << 1000000000000000LL - ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 19000
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String sl[] = s.split(" ");
            final int X = Integer.parseInt(sl[0]);
            final int t = Integer.parseInt(sl[1]);

            System.out.println(X - Math.min(X, t));
        }
    }
}


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

int main(){

    int n; cin >> n;
    vector<vector<int> > a(n, vector<int> (3));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            cin >> a[i][j];
        }
    }
    vector<int> score(n, 0);

    for(int j = 0; j < 3; j++){

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

            int cnt = 0;
            for(int k = 0; k < n; k++){
                if(a[i][j] == a[k][j]) cnt++;
            }

            if(cnt == 1) score[i] += a[i][j];
        }
        
    }

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


Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using ull = unsigned  long long ;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ull N;
    cin >> N;
    ull count = 0;
    if(N % 2  == 1){
        cout << 0 << endl;
        return 0;
    }else{
        ll tmp = 10;
        while(tmp <= N){
            count += N / tmp;
            tmp *= 5;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# D - Line++
# 標準入力の取得
N,X,Y = list(map(int, input().split()))

# 求解
# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|}であるため、
# (i, j)が決まれば、最短距離はO(1)で決まる。したがって、全(i, j)について、最短距離を求める。
k_list = [0 for i in range(1,N)]
for i in range(1, N):
    for j in range(i+1, N+1):
        min_path = min([abs(j-i), abs(X-i)+1+abs(j-Y)])
        k_list[min_path-1] += 1

# 結果出力
for k in k_list:
    print(k)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define CIN(A) int A; cin >> A;
#define CIN2(A, B) int A, B; cin >> A >> B;
#define CIN3(A, B, C) int A, B, C; cin >> A >> B >> C;
#define CINVEC(A, N) vector<int> A; REP(i, N) { int a; cin >> a; A.emplace_back(a); }
#define ANS(ans) cout << (ans) << endl
#define rsort(p, q) sort(p, q, greater<int>());

#define DEBUGV(V) REP(i, V.size()) cout << V.at(i) << " "; cout << endl 

int
main()
{
  CIN(N);
  CINVEC(W, N);

  int min = 101;
  REP(i, W.size()) {
    int a = 0, b = 0;
    for (int j = 0; j < i; j++) a += W.at(j);
    for (int j = i; j < W.size(); j++) b += W.at(j);
    if (abs(a - b) < min) min = abs(a - b);
  }

  ANS(min);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>
#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;

inline bool IN(int x, int y, int w, int h)
{
    return 0 <= x && x < w && 0 <= y && y < h;
}


int main()
{
	int a,b;
	while(cin >> a >>b){
		stringstream ss;
		ss << (a+b);
		cout << ss.str().size() << endl;

	}

	return 0;
}

Measured memory_bytes: 1212
import sys
import io


def run(input: io.TextIOBase, output: io.TextIOBase):
    nl = input.readline().split()
    n = int(nl[0])
    _ = int(nl[1])
    s = []
    for _ in range(0, n):
        s.append(input.readline().strip())
    s.sort()
    output.write("".join(s) + '\n')


if __name__ == '__main__':
    run(sys.stdin, sys.stdout)


Measured memory_bytes: 3060
#include <iostream>
#include <string.h>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>
#include <set>

using namespace std;

int main( void ) {

    int N;
    string S;
    cin >> N;
    cin >> S;

    int res = 1;
    for ( int i = 0; i < S.size() - 1; i++ ) {
        if ( S[i] != S[i + 1]) {
            res++;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 512
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        boolean[][] g = input();
        Boolean[] visited = new Boolean[g[0].length];
        Arrays.fill(visited,false);
        visited[0] = true;
        System.out.println(dfs(g,0,visited));
    }

    private static boolean[][] input(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[][] ret = new boolean[n][n];
        for(int i = 0; i < m;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            ret[a-1][b-1] = ret[b-1][a-1] = true;
        }
        sc.close();
        return ret;
    }

    private static int dfs(boolean[][] g, int s, Boolean[] bools){
        if(!Arrays.asList(bools).contains(false)){
            return 1;
        }
        int ans = 0;
        for(int i = 0; i < bools.length; i++){
            if(!g[s][i] || bools[i]) continue;
                bools[i] = true;
                ans += dfs(g,i,bools);
                bools[i] = false;
        }
        return ans;
    }
}


Measured memory_bytes: 21844
///
// File:  d.cpp
// Author: ymiyamoto
//
// Created on Sun Jan  7 21:59:59 2018
//

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main()
{
  int64_t N, H;
  cin >> N >> H;

  vector<int64_t> bs;
  int64_t max_a = 0;
  for (uint32_t i = 0; i < N; i++) {
    int64_t a, b;
    cin >> a >> b;
    bs.push_back(b);
    max_a = max(max_a, a);
  }

  sort(bs.begin(), bs.end(), greater<int64_t>());
  uint32_t count = 0;
  for (uint32_t i = 0; i < bs.size(); i++) {
    if (bs[i] > max_a) {
      H -= bs[i];
      count++;
      if (H <= 0) {
        cout << count << endl;
        return 0;
      }
    }
  }

  count += H / max_a;
  if ((H % max_a) != 0) {
    count++;
  }

  cout << count << endl;
  return 0;
}


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

namespace ABC173
{
    class D
    {
        static void Main(string[] args)
        {
            //var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray()
            var N = long.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(long.Parse).OrderByDescending(x => x).ToArray();

            var sum = A[0];
            var index = 1;
            for (int i = 1; i < N - 1; i++)
            {
                sum += A[index];
                if (i % 2 == 0)
                {
                    index++;
                }
            }
            //Console.WriteLine(string.Join(" ", A));
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 51560
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N, M;
  cin >> N >> M;
  vector<long> x(N);
  vector<long> y(N);
  vector<long> z(N);
  vector<vector<pair<long, long> > > foo(8);
  rep(i, N) {
    cin >> x[i] >> y[i] >> z[i];
  }
  rep(i, N) {
    for (long a = 0; a < 8; a++) {
      long sum = 0;
      sum += x[i] * ((a & 1) ? 1 : -1);
      sum += y[i] * ((a & 2) ? 1 : -1);
      sum += z[i] * ((a & 4) ? 1 : -1);
      foo[a].push_back(make_pair(sum, i));
    }
  }
  for (long a = 0; a < 8; a++) {
    sort(foo[a].rbegin(), foo[a].rend());
  }
  long ans = 0;
  for (long a = 0; a < 8; a++) {
    long tmp_x = 0;
    long tmp_y = 0;
    long tmp_z = 0;
    rep (i, M) {
      tmp_x += x[foo[a][i].second];
      tmp_y += y[foo[a][i].second];
      tmp_z += z[foo[a][i].second];
    }
    long tmp = abs(tmp_x) + abs(tmp_y) + abs(tmp_z);
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, D;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> D;

	int len = D * 2 + 1;
	int ans = (N + len - 1) / len;

	cout << ans << endl;
}







Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int n, r = 0;
	char s[101];
	scanf("%d%s", &n, s);
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {
			r++;
		}
	}
	if (n - r < r) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
const int mod = 1e9 + 7;
vector<int> adj[100005];
int dp[100005][2];
//0 - black 1 - white
int ans;
void dfs(int s,int p=-1)
{
  dp[s][1]=1;
  dp[s][0]=1;
  for(int u : adj[s])
  {
    if(u == p) continue;
    else{
      dfs(u,s);
      dp[s][1] *=dp[u][0];
      dp[s][1]%=mod;
      dp[s][0]*=(dp[u][0] + dp[u][1]);
      dp[s][0]%=mod;
    }
  }
}
signed main()
{
    IOS
    int n; cin>>n;
    int a,b;
    ans = 0;
    for(int i=0;i<n-1;i++)
    {
      cin>>a>>b;
      adj[a].pb(b);
      adj[b].pb(a);
    }
    dfs(1);
    // for(int i=1;i<=n;i++)
    // {
    //   cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
    // }
    cout<<((dp[1][0] + dp[1][1])%mod)<<endl;
    return 0;
}

Measured memory_bytes: 14208
#include <stdio.h>

int main(void)
{
	int H[10000], W[10000], h, i, j,c=0;
	for (i = 0; i < 10000; i++){
		scanf("%d %d", &H[i], &W[i]);
		if (H[i] == 0){
			break;
		}
		c++;
	}
	for (h = 0; h < c; h++){
		for (i = 1; i <= H[h]; i++){
			for (j = 1; j <= W[h]; j++){
				printf("#");
			}
			putchar('\n');
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1732
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();
		result(a,b);

	}

	//???????????¨?????????????????????
	private static void result(int a, int b){
		if(a>b){
			System.out.println("a > b");}
		else if(a<b){
		    System.out.println("a < b");}
		else{System.out.println("a == b");}
	}


}

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

int main(void){
    char str[200001];
    int i=0,len,ans=0,flag=0;
    scanf("%s",str);
    len=strlen(str);
    while(i<len){
        if(str[i]==str[i+1] && flag==0){
            i+=2;
            ans++;
            flag=1;
        }else if(str[i]==str[i+1] && flag==1){
            i++;
            ans++;
            flag=0;
        }else{
            i++;
            ans++;
            flag=0;
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;


void Main()
{
    string S;
    cin >> S;

    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }

}


int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

Measured memory_bytes: 256
n,k=map(int,input().split())
lst_1=list(map(int,input().split()))
# print(lst_1)
lst_2=[]
for i in range(n-k):
    temp=1
    temp=lst_1[i+k]/lst_1[i]
    lst_2.append(temp)
for i in lst_2:
    if i>1:
        print("Yes")
    else:print("No")


Measured memory_bytes: 31684
O=str(input())
E=str(input())
S=""
if len(O)==len(E):
  for i in range(len(O)):
    S=S+O[i]+E[i]
else:
  for i in range(len(O)-1):
    S=S+O[i]+E[i]
  S=S+O[len(O)-1]
print(S)

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl

using namespace std;

typedef long long ll;
typedef string str;

const ll MAXN = 1e5 + 10;
const ll MOD = 1000000000000037;

ll n, a[MAXN], ps[MAXN];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) ps[i] = ps[i - 1] + a[i];
	
	ll del = 0, x, ans = 0, res = MOD;
	for(int i = 1; i <= n; i++){
		if(i % 2 == 1){
			if(ps[i] + del >= 0){
			
				ans += (ps[i] + del + 1);
				del -= (ps[i] + del + 1);
			}
		} else {
			if(ps[i] + del <= 0){
				x = -(ps[i] + del) + 1;
				del += x;
				ans += x;
			}
		}
	}
	res = min(res, ans);
	//debug(res);
	del = ans = 0;
	for(int i = 1; i <= n; i++){
		//debug(del);
		if(i % 2 == 0){
			if(ps[i] + del >= 0){
				ans += (ps[i] + del + 1);
				del -= (ps[i] + del + 1);
			}
		} else {
			if(ps[i] + del <= 0){
				x = -(ps[i] + del) + 1;
				del += x;
				ans += x;
			}
		}
	}
	res = min(res, ans);
//	debug(res);
	cout << res;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const ll INF = (1LL << 31) - 1;
const double pi=acos(-1);

int main(){
  int n;
  cin >> n;
  map<ll,int>mp;
  rep(i,n){
    ll a;
    cin >> a;
    mp[a]++;
  }
  bool ok=false;
  if(mp[0]==n){
    ok=true;
  }
  else{
    ll sum=0;
    vector<ll>vec;
    for(auto p:mp){
      if(p.second){
        sum++;
        vec.push_back(p.first);
      }
    }
    
    if(n%3==0 && sum==2){
      if(mp[0]==n/3) ok = true;
    }
    if(n%3==0 && sum==3){
      bool can = true;
      for(auto t:mp){
      	if(t.second && t.second!=n/3) can = false;
      }
      ll bit=0;
      rep(i,3){
        bit^=vec[i];
      }
      if(can && !bit) ok = true;
    }
  }
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 8876
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
th,tw=0,0
mode=0
ans=[]
ope=0
while ope<h*w:
  if mode==0:
    if tw==w-1:
      if a[th][tw]%2==1 and th+1<h:
        a[th][tw]-=1
        a[th+1][tw]+=1
        ans.append([th+1,tw+1,th+2,tw+1])
      th+=1
      mode=1
    else:
      if a[th][tw]%2==1:
        a[th][tw]-=1
        a[th][tw+1]+=1
        ans.append([th+1,tw+1,th+1,tw+2])
      tw+=1
  elif mode==1:
    if tw==0:
      if a[th][tw]%2==1 and th+1<h:
        a[th][tw]-=1
        a[th+1][tw]+=1
        ans.append([th+1,tw+1,th+2,tw+1])
      th+=1
      mode=0
    else:
      if a[th][tw]%2==1:
        a[th][tw]-=1
        a[th][tw-1]+=1
        ans.append([th+1,tw+1,th+1,tw])
      tw-=1
  ope+=1
# print(a)
print(len(ans))
for aa in ans:
  print(*aa)


Measured memory_bytes: 32208
import sys

N = int(sys.stdin.readline().rstrip())  # 節点数

parents = [None] * N
sibling = [-1] * N
degree = [0] * N
depth = [None] * N
height = [None] * N
type_ = [None] * N

CHs = [[] for _ in range(N)]

# ## DFS ## #


def dfs(u, d, r=-1):

    # u を訪れたときの処理
    tmp = "leaf"
    h = 0

    for v in CHs[u]:
        if v == r:
            continue  # 親は無視
        tmp = "internal node"
        depth[v] = depth[u] + 1
        h = max(dfs(v, d + 1, u) + 1, h)  # 子の探索

    # u を離れる前の処理
    if r == -1:
        tmp = "root"
    type_[u] = tmp

    height[u] = h

    return h


def main():
    for i in range(N):
        id, lf, rg = map(int, sys.stdin.readline().rstrip().split())

        if lf != -1:
            parents[lf] = id
            degree[id] = 1
            CHs[id].append(lf)
        if rg != -1:
            parents[rg] = id
            degree[id] = 1
            CHs[id].append(rg)
        if lf != -1 and rg != -1:
            sibling[lf] = rg
            sibling[rg] = lf
            degree[id] = 2

    # 根を見つける
    u = 0
    while True:
        if parents[u] is None:
            root = u
            parents[u] = -1
            break
        u = parents[u]
    depth[root] = 0
    sibling[root] = -1

    # print(CHs)

    dfs(root, 0)

    for i in range(N):
        print(f"node {i}: parent = {parents[i]},", end="")
        print(f" sibling = {sibling[i]},", end="")
        print(f" degree = {degree[i]},", end="")
        print(f" depth = {depth[i]},", end="")
        print(f" height = {height[i]}, {type_[i]}")


main()



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

int n, q;
string s;
vector<char> t(q), d(q);

int solve(int pos){
	for(int i = 0; i < q; ++i){
		if(s[pos] == t[i]){
			if(d[i]=='R'){
				pos++;
			}else{
				pos--;
			}
		}
		if(pos == -1) return -1;
		if(pos == n) return 1;
	}
	return 0;
}

int main(void){
	cin >> n >> q >> s;
	t.resize(q); d.resize(q);
	for(int i = 0; i < q; ++i){
		cin >> t[i] >> d[i];
	}
	int l, r;

	/* 
	 * Meguru's binary search
	 * [ok, ng)
	 */
	int ok = 0;
	int ng = n-1;
	while(abs(ok-ng)>1){
		int mid = (ok + ng) / 2;
		if(solve(mid) == -1){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	l = ok; if(!solve(l)) l++;

	/* 
	 * Meguru's binary search 
	 * (ng,ok]
	 */
	ok = n-1;
	ng = 0;
	while(abs(ok-ng)>1){
		int mid = (ok + ng) / 2;
		if(solve(mid) == 1){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	r = ok; if(!solve(r)) r++;

	//cout << l << " " << r << endl;
	cout << r-l-1 << endl;
	return 0;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
typedef long long i64;
int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A==B) cout << C << endl;
    else if(B==C) cout << A << endl;
    else cout << B << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
const long long int mod=1e9+7;
typedef long long ll;
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
double reabs(double in){
    if(in<0){
        return (-1)*in;
    }else{
        return in;
    }
}

int main(){
    long long N,M;

    cin>>N>>M;
   
    long long ans;
    /*
    if(N>M){
        swap(N,M);
    }
    if(N==1){
        if(M==1){
            ans=1;
        
        }else{
            ans=(M-2);
        }
    
    }else{
        ans=(N-2)*(M-2);
    }
*/  if((N==1 && M!=1) || (N!=1 && M==1)){
        ans=N*M;
        ans-=2;
    }else{
        ans=(N-2)*(M-2);
    }
    
    cout<<ans<<endl;

    return 0;
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class281
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(A);
            int[] ans = new int[N];
            for(int i = 0; i < N-1; i++)
            {
                ans[A[i]-1]++;
            }
            foreach(int i in ans)
            {
                Console.WriteLine(i);
            }
        }
    }
}


Measured memory_bytes: 43528
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
#define MOD 1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int N,ans=0;cin>>N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N);
  REP(i,0,N){cin>>A[i];}
  REP(i,0,N){cin>>B[i];}
  REP(i,0,N){cin>>C[i];}
  sort(ALL(A));sort(ALL(B));sort(ALL(C));

  each(b,B){
    vector<int>::iterator pos_a;
    vector<int>::iterator pos_c;
    int idx_a,idx_c;
    pos_a=lower_bound(ALL(A),b);
    pos_c=upper_bound(ALL(C),b);
    idx_a=distance(A.begin(),pos_a);
    idx_c=distance(C.begin(),pos_c);
    idx_c=N-idx_c;
    ans+=idx_a*idx_c;
  }
  print(ans)


}


Measured memory_bytes: 2560
#include <stdio.h>

int main(){
  int n, x, ans[1000], i=0;
  
  while(1){
    scanf("%d %d", &n, &x);
    if(n==0&&x==0) break;

    if(x < 6){ans[i]=0;i++;continue;}
    if(x > 3*n-3){ans[i]=0;i++;continue;}

    ans[i]=0;
    for(int j=1;j<=n;j++){
      for(int k=j+1;k<=n;k++){
        for(int l=k+1;l<=n;l++){
          if(j+k+l==x)ans[i]++;
        }
      }
    }
    i++;

  }

  for(int l=0;l<i;l++){
    printf("%d\n", ans[l]);
  }

  return 0;
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'

int main()
{
    
    int n,m;
        cin>>n>>m;
        if(n==m) cout<<"Yes\n";
        else cout<<"No\n";
      
    
    return 0;
}



Measured memory_bytes: 256
import sys
from collections import deque



readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

def bfs(start):
    tansaku = deque(start)
    visited = {i:set() for i in range(h)}
    res = 0
    black = len(start)
    while black != h*w:
        for _ in range(len(tansaku)):
            pre_y,pre_x = tansaku.popleft()
            if pre_x in visited[pre_y]:
                continue
            for i in range(pre_x-1,pre_x+2,2):
                if 0 <= i <= w-1 and tizu[pre_y][i] == '.':
                    tansaku.append([pre_y,i])
                    tizu[pre_y][i] = '#'
            for j in range(pre_y-1,pre_y+2,2):
                if 0 <= j <= h-1 and tizu[j][pre_x] == '.':
                    tansaku.append([j,pre_x])
                    tizu[j][pre_x] = '#'
            visited[pre_y].add(pre_x)
        black += len(tansaku)
        res += 1
    return res

h,w = nm()
tizu = []
sharp = []
for i in range(h):
    temp = list(input())
    s_temp = [[i,j] for j in range(w)  if temp[j] == '#' ]
    tizu.append(temp)
    sharp += s_temp
ans = bfs(sharp)
print(ans)

Measured memory_bytes: 176100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1 << 17;
struct Segt {
	ll sum[N << 1], add[N << 1];
	Segt() {
		memset(sum, 0, sizeof sum);
		memset(add, 0, sizeof add);
	}
	void pd(int i, int l) {
		if (add[i]) {
			sum[i] += add[i] * l;
			if (i < N) {
				add[i + i] += add[i];
				add[i + i + 1] += add[i];
			}
			add[i] = 0;
		}
	}
	void upd(int i, int a, int b, int l, int r, int v) {
		if (l <= a && b <= r) {
			add[i] += v;
			pd(i, b - a); return;
		}
		pd(i, b - a);
		if (r <= a || b <= l) return;
		int md = (a + b) >> 1;
		upd(i + i, a, md, l, r, v);
		upd(i + i + 1, md, b, l, r, v);
		sum[i] = sum[i + i] + sum[i + i + 1];
	}
	ll qry(int i, int a, int b, int l, int r) {
		pd(i, b - a);
		if (l <= a && b <= r) return sum[i];
		if (r <= a || b <= l) return 0;
		int md = (a + b) >> 1;
		ll L = qry(i + i, a, md, l, r);
		ll R = qry(i + i + 1, md, b, l, r);
		return L + R;
	}
} segt;
int n, m;
int a[N];
int main() {
	ios :: sync_with_stdio(0);
	cin >> n >> m;
	for (int i = 0; i < n; ++ i) cin >> a[i], -- a[i];
	ll tot = 0;
	for (int i = 0; i + 1 < n; ++ i) {
		if (a[i] < a[i + 1]) {
			tot += a[i + 1] - a[i];
			segt.upd(1, 0, N, a[i] + 2, a[i + 1] + 1, 1);
			segt.upd(1, 0, N, a[i + 1] + 1, a[i + 1] + 2, -(a[i + 1] - a[i] - 1));
		} else {
			tot += m - a[i] + a[i + 1];
			segt.upd(1, 0, N, a[i] + 2, m, 1);
			segt.upd(1, 0, N, 0, 1, m - a[i] - 1);
			segt.upd(1, 0, N, 1, a[i + 1] + 1, 1);
			segt.upd(1, 0, N, a[i + 1] + 1, a[i + 1] + 2, -(m - a[i] + a[i + 1] - 1));
		}
//		for (int j = 0; j < m; ++ j) cerr << segt.qry(1, 0, N, 0, j + 1) << " "; cerr << endl;
	}
	cerr << tot << endl;
	ll mx = 0;
	for (int i = 0; i < m; ++ i) {
		ll cur = segt.qry(1, 0, N, 0, i + 1);
//		cerr << i << ": " << cur << endl;
		mx = max(mx, cur);
	}
	cout << tot - mx << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main() {
  ll N; cin >> N;
  string res;
  while(N>0){
    N--;
    char c = 'a' + N%26;
    res = c + res;
    N = N/26;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3596
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
factmod=[1 for i in range(n+1)]
for i in range(n):
    factmod[i+1]=(factmod[i]*(i+1))%mod
#print(factmod)
ans=0
for m in range(min(k+1,n)):
    a=factmod[-1]*pow((factmod[m]*factmod[n-m])%mod,mod-2,mod)
    b=factmod[n-1]*pow((factmod[m]*factmod[n-m-1])%mod,mod-2,mod)
    ans=(ans+(a*b))%mod
print(ans%mod)

    


Measured memory_bytes: 90512
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    
    int n,t;
    float a;
    
    cin >> n;
    
    t = 0;
    for(int i = 1;i <= n;i++){
        
        if(i % 2 != 0) t = t  + 1;
    
        
    }
    
    a = ((float)t) / ((float)n);
    
    printf("%.10f\n", a);
    
    return 0;
}


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

using namespace std;

typedef long long LL;

const int N = 110;

int main()
{
    string s;
    int res = -1, len = 0;

    cin >> s;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
            len++;
        else len = 0;
        res = max(res, len);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
#include <bitset>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...)
#define hash _hash
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)

#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 500010

template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}

//FILE* outFile;

inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}

int a[N], f[N];
vi v[1<<20];
int solve(vi &v, int m, int flag = 0){
    ll w, s1 = 0, s2 = 0, ans = 0;
    for(auto &i :v)if(a[i] == m){
        w = f[i] * s1 - s2 + 1;
        w %= mod;
        if(flag)ans += w, ans %= mod;
        if(w < 0)w += mod;
        s1 = (s1 + w) % mod;
        s2 = (s2 + w * f[i]) % mod;
    }
    if(flag)return ans;
    else return w;
}
int main(){
    int j,k,i,T,ca=0,K=0,m, n;
    scanf("%d", &n);
    K = 0;
    rep(i, 1, n+1){
        scanf("%d", &a[i]);
        a[i] ^= a[i-1];
        f[i] = f[i-1] + (a[i] == 0);
        if(a[i] == 0)K++;
        else v[a[i]].pb(i);
    }
    m = a[n];
    ll ans = 0;
    if(m > 0){
        ans = solve(v[m], m);
    }
    else{
        ans = 1;
        rep(i, 1, K)ans = ans * 2LL % mod;
        rep(i, 1, (1<<20))if(SZ(v[i])){
            ans = (ans + solve(v[i], i, 1)) % mod;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 37760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
//rep(i,n) rep(j,m) cin >> a[i][j]; 
//cout << fixed << setprecision(10) << ans << endl;
//sort小さい順(昇順)
//g++ code.cpp   ./a.out 
 
int main() {
    ll a,b;
    cin >> a >> b;
    ll h=__gcd(a,b);
    cout << a*b/h << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{

    string s,t;
    cin>>s;
    cin>>t;
    int n=s.length();
    int ans=0;
    rep(i,n)
    {
        if(s[i]!=t[i])
        {
            ans++;
        }
    }    
    cout<<ans;
    
}

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

int main(void){
    int n, ans=0;
    cin >> n;
    vector<int> v(n), c(n);
    for(int i=0;i<n;++i) cin >> v[i];
    for(int i=0;i<n;++i) cin >> c[i];
    for(int i=0;i<n;++i){
        if(v[i]>c[i])ans += v[i]-c[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
x=list(map(int,input().split()))

x.sort()

for p in range(x[0],x[len(x)-1]+1):
    psum=0
    for i in range(len(x)):
        psum=psum+(x[0]-x[i])**2
#    print(psum)
    pmin=psum    
    for j in range(x[0]+1,x[len(x)-1]):
        psum=0
        for i in range(len(x)):
            psum=psum+(j-x[i])**2
#        print(psum)
        if pmin>psum:
            pmin=psum
print(pmin)    

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define repb(bit,n,init) for(ll bit=init;bit<(1<<n);++bit)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    string s;
    cin >> s;
    cout << (s=="ARC"?"ABC":"ARC") << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.io.PrintWriter
import kotlin.comparisons.compareBy

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val lastT = 100000 * 2 + 1
    val (n, c) = readIntegerList()
    val stsList = Array<MutableList<Pair<Int, Int>>>(30) { mutableListOf() }
    repeat(n) {
        val (s, t, c) = readIntegerList()
        stsList[c - 1].add(Pair(s * 10, t * 10))
    }

    val sNums = IntArray(lastT)
    val tNums = IntArray(lastT)
    for (sts in stsList) {
        sts.sortWith(compareBy<Pair<Int, Int>>({it.first!!}, {it.second!!}))
        sts.add(Pair(100000000, 100000000)) // 番兵
        var s = sts.first().first
        var t = sts.first().second
        for (st in sts) {
            if (st.first <= t) {
                t = st.second
            } else {
                sNums[(s - 5) / 5]++
                tNums[t / 5]++

                s = st.first
                t = st.second
            }
        }
    }
    val sums = IntArray(lastT + 1)
    for (i in 0 until lastT) {
        sums[i + 1] = sums[i] + sNums[i] - tNums[i]
    }
    println(sums.max()!!)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 84888
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <assert.h>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <bitset>
#include <numeric>
#include <string.h>
#include <utility>

using namespace std;
#define IO                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define sz(x) (int)((x).size())
#define forn(i,n) for (int i=0; i < n; i++)
#define forse(i,s,e) for (int i=s; i < e; i++)
#define pb push_back 
#define pf push_front
#define rb pop_back
#define rf pop_front
#define mp make_pair
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)
#define debug(x) cerr << (#x) << " is " << (x) << endl;

#ifndef LOCAL
#define cerr if(false)cerr
#endif

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll P=998244353;
double PI=3.141592653589793;
const int arrn = 2e5 + 1;


void solve(){
	int n;
	cin >> n;
	vector<pii> tem,tem1;
	int pre=0,pre1=0;
	forn(i,n){
		string in;
		cin >> in;
		int mn=0,sum=0;
		forn(i,sz(in)){
			if(in[i]=='(') sum++;
			else sum--;
			mn=min(mn,sum);
		}
		if(mn<0){
			if(sum>=0) tem.pb({-mn,sum});
			else{
				reverse(all(in));
				int mn=0,sum=0;
				forn(i,sz(in)){
					if(in[i]==')') sum++;
					else sum--;
					mn=min(mn,sum);
				}
				if(mn<0){
					tem1.pb({-mn,sum});
				}else{
					pre1+=sum;
				}
			}
		}else{
			pre+=sum;
		}
	}

	sort(all(tem));
	for(auto i:tem){
		if(i.fi>pre){
			cout << "No";
			return;
		}
		pre+=i.se;
	}
	
	sort(all(tem1));
	for(auto i:tem1){
		if(i.fi>pre1){
			cout << "No";
			return;
		}
		pre1+=i.se;
	}
	if(pre1==pre) cout << "Yes";
	else cout << "No";

}

int main() {
	IO;
	int T=1;
//	cin >> T;
	forn(c,T){
		solve();
	}
}



Measured memory_bytes: 5172
use std::io::stdin;
fn get_string() -> String {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

macro_rules! input {
    ($single:ty) => ( get_string().parse::<$single>().unwrap() );
    ($plural:ty,) => ({
        let line = get_string();
        line.split_whitespace().map(|v| v.parse::<$plural>().unwrap()).collect::<Vec<$plural>>()
    });
    ($($plural:ty),+) => ({
        let line = get_string();
        let mut iter = line.split_whitespace();
        ($(iter.next().unwrap().parse::<$plural>().unwrap()),+)
    });
    ($single:ty; $times:expr) => ( (0..$times).map(|_| input!($single)).collect::<Vec<$single>>() );
    ($($plural:ty),+; $times:expr) => ( (0..$times).map(|_| input!($($plural),+)).collect::<Vec<($($plural),+)>>() );
}

#[allow(dead_code)]
fn get_value<T: std::str::FromStr>() -> T {
    get_string().parse().ok().unwrap()
}
#[allow(dead_code)]
fn get_values_for<T: std::str::FromStr>(times: u64) -> Vec<T> {
    (0..times).map(|_| get_value()).collect()
}
#[allow(dead_code)]
fn get_vector<T: std::str::FromStr>() -> Vec<T> {
    get_string()
        .split_whitespace()
        .map(|v| v.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn get_vectors_for<T: std::str::FromStr>(times: u64) -> Vec<Vec<T>> {
    (0..times).map(|_| get_vector()).collect()
}

fn main() {
    let n = input!(u32);
    if n % 2 == 1 {
        println!("{}", n * 2);
    } else {
        println!("{}", n);
    }
}


Measured memory_bytes: 4352
if __name__ == "__main__":
    n = list(input())
    #k, n = map(int, input().split())
    a = int(n[-1])
    
    if a==3:
        print("bon")
    elif a==0 or a==1 or a==6 or a==8:
        print("pon")
    else:
        print("hon")

Measured memory_bytes: 9172
def resolve():
    H, W, K = map(int, input().split())
    C = [input() for _ in range(H)]
    cnt = 0
    for h in range(1 << H):
        for w in range(1 << W):
            black = 0
            for i in range(H):
                for j in range(W):
                    if h >> i & 1 or w >> j & 1:
                        continue
                    if C[i][j] == "#":
                        black += 1
            if black == K:
                cnt += 1

    print(cnt)
resolve()

Measured memory_bytes: 73792
///ABC_127_A
#include <iostream>
#include <cstdio>
using namespace std;
main()
{
    int a,b;
    cin >> a >> b;
    if( a <= 5 )
    {
        printf( "0\n");
        return 0;
    }
    else if( a <= 12 )
    {
        printf( "%d\n", b / 2 );
        return 0;
    }
    else cout << b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

typedef long long int llint;



void solve(void){

  int n, k;
  std::cin >> n >> k;
  std::vector<int> p(n);
  for(int i=0; i<n; i++){
    std::cin >> p[i];
  }

  std::sort(p.begin(), p.end());

  int ret = 0;
  for(int i=0; i<k; i++){
    ret += p[i];
  }

  std::cout << ret << std::endl;
  
}

int main(void){

  solve();
  
  return 0;
}


Measured memory_bytes: 3596
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1
#余りの数字がそれぞれ何回出たかカウント
#count[0]は「累積和的」に0%2019を考えるために1にしている

num, d = 0, 1
#numは余りの累積和、dはcharの桁数
for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1
'''
charに一桁ずつ取り出す。そのMOD2019を考え、累積和をとる
しかし、それぞれの数字には10の累乗がかかっているのでそれについては別途dを用意してMOD2019をとる
つまり、numは1桁目のMOD2019、2桁目のMOD2019に1桁目のMOD2019に加える
'''

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

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

struct UnionFind {
  
  vector<int> r;
  
  UnionFind(int N) {
    r = vector<int>(N, -1); // 初期化
  }
  
  
  // 根を返す(経路圧縮つき)
  int root(int x) {
    if (r[x] < 0) return x;
    return r[x] = root(r[x]); // 圧縮
  }
  
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    
    if (x == y) return false;
    if (r[x] > r[y]) swap(x, y);
    
    // xが親になるように合併した
    r[x] += r[y]; // xは親なので頂点数 * (-1）を更新
    r[y] = x; // y は親ではないので親であるxをさす
    return true;
  }
  
  int size(int x) {
    return -r[root(x)];
  }


};

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<pair<int,int>> edge(M);
  
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    
    edge[i] = {a, b};
  }
  
  int ans = 0;
  
  // i番目の辺を抜いて，UnionFindを作り，1のsizeを調べてNと一致するか
  for (int i = 0; i < M; i++) {
    
    
    // UnionFindの作成
    UnionFind UF(N);
    
    for (int j = 0; j < M; j++) {
      // i番目の辺を無視
      if (j == i) continue;
      
      int A = edge[j].first, B = edge[j].second;
      A -= 1; B -= 1;
      
      UF.unite(A, B);
      
    }
    
    
    
    // UnionFind が1つのグループからなるか
    if (UF.size(1) != N) ans++;
  }
    
  cout << ans << endl;
  
  
  
}

Measured memory_bytes: 3640
#include <stdio.h>

long long int bit_counts[61];

int main (void) {
	int n, i, j;
	long long int a, res=0;
	
	scanf("%d\n", &n);
	
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a);
		for(j=0;a;j++,a>>=1)
		{
			bit_counts[j]+=a&1;
		}
	}
	
	for(i=60;i>=0;i--)
	{
		res=res*2%1000000007LL+bit_counts[i]*(n-bit_counts[i])%1000000007LL;
		res%=1000000007LL;
	}
	
	printf("%lld\n", res);
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
typedef pair<int,pair<int,int> > P;

int main(){
	int n,a[2222]={};
	bitset<2001*2002> bs(1);
	cin>>n;
	int s=0;
	FOR(i,0,n){
		cin>>a[i];
		s+=a[i];
		bs=bs|(bs<<a[i]);
	}
	FOR(i,(s+1)/2,s+1){
		if(bs[i]){
			cout<<i<<endl;
			break;
		}
	}

    return 0;
}


Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {

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

        final int N = sc.nextInt();
        final int X = sc.nextInt();
        final int[] m = new int[N];
        for (int i = 0; i < N; i++) m[i] = sc.nextInt();

        int total = m.length;

        int used = 0;
        int min = Integer.MAX_VALUE;

        for (int i = 0; i < N; i++) {
            used += m[i];
            min = Math.min(min, m[i]);
        }
        total += (X - used) / min;

        System.out.println(total);
    }
}


Measured memory_bytes: 21716