akhauriyash/Code-Regression huggingface dataset:
#ifndef ___Class_RangeTree
#define ___Class_RangeTree

// ------ Includes ------ //
#include <limits>
#include <vector>
#include <algorithm>

template<typename Type> class RangeTree {
private:
	int size_;
	std::vector<std::vector<Type> > dat;
	std::vector<std::vector<int> > vl;
	inline int query_(int a, int b, Type x, int k, int l, int r, int e) {
		// Find range [a, b) : value < x : Now k-th node and the range is [l, r) and e integers below x in the range
		if (r <= a || b <= l || e == 0) return 0;
		if (a <= l && r <= b) return e;
		int lc = query_(a, b, x, k << 1, l, (l + r) >> 1, vl[k][e - 1]);
		int rc = query_(a, b, x, k << 1 | 1, (l + r) >> 1, r, e - vl[k][e - 1]);
		return lc + rc;
	}
public:
	RangeTree() : size_(0), dat(std::vector<Type>()) {};
	template<class T>
	RangeTree(T begin_, T end_) {
		int n = (end_ - begin_);
		for (size_ = 1; size_ < n; size_ <<= 1);
		dat.resize(size_ << 1, std::vector<Type>());
		vl.resize(size_ << 1, std::vector<int>());
		for (int i = 0; i < n; i++) {
			dat[i + size_].push_back(*(begin_ + i));
			vl[i].push_back(1);
		}
		for (int i = size_ - 1; i > 0; i--) {
			dat[i].resize(dat[i << 1].size() + dat[i << 1 | 1].size());
			vl[i].resize(dat[i].size());
			int cl = 0;
			for (int j = 0; j < dat[i].size(); j++) {
				if (j - cl == dat[i << 1 | 1].size() || (cl != dat[i << 1].size() && dat[i << 1][cl] < dat[i << 1 | 1][j - cl])) dat[i][j] = dat[i << 1][cl++];
				else dat[i][j] = dat[i << 1 | 1][j - cl];
				vl[i][j] = cl;
			}
		}
	}
	inline int size() { return size_; }
	inline int query(int l, int r, Type x) {
		// Find range [a, b) : value < x
		int ptr = lower_bound(dat[1].begin(), dat[1].end(), x) - dat[1].begin();
		return query_(l, r, x, 1, 0, size_, ptr);
	}
};

#endif

#include <cstdio>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int N, Q, xl, yl, xr, yr;
int main() {
	scanf("%d%d", &N, &Q);
	vector<pair<int, int> > p(N);
	for (int i = 0; i < N; i++) scanf("%d%d", &p[i].first, &p[i].second);
	sort(p.begin(), p.end());
	vector<int> z1(N), z2(N);
	for (int i = 0; i < N; i++) {
		z1[i] = p[i].first;
		z2[i] = p[i].second;
	}
	RangeTree<int> seg(z2.begin(), z2.end());
	while (Q--) {
		scanf("%d%d%d%d", &xl, &yl, &xr, &yr);
		int ptr1 = lower_bound(z1.begin(), z1.end(), xl) - z1.begin();
		int ptr2 = lower_bound(z1.begin(), z1.end(), xr + 1) - z1.begin();
		int res1 = seg.query(ptr1, ptr2, yl);
		int res2 = seg.query(ptr1, ptr2, yr + 1);
		printf("%d\n", res2 - res1);
	}
	return 0;
}

Measured memory_bytes: 4252
import itertools
import functools
import math
from collections import Counter

def CHK():
    X,Y,A,B,C=map(int,input().split())
    p=sorted(list(map(int,input().split())),reverse=True)
    q=sorted(list(map(int,input().split())),reverse=True)
    r=sorted(list(map(int,input().split())),reverse=True)

    apples = sorted(p[:X] + q[:Y] + r, reverse=True)

    ans = sum(apples[:X+Y])
    print(ans)

CHK()

Measured memory_bytes: 29640
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {


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

	sort(p.begin(), p.end());
	vector<int>t;
	for (int i = 1; i <k; i++) {
		int a = p[i] - p[i - 1];
		t.push_back(a);
	}
	sort(t.begin(), t.end());
	if (n >= k) {
		cout << 0 << endl;
		return 0;
	}
	int ans = 0;
	for (int i = 0; i < k - n; i++) {
		ans += t[i];
	}
	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 1276
//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int i = sc.nextInt();
        System.out.println(n - i + 1);
    }
}

Measured memory_bytes: 35664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)

int main() {
	int n;
	string c,w;
	set<string> dic;
	cin >> n;
	rep(i,n) {
		cin >> c >> w;
		if (c=="insert") {
			dic.insert(w);
		}
		else {
			cout << (dic.find(w)!=dic.end()?"yes":"no") << endl;
		}
	}
}



Measured memory_bytes: 32580
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long m=sc.nextLong();
		if(n%2==1){
			for(int i=0;i<m;i++){
				System.out.println((i+1)+" "+(n-(i)));
			}
		}else{
			for(int i=0;i<m;i++){
				if(i%2==0){
					System.out.println((i/2+1)+" "+(n-(i/2)));
				}else{
					System.out.println((n/2-i/2)+" "+(n/2+i/2+2));
				}
			}
		}
	}
}


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

int main(){
    int a,b,c,d;
    cin >> a>>b>>c>>d;
    int th=c/b;
    if(c%b!=0){
        th++;
    }
    int ah=a/d;
    if(a%d!=0){
        ah++;
    }
    if(th<=ah){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h> 
using namespace std; 
int computeCost(int arr[], int N, int Y) 
{ 
    int cost = 0; 
    for (int i = 0; i < N; i++) 
        cost += (arr[i] - Y)*(arr[i] - Y); 
    return cost; 
} 
int minCostToMakeElementEqual(int arr[], int N) 
{ 
    int low, high; 
    low = high = arr[0]; 
    for (int i = 0; i < N; i++) { 
        if (low > arr[i]) 
            low = arr[i]; 
        if (high < arr[i]) 
            high = arr[i]; 
    }
    while ((high - low) > 2) { 
        int mid1 = low + (high - low) / 3; 
        int mid2 = high - (high - low) / 3; 
        int cost1 = computeCost(arr, N, mid1); 
        int cost2 = computeCost(arr, N, mid2); 
        if (cost1 < cost2) 
            high = mid2; 
        else
            low = mid1; 
    } 
    return computeCost(arr, N, (low + high) / 2); 
} 
  
int main() 
{ 
    int n,i;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    cout << minCostToMakeElementEqual(a, n); 
    return 0; 
} 

Measured memory_bytes: 3600
from collections import defaultdict

s = input()
n = len(s)
t = 0
d = defaultdict(int)
for i in range(1, n + 1):
    t = (t + pow(10, i, 2019) * int(s[-i])) % 2019
    d[t] += 1
c = d[0]
for v in d.values():
    c += v * (v - 1) // 2
print(c)

Measured memory_bytes: 9580
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<int> B(N-1);
  for(int i=0;i<N-1;i++) cin>>B[i];

  ll ans=B[0]+B.back();
  for(int i=1;i<N-1;i++){
    ans+=min(B[i-1],B[i]);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){

  int i,n,A[45];

  scanf("%d",&n);

  A[0]=1;
  A[1]=1;

  if(n>=2){
    for(i=2;i<=n;i++){
      A[i]=A[i-1]+A[i-2];
    }

    printf("%d\n",A[n]);
  }

  else if(n==1) printf("%d\n",A[1]);
  else if(n==0) printf("%d\n",A[0]);
  
  return 0;
}



Measured memory_bytes: 2112
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')

//------------------------------------------------------------------------------
const int V_MAX = 100000;

int V;
vector<int> G[V_MAX];
int last = 0;

void add_edge(int from, int to) {
  G[from].push_back(to);
  G[to].push_back(from);
}

//------------------------------------------------------------------------------
const int N_MAX = 100000;
const int K_MAX = N_MAX;
const int INF = 1e9;

struct node {
  int b, l, r;
};

int N;
int K;

int v0, p0;
node a[N_MAX];

void dump() {
  REP(i, N) {
    printf("v: %d, b: %d, l: %d, r: %d\n",
      i, a[i].b, a[i].l, a[i].r);
  }
}

bool check_parity(int p, int v, int b) {
  if (a[v].b >= 0) {
    if (a[v].b != b) return false;
  } else {
    a[v].b = b;
  }
  REP(i, G[v].size()) {
    int u = G[v][i];
    if (u == p) continue;
    if (!check_parity(v, u, 1 - b)) {
      return false;
    }
  }
  return true;
}

bool update_range(int v, int l, int r) {
  int l2 = max(a[v].l, l);
  int r2 = min(a[v].r, r);
  if (l2 > r2) return false;
  a[v].l = l2; a[v].r = r2;
  return true;
}

bool check_range(int p, int v, int l, int r) {
  if (!update_range(v, l, r)) return false;
  REP(i, G[v].size()) {
    int u = G[v][i];
    if (u == p) continue;
    if (!check_range(v, u, l - 1, r + 1)) return false;
    if (!update_range(v, a[u].l - 1, a[u].r + 1)) return false;
  }
  return true;
}

void fix_value(int p, int v, int l) {
  a[v].l = max(a[v].l, l);
  REP(i, G[v].size()) {
    int u = G[v][i];
    if (u == p) continue;
    fix_value(v, u, a[v].l - 1);
  }
}

void solve() {
  bool ret;
  ret = check_parity(-1, v0, p0 % 2);
  if (!ret) {
    puts("No");
    return;
  }

  ret = check_range(-1, v0, p0, p0);
  if (!ret) {
    puts("No");
    return;
  }

  puts("Yes");
  fix_value(-1, v0, p0);
  // dump();

  REP(i, N) printf("%d\n", a[i].l);
}

void input() {
  scanf("%d", &N);
  V = N;
  REP(i, N - 1) {
    int a, b;
    scanf("%d%d", &a, &b);
    add_edge(a - 1, b - 1);
  }
  REP(i, N) a[i] = { -1, -INF, INF };
  scanf("%d", &K);
  REP(i, K) {
    int v, p;
    scanf("%d%d", &v, &p);
    if (i == 0) {
      v0 = v - 1;
      p0 = p;
    }
    a[v - 1] = { p % 2, p, p };
  }
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 15360
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
const int INF = 1001001001;

int main()
{
    int n; cin >> n;
    vector<int> a(3*n); rep(i, 3*n) cin >> a[i];
    Sort2(a);
    ll ans = 0;
    rep(i,2*n){
        if(i%2==1) ans += a[i];
    }
    cout << ans << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }

int main () {
  int n;
  cin >> n;
  vector<string> s(n);
  map<string,int> mp;
  rep(i,n) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    mp[s[i]]++;
  }
  ll ans = 0;
  for (auto p : mp) {
    ans += (ll)p.se*(p.se-1)/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 18176
def main():
    N = int(input())
    robot = []
    for _ in range(N):
        X, L = map(int, input().split())
        robot.append([X-L,X+L])

    robot.sort(key=lambda x: x[1])
    cnt = 1
    l = robot[0][1]
    for i in range(1,N):
        if l <= robot[i][0]:
            cnt += 1
            l = robot[i][1]

    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 91840
import java.util.*;
public class Main {
    double [] p;
    
    private void doit(){
        //SHA KYO
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int m = sc.nextInt();
            if((n|m) == 0) break;
            p= new double[n];
            for(int i = 0; i < n; i++){
                p[i] = sc.nextDouble();
            }
            double ans = Integer.MIN_VALUE;
            for(int node0 = 0; node0 < n; node0++){
                double [][] dp = new double[m+1][n];
                for(int i = node0 ; i < n; i++){
                    dp[m][i] = area(i, node0);
                }
                
                for(int mi = m-1 ; mi >= 1; mi--){
                    for(int ni = node0; ni < n; ni++){
                        double max = Integer.MIN_VALUE;
                        for(int nj = ni + 1; nj < n; nj++){
                            max = Math.max(max, area(ni, nj) + dp[mi+1][nj]);
                        }
                        dp[mi][ni] = max;
                    }
                }
                ans = Math.max(ans, dp[1][node0]);
            }
            System.out.printf("%.6f\n",ans);
        }
    }
    
    private double area(int i, int j){
        return Math.sin((p[j] - p[i]) * 2 * Math.PI) / 2;
    }

    public static void main(String[] args) {
        Main obj = new Main();
        obj.doit();
    }
}

Measured memory_bytes: 13000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long LL;
typedef pair<LL, LL> pLL;

int main(void)
{
	LL N, D, x, y;
	cin >> N >> D;
	LL D2 = D * D;
	LL count = 0;
	for (int i = 0; i < N; i++) {
		cin >> x >> y;
		if (x*x + y * y <= D2) {
			count++;
		}
	}
	cout << count << endl;

	return 0;

}

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

int main() {
  int n; cin >> n;
  vector<double> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  LL x = 1;
  for (int i = n - 2; i >= 1; i --) x *= i;

  double sum = 0;
  for (int i = 0; i < n; i ++) {
    for (int j = i + 1; j < n; j ++) {
      double t = (a[i] - a[j]) * (a[i] - a[j]) + (b[i] - b[j]) * (b[i] - b[j]);
      sum += sqrt(t) * (n - 1) * 2 * x;
    }
  }

  for (int i = 1; i <= n; i ++) {
    sum /= i;
  }

  cout << setprecision(15) << sum << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int A, B;
  while (cin >> A >> B) {
    int res = max(0, A - B * 2);
    cout << res << endl;
  }
  return 0;
}


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

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

	string s; cin >> s;
	int k; cin >> k;
	set<string> t;
	for(int i = 0; i < s.size(); i++) {
		string tmp = "";
		for(int j = i; j < s.size() && j < i + 5; j++) {
			tmp += s[j];
			t.insert(tmp);
		}
	}
	int cnt = 1;
	for(auto i = t.begin(); i != t.end(); i++) {
			if(cnt == k) {
				cout << *i << endl;
				return 0;
			}
			cnt++;
	}
	return 0;
}	


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    // Your code here!
 
    string S, T;
    cin >> S >> T;

    sort(S.begin(), S.end());
    sort(T.begin(), T.end());
    reverse(T.begin(), T.end());
    
    if(S < T) cout << "Yes" << endl;
    else cout << "No" << endl;



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define STDIO
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
using namespace std;
int n;
long long m;
vector<int> ga[100100];
int x,y;
long long dpin[100100];
long long dpout[100100];
long long pref[100100],suff[100100];
vector<int> ch[100100];
void dp1(int u,int p){
	//dpin
	dpin[u]=1LL;
	for(int i=0;i<ga[u].size();i++){
		int v=ga[u][i];
		if(v!=p){
			ch[u].push_back(v);
			dp1(v,u);
			dpin[u]=(dpin[u]*((dpin[v]+1LL)%m))%m;
		}
	}
}
void dp2(int u,int p){
	//dpout
	pref[0]=dpout[u];
	for(int i=0;i<ch[u].size();i++){
		pref[i+1]=(pref[i]*((dpin[ch[u][i]]+1)%m))%m;
	}
	suff[ch[u].size()]=1LL;
	for(int i=(int)(ch[u].size())-1;i>=0;i--){
		suff[i]=(suff[i+1]*((dpin[ch[u][i]]+1)%m))%m;
	}
	for(int i=0;i<ch[u].size();i++){
		int v=ch[u][i];
		if(v==p)
			continue;
		dpout[v]=(1+pref[i]*suff[i+1])%m;
	}
	for(int i=0;i<ch[u].size();i++){
		int v=ch[u][i];
		dp2(v,u);
	}
}
int main(){
	#ifndef STDIO
		freopen("input.in","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<n;i++){
		cin>>x>>y;
		ga[x].push_back(y);
		ga[y].push_back(x);
	}
	dpout[1]=1LL;
	dp1(1,0);
	dp2(1,1);
	for(int i=1;i<=n;i++)
		cout<<(dpin[i]*dpout[i])%m<<endl;
	return 0;
}


Measured memory_bytes: 21632
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr int MOD_TYPE = 1;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  set<string> st;
  rep(i, n)
  {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 19232
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a,b;
	cin>>n>>a>>b;
	if(a>b)cout<<0<<endl;
	else if(n==1)cout<<((a==b)?1:0)<<endl;else cout<<(n-2)*(b-a)+1ll<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main()
{
	char in;
	for (;;) {
		scanf("%c", &in);
		if (islower(in)) {
			printf("%c", toupper(in));
		} else if (isupper(in)) {
			printf("%c", tolower(in));
		} else {
			printf("%c", in);
		}
		if (in == '\n') {
			return 0;
		}
	}
}

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

#define S size()
#define EN end()
#define BE begin()
#define LEN length()

#define endl "\n"
#define cnt count
#define in insert
#define er erase
#define fi first
#define se second
#define ld double
#define ll long long

#define gcd __gcd
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define np next_permutation

#define si set<ll>
#define sc set<char>
#define mll map<ll,ll>
#define vi vector<ll>
#define vc vector<char>
#define pll pair<ll,ll>
#define vpi vector<pll>
#define msi multiset<ll>
#define msc multiset<char>
#define vvi vector<vector<ll> >

#define all(v) v.BE,v.EN
#define godv(v) sort(all(v))
#define god(ar,n) sort(ar,ar+n)
#define godvr(v) godv(v) ; reverse(all(v))
#define godr(ar,n) god(ar,n) ; reverse(ar,ar+n)

#define iter(s) for(auto it:s)
#define forl(i,n) for(ll i=0;i<n;i++)
#define fore(i,n) for(ll i=1;i<=n;i++)
#define fora(i,v) for(ll i=0;v[i];i++)
#define forn(i,n) for(ll i=n-1;i>=0;i--)
#define forls(i,l,r) for(ll i=l;i<r;i++)
#define forns(i,l,r) for(ll i=r-1;i>=l;i--)

#define pat ll n;cin>>n;
#define wq ll q;cin>>q;while(q--)
#define tak(s) string s;cin>>s;ll n=s.LEN;
#define nokay if(ok) cout<<"YES\n";else cout<<"NO\n";
#define pat1 ll n;cin>>n;ll ar[n];forl(i,n) cin>>ar[i];
#define pat2 ll n,k;cin>>n>>k;ll ar[n];forl(i,n) cin>>ar[i];

#define inf 1e18
#define mod1 1000000007
#define mod2 998244353
#define PI 3.1415926535897932384626433832
#define eness(x) __builtin_ctzll(x)//trailing 0s
#define nhigh(x) __builtin_popcountll(x)//number of high terms
//**********************************
void Fast();
ll mf(ll x,ll mod);
ll mi(ll x,ll mod);
ll C(ll n,ll r,ll mod);
ll bpow(ll a,ll b,ll mod);

void Fast(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
ll mf(ll x,ll mod=mod1){
    if(x<2) return 1;
    return (x*mf(x-1))%mod;
}
ll mi(ll x,ll mod=mod1){
    return bpow(x,mod-2,mod);
}
ll C(ll x,ll y,ll mod=mod1){
    if(x<y) return 0;
    return (((mf(x)*mi(mf(y)))%mod)*mi(mf(x-y)))%mod;
}
ll bpow(ll x,ll y,ll mod){
    x%=mod;
    ll res=1;
    while(y>0){
        if(y&1){
            res=res*x%mod;
        }
        x=x*x%mod;
        y>>=1;
    }
    return res;
}
//**********************************

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    Fast();
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll w=0;
    forl(i,n){
        if(s[i]=='W'){
            w++;
        }
    }
    ll ans=0;
    forl(i,w){
        if(s[n-i-1]=='R'){
            ans++;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3764
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m=map(int,input().split())
uf=UnionFind(n)
fr=[set() for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    fr[a-1].add(b-1)
    fr[b-1].add(a-1)
    uf.union(a-1,b-1)
x=0
for i in range(n):
  x=max(x,uf.size(i))
print(x)

Measured memory_bytes: 152424
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, m = sc.nextLong
    if (n == 1 || m == 1) println(math.max(1, (n - 2)) * math.max(1, (m - 2)))
    else println((n - 2) * (m - 2))
  }
}


Measured memory_bytes: 25416
import sys
input = sys.stdin.readline

a, b = [int(i) for i in input().split()]
small = min(a,b)
big = max(a,b)

multi = 1
ans = big
while True:
    ans = big * multi
    if (ans % small) == 0:
        break
    multi += 1

print(ans)


Measured memory_bytes: 38640
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n,x,i,cnt=0;
    cin >> n;
    map<ll,ll> m;
    for(i=0;i<n;i++) {
    	cin >> x;
    	if(!m[x]) cnt++;
    	m[x]=1;
    }
    if(cnt==n) cout << "YES";
    else cout << "NO";
    cout << "\n";
    return 0;
}



Measured memory_bytes: 12800
// https://atcoder.jp/contests/arc075/tasks/arc075_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

struct Fenwick {
  vector<ll> tree;

  Fenwick(ll n) : tree(vector<ll>(n, 0)) {}

  // sum of [0, i)
  ll sum(ll i) {
    ll res = 0;

    for (i--; i >= 0; i = (i & (i + 1)) - 1) {
      res += tree[i];
    }

    return res;
  }

  void add(ll i, ll n) {
    for (ll len = tree.size(); i < len; i |= i + 1) {
      tree[i] += n;
    }
  }
};

void solve() {
  ll N, K;
  cin >> N >> K;

  VL bs(N + 1);

  {
    ll cur = 0;
    bs[0] = cur;

    rep(i, N) {
      ll a;
      cin >> a;
      bs[i + 1] = bs[i] + a - K;
    }
  }

  // 座標圧縮
  {
    VL cs(N + 1);
    rep(i, N + 1) cs[i] = bs[i];

    sort(all(cs));

    rep(i, N + 1) {
      ll b_i = lower_bound(all(cs), bs[i]) - cs.begin();
      bs[i] = b_i;
    }
  }

  ll res = 0;

  Fenwick bit(N + 1);

  rep(i, N + 1) {
    res += bit.sum(bs[i] + 1);
    bit.add(bs[i], 1);
  }

  cout << res << "\n";
}


Measured memory_bytes: 3428
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if b-a>k or c-a>k or d-a>k or e-a>k or c-b>k or d-b>k or e-b>k or d-c>k or e-c>k or e-d>k: 
  print(':(')
else:
  print('Yay!')
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  string A,B,C ;
  cin >> A >> B >> C ;
  int i = 0  , j = -1  , k = -1 ;
  int a = 0  , b = 0  , c = 0  ; 
  int n = 0 ;
  //cout << A{4] << endl;
  while(1){
    if( n == 0 ){
      a = 1 ;
      n = 1 ;
    }
    if ( a && A[i] == 'a' ){
      i++ ;
      a = 1 ,b = 0 , c = 0 ;
      //cout << "Aは" << i << "枚目" << "次はAの番" << endl;
      if( i == A.size()){
      	cout << 'A' << endl;
      	return 0 ;
      }
    }
    else if ( a && A[i] == 'b' ){
      j++ ;
      a = 0 ,b = 1 , c = 0 ;
      //cout << "Aは" << i << "枚目" << "次はBの番" << endl;
    }
    else if ( a && A[i] == 'c' ){
      k++ ;
      a = 0 ,b = 0 , c = 1 ;
      //cout << "Aは" << i << "枚目" << "次はCの番" << endl;
    }
    else if ( b && B[j] == 'a' ){
      i++ ;
      a = 1 ,b = 0 , c = 0 ;
      //cout << "Bは" << j << "枚目" << "次はAの番" << endl;
    }
    else if ( b && B[j] == 'b' ){
      j++ ;
      a = 0 ,b = 1 , c = 0 ;
      //cout << "Bは" << j << "枚目" << "次はBの番" << endl;
      if( j == B.size() ){
        cout << 'B' << endl;
        return 0 ;
      }
    }
    else if ( b && B[j] == 'c' ){
      k++ ;
      a = 0 ,b = 0 , c = 1 ;
      //cout << "Bは" << j << "枚目" << "次はCの番" << endl;
    }
    else if ( c && C[k] == 'a' ){
      i++ ;
      a = 1 ,b = 0 , c = 0 ;
      //cout << "Cは" << k << "枚目" << "次はAの番" << endl;
    }
    else if ( c && C[k] == 'b' ){
      j++ ;
      a = 0 ,b = 1 , c = 0 ;
      //cout << "Cは" << k << "枚目" << "次はBの番" << endl;
    }
    else if(c && C[k] == 'c' ){
      k++ ;
      a = 0 ,b = 0 , c = 1 ;
      //cout << "Cは" << k << "枚目" << "次はCの番" << endl;
      if ( k == C.size() ){ 
      	cout << 'C' << endl;
        return 0 ;
      }
    }
    if( i == A.size() ){
        cout << 'A' << endl;
        return 0 ;
    }
    else if( j == B.size() ){
        cout << 'B' << endl;
        return 0 ;
    }
    else if ( k == C.size() ){ 
      	cout << 'C' << endl;
        return 0 ;
    }
    else continue ; 
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<unordered_map>
using namespace std;

int main()
{
	unordered_map<string, bool> mp;
	
	int n;
	cin >> n;

	while (n--)
	{
		string str, target;
		cin >> str >> target;

		if (str == "insert") {
			mp[target] = true;
		}
		else {
			cout << ((mp[target]) ? "yes" : "no") << endl;
		}

	}

	return 0;
}


Measured memory_bytes: 49836
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CSccPuzzle solver = new CSccPuzzle();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSccPuzzle {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long s = in.nextLong(), c = in.nextLong();

            long answer = 0;
            long scc = Math.min(s, c / 2);
            s -= scc;
            c -= scc * 2;
            answer += scc;

            answer += c / 4;

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 22740
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

struct Food{
    ll a;
    ll b;
    Food(ll A, ll B){
        a = A;
        b = B;
    }

    bool operator>(const Food &another) const
    {
        return a+b > another.a + another.b;
    }

    bool operator<(const Food &another) const
    {
        return a+b < another.a + another.b;
    }

    string ToString(){
        stringstream ss;
        ss << "a b " << a << " " << b;
        return ss.str();
    }
};

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    vector<Food> F;
    F.reserve(N);

    FOR(i, 0, N){
        ll a, b;
        cin >> a >> b;
        F.push_back(Food(a, b));
    }

    sort(ALL(F));
    reverse(ALL(F));

    FOR(i, 0, N){
        //p(F[i].ToString());
    }

    ll A_happy = 0;
    ll B_happy = 0;
    FOR(i, 0, N){
        if(i%2==0){
            A_happy += F[i].a;
        }
        else{
            B_happy += F[i].b;
        }
    }

    p(A_happy - B_happy);

    return 0;
}

Measured memory_bytes: 1792
#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>
#include<cstdio>
#include<cstdlib>
#include<cstring>
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 ll dx[4] = { 0, -1, 1, 0 };
const ll 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);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	int N; cin >> N;
	int w[110];
	int sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> w[i];
		sum += w[i];
	}
	int ans = INF;
	for (int i = 0; i < N - 1; ++i) {
		int key = 0;
		for (int j = 0; j <= i; ++j) {
			key += w[j];
		}
		ans = min(ans, abs(sum - key- key));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = solve(s);
        System.out.println(ans);
    }

    static int solve(String s) {
        // ランレングス圧縮した文字列長-1が石を置く場所の数
        char[] cs = s.toCharArray();
        char before = '-';
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < cs.length; i++) {
            char at = cs[i];
            if (before != at) {
                if (at == 'W') {
                    sb.append('W');
                    before = 'W';
                } else {
                    sb.append('B');
                    before = 'B';
                }
            }
        }

        String ans = sb.toString();
        System.err.println(ans);
        if (ans.length() == 0) {
            return 0;
        } else {
            return ans.length() - 1;
        }
    }
}



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

long long int max(long long int a,long long int b)
{
    if(a<=b)
    {
        return b;
    }
    else
    {
        return a;
    }
}

int main()
{
    long long int n,wt,w[105],v[105],j,i;
    scanf("%lld %lld",&n,&wt);
    long long int t[n+2][wt+5];
    for(i=0;i<n;i++)
    {
        w[i]=0,v[i]=0;
        for(j=0;j<=wt;j++)
        {
            t[i][j]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        scanf("%lld %lld",&w[i],&v[i]);
    }
    for(i=0;i<=n;i++)
    {
        t[i][0]=0;
    }
    for(j=1;j<=wt;j++)
    {
        if(w[0]<=j)
        {
            t[0][j]=v[0];
        }
    }
    for(i=1;i<n;i++)
    {
        for(j=1;j<=wt;j++)
        {
            if(w[i]>j)
            {
                t[i][j]=t[i-1][j];
            }
            else
            {
                t[i][j]=max(v[i]+t[i-1][j-w[i]],t[i-1][j]);
            }
            // printf("%lld-%lld-%lld\n",i,j,t[i][j]);
        }
    }
    printf("%lld\n",t[n-1][wt]);
}

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

void solve(long long N, long long A, long long B, vector<long long> X){
	long long ans = 0;
	for(int i = 0 ; i+1 < N ; i++){
		ans += min( A*(X[i+1] - X[i]), B);
	}
	cout << ans << endl;
}

int main(){	
	long long A;
	long long N;
	long long B;
	scanf("%lld",&N);
	vector<long long> X(N-1+1);
	scanf("%lld",&A);
	scanf("%lld",&B);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&X[i]);
	}
	solve(N, A, B, X);
	return 0;
}


Measured memory_bytes: 1920
#include <iostream>
using namespace std;
int N, Q, x, y, e[100009][2], c[100009];
int main() {
	cin >> N >> Q;
	for (int i = 0; i < N; i++) {
		c[i] = 1;
		e[i][i == 0 ? 0 : 1] = 1;
	}
	while (Q--) {
		cin >> x >> y; x--, y--;
		if (e[x][0] == 1 && e[x][1] == 0) {
			if (c[x] == 1) {
				e[x][0] = 0;
				e[y][0] = 1;
				e[y][1] = 0;
			}
			else {
				e[x][1] = 1;
				e[y][0] = 1;
				e[y][1] = 1;
			}
		}
		else if (e[x][0] == 1 && e[x][1] == 1) {
			if (c[x] == 1) {
				e[x][0] = 0;
				e[x][1] = 0;
				e[y][0] = 1;
				e[y][1] = 1;
			}
			else {
				e[y][0] = 1;
				e[y][1] = 1;
			}
		}
		else {
			if (c[x] == 1) {
				e[x][1] = 0;
				e[y][1] = 1;
			}
			else {
				e[y][1] = 1;
			}
		}
		c[x]--, c[y]++;
	}
	int ret = 0;
	for (int i = 0; i < N; i++) ret += e[i][0];
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1408
N, K, Q = map(int, input().split())
score = [0 for i in range(N)]
for i in range(Q):
    A = int(input())
    score[A - 1] += 1

for i in range(N):
    if K + score[i] - Q > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 4684
import math
a,b,h,m=map(int,input().split())
tansin=[a*math.cos(math.radians(90-(30*h+(0.5*m)))),a*math.sin(math.radians(90-(30*h+(0.5*m))))]
chousin=[b*math.cos(math.radians(90-(6*m))),b*math.sin(math.radians(90-(6*m)))]
x=chousin[0]-tansin[0]
y=chousin[1]-tansin[1]
print((x**2+y**2)**0.5)

Measured memory_bytes: 9628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  
  vector<string> vec(H);
  int maxLen = 0;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> vec.at(i);
    s = vec.at(i);
    if ( maxLen < vec.at(i).size() ) {
      maxLen = vec.at(i).size();
    }
  }  
  string a;
  for (int i = 0; i < W+2; i++) a += "#";
  
  cout << a << endl;
  for (int i = 0; i < H; i++) {
    cout << "#" << vec.at(i) << "#" << endl;
  }
  cout << a << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int data[]= new int[5];
       data[0] = sc.nextInt();
       data[1] = sc.nextInt();
       data[2] = sc.nextInt();
       data[3] = sc.nextInt();
       data[4] = sc.nextInt();



      int k = sc.nextInt();

      for(int i = 0;i<5;i++){
        for(int j = i+1;j<5;j++){
          if(Math.abs(data[i]-data[j])>k){
            System.out.println(":(");
            System.exit(0);
          }
        }
      }
      System.out.println("Yay!");
  }
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; 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> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

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

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
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); }
// clang-format on

signed main(int argc, char *argv[]) {
  int x = in(), y = in(), z = in();
  x -= y + 2 * z;
  cout << (x / (y + z)) + 1 << endl;
}


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

std::string solve()
{
    int N;
    long long int M;
    long long int V, P;

    cin >> N >> M >> V >> P;

    long long int A[N];

    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    sort(A, A + N);

    long long int ans = 0;
    long long int key = N - P; // index of the P-th largest.

    ans += N - key;

    long long int cuml[N + 1];

    cuml[0] = 0;
    for (int i = 0; i < N; i++)
    {
        cuml[i + 1] = cuml[i] + A[i];
    }

    for (long long int i = 0; i < key; i++)
    {
        long long int score_i = A[i] + M; // i問目の点数の最大限

        if (score_i < A[key])
            continue; // どれだけ頑張っても、A[key] に到達できないので、大きいものに入らない

        if (V < P)
        {
            ans++;
            continue;
        }

        long long int needToVote = M * V;

        long long int canVoteSum = 0;

        canVoteSum += (P - 1) * M; //高い方から
        canVoteSum += (i + 1) * M; //低い方から

        canVoteSum += (key - i) * score_i;
        long long int aSum = 0;
        long long int bSum = 0;
        for (long long int j = i + 1; j < key + 1; j++)
        {
            aSum += A[j];
        }
        bSum = (long long int) cuml[key + 1] - (long long int) cuml[i + 1];        
        canVoteSum -= bSum;
        if (needToVote <= canVoteSum)
            ans++; // all votes are consumed.
    }
    return to_string(ans);
}

int main()
{
    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef pair<double,double> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll X,Y;
int main(){
	cin >> X >> Y;
	if(X%Y==0ll)cout << -1 << endl;
	else{
		cout << X << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define all(a) a.begin(),a.end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    string s; cin >> s;
    cout << s[0] << s.length()-2 << s[s.length()-1] << endl;
}

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

int main(){
    string s;
    int n;
    cin >> s >> n;
    string ans = "";
    for(int i=0; i<(int)s.length(); i+=n){
        ans += s[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256