akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int N,Q; vector<vector<int>> to; vector<long long> add;
vector<int> ans;

void dfs(int v, long long  sum){
  //今注目しているノード,今までのaddの和
  ans[v] = sum;
  
  for(int i = 0; i < (int) to[v].size(); i++){
    int p = to[v][i];
    if( ans[p] != -1){ continue;}
    else{
      dfs( p, sum + add[p]);}
  }
}
    
    
  
  

int main(){
   cin >> N >> Q;
  to.resize(N); add = vector<long long> (N,0LL);
  ans = vector<int> (N,-1);
 
  for(int i = 0; i < N - 1; i++){
    int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b); to[b].push_back(a);
  }
  
  for(int j = 0; j < Q; j++){
    int p,x; cin >> p >> x; p--;
    add[p] += x;}
  
  
  dfs(0, add[0]);
  
  for(int i = 0; i < N; i++){
    cout << ans[i] << endl; }
  return 0;}
  
  


Measured memory_bytes: 21888
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
    long long int t,n,i,j,k,l,sum,sum1,cnt,cnt1,flag,flag1,m,x,y,a,b,c,d,mid;
    cin>>a>>b>>n;
    if((n/b)==0)
    {
        x=n;
        sum=(((a*x)/b)-(a*(x/b)));
    }
    else if(n%b!=0)
    {
        cnt=n/b;
        cnt1=cnt*b;
        x=cnt1-1;
        sum=(((a*x)/b)-(a*(x/b)));

    }
    else if(n%b==0)
    {
        x=n-1;
        sum=(((a*x)/b)-(a*(x/b)));
    }
    cout<<sum<<endl;
    return 0;

}



Measured memory_bytes: 3560
'use strict'

function main(input) {
  input = input.split(' ').map(v => ~~v)
  const a = input[0] //aの倍数
  const b = input[1] //bで割る
  const c = input[2] //割った余り

  let i = 0
  while (i <= b) {
    if ((i * a) % b == c) {
      console.log('YES')
      return
    }
    // console.log(i, (i * a) % b, Math.floor((i * a) / b))
    i++
  }
  console.log('NO')
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
N, T = map(int,input().split())
S = list(map(int,input().split()))

k = 0
s = 0
ans = 0
for p in S:
    if k > p:
        k = p + T
    else:
        ans += k-s
        s = p
        k = p + T

print(ans+k-s)


Measured memory_bytes: 25200
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int h,w;
    cin>>h>>w;
    vector<string>s(h);
    rep(i,h){
        cin>>s[i];
    }
    pair<int,int>x=make_pair(0,0);
    s[0][0]='.';
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#'&&((i==x.first&&j==x.second+1)||(i==x.first+1&&j==x.second))){
                s[i][j]='.';
                x=make_pair(i,j);
            }
        }
    }
    if(x!=make_pair(h-1,w-1)){cout<<"Impossible"<<endl;}
    else{
        rep(i,h){
            rep(j,w){
                if(s[i][j]=='#'){
                    cout<<"Impossible"<<endl;
                    return 0;
                }
            }
        }
        cout<<"Possible"<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int hantei(int year);
//???????????´????????????????????????????????????

int main(void)
{
	int year[2];
	int NA = -1;
	int leapyear[3000];
	for(int i = 0; i < 3000; i++) {
		leapyear[i] = hantei(i);
	}
	for(;;) {
		scanf("%d %d", &year[0], &year[1]);
		if(year[0] == 0 && year[1] == 0) {
			break;
		}else if(NA != -1) {
			printf("\n");
		}
		NA = 0;
		for(int i = year[0]; i <= year[1]; i++) {
			if(leapyear[i] == 1) {
				printf("%d\n", i);
				NA++;
			}
		}
		if(NA == 0) {
			printf("NA\n");
		}
	}
	return 0;
}

int hantei(int year)
{
	if(year % 400 == 0) {
		return 1;
	}else if(year % 100 == 0) {
		return 0;
	}else if(year % 4 == 0) {
		return 1;
	}else{
		return 0;
	}
} 

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

int main(){
int n,m;
map<string,int>card;
cin >> n;
string tmp;
for (int i = 0; i < n; i++){
  cin >> tmp;
  card[tmp]++;
}
cin >> m;
for (int i = 0; i < m; i++){
  cin >> tmp;
  card[tmp]--;
}

int s = 0;

// Keyの値が小さい順にループ
for (auto p : card) {
  auto key = p.first;
  auto value = p.second;
  // key, valueを使う
s = max(s,value);
}


cout << s << endl;


}

Measured memory_bytes: 256
#![allow(non_snake_case)]
use proconio::input;
use std::collections::HashMap;
const M: i64 = 1000000007_i64;
fn main() {
    input! {
        n:usize,
        ab:[(i64,i64);n]
    }
    // 鰯(Ai,Bi)と(Aj,Bj)について、Ai*Aj + Bi*Bj =0になる組み合わせは不可。
    // (0,0)の鰯の数を x とすると、これらは一匹のみの場合のみ追加可能。
    // 両辺を Aj * Bi で割ると、Ai/Bi + Bj/Aj = 0となる。
    // 逆数にして -1 をかけた鰯とは組み合わせられないが、他ならOK。
    // 鰯について、既約分数で表現すれば、Ai/Biは一意に定まる。
    let ab: Vec<(i64, i64)> = ab.into_iter().filter(|&(a, b)| a != 0 || b != 0).collect();
    let zero = (n - ab.len()) as i64;
    let ab: Vec<(i64, i64)> = ab
        .into_iter()
        .map(|(a, b)| {
            let g = num::integer::gcd(a, b);
            (a / g, b / g)
        })
        .collect();
    // modPow(2,x)
    let mut mp2 = vec![1i64; n + 1];
    for i in 0..n {
        mp2[i + 1] = mp2[i] * 2 % M;
    }
    let mut group1 = HashMap::new();
    ab.iter().for_each(|&x| {
        let count = group1.entry(x).or_insert(0);
        *count += 1;
    });

    let mut get_pararell = |a: i64, b: i64| {
        let mut res = 0;
        if let Some(v) = group1.get(&(a, b)) {
            res += v;
            group1.remove(&(a, b));
        }
        if let Some(v) = group1.get(&(-a, -b)) {
            res += v;
            group1.remove(&(-a, -b));
        }
        res
    };
    //    println!("{:?}", group1);
    let mut ans = 1;
    for &(a, b) in &ab {
        let pararells = get_pararell(a, b);
        let crosses = get_pararell(b, -a);
        // println!("({},{}), p:{}, c:{}", a, b, pararells, crosses);
        ans = ans * ((mp2[pararells] + mp2[crosses] - 1) % M) % M;
    }
    ans = (ans + zero + M - 1) % M;
    println!("{}", ans);
}

// また、bの符号に一致する様に計算する。

//fn yakubun(a: i64, b: i64) -> (i64, i64) {
//    if b == 0 {
//        return (-1, 0);
//    }
//    if a == 0 {
//        return (0, 1);
//    }
//    let x = if b > 0 { gcd(a, b) } else { -gcd(a, b) };
//    return (a / x, b / x);
//}
//
//fn modPow(x: i64, a: i64, mp2: &Vec<i64>) -> i64 {
//    if x == 2 && (a as usize) < mp2.len() {
//        return mp2[a as usize];
//    }
//    if a == 1 {
//        x
//    } else {
//        if a % 2 != 0 {
//            (modPow(x, a - 1, &mp2) * x) % M
//        } else {
//            let t = modPow(x, a / 2, &mp2);
//            t * t % M
//        }
//    }
//}
////fn modInv(x: i64) -> i64 {
////    modPow(x, M - 2)
//}


Measured memory_bytes: 27004
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  scanf("%d%d",&n,&k);
long long int h[n],dp[n];
  for(int i=0;i<n;i++) {scanf("%lld",&h[i]);  dp[i]=1000000000;}

  dp[0]=0;
  for(int i=1;i<n;i++){
    for(int j=1;j<=i&&j<=k;j++){
     dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
  }
  }
  printf("%lld",dp[n-1]);
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
int W, H, x, y, r, z = 0;

  scanf("%d", &W);
  scanf("%d", &H);
  scanf("%d", &x);
  scanf("%d", &y);
  scanf("%d", &r);

  if(x + r > W || x - r < 0){
    z = z + 1;
  }

  if(y + r > H || y - r < 0){
    z = z + 1;
  }

  if(z != 0){
    printf("No\n");
  }else{
    printf("Yes\n");
  }

  return 0;

}

Measured memory_bytes: 1820
from math import sqrt
N = int(input())
i = 2
lis = []
n = N
while True:
    if i>sqrt(n):
        if n==1:
            break
        else:
            lis.append(str(n))
            break
    if n%i==0:
        lis.append(str(i))
        n //= i
    else:
        i += 1
print('{}: '.format(N)+' '.join(lis))


Measured memory_bytes: 5664
#include<iostream>

using namespace std;

int main()
{
	int a, x, y;
	cin >> a;
	x = a / 100;
	y = a % 100;
	if (1 <= x&&x <= 12) {
		if (1 <= y&&y <= 12) printf("AMBIGUOUS\n");
		else printf("MMYY\n");
	}
	else {
		if (1 <= y&&y <= 12) printf("YYMM\n");
		else printf("NA\n");
	}
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
using namespace std;
 
int main(){
   int A, B, c = 0;
   cin >> A;
   cin >> B;
   while(A <= B){
     if(A%10 == A/10000){
       if(A/1000%10 == A/10%10){
       c++;}}
       A++;
   }
  cout<<c<<endl;      
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static int[][] math;
	static final int MATH_LENGTH = 10;

	public static void main(String[] args) throws IOException {
		//?????°????????????
		math = new int[10][10];
		int x = 0, y = 0;
		int scale;

		//??\???????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String inputStr = null;
		while (true) {
			inputStr = br.readLine();
			if (inputStr == null || inputStr.isEmpty()) {
				break;
			}
			//??\???????????????","??§??????
			String[] inputSplitStr = inputStr.split(",");
			x = Integer.valueOf(inputSplitStr[0]);
			y = Integer.valueOf(inputSplitStr[1]);
			scale = Integer.valueOf(inputSplitStr[2]);

			// ???????????´???????????????????¨????
			switch (scale) {
			case 1: //???????????´????°????
				setSmallInk(x, y);
				break;
			case 2: //???????????´?????????
				setMediumInk(x, y);
				break;
			case 3: //???????????´?????§???
				setLargeInk(x, y);
				break;
			}
		}
		//???????????¶????????????????????¨?????????????????????????????????
		int whiteNumber = 0;
		int mostNumber = 0;
		for (int i = 0; i < MATH_LENGTH; i++) {
			for (int j = 0; j < MATH_LENGTH; j++) {
				if (math[i][j] == 0) {
					whiteNumber++;
				}
				if (mostNumber < math[i][j]) {
					mostNumber = math[i][j];
				}
			}
		}
		System.out.println(whiteNumber);
		System.out.println(mostNumber);
	}

	private static void setSmallInk(int x, int y) {
		math[x][y]++;
		if ((x - 1) >= 0) {
			math[x - 1][y]++;
		}
		if ((y - 1) >= 0) {
			math[x][y - 1]++;
		}
		if (MATH_LENGTH > (x + 1)) {
			math[x + 1][y]++;
		}
		if (MATH_LENGTH > (y + 1)) {
			math[x][y + 1]++;
		}
	}

	private static void setMediumInk(int x, int y) {
		math[x][y]++;
		if ((x - 1) >= 0) {
			math[x - 1][y]++;
			if ((y - 1) >= 0) {
				math[x - 1][y - 1]++;
			}
			if (MATH_LENGTH > (y + 1)) {
				math[x - 1][y + 1]++;
			}
		}
		if ((y - 1) >= 0) {
			math[x][y - 1]++;
		}
		if (MATH_LENGTH > (y + 1)) {
			math[x][y + 1]++;
		}
		if (MATH_LENGTH > (x + 1)) {
			math[x + 1][y]++;
			if ((y - 1) >= 0) {
				math[x + 1][y - 1]++;
			}
			if (MATH_LENGTH > (y + 1)) {
				math[x + 1][y + 1]++;
			}
		}
	}

	private static void setLargeInk(int x, int y) {
		math[x][y]++;
		if ((x - 2) >= 0) {
			math[x - 2][y]++;
		}
		if (MATH_LENGTH > (x + 2)) {
			math[x + 2][y]++;
		}
		if ((y - 2) >= 0) {
			math[x][y - 2]++;
		}
		if (MATH_LENGTH > (y + 2)) {
			math[x][y + 2]++;
		}
		if ((x - 1) >= 0) {
			math[x - 1][y]++;
			if ((y - 1) >= 0) {
				math[x - 1][y - 1]++;
			}
			if (MATH_LENGTH > (y + 1)) {
				math[x - 1][y + 1]++;
			}
		}
		if ((y - 1) >= 0) {
			math[x][y - 1]++;
		}
		if (MATH_LENGTH > (y + 1)) {
			math[x][y + 1]++;
		}
		if (MATH_LENGTH > (x + 1)) {
			math[x + 1][y]++;
			if ((y - 1) >= 0) {
				math[x + 1][y - 1]++;
			}
			if (MATH_LENGTH > (y + 1)) {
				math[x + 1][y + 1]++;
			}
		}
	}
}

Measured memory_bytes: 17068
package main

import (
	"fmt"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	list := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&list[i])
	}

	for i := 0; i < w+2; i++ {
		fmt.Print("#")
	}
	fmt.Println("")
	for i := 0; i < h; i++ {
		fmt.Print("#")
		fmt.Print(list[i])
		fmt.Println("#")
	}
	for i := 0; i < w+2; i++ {
		fmt.Print("#")
	}

}


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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  LL a,b;
  cin >> a >> b;
  int count[60]={0};
  for(int i=59;i>=0;i--){
    if(b&(1ll<<i)) count[i]+=(b&((1ll<<i)-1))+1;
  }
  if(b&2) count[0]++;
  // cout << count[0] << endl;
  for(int i=59;i>=0;i--){
    if((a-1)&(1ll<<i)) count[i]+=((a-1)&((1ll<<i)-1))+1;
  }
  if((a-1)&2) count[0]++;
  // cout << count[0] << endl;
  LL ans=0;
  for(int i=59;i>=0;i--){
    if(count[i]%2) ans+=(1ll<<i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll long long
#define INF 10000000000000000LL
#define pll pair<long long , long long>
const int MAX=1e6+10;
const int MOD=1e9+7;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
vector<int>adj[MAX];
int coun(int x){
	return __builtin_popcount(x);
}
ll dp[3005][3005];
int main() 
{ 
	//ios_base::sync_with_stdio(false);
  //  cin.tie(NULL);	
//	#ifndef ONLINE_JUDGE
	//freopen("inp.txt" ,"r", stdin );
//	freopen("out.txt", "w", stdout);
//	#endif
	int n;
	cin>>n;
	ll arr[n+1];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	for(int l=n-1;l>=0;l--){
		for(int r=l;r<n;r++){
			if(l==r)
				dp[l][r]=arr[l];
			else
				dp[l][r]=max(arr[l]-dp[l+1][r], arr[r]-dp[l][r-1]);
		}
	}
	cout<<dp[0][n-1];
}

Measured memory_bytes: 94336
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long 
#define db double
#define N 300010
#define L(x) ((x)&(-x))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define swap(T, a, b) ({T ttt = a; a = b; b = ttt;})
int n, m, L, R, C[N];
struct Seg
{
   int l, r, len;
}a[N];
bool cmp(const Seg a, const Seg b)
{
   return a.len < b.len;
}
void Add(int k, int x)
{
   for (; k <= m; k += L(k))
      C[k] += x;
}
int Sum(int k)
{
   int s = 0;
   for (; k; k -= L(k))
      s += C[k];
   return s;
}
int main()
{
   scanf("%d%d", &n, &m);
   memset(C, 0, sizeof(C)); 
   for (int i = 1; i <= n; i++) {
      scanf("%d%d", &L, &R);
      a[i] = (Seg) { L, R, R-L+1 };
   }
   std::sort(a+1, a+n+1, cmp);
   int k = 1; 
   for (int i = 1; i <= m; i++)
   {
      while (k <= n && a[k].len < i)
      {
	 Add(a[k].l, 1);
	 Add(a[k].r+1, -1);
	 k++;
      }
      int ans = n - k + 1; 
      for (int j = i; j <= m; j += i)
	 ans += Sum(j);
      printf("%d\n", ans);
   }
   return 0; 
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){   
   int n,m,X,Y;
   cin>>n>>m>>X>>Y;

   vector<int> x(n);
   vector<int> y(m);

   rep(i,n){
      int s;
      cin>>x[i];
   }
   rep(i,m){

      cin>>y[i];
   }

   int flag=1;
   for(int z=X+1;z<=Y;z++){
      flag=1;
      rep(i,n){
         if(x[i]>=z) {
            flag=0;
            break;
         }
      }
      rep(i,m){
         if(y[i]<z){
            flag=0;
            break;
         }
      }
      if(flag==1){
       cout<<"No War";
       break;
      }
   }
   if(flag==0) cout<<"War";
   return 0;
}

Measured memory_bytes: 256
#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;
 
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>

int main()
{
    int n,m;
    cin>>n>>m;
    if(m==n)
        cout<<"Yes";
    else 
        cout<<"No";
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int a,b,c;
    cin>>a>>b>>c;
    set <int> s;
    s.ins(a);
    s.ins(b);
    s.ins(c);

    if(s.size()==2) cout<< "Yes";
    else cout<< "No";

    return 0;
}

// ushareng--> github
// linkedin jobs


Measured memory_bytes: 3620
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);


    int s;
    cin >> s;

    const int N = 1000 * 1000 + 1000;
    vector<int> A(N + 1, -1);
    A[s] = 1;
    long long x = s;
    int res = 1;
    while (true) {
        if (x & 1) {
            x = 3 * x + 1;
        } else {
            x >>= 1;
        }
        ++res;
        if (A[x] > 0) {
            break;
        }
        A[x] = res;
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 4224
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n, p, x;
long long f[200][2];

int main() {
	scanf("%d%d", &n, &p);
	f[0][0] = 1;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &x);
		f[i][1] = f[i - 1][1] + (x & 1 ? f[i - 1][0] : f[i - 1][1]);
		f[i][0] = f[i - 1][0] + (x & 1 ? f[i - 1][1] : f[i - 1][0]);
	}
	printf("%lld\n", f[n][p]);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}

ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){ if(b==0) return a; return gcd(b, a%b);}

int counter(int x){
    if(x==0) return 0;
    return counter(x>>1)+(x&1);
}
int main(){
    fast_io

    int n;
    cin>>n;
    int A[20];
    int x[20][20];
    int y[20][20];
    
    rep(i,n){
        cin>>A[i];
        rep(j, A[i]){
            cin>>x[i][j]>>y[i][j];
            x[i][j]--;
        }
    }
    int ans=0;
    rep(bits,1<<n){
        bool ok=true;
        bitset<18> bs(bits);
        rep(i, n){
            if(bs[i]!=1)continue;
            rep(j, A[i]){
                if((bs[x[i][j]])^y[i][j]) ok=false;
            }
        }
        if(ok) ans=max(ans, (int)bs.count());
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
s = [input() for _ in range(h)]
dx = [1,1,1,-1,-1,-1,0,0]
dy = [0,1,-1,0,1,-1,1,-1]
for i in range (h):
	z=[]
	for j in range (w):
		if(s[i][j] == "."):
			cnt = 0
			for k in range (8):
				x = i + dx[k]
				y = j + dy[k]
				if(x >= 0 and x < h and y >= 0 and y < w and s[x][y] == "#"):
					cnt += 1
			z.append(cnt)
		else:
			z.append("#")
	print (*z, sep="")

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef map<string,ll> mapstl;
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	ll cnt = 0;
	for(int i=1;i<n;i++)cnt+=i;
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
inline long long read(){
	long long x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
int main(){
	long long Q=read(),H=read(),S=read(),D=read(),N=read();
	long long k=min(Q*4,min(H*2,S));
    cout<<(k+k<=D?k*N:(N%2)*k+N/2*D)<<"\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		System.out.print(z + " ");
		System.out.print(x + " ");
		System.out.print(y);

	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    LL N,K; cin >> N >> K;
    VVI nxt(62,VI(N));
    REP(i,N){
        cin >> nxt[0][i];
        nxt[0][i]--;
    }
    FOR(i,1,62){
        REP(j,N){
            nxt[i][j] = nxt[i-1][nxt[i-1][j]];
        }
    }
    int now = 0;
    for(int i = 61; i >= 0; i--){
        if((K >> i)&1){
            now = nxt[i][now];

        }
    }
    cout << now + 1 << endl;

}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s;

int main() {
	cin >> s;
	cout << s.substr(0,5) << " " << s.substr(6,7) << " " << s.substr(14,5) << ln;
}

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

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];

    vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(401, vector<int>(401, 1e9)));
    dp[0][0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= 400; j++) {
            for (int k = 0; k <= 400; k++) {
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                if (j+a[i] <= 400 && k+b[i] <= 400) dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
            }
        }
    }

    int ans = 1e9;
    for (int ia = ma, ib = mb; ia <= 400 && ib <= 400; ia += ma, ib += mb) {
        ans = min(ans, dp[n][ia][ib]);
    }
    cout << (ans != 1e9 ? ans : -1) << endl;
}


Measured memory_bytes: 27264
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n + 1];
		int b[] = new int[n];

		String str[] = br.readLine().split(" ");

		for (int i = 0; i < n + 1; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		str = br.readLine().split(" ");

		for (int i = 0; i < n; i++) {
			b[i] = Integer.parseInt(str[i]);
		}

		long ans = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] > 0) {
				int temp = Math.min(a[i], b[i]);
				a[i] -= temp;
				b[i] -= temp;
				ans += temp;
			}

			if (a[i] <= 0 && b[i] > 0) {
				int temp = Math.min(a[i + 1], b[i]);
				a[i + 1] -= temp;
				b[i] -= temp;
				ans += temp;
			}
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 56760
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    ll n;
    cin >> n;

    ll p[n];
    rep(i, n) { cin >> p[i]; }

    ll temp_min = p[0];
    ll ans = 1;

    repd(i, 1, n) {
        if (p[i] < temp_min) {
            temp_min = p[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

int main(){
  string s;
  cin >> s;
  if(s[0] == 'S' && s[1] == 'U'){
    cout << 7 << endl;
  }else if(s[0] == 'S' && s[1] == 'A'){
    cout << 1 << endl;
  }else if(s[0] == 'M'){
    cout << 6 << endl;
  }else if(s[2] == 'E'){
    cout << 5 << endl;
  }else if(s[0] == 'W'){
    cout << 4 << endl;
  }else if(s[2] == 'U'){
    cout << 3 << endl;
  }else if(s[0] == 'F'){
    cout << 2 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100

int main(){
  int i,j,k,n,key;
  int A[N];

  scanf("%d",&n);
  for(i=0; i<n; i++)
    scanf("%d",&A[i]);

  for(i=0; i<n; i++){
    key = A[i];
    j = i-1;
    while(j>=0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    for(k=0; k<n; k++){
      if(k!=n-1) printf("%d ",A[k]);
      else printf("%d\n",A[k]);
    }
  }

  return 0;
}

  



Measured memory_bytes: 2140
// Author: Shusuke Ueda
// AtCoder Beginner Contest 136 - Problem C

#include <iostream>
#include <vector>

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

    std::vector<int> a(n);
    for (auto& e: a) {
        std::cin >> e;
    }

    bool ans = true;
    for (int i = n - 1; i > 0; i--) {
        if (a[i - 1] <= a[i]) {
            continue;
        } else if (a[i - 1] - a[i] == 1) {
            a[i - 1]--;
            continue;
        } else {
            ans = false;
            break;
        }
    }

    if (ans) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  long long L[100];
  for(int i=0; i<N; i++){
    cin >> L[i];
  }
  
  int cnt=0;
  for(int i=0; i<N-2; i++){
    for(int j=i+1; j<N-1; j++){
      for(int k=j+1; k<N; k++){
        if(L[i]+L[j] > L[k] && L[i]+L[k] > L[j] && L[j]+L[k] > L[i]){
          if(L[i] != L[j] && L[j] != L[k] && L[i] != L[k]){
          	cnt++;
          }
        }                                            
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3644
import java.util.Scanner;

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

		int a = sc.nextInt();
		String b = sc.next();
		int c = sc.nextInt();

		if(b.equals("+")){
			System.out.println(a+c);
		}else if(b.equals("-")){
			System.out.println(a-c);
		}

	}
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long long int a, b, c, d;
	scanf("%lli %lli %lli %lli", &a, &b, &c, &d);
	
	cout << max({a * c, a * d, b * c, b * d}) << endl;
		
}

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

int main(void)
{
	double x1, x2, y1, y2;
	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

	printf("%lf", sqrt(pow( (x1 - x2), 2) + pow((y1 - y2), 2) ) );

	return 0;
}

Measured memory_bytes: 652
#include <stdio.h>

#define MAX 100000

typedef long long llong;

int n,k;
llong T[MAX];

int cech(llong P){
  int i=0,j;
  llong s;
  for(j=0;j<k;j++){
    s=0;
    while(s+T[i]<=P){
      s+=T[i];
      i++;
      if(i==n)return n;
    }
  }
  return i;
}

int solve(){
  llong left=0;
  llong right=10000000000;
  llong mid;
  int v;
  while(right-left>1){
    mid=(left+right)/2;
    v=cech(mid);
    if(v>=n)right=mid;
    else left =mid;
  }
  return right;
}

int main(){
  int i;
  llong ans;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%lld",&T[i]);
  }
  ans=solve();
  printf("%lld\n",ans);

  return 0;
}



Measured memory_bytes: 2632
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
#define MAXN 100000
#define INF 1000000000
int n,a,b,ans,p[MAXN+5];
int main()
{
	scanf("%d",&n,&a);
	printf("%.10f",(double)((n+1)/2)/n);
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    readLine()
    val numbers = readLine()?.split(" ")?.map(String::toInt) ?: throw IllegalArgumentException()
    val minimumValue = numbers.min() ?: 0
    (1..minimumValue / 2).forEach { num ->
        val a = numbers.firstOrNull { it %  num != 0 }
        if (a == null) {
            println(num)
        }
    }
}


Measured memory_bytes: 40480
#include <iostream>
#include <string>
using namespace std;
int m, n, i, j,a[5];

int main()
{
    for(int t=1;t<4;t++){
        cin>>a[t];
    }

    if(a[2]-a[1]==a[3]-a[2]) cout<<"YES";
    else cout<<"NO";
    return 0;
}

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

using namespace std;

typedef long long ll;
 
int main()
{
    int n;
    while (cin >> n, n) {
	ll a[n], ans = 0;
 
	cin >> a[0];
	for (int i = 1; i < n; i++) {
	    cin >> a[i];
	}
	sort(a, a + n);
 
	for (int i = 1; i < n; i++) {
	    a[i] += a[i-1];
	    ans += a[i-1];
	}
	cout << ans << endl;
    }
    return 0;
}

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

int main(){
int n,m;
cin>>n;m=n;
vector<long> nums(n);int i=0;
while(n--){ cin>>nums[i++];}
int cnt=0;
for(int i=0; i<m-2;i++){
    for(int j=i+1; j<m-1; j++){
        for(int k=j+1; k<m; k++){
            int a= nums[i];
            int b= nums[j];
            int c= nums[k];
            if( (a!=b) &&  (b!=c) && (c!=a) ){
                if( (a+b>c) && (b+c>a) && (c+a>b) ){
                    cnt++;
                }
            }
        }
    }
}
cout<<cnt<<"\n";
    return 0;
}

Measured memory_bytes: 3572
def tmp(n):
    return n * (n - 1) / 2


def main():
    line = input().strip()
    n, m = [int(v) for v in line.split(' ')]

    ans_n = tmp(n) if n > 1 else 0
    ans_m = tmp(m) if m > 1 else 0
    ans = ans_n + ans_m
    print(int(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n = int(input())
A = list(map(int, input().split()))

ans = 1
sq = 0
a = A[0]
for i in range(1,n):
    #print(a,A[i], sq)
    if sq == 0 and A[i] < a:
        sq = -1
    elif sq == 0 and A[i] > a:
        sq = 1
    elif (sq == 1 and A[i] < a) or (sq == -1 and A[i] > a):
        #print('---')
        ans += 1
        sq = 0
    a = A[i]

print(ans)



Measured memory_bytes: 14252
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct List {
  int key;
  struct List *before;
  struct List *next;
};

struct List l;

void insert(int key) {
  struct List *a = malloc(sizeof(struct List));
  a->key = key;
  a->before = &l;
  a->next = l.next;
  l.next = a;
  a->next->before = a;
}

void delete(int b) {
  struct List *c;
  c = l.next;
  while(c->key != -1) {
    if (c->key == b) {
      c->next->before = c->before;
      c->before->next = c->next;
      break;
    }  
    c = c->next;
  } 
  }

void delete_First() {
  l.next = l.next->next;
  l.next->before = &l;
}

void delete_Last() {
  l.before = l.before->before;
  l.before->next = &l;
}

int main(void) {
  int n;
  char command[12];
  int key;
  struct List *box;
  l.key = -1;
  l.before = &l;
  l.next = &l;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", command);
    if (strcmp(command, "deleteFirst") == 0)
      delete_First();
    else if (strcmp(command, "deleteLast") == 0)
      delete_Last();
    else {
      scanf("%d", &key);
      if (strcmp(command, "insert") == 0) 
	insert(key);
      else if (strcmp(command, "delete") == 0)
	delete(key);
      }
    }
 
  
  box = l.next;
  while(box->key != -1) {
    printf("%d", box->key);
    box = box->next;
    if (box->key != -1)
      printf(" ");
  }
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 36068
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
  int X;
  cin>>X;
  int c=0;
  int y=0;
  int ans[10005]={0};
  for(int i=1;i<=70;i++)
  {
    for(int k=2;k<=50;k++)
    {
      ans[c]=pow(i,k);
      c++;
    }
  }
sort(ans,ans+10000);
  for(int i=0;i<=10000;i++)
  {
    if(ans[i]<=X && ans[i+1]>X)
    {
      cout<<ans[i]<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
def F(n):
	if n%2==1:
		ans=0 if (n+1)%4==0 else 1
	else:
		ans=n^0 if n%4==0 else n^1
	return ans
def resolve():
	A,B=map(int,input().split())
	print(F(A-1)^F(B))
resolve()

Measured memory_bytes: 38428
open Batteries
let get_max a b c = max a @@ max b c
let get_others a b c =
  let max_ = get_max a b c in
    if a = max_ then (b, c) else
    if b = max_ then (a, c) else (a, b)


let n = read_int ()
let l = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ fun a -> a

let is_triangle a b c =
  let cosa = (float_of_int @@ b * b + c * c - a * a) /. (float_of_int @@ 2 * b * c) in
  -1. < cosa && cosa < 1.


let rec i_loop i result_i =

  let rec j_loop j result_j =

    let rec k_loop k result_k =
      if k >= n then result_k else (
        if l.(i) = l.(j) || l.(j) = l.(k) || l.(i) = l.(k) then k_loop (k+1) result_k else
        if is_triangle l.(i) l.(j) l.(k) then k_loop (k+1) (result_k+1) else k_loop (k+1) result_k
      )
    in if j >= n then result_j else j_loop (j+1) (result_j + k_loop (j+1) 0)
  in if i >= n then result_i else i_loop (i+1) (result_i + j_loop (i+1) 0)

let _ = Printf.printf "%d\n" @@ i_loop 0 0


Measured memory_bytes: 5780
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n;cin>>n;
    string a,b;cin>>a>>b;
    for(ll i=0;i<n;++i)
    {
        cout<<a[i]<<b[i];
    }
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const long long int  mod  = 1000000007;
int main()
{
	ll n,m;
	cin>>n>>m;
	float f=(float)m/n;
	if(f>500)
		cout<<"No";
	else
		cout<<"Yes";
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

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

int main() {
  int R, G, B, N;
  std::cin >> R >> G >> B >> N;
  int count = 0;
  REP(r, N / R + 1) {
    REP(g, (N - R * r) / G + 1) {
      if ((N - R * r - G * g) % B == 0)
        count++;
    }
  }
  std::cout << count << '\n';
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100010;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
struct UnionFind{
    vector<int> parent;
    vector<int> rank; // tree's depth
 
    UnionFind(int n){
        parent.resize(n);
        rank.resize(n);
        init(n);
    }
 
    // initialize
    void init(int n){
        for(int i = 0; i < n; i++){
            parent[i] = i;
            rank[i] = 0;
        }
    }
    // find root
    int find(int x){
        if(parent[x] == x){
            return x;
        }else{
            return parent[x] = find(parent[x]);
        }
    }
 
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
 
        if(rank[x] < rank[y]){
            parent[x] = y;
        }else{
            parent[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
 
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int n, m; cin >> n >> m;
    UnionFind UF(n);

    int x, y, z;
    rep(i, m){
        cin >> x >> y >> z;
        x--, y--;
        UF.unite(x, y);
    }
    set<int> count;
    rep(i, n) count.insert(UF.find(i));
    cout << count.size() << endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int i,j,n,a,b,c,d;
int main(){
  for(cin>>a>>b>>c>>d;a>0;a-=d){
    c-=b;
    if(c<1)return cout<<"Yes",0;
  }
  cout<<"No";
}

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

int main(){
    string S;
    cin >> S;
    int N = S.size();
    bool flag = true;
    for(int i=0,j=N-1;i<j;i++,j--) if(S[i] != S[j]) flag = false;
    if (flag) for(int i=0, j=(N-1)/2-1;i<j;i++,j--) if(S[i]!=S[j]) flag = false;
    if (flag) for(int i=(N+3)/2-1, j=N-1;i<j;i++,j--) if(S[i]!=S[j]) flag = false;
    cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int l,s,cnt=0,n,sort[5],i,j;
    while(scanf("%d",&n),n!=0000){
        cnt=0;
        while(n!=6174 && n%1111!=0){
            sort[0]=n/1000;
            sort[1]=n/100-sort[0]*10;
            sort[2]=n/10-(sort[0]*100+sort[1]*10);
            sort[3]=n%10;
            for(i=0;i<4;i++){
                for(j=i+1;j<4;j++){
                    if(sort[i]<sort[j]){
                        sort[4]=sort[i];
                        sort[i]=sort[j];
                        sort[j]=sort[4];
                    }
                }
            }
            l=sort[0]*1000+sort[1]*100+sort[2]*10+sort[3];
            s=sort[3]*1000+sort[2]*100+sort[1]*10+sort[0];
            n=l-s;
            cnt++;
        }
        if(n%11==0)printf("NA\n");
        else printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 608
/*
Sample Input 2

Copy
1
Z
Z
Sample Output 2

Copy
3
Sample Input 1

Copy
3
aab
ccb
Sample Output 1

Copy
6*/ 
#include <bits/stdc++.h>
using namespace std;
char s[60];
long long dp[60];
int a[60];
const int MD=1000000007;
int main()
{
    int n;
    scanf("%d",&n);
    int t=0;
    scanf("%s",s+1);
    for(int i=1; i<=n; i++)
        if(s[i]==s[i-1])
            a[t]++;
        else
            a[++t]++;
    if(a[1]==1)dp[1]=3;
    else dp[1]=6;
    for(int i=2; i<=t; i++)
    {
        if(a[i-1]==2)
        {
            if(a[i]==2)
                dp[i]=dp[i-1]*3%MD;
            else if(a[i]==1)
                dp[i]=dp[i-1];
        }
        else if(a[i-1]==1)
        {
            if(a[i]==2||a[i]==1)
            dp[i]=dp[i-1]*2%MD;
        }
    }
    scanf("%s",s+1);
    cout<<dp[t];
    return 0;
}

Measured memory_bytes: 256
h, w = [int(i) for i in input().split()]
A = [0] * h
for i in range(h):
    A[i] = [int(j) for j in input().split()]
b = []
for i in range(w):
    b.append(int(input()))
for i in range(h):
    num = 0
    for j in range(w):
        num += A[i][j] * b[j]
    print(num)


Measured memory_bytes: 6008
using System;
using System.Collections.Generic;
using System.Linq;

public class HelloWorld
{
    static public void Main ()
    {
        var input = Console.ReadLine().Split(' ');
        var n = int.Parse(input[0]);
        var y = int.Parse(input[1]);
        for (int i = 0; i <= n; i++)
        {
            for (int j = 0; j <= n - i; j++)
            {
                for (int k = 0; k <= n - i - j; k++)
                {
                    if (10000 * i + 5000 * j + 1000 * k == y && i + j + k == n)
                    {
                        Console.WriteLine(string.Format("{0} {1} {2}", i, j, k));
                        return;
                    }
                }
            }
        }
        Console.WriteLine("-1 -1 -1");
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)==2)
{
if(a==4 && (b==4 || b==6 || b==9 || b==11))
printf("Yes\n");
else if(a==6 && (b==4 || b==6 || b==9 || b==11))
printf("Yes\n");
else if(a==9 && (b==4 || b==6 || b==9 || b==11))
printf("Yes\n");
else if(a==11 && (b==4 || b==6 || b==9 || b==11))
printf("Yes\n");
else if(a==2 && b==2)
printf("Yes\n");


else if(a==1 && (b==3 || b==5 || b==7 || b==8 || b==10 || b==12))
printf("Yes\n");
else if(a==3 && (b==3 || b==5 || b==7 || b==8 || b==10 || b==12))
printf("Yes\n");
else if(a==5 && (b==3 || b==5 || b==7 || b==8 || b==10 || b==12))
printf("Yes\n");
else if(a==7 && (b==3 || b==5 || b==7 || b==8 || b==10 || b==12))
printf("Yes\n");
else if(a==8 && (b==3 || b==5 || b==7 || b==8 || b==10 || b==12))
printf("Yes\n");
else if(a==10 && (b==3 || b==5 || b==7 || b==8 || b==10 || b==12))
printf("Yes\n");
else if(a==12 && (b==3 || b==5 || b==7 || b==8 || b==10 || b==12))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}


Measured memory_bytes: 128
N = int(input())
v = list(map(int, input().split()))

even_v=[]
odd_v=[]
for i in range(N):
    if i%2==0:
        even_v.append(v[i])
    else:
        odd_v.append(v[i])

import collections
even_c = collections.Counter(even_v)
odd_c = collections.Counter(odd_v)

even_num = even_c.most_common()[0][0]
odd_num = odd_c.most_common()[0][0]
even_cnt = even_c.most_common()[0][1]
odd_cnt = odd_c.most_common()[0][1]

if even_num == odd_num:
    if len(odd_c.most_common())==1 and len(even_c.most_common())==1: # only one num
        odd_num=even_num+1
    elif len(odd_c.most_common())!=1 and len(even_c.most_common())==1: # change odd
        odd_num = odd_c.most_common()[1][0]
    elif len(odd_c.most_common())==1 and len(even_c.most_common())!=1: # change even
        even_num = even_c.most_common()[1][0]
    else:
        if odd_cnt==even_cnt:
            even_cnt2= even_c.most_common()[1][1]
            odd_cnt2 = odd_c.most_common()[1][1]
            if even_cnt2>odd_cnt2:
                even_num = even_c.most_common()[1][0]
            else:
                odd_num = odd_c.most_common()[1][0]
        elif odd_cnt>even_cnt:
            even_num = even_c.most_common()[1][0]
        else:
            odd_num = odd_c.most_common()[1][0]
ans=0

for i in range(N):
    if i%2==0:
        num=even_num
    else:
        num=odd_num
    if num!=v[i]:
        ans+=1

print(ans)

Measured memory_bytes: 20704
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    o = IS()
    e = IS()
    res = ''
    for i in range(len(e)):
        res += o[i]+e[i]
    if len(o) > len(e):
        res += o[-1]
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin>>s;
	int c1,c2;
	c1 = c2 = 0;
	rep(i,3){
		if(s[i]=='A')c1=1;
		else c2 = 1;
	}	
	if(c1 > 0 && c2 > 0)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256