akhauriyash/Code-Regression huggingface dataset:
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"3 2 6"# => r#"1"#,
r#"3 1 3"# => r#"0"#,
r#"5 10 1"# => r#"4"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        w: isize,
        a: isize,
        b: isize,
    }

    let (a, b) = if b < a { (b, a) } else { (a, b) };
    if b - w - a < 0 { 0 } else { b - w - a }.to_string()
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int n;
int a[5][5];
int b[5][5];
bool check()
{
	for(int i=1;i<=3;i++)
	{
		if(b[i][1]&&b[i][2]&&b[i][3])
			return true;
		if(b[1][i]&&b[2][i]&&b[3][i])
			return true;
	}
	if(b[1][1]&&b[2][2]&&b[3][3]) return true;	
	if(b[1][3]&&b[2][2]&&b[1][3]) return true;	
	return false;
}
signed main()
{
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
			scanf("%d",&a[i][j]);
	int n;
	scanf("%d",&n);
	for(int t=1;t<=n;t++)
	{
		int x;
		scanf("%d",&x);
		for(int i=1;i<=3;i++)
			for(int j=1;j<=3;j++)
				if(a[i][j]==x)
					b[i][j]=1;
	}
		if(check())
		{
			printf("Yes");
			return 0;
		}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;

  rep(i, 9) {
    rep(j, 9) {
      if ((i+1) * (j+1) == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  puts("No");
}


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

using namespace std;

typedef long long ll;

int n, k;
int p[maxn], c[maxn];
ll ans = -1e18;

bool vis[maxn];
vector<ll> v;
ll sum;

void dfs(register int i){
	if(vis[i]){
		register int x = k % v.size();
		//ll tot = 0, mx = -1e18;
		register int len = v.size();
		for(register int j = 0;j < len;j++) v.push_back(v[j]);
		/*for(register int j = 0;j < x;j++) tot += v[j];
		mx = max(mx, tot);
		for(register int j = x;j < v.size();j++){
			tot += v[j], tot -= v[j - x];
			mx = max(mx, tot);
		}
		ans = max(ans, mx + k / len * sum);*/
		for(register int j = 1;j < v.size();j++) v[j] += v[j - 1];
		for(register int j = 0;j < v.size();j++){
			for(register int l = max(0, j - k);l < j;l++){
				ans = max(ans, v[j] - v[l]);
				ans = max(ans, v[j] - v[l] + (k - (j - l)) / len * sum);
			}
			if(j + 1 <= k) ans = max(ans, v[j]);
			if(j + 1 <= k) ans = max(ans, v[j] + (k - (j + 1)) / len * sum);
		}
		v.clear(), sum = 0;
	}else{
		vis[i] = true;
		sum += c[i], v.push_back(c[i]);
		dfs(p[i]);
	}
}

int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1;i <= n;i++) scanf("%d", &p[i]);
	for(int i = 1;i <= n;i++) scanf("%d", &c[i]);
	for(int i = 1;i <= n;i++) if(!vis[i]) dfs(i);
	printf("%lld", ans);
}

Measured memory_bytes: 4520
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int mod=1e9+7;
const int Max=1010;
int n,ans=1,tot;
int sum[Max],zhi[Max];

inline void pre()
{
	zhi[++tot]=2;
	for(int i=3;i<=1000;++i)
	{
	  int x=0;
	  for(int j=2;j<=(int)sqrt(i);++j) if(!(i%j)){x=1;break;}
	  if(!x) zhi[++tot]=i;
	}
}

signed main()
{
	pre();
	cin>>n;
	for(int i=2;i<=n;i++)
	{
	  int x=i;
	  for(int j=1;zhi[j]<=x&&x!=1&&j<=tot;j++)
	  	while(!(x%zhi[j])) x/=zhi[j],sum[j]++;
	}
	for(int i=1;i<=tot;i++)
	  if(sum[i]) ans=(ans%mod*(sum[i]+1)%mod)%mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
vl g[MAX_N];
vl visited(MAX_N, 0);
vl ANS(MAX_N, 0);
void bfs(ll i) {
    p = 0;
    queue<ll> q;
    q.push(i);
    vl d(n, -1);
    d[i] = p;
    while (!q.empty()) {
    	queue<ll> q2;
        p++;
        while(!q.empty()){
        int v = q.front();
        q.pop();
        for (ll x : g[v]) {
            if (d[x] == -1) {
                d[x] = p;
                q2.push(x);
            }
        }
        }
        q=q2;
    }

    rep(j, n) { ANS[d[j]]++;}
}
int main() {
    cin >> n >> x >> y;
    rep(i, n - 1) {
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);

    rep(i, n) { bfs(i); }

    rep(i,n){
        if (i != 0) cout << ANS[i]/2 << endl;
    }
}

Measured memory_bytes: 19840
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n,p=map(int,input().split())
a=list(map(int,input().split()))
o=0
e=0
for i in a:
    if i%2==0:
        e+=1
    else:
        o+=1
ans=2**e
cnt=0
if p==0:
    for i in range(0,o+1,2):
        cnt+=comb(o,i)
    print(ans*cnt)
else:
    for i in range(1,o+1,2):
        cnt+=comb(o,i)
    print(ans*cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using P = pair<string,int>;

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

    vector<P> v(n);
    rep(i,n){
        string s;
        int p;
        cin >>s >>p;
        v[i] = {s,-p};
    }

    vector<P> s(v);
    sort(all(s));
    rep(i,n){
        int a = 0;
        while(s[i] != v[a]) ++a;
        cout << a+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>


using namespace std;


int main(void){
  
  int N;
  string ans="No";
  
  vector<vector<int>> A(3,vector<int>(3)),bingo(3,vector<int>(3));

  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> A.at(i).at(j);
      bingo.at(i).at(j)=0;
     
    }
  }




  cin >> N;

  vector<int> b;

  for(int i =0; i<N;i++){
    int tmp;
    cin >> tmp;
    b.push_back(tmp);
  }

  for(int k=0; k<N;k++){
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      if(b.at(k)==A.at(i).at(j))
      bingo.at(i).at(j)=1;
    }
  }
  }

  for(int i=0;i<3;i++){
      if( bingo.at(i).at(0)==1&&bingo.at(i).at(1)==1&&bingo.at(i).at(2)==1){
        ans="Yes";
      } 
      if( bingo.at(0).at(i)==1&&bingo.at(1).at(i)==1&&bingo.at(2).at(i)==1){
        ans="Yes";
      }      
  }

     if( bingo.at(0).at(0)==1&&bingo.at(1).at(1)==1&&bingo.at(2).at(2)==1){
        ans="Yes";
      } 

     if( bingo.at(0).at(2)==1&&bingo.at(1).at(1)==1&&bingo.at(2).at(0)==1){
        ans="Yes";
      } 

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc153/tasks/abc153_e

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

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#if 0
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(a) if (DEBUG) REP(_i, a.size()) DUMP(a[_i]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(a)
#endif

const int H_MAX = 1e4;
const int N_MAX = 1e3;
const int A_I_MAX = 1e4;
const int B_I_MAX = 1e4;
const int INF = 1e9;

int H, N;
vector<int> A;
vector<int> B;

int ax = 0;
vector<int> dp;

int main() {
  cin >> H >> N;
  A = vector<int>(N);
  B = vector<int>(N);
  REP(i, N) {
    cin >> A[i] >> B[i];
    ax = max(ax, A[i]);
  }

  dp = vector<int>(H + ax + 1, INF);
  dp[0] = 0;
  REP(i, N) {
    FOR(j, A[i], H + A[i]) {
      dp[j] = min(dp[j], dp[j - A[i]] + B[i]);
    }
    DUMP(dp);
  }

  int ans = INF;
  FOR(j, H, H + ax) ans = min(ans, dp[j]);
  cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve():
    S = input()
    s1 = (S[0] == S[1] and S[1] != S[2] and S[2] == S[3])
    s2 = (S[0] == S[2] and S[2] != S[1] and S[1] == S[3])
    s3 = (S[0] == S[3] and S[3] != S[1] and S[1] == S[2])
    return 'Yes' if (s1 or s2 or s3) else 'No'


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
N = int(input())
ary = list(map(int, input().split(' ')))

def insertion_sort(array, n):
    print_out(array)
    for i in range(1,n):
        v = array[i]
        j = i-1
        while(j>=0 and array[j] > v):
            array[j+1] = array[j]
            j -= 1
        array[j+1] = v
        print_out(array)

def print_out(array):
    array_str = [str(i) for i in array]
    print(" ".join(array_str))

insertion_sort(ary, N)



Measured memory_bytes: 5604
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

using ld = long double;
ld a, b, x;

int main() {
  cin >> a >> b >> x;
  if (x < a * a * b / 2.0) {
    ld c = 2.0 * x / (a * b);
    ld rad = atan(b / c);
    cout << setprecision(20) << fixed << rad * 180.0 / M_PI;
  } else {
    x = (a * a * b) - x;
    ld c = 2.0 * x / (a * a);
    ld rad = atan(c / a);
    cout << setprecision(20) << fixed << rad * 180.0 / M_PI;
  }
}


Measured memory_bytes: 3780
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
for i in range(1, n):
    mincost = 10 ** 9
    for j in range(1, min(i+1, k+1)):
        mincost = min(mincost, dp[i-j] + abs(h[i]-h[i-j]))
    dp[i] = mincost
print(dp[n-1])

Measured memory_bytes: 52448
import heapq
n,m = map(int,input().split())
a = list(map(int,input().split()))

for i in range(len(a)):
  a[i] *= -1

heapq.heapify(a)

for i in range(m):
  tmp = heapq.heappop(a)
  heapq.heappush(a,tmp/2)
  
ans = -1 * sum(map(int,a))

print(ans)

Measured memory_bytes: 14180
#include <stdio.h>
#define MAX 100000
int Parent(int i){
    return i/2;
}
int Left(int i){
    return 2*i;
}
int Right(int i){
    return 2*i+1;
}

int main(){
    int CompBT[MAX];
    int i,n;
    
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&CompBT[i]);
    }
    for(i=1;i<=n;i++){
        printf("node %d: key = %d, ",i,CompBT[i]);
        if(Parent(i)>=1) printf("parent key = %d, ",CompBT[Parent(i)]);
        if(Left(i)<=n) printf("left key = %d, ",CompBT[Left(i)]);
        if(Right(i)<=n) printf("right key = %d, ",CompBT[Right(i)]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 604
import java.util.Scanner;

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

    while (in.hasNext()) {
      int N = in.nextInt();
      int countEightDivisor = 0;

      for (int i = 1; i <= N; i += 2) {
        int divisorCount = 0;

        for (int d = 1; d <= i; ++d) {
          if (i % d == 0) {
            ++divisorCount;
          }
        }

        if (divisorCount == 8) {
          ++countEightDivisor;
        }
      }

      System.out.println(countEightDivisor);
    }
  }
}

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

using namespace std;

int main() {
    unsigned int h, w;
    cin >> h >> w;

    char a[105][105];
    vector<bool> row(h, false);
    vector<bool> col(w, false);

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
            if (a[i][j] == '#') {
                row[i] = true;
                col[j] = true;
            }
        }
    }

    for (int i = 0; i < h; i++) {
        if (row[i]) {
            for (int j = 0; j < w; j++) {
                if (col[j]) cout << a[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import collections

def prime_factorize(x):
    factor = []
    while x % 2 == 0:
        x //= 2
        factor.append(2)
    div = 3
    while div ** 2 <= x:
        if x % div == 0:
            x //= div
            factor.append(div)
        else:
            div += 2
    if x != 1:
        factor.append(x)
    return collections.Counter(factor)

n = int(input())
ans = 0
for x in prime_factorize(n).values():
    tmp = 0
    check = 1
    i = 2
    while check <= x:
        check += i
        tmp += 1
        i += 1
    ans += tmp
print(ans)

Measured memory_bytes: 9468
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=200000+19;
const int p=1e9+7;
const int I2=(p+1)/2;

int Pow(int a,int b){
	int res=1;
	for (;b;b>>=1,a=1ll*a*a%p) if (b&1) res=1ll*res*a%p;
	return res;
}

struct Edge{
	int y,nxt;
} E[N];
Vi V[N];
int A[N],fa[N],d[N],las[N],ed[N],c[N],fac[N],inv[N];
int n,res=1;

int C(int n,int m){
	return 1ll*fac[n]*inv[m]%p*inv[n-m]%p;
}
int getf(int x){
	return fa[x]==x?x:fa[x]=getf(fa[x]);
}
void Union(int x,int y){
	x=getf(x),y=getf(y);
	if (x!=y){
		fa[x]=y;
		d[y]=min(d[y],d[x]);
		E[ed[y]].nxt=las[x];
		ed[y]=ed[x];
	}
}

namespace Tree{
	#define forall for (int i=las[x],y;~i;i=E[i].nxt) if (y=E[i].y)
	int pa[N],top[N],dep[N],fa[N],vis[N],mx[N],len,res,tmp,u,v;
	Vi V[N];
	int getf(int x){
		return pa[x]==x?x:pa[x]=getf(pa[x]);
	}
	void Union(int x,int y){
		x=getf(x),y=getf(y);
		if (x!=y) pa[x]=y;
	}
	void dfs(int x){
		For(i,0,V[x].size()){
			int y=V[x][i];
			if (y==fa[x]) continue;
			fa[y]=x;
			dep[y]=dep[x]+1;
			dfs(y);
		}
	}
	bool Dfs(int x){
		if (vis[x]){
			top[x]=x;
		} else{
			if (V[x].size()>1) return 0;
		}
		mx[vis[top[x]]]=max(mx[vis[top[x]]],dep[x]-dep[top[x]]);
		For(i,0,V[x].size()){
			int y=V[x][i];
			if (y==fa[x]) continue;
			top[y]=top[x];
			if (!Dfs(y)) return 0;
		}
		return 1;
	}
	int Work(int x){
		forall pa[y]=y;
		forall
			if (getf(y)!=getf(A[y])){
				Union(y,A[y]);
				V[A[y]].pb(y);
			} else{
				u=y,v=A[y];
			}
		dfs(u);
		len=0;
		for (int i=v;i;i=fa[i]){
			vis[i]=++len;
			mx[len]=0;
		}
		if (!Dfs(u)) return 0;
		For(i,len+1,2*len+1) mx[i]=mx[i-len];
		res=1;tmp=0;
		For(i,1,2*len+1){
			if (i>len&&mx[i]){
				res=1ll*res*(mx[i]>tmp?0:mx[i]==tmp?1:2)%p;
			}
			if (mx[i]) tmp=0;
			tmp++;
		}
		return res;
	}
}

int main(){
	fac[0]=1;
	For(i,1,N) fac[i]=1ll*fac[i-1]*i%p;
	inv[N-1]=Pow(fac[N-1],p-2);
	for (int i=N-1;i;i--) inv[i-1]=1ll*inv[i]*i%p;
	n=IN();
	For(i,1,n+1){
		A[i]=IN();
		fa[i]=i;
		if (++d[A[i]]>2){
			puts("0");
			return 0;
		}
		las[i]=ed[i]=i;
		E[i]=(Edge){i,-1};
	}
	For(i,1,n+1){
		Union(i,A[i]);
	}
	For(x,1,n+1)
		if (fa[x]==x){
			if (d[x]==1){
				int sz=0;
				for (int i=las[x];~i;i=E[i].nxt) sz++;
				c[sz]++;
			} else{
				res=1ll*res*Tree::Work(x)%p;
			}
		}
	For(i,1,n+1)
		if (c[i]){
			int sum=0;
			for (int k=0;2*k<=c[i];k++){
				int tmp;
				tmp=1ll*C(c[i],2*k)*C(2*k,k)%p*fac[k]%p*Pow(1ll*i*I2%p,k)%p;
				if (i!=1&&i%2!=0) tmp=1ll*tmp*Pow(2,c[i]-2*k)%p;
				sum=(sum+tmp)%p;
			}
			res=1ll*res*sum%p;
		}
	printf("%d\n",res);
}

Measured memory_bytes: 29184
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
#include <stack>
//#include <atcoder/scc>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
//using namespace atcoder;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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

lli gcd2(lli x, lli y)
{
    lli t;
    while (y != 0)
        t = x % y, x = y, y = t;
    return (x);
}

lli lcm2(lli x, lli y)
{
    lli xy = x * y;
    if (xy < 0)
        xy = -xy;
    return (xy / gcd2(x, y));
}
lli m = 1e9 + 7;
int main(void)
{
    int X, A, B;
    cin >> X >> A >> B;
    if (B - A <= X && B - A > 0)
    {
        cout << "safe" << endl;
    }
    else if (B - A <= X && B - A <= 0)
    {
        cout << "delicious" << endl;
    }
    else
    {
        cout << "dangerous" << endl;
    }
    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std; 
int a[110];
int main()
{
	int n,count=0,t,s;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
	{
		if(a[i]%2==0)
			count++;
	}
	t=pow(3,n);
	s=pow(2,count);
	cout<<t-s<<endl;
} 


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

typedef struct{
  double x;
  double y;
}point;

void koch(int ,point ,point);

int main(){
  point a,b;
  int n;
  scanf("%d",&n);
  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;
  printf("%0.8f %0.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%0.8f %0.8f\n",b.x,b.y);
  return 0;
}
void koch(int n,point a,point b){
  if(n==0){
    return;
  }
  point s,t,u;
  double rad=60.0*M_PI/180.0;
  s.x=((2.0*a.x)+(1.0*b.x))/3.0;
  s.y=((2.0*a.y)+(1.0*b.y))/3.0;
  t.x=((1.0*a.x)+(2.0*b.x))/3.0;
  t.y=((1.0*a.y)+(2.0*b.y))/3.0;
  u.x=(t.x-s.x)*cos(rad)-(t.y-s.y)*sin(rad)+s.x;
  u.y=(t.x-s.x)*sin(rad)+(t.y-s.y)*cos(rad)+s.y;
  koch(n-1,a,s);
  printf("%0.8f %0.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%0.8f %0.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%0.8f %0.8f\n",t.x,t.y);
  koch(n-1,t,b);
}



Measured memory_bytes: 2112
def main():
    from collections import deque
    N, M = (int(i) for i in input().split())
    G = [[] for _ in range(N)]
    for i in range(M):
        a, b = (int(i) for i in input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)

    def bfs(s):
        G_color = ['WHITE' for _ in range(N)]
        G_distance = [float('inf') for _ in range(N)]
        G_parent = ['NIL' for _ in range(N)]
        G_color[s] = 'GRAY'
        G_distance[s] = 0
        Q = deque()
        Q.append(s)
        while Q:
            u = Q.popleft()
            for v in G[u]:
                if G_color[v] == 'WHITE':
                    G_color[v] = 'GRAY'
                    G_distance[v] = G_distance[u] + 1
                    G_parent[v] = u
                    Q.append(v)
            G_color[u] = 'BLACK'
        return G_parent

    par = bfs(0)
    if all(par[i] != 'NIL' for i in range(1, N)):
        print("Yes")
        for i in range(1, N):
            print(par[i]+1)
    else:
        print("No")


if __name__ == '__main__':
    main()


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

int main() {
  int N;
  int j = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    j += r - l + 1;
  }
  cout << j << endl;
}

Measured memory_bytes: 256
n,k = gets.chomp.split.collect{ |item| item.to_i}
s = gets.chomp
s.insert(0,"R")
s += "L"

def check(arr,i)
  if(arr[i] == "R")
  return (arr[i] == arr[i+1])
  else
    return (arr[i] == arr[i-1])
  end
end

ans = n
badn = 0
1.upto(n) do |ni|
  badn += 1 if check(s,ni) == false
end
ans -= [1,(badn - 2*k)].max

puts ans


Measured memory_bytes: 4092
#include<bits/stdc++.h>
using namespace std;
static vector< int > sum[5011];
int main(){
  for(int i = 0; i <= 5010 ; i++){
    sum[i].resize(i + 10, 0);
  }
  int N, M;
  scanf("%d %d", &N, &M);
  for(int i = 0; i < M; i++){
    int a, b, x;
    scanf("%d %d %d", &a, &b, &x);
    ++sum[a][b];
    --sum[a][b + 1];
    ++sum[a + x + 1][b + x + 2];
    --sum[a + x + 2][b + x + 2];
    ++sum[a + x + 2][b + 1];
    --sum[a + x + 1][b];
  }

  for(int i = 1; i <= N + 10; i++){
    for(int j = 1; j <= i + 5; j++){
      sum[i][j] += sum[i - 1][j - 1];
    }
  }
  for(int i = 1 ; i <= N + 10 ; i++){
    for(int j = 1 ; j <= i + 5; j++){
      sum[i][j] += sum[i][j - 1];
    }
  }
  for(int i = 1; i <= N + 10; i++){
    for(int j = 1; j <= i + 5; j++){
      sum[i][j] += sum[i - 1][j];
    }
  }

  int ret = 0, cnt = 0;
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= i; j++){
      if(sum[i][j]) ret++;
    }
  }
  printf("%d\n", ret);
}

Measured memory_bytes: 50580
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  int c[3];
  for (int i=0; i<3; i++) cin >> c[i];
  sort(c,c+3);
  if (c[2] == c[1]+c[0]) cout <<"Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9;
int main()
{
int n,i,j,k;
cin>>n>>k;
int a[n],ans[n];
for(i=0;i<n;i++)
    {cin>>a[i];}

memset(ans,127,sizeof ans);
ans[n-1]=0;

for(i=n-2;i>=0;i--)
{
    for(j=i+1;j-i<=k&&j<n;j++)
    {
        ans[i]=min(ans[i],abs(a[i]-a[j])+ans[j]);
    }
}
cout<<ans[0]<<endl;

return 0;}


Measured memory_bytes: 1024
/*input
29
20
7
35
120
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-6;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll sub(ll a,ll b){
    ll x=a-b;
    while(x<0) x+=MOD;
    while(x>MOD) x-=MOD;
    return x;
}
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=1e2+5;
const ll maxlg=__lg(maxn)+2; 
int main(){
	int arr[5];
	REP(i,5) cin>>arr[i];
	sort(arr,arr+5);
	int ans=INF;
	do{
		int sum=0;
		REP(i,5){
			sum=((sum+9)/10)*10;
			sum+=arr[i];
		}
		MNTO(ans,sum);
	}while(next_permutation(arr,arr+5));
	cout<<ans;
}


Measured memory_bytes: 768
import sys
import math
n = int(input())
if n == 1:
  print(1)
  sys.exit()
prime_list = []
    #2からnまでの数字をsearch_listに入れる
search_list = list(range(2,n+1))
while True:
      #search_listの先頭の値が√nの値を超えたら処理終了
      if search_list[0] > math.sqrt(n):
        #prime_listにsearch_listを結合
          prime_list.extend(search_list)
          break
      else:
        #search_listの先頭をprime_listに入れる
          head_num = search_list[0]
          prime_list.append(head_num)
        #search_listの先頭をpopする
          search_list.pop(0)
        #head_numの倍数を取り除く
          search_list = [num for num in search_list if num % head_num != 0]
#print(prime_list)
########ここから本問を解く#########
ans = 1
for x in prime_list:
  tmp = 0
  nl = 1
  while(x**nl <= n):
    tmp += n//(x**nl)
    nl += 1
  ans *= tmp+1
if ans >= 10**9+7:
  ans %= (10**9+7)
print(ans)

Measured memory_bytes: 9204
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		sc.close();

		String[] lines = line.split(" ");

		int a = Integer.parseInt(lines[0]);
		int b = Integer.parseInt(lines[1]);

		if (a > 8 || b > 8) {
			System.out.println(":(");
		} else {
			System.out.println("Yay!");
		}
	}

}


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

using namespace std;

vector<list<int> > li;

void f0()
{
    int p1,p2;
    cin>>p1>>p2;

    li[p1].push_back(p2);
}

void f1()
{
    int p;
    cin>>p;

    int flag=0;
    for(auto &i:li[p])
    {
        if(flag) cout<<' ';
        cout<<i;
        flag++;
    }
    cout<<endl;
}

void f2()
{
    int p1,p2;
    cin>>p1>>p2;

    li[p2].splice(li[p2].end(),li[p1]);
}

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

    cin>>n>>q;

    li.resize(n);

    while(q--)
    {
        int op;
        cin>>op;

        switch(op)
        {
            case 0:f0();break;
            case 1:f1();break;
            case 2:f2();break;
        }
    }


    return 0;
}





Measured memory_bytes: 18760
n = gets.to_i
nums = gets.split.map(&:to_i)
hash = Hash.new(0)
nums.each_with_index do |num, i|
  next if i == 0
  hash[num - i] += 1
end
ans = 0
nums.each_with_index do |num, i|
  next if i == n - 1
  ans += hash[(num + i) * - 1]
  hash[num[i + 1]] -= 1
end
puts ans


Measured memory_bytes: 37000
#include<iostream>

int source[500][500] = {};

void copy_array(int a[],int b[],int m){
    for(int i=0;i<m;i++){
        b[i] = a[i];
    }
}

bool check(int n,int m,int sum[]){
    for(int j=0;j<m;j++){
        if(sum[j] %2 == 1) return false;
    }
    //std::cout << "      ";
    /*for(int j=0;j<m;j++){
        std::cout << sum[j] << ' ';
    }
    std::cout << '\n';
     */
    return true;
}

bool sum_calc(int f_num,int f_pos,int m,int n,int pri_sum[]){
    //std::cout << "再起\n";
    int sum[500] = {};
    //std::cout << "f_num=" << f_num << '\n';
    for(int i=f_pos;i<n-f_num+1;i++){
        //std::cout << "f_num=" << f_num << "  f_pos=" << i << '\n';
        copy_array(pri_sum,sum,m);
        
        for(int j=0;j<m;j++){
            sum[j] -= source[i][j];
        }
        
        f_num--;
        if(f_num==0){
            //std::cout << "      f_num=0\n";
            if(check(n,m,sum)){
                return true;
            }else{
                //std::cout << "失敗した\n";
                f_num++;
            }
        }else{
            if(sum_calc(f_num,i+1,m,n,sum)){
                return true;
            }else{
                f_num++;
            }
        }
    }
    //std::cout << "終了\n";
    return false;
}

void to_int(char s[],int i){
    int j=0;
    while(s[j] != '\0'){
        if(s[j] == '0'){
            source[i][j++] = 0;
        }else{
            source[i][j++] = 1;
        }
    }
}

int search(int n,int m,int sum[]){
    for(int f_num=1;f_num<n;f_num++){
        //std::cout << "f_num=" << f_num << '\n';
        if(sum_calc(f_num,0,m,n,sum)) return f_num;
    }
    return n;
}

int main(){
    int n,m;
    while(1){
        std::cin >> n >> m;
        if(n==0&&m==0) return 0;
        //std::cout << "n:" << n <<" m:" << m << '\n';
        char s[500];
        for(int i=0;i<n;i++){
            std::cin >> s ;
            to_int(s,i);
        }
        
        /*for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                std::cout << source[i][j] << ' ';
            }
            std::cout << '\n';
        }
        */
        int sum[500] = {};
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                sum[j] += source[i][j];
            }
        }
        
        if(check(n,m,sum)){
            std::cout << /*"ans=" <<*/ n << '\n';
        }else{
            int ans=n-search(n,m,sum);
            std::cout << /*"ans=" <<*/ ans << '\n';
        }
        //std::cout << '\n';
    }
    /*for(int j=0;j<m;j++){
     std::cout << sum[j] << ' ' ;
     }
     std::cout << '\n';
     */
    
    return 0;
}



Measured memory_bytes: 3988
a,b = map(int,input().split())
val = 0
if a*b < 0:
    val += 1
elif (a>0 and b==0) or (a==0 and b<0):
    val += 1
elif b < a:
    val += 2
val += abs(abs(a)-abs(b))
print(val)

Measured memory_bytes: 9164
H, W = map(int, input().split())
a = []
for i in range(H):
    b = input()
    count = b.count('.')
    if count == W:
        continue
    else:
        a += [list(map(str, b))]

num = len(a)
val = []
for i in range(W):
    for j in range(num):
        if a[j][i] == '.':
            if j == num-1:
                val.append(i)
            else:
                continue
        else:
            break
for i in reversed(val):
    for j in range(num):
        del a[j][i]
for i in range(len(a)):
    print(''.join(a[i]))

    


Measured memory_bytes: 9248
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <vector>
#include <stack>
#include <queue>

using namespace std;
int n;
struct Point
{
    int when;
    Point() {
    }
    Point(int _when) {
        when = _when;
    }
};
vector<Point>time_stamp[100010];
map<string, int>dict;
vector<string>ID;
void Init() {
    dict.clear();
    ID.clear();
    for(int i = 1; i <= n; i++) {
        time_stamp[i].clear();
    }
}
int tranTime(int hh, int mm) {
    return hh * 60 + mm;
}
int godness;

int Cut(int l, int r, int a, int b) {
    int ret = 0;
    if(r <= a || l >= b) {
        return 0;
    }
    return min(b, r) - max(l, a);
}
int sum[100010];
int tot;
int ans = 0;
void Solve() {
    if(godness == -1) {
        return ;
    }
    for(int i = 1; i <= tot; i++) {
        if(i == godness) {
            continue;
        }
        int st = 0, ed;
        for(int j = 0; j < (int)time_stamp[i].size(); j += 2) {
            int l, r;
            l = time_stamp[i][j].when;
            r = time_stamp[i][j + 1].when;
            while(st < (int)time_stamp[godness].size() && time_stamp[godness][st + 1].when <= l) {
                st += 2;
            }
            for(int k = st; k < (int)time_stamp[godness].size(); k += 2) {
                sum[i] += Cut(l, r, time_stamp[godness][k].when, time_stamp[godness][k + 1].when);
                if(time_stamp[godness][k].when >= r) {
                    break;
                }
            }
        }
        ans = max(ans, sum[i]);
    }

}
void Input() {
    memset(sum, 0, sizeof(sum));
    int month, day, hh, mm;
    char IO[10];
    string id;
    Init();
    int lastMonth;
    int lastDay;
    lastMonth = -1;
    lastDay = -1;
    godness = -1;
    for(int i = 1; i <= n; i++) {
        scanf("%d/%d %d:%d %s", &month, &day, &hh, &mm, IO);
        cin>>id;
        if(!dict[id]) {
            dict[id] = (int)dict.size();
            tot = (int)dict.size();
            if(id == "000") {
                godness = dict[id];
            }
        }
        if(lastMonth == month && lastDay == day) {
            time_stamp[dict[id]].push_back(  Point(tranTime(hh, mm))  );
        } else {
            Solve();
            for(int i = 1; i <= tot; i++) {
                time_stamp[i].clear();
            }
            time_stamp[dict[id]].push_back(  Point(tranTime(hh, mm))  );
        }
        lastDay = day;
        lastMonth = month;    
    }
    Solve();
}
int main() {
    //freopen("input.txt","r",stdin);
    while(scanf("%d", &n) != EOF) {
        if(n == 0) {
            break;
        }
        ans = 0;
        Input();
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 4084
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int n, m, X, Y, x[max], y[max];
    int xmax=INT_MIN, ymin=INT_MAX;
    
    scanf("%d%d%d%d", &n, &m, &X, &Y);
    rep(i, n){
        scanf("%d", &x[i]);
        if (xmax<x[i]) {
            xmax=x[i];
        }
    }
    rep(i, m){
        scanf("%d", &y[i]);
        if (ymin>y[i]) {
            ymin=y[i];
        }
    }
    
    for (int i=X+1; i<=Y; i++) {
        if (xmax<i&&ymin>=i) {
            printf("No War\n");
            return 0;
        }
    }
    
    printf("War\n");
    
    return 0;
}


Measured memory_bytes: 1648
import java.util.Scanner;

class Main {public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int a[] = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		
		int s = n;
		int m = 0;
		int g[] = new int[n];
		while(s > 0) {
			s = s / 2;
			g[m] = s;
			m++;
		}
		
		//shellSort
		int cnt = 0;
		for(int i = 0; i < m; i++) {
			//insertionSort
			for(int h = g[i]; h <= n-1; h++) {
				int v = a[h];
				int j = h - g[i];
				while(j >= 0 && a[j] > v) {
					a[j+g[i]] = a[j];
					j = j - g[i];
					cnt++;
				}
				a[j+g[i]] = v;
			}
		}
		
		System.out.println(m);
		for(int i = 0; i < m; i++) {
			if(i != 0) System.out.print(" ");
			System.out.print(g[i]);
		}
		System.out.println("\n" + cnt);
		for(int i = 0; i < n; i++) System.out.println(a[i]);
	}
}


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

using namespace std;
typedef long long int ll;

int main()
{
   int n;
   cin >> n;
   vector<int>a(n);
   for(int i = 0; i < n; i++) cin >> a[i];
   int q;
   cin >> q;
   vector<int>m(q);
   for(int i = 0; i < q; i++) cin >> m[i];
   set<int>result;
   for(int bit = 0; bit<(1<<n); bit++) 
    {
        int sum = 0;
        for(int j = 0; j < n; j++) if(bit & (1<<j)) sum += a[j];
        result.insert(sum);
    }
    for(int i = 0; i < q; i++)
    {
        if(result.count(m[i])) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

vector<vector<pii > > g;
vector<bool> seen;
vi ans;

void dfs(int v,int c){
	seen[v]=true;
	ans[v]=c;
	
	for(auto elem:g[v]){
		int u,w;
		tie(u,w)=elem;
		if(seen[u]){}
		else dfs(u,(ans[v]+w)%2);
	}
}

//解説参考.
int main(){
	int n;
	cin>>n;
	
	g.resize(n);
	seen.assign(n,false);
	ans.resize(n);
	
	REP(i,n-1){
		int u,v,w;
		cin>>u>>v>>w;
		u--, v--;
		g[u].emplace_back(v,w);
		g[v].emplace_back(u,w);
	}
	
	dfs(0,0);
	
	for(auto elem:ans) cout<<elem<<endl;
}

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

int V, E;
vector<unordered_set<int>> redge;

unordered_set<int> memo;
void topological_sort(int u) {
  if(memo.count(u)) return;
  memo.insert(u);
  for(int v: redge[u]) topological_sort(v);
  cout << u << endl;
}

int main() {
  cin >> V >> E;
  redge.resize(V);
  for(int i = 0; i < E; ++i) {
    int u, v;
    cin >> u >> v;
    redge[v].insert(u);
  }
  for(int i = 0; i < V; ++i) topological_sort(i);
}

Measured memory_bytes: 4700
#include <stdio.h>

int main(){
    int h , w;
    int i,j;
    
    while(1){
    scanf("%d %d",&h,&w);
     if(h==0 && w==0) break;
     else
        for(i=0;i<h;i++){
            for(j=1;j<=w;j++){ 
                if(i==0 || i==(h-1)){
                  printf("#"); 
                } else{
                    if(j==1 || j==w){
                    printf("#"); 
                    } else {
                    printf("."); 
                    }
                }
            }
            printf("\n");
        }
            printf("\n");
    }
return 0;
}


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

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

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

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

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

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

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

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

def main():
    N, M = map(int, input().split())
    uni = UnionFind(N)
    for _ in range(M):
        X, Y, Z = map(int, input().split())
        X -= 1
        Y -= 1
        uni.union(X,Y)

    print(uni.group_count())



if __name__ == "__main__":
    main()

Measured memory_bytes: 62684
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/*
 * AtCoder Beginner Contest 088 C "Takahashi's Information"
 *   https://abc088.contest.atcoder.jp/tasks/abc088_c/
 */
public class Main {

	public static void main(String[] args) {

		InputScanner in = new InputScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int[][] c = in.nextIntArray(3, 3);

		int[] a = new int[3];
		int[] b = new int[3];

		a[0] = 0;
		b[0] = c[0][0] - a[0];
		b[1] = c[0][1] - a[0];
		b[2] = c[0][2] - a[0];
		a[1] = c[1][0] - b[0];
		a[2] = c[2][0] - b[0];

		String ans = "Yes";
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (c[i][j] != a[i] + b[j]) {
					ans = "No";
				}
			}
		}

		out.println(ans);

		in.close();
		out.close();
	}

	/*
	 * extends java.util.Scanner
	 */
	static class InputScanner {

		Scanner scanner;

		public InputScanner(InputStream inputStream) {
			this.scanner = new Scanner(inputStream);
		}

		public int nextInt() {
			return scanner.nextInt();
		}

		public long nextLong() {
			return scanner.nextLong();
		}

		public double nextDouble() {
			return scanner.nextDouble();
		}
		public String next() {
			return scanner.next();
		}

		public int[] nextIntArray(int n) {
			int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextInt();
			}
			return ret;
		}

		public int[][] nextIntArray(int h, int w) {
			int[][] ret = new int[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextInt();
				}
			}
			return ret;
		}

		public long[] nextLongArray(int n) {
			long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextLong();
			}
			return ret;
		}

		public long[][] nextlongArray(int h, int w) {
			long[][] ret = new long[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextLong();
				}
			}
			return ret;
		}

		public double[] nextDoubleArray(int n) {
			double[] ret = new double[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextDouble();
			}
			return ret;
		}

		public double[][] nextDoubleArray(int h, int w) {
			double[][] ret = new double[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextLong();
				}
			}
			return ret;
		}

		public String[] nextStringArray(int n) {
			String[] ret = new String[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.next();
			}
			return ret;
		}

		public String[] nextStringArray(String split) {
			String[] ret = scanner.next().split(split);
			return ret;
		}

		public String[][] nextStringArray(int h, int w) {
			String[][] ret = new String[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.next();
				}
			}
			return ret;
		}

		public String[][] nextStringArray(int h, String split) {
			String[][] ret = new String[h][];
			for (int i = 0; i < h; i++) {
				ret[i] = scanner.next().split(split);
			}
			return ret;
		}

		public void close() {
			scanner.close();
		}

	}

}


Measured memory_bytes: 23764
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cinii(N,M);
    vector<int> l(M),r(M);
    rep(i,M) cin >> l[i] >> r[i];
    int maxL=0,minR=100000+1;
    rep(i,M){
        maxL = max(maxL,l[i]);
        minR = min(minR,r[i]);
    }
    cout << max(minR - maxL + 1,0) << nn;
    return 0;
}

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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fr(i,x,n) for(i=x;i>=n;--i)
#define endl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll ans=a*x+b*y;
    int i;
    F(i,2,2*(max(x,y))+1,2){
        ll res=i*c;
        if(x-(i>>1)>=0){
            res+=(x-(i>>1))*a;
        }
        if(y-(i>>1)>=0){
            res+=(y-(i>>1))*b;
        }
        ans=min(ans,res);
    }
    
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
import numpy as np
n, k = map(int, input().split())
r, s, p = map(int, input().split())
T = np.array(list(input()))

ans = 0
for i in range(k):
  sli = T[list(range(i, n, k))]
  rc = sc = pc = 0
  for t in sli:
    if t == 'r':
      if rc+sc != 0:
        ans += (rc+1)//2 * r + (sc+1)//2 * s
        rc = sc = 0
      pc += 1
    elif t == 's':
      if sc+pc != 0:
        ans += (sc+1)//2 * s + (pc+1)//2 * p
        sc = pc = 0
      rc += 1
    elif t == 'p':
      if rc+pc !=0:
        ans += (rc+1)//2 * r + (pc+1)//2 * p
        rc = pc = 0
      sc += 1
      
  if rc+sc+pc != 0:
    ans += (rc+1)//2 * r + (sc+1)//2 * s + (pc+1)//2 *p
   
print(ans)

Measured memory_bytes: 17488