akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define SP << " " <<
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    ll sum=0;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    rep(i,N) sum+=A[i];
    bitset<4010101> bs;
    bs[0]=1;
    rep(i,N){
        bs |= bs<<A[i];
    }
    reps(i,(sum+1)/2,sum+1){
        if(bs[i]) { cout<< i <<"\n"; return;}
    }
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 1792
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int a[5];
void solve(int val, int idx, string str) {
    string pat = "+-";
    // printf("val = %lld, idx = %lld, str = %s\n", val, idx, str.c_str());
    if(idx == 4) {
        if(val == 7) {
            str += "=7";
            cout << str << endl;
            exit(0);
        }
        return;
    }
    rep(i,0,2) {
        string nstr = str + pat[i] + (char)(a[idx] + '0');
        int nval = (i == 0 ? val + a[idx] : val - a[idx]);
        solve(nval, idx+1, nstr);
    }
}

signed main() {
    string s; cin >> s;
    rep(i,0,4) {
        a[i] = (s[i] - '0');
    }

    string init = "";
    init += s[0];
    solve(a[0], 1, init);
    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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
typedef pair<ll,ll> P;

int main() {
  int n,m;
  cin >> n>>m;
  vector<int>d[m];
  vector<int>b(m);
  rep(i,m){
    cin>>b.at(i);
    int a;
    cin>>a;
    rep(j,a){
      int c;
      cin>>c;
      c--;
      d[i].push_back(c);
    }
  }
  int inf=1001001001;
  vector<int>dp(5000,inf);
  dp[0]=0;
  rep(i,m){
    int now=0;
    rep(j,d[i].size()){
      now|=(1<<d[i][j]);
    }
    rep(tmp,(1<<n)){
      if(dp[tmp|now]>dp[tmp]+b[i]){
        dp[tmp|now]=dp[tmp]+b[i];
      }
    }
  }
        
  if(dp[(1<<n)-1]!=inf){
    cout<<dp[(1<<n)-1]<<endl;
  }
  else{
    cout<<-1<<endl;
  }
}

Measured memory_bytes: 3656
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

constexpr bool isPrime(const int n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}

main {
  int n, x;
  while (cin >> n >> x, n) {
    vi v(n);
    cin >> v;
    vi dp(x + 1);
    dp[0] = true;
    for (auto &t : v) rep(i, x + 1 - t) dp[i + t] |= dp[i];
    for (int i = x; i > 0; i--) {
      if (dp[i] && isPrime(i)) {
        cout << i << endl;
        goto next;
      }
    }
    cout << "NA" << endl;
  next:;
  }
}

Measured memory_bytes: 16636
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n;
    cin >> n;
    double d = 0.5;
    int c = n*2;
    cout << c/60 << " " << c%60 << endl;

}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <set>
 
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
#define DEV_VAL (1000000000 + 7)
 
int main()
{
  ll a;
  cin >> a;
  cout << (a + a * a + a * a * a) << endl;
 
 
  return 0;
}

Measured memory_bytes: 3580
h,w = map(int,input().rsplit())
s = []
s.append("."*(w+2))
for i in range(h):
	s.append("."+input()+".")
s.append("."*(w+2))
count = 0
ans = 0
for i in range(1,h+1):
	for j in range(1,w+1):
		if s[i][j] == "#":
			if s[i-1][j] == "#":
				count+=1
			elif s[i+1][j] == "#":
				count +=1
			elif s[i][j-1] == "#":
				count +=1
			elif s[i][j+1] == "#":
				count +=1
			else:
				ans = 1
				break

if ans == 0:
	print("Yes")
if ans == 1:
	print("No")

Measured memory_bytes: 9228
s = input().split()

n = int(s[0])
a = int(s[1])
b = int(s[2])

count = 0

for i in range(1,n+1):
    s = list(str(i))
    g = 0
    for stri in s:
        g += int(stri)
    if g >= a and g <= b:
        count += i

print(count)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	ll N;
	ll A[100001];
	cin >> N;
	for(int i = 0; i <= N; i++){
		cin >> A[i];
	}
	ll S[100001];
	fill(S, S+N+1, 0);
	S[0] = A[0];
	for(int i = 1; i <= N; i++){
		S[i] = S[i-1] + A[i];
	}
	
	ll P[100001];
	fill(P, P+N+1, 0);
	P[0] = 1;
	if(P[0] < A[0]){
		cout << -1 << endl;
		return 0;
	}
	for(int i = 1; i <= N; i++){
		P[i] = min(2 * (P[i-1] - A[i-1]), S[N]-S[i-1]);
		if(P[i] < A[i]){
			cout << -1 << endl;
			return 0;
		}
	}
	
	ll ans = 0;
	for(int i = 0; i <= N; i++){
		ans += P[i];
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5976
#include<bits/stdc++.h>
typedef unsigned long long int ull;
typedef long long int ll;
#define loop(i,a,b) for(int i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(false);
using namespace std;


int main(){
	fastio
	int a,b,c;
	cin >> a >> b >>c;
	if(a+b+c >= 22)
		cout << "bust" << endl;
	else{
		cout << "win" << endl;
	}
	return 0;
}

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

using namespace std;
long long int n,k;

int dp[1000001];

void test()
{
    int x,y;
    cin>>x>>y;

    if(y>=2*x && y<=4*x && y%2==0)
        cout<<"Yes\n";
    else
        cout<<"No\n";

}

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

    test();

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>

using namespace std;
string s;
int main(){
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3]){
        cout << "No";
    }else if(s[0] == s[1] && s[2] == s[3]){
        cout << "Yes";
    }else if(s[0] == s[2] && s[1] == s[3]){
        cout << "Yes";
    }else if(s[0] == s[3] && s[1] == s[2]){
        cout << "Yes";
    }else{
        cout << "No";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <random>
#include <map>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)
#define YN(f) f?cout<<"YES"<<endl:cout<<"NO"<<endl;
#define yn(f) f?cout<<"Yes"<<endl:cout<<"No"<<endl;

int a[4];
string s;
bool f=false;

signed main(){
	cin>>a[0]>>a[1]>>a[2]>>a[3];
	sort(a,a+4);
	if(a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9)f=true;
	YN(f);
	return 0;
}

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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  string s = stin();
  int n = s.size();
  int ans = 0;
  int counter = 0;
  for(int i = 0; i < n; ++i) {
    if(s[i]=='S') ++counter;
    else {
      if(counter) {
        ++ans;
        --counter;
      }
    }
  }
  cout << n-ans*2;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll n,m,q;
const ll MAX_Q=50;
vll a(MAX_Q),b(MAX_Q),c(MAX_Q),d(MAX_Q);


ll calc(vll v){
  ll res=0;
  REP(i,q){
    if(v[b[i]]-v[a[i]]==c[i])
      res+=d[i];
  }

  return res;
}


ll dfs(ll now, ll remind, vll& v){
  if(remind==0)
    return calc(v);
  ll res=0;

  v[n-remind]=now;
  for(ll i=now; i<=m; i++)
    res=max(res,dfs(i,remind-1,v));

  return res;
}

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

  cin>>n>>m>>q;
  REP(i,q){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    a[i]--;
    b[i]--;
  }

  vll v(n);
  ll ans=dfs(1,n,v);
  cout<<ans<<endl;


}



Measured memory_bytes: 3664
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const size_t SIZE = 2010;
ll A[SIZE], par[SIZE];
multiset<ll> mst[SIZE], num;
bool used[SIZE];

void merge(ll i, ll j) {
    ll pi = par[i];
    ll pj = par[j];
    if(pi == pj) return;
    if(mst[pi].size() < mst[pj].size()) swap(pi, pj);
    for(ll e : mst[pj]) mst[pi].insert(e);
    par[pj] = pi;
    mst[pj].clear();
}

ll find_par(ll i) {
    return i == par[i] ? i : (par[i] = find_par(par[i]));
}

const ll inf = 5e15;

int main() {
    ll N, K, Q;
    cin >> N >> K >> Q;
    for(ll i = 0; i < N; i++) {
        cin >> A[i];
        mst[i].insert(A[i]);
    }

    iota(par, par + N, 0ll);
    V<ll> ord(N);
    iota(ALL(ord), 0ll);
    sort(ALL(ord), [&](ll i, ll j) { return A[i] > A[j]; });
    ll ans = inf;

    for(ll idx : ord) {
        if(0 < idx && used[idx - 1]) merge(idx, find_par(idx - 1));
        if(idx + 1 < N && used[idx + 1]) merge(idx, find_par(idx + 1));
        used[idx] = true;
        ll p = find_par(idx);
        while(K <= mst[p].size()) {
            auto ite = mst[p].begin();
            num.insert(*ite);
            mst[p].erase(ite);
        }
        while(Q < num.size()) {
            auto ite = prev(num.end());
            num.erase(ite);
        }

        if(num.size() == Q) chmin(ans, *num.rbegin() - *num.begin());
    }

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }

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

    lint res = 0;

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

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3636
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, Q;
    string s;
    cin >> N >> Q >> s;
    vector<char> t(Q), d(Q);
    for (ll i = 0; i < Q; i++) {
        cin >> t[i] >> d[i];
    }

    //[left, right]にあるものは生き残る
    ll left = 0, right = N - 1;

    for (ll i = Q-1;i>=0;i--) {
        if (d[i] == 'L') {
            if (t[i] == s[left]) {
                left++;
            }
            //範囲を広げている
            if (right < N-1 && t[i] == s[right+1]) {
                right++;
            }
        } else {
            if (t[i] == s[right]) {
                right--;
            }
            //範囲を広げている
            if (left > 0 && t[i] == s[left-1]) {
                left--;
            }
        }
    }

    cout << max(right - left + 1,(ll)0) << endl;
}


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

#define ll long long
#define ar array

const int mxN=3e3, M=998244353;
int n, s, a[mxN];
ll dp[mxN+1][mxN+1], ans;

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

	cin >> n >> s;
	for(int i=0; i<n; ++i) {
		cin >> a[i];
		memcpy(dp[i+1], dp[i], sizeof(dp[0]));
		//start a new sequence
		dp[i+1][a[i]]=(dp[i+1][a[i]]+i+1)%M;
		for(int j=0; j+a[i]<=s; ++j)
			dp[i+1][j+a[i]]=(dp[i+1][j+a[i]]+dp[i][j])%M;
		ans=(dp[i+1][s]+ans)%M;
	}
	cout << ans;
}


Measured memory_bytes: 70656
#include "bits/stdc++.h"
#define ll long long
#define PI 3.1415926535897932384626433832795l
#define MAX_NUM 1000000000
#define line printf("-----------------\n");
using namespace std;
int SET(int N, int pos) { return N = N | (1 << pos); }
int RESET(int N, int pos) { return N = N & ~(1 << pos); }
bool CHECK(int N, int pos) { return (bool)(N & (1 << pos)); }
template <typename T>
inline T __lcm(T a, T b)
{
    return (a * b) / __gcd(a, b);
}
struct node
{
    int x, y, i;
};
int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};
int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};

struct DisJointSet
{
    vector<ll> size_;
    vector<ll> parent;

    DisJointSet(ll n)
    {
        size_.resize(n + 1, 1);
        parent.resize(n + 1);

        for (int i = 1; i <= n; i++)
            parent[i] = i;
    }
    ll findSet(ll x)
    {
        if (parent[x] == x)
            return x;
        return parent[x] = findSet(parent[x]);
    }
    void unionSet(ll a, ll b)
    {
        a = findSet(a);
        b = findSet(b);
        if (a != b)
        {
            if (size_[a] < size_[b])
            {
                swap(a, b);
            }
            parent[b] = a;
            size_[a] += size_[b];
        }
    }
};
ll fun(ll n)
{
    return n * (n - 1) / 2;
}
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> v;

    vector<ll> v2;

    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        v.push_back({x, y});
    }
    reverse(v.begin(), v.end());
    DisJointSet dsu(n);
    ll ans = (n - 1) * n / 2;

    v2.push_back(ans);

    for (int i = 0; i < m - 1; i++)
    {
        //int temp = ans;
        ll x, y;
        x = v[i].first;
        y = v[i].second;
        //cout<<x<<" "<<y<<endl;
        ll sizex = dsu.size_[dsu.findSet(x)];
        ll sizey = dsu.size_[dsu.findSet(y)];
        //cout<<sizex<<" + "<<sizey<<endl;
        if (dsu.findSet(x) != dsu.findSet(y))
        {
            dsu.unionSet(x, y);
            //int sizexy = dsu.size_[dsu.findSet(x)];
            //cout<<fun(sizexy)<<" "<<fun(sizex)<<" "<<fun(sizey)<<endl;
            ans -= sizex*sizey;
            v2.push_back(ans);
        }
        else
        {
            v2.push_back(ans);
        }
        
    }

    for (int i = m-1; i >= 0; i--)
    {
        cout << v2[i] << endl;
    }
}

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("inputf.txt", "r", stdin);
    //freopen("outputf.txt", "w", stdout);
#endif // ONLINE_JUDGE
    solve();
    return 0;
}

Measured memory_bytes: 6256
n,m=map(int,input().split())
a=[list(input()) for _ in range(n)]
b=[list(input()) for _ in range(m)]

eq = False
find = False
for i in range(n-m+1):
  for j in range(n-m+1):
    for p in range(m):
      for q in range(m):
        if a[p+i][q+j] == b[p][q]:
          eq = True
        else:
          eq = False
          break
      if not eq:
        break
    if eq:
      find = True
      break
  if find:
    break
if find:
  print('Yes')
else:
  print('No')

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

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


Measured memory_bytes: 5072
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a;
  cin>>b;
  if(a!=1 && b!=1){
    c=1;
  }
  else if(a!=2 && b!=2){
    c=2;
  }
  else{
    c=3;
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
local H, W, h, w = io.read("*n", "*n", "*n", "*n")
if H % h == 0 and W % w == 0 then
  print("No")
else
  print("Yes")
  if H % h ~= 0 then
    local dv = H // h
    local p1 = dv + 1
    local p2 = -p1 - 1
    for i = 1, H do
      for j = 1, W do
        if i % h == 1 then
          io.write(p1)
        elseif i % h == 0 then
          io.write(p2)
        else
          io.write(0)
        end
        io.write(j == W and "\n" or " ")
      end
    end
  else
    local dv = W // w
    local p1 = dv + 1
    local p2 = -p1 - 1
    for i = 1, H do
      for j = 1, W do
        if j % w == 1 then
          io.write(p1)
        elseif j % w == 0 then
          io.write(p2)
        else
          io.write(0)
        end
        io.write(j == W and "\n" or " ")
      end
    end
  end
end


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

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

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

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

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

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


int main(){
  int n;
  vector<pair<int,int> > vec;

  scanf("%d", &n);

  for(int i=0;i<n;i++){
    int a, b;
    scanf("%d%d", &a, &b);
    vec.push_back({a+b, a});
  }

  sort(vec.begin(), vec.end(), greater<pair<int,int>>());

  ll ans = 0;

  for(int i=0;i<n;i++){
    if(i % 2 == 0) ans += vec[i].second;
    else ans -= vec[i].first - vec[i].second;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1528
#include <stdio.h>

int main (int argc,char **argv)
{
	int a = 0,b = 0,x = 0;

	scanf("%d %d %d",&a,&b,&x);

	if((a <= x) && (x <= a+b))
	{
		printf("YES\n");
	}

	else
	{
		printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;

namespace ABC153
{
    class E
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long H = input[0];
            long N = input[1];

            long[,] DP = new long[N + 10, H + 10];
            long[] A = new long[N];
            long[] B = new long[N];

            for (int i = 0; i < N; i++)
            {
                input = Console.ReadLine().Split().Select(long.Parse).ToArray();
                A[i] = input[0];
                B[i] = input[1];
            }

            for (int i = 0; i <= N; i++)
            {
                for (int h = 0; h <= H; h++)
                {
                    DP[i, h] = int.MaxValue;
                }
            }

            DP[0, 0] = 0;
            for (int i = 0; i < N; i++)
            {
                for (int h = 0; h <= H; h++)
                {
                    DP[i + 1, h] = Math.Min(DP[i + 1, h], DP[i, h]);
                    DP[i + 1, Math.Min(h + A[i], H)] = Math.Min(DP[i + 1, Math.Min(h + A[i], H)], DP[i + 1, h] + B[i]);


                }
            }
            Console.WriteLine(DP[N, H]);
        }
    }
}


Measured memory_bytes: 91608
s = input()
n = len(s)
for i in range((n-1)//2):
  if s[i]!=s[(n-1)//2-1-i] or s[i+(n-1)//2+1]!=s[(n-1)-i] or s[i]!=s[(n-1)-i]:
    print('No')
    exit()
print('Yes')

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


using namespace std;

int main(){
   
   int c=0;
  string S;
  getline(cin, S); 
  int n=S.length();
  for(int i=0;i<n/2;i++){
      if(S[i]!=S[n-i-1]){
          c++;
      }
  }
   
   cout<<c;


}

Measured memory_bytes: 256
#include<stdio.h>
#include <iostream>
#include<cmath>
using namespace std;
struct Dice{
    int face[6];
    void roll(char c){
        if(c == 'N'){
            int tmp;
            tmp = face[0];
            face[0]=face[1];
            face[1]=face[5];
            face[5]=face[4];
            face[4]=tmp;
        }else if(c == 'E'){
            int tmp;
            tmp = face[0];
            face[0]=face[3];
            face[3]=face[5];
            face[5]=face[2];
            face[2]=tmp;
        }else if (c == 'S'){
            int tmp;
            tmp=face[0];
            face[0]=face[4];
            face[4]=face[5];
            face[5]=face[1];
            face[1]=tmp;

        }else if(c == 'W'){
            int tmp;
            tmp=face[0];
            face[0]=face[2];
            face[2]=face[5];
            face[5]=face[3];
            face[3]=tmp;
        }
    }
    int top(){
        return face[0];
    }
};

int main(){
    Dice d;
    for(int i=0;i<6; i++){
        cin >> d.face[i];  
    }
    string req;
    cin >> req;
    for(int i=0; i < req.size();i++){
        d.roll(req[i]);
    }
    cout << d.top() << endl;
    return 0;
}




Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=(1e9)+7;
int n,L,X,cnt[510],C[510][510];
ll dp[2][510][510],tmp,ans,ivjc[510],iv[510],jc[510];
ll ksm(ll x,ll y) {
	ll res=1;
	while (y) {
		if (y&1) res=res*x%mod;
		x=x*x%mod; y>>=1;
	} return res;
}
void update(ll &x,ll y) {
	x+=y; if (x>=mod) x-=mod;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(X);
	for (int i=1;i<=n;i++) read(L),cnt[L]++;
	for (int i=0;i<=X;i++) {
		C[i][0]=C[i][i]=1;
		for (int j=1;j<i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	iv[0]=jc[0]=ivjc[0]=1;
	iv[1]=jc[1]=ivjc[1]=1;
	for (int i=2;i<=X;i++) {
		jc[i]=jc[i-1]*i%mod;
		iv[i]=(mod-mod/i)*iv[mod%i]%mod;
		ivjc[i]=ivjc[i-1]*iv[i]%mod;
	}
	dp[X&1^1][0][0]=1;
	for (int i=X;i>=1;i--) {
		for (int j=0;j<=X;j++)
		for (int k=i*j;k<=X;k++) {
			dp[i&1][j][k]=0;
			tmp=ksm(k-(i-1)*j,cnt[i]);
			for (int l=0;l<=min(j,k/i);l++)
				update(dp[i&1][j][k],dp[i&1^1][j-l][k-i*l]*C[j][l]%mod*tmp%mod);
		}
	}
	for (int i=0;i<=X;i++)
	for (int j=0;j<=min(i+1,X);j++) {
		tmp=C[i+1][j]*dp[1][j][X-i]%mod;
		if (i&1) tmp=mod-tmp;
		update(ans,tmp);
	}
	printf("%lld\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD=998244353;
const ll hell=1000000007;
const int INF = 1e8;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=100005;

int dp[3005][3005][2];

void solve()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
for(int l=1;l<=n;l++)
{
    for(int i=0;i<=n-l;i++)
    {
        int j=i+l-1;
        if(i==j)
        {
            dp[i][j][0]=a[i];
            dp[i][j][1]= -a[i];
            continue;
        }
        dp[i][j][0]=max(a[i]+dp[i+1][j][1],a[j]+dp[i][j-1][1]);
        dp[i][j][1]=min(-a[i]+dp[i+1][j][0],-a[j]+dp[i][j-1][0]);
    }
}
cout<<dp[0][n-1][0]<<endl;
}




int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}

Measured memory_bytes: 85428
n,m=map(int,input().split())
s=["0"]*n
for i in range(m):
    a,b=map(int,input().split())
    if s[a-1]=="0":
        s[a-1]=b
    elif s[a-1]!=b:
        print(-1)
        exit()
if n>1 and s[0]=="0":
    s[0]="1"
if n>1 and s[0]==0:
    print(-1)
    exit()
print(*s, sep="")

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

int main(){
	int r,g;
	cin >> r >> g;
	cout << 2*g-r << endl;
}

Measured memory_bytes: 256
void main() {
    int n = readln.chomp.to!int;
    int k = readln.chomp.to!int;
    int[] x = readln.split.to!(int[]);
    int ans;
    foreach (y; x) {
        ans += 2 * min(y, k-y);
    }
    ans.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n;
    cin>>n;
    set<int> a;

    rep(i,n){
        int tmp;
        cin>>tmp;
        a.insert(tmp);
    }

    if(a.size()==n)cout<<"YES\n";
    else cout<<"NO\n";

    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

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

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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 pid_t pid = getpid();
// Problem Specific Parameter:

using pii = pair<int,int>;
vector<pii> ary;
set<int> block;

const int limit = 200010;
int s[limit], t[limit], x[limit], e[limit];

int main(void){
	int n,q;
	cin >> n >> q;
	rep(i, n){
		cin >> s[i] >> t[i] >> x[i];
		s[i] -= x[i];
		t[i] -= x[i];
		ary.push_back(pii(s[i], i));
		ary.push_back(pii(t[i], i));
	}

	rep(i, q) cin >> e[i];
	
	sort(begin(ary), end(ary));
	const int m = ary.size();
	int pos = 0;

	rep(i, q){
		while(pos < m and ary[pos].first <= e[i]){
			const int idx = ary[pos].second;
			if(block.find(x[idx]) != end(block))
				block.erase(x[idx]);
			else
				block.insert(x[idx]);
			pos++;
		}
		if(block.empty())
			cout << -1 << endl;
		else
			cout << *begin(block) << endl;
	}

	return 0;
}

Measured memory_bytes: 16876
from collections import deque

queue = deque([])

for _ in range(int(input())):
    commands = input().split(" ")
    command = commands[0]
    if command == "insert":
        queue.appendleft(commands[1])
    elif command == "delete":
        try:
            queue.remove(commands[1])
        except ValueError:
            pass
    elif command == "deleteFirst":
        queue.popleft()
    elif command == "deleteLast":
        queue.pop()

print(" ".join(queue))

Measured memory_bytes: 71880
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
int ans = INT_MAX;
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
vector < int > tree[N];
vector < bool > visited(N,0) ;
vector < int > long_path(N,0) ;
void dfs( int x ){
	visited[x] = true ;
	for( int child = 0 ; child < tree[x].size(); child++ ){
		if(!visited[tree[x][child]])
			dfs(tree[x][child]);
		long_path[x] = max( long_path[x] , long_path[tree[x][child]]+1);
	}
}
void solve(){
	int n , m ; 
	cin >> n >> m ; 
	for( int i = 0 ; i < m ; i++){
		int x , y ; 
		cin >> x >> y ;
		tree[x].PB(y);
	}
	for( int i = 1 ; i <= n ; i++ ){
			if(!visited[i])
				dfs(i);
	}
	cout << *max_element(st(long_path));
	
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


Measured memory_bytes: 8192
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0)
    return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1; // 分母
  ll numerator = 1;   // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
private:
  vector<ll> parents;

public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y))
      return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry])
      swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

private:
  ll root(ll x) {
    if (parents[x] < 0)
      return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

void dfs(vector<vector<ll>> &graph, vector<ll> &points, vector<bool> &visited, ll current) {
  if (visited[current]) {
    return;
  }

  visited[current] = true;
  for (auto v : graph[current]) {
    if (visited[v])
      continue;
    points[v] += points[current];
    dfs(graph, points, visited, v);
  }
}

int main() {
  ll N, Q;
  cin >> N >> Q;
  vector<vector<ll>> graph(N, vector<ll>());
  for (ll i = 0; i < N - 1; i++) {
    ll a, b;
    cin >> a >> b;
    graph[a - 1].push_back(b - 1);
    graph[b - 1].push_back(a - 1);
  }

  vector<ll> points(N, 0);
  for (ll i = 0; i < Q; i++) {
    ll p, x;
    cin >> p >> x;
    points[p - 1] += x;
  }

  vector<bool> visited(N, false);
  dfs(graph, points, visited, 0);
  for (ll i = 0; i < N; i++) {
    cout << points[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 30592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define SORT(a) sort(a.begin(),a.end())
 
int main() {
	
	//string ans="";
	//vector<int> c(30,0);
	//cout << a << b << endl;
	
	
	int ans=0;
	
	int n;
	
	cin >> n;// >> b;
	
	string s;
	
	cin >> s;
	
	rep(i,n-1){
		if(s[i]!=s[i+1]) ans++;
	}

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

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,p,x;
    cin>>n>>p;
    priority_queue<int,vector<int>>a;
    for(int i = 0;i<n;i++)
    {
        cin>>x;
        a.push(x);
    }
    if(p>=n)
    {
        cout<<0;
        return 0;
    }
    while((!a.empty())&&(p--))
    {
        a.pop();
    }
    long long int sum = 0;
    while(!a.empty())
    {
        sum = sum+a.top();
        a.pop();
    }
    cout<<sum;

}


Measured memory_bytes: 1400
import sys

n, *ab = map(int, sys.stdin.read().split())
graph = [[]for _ in range(n+1)]
for a, b in zip(*[iter(ab)] * 2):
    graph[a].append(b)
    graph[b].append(a)

def dfs(v):
    stack = [v]
    dist = [None] * (n + 1)
    dist[v] = 0
    while stack:
        x = stack.pop()
        for y in graph[x]:
            if dist[y] is None:
                dist[y] = dist[x] + 1
                stack.append(y)
    return dist

def main():
    dist_1 = dfs(1)
    dist_n = dfs(n)
    black_cnt = 0
    for i in range(1, n+1):
        if dist_1[i] <= dist_n[i]:
            black_cnt += 1

    if black_cnt <= n // 2:
        return 'Snuke'
    else:
        return 'Fennec'

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 30552
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    int a, b, c; cin >> a >> b >> c;
    for(int i = a; i <= a*b; i+=a) {
        if(i % b == c) {
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
    
    
    
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

bool solve(int n, vector<int> &a, vector<vector<int> > &g) {
    vector<int> dp(n);
    auto is_leaf = [&](int i) { return g[i].size() == 1; };
    function<bool(int, int)> go = [&](int i, int parent) {
        if (is_leaf(i)) {
            dp[i] = a[i];
        } else {
            ll sum_dp = 0;
            for (int j : g[i])
                if (j != parent) {
                    if (not go(j, i)) return false;
                    sum_dp += dp[j];
                }
            ll b = sum_dp - a[i];
            ll c = a[i] - b;
            if (b < 0 or c < 0) return false;
            int argmax_dp = *whole(max_element, g[i],
                                   [&](int j, int k) { return make_pair(j != i, dp[j]) < make_pair(k != i, dp[k]); });
            ll max_dp = dp[argmax_dp];
            if (max_dp > sum_dp / 2) {
                if (sum_dp - max_dp < b) return false;
            } else {
                if (sum_dp / 2 < b) return false;
            }
            dp[i] = c;
        }
        return true;
    };
    assert (n >= 2);
    if (n == 2) {
        return a[0] == a[1];
    } else {
        int i = 0;
        while (is_leaf(i)) ++i;
        if (not go(i, -1)) return false;
        return dp[i] == 0;
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a[i];
    vector<vector<int>> g(n);
    rep(i, n - 1) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    cout << (solve(n, a, g) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    string S;
    cin >> S;
    int N=S.size();
    string ans="NO";
    string a,b;
    rep(i,7){
        a=S.substr(0,i);
        b=S.substr(N-7+i);
        if("keyence"== a+b) ans="YES";
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
import numpy as np
N,K = map(int, input().split())
ans = 0
logK = np.log2(K)
if N < K:
    for i in range(N):
        sisu = int(logK - np.log2(i + 1))
        if np.log2(K/(i+1)) != int(np.log2(K/(i+1))):
            sisu += 1
        ans +=1 / (2 ** sisu)
    print(ans/ N)
else:
    for i in range(K - 1):
        sisu = int(logK - np.log2(i + 1))
        if np.log2(K/(i+1)) != int(np.log2(K/(i+1))):
            sisu += 1
        ans +=1 / (2 ** sisu)   
    ans += N - K + 1
    ans = ans / N
    print(ans)

Measured memory_bytes: 21484
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		s = s.substring(0, s.length() - 2);
		for (int i = s.length() - 1; i > 0; i--) {
			if (s.length() % 2 == 0) {
				String a = s.substring(0, s.length() / 2 - 1);
				String b = s.substring(s.length() / 2 , s.length() - 1);
				if (a.equals(b)) {
					System.out.println(s.length());
					break;
				}
			}
			s = s.substring(0, s.length() - 2);
		}
		if (s.length() == 1) {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 23764
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int k = sc.nextInt();
		char c = arr[k - 1];
		for (int i = 0; i < n; i++) {
			if (arr[i] != c) {
				arr[i] = '*';
			}
		}
		System.out.println(arr);
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int N, result;
	vector<ll> a;
	cin >> N;
	result = 0;
	for (int i = 0; i < N; i++) {
		ll ai;
		cin >> ai;
		a.push_back(ai);
	}

	for (int i = 0; i < N; i++) {
		if (a[i] % 2 == 0) {
			a[i] /= 2;
			i = -1;
			result++;
		}
	}
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 512