akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-6
#define inf LLONG_MAX
using namespace std;

int main() {
	speed;
	string s, t;
	cin >> s >> t;
	map<char, set<int>>m;
	for (int i = 0; i < s.size(); ++i)
		m[s[i]].insert(i);
	ll cp = -1, ans = 0, sz = s.size();
	for (int i = 0; i < t.size(); ++i) {
		auto it = m[t[i]].upper_bound(cp);
		if (it != m[t[i]].end())
			ans += *it - cp, cp = *it;
		else {
			it = m[t[i]].upper_bound(-1);
			if (it != m[t[i]].end())
				ans += sz - cp + *it, cp = *it;
			else
				return cout << -1, 0;
		}
	}
	cout << ans;
}

Measured memory_bytes: 7248
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

signed main(){
  int n;cin >> n;
  vector<int> a(n), b(n);
  rep(i,n)cin >> a[i];
  int sum = accumulate(all(a), 0LL);
  b[0] = sum;
  repi(i,1,n-1){
    b[0] -= 2*a[i];
    i++;
  }
  repi(i,1,n){
    b[i] = 2*a[i-1]-b[i-1];
  }
  cout << b << endl;
  return 0;
}






Measured memory_bytes: 2944
#pragma warning disable
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
using System.Collections;
using static System.Math;
using static System.Console;
class E { static void Main() => new J(); }
class J
{
	const int Mod = 1000000007;
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	public J()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int N, D, B;
	int[] h;
	void Solve()
	{
		var I = G();
		N = I[0];
		D = I[1] - I[2];
		B = I[2];
		h = new int[N];
		for (var i = 0; i < N; i++) h[i] = F();
		WriteLine(FirstBinary(0, Mod, OK));
	}
	bool OK(int n)
	{
		var s = 0L;
		foreach (var p in h)
		{
			var l = p - (long)n * B;
			if (l >= 0) s += (l + D - 1) / D;
			if (s > n) return false;
		}
		return s <= n;
	}
	int FirstBinary(int min, int max, Predicate<int> pred)
	{
		while (min < max)
		{
			var mid = (min + max) / 2;
			if (pred(mid)) max = mid;
			else min = mid + 1;
		}
		return min;
	}
	long GCD(long a, long b)
	{
		var n = (ulong)Abs(a); var m = (ulong)Abs(b);
		if (n == 0) return (long)m; if (m == 0) return (long)n;
		int zm = 0, zn = 0;
		while ((n & 1) == 0) { n >>= 1; zn++; }
		while ((m & 1) == 0) { m >>= 1; zm++; }
		while (m != n)
		{
			if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; }
			else { n -= m; while ((n & 1) == 0) n >>= 1; }
		}
		return (long)n << Min(zm, zn);
	}
}

Measured memory_bytes: 17628
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn main() {
    let v: Vec<i32> = read_vec();
    let result = if v[0] < v[1] && v[1] < v[2] { "Yes" } else { "No" };
    println!("{}", result);
}



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

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

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

print(ans) # 答えの出力

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

using namespace std;


inline bool isPrime(int n){
    int sq=sqrt(n);
    for(int i=3;i<=sq;i+=2){
        if(n%i==0)return false;
    }
    return true;
}



int main(){
    
    int n;
    while(cin>>n){
        if(n==0)break;
        
        int ans=-1;
        if(n%10==9)n++;
        else n=(int)(n/10)*10;
        
        for(int i=n;i>10;i-=10){
            if( isPrime(i-9) && isPrime(i-7) && isPrime(i-3) && isPrime(i-1) ){
                ans=i-1;
                break;
            }
        }
        if(ans==-1)ans=13;
        
        cout<<ans<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#define esp 1e-9
#define INF 0x3f3f3f3f
#define Pi acos(-1.0)
const int maxn = 1e3;
typedef long long ll;
using namespace std;
struct strstrstr
{
    string s;
};
strstrstr t[maxn];
bool cmp(struct strstrstr &a, struct strstrstr &b)
{
    return a.s < b.s;
}
int main()
{
    int n, l;
    cin>>n>>l;
    for(int i=0;i<n;i++)
    {
        string str;
        cin>>str;
        t[i].s = str;
    }
    sort(t, t+n, cmp);
    for(int i=0;i<n;i++)
        cout<<t[i].s;
    cout<<endl;
    return 0;
}


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

struct UnionFind{
  Int n;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> d(n);
  for(Int i=0;i<n;i++) cin>>d[i];
  map<Int, Int> r;
  for(Int i=0;i<n;i++) r[d[i]]=i;

  vector<vector<Int> > G(n);
  auto NO=[](){cout<<-1<<endl;exit(0);};
  auto add_edge=[&](Int x,Int y){
		  G[x].emplace_back(y);
		  G[y].emplace_back(x);
		};

  using P = pair<Int, Int>;
  priority_queue<P> pq;
  vector<Int> s(n,1),used(n,0);
  for(Int i=0;i<n;i++) pq.emplace(d[i],i);
  
  while(pq.size()>1u){
    Int x,v;
    tie(x,v)=pq.top();pq.pop();
    
    Int nd=x-(n-s[v])+s[v];
    if(!r.count(nd)) NO();
    
    Int u=r[nd];    
    if(used[u]) NO();
    
    add_edge(v,u);
    s[u]+=s[v];    
    used[v]=1;
  }

  vector<Int> sz(n,1);
  vector<Int> dp1(n,0),dp2(n,0);
  function<Int(Int, Int)> dfs1=
    [&](Int v,Int p){
      for(Int u:G[v]){
	if(u==p) continue;
	dp1[v]+=dfs1(u,v);
	dp1[v]+=sz[u];
	sz[v]+=sz[u];
      }
      return dp1[v];
    };
  
  function<void(Int, Int, Int)> dfs2=
    [&](Int v,Int p,Int d){
      Int sum=0;
      dp2[v]=dp1[v]+d;
      for(Int u:G[v])
	if(u!=p) sum+=dp1[u]+sz[u];
      for(Int u:G[v])
	if(u!=p) dfs2(u,v,d+sum-(dp1[u]+sz[u])+(n-sz[u]));
    };
  
  dfs1(0,-1);
  dfs2(0,-1,0);

  //for(Int i=0;i<n;i++) cout<<d[i]<<" "<<dp2[i]<<endl;
  for(Int i=0;i<n;i++) if(d[i]!=dp2[i]) NO();
  
  for(Int v=0;v<n;v++)
    for(Int u:G[v]) if(v<u) cout<<v+1<<" "<<u+1<<endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        //cout << "HI" << endl;
    }
    bool flag = true;
    int cnt = -1;
    while(flag){
        for(int i=0;i<n;i++){
            if(a[i]%2==0){
                a[i] = a[i]/2;
                
            }else{
              flag = false;
              break;
            } 
        }
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        persons: [i32; n],
    }

    persons.sort();
    let &min = persons.first().unwrap();
    let &max = persons.last().unwrap();

    let mut ans: i32 = max.pow(2) * n as i32;
    for p in min..(max + 1) {
        let s = persons.iter().map(|x| (x - p).pow(2)).sum();
        if s < ans {ans = s;}
    }
    println!("{:?}", ans);
}


Measured memory_bytes: 4352
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;



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

	cin >> H >> W;
	cin >> N;
	vector<pair<long long int, long long int>>place(N);
	vector<long long int>x(N);
	vector<long long int>y(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
		place[i].first = x[i];
		place[i].second = y[i];
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	long long int cy, cx;
	cy = y[(N - 1) / 2];
	cx = x[(N - 1) / 2];
	vector<pair<long long int, pair<long long int, long long int>>>ans;
	for (int i = 0; i < N; i++) {
		K += (abs(place[i].first - cx) + abs(place[i].second - cy)) * 2;
		M = max(M, (abs(place[i].first - cx) + abs(place[i].second - cy)));
	}
	ans.push_back({ K - M,{ cx,cy } });
	if (N % 2 == 0) {
		K = 0;
		M = 0;
		cy = y[N / 2];
		for (int i = 0; i < N; i++) {
			K += (abs(place[i].first - cx) + abs(place[i].second - cy)) * 2;
			M = max(M, (abs(place[i].first - cx) + abs(place[i].second - cy)));
		}
		ans.push_back({ K - M,{ cx,cy } });
		K = 0;
		M = 0;
		cx = x[N / 2];
		for (int i = 0; i < N; i++) {
			K += (abs(place[i].first - cx) + abs(place[i].second - cy)) * 2;
			M = max(M, (abs(place[i].first - cx) + abs(place[i].second - cy)));
		}
		ans.push_back({ K - M,{ cx,cy } });
		K = 0;
		M = 0;
		cy = y[(N - 1) / 2];
		for (int i = 0; i < N; i++) {
			K += (abs(place[i].first - cx) + abs(place[i].second - cy)) * 2;
			M = max(M, (abs(place[i].first - cx) + abs(place[i].second - cy)));
		}
		ans.push_back({ K - M,{ cx,cy } });
	}
	sort(ans.begin(), ans.end());
	cout << ans[0].first << endl;
	cout << ans[0].second.first << " " << ans[0].second.second << endl;
	return 0;
}

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

int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n+1);
  for(ll i=0; i<=n; i++) cin >> vec[i];
  ll res = 0;
  ll current = 0;
  vector<ll> mx(n+1);
  if(n == 0 && vec[0] != 1){
    cout << -1 << endl;
    return 0;
  }
  if(n != 0 && vec[0] != 0){
    cout << -1 << endl;
    return 0;
  }
  for(ll i=0; i<=n; i++){
    if(i == 0) mx[i] = 1;
    else{
      if((mx[i-1]-vec[i-1])*2 < vec[i]){
        cout << -1 << endl;
        return 0;
      }
      mx[i] = min((mx[i-1]-vec[i-1])*2, (ll)1e18);
    }
  }
  for(ll i=n; i>=0; i--){
    if(i == n){
      current += vec[i];
      res += current;
    }else{
      current = min(vec[i]+current, mx[i]);
      res += current;
    }
  }
  cout << res << endl;
  return 0;
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int N = 1e5 + 10, mod = 1e9 + 7;
int fact[N], invfact[N];
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (((ll) x) * y) % mod;}
inline int powr(int a, ll b){
	int x = 1 % mod;
	while(b){
		if(b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a){ return powr(a, mod - 2);}
void pre(){
	fact[0] = invfact[0] = 1;
	for(int i = 1;i < N; i++) fact[i] = mul(i, fact[i - 1]);
	invfact[N - 1] = inv(fact[N - 1]);
	for(int i = N - 2; i >= 1; i--) invfact[i] = mul(invfact[i + 1], i + 1);
	assert(invfact[1] == 1);
}

inline int C(int n, int k){
	if(n < k || k < 0) return 0;
	return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

int dp[1005][1005], dp2[1005][1005];
int a[1005];
int main(){
	pre();
	dp[0][0] = 1;
	int n, k; sd(n); sd(k);
	for(int i = 1; i <= k; i++){
		sd(a[i]);
		for(int old = 0; old <= n; old++){
			for(int x = 0; x <= a[i] && x + old <= n; x++){
				dp[i][old + x] = add(dp[i][old + x], mul(dp[i - 1][old], mul(invfact[x], C(n - x, a[i] - x))));
			}
		}
		// trace(dp[i][1], dp[i][2], dp[i][3]);
	}
	printf("%d\n", mul(fact[n], dp[k][n]));
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
bool isOK(const string& s, int i, int m, int f) {
    string memo = s.substr(m - i + f, i);
    reverse(memo.begin(), memo.end());
    return memo == s.substr(m + 1, i);
}
//(ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9 + 7;
    int n;
    cin >> n;
    vector<P> ans;
    if (n % 2) {
        rep(i, 1, n) {
            ans.emplace_back(i, n);
        }
    }
    else n++;
    vector<vector<int>> vec(n+1, vector<int>(n+1, false));
    rep(i, 1, n / 2 + 1) {
        rep(j, 1, n - 1) {
            if (j == i || j == n - i) continue;
            if (!vec[i][j]) ans.emplace_back(i, j);
            vec[i][j] = true;
            vec[j][i] = true;
            if (!vec[n - i][j]) ans.emplace_back(n - i, j);
            vec[n - i][j] = true;
            vec[j][n - i] = true;
        }
    }
    cout << ans.size() << endl;
    for (P it : ans) cout << it.first << ' ' << it.second << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){

  Node x;
  
  if(x == NIL || k == x->key) return x;
  if(k<x->key) return treeSearch(x->left, k);
  else return treeSearch(x->right, k);
}

Node treeSuccessor(Node x){
  Node y;
  
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u != NIL){
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
  }
}
void preorder(Node u){
  printf(" %d", u->key);
  if(u->left!=NIL) preorder(u->left);
  if(u->right!=NIL) preorder(u->right);
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040
#include <bits/stdc++.h>
const int MAX=1e6+10;
const int modn=1e9+7;
typedef long long ll ;
#define endl '\n'
#define cwk     freopen("D:\\workplace\\CLion\\in.in","r",stdin),freopen("D:\\workplace\\CLion\\out.out","w",stdout)
using namespace std;
ll fastpow(ll a,ll n){
    ll res=1;
    while(n){
        if(n&1){
            res=(res*a)%modn;
        }
        a=(a*a)%modn;
        n>>=1;
    }
    return res;
}
int n,m;
string a,b;
void slove(){
    cin>>a;
    if(a.find("RRR")!=-1)
        cout<<"3";
    else if(a.find("RR")!=-1)
        cout<<"2";
    else if(a.find("R")!=-1)
        cout<<"1";
    else cout<<"0";
}
int main() {
    //ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    //cwk;
    int _=1;
    //cin>>_;
    while(_--){
        slove();
    }
    return 0;
}

Measured memory_bytes: 3628
import sys

N, K = map(int, sys.stdin.readline().split())
V = list(map(int, sys.stdin.readline().split()))

ans = 0

for i in range(N+1):
    if K < i:
        continue
    score = sum(V[0:i])
    # print("i", i, "l score", score)
    ans = max(ans, score)
    for j in range(N+1):
        if N < i + j or K < i + j:
            continue
        tmp = score
        tmp += sum(V[N-j:])
        ans = max(ans, tmp)
        # print("i", i, "j", j, "lr score", tmp)

        # 捨てる最大個数
        k = K - i - j
        if k < 0:
            continue
        negs = []
        for n in range(0, i):
            if V[n] < 0:
                negs.append(V[n])
        for n in range(N-j, N):
            if V[n] < 0:
                negs.append(V[n])
        negs.sort()
        # print(negs)
        tmp -= sum(negs[:k])
        ans = max(ans, tmp)
        # print("i", i, "j", j, "k", k, "lrd score", tmp)

print(ans)

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

int A,B;

int main() {
  cin >> A >> B;
  int res = 0;
  //res = res + max(A,B);
  for (int i = 0; i<2; i++) {
    if (A > B) {
      res = res + A;
      A--;
    } else {
      res = res + B;
      B--;
    }
  }
  cout << res << "\n";

#if 0
  cout << A << " " << B << "\n";
#endif
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int
main(void)
{
  int h, w, i, j;
  while (1) {
    scanf("%d %d", &h, &w);
    if (h == 0 && w == 0) {
      break;
    }
    for (i = 0; i < h; i++) {
      for(j = 0; j < w; j++) {
        printf("%c", '#');
      }
      printf("\n");
    }
    printf("\n");
  }
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int d;
vector<int> c(26);
vector<vector<int>> s(400, vector<int>(26));

int get_score(vector<int> t){
    int ans = 0;
    vector<int> last(26, 0);
    rep(i, d){
        ans += s[i][t[i]];
        rep(j, 26){
            if(t[i] == j)last[j] = i+1;
            ans -= c[j] * ((i+1)-last[j]);
        }
    }
    return ans;
}

int main() {
    cin >> d;
    rep(i, 26)cin >> c[i];
    rep(i, d)rep(j, 26)cin >> s[i][j];
    //-----code------// 
    vector<P> a;
    rep(i, 26){
        int now = 0;
        rep(j, d)now += s[j][i];
        a.push_back({now, i+1});
    }
    sort(rall(a));
    vector<int> t(d, a[0].second);
    while(clock() < 1950000){
        int D = rand() % d, q = rand() % 26;
        int old = t[D], olds = get_score(t);
        t[D] = q;
        if(get_score(t) < olds)t[D] = old;
    }
    rep(i, d)cout << t[i]+1 << endl;
}


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

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    using i64=int_fast64_t;
    i64 a;
    const i64 MOD=1000000007;
    modint(i64 a_=0){
        a=a_%MOD;
        if(a<0) a+=MOD;
    }
    modint inv()const{
        i64 n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y;
        y.a=a+x.a;
        if(y.a>MOD) y.a-=MOD;
        return y;
    }
    modint operator-(const modint& x){
        modint y;
        y.a=a-x.a;
        if(y.a<0) y.a+=MOD;
        return y;
    }
    modint operator*(const modint& x){
        modint y;
        y.a=(a*x.a)%MOD;
        return y;
    }
    modint operator/(const modint& x){
        modint y;
        y.a=(a*x.inv().a)%MOD;
        return y;
    }
    modint& operator+=(const modint& x){
        a+=x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint& operator-=(const modint& x){
        a-=x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    modint& operator*=(const modint& x){
        (a*=x.a)%=MOD;
        return *this;
    }
    modint& operator/=(const modint& x){
        (a*=x.inv().a)%=MOD;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    int_fast64_t a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(int_fast64_t a,int_fast64_t b){
    modint _;
    int_fast64_t n=1,A=a,MOD=_.MOD;
    while(b){
        if(b&1) (n*=A)%=MOD;
        (A*=A)%=MOD;
        b>>=1;
    }
    _.a=n;
    return _;
}

class ARobotRacing {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n;
        in>>n;
        vector<int> x(n);
        for(auto&i:x) in>>i;
        modint ans(1);
        int c=1;
        fr(i,n){
            ans*=c;
            if(x[i]>2*c-2) ++c;
        }
        out<<ans<<endl;
    }
};

int main() {
    ARobotRacing solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 640
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

temp = T - H[0] * 0.006 - A
ans = 0
for i, height in enumerate(H):
    B = T - height * 0.006 - A
    if abs(T - height * 0.006 - A) <= abs(temp):
        temp = T - height * 0.006 - A
        ans = i + 1

print(ans)

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

vector<int> divisor(int n) {
  vector<int> res;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i * i != n) res.push_back(n / i);
    }
  }
  sort(begin(res), end(res));
  return res;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 1;
  ll mx = accumulate(begin(a), end(a), 0);
  auto div = divisor(mx);
  for (auto d : div) {
    ll cnt = 0;
    vector<int> phase(n);
    for (int i = 0; i < n; i++) {
      phase[i] = a[i] % d;
      cnt += phase[i];
    }
    sort(begin(phase), end(phase));
    ll sum = accumulate(begin(phase), begin(phase) + n - cnt / d, 0LL);
    if (sum <= k) ans = max(ans, (ll)d);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = gets.to_i
ls = gets.split.map(&:to_i)

ls = ls.sort

ret = 0

i = 0
while i < N
  j = i + 1
  k = j + 1
  while k < N
    if ls[i] + ls[j] <= ls[k]
      j += 1
      if j == k
        k += 1
      end
    else
      ret += k - j
      k += 1
    end
  end
  i += 1
end

p ret



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

int main() {
	string S;
	int count1 = 0, count2 = 0;
	cin >> S;
	for (int i = 0; i < S.size(); i++) { //1010
		if (S[i] == '1' && i % 2 == 0) count1++;
		else if (S[i] == '0' && i % 2 == 1) count1++;
		else count2++;
	}
	cout << min(count1, count2);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    inl(n,a,b);

    
    out((n/(a+b))*a+min(n%(a+b),a));
}

Measured memory_bytes: 256
s = str(input())
S = s.split('/')
if int(S[0]) > 2019:
  print('TBD')
elif int(S[0]) == 2019:
  if int(S[1]) > 4:
    print('TBD')
  elif int(S[1]) == 4:
    print('Heisei')
  else:
    print('Heisei')
else:
  print('Heisei')

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	s := Scan()
	e := make([]int, n)
	w := make([]int, n)
	for i := 0; i < n; i++ {
		if string(s[i]) == "E" {
			e[i]++
		} else {
			w[i]++
		}
	}
	for i := 1; i < n; i++ {
		w[i] += w[i-1]
	}
	for i := n - 2; i >= 0; i-- {
		e[i] += e[i+1]
	}
	ans := smaller(e[1], w[n-2])
	for i := 1; i < n-1; i++ {
		ans = smaller(e[i+1]+w[i-1], ans)
	}
	fmt.Println(ans)
}


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

int main()
{
  int x, t;
  cin >> x >> t;
  if (x < t) cout << 0 << endl;
  else cout << x - t << endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    /**/
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    long long ans = 0;

    int t = n-1;
    for(int i = 0;i < n;i++){
    int lim = 2;
    if (i == 0) lim = 1;
    for(int j = 0;j < lim;j++) {
      if (t > 0) {
        ans += a[i];
        t--;
        //cout << t << endl;
      }
    }
  }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
pair<long long, int> P = make_pair(1, 0);
vector<vector<int>> child(vector<vector<int>> &E, int r){
  int N = E.size();
  vector<vector<int>> c(N);
  queue<int> Q;
  Q.push(r);
  while (!Q.empty()){
    int v = Q.front();
    Q.pop();
    for (int w : E[v]){
      if (c[w].empty()){
        c[v].push_back(w);
        Q.push(w);
      }
    }
  }
  return c;
}
long long modpow(long long a, long long b){
	a %= MOD;
	long long res = 1;
	while (b > 0){
		if (b % 2 == 1) res = res * a % MOD;
		a = a * a % MOD;
		b = b / 2;
	}
	return res;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
vector<long long> mf;
long long modfact(long long n){
	if (n < mf.size()){
		return mf[n];
	} else {
		if (mf.empty()) mf.push_back(1);
		long long res = mf.back();
		for (int i = mf.size(); i <= n; i++){
			res = res * i % MOD;
			mf.push_back(res);
		}
		return res;
	}
}
long long modbinom1(long long n, long long r){
	long long res;
	res = modfact(n);
	res = res * modinv(modfact(r)) % MOD;
	res = res * modinv(modfact(n - r)) % MOD ;
	return res;
}
pair<long long, int> add(pair<long long, int> A, pair<long long, int> B){
  return make_pair((A.first * B.first) % MOD * modbinom1(A.second + B.second, B.second) % MOD, A.second + B.second);
}
pair<long long, int> root(pair<long long, int> A){
  return make_pair(A.first, A.second + 1);
}
pair<long long, int> dfs1(vector<pair<long long, int>> &dp, vector<vector<int>> &c, int v){
  for (int w : c[v]) dp[v] = add(dp[v], root(dfs1(dp, c, w)));
  return dp[v];
}
void dfs2(vector<pair<long long, int>> &dp1, vector<pair<long long, int>> &dp2, vector<vector<int>> &c, int v){
  int deg = c[v].size();
  vector<pair<long long, int>> L(deg + 1, P), R(deg + 1, P);
  for (int i = 0; i < deg; i++) L[i + 1] = add(L[i], root(dp1[c[v][i]]));
  for (int i = deg - 1; i >= 0; i--) R[i] = add(R[i + 1], root(dp1[c[v][i]]));
  for (int i = 0; i < deg; i++){
    dp2[c[v][i]] = root(add(dp2[v], add(L[i], R[i + 1])));
    dfs2(dp1, dp2, c, c[v][i]);
  }
}
int main(){
  int N;
  cin >> N;
  vector<vector<int>> E(N);
  for (int i = 0; i < N - 1; i++){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    E[x].push_back(y);
    E[y].push_back(x);
  }
  vector<vector<int>> c = child(E, 0);
  vector<pair<long long, int>> dp1(N, P), dp2(N, P);
  dfs1(dp1, c, 0);
  dfs2(dp1, dp2, c, 0);
  for (int i = 0; i < N; i++){
    cout << add(dp1[i], dp2[i]).first << endl;
  }
}

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

#define black 1
#define white 0

int main(){

    int l, k; cin >> l >> k;
    vector<vector<long long> > dp(l + 1, vector<long long> (2, 0LL));
    dp[0][white] = 1LL;
    for(int i = 0; i < l; i++){
        for(int j = 0; j < 2; j++){

            if(j == 1){

                //白を置く
                //thin
                dp[i + 1][white] += dp[i][j];
            }else{

                //黒を置く
                //thin
                dp[i + 1][black] += dp[i][j];

                //thick
                if(i + k <= l) dp[i + k][black] += dp[i][j];
            }
        }
    }

    long long ans = 0LL;
    for(int i = 0; i <= l; i++){
        //cout << i << " " << dp[i][1] << endl;
        ans += dp[i][1];
    }

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



Measured memory_bytes: 3184
//////////////////////////
//      _        ____   //
//  U  /"\  u U /"___|  //
//   \/ _ \/  \| | u    //
//   / ___ \   | |/__   //
//  /_/   \_\   \____|  //
//   \\    >>  _// \\   //
//  (__)  (__)(__)(__)  //
//  Compro by NULL_CT©  //
//////////////////////////
// STL libs
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

//Boost
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#define REP(I, LIM) for (int I = 0; I < (LIM); I++)
#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;
using boost::irange;
using boost::multiprecision::cpp_int;

typedef long long ll;

const int MOD = pow(10,9)+7;

vector<ll> divisor(ll &_n) {
  vector<ll> head, tail;
  for (long i = 1; i * i <= _n; i++) {
    if (_n % i == 0) {
      head.push_back(i);
      if (i * i != _n)
        tail.push_back(_n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return head;
}

ll kadanes(vector<ll> &_ls) {
  ll highestMax = 0, currentMax = 0, length = _ls.size();
  for (ll i = 0; i < length; i++) {
    currentMax = max(_ls[i], currentMax + _ls[i]);
    highestMax = max(highestMax, currentMax);
  }
  return highestMax;
}

class UnionFind {
public:
  vector<ll> par;

  UnionFind(ll N) : par(N) {
    for (ll i = 0; i < N; i++)
      par[i] = i;
  }

  ll root(ll x) {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    if (rx == ry)
      return;
    par[rx] =
        ry;
  }

  bool same(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    return rx == ry;
  }
};

struct init {
  init() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // cout<<fixed<<setprecision(20);
  }
} init;

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

int main() {
  cpp_int a, b;
  cin >> a >> b;
  if (a < b) {
    cout<<"LESS\n";
  }else if (a > b) {
    cout<<"GREATER\n";
  } else {
    cout<<"EQUAL\n";
  }
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

vl d;
vl* dijkstra(vv(PL) &G,int V,int s) {
// G[f][i] = P(t,c) means that from `f` to `t` 's cost is `c` 
  d = vl(V,LINF);
  priority_queue<PL,vp, greater<PL>> que;
  d[s] = 0;
  que.push(PL(0,s));
  while(!que.empty()) {
    PL p = que.top();
    que.pop();
    ll  tar = p.second;
    if(d[tar] < p.first) continue;
    rep(i,sz(G[tar])) {
      PL e = G[tar][i];
      if(d[e.first] > d[tar] + e.second) {
        d[e.first] = d[tar] + e.second;
        que.push(PL(d[e.first],e.first));
      }
    }
  }
  return &d;
}
  
int main() {
  int N;
  cin >> N;
  vv(PL) G(N);
  rep(i,N-1) {
    int a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back(PL(b,c));
    G[b].push_back(PL(a,c));
  }
  int q,k;
  cin >> q >> k;
  k--;
  
  vl* res = dijkstra(G,N,k);
  vl ans(q);
  rep(i,q) {
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    ans[i] = (*res)[x] + (*res)[y];
  }
  rep(i,q) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 10752
function main(input) {
    const args = input.split('\n');
  
  	const a = parseInt(args[0], 10),
          b = parseInt(args[1], 10),
          h = parseInt(args[2], 10);
          
    console.log((a+b)*h/2);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;
	vector<int> a(N);
	vector<int> b(N);
	REP(i,N) cin >> a[i];
	REP(i,N) cin >> b[i];

	vector<int> sum_a(N+1,0);
	vector<int> sum_b(N+1,0);
	
	FOR(i,1,N+1){
		sum_a[i] = sum_a[i-1] + a[i-1];
		sum_b[i] = sum_b[i-1] + b[i-1];
	}

	int ans = -1;
	REP(i,N){
		ans = max(ans, sum_a[i+1] + (sum_b[N]-sum_b[i]));
	}

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M   998244353    //1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define N 100005
#define vi vector<int>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,k;
   cin>>n>>k;
   vector<int>v;
   for(int i=0;i<n;i++)
   {
       int x;
       cin>>x;
       v.pb(x);
   }
   sort(v.begin(),v.end());
   int s=0;
   for(int i=0;i<n-k;i++)
   {
       s+=v[i];
   }
   cout<<s<<endl;

}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T>

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

vvi adl_input(int N,int M){ //N頂点M辺
  vvi L(N);
  rep(i,M){
    int a,b;
    cin >> a >> b;
    //a--;b--;
    L[a].push_back(b);
    L[b].push_back(a);
  }
  return L;
}

ll gcd(ll a,ll b){
  if (a%b==0) return(b);
  else return(gcd(b,a%b));
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

vector<int> bfs(vvi L,int S){ //List,Start
  vector<int> v(L.size(),-1);
  v[S]=0;
  queue<int> q;
  q.push(S);
  while(!q.empty()){
    int a=q.front();
    q.pop();
    for(int x:L[a]){
      if (v[x]==-1){
        v[x]=v[a]+1;
        q.push(x);
      }
    }
  }
  return v;//startからの距離
}

void initialize(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
}

/////////////////////////////////////////

int main(){
  initialize();
  int N,D;
  cin >> N >> D;
  int x=D*2+1;
  cout << (N+x-1)/x << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    ll N; cin >> N;
    int ans = 0;
    FOR(i, 2, 1000010) {
        int cur = 0;
        while (N % i == 0) {
            cur++;
            N /= i;
        }
        FOR(j, 1, 10000) {
            if (cur < j) break;
            ans++; cur -= j;
        }
    }
    if (N > 1) ans++;
    cout << ans << nl;
	
	return 0;
}




Measured memory_bytes: 3660
N, M = map(int, input().split())
AB = [[int(a) for a in input().split()] for _ in range(N)]
AB = sorted(AB, key=lambda x: x[0])

sum = 0
remain_cnt = M
i = 0

while(True):
    if remain_cnt <= AB[i][1]:
        sum += remain_cnt * AB[i][0]
        break

    sum += AB[i][0] * AB[i][1]
    remain_cnt -= AB[i][1]
    i += 1

print(sum)


Measured memory_bytes: 23524