akhauriyash/Code-Regression huggingface dataset:
// Problem : A - Five Variables
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define nl cout<<"\n"
#define endl "\n"
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++)
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define f first
#define s second

inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a; a%=b;return gcd(b,a);}
ll power(ll x, ll y){if(y == 0) return 1; ll a = power(x,y/2);if (y % 2 == 0) return a * a; else return x * a * a; }
ll powermod(ll x, ll ex , ll md) {ll ans = 1ll;while (ex > 0) {if (ex & 1ll) ans = (ans * x) % md; ex >>= 1ll;x = (x * x) % md;}return ans;}

const ll inf = 1e18 + 9;
const ll mod = 1e9 + 7;
const ld PI = acos(-1);
const ld eps = 1e-9;

const ll N = 1e6 + 1;

void solve(){
	ll x[5];
	rep(i , 5) cin >> x[i];
	ll mark = 0;
	rep(i ,5) if(x[i] == 0) mark = i;
	cout << mark + 1 << endl;
}
int main(){
    IOS;
    cout << fixed << setprecision(20);
    ll NTC=1;
    // cin>>NTC;
    ll PTC=0;
    while(PTC++<NTC){
        // cout<<"Case #"<<PTC<<":"<<' ';
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 3796
#!/usr/bin/python3

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

    count = 0
    for i, h in enumerate(height):
        if i == 0:
            count += 1
        elif max(height[:i]) <= h:
            count += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
//   PIGMEISTER™   //

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define PI (ld)3.141592653589793238
#define MAX 100005

int main()
{
    jaldi;
    
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    ll cp = 0, cn = 0, cz = 0;
    sidha (i, 0, n) {
        cin >> a[i];
        if (a[i] > 0) cp++;
        else if (!a[i]) cz++;
        else cn++;
    }

    if ((cp == 0 and k&1) or (k == n and cn&1)) {
        ll ans = 1;
        sort(bas(a));
        sidha (i, 0, k) {
            ans *= a[i];
            ans = (ans + MOD*MOD)%MOD;
            //cout<<ans<<' ';
        }
        return cout << ans, 0;
    }
    
    vector<pair<ll, ll>> b(n);
    for (auto i : a) {
        if (i < 0) b.push_back({abs(i), 1});
        else if (i > 0) b.push_back({i, 0});
        else b.push_back({i, 2});
    }
    sort(bas(b));

    ll ccp = 0, ccn = 0, ccz = 0;
    pair<ll, ll> lp = {-1, -1}, ln = {-1, -1};
    sidha (i, 0, k) {
        if (b[i].second == 0) ccp++, lp = {b[i].first, i};
        else if (b[i].second == 1) ccn++, ln = {b[i].first, i};
        else ccz++;
    }
    if (ccz or (ccn&1 and ccn == cn and ccp == cp)) return cout << 0, 0;
    
    if (ccn&1) {
        pair<ll, ll> fp = {0, -1}, fn = {0, -1};
        sidha (i, k, n) {
            if (b[i].second == 2) break;
            else if (fp.second == -1 and b[i].second == 0) {
                fp = {b[i].first, i};
            }
            else if (fn.second == -1 and b[i].second == 1)
                fn = {b[i].first, i};
        }
        
        if (lp.second >= 0) {
            if (lp.first*fp.first > ln.first*fn.first) {
                swap(b[ln.second], b[fp.second]);
            }
            else 
                swap(b[lp.second], b[fn.second]);
        }
        else {
            swap(b[ln.second], b[fp.second]);
        }
    }

    ll ans = 1;
    sidha (i, 0, k) {
        ans *= b[i].first;
        ans %= MOD;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 11052
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
A = LI()
ANS = [0]*(n+1)
ANS[0] = 1
CONTINUE = 0
if A[0] == 0:
    CONTINUE = 1
elif A[0] == 1:
    CONTINUE = 0
else:
    print(-1)
    exit()

tmp = 0
for i in range(1, n+1):
    if A[i] > CONTINUE*2:
        print(-1)
        exit()
    else:
        CONTINUE = CONTINUE*2 - A[i]
        ANS[i] = CONTINUE + A[i]

for i in reversed(range(n+1)):
    tmp += A[i]
    ANS[i] = min(ANS[i], tmp)

print(sum(ANS))


Measured memory_bytes: 702808
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

template<typename T, typename S>
istream& operator>> (istream& in, pair<S, T>& p) {
    in >> p.fs >> p.sn;
    return in;
}
template<typename T, typename S>
ostream& operator<< (ostream& out, pair<S, T>& p) {
    out << p.fs << ' ' << p.sn << ' ';
    return out;
}

template<typename T>
istream& operator>> (istream& in, vector<T>& v) {
    for (T& x : v) in >> x;
    return in;
}
template<typename T>
ostream& operator<< (ostream& out, vector<T>& v) {
    for (T& x : v) out << x << ' ';
    return out;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    int ans = 0;
    cin >> a >> b;
    forn(i, 0, 30) {
        //cerr << i << '\n';
        vector<int> res(n);
        forn(j, 0, n) res[j] = b[j] % (1 << (i + 1));
        sort(all(res));
        int total = 0;
        forn(j, 0, n) {
            int x = a[j] % (1 << (i + 1));
            int st = x ? (1 << (i + 1)) - x : 0;
            int fn = st ^ (1 << i);
            //cerr << x << ' ' << st << ' ' << fn << '\n';
            int cnt = (int)(lower_bound(all(res), st) - res.begin()) - (int)(lower_bound(all(res), fn) - res.begin());
            if (cnt < 0) cnt += n;
            total += cnt;
        }
        //cerr << total << '\n';
        if (total % 2)
            ans ^= (1 << i);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 2672
nu = gets.to_i
item = Array.new(nu, 0)
for i in 0..nu - 1
  item[i] = gets.to_i
end
item = item.sort
ans = 0
ans += (item[-1] / 2)
for i in 0..nu - 2
  ans += item[i]
end
puts ans


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

int H, W, h, w;
int ans;

int main() {
	cin >> H >> W >> h >> w;
	H -= h;
	W -= w;
	ans = H * W;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,j,n) for (int i = j; i < (n); ++i)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(){
    ll n;
    cin >> n;
    vector<ll> C(n,0),D(n+1,0);
    rep(i,n){
        ll ci; cin >> ci;
        ci--;
        C[ci]++;
        D[C[ci]]++;
    } 

    vector<ll> S(n+1,0);
    REP(i,1,n+1) S[i] = S[i-1] + D[i];

    REP(k,1,n+1){
        ll low = 0,high = n+1;
        while(high-low>1){
            ll x = (low+high)/2;
            if(S[x] >= k*x) low=x;
            else high = x;
        }
        cout<<low<<endl;
    }


}

Measured memory_bytes: 7936
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    S = input()
    T = input()

    #TがSの部分文字列になるようにSを書き換える

    N = len(S)
    M = len(T)
    L = N - M #Sを調べるループの回数
    #二重ループが許される
    ans = M
    for i in range(L+1): 
        #最大M個一致していない。
        cnt = M
        for j in range(M):
            if S[i+j] == T[j]: 
                cnt -= 1
        #最小を取る
        ans = min(ans, cnt)
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 9108
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
int main() {
	ll N;
	cin >> N;

	vll a(N + 1);
	repn(i, N) cin >> a[i];

	ll M = 40;
	vll c(M, 0);
	repn(i, N) {
		rep(j, M) {
			if ((a[i] >> j) & 1) { c[j]++; break; }
		}
	}

	ll ans = 0;

	for (ll j = M - 1; j >= 0; j--) {

		ll count = 0;
		repn(i, N) { if ((a[i] >> j) & 1) { count++; } }
		count += ans;

		if (count % 2 == 1) {
			if (c[j] == 0) { cout << -1 << endl; return 0; }
			ans++;
		}
	}

	cout << ans << endl;
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

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

    int N, K; cin >> N >> K;
    vb D(10, false);
    REP(i, K)
    {
        int a; cin >> a;
        D[a] = true;
    }

    int ans = N;
    while(true)
    {
        bool ok = true;
        string s = to_string(ans);
        REP(i, (int)s.length()) if(D[s[i]-'0']) ok = false;
        if(ok)
        {
            cout << ans << endl;
            return 0;
        }
        ans++;
    }
}

Measured memory_bytes: 3716
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

//
// from https://drken1215.hatenablog.com/entry/2018/06/08/210000
//

// ax + by = gcd(a, b) となるような (x, y) を求める
// 多くの場合 a と b は互いに素として ax + by = 1 となる (x, y) を求める
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x); // 再帰的に解く
	y -= a / b * x;
	return d;
}

// 負の数にも対応した mod (a = -11 とかでも OK) 
inline long long mod(long long a, long long m) {
	return (a % m + m) % m;
}

// 逆元計算 (ここでは a と m が互いに素であることが必要)
long long modinv(long long a, long long m) {
	long long x, y;
	extGCD(a, m, x, y);
	return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので
}


ll comb(ll a, ll b)
{
	ll x = 1;
	ll xx = 1;
	for (ll i = 0; i < b; ++i)
	{
		x *= (a - i);
		x %= MOD;
		xx *= (i + 1);
		xx %= MOD;
	}
	x *= modinv(xx, MOD);
	x %= MOD;

	return x;
}

//
// from https://augusuto04.hatenablog.com/entry/2015/05/02/183451
//
ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

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

	ll n, a, b;
	cin >> n >> a >> b;

	ll cands = myPow(2, n, MOD);

	cands -= 1;

	cands -= comb(n, a);
	cands -= comb(n, b);

	cands = mod(cands, MOD);

	//ll ans = x;

	cout << cands << endl;

	//system("pause");
}


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

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
    int n;
    cin >> n;
    vector<pair<string, int>> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
    }
    string x;
    cin >> x;
    int tot = 0;
    bool done = false;
    for (int i = 0; i < n; ++i) {
        if (done) {
            tot += v[i].second;
        }
        if (v[i].first == x) {
            done = true;
        }
    }
    cout << tot << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    test_case();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
   
    int main(){
      int N;
      double ave = 0.0,sum = 0.0;
      int path = 1;
      cin >> N;
      int x[N],y[N];
      double lx,ly;
      for (int i = 1; i <= N; i++)
      {
        cin >> x[i] >> y[i];
        path = path * i;
      }
      vector<int> v(N);
      for (int i = 0; i < N; i++)
      {
        v[i] = i +1;
      }
      do{
        for(int i = 0; i < N-1;i++) sum +=pow((x[v[i]]-x[v[i+1]])*(x[v[i]]-x[v[i+1]])+(y[v[i]]-y[v[i+1]])*(y[v[i]]-y[v[i+1]]),0.5);
        
      }while(next_permutation(v.begin(),v.end()));

      ave = sum/path;
      cout << fixed << setprecision(10)<<ave;
     }

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

/*int max_bai(long a long b);*/

int min_yaku(long a, long max ,long b);

int main(void)
{
        unsigned long a = 0, b = 0, min = 0, max = 0;
        unsigned long i = 0 , r = 0, memoa=0,memob=0;

        while(scanf("%ld %ld", &a , &b) != EOF)
        {

                memoa = a;
                memob = b;
                if(a == b)
                {
                        max = a;
                        min = min_yaku(memoa, max, memob);
                        printf("%ld %ld\n", max, min);
                }
                else if(a != b)
                {
                        while(a != b)
                        {
                                r = abs(a - b);
                                a = b;
                                b = r;
                        }
                        max = a;
                        min = min_yaku(memoa, max, memob);
                        printf("%ld %ld\n", max, min);
                }
        }
        return 0;
}
int min_yaku(long a ,long max ,long b)
{
        long min=0;
        min = a / max * b;
        return min;
}

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

int main(void){
    int x, a, b;
    cin >> x >> a >> b;

    if(a >= b)
        cout << "delicious" << endl;
    if(a < b && (x+a) >= b)
        cout << "safe" << endl;
    if((x+a) < b)
        cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    long long int Q,H,S,D;
    scanf("%lld %lld %lld %lld",&Q,&H,&S,&D);
    if(H>2*Q)H=2*Q;
    if(S>2*H)S=2*H;
    if(D>2*S)D=2*S;
    long long int N;
    scanf("%lld",&N);
    long long int ans=0;
    if(N%2==1){ans+=S;N--;}
    ans+=D*N/2;
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;
int solve(int a, int b,int c,int x){
	int ans=0;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(x==((i*500)+(j*100)+(k*50))){
					ans++;
				}
			}
		}
	}
	return ans;
}

int main(){	
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	cout<<solve(a,b,c,x);	
}

Measured memory_bytes: 3632
from itertools import combinations

def March(n , sl):

    ans = 0
    count = {m: 0 for m in list("MARCH")}

    for i in sl:
        if i[0] in count:
            count[i[0]] += 1

    c = combinations(list("MARCH"), 3)
    for q, w, i in c:
        ans += count[q] * count[w] * count[i]

    return ans

def main():
    n = int(input())
    sl = [str(input()) for i in range(n)]
    print(March(n , sl))

if __name__ == '__main__':
    main()

Measured memory_bytes: 55128
n, k = list(map(int, input().split()))
x = [i for i in range(n+1)]

left, right = [x[0]], [x[-1]]
for i in range(1, n+1):
    left.append(left[i-1] + x[i])
    right.append(right[i-1] + x[-(i+1)])

total = 0
for i in range(k-1, n+1):
    total += right[i] - left[i] + 1

print(total % (10**9 + 7))

Measured memory_bytes: 38124
import numpy as np

# input
N = int(input().split()[0])
sequence = np.array(list( map(int, input().split()) ))

# a_N>N must be removed
remove = np.sum(sequence>N)
sequence = sequence[sequence<=N]

index = np.unique(sequence)

for idx in index:

    n_idx = np.sum(sequence==idx)
    if n_idx < idx:
        remove += n_idx
    else:
        remove += (n_idx-idx)

print(remove)




Measured memory_bytes: 38768
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const int64_t INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int vis[N];
vector<int> g[N];

void dfs(int u) {
    vis[u] = 1;
    for (auto v : g[u]) if (!vis[v]) {
        dfs(v);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (vis[i] == 0) {
            dfs(i);
            ans++;
        }
    }
    cout << ans - 1 << '\n';
    return 0;
}


Measured memory_bytes: 14600
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    string str;
    cin >> str;
    
    long long int ans=0;
    long long int tmp;
    for(int bit=0; bit<(1<<(str.size()-1)); bit++) {
        tmp=(long long int)str[0]-(long long int)'0';
        for(int f=0; f<str.size()-1; f++) {
            if(bit & (1<<f)) {
                ans += tmp;
                tmp = (long long int)str[f+1] - (long long int)'0';
                // cout << tmp << endl;
            } else {
                tmp *= 10;
                tmp += (long long int)str[f+1] - (long long int)'0';
                // cout << tmp << endl;
            }
        }
        ans += tmp;
    }
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256
import sys
from operator import itemgetter

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    Cut = [[int(i) - 1 for i in input().split()] for _ in range(M)]
    Cut.sort(key = itemgetter(1))
    count = 1
    cindex = 1
    cutPlace = Cut[0][1]
    while cindex < M:
        if Cut[cindex][0] < cutPlace: cindex += 1
        else:
            count += 1
            cutPlace = Cut[cindex][1]
            cindex += 1
    print(count)

    return 0

if __name__ == "__main__":
    solve()

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

int main()
{
  int X;
  cin >> X;
  
  if(X == 7 || X == 5 || X == 3)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long x,y;
    long long x1,y1;
    cin>>x>>y;

    int a=0,b=0;
    int a1=0,b1=0;
    if(x>y){
        long long t=x;
        x=y;
        y=t;
    }
    x1=x;y1=y;
    while(x>1 || y>1){
        a+=x/2;
        y+=x/2;
        x=(x%2==1);
        b+=y/2;
        x+=y/2;
        y=(y%2==1);
    }
    if(a!=b){
        cout<<"Alice"<<endl;
    }
    else{
        cout<<"Brown"<<endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,i,number,count[4001][2];
	long long int score[4001],price,howmany;
	scanf("%d",&n);
	while(n!=0){
		for(i=0; i<=4000; i++){
			score[i]=0;
			count[i][0]=0;
			count[i][1]=0;
		}
		count[0][0]=1;
		for(i=0; i<n; i++){
			scanf("%d%lld%lld",&number,&price,&howmany);
			score[number]+=price*howmany;
			if(count[number][1]==0){
				count[count[0][0]][0]=number;
				count[number][1]=1;
				count[0][0]++;
			}
		}
		for(i=1; i<=count[0][0]; i++){
			if(score[count[i][0]]>=1000000){
				printf("%d\n",count[i][0]);
				score[0]++;
			}
		}
		if(score[0]==0){
			printf("NA\n");
		}
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 676
#include <bits/stdc++.h>
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define rep(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;

int main(){
    ll n,sum=0,v;
    cin>>n;
    rep(i,n){
        cin>>v;
        sum+=v;
    }
    cout<<sum-(1+n)*n/2<<endl;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;
 
//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!
 
// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(1e9 + 7)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long
 
//////////////////////
const int N = 100005;


int32_t main() {
 
    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);
	
	int tt = 1;
	// cin/ >> tt;
	while(tt--) {
		int n;
		cin >> n;
		vector<int> p(n),q(n),v(n);
		rep(i,n) cin >> p[i];
		rep(i,n) cin >> q[i];
		rep(i,n) v[i] = i+1;
		int fi, sec;
		int st = 1;
		do {
			if(v==p) fi=st;
			if(v==q) sec=st;
			st++; 
		} while(next_permutation(all(v)));
		cout << abs(fi-sec) << '\n';
	}
}


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

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


Measured memory_bytes: 256
h,w=gets.split.map(&:to_i)
m,s=[[1,0],[0,1],[-1,0],[0,-1]],[]
ans=true
h.times{|i|s[i]=gets.chomp.split('')}
h.times{|i|
  w.times{|j|
    if s[i][j]=='#' then
      tmp=false
      m.size.times{|k|
        ii=i+m[k][0]
        jj=j+m[k][1]
        if 0<=ii && ii<h && 0<=jj && jj<w then
          tmp=true if s[ii][jj]=='#'
        end
      }
      ans=false if !tmp
    end
  }
}
puts ans ? 'Yes' : 'No'

Measured memory_bytes: 2172
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
   ll dp[2000000];
 int gcd(int a, int b)
{
  if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b,a%b));
}
}
int main(){
  ll a,b,c;cin>>a>>b;
  c=a+b;
  if(c<10)cout<<c;
  else cout<<"error";
}



Measured memory_bytes: 27040
// #include<iostream>
// #include<vector>
// #include<algorithm>
// #include<map>
// #include<cstring>
// #include<math.h>
// #include<bitset>
// #include<queue>
// #include<set>
// #include<iomanip>
// #include<math.h>
// #include<assert.h>
// #include<string>
// #include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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(){
  int N,M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  vector<pair<int,int>> P;
  for(int i=0; i<M; i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
    P.push_back(make_pair(a,b));
  }
  int ans=0;
  for(int i=0; i<M; i++){
    pair<int,int> check;
    check = P[i];
    queue<int> que;
    vector<bool> visited(N,false);
    que.push(0);
    visited[0] = true;
    while(!que.empty()){
      int v;
      v = que.front();
      que.pop();
      for(int nv: G[v]){
        if(nv==check.first || nv==check.second){
          if(v==check.first || v==check.second){
            continue;
          }
        }
        if(visited[nv]) continue;
        visited[nv] = true;
        que.push(nv);
      }
    }
    bool can = true;
    for(int i=0; i<N; i++){
      if(!visited[i]){
        can = false;
      }
    }
    if(!can){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long a, b;
    cin >> a >> b;

    double k = (a + b) / 2.0;
    long ik = (a + b) / 2;
    if (k == ik)
        cout << ik << '\n';
    else
        cout << "IMPOSSIBLE\n";
}


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

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

const int maxn = 2e5+7;
const int mod  = 1e9+7;
const int inf  = 2e9;

int heap[maxn];

LL min(LL a,int b)
{
    return a>b? b:a;
}

int main()
{
#ifdef LOCAL
    freopen("sample.in","r",stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    LL ans=inf*1e5+7;
    LL sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>heap[i];
        sum+=heap[i];
    }
    LL now=heap[0];
    for(int i=1;i<n;i++)
    {
        ans=min(ans,abs(now-sum+now));
        now+=heap[i];
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n, k;
  ll a[1010] = {};

  scanf("%d%d", &n, &k);

  for(int i=1;i<=n;i++){
    scanf("%lld", a+i);
    a[i] += a[i-1];
  }

  vector<ll> vec;
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<=n;j++){
      vec.push_back(a[j]-a[i]);
    }
  }
  
  ll ans = 0;
  
  for(int i=0;i<40;i++){
    ll next = ans + (1LL << (39-i));
    int counter = 0;
    for(int j=0;j<vec.size();j++){
      if((next & vec[j]) == next) counter++;
    }

    if(counter >= k) ans = next;
  }

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



Measured memory_bytes: 6000
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long LL;

string s;
LL n,cnt[2025] = {0},now = 0,tot = 0;

LL kpw(LL x,LL y){
	LL ans = 1,tmp = x;
	while(y){
		if(y & 1) ans = (ans * tmp) % 2019;
		tmp = (tmp * tmp) % 2019;
		y >>= 1;
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin >> s; n = s.length(); s = ' ' + s;
	cnt[0] = 1;
	for(LL i = n;i >= 1;i --){
		now += kpw(10,n - i) * (s[i] - '0');
		now %= 2019;
		tot += cnt[now];
		cnt[now] ++;
//		cout << now << endl;
	}
	cout << tot << '\n';
	return 0;
}

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

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

   int n,x=1,y,z,k;
   cin>>n>>k;
   while(n--)
   {
       y=2*x;
       z=x+k;
       if(y<z)
       {
           x=y;
       }
       else
       {
           x=z;
       }
   }
   cout<<x;


   return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int N;
//下からi桁目まで決めていて、上に繰り上がりを要求するかどうか
ll dp[1001005][2];
void debug(){
    rep(i,N+1){
        rep(j,2){
            cerr<<dp[i][j]<<" ";
        }
        cerr<<endl;
    }
    cerr<<endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S;
    cin >> S;
    reverse(all(S));
    S += "0";
    N = S.size();
    rep(i,N+1)rep(j,2)dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,N){
        int d = S[i] - '0';
        rep(j,2){
            for(int k = 0; k < 10; k++){
                int tmpk = k;
                if(j)tmpk--;
                //if(tmpk < 0)continue;
                if(tmpk >= d){
                    chmin(dp[i+1][0], dp[i][j] + k + (tmpk - d));
                }
                else{
                    chmin(dp[i+1][1], dp[i][j] + k + 10 + tmpk - d);
                }
            }
        }
    }
    //debug();
    cout << min(dp[N][0], dp[N][1])<<endl;
}

Measured memory_bytes: 17052
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
int main() {
	string s;
	cin >> s;
	int res = 0;
	stack<char>st;
	for (int i = 0; i < s.size(); ++i) {
		if (st.empty() || st.top() == s[i]) {
			st.push(s[i]);
		}
		else {
			res += 2;
			st.pop();
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;
#define pi 3.14159265358979

int main()
{
	int n;
	char before = ' ';
	map<string, bool> word;
	cin >> n;

	rep(i, n)
	{
		string s;
		cin >> s;
		if (before != ' ' && s[0] != before || word[s] != false)
		{
			cout << "No";
			return 0;
		}
		before = s[s.length() - 1];
		word[s] = true;
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 3596
using System;

public class Program {
  public static void Main(string[] args) {
    var str1 = Console.ReadLine().Split();
    string s = str1[0];
    string t = str1[1];
    var str2 = Console.ReadLine().Split();
    int num_s = int.Parse(str2[0]);
    int num_t = int.Parse(str2[1]);
    string u = Console.ReadLine();
    
    if (u.Equals(s)) {
      Console.WriteLine((num_s-1) + " " + num_t);
    }else if (u.Equals(t)){
      Console.WriteLine(num_s + " " + (num_t-1));
    }
  }
}

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

int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(max(a,c)<=min(b,d)) {
		cout<<min(b,d)-max(a,c)<<endl;
	}
	else {
		cout<<"0"<<endl;
	}
}

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

using namespace std;

using int64 = long long;
const int mod = (int) (1e9 + 7);

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

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

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

int main() {
  int N, Q;
  cin >> N >> Q;
  UnWeightedGraph g(N);
  for(int i = 1; i < N; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }
  vector< int64 > t(N);
  for(int i = 0; i < Q; i++) {
    int p, x;
    cin >> p >> x;
    --p;
    t[p] += x;
  }
  vector< int64 > ans(N);
  auto rec = MFP([&](auto rec, int idx, int par, int64 add) -> void {
    add += t[idx];
    ans[idx] = add;
    for(auto &to : g[idx]) {
      if(to == par) continue;
      rec(to, idx, add);
    }
  });
  rec(0, -1, 0);
  cout << ans << endl;
}

Measured memory_bytes: 26496
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());
            int[] Aarray = ReadLine().Split(' ').Select(int.Parse).ToArray();
            var ls = new List<int>();
            ls.AddRange(Aarray);
            int[] Barray = ReadLine().Split(' ').Select(int.Parse).ToArray();

            long ans = 0;
            for (int i = 0; i < N; i++)
            {
                int tmp = Barray[i];

                //まだ一回転保証
                if (tmp - ls[i] >= 0)//左全部殺せる
                {
                    tmp -= ls[i];
                    ans += ls[i];
                    ls[i] = 0;

                    if (tmp - ls[i + 1] >= 0)//右も全部殺せる
                    {
                        ans += ls[i + 1];
                        ls[i + 1] = 0;
                    }
                    else//殺しきれない
                    {
                        ls[i + 1] -= tmp;
                        ans += tmp;
                    }
                }
                else//左殺しきれない
                {
                    ans += tmp;
                }
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 36804
n,m=map(int,input().split())
h=list(map(int,input().split()))
miti=[[0] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    miti[a].append(h[b])
    miti[b].append(h[a])


count=0
for i in range(n):
    if h[i] > max(miti[i]):
        count+=1
print(count)


Measured memory_bytes: 26116
#include <iostream>

int main()
{
  long long x, k, d;
  std::cin >> x >> k >> d;
  x = std::abs(x);
  long long cand;
  if (k%2 == 0)
  {
    cand = x % (2*d);
    if (cand > d) cand = 2*d - cand;
  }
  else
  {
    cand = (x+d) % (2*d);
    if (cand > d) cand = 2*d - cand;
  }
  long long ans = 0;
  if (std::abs(x) / d <= k)
  {
    ans = cand;
  }
  else
  {
    ans = std::abs(x) - d * k;
  }
  
  std::cout << ans;
  
  return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	string s,t; cin>>s>>t;
	char dp[s.size()+1][t.size()+1]={};
    int lgh[s.size()+1][t.size()+1]={};
    pair<int,int> pre[s.size()+1][t.size()+1]={};
	rep(i,1,s.size()+1)rep(j,1,t.size()+1){
		if(lgh[i-1][j] > lgh[i][j]){
            dp[i][j]=dp[i-1][j];
            lgh[i][j]=lgh[i-1][j];
            pre[i][j]=pre[i-1][j];
        }if(lgh[i][j-1] > lgh[i][j]){
            dp[i][j]=dp[i][j-1];
            lgh[i][j]=lgh[i][j-1];
            pre[i][j]=pre[i][j-1];
        }if(s[i-1]==t[j-1] && lgh[i-1][j-1]+1 > lgh[i][j]){
            dp[i][j]=s[i-1];
            lgh[i][j]=lgh[i-1][j-1]+1;
            pre[i][j]={i-1,j-1};
        }
	}//pprint(dp,,s.size()+1,t.size()+1);
    string ans="";
    int a=s.size(),b=t.size();
    rep(i,0,lgh[s.size()][t.size()]){
        ans=dp[a][b]+ans;
        pair<int,int> p=pre[a][b];
        a=p.first; b=p.second;
    }cout<<ans<<endl;
}

Measured memory_bytes: 114560
a,b = [int(i) for i in input().split()]

temp = 0
l = sorted([[int(i) for i in input().split()] for _ in range(a)],key = lambda x: x[0])
for i in l:
    temp += i[1]
    if temp >= b:
        ans = i[0]
        break
print(ans)

Measured memory_bytes: 23640
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
	int N;
	cin >> N;
	int P[N],Q[N];
	int i,tmp=1;
	for(i=0;i<N;i++){
		cin >> P[i];
	}
	for(i=0;i<N;i++){
		cin >> Q[i];
	}
	for(i=1;i<N;i++){
		tmp*=i;
	}
	int j;
	int a=0,b=0;
	int psm,qsm;
	for(i=0;i<N-1;i++){
		psm=0;qsm=0;
		for(j=i+1;j<N;j++){
			if (P[i]>P[j])psm++;
			if (Q[i]>Q[j])qsm++;
		}
		a+=tmp*psm;
		b+=tmp*qsm;
		tmp=tmp/(N-1-i);
	}
	cout << abs(a-b)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <math.h>
#include <string>
typedef long long int ll;
#define pb(b) push_back(b)
#define sort(b) sort(b.begin(),b.end())
#define mp(a,b) make_pair(a,b)
#define sf(n) scanf("%d", &n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define pf(n) printf("%d",n)
#define pfs(s) printf("%s",s)
vector<vector<int>> adjacencyList;
 
int main()
{
    
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ll n,q,l,r,t,sum = 0,k,last = 0,d,m,no,ans = 0;
    std::vector<ll> a,b;    
 
  	cin>>n>>k;
		bool found[n+1] = {false};

		for(int j = 0; j < k; j++)
		{
			cin>>d;
			for(int i = 0; i < d; i++)
			{
				cin>>no;
				found[no]=true;
			}
		}
		for(int i = 1; i <=n; i++)
		{
			if(found[i] == false)
			ans++;
		}

		cout<<ans;

    return 0;
}


Measured memory_bytes: 3596