akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <bitset>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";}
template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";}
template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 1e9+7;

int main() {
  int n; cin>>n;
  int p[n];for(int i=0;i<n;i++) cin>>p[i];

  ll ka[n]={}, kb[n+1]={}, aa[n]={}, ab[n]={};
  for(int i=0;i<n;i++) {
    ka[i]=kb[i]=1;
  }

  for(int i=0;i<n;i++) {
    if (i==0) continue;
    ka[p[i]-1]+=i;
    kb[p[i]]+=i;
  }

  ll nw=0;
  for(int i=0;i<n;i++) {
    nw+=ka[i]; aa[i]=nw;
  }
  nw=1e9;
  for(int i=0;i<n;i++) {
    nw-=kb[i]; ab[i]=nw;
  }
  for(int i=0;i<n;i++) {
    cout<<aa[i]<<" ";
  } cout<<endl;
  for(int j=0;j<n;j++) {
    cout<<ab[j]<<" ";
  } cout<<endl;
}
// Thank you for making problems and running the contest

Measured memory_bytes: 1280
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, (llint)b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	int n;
	cin >> n;
	if (n % 100 == 0)cout << 1 << endl;
	else {
		int e = (n % 100) / 5;
		if ((n % 100) % 5 != 0) {
			e++;
		}
		if (e * 100 <= n)cout << 1 << endl;
		else cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,b[100]={0},flag,m;
    scanf("%d",&m);
    for(i=0;i<m;)
    {
    	scanf("%d",&flag);
    	if(b[flag]==0)
    	{
    		b[flag]=1;
    		i++;
		}
		else
		{
			m--;
		}
	}
	printf("%d",m);
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

vector<ll> Plus(200001);
vector<ll> cnt(200001);
vector<ll> vis(200001);
vector<vector<ll>> edges(200001,vector<ll>(0));

void dfs(ll now,ll sum){
    vis[now]=1;
    cnt[now]=sum+Plus[now];
    rep(i,edges[now].size()){
        if(vis[edges[now][i]]!=1){
            dfs(edges[now][i],sum+Plus[now]);
        }
    }
    return;   
}

//
void solve(long long N, long long Q, std::vector<long long> a, std::vector<long long> b, std::vector<long long> p, std::vector<long long> x){
    vis[0]=1;
    dfs(0,0);
    //cnt[0]+=Plus[0];
    rep(i,N){
        cout<<(cnt[i]);
        if(i<N-1) cout<<" ";
        else cout<<endl;
    }
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    cnt.resize(N);
    edges.resize(N-1);
    Plus.resize(N);
    vis.resize(N);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        edges[a[i]-1].push_back(b[i]-1);
        edges[b[i]-1].push_back(a[i]-1);
    }
    std::vector<long long> p(Q);
    std::vector<long long> x(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&p[i]);
        scanf("%lld",&x[i]);
        Plus[p[i]-1]+=x[i];
    }
    solve(N, Q, std::move(a), std::move(b), std::move(p), std::move(x));
    return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> masu(H,vector<char>(W));
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> masu.at(i).at(j);
    }
  }
  
  for(int i=0;i<masu.size();i++){
    int j=0;
    while(masu.at(i).at(j) == '.'){
      if(j == masu.at(i).size()-1){
        for(int k=i;k < masu.size()-1;k++){
          for(int l=0;l<masu.at(k).size();l++){
            masu.at(k).at(l) = masu.at(k+1).at(l);
          }
        }
        masu.pop_back();
        i--;
        break;
      }else{
        j++;
      }
    }
  }
  for(int i=0;i<masu.at(0).size();i++){
    int j=0;
    while(masu.at(j).at(i) == '.'){
      if(j == masu.size()-1){
        for(int k=0;k<masu.size();k++){
          for(int l=i;l < masu.at(k).size()-1;l++){
            masu.at(k).at(l) = masu.at(k).at(l+1);
          }
          masu.at(k).pop_back();
        }
        i--;
        break;
      }else{
        j++;
      }
    }
  }
  for(int i=0;i<masu.size();i++){
    for(int j=0;j<masu.at(i).size();j++){
      cout << masu.at(i).at(j);
    }
    cout << endl;
  }
}


Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	bool h=false;
	rep(i,b)if(a*i%b==c)h=true;
	if(h)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}











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

// headers {{{
using namespace std;
// using namespace rel_ops;
 
const double pi=acos(-1.0);
const double eps=1e-11;
const int INF=0x7FFFFFFF;
template<class T> inline bool checkmin(T &a,T b){return b<a?a=b,1:0;}
template<class T> inline bool checkmax(T &a,T b){return b>a?a=b,1:0;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline bool bit(T a, int b) {return (a>>b)&1;}
inline int popcount(int n) { return __builtin_popcount(n); }
inline int popcount(long long n) { return __builtin_popcountll(n); }
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define eb(args...) emplace_back(args)
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ff first
#define ss second
#define sz(g) int(g.size())
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
#ifdef LOCAL
#define dout cerr 
void out() { dout << endl; }
template<typename A, typename... B> void out(A a, B... b) { dout << ' ' << a; out(b...); }
#define dbg(args...) dout << __LINE__ << ":(" << #args << ") -> ", out(args)
template<class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
template<class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}
constexpr bool local = true;
#else
#define dbg(...)
#define dout if(true);else cerr
#define out(...)
#define show(...)
constexpr bool local = false;
#endif
// }}}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    VI a(5);
    rep(i, 5) cin >> a[i];
    rep(i, 5) if (!a[i]) cout << i+1 << endl;
    return 0;
}



Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        int[] dn = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        int D = dn[0];
        int N = dn[1];

        if (N != 100)
        {
            Console.WriteLine((int)Math.Pow(100, D) * N);
        }
        else
        {
            Console.WriteLine((int)Math.Pow(100, D) * N + (int)Math.Pow(100, D));
        }
    }
}



static class MathUtil
{
    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}



Measured memory_bytes: 13268
def divisor_enumetarion(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.remove(n)
    return divisors
    
n,k=map(int,input().split())
 
dp=[0]*k
mod=10**9+7
 
ans=0
for i in range(k,0,-1):
    toori=pow(k//i,n,mod)
 
    dp[i-1]+=toori
 
    x=divisor_enumetarion(i)
    for j in x:
        dp[j-1]-=dp[i-1]%mod
 
    ans+=(dp[i-1]*i)%mod
print(ans%mod)

Measured memory_bytes: 70320
S = input()
N = len(S)
l = 1
before = S[0]
ans = 1
while l < N:
    r = l+1
    while r < N and before == S[l:r]:
        r += 1
    tmp = S[l:r]
    if before != tmp:
        ans += 1
    before = tmp
    l = r

print(ans)


Measured memory_bytes: 41564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi; 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn = 5e5+10;
const int inf = 0x3f3f3f3f;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	int n,m,ans;
	cin>>n>>m;
	ans=n*(n-1)/2+m*(m-1)/2;
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

using coord = std::pair<double, double>;

double len(const coord& line) {
  return std::sqrt(line.first * line.first + line.second * line.second);
}

void Koch(coord start, coord end, uint32_t n) {
  if (n == 0) {
    std::cout << start.first << " " << start.second << std::endl;
    return;
  }

  auto diff = coord(end.first - start.first, end.second - start.second);
  auto s = coord(diff.first / 3 + start.first, diff.second / 3 + start.second);
  auto t = coord(diff.first * 2 / 3 + start.first,
                 diff.second * 2 / 3 + start.second);
  auto u = coord(diff.first / 2 + start.first, diff.second / 2 + start.second);

  auto normal = coord(-diff.second / len(diff), diff.first / len(diff));
  double normal_len = std::sqrt(3) * len(diff) / 6;
  normal = coord(normal_len * normal.first, normal_len * normal.second);

  u = coord(u.first + normal.first, u.second + normal.second);

  Koch(start, s, n - 1);
  Koch(s, u, n - 1);
  Koch(u, t, n - 1);
  Koch(t, end, n - 1);

  return;
}

int main() {
  uint32_t n = 0;
  std::cin >> n;

  std::cout << std::fixed;
  std::cout << std::setprecision(8);

  auto start = coord(0, 0);
  auto end = coord(100, 0);
  Koch(start, end, n);

  std::cout << end.first << " " << end.second << std::endl;
  return 0;
}


Measured memory_bytes: 3228
N = int(input())
X = list(map(int,input().split()))
MOD = 10**9+7

f = 1
for i in range(1,N):
  f *= i
  f %= MOD
#print(f)

c = [1 for _ in range(N)]
for i in range(1,N):
  c[i] = c[i-1] + pow(i+1,MOD-2,MOD) # 1/(i+1)を加算
  c[i] %= MOD

ans = 0
for i in range(N-1):
  ans += (X[i+1]-X[i])*c[i]
  ans %= MOD
print((ans*f)%MOD)


Measured memory_bytes: 63640
/*
THE BEST IS YET TO COME
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define r(i,s,l) for(int i=s;i<l;i++)
#define mod 1000000007
#define INT_BITS 32
#define ld long double
#define pp pair<long long,long long>
#define ss second
#define ff first
#define N 2000005
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fast();
    int n,Q;
    cin>>n>>Q;
    vector<ll> g[n+1];
    r(i,0,n-1)
    {

        int x,y;
        cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    vector<ll> a(n+1,0);
    while(Q--)
    {
        int x,y;
        cin>>x>>y;
        a[x] += y;
    }
    queue<int> q;
    q.push(1);
    vector<bool> vis(n+1,false);
    vis[1]=true;
    while(!q.empty())
    {
        ll x=q.front();
        q.pop();
        for(auto i=g[x].begin();i!=g[x].end();i++)
        {
            if(!vis[*i])
            {
                vis[*i]=true;
                a[*i]+=a[x];
                q.push(*i);
            }
        }
    }
    r(i,1,n+1)
    cout<<a[i]<<" ";
	return 0;
}


Measured memory_bytes: 17136
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
using namespace std;

int main(int argc, const char * argv[]) {
    string S;
    cin >> S;
    if (S[0]=='R' && S[1]=='R' && S[2]=='R') cout<<3<<endl;
    else if (S[0]=='R' && S[1]=='R' && S[2]=='S') cout<<2<<endl;
    else if (S[0]=='S' && S[1]=='R' && S[2]=='R') cout<<2<<endl;
    else if (S[0]=='S' && S[1]=='S' && S[2]=='S') cout<<0<<endl;
    else  cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <functional>

using namespace std; using ll=long long; using ld=long double; using P=pair<ll,ll>; const int INF=1e9; const ll LINF=1e18;
template<typename T> void caut(T a, T b, T c){cout<<"("<<a<<","<<b<<","<<c<<") ";}
template<typename T> void caut(T a, T b){cout<<"("<<a<<","<<b<<") ";}
template<typename T> void caut(T a){cout<<"("<<a<<") ";}

const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};
bool valid(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}

int mx=0;

string s[2000];
int o[2000][2000][5], h, w;
//int o2[2000][2000][5];
bool done[2000][2000];

void dfs(int nx, int ny, int mu) {
  if (done[nx][ny] || s[nx][ny]=='0') return;
  done[nx][ny]=true;
  if (mu!=-1) o[nx][ny][mu]++;
  for(int i=0;i<4;i++) {
    int tx = nx+up[i], ty = ny+lf[i];
    if (valid(tx,ty,h,w)) {
      dfs(tx,ty,i);
    }
  }
}

int main(){
  int q; cin>>h>>w>>q;
  for(int i=0;i<h;i++) cin>>s[i];
  bool checked=false;
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      dfs(i,j,4);
    }
  }
  
  /*
  for(int k=0;k<5;k++) {
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      cout<<o[i][j][k]<<" ";
    } cout<<endl;
  }cout<<endl;}*/

  //copy(o[0][0], o[2000][2000], o2[0][0]);

  for(int k=0;k<5;k++) {
    for(int i=0;i<h;i++) {
      for(int j=1;j<w;j++) {
        o[i][j][k]+=o[i][j-1][k];
      }
    }
    for(int j=0;j<w;j++) {
      for(int i=1;i<h;i++) {
        o[i][j][k]+=o[i-1][j][k];
      }
    }
  }
  /*
  for(int k=0;k<5;k++) {
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      cout<<o[i][j][k]<<" ";
    } cout<<endl;
  }cout<<endl;}*/

  for(int i=0;i<q;i++) {
    int a,b,c,d; cin>>a>>b>>c>>d;
    a--; b--; c--; d--;
    int an = 0;//, sm=0;
    /*
    for(int j=a;j<=c;j++) {
      for(int k=b;k<=d;k++) {
        sm+=o2[j][k][4];
      }
    }
    for(int j=a;j<=c;j++) {
      sm+=o2[j][b][2]+o2[j][d][3];
    }
    for(int k=b;k<=d;k++) {
      sm+=o2[a][k][0]+o2[c][k][1];
    }*/

    an+=o[c][d][4];
    if (a>0) an-=o[a-1][d][4];
    if (b>0) an-=o[c][b-1][4];
    if (a>0&&b>0) an+=o[a-1][b-1][4];

    an+=o[c][b][2];
    if (a>0) an-=o[a-1][b][2];
    if (b>0) an-=o[c][b-1][2];
    if (a>0&&b>0) an+=o[a-1][b-1][2];

    an+=o[c][d][3];
    if (a>0) an-=o[a-1][d][3];
    if (d>0) an-=o[c][d-1][3];
    if (a>0&&d>0) an+=o[a-1][d-1][3];

    an+=o[a][d][0];
    if (b>0) an-=o[a][b-1][0];
    if (a>0) an-=o[a-1][d][0];
    if (a>0&&b>0) an+=o[a-1][b-1][0];

    an+=o[c][d][1];
    if (b>0) an-=o[c][b-1][1];
    if (c>0) an-=o[c-1][d][1];
    if (b>0&&c>0) an+=o[c-1][b-1][1];

    cout<<an<<endl;
  }
}

Measured memory_bytes: 88448
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
ll in(){ ll x; cin >> x; return x; }
vector<ll> in(size_t n){ vector<ll> v(n); each(x, v) cin >> x; return v; }
/* ]]] */

int main(){
  ll a, b;
  cin >> a >> b;
  if (a <= 0 && 0 <= b){
    cout << "Zero\n";
  }
  else if (0 < a){
    cout << "Positive\n";
  }
  else if ((b - a + 1) & 1){
    cout << "Negative\n";
  }
  else {
    cout << "Positive\n";
  }
}



Measured memory_bytes: 256
#include <stdio.h>
#define MAX 10000
#define NIL -1

void preParse(int);
void inParse(int);
void postParse(int);

struct node{
  int parent;
  int left;
  int right;
};
struct node T[MAX];

int main(){
  int n, i, v, r, l, root;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }
  for(i = 0; i < n; i++){
  scanf("%d %d %d", &v, &l, &r);
  T[v].left = l;
  T[v].right = r;
  if(l != NIL) T[l].parent = v;
  if(r != NIL) T[r].parent = v;
  }
  for(i = 0; i < n; i++) if(T[i].parent == NIL) root = i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
  
  return 0;
}
void preParse(int u){
  if(u == NIL) return;
  printf(" %d", u);
  preParse(T[u].left);
  preParse(T[u].right);
}
void inParse(int u){
  if(u == NIL) return;
  inParse(T[u].left);
  printf(" %d", u);
  inParse(T[u].right);
}
void postParse(int u){
  if(u == NIL) return ;
  postParse(T[u].left);
  postParse(T[u].right);
  printf(" %d", u);
}



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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pt;
vector<ll> x, y;
vector<pt> points;

bool inside(pt a, pt b, pt p) {
  if (p.x < a.x) return false;
  if (p.x > b.x) return false;
  if (p.y < a.y) return false;
  if (p.y > b.y) return false;
  return true;
}

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  x.resize(n);
  y.resize(n);
  points.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &x[i], &y[i]);
    points[i] = pt(x[i], y[i]);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  ll result = LLONG_MAX;
  for (int i1 = 0; i1 < n; i1++) {
    for (int i2 = i1; i2 < n; i2++) {
      for (int j1 = 0; j1 < n; j1++) {
        for (int j2 = j1; j2 < n; j2++) {
          int counter = 0;
          for (int l = 0; l < n; l++) {
            if (inside(pt(x[i1], y[j1]), pt(x[i2], y[j2]), points[l])) {
              counter++;
            }
          }
          if (counter >= k) {
            result = min(result, (x[i2] - x[i1]) * (y[j2] - y[j1]));
          }
        }
      }
    }
  }
  printf("%lld\n", result);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6;
int aa[N+2],bb[N+2],cc[N+2],dd[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int a,b;cin>>a>>b;
  for(int i=1;i<=1000000;i++)
  {
    int ta=floor((i*8.0)/(100.0));
    int tb=floor((i*10.0)/(100.0));

    //cout<<ta<<" "<<tb<<endl;

    if(ta==a&&tb==b)cout<<i<<endl,exit(0);
  }
  cout<<-1<<endl;
  return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	stack<char> st;
	for(int i=0;i<s.size();i++){
		if(s[i]=='S')
			st.emplace(s[i]);
		else{
			if(st.size()&&st.top()=='S')
				st.pop();
			else
				st.emplace('T');
		}
	}
	cout<<st.size()<<endl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll mod = 1e9 + 7;
    string s;
    cin >> s;
    ll sl = len(s);
    vector<vector<ll>> dp(sl + 1, vector<ll>(2, 0));
    dp[0][0] = 1;
    rep(i, sl) {
        if (s[i] == '1') {
            dp[i + 1][0] = (dp[i][0] * 2) % mod;
            dp[i + 1][1] = (dp[i][0] + dp[i][1] * 3) % mod;
        }
        else {
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = (dp[i][1] * 3) % mod;
        }
    }
    cout << ((dp[sl][0] + dp[sl][1]) % mod) << endl;
    return 0;
}


Measured memory_bytes: 5840
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ceel(x, y) ((x) / (y) + !((x) % (y) == 0))
#define ff first
#define ss second
#define endl '\n'
#define print(v) for(auto x : v) cout << x << ' '; cout << endl;
#define debug(v) cout << #v << " = "; print(v);
#define printmp(v) for(auto x : v) cout << x.first << ' ' << x.second << endl; cout << endl;
using namespace std;
typedef long long int ll;
typedef long double ld;
void solve(){
   int n , l;
   cin >> n >> l;
   vector <string> str;
   string temp;
   for(int i = 0 ; i < n ; i++){
       cin >> temp;
       str.pb(temp);
   }
   sort(str.begin() , str.end());
   string ans;
   for(string s : str){
       ans += s;
   }
   cout << ans << endl;
}
int main(){
    fastio;
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

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

int main() { 
  int A, B;
  cin >> A >> B;
  
  int coin = 0;
  
  for (int i = 0; i < 2; i++) {
    if (A >= B) {
      coin += A;
      A--;
    }
    else {
      coin += B;
      B--;
    }
  }
  cout << coin << endl;
}

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

int main() {
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0 ; i <= s.size() ; i++){
		string x = s.substr(0,i);
		string y = s.substr(i);
		if( y.size() && y[0] == '0' ) continue;
		if( y.size() == 0 ) y = "0";
		if( x.size() == 0 ) x = "0";
		  
		int X = atoi(x.c_str());
		int Y = atoi(y.c_str());
		if( (X+Y) % 2 != 0 ) continue;
		int a = (X+Y) / 2;
		int b = (Y-X) / 2;
		if( a < 0 || b < 0 ) continue;
		ans ++;
	}
	cout << ans << endl;
	
	
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int a, b, c;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b >> c;
	cout << (a * b) / 2 << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.List;
import java.util.Scanner;
import java.util.Vector;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		long a[][] = new long[n][n];
		for (int i=0;i<n;i++)
			for (int j=0;j<n;j++)
				a[i][j] = sc.nextLong();
		
		long r[][] = Pow(n,a,k,1000000007);
		System.out.println(Sum(n,r,1000000007));
	}

	private static long Sum(int n, long[][] a, int mod) {
		long sum = 0;
		for (int i=0;i<n;i++)
			for (int j=0;j<n;j++)
				sum = (sum + a[i][j]) % mod;
		return sum;
	}

	private static long[][] Pow(int n, long[][] a, long k, int mod) {
		if (k == 0) return I(n);
		else {
			long r[][] = Pow(n,a,k/2,mod);
			r = Mul(n,r,r,mod);
			if (k%2==1) r = Mul(n,r,a,mod);
			return r;
		}
		
	}

	private static long[][] Mul(int n, long[][] a, long[][] b,int mod) {
		long r[][] = new long[n][n];
		for (int i=0;i<n;i++)
			for (int j=0;j<n;j++) {
				r[i][j] = 0;
				for (int k=0;k<n;k++)
					r[i][j]=(r[i][j]+(a[i][k]*b[k][j])%mod)%mod;
			}
					
		return r;
	}

	private static long[][] I(int n) {
		long r[][] = new long[n][n];
		for (int i=0;i<n;i++)
			r[i][i] = 1;
		return r;
	}

}


Measured memory_bytes: 27904
import java.util.Scanner;

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

	String b = scan.next();
	if(b.charAt(0) == 'A'){
	    System.out.println('T');
	}else if(b.charAt(0) == 'C'){
	    System.out.println('G');
	}else if(b.charAt(0) == 'G'){
	    System.out.println('C');
	}else{
	    System.out.println('A');
	}
    }
}
		


Measured memory_bytes: 21588
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
#include <boost/multiprecision/integer.hpp>


template<typename T>
void invec(vector<T> &A){rep(i, 0, A.size()) cin >> A[i];}

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

int N; cin >> N;
VI A(N); invec(A);

i64 ans = 0;
rep(digit, 0, (int)log2(*max_element(ALL(A)))+ 1){
    i64 cnt1 = 0;
    rep(i, 0, N)
        if (A[i] & (1LL<<digit)) ++cnt1;
    (ans += (1LL<<digit) %MOD * cnt1 %MOD * (N - cnt1) %MOD) %= MOD;
}
cout << ans << endl;

}
// 書いて考える．場合分け
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 2560
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007

using namespace std;

typedef long long ll;


int add(int a, int b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

ll n, v[3002], dp[3002][3002];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    for(int i = n; i >= 1; --i)
        for(int j = i+1; j <= n+1; ++j)
            dp[i][j] = max(v[i] - dp[i+1][j], v[j-1] - dp[i][j-1]);
    cout << dp[1][n+1];
    return 0;
}


Measured memory_bytes: 70016
import math
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from heapq import heapify, heappop, heappush
from itertools import chain, combinations, permutations, product
from typing import List, Dict

# import numpy as np

sys.setrecursionlimit(10**5 + 1)
input = sys.stdin.readline
write = sys.stdout.write


def read_item(cls=int):
    return cls(input())


def read_n_item(cls=int) -> list:
    return [cls(s) for s in input().split()]


def list2d(row, col, init_val=0) -> List[list]:
    return [[init_val] * col for _ in range(row)]


MOD = 10**9 + 7
# MOD = 998244353


N, M = read_n_item()
if N & 1:
    for i in range(1, M+1):
        print(i, N-i+1)
else:
    used = [False] * (N+1)
    left, right = 1, N
    cnt = 0
    for i in range(1, N//2+1):
        if cnt == M:
            break
        l_d = right-left
        r_d = left+N-right
        if not used[right-left] and not used[left+N-right] and l_d != r_d:
            used[right-left] = used[left+N-right] = True
            print(left, right)
            cnt += 1
            left += 1
            right -= 1
        else:
            left += 1



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

int main() {
	int a, b;
	cin >> a >> b;
	
	if (a == b) {
		cout << 2*a << endl;
	}
	else {
		cout << 2 * max({a, b}) - 1 << endl;
	}
}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
char next(char c) {
	if (isdigit(c)) {
		if (c == '9')return '0';
		else return c + 1;
	}
	return c;
}
char form(char c) {
	if (isdigit(c)) {
		if (c == '0')return '9';
		return c - 1;
	}
	return c;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	REP(j, n) {
		string v, s;
		cin >> v >> s;
		reverse(ALL(v));
		REP(i, v.size()) {
			if (v[i] == 'C') {
				char c = s[0];
				REP(k, s.size() - 1) {
					s[k] = s[k + 1];
				}
				s[s.size() - 1] = c;
			}
			else if (v[i] == 'J') {
				char c = s[s.size() - 1];
				RREP(k, s.size() - 1) {
					s[k + 1] = s[k];
				}
				s[0] = c;
			}
			else if (v[i] == 'E') {
				int c = s.size() / 2;
				string tmp = s.substr(0, c);
				REP(k, c) {
					s[k] = s[s.size() - c + k];
				}
				REP(k, c) {
					s[s.size() - c + k] = tmp[k];
				}
			}
			else if (v[i] == 'A') {
				REP(k, s.size() / 2) {
					swap(s[k], s[s.size() - 1 - k]);
				}
			}
			else if (v[i] == 'P') {
				REP(k, s.size()) {
					s[k] = form(s[k]);
				}
			}
			else if (v[i] == 'M') {
				REP(k, s.size()) {
					s[k] = next(s[k]);
				}
			}
		}

		cout << s << endl;

	}
}

Measured memory_bytes: 3232
#include<iostream>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  
  int sum = 0;
  
  for (int i=0; i < N; i++) {
    int left;
    int right;
    cin >> left >> right;
    sum += (right - left + 1);
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	#define IOS ios::sync_with_stdio(false), cin.tie(0)
	#define REP(i, n) for (int i = 0; i < n; i++)
	#define FOR(i, a, b) for (int i = a; i < b; i++)
	#define ALL(x) (x).begin(), (x).end()
	#define dump(x) cout << (x) << endl
	#define LMAX 9223372036854775807LL
	#define LMIN -9223372036854775807LL

	using ll = long long;
	template<typename T>
	using vec = vector<T>;
	using P = pair<ll, ll>;

	template <typename A, size_t N, typename T>
	void Fill(A (&array)[N], const T &val){
		fill((T *)array, (T *)(array + N), val);
	}
	
	const ll INF = 1e16;
	const ll MOD = 1e9 + 7;

	//int dx[4] = {1,0,-1,0};
	//int dy[4] = {0,1,0,-1};
	//ll pas[51][52];
	struct UnionFind {
		vector<int> data;
		UnionFind(int size) : data(size, -1) {}
		void unionSet(int x, int y) {
			x = root(x), y = root(y);
			if (x != y) {
				if (data[y] < data[x])swap(x, y);
				data[x] += data[y]; data[y] = x;
			}
		}
		bool findSet(int x, int y) {
			return root(x) == root(y);
		}
		int root(int x) {
			return data[x] < 0 ? x : data[x] = root(data[x]);
		}
		int size(int x) {
			return -data[root(x)];
		}
	};

	signed main(){
		IOS;
		ll n, k, l;
		cin >> n >> k >> l;
		UnionFind ufa(n + 1), ufb(n + 1);
		REP(i, k){
			int x, y;
			cin >> x >> y;
			ufa.unionSet(x, y);
		}
		REP(i, l){
			int x ,y;
			cin >> x >> y;
			ufb.unionSet(x, y);
		}
		map<P,ll> mp;
		for(int i = 1;i <= n;i++){
			mp[P(ufa.root(i),ufb.root(i))]++;
		}
		for(int i = 1;i <= n;i++){
			if(i != 1)cout << " ";
			cout << mp[P(ufa.root(i),ufb.root(i))];
		}
		cout << endl;
	}

Measured memory_bytes: 13568
N,M = map(int,input().split())
p = [i for i in range(N)]#parent
g = [[i] for i in range(N)]#group
for _ in range(M):
  x,y,z = map(int,input().split())
  x,y = p[x-1],p[y-1]
  if x==y:
    continue
  if len(g[x])<len(g[y]):
    x,y = y,x
  g[x] += g[y]
  for z in g[y]:
    p[z] = x
  g[y] = []
print(len(set(p)))

Measured memory_bytes: 26612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string x = Console.ReadLine();
                x = " " + x;
                string y = Console.ReadLine();
                y = " " + y;

                int lenX = x.Length;
                int lenY = y.Length;

                int[,] lcs = new int[lenX, lenY];
                int max = int.MinValue;

                for (int j = 1; j < lenX; j++)
                {
                    for (int k = 1; k < lenY; k++)
                    {
                        if (x[j] == y[k]) lcs[j, k] = lcs[j - 1, k - 1] + 1;
                        else lcs[j, k] = Math.Max(lcs[j - 1, k], lcs[j, k - 1]);

                        if (max < lcs[j, k]) max = lcs[j, k];
                    }
                }
                sb.AppendLine(max.ToString());
            }
            Console.Write(sb);
        }
    }
}

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

using namespace std;

#define PI 3.14159265358979323846264338327950L

long long MOD = 1e9+7;

int main(void){

    long long N;
    long long U=1,S0=1,S9=1,S09=1,ans=0;

    cin>>N;

    for(long long n=0;n<N;n++){
        U=U*10;
        U=U%MOD;

        S0=S0*9;
        S0=S0%MOD;

        S9=S9*9;
        S9=S9%MOD;

        S09=S09*8;
        S09=S09%MOD;
    }

    ans=U%MOD;
    ans=(ans-S0)%MOD;
    ans=(ans-S9)%MOD;
    ans=(ans+S09)%MOD;

    if(ans<0){
        ans=ans+MOD;
    }

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3624
// https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_e

#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);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  V<string> ss(3);
  rep(i, 3) cin >> ss[i];

  ll max_len = max(max(ss[0].size(), ss[1].size()), ss[2].size());

  ll res = INF;

  sort(all(ss));

  do {
    // 左端の順番が ss の順番であるとする、順に a, b, c とする。
    // oks[i][j][k]: s[i] と s[j] について、オフセットが k の時重なるか
    V<V<V<bool>>> oks(3, V<V<bool>>(3, V<bool>(max_len)));

    // ss[i] と ss[j] の重なりについて、 i < j について考える。 ss[j]
    // のオフセットは左端の条件より正となる
    rep(j, 3) rep(i, j) rep(k, ss[i].size()) {
      bool ok = true;

      rep(ji, ss[j].size()) {
        ll ii = k + ji;
        unless(ii < ss[i].size()) break;
        if (ss[i][ii] == '?' || ss[j][ji] == '?') continue;
        if (ss[i][ii] != ss[j][ji]) ok = false;
      }

      oks[i][j][k] = ok;
    }

    auto is_ok = [&](ll i, ll j, ll k) {
      if (k >= ss[i].size()) return true;
      bool res = oks[i][j][k];
      return res;
    };

    rep(offset2, max_len + 1) rep(offset3, max_len + 1) {
      if (!is_ok(0, 1, offset2)) continue;
      if (!is_ok(1, 2, offset3)) continue;
      if (!is_ok(0, 2, offset2 + offset3)) continue;

      ll r = ss[0].size();
      chmax<ll>(r, offset2 + ss[1].size());
      chmax<ll>(r, offset2 + offset3 + ss[2].size());

      chmin(res, r);
    }
  } while (next_permutation(all(ss)));

  cout << res << endl;
}

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

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

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

  return 0;
}
#endif

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;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pii pair<int, int>
#define mp make_pair
const int maxn = 1e3 + 10;
const int inf = 0x3f3f3f3f;
int n, m, sx, sy, tx, ty;
int dis[maxn][maxn];
char s[maxn][maxn];
deque<pii> q;
const int dxx[] = { 0, -1, 0, 1 };
const int dyy[] = { 1, 0, -1, 0 };

int main() {
	scanf("%d%d", &n, &m);
	scanf("%d%d", &sx, &sy);
	scanf("%d%d", &tx, &ty);
	for (int i = 1; i <= n; ++i)
		scanf("%s", s[i] + 1);
	memset(dis, 0x3f, sizeof(dis));
	dis[sx][sy] = 0;
	q.push_back(mp(sx, sy));
	while (!q.empty()) {
		int nx, ny;
		pii u = q.front(); q.pop_front(); 
		for (int d = 0; d < 4; ++d) {
			nx = u.first + dxx[d];
			ny = u.second + dyy[d];
			if (s[nx][ny] == '.' && dis[nx][ny] > dis[u.first][u.second]) {
				dis[nx][ny] = dis[u.first][u.second];
				q.push_front(mp(nx, ny));
			}
		}
		for (int dx = -2; dx <= 2; ++dx)
			for (int dy = -2; dy <= 2; ++dy) {
				nx = u.first + dx;
				ny = u.second + dy;
				if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && s[nx][ny] == '.' && dis[nx][ny] > dis[u.first][u.second] + 1) {
					dis[nx][ny] = dis[u.first][u.second] + 1;
					q.push_back(mp(nx, ny));
				}
			}
	}
	if (dis[tx][ty] == inf) puts("-1");
	else printf("%d\n", dis[tx][ty]);
	return 0;
}

Measured memory_bytes: 8856
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>

using namespace std;

int main() {
	int alice = 0, bob = 0;
	int N; cin >> N;
	vector<int> cards(N);

	for (int i = 0; i < N; i++) {
		cin >> cards.at(i);
	}

	//カードを並び替え
	sort(cards.begin(), cards.end());
	reverse(cards.begin(), cards.end());


	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			alice += cards[i];
		}
		else {
			bob += cards[i];
		}
	}

	cout << alice - bob << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n, k = inm()
a = inl()
if len(set(a)) <= 2:
    print(0)
else:
    b = {}
    for i in a:
        if i not in b:
            b[i] = 0
        b[i] += 1
    b = list(map(lambda x: x[1], sorted(b.items(), key=lambda x: x[1])))
    print(sum(b[:len(set(a))-k]))

Measured memory_bytes: 49640
#include <bits/stdc++.h>
#define INL inline
#define REG register
#define DB double
#define LDB long double
#define ULL unsigned long long
#define LL long long

#define RPT(i,x,y) for (REG int i=(x);i<(y);i++)
#define DRPT(i,x,y) for (REG int i=(x);i>(y);i--)
#define MST(a,b) memset((a),(b),sizeof(a))
#define MRK() cout<<"Mark"<<endl;
#define WRT(x) cout<<#x<<" = "<<(x)<<endl;

#define MAXN 520
#define MAXM 10000
#define MOD 998244353
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-5

#define _ 0
using namespace std;

char c[MAXN][MAXN];
char c1[MAXN][MAXN];
char c2[MAXN][MAXN];


int n,m;
int main()
{
	scanf("%d%d",&n,&m); 
	RPT(i,0,n)
		cin>>c[i];
	RPT(i,0,n)
	{
		RPT(j,0,m)
			if (j==0 || (i&1 && j!=m-1) || c[i][j]=='#')
				cout<<'#';
			else
				cout<<'.';
		cout<<endl;
	}
	cout<<endl;
	RPT(i,0,n)
	{
		RPT(j,0,m)
			if (j==m-1 || (!(i&1) && j!=0) || c[i][j]=='#')
				cout<<'#';
			else
				cout<<'.';
		cout<<endl;
	}
	return ~~(0^_^0);
}



Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int diviser(int n) {
    int res = 0;
    for (int i=1; i*i<=n; i++) {
        if (n%i == 0) {
            res++;
            if (n/i != i) res++;
        }
    }
    return res;
}

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

    int ans = 0;
    for (int i=1; i<=n; i+=2) {
        if (diviser(i) == 8) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256