akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

// mint
template<int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x=0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; }
  mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; }
  mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; }
  mod_int operator+(mod_int const& r) const { mod_int res(*this); return res += r; }
  mod_int operator-(mod_int const& r) const { mod_int res(*this); return res -= r; }
  mod_int operator*(mod_int const& r) const { mod_int res(*this); return res *= r; }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while(x > 0) {
      if(x&1) (res *= v) %= Prime;
      x/=2; (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime-2); }
};

int64_t const MOD = 1e9+7;
typedef mod_int<MOD> mint;

// fact
template<typename INT>
struct factorial {
  std::vector<INT> fact, ifact;
  void init(int64_t N) {
    fact.resize(N+1); ifact.resize(N+1);
    fact[0] = fact[1] = INT(1);
    for(int i = 2; i <= N; ++i) fact[i] = fact[i-1]*i;
    ifact[N] = fact[N].inv();
    for(int i = N-1; i >= 0; --i) ifact[i] = ifact[i+1]*(i+1);
  }
  INT comb(int64_t n, int64_t k) { // nCk
    if(k > n || k < 0) return INT(0);
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int64_t N, M, K; std::cin >> N >> M >> K;
  factorial<mint> F;
  F.init(std::max(N*M, std::max(N, M)+1));
  mint ans = mint(M*M)*F.comb(N+1,3) + mint(N*N)*F.comb(M+1,3);
  ans *= F.comb(N*M-2, K-2);
  fin(ans.v_);
  return 0;
}


Measured memory_bytes: 3328
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

// vector<int>を渡してあげると、それを元にセグメント木を構築する。
 struct SegmentTree {
   int n;  // 最下段のノード数
   vector<int> node;
   int SIJK;  // 最弱なやつ(INFとか-1とか)
 
  public:
   SegmentTree(vector<int> v) {
     SIJK = ((1ll << 31) - 1) * (-1);  // INFは最弱なので
 
     int sz = v.size();
     n = 1;
     while (n < sz) n *= 2;  // n…最下段の横幅
     node.resize(2 * n - 1, SIJK);
 
     // 最下段に突っ込む
     for (int i = 0; i < sz; i++) node[(n - 1) + i] = v[i];
 
     // 最下段以外を更新していく
     for (int i = n - 2; i >= 0; i--) {
       node[i] = compare(node[i * 2 + 1], node[i * 2 + 2]);
     }
   }
 
   // 結合法則を満たすやつならなんでもいいよー。aかbを返す。
   int compare(int a, int b) {
     return max(a, b);
   }
 
   // i番目の要素をvalに変更する
   void update(int i, int val) {
     // まず最下段(2n-1)を変更する
     i += n - 1;
     node[i] = val;
 
     // 上に行きながら更新していく
     while (i > 0) {
       i = (i - 1) / 2;  // 親へ
       node[i] = compare(node[2 * i + 1], node[2 * i + 2]);
     }
   }
 
   // [a,b) 中の結果を返す。[l,r)は対称区間の左端と右端。
   int find(int a, int b, int now = 0, int l = 0, int r = -1) {
     // 初期化
     if (r < 0) r = n;
 
     // 俺は関係ないとき -> 答えの邪魔にならない値を返す
     if (r <= a || b <= l) return SIJK;
 
     // 要求区間の中にノードがすっぽり入ってる → 計算候補として返す
     if (a <= l && r <= b) return node[now];
 
     // ノードの一部分だけ要求区間に入ってる → 子を再帰的に探索する
     int vl = find(a, b, 2 * now + 1, l, (l + r) / 2);  // 子(左)
     int vr = find(a, b, 2 * now + 2, (l + r) / 2, r);  // 子(右)
     return compare(vl, vr);
   }
 };
 

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> al(n);
    vector<int> dp(500010);
    
    rep(i, n){
        int a;
        cin >> al[i];
    }

    SegmentTree sg = SegmentTree(dp);

    rep(i, n){
        int a = al[i];
        int s = max(a - k, 0);
        int e = min(500010, a + k + 1);
        int v = sg.find(s, e);
        sg.update(a, v + 1);
    }
    int ans = sg.find(0, 500010);
    cout << ans << endl;
}


Measured memory_bytes: 12508
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int a;
    cin>>a;
    cout<<a+(a*a)+(a*a*a);
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-

def maxStack(k, p, W):
    nw = 0
    count = 0
    t = 1
    for x in W:
        if x > p:
            return count
        if nw + x <= p:
            nw += x
            count += 1
        else:
            if t == k:
                return count
            else:
                t += 1
                nw = x
                count += 1
    return count

n, k = map(int, raw_input().split())
W = [int(raw_input()) for i in range(n)]
left = 1
right = sum(W)
while left < right:
    mid = (left+right)/2
    v = maxStack(k, mid, W)
    if v >= n:
        right = mid
    else:
        left = mid+1
print left

Measured memory_bytes: 12660
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s,t;
    cin >> s >> t;
    
    REP(i,s.length()){
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
        s = s[s.length()-1]+s.substr(0,s.length()-1);
    }
    cout << "No" << endl;
    return 0;
}

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

int main()
{
    char b;
    cin >> b;
    char res;
    if (b == 'A') res = 'T';
    else if (b == 'T') res = 'A';
    else if (b == 'C') res = 'G';
    else res = 'C';

    cout << res << endl;

    return 0;
}

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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define MOD 1000000007

const int MAX_M = 100000;


int main(){
  //ll n; 
  string s;
  cin >> s;
  
  if((s.at(0) == '7')||(s.at(1) == '7')||(s.at(2) == '7'))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  //cout << n << endl;
}


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

int main(void){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int left = a+b;
    int right = c+d; 
    if(left > right){
        cout << "Left" << endl;
    }else if(left == right){
        cout << "Balanced" << endl;
    }else{
        cout << "Right" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
local n = io.read("*n")
local edge = {}
for i = 1, n do
  edge[i] = {}
end
for i = 1, n - 1 do
  local a, b = io.read("*n", "*n")
  a = a + 1
  b = b + 1
  table.insert(edge[a], b)
  table.insert(edge[b], a)
end

local function getend(start)
  local len = {}
  for i = 1, n do
    len[i] = -1
  end
  len[start] = 0
  local mlenidx = 1
  local tasks = {start}
  while 0 < #tasks do
    local src = tasks[#tasks]
    table.remove(tasks)
    for i = 1, #edge[src] do
      local dst = edge[src][i]
      if len[dst] < 0 then
        len[dst] = len[src] + 1
        if len[mlenidx] < len[dst] then
          mlenidx = dst
        end
        table.insert(tasks, dst)
      end
    end
  end
  return mlenidx
end
local root = getend(1)

local parent = {}
local asked = {}
local asked_child_cnt = {}
local tasks = {}
local required = {}
for i = 1, n do
  required[i] = false
  parent[i] = 0
  asked[i] = false
  asked_child_cnt[i] = 0
  if #edge[i] == 1 then
    if i ~= root then
      table.insert(tasks, i)
    end
  end
end
local done = 0
while done < #tasks do
  done = done + 1
  local child = tasks[done]
  asked[child] = true
  if child == root then break end
  if 3 <= #edge[child] then
    required[child] = true
  end
  for i = 1, #edge[child] do
    local pcand = edge[child][i]
    if not asked[pcand] then
      parent[child] = pcand
      asked_child_cnt[pcand] = asked_child_cnt[pcand] + 1
      if asked_child_cnt[pcand] == #edge[pcand] - 1 then
        table.insert(tasks, pcand)
      end
    else
      if required[pcand] then required[child] = true end
    end
  end
end
-- for i = 1, n do
--   asked[i] = false
-- end
-- asked[root] = true
tasks[1] = edge[root][1]
tasknum = 1
done = 0
local ret = 1
while done < tasknum do
  done = done + 1
  local p = tasks[done]
  local required_cnt = #edge[p] - 2
  for i = 1, #edge[p] do
    local c = edge[p][i]
    if c ~= parent[p] then
      if required[c] then
        required_cnt = required_cnt - 1
      end
      tasknum = tasknum + 1
      tasks[tasknum] = c
    end
  end
  if 0 < required_cnt then
    ret = ret + required_cnt
  end
end
print(ret)


Measured memory_bytes: 19488
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
  string s;
  ll ans=0;
  cin >> s;
//  cout << (1<<(s.size()-1)) << endl;
  for(int i=0;i<(1<<(s.size()-1));i++){
    vector<string> tmp;
    int j=0;
    for(int k=0;k<(s.size()-1);k++){
      if(k==0){
        tmp.push_back("0");
        tmp[j].push_back(s[k]);
//        cout << "a" << i << j << endl;
      }
      if((i&(1<<k))==0){tmp[j].push_back(s[k+1]);
//        cout << "b" << i << j << endl;
      }
      else{
        j++;
        tmp.push_back("0");
        tmp[j].push_back(s[k+1]);
//        cout <<"c"<< i << j << endl;
        continue;
      }
    }
    for(int i=0;i<tmp.size();i++){
//      cout << tmp[i] <<" ";
      ans+=stoll(tmp[i]);
    }
//    cout << endl;
  }
  if(s.size()==1) cout << s;
  else cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int N;
	cin >> N;
	vector<int> A(N);
	REP(i, N) cin >> A[i];
	sort(A.begin(), A.end());
	string res = "YES";
	for (int i = 1;i < N;i++) {
		if (A[i - 1] == A[i]) {
			res = "NO";
		}
	}
	cout << res << endl;

	return 0;
}

												

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s[0] == s[1] && s[2] == s[3] && s[0] != s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
k = list(x for x in input())
ans = [0] * n
for i in range(n):
  l = []
  for j in range(0,i):
    if l.count(k[j]) == 0:
      l.append(k[j])
      if k[i:n].count(k[j]) > 0:
        ans[i] += 1
print(max(ans))

Measured memory_bytes: 3064
ans = ""
s = input()

for i in range(len(s)):
    if s[i] == '0':
        ans = ans + '0'
        
    elif s[i] == '1':
        ans = ans + '1'
        
    elif s[i] == 'B':
        if ans == "":
            pass
        else:
            ans = ans[:-1]
            
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  int n,k;
  cin>>n>>k;
  int h[100000];
  rep(i,0,n) cin>>h[i];

  int cnt=0;
  rep(i,0,n){
    if(h[i]>=k) cnt++;
  }

  cout<<cnt<<endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader vd = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(vd.readLine());

		if(n>=1099&&n<1999) System.out.println("ABD");
		if(n>=1009&&n<1099) System.out.println("ABD");
		if(n>=1000&&n<1009) System.out.println("ABD");
		if(n>=100&&n<1000) System.out.println("ABC");
		if(n>=10&&n<100) System.out.println("ABC");
		if(n>=1&&n<10) System.out.println("ABC");

	}

}


Measured memory_bytes: 21204
#include<iostream>
#include<set>

using namespace std;

int hoge(char c){

    if(c=='m') return 1000;
    if(c=='c') return 100;
    if(c=='x') return 10;
    if(c=='i') return 1;
}

char geho(int k){

    if(k==1000) return 'm';
    if(k==100) return 'c';
    if(k==10) return 'x';
    if(k==1) return 'i';
}

int mcxi(string s){

    int ret=0;
    int num=1;
    for(int i=0; i<s.size(); i++){
        if('a'<=s[i]&&s[i]<='z'){
            ret+=num*hoge(s[i]);
            num=1;
        }else{
            num=s[i]-'0';
        }
    }

    return ret;
}

string rev(int k){

    string ret;
    for(int i=1000; i>=1; i/=10){
        int m=(k/i)%10;
        if(m){
            if(m==1){

            }else{
                ret+=m+'0';
            }
            ret+=geho(i);
        }
    }
    return ret;
}

int main(){

    int n;
    cin>> n;
    string s[n][2];
    for(int i=0; i<n; i++){
        for(int j=0; j<2; j++){
            cin>> s[i][j];
        }
    }

    for(int i=0; i<n; i++){
        int sum=0;
        for(int j=0; j<2; j++){
            sum+=mcxi(s[i][j]);
        }
        cout<< rev(sum)<< endl;
    }

    return 0;
}

Measured memory_bytes: 3252
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private final static String NEG = "NO\n";
	private final static String AFF = "YES\n";

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in),1024);
		int number = Integer.parseInt(br.readLine());
		int sides[] = new int[3];
		StringTokenizer tknz;
		StringBuilder builder = new StringBuilder();

		for (; 0 < number; number--) {
			tknz = new StringTokenizer(br.readLine());
			for (int i = 0; i < 3; i++) {
				sides[i] = Integer.parseInt(tknz.nextToken());
			}
			Arrays.sort(sides);
			if (sides[0] * sides[1] * sides[2] % 60 != 0) {
				builder.append(NEG);
			} else if (Math.pow(sides[0], 2) + Math.pow(sides[1], 2) != Math.pow(sides[2], 2)) {
				builder.append(NEG);
			} else {
				builder.append(AFF);
			}
		}
		System.out.print(builder);
	}
}

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

using namespace std;

using ll = long long;

#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()

int main()
{
    int N;
    cin >> N;
    vector<int> A(N+1),B(N);
    rep(i,N+1) cin >> A.at(i);
    rep(i,N) cin >> B.at(i);

    ll ans = 0;

    rep(i,N)
    {
        if(B.at(i) < A.at(i))
        {
            ans += B.at(i);
        }
        else
        {
            ans += min(B.at(i),A.at(i)+A.at(i+1));
            A.at(i+1) = max(0,A.at(i)+A.at(i+1)-B.at(i));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template <typename T>
inline void pr(const vector<T> &xs) {
	for (int i = 0; i < xs.size() - 1; i++) cout << xs[i] << " ";
	(xs.empty() ? cout : (cout << xs[xs.size() - 1])) << endl;
}
template <typename T>
inline void debug(const vector<T> &xs) {
#ifdef DEBUG
	pr(xs);
#endif
}

template <typename T>
struct LCA {
	int n, l, root;
	vector<vector<pair<int, T>>> graph;
	vector<int> dep;
	vector<T> dist;
	vector<vector<int>> par;
	LCA(int n) : n(n) {
		l = 0;
		while ((1 << l) < n)
			l++;
		graph.assign(n, {});
		dist.assign(n, 0);
		dep.assign(n, 0);
		par.assign(n, vector<int>(l));
	}
	void add_edge(int u, int v, T c = 0) {
		graph[u].emplace_back(v, c);
		graph[v].emplace_back(u, c);
	}
	void init(int _root = 0) {
		root = _root;
		dfs(root, -1, 0, 0);
		for (int i=1; i<l; i++) {
			for (int u=0; u<n; u++) {
				if (par[u][i-1] < 0) continue;
				par[u][i] = par[par[u][i-1]][i-1];
			}
		}
	}
	void dfs(int u, int p, T c, int d) {
		dist[u] = c;
		par[u][0] = p;
		dep[u] = d;
		for (auto e : graph[u]) {
			int v = e.first;
			T cv = e.second;
			if (v==p) continue;
			dfs(v, u, c+cv, d+1);
		}
	}
	int operator() (int u, int v) const {
		if (dep[u]<dep[v]) swap(u, v);
		int gap = dep[u]-dep[v];
		for (int i=0; i<l; i++) {
			if (gap & (1 << i)) u = par[u][i];
		}
		if (u==v) return u;
		for (int i=l-1; i>=0; i--) {
			if (par[u][i]!=par[v][i]) {
				u = par[u][i];
				v = par[v][i];
			}
		}
		return par[u][0];
	}
	T distance(int u, int v) const {
		int c = (*this)(u, v);
		return dist[u]+dist[v]-2*dist[c];
	}
};

struct Query {
	int qid;
	int color;
	int coeff;
};

struct Edge {
	int to;
	int color;
	int cost;
};

vector<ll> ans;
vector<vector<Edge>> graph;
vector<vector<Query>> qsum, qnum;
vector<ll> sum, num;
void dfs(int u, int p)
{
	for (auto q : qsum[u]) ans[q.qid] += q.coeff * sum[q.color];
	for (auto q : qnum[u]) ans[q.qid] += q.coeff * num[q.color];
	for (auto e : graph[u]) {
		if (e.to == p) continue;
		sum[e.color] += e.cost;
		num[e.color] += 1;
		dfs(e.to, u);
		sum[e.color] -= e.cost;
		num[e.color] -= 1;
	}
}

int main() {
	int N, Q;
	cin >> N >> Q;
	LCA<ll> lca(N);
	graph.assign(N, {});
	for (int i = 0; i < N - 1; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--; b--;
		lca.add_edge(a, b, d);
		graph[a].push_back({b, c, d});
		graph[b].push_back({a, c, d});
	}
	lca.init();
	qsum.assign(N, {});
	qnum.assign(N, {});
	sum.assign(N, 0);
	num.assign(N, 0);
	ans.assign(Q, 0);
	for (int i = 0; i < Q; i++) {
		int x, y, u, v;
		cin >> x >> y >> u >> v;
		u--; v--;
		int c = lca(u, v);
		ans[i] = lca.distance(u, v);
		debug(any{ans[i], c});
		qsum[u].push_back({i, x, -1});
		qsum[v].push_back({i, x, -1});
		qsum[c].push_back({i, x, 2});
		qnum[u].push_back({i, x, y});
		qnum[v].push_back({i, x, y});
		qnum[c].push_back({i, x, -2*y});
	}
	dfs(0, -1);

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

	return 0;
}


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

int main() {
  int n, a, b, c, d;
  string s;
  bool w = true;
  cin >> n >> a >> b >> c >> d >> s;
  if(c > d) {
    w = false;
    for(int i = b-2;i < d-1;i++) if(s[i]=='.' && s[i+1]=='.' && s[i+2]=='.') w = true;
  }
  for(int i = a;i < min(max(c, d), n-1);i++) if(s[i] == '#' && s[i+1] == '#') w = false;
  cout << (w ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
string s;
int sumt;
int sums;
int sum;
int main(){
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='S') sums++;
        else if(sums) sumt++;
        if(sums>=sumt){
            sum+=min(sums,sumt)*2;
            sums-=min(sums,sumt);
            sumt=0;
        }
    }
    while(0){
    	int a;
    	
    	cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;cin>>a;
	}
    cout<<n-sum<<endl;
    return 0;
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }

#[allow(dead_code)]
const M: u64 = 1_000_000_007;

fn main() {
    let n = get!(usize);
    let mut aa = get!(u64; n);
    let mut bb = get!(u64; n);

    for x in &mut aa {
        *x += 1;
    }

    for x in &mut bb {
        *x += 1;
    }

    aa.sort();
    bb.sort();

    let mut seq = Vec::new();

    while !aa.is_empty() || !bb.is_empty() {
        if aa.last().cloned().unwrap_or(0) > bb.last().cloned().unwrap_or(0) {
            aa.pop();
            seq.push(true);
        } else {
            bb.pop();
            seq.push(false);
        }
    }

    let mut ans = 1;
    let mut a = 0;
    let mut b = 0;

    for &x in &seq {
        if x {
            if b > 0 {
                ans = ans * b % M;
                b -= 1;
            } else {
                a += 1;
            }
        } else {
            if a > 0 {
                ans = ans * a % M;
                a -= 1;
            } else {
                b += 1;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 6396
#!/usr/bin/python
# coding: UTF-8

from math import *
import os
import sys

#import scipy.optimize
import numpy as np


##################################################################
if __name__ == "__main__":
    Input = [input() for i in range(4)]
    N = int(Input[0])
    A = list(map(int,Input[1].split()))
    B = list(map(int,Input[2].split()))
    C = list(map(int,Input[3].split()))

    raw = sum(B[i-1] for i in A)
    for i in np.arange(1,len(A),1):
        if A[i]-A[i-1] == 1:
            raw = raw + C[A[i-1]-1]
    print(raw)    
    


Measured memory_bytes: 21336
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int H,W,A,B;
  cin >> H >> W >> A >> B;
  REP(i,H){
    REP(j,W){
      if((i<B&&j<A)||(i>=B&&j>=A)){
        cout << 0; 
      }else{
        cout << 1;
      }
    }
    cout << endl;
  }

}

Measured memory_bytes: 1280
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll Ap = -1;
    ll Zp = -1;
    rep(i, s.size()){
        if(s[i] == 'A' && Ap == -1){
            Ap = i;
        }else if(s[i] == 'Z'){
            Zp = i;
        }
    }

    cout << Zp - Ap + 1 << endl;

    return 0;
}

Measured memory_bytes: 3724
n = int(input())
s = [int(input()) for i in range(n)]
summ = sum(s)
ans = [summ]*n
for i in range(n):
  ans[i] -= s[i]
ans.sort(reverse = True)
if summ % 10 != 0:
  print(summ)
else:

  for i in ans:
    if i % 10 != 0:
      print(i)
      break
  else:
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int > pp;
typedef long long ll;
 
#define sz(x) (int)x.size() 
int const N=3e5+10,oo=1e9;
ll const OO=2e18;
double const eps=1e-8,PI=acos(-1);
int mod=oo+7;

int n,k;
string s;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin>>n>>k;
  cin>>s;
  vector<pp > zer;
  for(int i=0;i<n;i++){
  	if(s[i]=='1')continue;
  	int j=i;
  	while(j<n&&s[j]==s[i])j++;
  	zer.push_back({i,j-1});
  	i=j-1;
  }
  if(sz(zer)<=k){
  	cout<<n<<'\n';
  	return 0;
  }
  int an=0,i=0;
  while(i+k-1<sz(zer)){
  	int c=0;
  	if(i)c+=zer[i].first-zer[i-1].second-1;
  	else c+=zer[i].first;
  	if(i+k==sz(zer))c+=n-zer[i].first;
  	else c+=zer[i+k].first-zer[i].first;
  	an=max(an,c);
  	i++;
  }
  cout<<an;
  return 0;
}






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

using namespace std;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }

    return gcd(b, a % b);
}

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

    int sum = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                sum += gcd(a, gcd(b, c));
            }
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3648
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<functional>

using namespace std;

template <typename T>
struct SegmentTree
{
    using F = function<T(T, T)>;
    int n;
    F f;
    T ti;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(F f, T ti) : f(f), ti(ti) {}
    void init(int n_)
    {
        n = 1;
        while (n < n_)
            n <<= 1;
        dat.assign(n << 1, ti);
    }

    void build(const vector<T> &v)
    {
        int n_ = v.size();
        init(n_);
        for (int i = 0; i < n_; i++)
            dat[n + i] = v[i];
        for (int i = n - 1; i; i--)
            dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
    }

    // v[k] = x (0-indexed)
    void set(int k, T x)
    {
        dat[k += n] = x;
        while (k >>= 1)
            dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }

    // get F(v[a], v[a + 1], ... , v[b - 1]) (0-indexed)
    T query(int a, int b)
    {
        T vl = ti, vr = ti;
        for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1)
        {
            if (l & 1)
                vl = f(vl, dat[l++]);
            if (r & 1)
                vr = f(dat[--r], vr);
        }
        return f(vl, vr);
    }
};

using ll = long long;
using Mat = vector<vector<ll>>;

ll k;
int n;
Mat adj;

void prod(const Mat& a, const Mat& b, Mat& dest) {
    REP(i, n) dest[i].assign(n, 0);
    REP(i, n) REP(j, n) REP(k, n) {
        dest[i][j] += (a[i][k] * b[k][j]) % 1000000007;
        dest[i][j] %= 1000000007;
    }
}

int main()
{
    cin >> n >> k;
    adj = Mat(n, vector<ll>(n));
    REP(i, n) REP(j, n) cin >> adj[i][j];

    auto ans = Mat(n, vector<ll>(n, 0));
    REP(i, n) ans[i][i] = 1;
    while (k > 0) {
        if ((k & 1)) {
        // REP(i, n){ DV(adj[i]);}
            auto cp = ans;
            prod(cp, adj, ans);
        }
        auto cp = adj;
        prod(cp, cp, adj);
        k >>= 1;
    }
    ll total = 0;
    // REP(i, n){ DV(ans[i]);}
    REP(i, n) REP(j, n) {total += ans[i][j]; total %= 1000000007;}
    cout << total << endl;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
# 学籍番号 17D8101029G 石塚 博之 ID: mcatpolo 言語: python3

N = int(input())
X = list(map(int, input().split()))
M = int(input())
A = list(map(int, input().split()))



for i in range(0, M):
    if X[A[i]-1]+1 not in X and X[A[i]-1] < 2019:
        X[A[i]-1] += 1

for i in X:
    print(i)


Measured memory_bytes: 5612
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n;
int main()
{
	cin >>n;
	cout <<n*(n-1)/2;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] arg) {
		Scanner in = new Scanner(System.in).useDelimiter("(\\s|,)+");
		int case_ = 0;
		while (in.hasNext()) {
			int w = in.nextInt();
			if (w != 0) {
				System.out.print("Case ");
				System.out.print(++case_);
				System.out.println(":");
				int[] pack = new int[w + 1];
				int n = in.nextInt();
				int maxNum = 0;
				for (int j = 0; j < n; j++) {
					int p = in.nextInt();
					int pw = in.nextInt();
					for (int i = w - pw; i >= 0; i--) {
						pack[i + pw] = Math.max(pack[i + pw], pack[i] + p);
						if (pack[maxNum] <= pack[i + pw]) {
							maxNum = i + pw;
						}
					}
				}
				System.out.println(pack[maxNum]);
				System.out.println(maxNum);
			}
		}
	}
}

Measured memory_bytes: 24156
function gcd(a, b) {
    if (a%b === 0) return b;
    return gcd(b, a%b);
}

function lcm(a, b) {
    return a * b / gcd(a, b)
}

function Main(input) {
    var N = parseInt(input);
    
    console.log(lcm(N, 2));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include "bits/stdc++.h"
using namespace std;
//const int N = 1e5 + 5;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    int n,ans = 0;
    cin>>n;
    int a[n],mx = n + 1;
    for(int i = 0; i < n; ++i){
        cin>>a[i];
        if(a[i]< mx){ ++ans; mx = a[i];}
    }
    cout<<ans<<endl;
    return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define FILE "parade"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const ull ULLINF = numeric_limits<ull>::max();
const double PI = acos(-1.0);

long long x[100010], l;
int n;
int r[18][100010];

int binsearch(int i)
{
    int tl = i, tr = n, res = i + 1;
    while(tl <= tr)
    {
        int tm = (tl + tr) >> 1;
        if(x[i] + l >= x[tm])
            res = tm, tl = tm + 1;
        else
            tr = tm - 1;
    }
    return res;
}

int main()
{
//    freopen(FILE".in", "r", stdin);
//    freopen(FILE".out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> x[i];
    cin >> l;
    for(int i = 0; i < n; i++)
        r[0][i] = upper_bound(x, x + n, x[i] + l) - 1 - x;
    for(int h = 1; h <= 16; h++)
        for(int i = 0; i < n; i++)
            r[h][i] = r[h - 1][r[h - 1][i]];
    int q;
    cin >> q;
    while(q--)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if(a > b)
            swap(a, b);
        int tl = 1, tr = n, res = n;
        while(tl <= tr)
        {
            int tm = (tl + tr) >> 1;
            int cur = tm;
            int c = a, p = 0;
            while(cur)
            {
                if(cur % 2)
                    c = r[p][c];
                cur >>= 1;
                p++;
            }
            if(c == 0 || c >= b)
                res = tm, tr = tm - 1;
            else
                tl = tm + 1;
        }
        cout << res << '\n';
    }
    return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
  ll x,y,z;
  cin>>x>>y>>z;
  cout<<((x-z)/(y+z))<<endl;
    
}
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.LinkedHashSet;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String[] A = new String[n];
      for(int i=0;i<n;i++){
        A[i]=sc.next();
      }
      int after=check(A);
      if(n==after){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
  }      
  static int check(String[] A){
      Set<String> LinkedHashSet = new LinkedHashSet<String>();
      for (int i=0;i<A.length;i++){
        LinkedHashSet.add(A[i]);
      }
      Object[] A_after = LinkedHashSet.toArray();
      return A_after.length;
  }
}

Measured memory_bytes: 78396
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;
	int n, m,tmp=0,ax=0,k,t[5000],p[5000],x[5000],res[5000];
	string str, str2[5000];
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> t[i];
		tmp += t[i];
	}
	
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >>p[i]>> x[i];
		cout << tmp - t[p[i]-1] + x[i] << endl;
	}

	
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int n;
  cin >> n;
  char t[100000];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    //cout << i << endl;
  }
  if(n % 2 == 1){
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < n/2; i++) {
    //cout << i << " " << i + (n/2) << endl;
    if(t[i] != t[i + (n/2)]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	scanner := Scanner()
	n := ReadInt(scanner)
	a := ReadIntSlice(scanner, n)

	count := 0
	for i := 0; i < n; i++ {
		if a[i]%2 != 0 && (i+1)%2 != 0 {
			count++
		}
	}
	fmt.Println(count)

}

func Scanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func ReadInt(scanner *bufio.Scanner) int {
	var t string

	if scanner.Scan() {
		t = scanner.Text()
	}

	n, err := strconv.Atoi(t)
	if err != nil {
		log.Fatal(err)
	}

	return n

}
func ReadIntSlice(scanner *bufio.Scanner, n int) []int {
	s := make([]int, n)
	var t string

	for i := 0; i < int(n); i++ {
		if scanner.Scan() {
			t = scanner.Text()
		}

		num, err := strconv.Atoi(t)
		if err != nil {
			log.Fatal(err)
		}
		s[i] = num
	}

	return s
}


Measured memory_bytes: 1836
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const int N = 15e4;
vector<vector<int>> g0(N), g1;
map<int, ld> dp[N];
int n;
ld dfs0(int i, int p) {
  int cnt = 0;
  ld res = 0;
  for(int j : g0[i]) if(j != p) {
    cnt++;
    res += dfs0(j, i);
  }
  if(cnt) res /= cnt, res += 1.0;
  return dp[i][p] = res;
}
ld dfs1(int i, int p) {
  if(dp[i].count(p)) return dp[i][p];
  vector<int> gi;
  int cnt = 0;
  ld res = 0;
  if(p == -1) {
    for(int j : g0[i]) {
      cnt++;
      res += dfs1(j, i);
    }
  } else {
    cnt = g0[i].size() - 1;
    res = (dfs1(i, -1) - 1.0) * g0[i].size() - dfs1(p, i);
  }
  if(cnt) res /= cnt, res += 1.0;
  return dp[i][p] = res;
}
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n;
  for(int i = 0; i < n - 1; i++) {
    int a, b; cin >> a >> b; a--; b--;
    g0[a].emplace_back(b);
    g0[b].emplace_back(a);
  }
  // g1 = g0;
  dfs0(0, -1);
  cout << fixed << setprecision(8);
  for(int i = 0; i < n; i++) cout << dfs1(i, -1) << endl;
  // for(int i = 0; i < n; i++) cout << dp[i][-1] << endl;
  return 0;
}


Measured memory_bytes: 60416
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int T = scanner.nextInt();
        int time = 0;
        int biscuitNum = 0;

        if(A <= T) {
            time += A;
            for (int i = 0; time <= T + 0.5; ++i) {
                time += A;
                biscuitNum += B;
            }
        }
        System.out.println(biscuitNum);
    }
}


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

using namespace std;

bool dfs(int v, vector<vector<int> >& graph, vector<bool>& used, vector<int>& match) {
	used[v] = true;
	for(int i = 0; i < graph[v].size(); ++i) {
		int u = graph[v][i];
		int w = match[u];
		if(w == -1 || (!used[w] && dfs(w, graph, used, match))) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int main(void) {
	int N;
	cin >> N;
	vector<vector<int> > graph(2 * N, vector<int>(0, 0));
	vector<pair<int, int> > P;
	vector<pair<int, int> > Q;
	for(int i = 0; i < N; ++i) {
		int a, b;
		cin >> a >> b;
		P.push_back(make_pair(a, b));
	}
	for(int j = 0; j < N; ++j) {
		int c, d;
		cin >> c >> d;
		Q.push_back(make_pair(c, d));
	}
	for(int i = 0; i < N; ++i) {
		for(int j = 0; j < N; ++j) {
			if(P[i].first < Q[j].first && P[i].second < Q[j].second) {
				graph[i].push_back(N + j);
				graph[N + j].push_back(i);
			}
		}
	}
	int result = 0;
	vector<int> match(2 * N, -1);
	for(int i = 0; i < 2 * N; ++i) {
		if(match[i] == -1) {
			vector<bool> used(2 * N, false);
			if(dfs(i, graph, used, match)) {
				++result;
			}
		}
	}
	cout << result << '\n';
	return 0;
}



Measured memory_bytes: 256
using System.Collections.Generic;
using System;

public class P
{
    public string a { get; set; }
    public int b { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var d1 = new string[] { "yotta", "zetta", "exa", "peta", "tera", "giga", "mega",
            "kilo", "hecto", "deca", "deci", "centi", "milli", "micro", "nano", "pico", "femto",
            "ato", "zepto", "yocto" };
        var d2 = new int[] { 24, 21, 18, 15, 12, 9, 6, 3, 2, 1, -1, -2, -3, -6, -9, -12, -15, -18, -21, -24 };
        var d = new Dictionary<string, int>();
        for (int i = 0; i < d1.Length; i++) d[d1[i]] = d2[i];
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var ret = getAns(line[0]);
            if (d.ContainsKey(line[1]))
            {
                var w = ret.b + d[line[1]];
                Console.WriteLine("{0} * 10^{1} {2}", ret.a, w, line[2]);
            }
            else Console.WriteLine("{0} * 10^{1} {2}", ret.a, ret.b, line[1]);
        }
    }
    public static P getAns(string s)
    {
        var ret = "";
        var sL = s.Length;
        var si = s.IndexOf('.');
        if (si == -1)
        {
            if (sL == 1) return new P { a = s, b = 1 };
            ret = s.Substring(0, 1) + "." + s.Substring(1);
            return new P { a = ret, b = sL - 1 };
        }
        else if (s.Substring(0, 2) == "0.")
        {
            var first = true; var count = 0;
            for (int i = 2; i < sL; i++)
            {
                if (s[i] == '0' && first) count++;
                else if (s[i] == '0' && !first) ret += s[i].ToString();
                else if (s[i] != '0' && first) { ret += s[i].ToString() + "."; first = false; }
                else { ret += s[i]; first = false; }
            }
            if (ret[ret.Length - 1] == '.') ret = ret.Replace(".", "");
            return new P { a = ret, b = -count - 1 };
        }
        else
        {
            var w = s.Replace(".", "");
            ret = w.Substring(0, 1) + "." + w.Substring(1);
            return new P { a = ret, b = si - 1 };
        }
    }
}


Measured memory_bytes: 9268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N=200010;
int a[N];
int n, m;
int main(){
	int t;
	// while(){
		int cnt=0, l, r;
		scanf("%d%d%d",&l,&r,&n);
		for(int i=l; i<=r; ++i){
			if(i%n==0)++cnt;
		}
		cout<<cnt<<endl;
	// }
}

Measured memory_bytes: 3624
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> y;
  rep(i, n+1) {
    rep(j, n+1) {
      k = n - i - j;
      if (k < 0) continue;
      cnt = 10000 * i + 5000 * j + 1000 * k;
      if (cnt != y) continue;
      cout << i << " " << j << " " << k << "\n";
      return 0;
    }
  }
  Cout("-1 -1 -1");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    long num;
    cin >> num;
    vector<pair<long,long> > v;
    long current;
    for(long i=0;i<num;i++){
        cin >> current;
        v.push_back(make_pair(current,i));
    }
    sort(v.begin(),v.end());
    long index = 0;
    long number = 1;
    long sum = 0;
    current = v[0].first;
    for(long i=1;i<num;i++){
        if(v[i].first == current){
            number ++;
        }else{
            for(long j=index;j<i;j++){
                v[j].first = v[j].second;
                v[j].second = number;
            }
            sum += ((number-1)*number)/2;
            number = 1;
            index = i;
            current = v[i].first;
        }
    }
    for(long i=index;i<num;i++){
        v[i].first = v[i].second;
        v[i].second = number;
    }
    sum += ((number-1)*number)/2;
    sort(v.begin(),v.end());
    for(long i=0;i<num;i++){
        cout << sum-v[i].second+1 << endl;
    }
}

Measured memory_bytes: 6384
let findSumOfDigits s =
  let l = List.of_seq (String.to_seq s) in
  List.fold_left
    (fun acc c ->
      acc + ((Char.code c) - 48))
    0
    l

let main () =
  let line = read_line () in
  let r = (findSumOfDigits line) mod 9 in
  let ans = if r = 0
            then
              "Yes"
            else
              "No" in
  (
    print_string ans;
    print_newline ()
  )

let _ = main ()


Measured memory_bytes: 14768