akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;

int res,n,m,x,y,a[105],b[105];
int main(){
	int maxa = -999,minb = 999;
	scanf("%d %d %d %d",&n,&m,&x,&y);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		if(a[i] > maxa)	maxa = a[i];
	}
	for(int i = 1; i <= m; i++){
		scanf("%d",&b[i]);
		if(b[i] < minb)	minb = b[i];
	}
	
	for(int i = x + 1; i <= y; i++)
		if(i > maxa && minb >= i)
			res = 1; 

	res ? printf("No War") : printf("War");
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <cmath>

// the mean of N numbers will minimize the cost
// let x = (a_1 + a_2 + ... + a_N) / N be the mean of given N numbers
// then (a_1 - x)^2 + (a_2 - x)^2 + .... + (a_N - x)^2 is minimzed
// so we're interested in turning all the numbers into the mean
// but the mean can be a fraction and we're only interested in integers
// so if x is a fraction we'll round it to the nearest integer


int main(int argc, char const *argv[])
{
    int N;
    std::cin >> N;
    std::vector <int> numbers(N);
    
    int sum = 0;
    for(int i = 0 ; i < N ; ++i) {
        std::cin >> numbers[i];
        sum += numbers[i];
    }

    std::div_t result = std::div(sum, N);
    int mean = result.quot;
    if(result.rem > 0){
        // mean is a fraction
        mean = static_cast<int>(std::round(sum * 1.0 / N));
    }

    int cost = 0;
    for(int i = 0 ; i < N ; ++i){
        int difference = mean - numbers[i];
        if(numbers[i] > mean){
            difference = numbers[i] - mean;
        }
        cost += difference * difference;
    }

    std::cout << cost << '\n';

    return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n,0);
    rep(i,n)cin >> a[i];
    sort(a.rbegin(),a.rend());
    ll res = 0;
    rep(i,n-1) res += a[(i+2-1)/2];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
long long n, m, dp[1005][1005], mod=1e9+7;
char grid[1005][1005];
long long go(int i, int j)
{
    if (i==n || j==m || grid[i][j]=='#')
        return 0;
    else if (i==n-1 && j==m-1)
        return 1;
    if (dp[i][j]!=-1)
        return dp[i][j];
    return dp[i][j]=(go(i+1, j)+go(i, j+1))%mod;
}
int main()
{
    cin >> n >> m;
    memset(dp, -1, sizeof dp);
    for (int i=0 ; i<n ; i++)
        for (int j=0 ; j<m ; j++)
            cin >> grid[i][j];
    cout << go(0, 0);
    return 0;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e3+10;
int h,n,A[MAX],B[MAX];
int dp[MAX][10*MAX];
int solve(int idx,int rem){
    if(rem<=0)return 0;
    if(idx>n)return 1e9;
    if(dp[idx][rem]!=-1)return dp[idx][rem];
    int ret = B[idx] + solve(idx,rem-A[idx]);
    ret = min(ret,solve(idx+1,rem));
    return dp[idx][rem] = ret;
}
int main (){
   ios_base::sync_with_stdio(false);
cin.tie(0);
    memset(dp,-1,sizeof dp);
    cin >> h >> n;
    for(int i=1;i<=n;i++){
        cin >> A[i] >> B[i];
    }
    cout<<solve(1 , h);
    //main();
    return 0;
}



Measured memory_bytes: 40576
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;
int main()
{
	string s;
	int k;
	cin >> k >> s;
	if (s.size() <= k)	cout << s << endl;
	else {
		cout << s.substr(0, k) << "..." << endl;
	}
	return 0;
}

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");

int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}

vi vis(100001,0);
vi adj[100001];

int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    priority_queue<int> pq;
    int n,m;
    cin>>n>>m;
    for(int i=0; i<n; ++i)
    {
    	int x;
    	cin>>x;
    	pq.push(x);
    }
    while(m--)
    {
    	pq.push(pq.top()/2);
    	pq.pop();
    }
    ll sum=0;
    while(pq.size()>0)
    {
    	sum+=pq.top();
    	//cout<<pq.top()<<" ";
    	pq.pop();
    }
    //cout<<"\n";
    cout<<sum<<"\n";

    
}

Measured memory_bytes: 3708
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 998244353;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

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

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

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n,m,k; cin >> n >> m >> k;
  vl mpow(n+1); mpow[0] = 1;
  
  rep(i,n){
    mpow[i+1] = mod(mpow[i]*(m-1));
  }
  
  nCrprep();
  
  ll sum = 0;
  
  rep(i,k+1){
    sum += mod(mod(m*mpow[n-i-1])*nCr(n-1,i));
    sum = mod(sum);
  }
  
  cout << sum << endl;
  
  
}

Measured memory_bytes: 51784
#include "bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T & a, const T & b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, MAX = LLONG_MAX;

unordered_map<string, lint> mp, mp2;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s, l, r;
	lint N;
	cin >> N;
	cin >> s;
	l = s.substr(0, N);
	r = s.substr(N, N);
	reverse(r.begin(), r.end());
	REP(i, 1 << N) {
		string red = "", blue = "";
		REP(j, N) {
			if ((i >> j) % 2 == 1) {
				red += l[j];
			}
			else {
				blue += l[j];
			}
		}
		mp[red + " " + blue]++;

		red = "", blue = "";
		REP(j, N) {
			if ((i >> j) % 2 == 1) {
				red += r[j];
			}
			else {
				blue += r[j];
			}
		}
		mp2[red + " " + blue]++;
	}

	lint cnt = 0;
	for (auto itr : mp) {
		if (mp2.find(itr.first) != mp2.end()) {
			cnt += itr.second * mp2[itr.first];
		}
	}
	cout << cnt << endl;
}


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

int main() {
    int N;
    cin >>N;
    int h[60], ans=0, g=0;
    for(int i=0;i<N;i++) cin >> h[i];

    for(int i=0;i<N;i++) {
      if(h[i]>=g){
        ans += 1;
        g = h[i];
      }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//
// Created by 10034 on 2020/7/28.
//

#include <iostream>
using namespace std;
char g[10][10];
int main(){
    int w,h,k,ans=0;
    cin>>h>>w>>k;
    for(int i=0;i<h;++i)
        scanf("%s",g[i]);
    for(int i=0;i<(1<<h);++i){
        for(int j=0;j<(1<<w);++j){
            int cnt=0;
            for(int k=0;k<h;++k){
                for(int l=0;l<w;++l){
                    if(g[k][l]=='#'&&((i>>k)&1)==0&&((j>>l)&1)==0){
                        cnt++;
                    }
                }
            }
            if(cnt==k) ans++;
        }
    }
    cout<<ans<<endl;



    return 0;
}

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

int main()
{
    int a, b, c, d;
    string ans;
    cin  >> a >> b >> c >> d;
    if (abs(a - c) <= d) ans = "Yes";
    else if (abs(a - b) <= d && abs (b - c) <= d) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
int n;
int a[maxn];
vector<int> way[maxn];
ll par[maxn];
int bad;
void dfs(int u, int last) {
    int child = 0;
    for(auto v : way[u]) {
        if(v==last) continue;
        dfs(v, u);
        child++;
    }
    if(child==0) par[u] = a[u];
    else {
        par[u] = 2*a[u];
        for(auto v : way[u]) {
            if(v==last) continue;
            if(par[v]>a[u]) bad = 1;
            par[u] -= par[v];
        }
        if(par[u]>a[u]) bad = 1;
    }
    if(par[u]<0) bad = 1;
//    printf("par %d = %d\n",u,par[u]);
}
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n-1;i++) {
        int u,v; scanf("%d%d",&u,&v);
        way[u].push_back(v);
        way[v].push_back(u);
    }
    if(n==2) {
        printf("%s",a[1]==a[2] ? "YES" : "NO");
        return 0;
    }
    int root = -1;
    for(int i=1;i<=n;i++) if(way[i].size()>1) root = i;
    dfs(root,0);
    if(par[root]!=0) bad = 1;
    printf("%s",bad?"NO":"YES");
}


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

int main(){
    int i, j, a[4];
    string s;
    cin >> s;
    for(i = 0; i < 4; i++){
        a[i] = s[i] - '0';
    }
    for(i = 0; i < 1 << 3; i++){
        int sum = a[0];
        for(j = 0; j < 3; j++){
            if(i >> (2-j) & 1 == 1){
                sum += a[j+1];
            }
            else{
                sum -= a[j+1];
            }
        }
        if(sum == 7){
            printf("%d", a[0]);
            for(j = 0; j < 3; j++){
                if(i >> (2-j) & 1 == 1){
                    putchar('+');
                }
                else{
                    putchar('-');
                }
                printf("%d", a[j+1]);
            }
            printf("=7\n");
            break;
        }
    }
}

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

using namespace std;

template <int p>
struct Modint
{
	int value;

	Modint() : value(0) {}
	Modint(long x) : value(x >= 0 ? x % p : (p + x % p) % p) {}

	inline Modint &operator+=(const Modint &b)
	{
		if ((this->value += b.value) >= p)
			this->value -= p;
		return (*this);
	}
	inline Modint &operator-=(const Modint &b)
	{
		if ((this->value += p - b.value) >= p)
			this->value -= p;
		return (*this);
	}
	inline Modint &operator*=(const Modint &b)
	{
		this->value = (int)((1LL * this->value * b.value) % p);
		return (*this);
	}
	inline Modint &operator/=(const Modint &b)
	{
		(*this) *= b.inverse();
		return (*this);
	}

	Modint operator+(const Modint &b) const { return Modint(*this) += b; }
	Modint operator-(const Modint &b) const { return Modint(*this) -= b; }
	Modint operator*(const Modint &b) const { return Modint(*this) *= b; }
	Modint operator/(const Modint &b) const { return Modint(*this) /= b; }

	inline Modint &operator++(int) { return (*this) += 1; }
	inline Modint &operator--(int) { return (*this) -= 1; }

	inline bool operator==(const Modint &b) const { return this->value == b.value; }
	inline bool operator!=(const Modint &b) const { return this->value != b.value; }
	inline bool operator<(const Modint &b) const { return this->value < b.value; }
	inline bool operator<=(const Modint &b) const { return this->value <= b.value; }
	inline bool operator>(const Modint &b) const { return this->value > b.value; }
	inline bool operator>=(const Modint &b) const { return this->value >= b.value; }

	//requires that "this->value and p are co-prime"
	// a_i * v + a_(i+1) * p = r_i
	// r_i = r_(i+1) * q_(i+1) * r_(i+2)
	// q == 1 (i > 1)
	// reference: https://atcoder.jp/contests/agc026/submissions/2845729 (line:93)
	inline Modint inverse() const
	{
		assert(this->value != 0);
		int r0 = p, r1 = this->value, a0 = 0, a1 = 1;
		while (r1)
		{
			int q = r0 / r1;
			r0 -= q * r1;
			swap(r0, r1);
			a0 -= q * a1;
			swap(a0, a1);
		}
		return Modint(a0);
	}

	friend istream &operator>>(istream &is, Modint<p> &a)
	{
		long t;
		is >> t;
		a = Modint<p>(t);
		return is;
	}
	friend ostream &operator<<(ostream &os, const Modint<p> &a)
	{
		return os << a.value;
	}
};

const int MOD = 1e6+3;

using Int = Modint<MOD>;

Int pow(Int e, int64_t x)
{
	if (x == 0)
		return 1;
	Int res = (x & 1 ? e : 1), tmp = pow(e, x >> 1);
	res *= tmp * tmp;
	return res;
}

void solve(void)
{
	int q;
	scanf("%d", &q);
	vector<Int> acc(MOD);
	acc[1] = 1;
	for (int i = 1; i < MOD-1; i++)
	{
		acc[i + 1] = acc[i] * Int(i + 1);
	}
	while(q--)
	{
		Int x, d;
		int n;
		scanf("%d%d%d", &x.value, &d.value, &n);
		if (d == 0)
		{
			cout << pow(x, n) << endl;
			continue;
		}
		x /= d;
		if (x.value+n-1 >= MOD)
		{
			cout << 0 << endl;
			continue;
		}
		Int ans = acc[x.value+n-1] / acc[x.value-1] * pow(d, n);
		printf("%d\n", ans.value);
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 4736
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();
        long d = sc.nextInt();
        long x;
        long y;
        long s;
        long t;
        long z;
        long zz;
        long zzz;
        long zzzz;
        
        if(b<0 && d<0 ) {
        	z=a*c;
        } else if(a>0 && c>0) {
        	z=b*d;
        }else if(b<0 && c>0) {
        	z=b*c;
        }else if(a>0 && d<0) {
        	z=a*d;
        } else {
        	s=a*c;
        	t=b*d;
        	x=a*d;
        	y=b*c;
        	zz=Math.max(s,t);
        	zzz=Math.max(zz,x);
        	zzzz=Math.max(zzz,y);
        	z=Math.max(zzzz, 0);
        }
        
        System.out.println(z);
        

    }
}


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

int main() {
    int n;
    cin >> n;
    int F[50];
    F[0] = 1;
    F[1] = 1;
    for (int i = 2; i <= n; i++)
        F[i] = F[i-1] + F[i-2];
    cout << F[n] << endl;
    return 0;
}



Measured memory_bytes: 3120
n = int(input())
a = list(map(int,input().split()))
m = 0
for i in range(n):
	if a[i] < 0:
		m = m + 1
b = list(map(abs,a))
b.sort()
ans = 0
if m % 2 == 0:
	for j in range(n):
		ans = ans + b[j]
else:
	for j in range(n):
		if j == 0:
			ans = ans - b[0]
		else:
			ans = ans + b[j]
print(ans)

Measured memory_bytes: 14412
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <map>
#include <cstring>
using namespace std;

string s;
int idx;
bool unknown;
map<string, int> table;

int atom() {
    //cout << "in atom(): ";
    if (islower(s[idx+1])) {
        int ans = table[s.substr(idx, 2)];
        if (ans == 0) unknown = true;
        //cout << s.substr(idx, 2) << endl;
        idx += 2;
        return ans;
    } else {
        int ans = table[s.substr(idx, 1)];
        if (ans == 0) unknown = true;
        //cout << s.substr(idx, 1) << ' ' << idx << endl;
        idx++;
        return ans;
    }
}

int number() {
    //cout << "in number: idx: " << idx ;
    if (isdigit(s[idx+1])) {
        int ans = atoi(s.substr(idx, 2).c_str());
        idx += 2;
        //cout << s.substr(idx, 2) << endl;
        return ans;
    }
    //cout << s[idx] << endl;
    return s[idx++] - '0';
}

int molecular() {
    //cout << "s: " << s << "\t" << "index: " << idx << endl;
    if (idx == s.size() || s[idx] == ')') return 0;
    int ans = 0;
    if (s[idx] == '(') {
        idx++;
        ans = molecular();
        //cout << s[idx] << ' ';
        idx++; // for ')'
        ans *= number();
    } else if (isupper(s[idx])) {
        ans = atom();
        if (isdigit(s[idx])) ans *= number();
    }
    return ans + molecular();
}

int main() {
    while (getline(cin, s)) {
        do {
            if (s == "END_OF_FIRST_PART") break;
            istringstream is(s);
            string ch; int mass;
            is >> ch >> mass;
            table[ch] = mass;
        } while (getline(cin, s));
        while (getline(cin, s)) {
            if (s == "0") break;
            idx = 0;
            unknown = false;
            int ans = molecular();
            if (unknown) cout << "UNKNOWN" << endl;
            else cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1252
#include<iostream>
using namespace std;
int main() {
  int a[100000],b[100000],cnt=0;
  while (1) {
   cin >> a[cnt]>>b[cnt];
   if (a[cnt] == 0&&b[cnt]==0) break;
    ++cnt;
    }
    for (int i = 0; i < cnt; ++i) {
    if(b[i]<=a[i]){
      cout << b[i]<<" "<<a[i] << endl;
   }else{
   cout << a[i]<<" "<<b[i] << endl;}
 }
 return 0;
}




Measured memory_bytes: 3108
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
typedef long long ll;

void factprime(long long x, std::set<long long> &st)
{
    long long i = 2;
    long long cur = x;
    //map<long long, long long> tmp;

    while (cur >= 2)
    {
        for (long long i = 2;; i++)
        {
            if (i * i > cur)
            {
                st.insert(cur);
                return;
            }
            if (cur % i == 0)
            {
                cur = cur / i;
                //tmp[i]++;
                st.insert(i);
                break;
            }
        }
    }
    //primefact[x] = tmp;
}

int main(void)
{
    ll a, b;
    cin >> a >> b;
    std::set<long long> sta;
    std::set<long long> stb;
    factprime(a, sta);
    factprime(b, stb);
    //cout << sta << stb << endl;
    auto itra = sta.begin();
    auto itrb = stb.begin();
    long long ans = 1;
    for (; itra != sta.end() && itrb != stb.end();)
    {
        if (*itra == *itrb)
        {
            ans++;
            itra++;
            itrb++;
        }
        else if (*itra > *itrb)
        {
            itrb++;
        }
        else
        {
            itra++;
            /* code */
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
/*

                   بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
                  لآ اِلَهَ اِلّا اللّهُ مُحَمَّدٌ رَسُوُل اللّهِ
*/

/*
    Auther:   n0oO0o0Ob(None of them)
    from  :   https://n0oo0o0ob.sleek.page/

*/




#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define pb push_back

                                        #define noob n0oO0o0Ob
// ---------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
//----------------------------------
const ld PI = acos((ld)-1);
const int MOD = 1000000007;
//----------------------------------


int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int a, b;
    cin >> a >> b;
    int x = 100 *(10-a);
    if(a <= 10) cout << x+b << endl;
    else cout << b << endl;



	return 0;
}



Measured memory_bytes: 3660
#include<iostream>
using namespace std;
int N,S,A[3000];
long mod=998244353,dp[3001];
main()
{
	cin>>N>>S;
	dp[0]=1;
	long ans=0;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		if(S>=A[i])(ans+=dp[S-A[i]]*(N-i))%=mod;
		for(int j=S-A[i]-1;j>=0;j--)
		{
			(dp[j+A[i]]+=dp[j])%=mod;
		}
		dp[0]++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> pi;
#define inf 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define mt make_tuple

vector<pi> v;
ll n, k, a, b, ans=0;

int main(){

cin >> n >> k;
rep(i, 0, n-1){
cin >> a >> b;
v.pb({a,b});
}
sort(v.begin(), v.end());
rep(i, 0, n-1){
ans+=v[i].s;
if(k<=ans){cout << v[i].f ;break;}
}



return 0;}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
  
#define INF 2000000010
#define mod7 1000000007
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define INF_LL 9223372036854775
#define EPS 1e-10
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double 
 
using namespace std;

#define MAX_N 2005

int N, K;
vector<int> Edge[MAX_N];

void input(){

  cin >> N >> K;
  for(int i = 0; i < N-1; i++){
    int f, t;
    cin >> f >> t;
    f--; t--;
    Edge[f].push_back(t);
    Edge[t].push_back(f);
  }

}

bool used[MAX_N];
int bfs(int pos, int cnt, int pre){
  
  typedef pair<int, int> II;

  memset(used, 0, sizeof(used));
  used[pos] = true;
  queue<II> que;
  que.push(II(pos, cnt));

  int ret = 1;
  while(que.size()){
    
    II p = que.front();
    que.pop();
    
    if(p.second == 0)
      continue;
    
    for(int i = 0; i < (int)Edge[p.first].size(); i++){
      int next = Edge[p.first][i];
      if(!used[next] && next != pre){
	used[next] = true;
	ret++;
	que.push(II(next, p.second-1));
      }
    }

  }

  return ret;

}

int solve(){

  int ret = INF;

  for(int i = 0; i < N; i++){
    if(K%2 == 0){
      ret = min(ret, N-bfs(i, K/2, -1));
    }
    else{
      for(int e = 0; e < (int)Edge[i].size(); e++){
	ret = min(ret, N-(bfs(i, K/2, Edge[i][e]) + bfs(Edge[i][e], K/2, i)));
      }
    }
  }

  return ret;

}

int main(){

  input();

  cout << solve() << endl;

  return 0;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;


typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

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

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}



////////////////////////////////////////////////////////////////////
vector<int> vec[250]{};
int color[250];
int cnt;
int dis[250];

void nb(int t, int c){
color[t]=c;
for(int vi=0;vi<vec[t].size();vi++){
	int v=vec[t][vi];
if(color[v]==-1) nb(v,abs(c-1));
else if(color[v]!=abs(c-1)) cnt=1;
}
}




int main() {
	cnt=0;
int n;
cin>>n;
rep(i,n){
	color[i]=-1;
}
rep(i,n){
	dis[i]=-1;
}
int d[n+1][n+1];

rep(i,n){
rep(j,n){
char ca;
cin>>ca;
  int a=ca-'0';
if(i==j){
d[i][j]=0;continue;}
if(a){d[i][j]=1;}
else d[i][j]=MOD;
if(a) {vec[i].push_back(j); vec[j].push_back(i);}
}
}

nb(1,0);
if(cnt){cout<<-1<<endl; return 0;}

int ans=0;



rep(i,n){
	rep(j,n){
		rep(k,n){
d[j][k]=min(d[j][k],d[j][i]+d[i][k]);

		}
	}
}

rep(i,n){
	rep(j,n){
		ans=max(ans,d[i][j]);
	}
}

cout<<ans+1<<endl;
return 0;



}


Measured memory_bytes: 768
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		List<Integer> mark = new ArrayList<>();
		int sum = 0;

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(sc.next());
			sum += a;
			mark.add(sum);
		}
		int be;
		int ans = sum;
		for (int p : mark) {

			be = sum - p;
			if (Math.abs(be - p) < ans) {
				ans = Math.abs(be - p);
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 25172
#include <iostream>
using namespace std;
int main(void) { 
    int n, m, v[101], w[101];  
    int dp[101][10001];  
    cin >> n >> m;  
    for (int i = 0; i < n; i++){  
        cin >> v[i] >> w[i];    }    
        for(int i=0; i<=m; i++) dp[0][i] = 0;    
        for (int i = 0; i < n; i++)   
        for (int j = 0; j <= m; j++) {      
            if (j < w[i])  dp[i + 1][j] = dp[i][j];      
            else            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);    
        }   
        
        cout << dp[n][m] << endl;   
    return 0;
    
}
       


Measured memory_bytes: 7020
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc=new Scanner(System.in);
       String S=sc.next();
       if(S.contains("7")){
           System.out.println("Yes");
       }else{
           System.out.println("No");
       }




    }
}


Measured memory_bytes: 35620
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    int x=1;
    rep(i,0,n){
        if(x*2<x+k)x*=2;
        else x+=k;
    }
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
a, b, C = map(int, input().split())

S = 0.5 * a * b * math.sin(math.pi * C / 180)
print(S)

c = (a ** 2 + b ** 2 - 2 * a * b * math.cos(math.pi * C / 180)) ** 0.5
L = a + b + c
print(L)

h = 2 * S / a

print(h)


Measured memory_bytes: 5720
#include <bits/stdc++.h>
using namespace std;
int main(){

  long long  x;
  cin >> x;
  int  count = 0;
  int count1 = 0;
  
  while(x >= 500){

    x = x - 500;
    count++;
  }
  
  while(x >= 5){
    
    x = x - 5;
    count1 ++;
  }
  
  cout << count * 1000 + count1 * 5 <<endl;
}
    

Measured memory_bytes: 256
n, m = [ int(v) for v in input().split() ]
drink_list = sorted([ [ int(v) for v in input().split() ] for i in range(n) ])

total = 0
for i in drink_list:
    buy = min(m,i[1])
    total += i[0] * buy
    m -= buy

print(total) 

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

class Main {
	static final int M = 1000000007;

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[][] a = new long[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				a[i][j] = sc.nextLong();
			}
		}

		int[][] dp = new int[n + 1][(1 << n)];
		dp[0][0] = 1;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < (1 << n); j++) {
				if (i != Integer.bitCount(j)) continue;
				for (int k = 0; k < n; k++) {
					if ((j & (1 << k)) == 1) continue;
					if (a[i][k] == 1) {
						dp[i + 1][j | (1 << k)] =
								(dp[i + 1][j | (1 << k)] + dp[i][j]) % M;
					}
				}
			}
		}

		System.out.println(dp[n][(1 << n) - 1]);
	}
}


Measured memory_bytes: 205012
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int n;
  cin >> n;
  map <string, int> mp;
  int mx=0;
  rep(i, n){
    string s;
    cin >> s;
    mp[s]++;
    mx = max(mp[s], mx);
  }
  vector <string> vs;
  for(auto t: mp){
    if (t.second == mx) vs.push_back(t.first);
  }
  sort(vs.begin(), vs.end());
  for(auto t: vs){
    cout << t << endl;
  }
  return 0;
}

Measured memory_bytes: 28660
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
template<typename T>
class RangeAddQuery {
public:
    explicit RangeAddQuery(int n) : N(calcN_(n)) {
        mVal.assign(2*N+1, 0);
    }
    void update(int l, int r, T value){
        l = max(0, l);
        r = min(N, r);
        int offset = N;
        while(offset > 0){
            if(l >= r) break;
            if(l&1){ update_(mVal[offset+l-1], value); l++; }
            if(r&1){ update_(mVal[offset+r-2], value); }
            l /= 2;
            r /= 2;
            offset /= 2;
        }
    }
    T get(int idx){
        int i = N + idx - 1;
        auto res = mVal[i];
        while(i > 0){
            i = (i-1)/2;
            update_(res, mVal[i]);
        }
        return res;
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    inline void update_(T& data, T val) { data += val; }
    const int N;
    vector<T> mVal;
};


int main(){
    int N, D, A;
    while(cin >> N >> D >> A){
        RangeAddQuery<long long> raq(N);
        vector<pair<long long, long long>> vp(N);
        for(auto& p : vp) cin >> p.first >> p.second;
        sort(vp.begin(), vp.end());
        for(int i=0;i<N;i++){
            raq.update(i, i+1, vp[i].second);
        }
        long long res = 0;
        int end = 0;
        for(int i=0;i<N;i++){
            while(end < N && vp[end].first <= vp[i].first + 2*D) ++end;
            int cur = raq.get(i);
            if(cur <= 0) continue;
            long long req = (cur + A - 1) / A;
            raq.update(i, end, -(req*A));
            res += req;
        }
        cout << res << endl;
    }
}


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

int main(){
  int N, M;

  cin >> N;
  vector<string> red(N);
  for(int i = 0; i < N; i++)
    cin >> red.at(i);

  cin >> M;
  vector<string> blue(M);
  for(int i = 0; i < M; i++)
    cin >> blue.at(i);

  // Redカードを昇順にソート
  sort(red.begin(), red.end());
  // Blueカードを昇順にソート
  sort(blue.begin(), blue.end());

  int cnt = 0;
  int i = 0;
  int j = 0;
  int max = 0;
  string hozon;
  while(i < N){
    cnt = 0;
    hozon = red.at(i);
    // Redカードの同じ単語の個数をカウント
    while(i < N && hozon == red.at(i)){
      cnt++;
      i++;
    }
    // Redカードと同じ単語がでるまでBlueカードを進める
    while(j < M && hozon > blue.at(j)){
      j++;
    }
    // Redカードと同じ単語のBlueカードはマイナスする
    while(j < M && hozon == blue.at(j)){
      cnt--;
      j++;
    }
    //cout << hozon << ": " << cnt << endl;
    // 同じ単語のカウントの最大値を求める
    if(cnt > max){
      max = cnt;
    }
  }
  cout << max;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>n>>m;
    n=n*3+m;
    cout<<n/2<<"\n";
    return 0;
}



Measured memory_bytes: 3572
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323
 
template <class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
T GCD(T a, T b) {
	if (b == 0)
		return a;
	else
		return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
	return (a * b) / GCD(a, b);
}
 
using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long
 
signed main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int sum = 0;
    sort(p.begin(), p.end());
    rep(i, k) sum += p[i];
    cout << sum << endl;
}

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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	string S=in<string>();
	int N=S.size();
	int length=0;
	set<string> V;
	REP(i,N){
		for(int j=i+1;j<=N;j++){
			V.emplace(S.substr(i,j-i));
		}
	}
	for(auto& x:V){
		bool exist=false;
		for(auto& y:x){
			if(y!='A' && y!='T' && y!='G' && y!='C'){
				exist = true;
				break;
			}
		}
		if(!exist){
			length = max<int>(length,x.size());
		}
	}
	out(length);
	return 0;
}


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define INF 		2000000007
#define MOD			10e9+7
#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;


int main(){
	int N,K;cin>>N>>K;
	vector<int> A(N+1);
	REP(i,N)cin>>A[i];
	A[N] = INF;

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

	priority_queue<int> D;
	int ans = 0;
	int cnt = 1;
	REPS(i,1,N+1){
		if(A[i]==A[i-1])cnt++;
		else{
			D.push(cnt);
			cnt = 1;
		}
	}

	REP(i,K){
		if(D.empty())break;
		ans += D.top();
		D.pop();
	}

	cout << (N-ans) << endl;

	return 0;
}



Measured memory_bytes: 2168
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = int(1e9) + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    vi a(N);
    rep(i, N) cin >> a[i];

    vv<int> ans = vvec(H, W, 0);
    int c = 0;
    rep(h, H) {
        if (h % 2) {
            for (int w = 0; w < W; ++w) {
                if (a[c] == 0) c++;
                ans[h][w] = c + 1;
                a[c]--;
            }
        }
        else {
            for (int w = W - 1; w >= 0; --w) {
                if (a[c] == 0) c++;
                ans[h][w] = c + 1;
                a[c]--;
            }
        }
    }

    rep(h, H) {
        rep(w, W - 1) {
            cout << ans[h][w] << " ";
        }
        write(ans[h][W - 1]);
    }
}

Measured memory_bytes: 384
import java.util.*

fun getDistanceArray(graph: Array<IntArray>, s: Int): IntArray {
  val n = graph.size
  val distanceArray = IntArray(n, { -1 })
  fun dfs(v: Int, d: Int) {
    distanceArray[v] = d
    for (u in graph[v]) {
      if (distanceArray[u] >= 0) continue
      dfs(u, d + 1)
    }
  }
  dfs(s, 0)
  return distanceArray
}

fun getDistanceArray(graph: Array<IntArray>, cs: List<Int>): IntArray {
  val n = graph.size
  val distanceArray = IntArray(n, { -1 })
  data class BFSState(val v: Int, val d: Int)
  val queue = ArrayDeque<BFSState>()
  for (c in cs) {
    queue.offerLast(BFSState(c, 0))
    distanceArray[c] = 0
  }
  while (queue.isNotEmpty()) {
    val s = queue.pollFirst()
    for (u in graph[s.v]) {
      if (distanceArray[u] == -1) {
        queue.offerLast(BFSState(u, s.d + 1))
        distanceArray[u] = s.d + 1
      }
    }
  }
  return distanceArray
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val mutableGraph = Array(n, { mutableListOf<Int>() })
  repeat(n - 1) {
    val (v1Raw, v2Raw) = readLine()!!.split(" ").map { it.toInt() }
    val v1 = v1Raw - 1
    val v2 = v2Raw - 1
    mutableGraph[v1].add(v2)
    mutableGraph[v2].add(v1)
  }
  val graph = mutableGraph.map { it.toIntArray() }.toTypedArray()
  val x0 = 0
  val x0DistanceArray = getDistanceArray(graph, x0)
  val x1 = x0DistanceArray.indexOf(x0DistanceArray.max()!!)
  val x1DistanceArray = getDistanceArray(graph, x1)
  val x2 = x1DistanceArray.indexOf(x1DistanceArray.max()!!)
  val x2DistanceArray = getDistanceArray(graph, x2)

  val diameter = x2DistanceArray.max()!!
  val radius = diameter / 2
  // println("diameter: $diameter")
  // println("radius: $radius")
  val centroids = (0 until n).filter {
    if (diameter % 2 == 1) {
      (x1DistanceArray[it] == radius && x2DistanceArray[it] == radius + 1) ||
          (x1DistanceArray[it] == radius + 1 && x2DistanceArray[it] == radius)
    } else {
      x1DistanceArray[it] == radius && x2DistanceArray[it] == radius
    }
  }
  // println("centroids: $centroids")

  fun leafCountForCentroids(inputCentroids: List<Int>): Long {
    val distanceArray = getDistanceArray(graph, inputCentroids)
    val maxChildren = IntArray(radius)
    for (v in 0 until n) {
      val d = distanceArray[v]
      if (d == radius) continue
      val childrenCount = graph[v].count { distanceArray[it] == d + 1 }
      maxChildren[d] = Math.max(maxChildren[d], childrenCount)
    }

    val leafCount = inputCentroids.size.toLong() *
        maxChildren.fold(1L, { l: Long, r: Int -> l * r.toLong() })
    return leafCount
  }

  val colorCount = radius + 1
  if (centroids.size == 2) {
    val leafCount = leafCountForCentroids(centroids)
    println("$colorCount $leafCount")
  } else if (centroids.size == 1) {
    val c = centroids[0]
    var minLeafCount = leafCountForCentroids(centroids)
    for (v in graph[c]) {
      minLeafCount = Math.min(minLeafCount, leafCountForCentroids(listOf(c, v)))
    }
    println("$colorCount $minLeafCount")
  } else {
    throw RuntimeException()
  }
}


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

vector<int> g[200005];
vector<int> ans;

void dfs(int n, int p = -1){
  for(auto c: g[n]){
    if(c == p) continue;
    ans[c] += ans[n];
    dfs(c, n);
  }
}

int main(){
  int n, q;
  cin >> n >> q;
  ans.resize(n);
  for(int i = 0, from, to; i < n - 1; ++i){
    cin >> from >> to;
    from--;
    to--;
    g[from].push_back(to);
    g[to].push_back(from);
  }
  for(int i = 0, node, counter; i < q; ++i){
    cin >> node >> counter;
    node--;
    ans[node] += counter;
  }
  dfs(0);
  for(int i = 0; i < n; ++i) cout << (i ? " " : "") << ans[i];
  cout << endl;
}

Measured memory_bytes: 23424
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define pb push_back
#define fo for(int i=0;i<n;i++)
#define clear cin.clear();cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define loopSolve int t; cin>>t; while(t--){solve();}
//INT_MAX         2,147,483,647                       <10^10
//U_INT_MAX       4,294,967,295                       <10^10
//LONG_LONG_MAX   9,223,372,036,854,775,807           <10^18
//U_LONG_LONG_MAX 18,446,744,073,709,551,615          <10^18

/*ll power(int a, int b){
    return (ll)(pow(a,b)+0.5);
}*/

vector<int> gV(int n){
    vector<int> v;
    int input;
    fo { cin>>input; v.pb(input); }
    return v;
}

int* gA(int n){
    int* arr = new int[n];
    fo cin>>arr[i];
    return arr;
}


void solve(){
    int H,W,K;
    cin>>H>>W>>K;
    char** arr= new char*[H];
    for(int i=0;i<H;i++){
        arr[i]=new char[W];
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>arr[i][j];
        }
    }
    int range = (1<<H+W)- 1;
    ll ans=0;
    for(int i=0;i<=range;i++){
        int t=i,count=0;
        map<int,bool> row;
        map<int,bool>col;
//        char s[100];
        while(t>0){

            if(t&1==1){
//                s[count]='1';
                if(count<W){
                    col[count]=true;
                }else{
                    row[count-W]=true;
                }
            }
//            }else{
//                s[count]='0';
//            }
            t=t>>1;
            count++;
        }
//        s[count]='\n';
//        cout<<"\n-------------------------------"<<endl;
//        for(int i=0;i<5-count;i++)
//            cout<<0;
//        for(int i=count-1;i>=0;i--){
//            cout<<s[i];
//        }
//        cout<<endl;

        ll temp=0;
        for(int p=0;p<H;p++){
            if(row[p]){
//                cout<<"\tAlready Painted Row "<<p<<endl;
                continue;
            }
            for(int q=0;q<W;q++){
                if(col[q]){
//                    cout<<"\tAlready Painted Col "<<q<<endl;
                    continue;
                }
                if(arr[p][q]=='#'){
                    temp++;
//                    cout<<"\t\tFound # for "<<"("<<p<<","<<q<<")"<<endl;
                }
            }
        }
//        cout<<"\ttemp was "<<temp;
        if(temp==K){
            ans++;
        }

    }

    cout<<ans<<endl;




//    for(int i=0;i<H;i++){
//        for(int j=0;j<W;j++){
//            cout<<arr[i][j];
//        }
//        cout<<endl;
//    }

}




int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    //loopSolve;

	return 0;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <algorithm>

using namespace std;

int N;
typedef long long int ll;
ll K;
ll A[200007];

bool possible(ll max_val){
    // printf("testing %lld\n",max_val);
    ll c=0;
    for(int i=1;i<=N;i++){
        ll t=max_val;
        ll twice=A[i];
        c+=((twice/t)-(twice%t==0));
        // printf("c=%lld\n",c);
    }

    return c<=K;
}

int main(){

    scanf("%d%lld",&N,&K);
    for(int i=1;i<=N;i++) scanf("%lld",A+i);

    ll low=1,high=(*max_element(A+1,A+N+1))+1;
    ll res=high-1;
    // int i=0;
    while (high!=low){
        // printf("low=%lld high=%lld\n",low,high);
        ll mid=(low+high)/2;
        if (possible(mid))
            high=mid,res=min(mid,res);
        else 
            low=mid+1;
        // i++;
    }

    printf("%lld\n",res);

    return 0;
}

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

using namespace std;

int main()
{
   int n,m,sum=0;
   cin>>n>>m;
   int a[m];
   for(int i=0;i<m;i++)
   {
       cin>>a[i];
       sum+=a[i];

   }
   if(sum>n){cout<<-1;}
   else{cout<<n-sum<<endl;}
    return 0;
}


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

namespace ALDS1_3_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var v = Console.ReadLine();
            var values = v.Split(' ').Select(s => s).ToList();
            Stack stack = new Stack();
            Console.WriteLine(stack.calculation(values));
        }
    }

    public class Stack
    {
        int top { get; set; }
        int max { get; set; }
        int[] stack { get; set; }

        public Stack()
        {
            top = 0;
            max = 100;
            stack = new int[max];
        }

        private bool isEmpty()
        {
            return top == 0;
        }

        private bool isFull()
        {
            return top >= max;
        }

        private void push(int v)
        {
            if(isFull())
            {
                Console.WriteLine("オーバーフロー");
            }
            stack[top] = v;
            top++;
        }

        private int pop()
        {
            if(isEmpty())
            {
                Console.WriteLine("アンダーフロー");
            }
            top--;
            return stack[top];
        }

        public int calculation(List<string>values)
        {
            foreach(var x in values) {
                if (x == "+")
                {
                    int a = pop();
                    int b = pop();
                    push(b + a);
                }
                else if (x == "-")
                {
                    int a = pop();
                    int b = pop();
                    push(b - a);
                }
                else if (x == "*")
                {
                    int a = pop();
                    int b = pop();
                    push(a * b);
                }
                else
                {
                    push(int.Parse(x));
                }
            }
            return stack[0];
        }

    }

}



Measured memory_bytes: 18396