akhauriyash/Code-Regression huggingface dataset:
import sys
# import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

tower = [[0] * 13 for i in range(4)]
Pattern = 'SHCD'
N = int(readline())
for _ in range(N):
    x = readline()
    P, num = x.split()[0].decode('utf8'), int(x.split()[1])
    tower[Pattern.index(P)][num - 1] += 1

for num, i in enumerate(tower):
    P = Pattern[num]
    for number,j in enumerate(i):
        if j == 0:
            print(P, number + 1)



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;

long long modpow(long long a,long long n,long long p)
{
    if(n==1)
    {
        return a%p;
    }
    if(n%2==1)
    {
        return a*modpow(a,n-1,p)%p;
    }
    long long t = modpow(a,n/2,p);
    return t*t%p;
}
 
//O(K)でnCkを求める
int comb( int N, int K ){
  int X = 1; //分子
  int Y = 1; //分母
  for( int i = N; i > N-K; i-- ){
    X = (X*i)%MOD;
  }
  for( int i = 1; i <= K; i++ ){
    Y = (Y*i)%MOD;
  }
  return X * modpow(Y, MOD-2, MOD)%MOD;   //Aの逆元を取る場合、modpow(A, MOD-2, MOD) https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a 3-4参照
}

int main()
{
    /*A
    int n,m;
    cin>>n>>m;
    int count;
    count = (n*(n-1)/2+m*(m-1)/2);
    cout<<count<<endl;
    */

    string s;
    cin>>s;
    int n = s.size();
    bool flag = true;
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            flag = false;
        }
    }
    
    for(int i=0;i<(n-1)/2;i++)
    {
        if(s[i]!=s[(n-1)/2-(i+1)])
        {
            flag = false;
        }
    }
    for(int i=(n+3)/2;i<n;i++)
    {
        if(s[i]!=s[n-(i+1)])
        {
            flag = false;
        }
    }

    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

    return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

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

const int INF = 1e15;

int N;
int h[111111];
int dp[111111];

signed main() {
  cin >> N;
  repp (i, 0, N) {
    cin >> h[i];
  }

  fill(dp, dp+N+10, INF);
  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    if (i + 1 < N) {
      dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    }
    if (i + 2 < N) {
      dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
    }
  }

  cout << dp[N-1] << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int i,j,tmp,min;
int a,b,c;
int data_in[3] = {0,0,0};
int data_cal[3] = {0,0,0};
int total = 3;

int main(void){
    scanf("%d %d %d",&data_in[0],&data_in[1],&data_in[2]);
    data_cal[0] = data_in[0] + data_in[1];
    data_cal[1] = data_in[1] + data_in[2];
    data_cal[2] = data_in[2] + data_in[0];
    
    for (i=0; i<total; ++i) {
        for (j=i+1; j<total; ++j) {
            if (data_cal[i] > data_cal[j]) {
                tmp =  data_cal[i];
                data_cal[i] = data_cal[j];
                data_cal[j] = tmp;
            }
        }
    }
    
    //printf("%d %d %d",data_cal[0],data_cal[1],data_cal[2]);
    printf("%d",data_cal[0]);
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
int main()
{
    int N, K, C;
    std::cin >> N >> K >> C;
    std::string s;
    std::cin >> s;
    std::vector<int> front(K);
    std::vector<int> back(K);
    int              farthest_front, farthest_back;
    int              count_front = -1, count_back = K;
    for (int i = 0; i < N; i++) {
        if (s[i] == 'o')
            if (count_front == -1 || (i - farthest_front) > C) {
                if (++count_front >= K) return 0;
                front[count_front] = i + 1;
                farthest_front     = i;
            }
        if (s[N - i - 1] == 'o')
            if (count_back == K || (i - farthest_back) > C) {
                if (--count_back < 0) return 0;
                back[count_back] = N - i;
                farthest_back    = i;
            }
    }
    for (int i = 0; i < K; i++)
        if (front[i] == back[i]) std::cout << front[i] << std::endl;
}

Measured memory_bytes: 3332
import java.util.*;

public class Main {
    private static final String lin = "####################";

    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int[][][] tbl = new int[4][3][10];
        for(int i = 0, n = scn.nextInt(); i < n; i++) {
            int b = scn.nextInt(), f = scn.nextInt();
            int r = scn.nextInt(), v = scn.nextInt();
            tbl[~-b][~-f][~-r] += v;
        }
        for(int b = 0; b < 4; b++) {
            for(int f = 0; f < 3; f++) {
                for(int r = 0; r < 10; r++) {
                    System.out.print(" " + tbl[b][f][r]);
                }
                System.out.println();
            }
            if(b < 3) {
                System.out.println(lin);
            }
        }
    }
}

Measured memory_bytes: 21060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static int n;
	static List<ArrayList<Edge>> g;
	static int[] ans;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		g = new ArrayList();
		for(int i = 0 ;i < n ;i++) {
			g.add(new ArrayList<Edge>());
		}
		
		for(int i = 0 ;i < n-1 ;i++) {
			int a = Integer.parseInt(sc.next())-1;
			int b = Integer.parseInt(sc.next())-1;
			
			g.get(a).add(new Edge(i,b));
			g.get(b).add(new Edge(i,a));
			
		}
		
		ans = new int [n-1];
		
		dfs(0 ,-1 ,-1);
		int max = 0;
		
		for(int temp : ans) {
			max = Math.max(max, temp);
		}
		
		System.out.println(max);
		
		for(int c : ans) {
			System.out.println(c);
		}
		
		
	}
	
	static void dfs(int to , int color , int parents) {
		int k = 1 ; 
		for(Edge e : g.get(to)) {
			if(e.to == parents) continue;   //自身の親へ行こうとするときは考えない
			if(k == color) k++;              //自身の色と塗ろうとしている色が同じなら違う色にする
			ans[e.id] = k;                   //考えている辺の相手側の色を決める
			dfs(e.to , k , to);              //その相手側を自身の立場に置き換えて再度考える
			k++;                             //複数の相手に対して異なる色で塗る
			
		}
	}
	
	}
class Edge{
	
	 Edge(int id, int to){
		 this.id = id;
		 this.to = to;
	 }
	 
	 int id;
	 int to;
}




Measured memory_bytes: 81612
#include<stdio.h>
#include<math.h>
int main(){
double v;
double time;
double y;
int floors;
while(scanf("%lf",&v)!=EOF){
  time=v/9.8;
  y=4.9*time*time;
  floors=(y+5)/5+1;
  printf("%d\n",floors);

}
return 0;
}

Measured memory_bytes: 628
#include<iostream>
#include<string>
using namespace std;
int d,t,n,s;

int main()
{
	d=0;t=0;cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		if(s%4==0)t++;
		else if(s%2==0)d++;
	}
	if(2*t+d>=n)cout<<"Yes";
	else if(d==0&&2*t+1>=n)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> xv(n);
    rep(i, n) {
        cin >> xv[i];
    }
    sort(xv.begin(), xv.end());
    ll ans = 1e18;
    rep(i, n - k + 1) {
        if ( xv[i] < 0LL && xv[i+k-1] < 0LL ) {
            ans = min(ans, abs(xv[i]));
        }
        else if ( xv[i] > 0LL && xv[i+k-1] > 0LL ) {
            ans = min(ans, abs(xv[i+k-1]));
        }
        else {
            ans = min({ans, abs(xv[i+k-1]) + abs(xv[i]) + abs(xv[i]), abs(xv[i+k-1]) + abs(xv[i]) + abs(xv[i+k-1])});
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

int main()
{

    ll X, Y;

    cin >> X >> Y;

    if ((X + Y) % 3 != 0)
    {
        cout << 0 << endl;
        return 0;
    }

    ll m = (Y - 2 * X) / -3;
    ll n = (X - 2 * Y) / -3;

    if (m < 0 || n < 0)
    {
        cout << 0 << endl;
        return 0;
    }

    cout << combi(n + m, n) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  string s; cin >> s;
  if(s[2] == s[3] && s[4] == s[5]){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;

  system("pause");
}


Measured memory_bytes: 1012
#include<bits/stdc++.h>
using namespace std;
int main()
{
   char b;
   cin>>b;
   if(b=='A')
   cout<<"T"<<endl;
   else if(b=='T')
   cout<<"A"<<endl;
   else if(b=='C')
   cout<<"G"<<endl;
   else if(b=='G')
   cout<<"C"<<endl;

   return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int a,b;
void dfs(int x,int y,string s){
  if(x==a&&y==b){
    cout<<s<<endl;
    return;
  }
  if((x<4&&y>4)||(x>4&&y<4)||y>b||x>a)return;
  dfs(x+1,y,s+"A");
  dfs(x,y+1,s+"B");
}
main(){
  cin>>a>>b;
  dfs(0,0,"");
}

Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>


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

    std::vector<int> h(n);
    for(int i = 0; i<n; ++i) {
        std::cin>>h[i];
    }

    std::sort(std::begin(h), std::end(h), std::greater<int>());

    auto hp_f = std::begin(h) + k;
    auto hp_l = std::end(h);

    if(hp_f >= hp_l){
        std::cout<<0<<std::endl;
    }else{
        std::cout<<std::accumulate(hp_f, hp_l, 0ull)<<std::endl;
    }

}


Measured memory_bytes: 1024
import numpy as np
s=input()
prev='R'
a=0
x=np.zeros(len(s)).astype(np.uint32)
b=0
for i in range(len(s)):
    if s[i]==prev:
        a+=1
        continue
    else:
        if prev=='R':
            prev='L'
            x[b+a-1]+=(a-a//2)
            x[b+a]+=a//2
            b+=a
        else:
            prev='R'
            x[b]+=(a-a//2)
            x[b-1]+=a//2
            b+=a 
        a=1
x[b]+=(a-a//2)
x[b-1]+=a//2
p=''
for i in range(len(s)):
    p+=str(x[i])+' '
print(p[:-1])

Measured memory_bytes: 21408
fun main(args : Array<String>) {
    val (x, y) = readLine()!!.split(delimiters = " ").map { it.toLong() }
    var count = 1
    var num = x
    while (num < y) {
        if (2 * num <= y) count++
        num *= 2
    }

    println(count)
}

Measured memory_bytes: 37864
#include <iostream>
#include <string>

using namespace std;

int main(){
	int a,b,k1,k2;
	cin >> a >> b >> k1;
	k2 = (b-a-k1)*-1;
	for(;a<=b;a++){
		if(k1>0||k2>0)cout << a << endl;
		k1--;
		k2++;
	}

	return 0;
}


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

import java.util.*;

public class Main {
    static int[] flag;
public static ArrayList<Integer> erathosthenes(int x) {
    int[] nums = new int[x];
    flag = new int[x];
    for (int i=2;i<x;i++) {
        nums[i]=i;
    }
    for (int i=2;i<Math.sqrt(x);i++) {
        if (flag[i]==1) {
            continue;
        }
        for (int j=2;j*i<x;j++) {
            flag[j*i]=1;
        }
    }
    ArrayList<Integer> ans = new ArrayList<Integer>();
    for (int i=2;i<x;i++) {
        if (flag[i]==0) {
            ans.add(nums[i]);
        }
    }
    return ans;
}
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int[] isPrime = new int[100000+1];
        isPrime[1] = 1;
        for (Integer i : erathosthenes(100000)) {
            isPrime[i]=1;
        }
        int[] ruiseki = new int[100000+1];
        for (int i=2;i<100000;i+=2) {
            ruiseki[i+1] = ruiseki[i-1];
            if (isPrime[i+1]==1 && isPrime[(i+2)/2]==1) {
                ruiseki[i+1]++;
            }
        }
        int Q = in.nextInt();
        for (int i=0;i<Q;i++) {
            int l = in.nextInt();
            if (l==1) {
                l=2;
            }
            int r = in.nextInt();
            out.println(ruiseki[r]-ruiseki[l-2]);
        }

        out.close();
    }

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

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

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

    }
}


Measured memory_bytes: 44460
import sys

sys.setrecursionlimit(1000000)

N = int(input())
Nodes = [{} for i in range(N)]


def search(index, dist):
    neighbors = Nodes[index]
    for key in neighbors:
        if distances[key] is not None:
            continue

        distances[key] = dist + neighbors[key]
        search(key, distances[key])


# 木を作る
for _ in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    Nodes[a][b] = c
    Nodes[b][a] = c

# 頂点Kから各点への距離を求める
Q, K = map(int, input().split())
distances = [None for i in range(N)]
distances[K-1] = 0
search(index=K-1, dist=0)

#print(distances)

# 解答
for _ in range(Q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(distances[x] + distances[y])


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

typedef long long ll;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << " "; err(++it, args...); }

#define        optimize           ios::sync_with_stdio(0); cin.tie(0);
#define PI    acos(-1.0)
#define pb push_back
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define RESET(a, b) memset(a, b, sizeof(a))
#define pii pair <int, int>
#define gcd(a, b) __gcd(a, b)
#define min3(a, b, c) min(c, min(a, b))
#define max3(a, b, c) max(c, max(a, b))

const ll MX = 4e2 + 5;
const ll inf = 1e18 + 5;

ll dp[MX][MX];
ll ara[MX];
ll sum[MX];

void solve(int l, int r)
{
    if(l == r){
        dp[l][r] = 0;
        return;
    }
    if(dp[l][r] != -1) return;

    ll &res = dp[l][r];
    res = inf;
    for(int i = l; i <= r; i++){
        solve(l, i);
        solve(i+1, r);
        dp[l][r] = min(dp[l][r], dp[l][i]+dp[i+1][r]+(sum[r]-sum[l-1]));
    }
}


int main()
{
    optimize
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++){
        cin>>ara[i];
        sum[i] = sum[i-1]+ara[i];
    }
    RESET(dp, -1);
    solve(1, n);
    cout<<dp[1][n]<<endl;
}


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int c = Integer.parseInt(str[2]);
    int d = Integer.parseInt(str[3]);
    System.out.println(a*b>=c*d?a*b:c*d);
  }
}

Measured memory_bytes: 32620
import sys
import numpy as np
from numba import njit

R, C, K = map(int, input().split())
item = np.zeros((R, C), np.int_)
for s in sys.stdin.readlines():
    r, c, v = map(int, s.split())
    item[r-1,c-1] = v

@njit
def solve(R, C, K, item):
    DP = np.zeros((R, C, 4), np.int_)

    DP[0][0][1] = item[0][0]

    for i in range(R):
        for j in range(C):
            for k in range(4):
                if i > 0:  # 前の行から
                    DP[i,j,0] = max(DP[i,j,0], max(DP[i-1,j]))  # 取らない
                    DP[i,j,1] = max(DP[i,j,1], max(DP[i-1,j])+item[i,j])  # 取る

                if j > 0:  # 前の列から
                    DP[i,j,k] = max(DP[i,j,k], DP[i,j-1,k])  # 取らない
                    if k >= 1:
                        DP[i,j,k] = max(DP[i,j,k], DP[i,j-1,k-1]+item[i,j])  # 取る

    print(max(DP[R-1,C-1]))

solve(R, C, K, item)

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<(a+b)*c/2;
}
	 


Measured memory_bytes: 256
a,b,k=map(int,input().split())
A=set()
for i in range(1,a+1):
    if a%i==0:
        A.add(i)
B=set()
for j in range(1,b+1):
    if b%j==0:
        B.add(j)
ans=A & B
ans2=list(ans)
ans3=sorted(ans2, reverse=True)
#print(ans3)
print(ans3[k-1])



Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
	char s[10];
	scanf("%s",s);
	if(s[0]=='S'){
		printf("Cloudy");
	}else if(s[0]=='C'){
		printf("Rainy");
	}else if(s[0]=='R'){
		printf("Sunny");
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
typedef long long LL;
const int mod = 1e9+7;

int main()
{
    int n,k;
    cin>>n>>k;
    LL ans=0;
    for(LL i=k;i<=n+1;i++)
    {
        LL l=i*(i-1)/2,r=i*(2*n-i+1)/2;
        ans=(ans+r-l+1)%mod;
    }
    cout<<ans%mod<<endl;




    int ab;
    cin>>ab;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <complex>
#include <cstdio>

using namespace std;

typedef complex<double> P;
const int MAX_V = 205;

int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void init(int x){
  V = x;
  for(int i=0;i<MAX_V;++i) G[i].clear();
}

void add_edge(int u, int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v){
  used[v] = true;
  for(int i=0;i<G[v].size();i++){
    int u = G[v][i], w = match[u];
    if(w < 0 || !used[w] && dfs(w)){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching(){
  int res = 0;
  fill(match, match+MAX_V, -1);
  for(int v=0;v<V;v++){
    if(match[v] < 0){
      fill(used, used+MAX_V, false);
      if(dfs(v)) res++;
    }
  }
  return res;
}

main(){
  int n, m;
  while(cin >> n >> m && (n|m)){
    vector<P> tr, ba;
    vector<double> v;
    for(int i=0;i<n;++i){
      double a, b, c;
      cin >> a >> b >> c;
      tr.push_back(P(a, b));
      v.push_back(c);
    }
    for(int i=0;i<m;++i){
      double a, b;
      cin >> a >> b;
      ba.push_back(P(a, b));
    }
    double l = 0, r = 1e10;
    for(int k=0;k<80;k++){
      double mid = (l + r) / 2;
      init(n+m);
      for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
          if(abs(tr[i]-ba[j])/v[i] < mid) add_edge(i, n+j);
        }
      }
      if(bipartite_matching() == m) r = mid;
      else l = mid;
    }
    printf("%.8f\n", l);
  }
}

Measured memory_bytes: 1416
from fractions import gcd
def gc(a,b):
  if a==0 or b==0:
    return max(a,b)
  else:
    return gcd(a,b)
n=int(input())
a=list(map(int,input().split()))
a=[0]+a+[0]
lgcd=[0]
rgcd=[0]
for i in range(1,n):
  lgcd.append(gc(a[i],lgcd[-1]))
  rgcd.append(gc(a[-i-1],rgcd[-1]))
GCD=0
for i in range(n):
  GCD=max(GCD,gc(lgcd[i],rgcd[-i-1]))
print(GCD)

Measured memory_bytes: 16112
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#define inf 1e9
#define NODE(x, y, d) (make_pair(make_pair(x, y), d))

using namespace std;
typedef pair<pair<int, int>, int> Node;
typedef pair<int, Node> P;

struct edge{
	Node to;
	int cost;
	edge(){}
	edge(Node a, int b){
		to = a, cost = b;
	}
};

int w, h;
int map[35][35];
int c[4];
vector<edge> G[35][35][4];
int dist[35][35][4];
int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
Node S;

void dijkstra()
{
	for(int x = 1; x <= w; x++){
		for(int y = 1; y <= h; y++){
			for(int d = 0; d < 4; d++){
				dist[x][y][d] = inf;
			}
		}
	}
	dist[1][1][0] = 0;
	
	priority_queue<P, vector<P>, greater<P> > Q;
	Q.push(make_pair(0, S));
	
	int x, y, dir, d;
	while(Q.size()){
		x = Q.top().second.first.first;
		y = Q.top().second.first.second;
		dir = Q.top().second.second;
		d = Q.top().first;
		Q.pop();
		if(dist[x][y][dir] < d) continue;
		for(int i = 0; i < G[x][y][dir].size(); i++){
			Node u = G[x][y][dir][i].to;
			int nx = u.first.first, ny = u.first.second, ndir = u.second;
			if(dist[nx][ny][ndir] > d + G[x][y][dir][i].cost){
				dist[nx][ny][ndir] = d + G[x][y][dir][i].cost;
				Q.push(make_pair(dist[nx][ny][ndir], NODE(nx, ny, ndir)));
			}
		}
	}
}

int main(void)
{
	while(1){
		cin >> w >> h;
		if(w == 0 && h == 0) break;
		for(int y = 1; y <= h; y++){
			for(int x = 1; x <= w; x++){
				cin >> map[x][y];
			}
		}
		for(int i = 0; i < 4; i++) cin >> c[i];
		S = NODE(1, 1, 0);
		
		for(int x = 1; x <= w; x++){
			for(int y = 1; y <= h; y++){
				for(int d = 0; d < 4; d++){
					G[x][y][d].clear();
					
					int nx, ny, nd, cost;
					for(int i = 0; i < 4; i++){
						nd = (d+4-i)%4;
						nx = x + dx[nd], ny = y + dy[nd];
						cost = c[i];
						if(map[x][y] == i) cost = 0;
						
						if(nx <= 0 || nx > w || ny <= 0 || ny > h) continue;
						G[x][y][d].push_back(edge(NODE(nx, ny, nd), cost));
					}
				}
			}
		}
		
		dijkstra();
		
		int ans = inf;
		for(int i = 0; i < 4; i++) ans = min(ans, dist[w][h][i]);
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3612
#pragma warning(disable:4996)

#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <complex>
#include <iterator>
#include <random>
#include <time.h>
#include <tuple>
#include <functional>
#include <list>
#include <limits.h>
#define mp make_pair
#define ni(x) scanf("%d", &(x))
#define nii(x,y) scanf("%d%d",&(x),&(y))
#define mul(x,y) ((ll)(x)*(y)%mod)
#define mtp make_tuple
#define F(i,n) for(int i = 0; i < (n); i++)
#define FF(i,n) for(int i = 1; i <= (n); i++)
#define FE(i,n) for(int i = 0; i <= (n); i++)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int mod = 1000000007;
const int inf = 2012345678;
const ll infl = 9012345678901234567;
const double pi = 3.1415926535897932384626433832795;
//----------------------------------------------------------------------------//


int main() {
#ifndef __GNUG__
	freopen("input.txt", "r", stdin);
#endif
	int n; ni(n);
	int cnt = 0;
	F(i, n) {
		int x; ni(x);
		if (x & 1)cnt++;
	}
	if (cnt & 1)puts("NO");
	else puts("YES");
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 1000000000
#define pi 3.14159265358979323846264338327950L
#define FOR(i,a,b) for(int i=a;i<b;i++)

int main()
{
    //freopen("contest.txt","r",stdin);
    //freopen("contest.txt","w",stdout);
    IOS
    int x,y;
    cin>>x>>y;
    if(y%2!=0)
    {
        cout<<"No"<<endl;
        return 0;
    }
    else if(y<(x*2) || y>(x*4))
    {
        cout<<"No"<<endl;
        return 0;
    }
    else
    {
        cout<<"Yes"<<endl;
    }


    return 0;
}


Measured memory_bytes: 3584
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
      Set<Integer> ac = new HashSet<>();
      int[] penalty = new int[N];
      int total = 0;
		for (int i = 0; i < M; i++) {
         int p = sc.nextInt();
		   String result = sc.next();
         if (result.equals("AC")) {
            if (!ac.contains(p)) {
               ac.add(p);
               total+=penalty[p-1];
            }
         } else {
            if (!ac.contains(p)) {
               penalty[p-1]++;
            }
         }
      }
		System.out.println(ac.size() + " " + total);
	}
}

Measured memory_bytes: 69240
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>
#include <complex>
#include <stdio.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define previous fake_previous
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LD PI = acos(-1.0);
const LL mod = 1000000007;
const LL INF = 1e9;
const LL MAXN = 41;
const LL MAXK = 20;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	LL a, b;
	cin >> a >> b;
	if (a < b)
		swap(a, b);

	if (b <= 0 && a >= 0)
		cout <<"Zero";
	else
	{
		if (b >= 0)
			cout << "Positive";
		else
		{
			LL c = a - b;
			if (c & 1)
				cout << "Positive";
			else
				cout << "Negative";
		}
	}



	return 0;
}

Measured memory_bytes: 256
from math import gcd

N = int(input())
A = list(map(int, input().split()))

g_all = A[0]
for a in A[1:]:
    g_all = gcd(g_all, a)

if g_all > 1:
    print('not coprime')
    quit()

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


appeared = [False] * (10**6 + 1)
primes = sieve(10**3)[1]
for a in A:
    if a == 1:
        continue
    for p in primes:
        if a % p == 0:
            if appeared[p]:
                print('setwise coprime')
                quit()
            appeared[p] = True
            while a % p == 0:
                a //= p
    
    if a != 1:
        if appeared[a]:
            print('setwise coprime')
            quit()
        
        appeared[a] = True

print('pairwise coprime')

Measured memory_bytes: 205028
package main
import (
  "bufio"
  "fmt"
  "os"
  "strconv"
  "strings"
)

const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin,size)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextStringArray() []string {
  return strings.Split(NextLine()," ")
}
func NextIntArray() []int {
  var s []string = strings.Split(NextLine()," ")
  var n int = len(s)
  var a []int = make([]int,n)
  for i:=0;i<n;i++ {
    a[i],_ = strconv.Atoi(s[i])
  }
  return a
}

func main() {
  var n int
  var a []int
  n,_ = strconv.Atoi(NextLine())
  a = NextIntArray()
  var m = map[int]int{}
  for i:=0;i<n;i++ {
    if v,ok := m[a[i]];ok {
      m[a[i]] = v + 1
    } else {
      m[a[i]] = 1
    }
  }
  var s int64 = 0
  for key,val := range m {
    if key < val {
      s += int64(val-key)
    } else if key > val {
      s += int64(val)
    }
  }
  fmt.Println(s)
}

Measured memory_bytes: 8064
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007


constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 

 
int main() {
    int N=0;
    cin >>N;
    ll x[N];
    ll y[N];
    ll h[N];
    ll H[101][101];

    FOR(i,0,N-1){
        cin>>x[i]>>y[i]>>h[i];
    }

    bool F=false;

    FOR(i,0,100){
    FOR(j,0,100){
        F=true;
        ll kari;
        FOR(ii,0,N-1){
            if(h[ii]>0 && (abs(i-x[ii])+abs(j-y[ii])+h[ii])>0){
                kari=abs(i-x[ii])+abs(j-y[ii])+h[ii];
                //cout<<i<<" "<<j<<" "<<ii<<" "<<kari<<endl;
                break;
            }
        }
        FOR(ii,0,N-1){
            if(kari!=abs(i-x[ii])+abs(j-y[ii])+h[ii] && (h[ii])>0){
                F=false;
            }
            if(h[ii]==0){
                if(kari-abs(i-x[ii])-abs(j-y[ii])>0){
                    F=false;
                }
            }
        }
        if(F){cout<<i<<" "<<j<<" "<<kari<<endl;}

    }
    }

  return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
l=[list(map(int,input().split())) for i in range(M)]
maxL=1
minR=N
for j in range(M):
  maxL=max(maxL,l[j][0])
  minR=min(minR,l[j][1])

ans=minR-maxL+1
ans=max(ans,0)
print(ans)

Measured memory_bytes: 27332
#include <iostream>
using namespace std;
 
 
int main() {
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  
  int last, start, study_time;
  last = 60*H2 + M2;
  start = 60*H1 + M1;  
  study_time = (last - K) - start;

cout << study_time << endl;
}
 

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(s);
	LL pos = 1;
	map<LL,bool> present;
	while(true) {
		present[s] = true;
		if(s%2 == 0)	s /= 2;
		else	s = 3*s+1;
		pos++;
		if(present[s])	break;
	}
	pll(pos);
}


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

using namespace std;

template<class INT>
INT mod_pow(INT n, INT k, INT p){
    if (k == 0)
        return 1;
    if (k % 2 == 0){
        INT res = mod_pow(n, k / 2, p);
        return res * res % p;
    }
    return mod_pow(n, k - 1, p) * n % p;
}

template<class INT>
vector<INT> fact(INT n, INT p=INT(1e9 + 7)){
    vector<INT> f(n + 1);
    f[0] = 1;
    for (INT i = 0; i < n; i++)
        f[i + 1] = (i + 1) * f[i] % p;
    return f;
}

template<class INT>
vector<INT> invfact(INT n, const vector<INT> &f, INT p=INT(1e9 + 7)){
    vector<INT> inv(n + 1);
    inv[n] = mod_pow<INT>(f[n], p - 2, p);
    for (INT i = n; i > 0; i--)
        inv[i - 1] = inv[i] * i % p;
    return inv;
}

template<class INT>
INT comb(INT a, INT b, const vector<INT> &f, const vector<INT> &invf, INT p=(INT)(1e9 + 7)){
    if (a < b)
        return 0;
    if (a < 0 or b < 0)
        return 0;
    return f[a] * invf[b] % p * invf[a - b] % p;
}

int main(){
    int n;
    cin >> n;
    vector<int64_t> X(n);
    copy_n(istream_iterator<int64_t>(cin), n, X.begin());
    const int64_t p = 1e9 + 7;

    vector<int64_t> D(n - 1);
    for (int i = 0; i < n - 1; i++){
        D[i] = X[i + 1] - X[i];
        D[i] %= p;
    }

    int64_t ans = 0;
    int64_t S = 0;
    for (int i = 0; i < n - 1; i++){
        S += mod_pow<int64_t>(i + 1, p - 2, p);
        ans += D[i] * S % p;
        ans %= p;
    }

    auto f = fact<int64_t>(n, p);
    
    cout << ans * f[n - 1] % p << endl;
}

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

N = int(input())
A = list(map(int, input().split()))
ans = 1
MOD = 10**9+7
r, g, b = 0, 0, 0

for Ai in A:
    cnt = 0
    
    if r==Ai:
        cnt += 1
    
    if g==Ai:
        cnt += 1
    
    if b==Ai:
        cnt += 1
        
    ans *= cnt
    ans %= MOD
    
    if r==Ai:
        r += 1
    elif g==Ai:
        g += 1
    else:
        b += 1
    
print(ans)

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

int main() {
  int a, b;
  cin >> a >> b;
  rep(i, 1300) {
    if(i * 8 / 100 == a && i / 10 == b) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}


Measured memory_bytes: 3640
#pragma region def
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
using pint = pair<int, int>;
const int INF = 1e9;
const long long llINF = 1e18;
#pragma endregion

llint convert(llint x, llint n){
    llint y=0, i=0, z;
    while(x > 0){
        z = x%n;
        y += z*pow(10, i);
        x = x/n;
        i++;
    }
    return y;
}

llint getDigit (llint x){
    llint digit = 0;
    while (x != 0) {
        x /= 10;
        digit++;
    }
    return digit;
}

int main () {
    llint n, k; cin >> n >> k;
    llint ans = 0;
    while (n >= k) {
        n = n / k;
        ans++;
    }
    cout << ++ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

vector<int> d(100,0);

void primefact(int N){
    vector<pair<int,int>> ans(0);
    int a=2;
    while(N>=a*a){
        if(N%a==0){
            ans.push_back({a,0});
            int A=ans.size()-1;
            while(N%a==0){
                ans.at(A).second++;
                N/=a;
            }
        }
        a++;
    }
    if(N>1)ans.push_back({N,1});
    rep(i,sz(ans)){
        d.at(ans.at(i).first)+=ans.at(i).second;
    }
    return;
}

int main() {
    int N;
    cin>>N;
    for(int i=1;i<=N;i++)primefact(i);
    vector<int> D(0);
    rep(i,100){
        if(d.at(i))D.pb(d.at(i));
    }
    vector<vector<int>> dp(sz(D)+1,vector<int>(76));
    vector<int> list={1,3,5,15,25,75};
    dp.at(0).at(1)=1;
    rep(j,sz(D)){
        int x=D.at(j);
        for(int i=0;i<6;i++){
            if(x<list.at(i)-1)break;
            rep(k,6){
                if(list.at(k)*list.at(i)<76)dp.at(j+1).at(list.at(k)*list.at(i))+=dp.at(j).at(list.at(k));
            }
        }
    }
    cout<<dp.at(sz(D)).at(75)<<endl;
}

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

int main()
{
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    ll a[n], b[n];
    vector<pair<ll, ll>> v;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
        v.push_back(make_pair(a[i], b[i]));
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n && m > 0; i++)
    {
        pair<ll, ll> p = v[i];
        ll s = p.first, t = p.second;
        if (m - t > 0)
            m -= t, ans += s * t;
        else
            ans += s * m, m = 0;
    }
    cout << ans << endl;
}

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

int main()
{
    int n;cin>>n;
    string s;cin>>s;
    string ans,temp;
    stack<char>st;
    for(int i=0;i<s.length();)
    {
        if(s[i]=='(')
        {
            ans+=s[i];
            st.push(s[i]);
            i++;
        }
        else
        {
            if(st.empty())
            {
                int cnt=0;
                while(s[i]==')'&&i<s.length())
                {
                    cnt++;
                    i++;
                    temp+='(';
                }
                while(cnt--)ans+=')';
            }
            else {
                st.pop();
                ans+=')';
                i++;
            }
        }
    }
    while(!st.empty()){
        st.pop();
        ans+=')';
    }
    ans=temp+ans;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int n;
int m;
bool mark[N];
int parent[N];

int getP(int u){
    if(parent[u] == u)
        return u;
    return parent[u] = getP(parent[u]);
}

void join(int u , int v){
    u = getP(u);
    v = getP(v);
    parent[u] = v;
}

int main(){
    scanf("%d%d" , &n , &m);
    for(int i = 1; i <= n; i++){
        parent[i] = i;
    }
    for(int i = 1; i <= m; i++){
        int u , v , w;
        scanf("%d%d%d" , &u , &v , &w);
        join(u , v);
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(mark[getP(i)])
            continue;
        cnt++;
        mark[getP(i)] = 1;
    }
    printf("%d\n" , cnt);
}

Measured memory_bytes: 1152
/** author: __nishad__ **/
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(ll i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    int m, n, sum=0;
    cin>>m;

    n = m;

    while(n>0){
        sum = sum + n%10;
        n = n/10;
    }

    if(m%sum == 0)
        cout<<"Yes";
    else
        cout<<"No";

}






























Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string bans(bool ans){
  return (ans?"Even":"Odd");
}
int main() {
  int a,b;cin>>a>>b;
  bool ans=(a*b)%2==0;
  cout << bans(ans) << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    long long a[n], s=0, dp[n];
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n; i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
D,G = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(D)]
ans = 0

for i in range(2**D):
	point = 0
	count = 0
	for j in range(D):
		if (i>>j)&1:
			point += 100*(j+1)*X[j][0]+X[j][1]
			count += X[j][0]
	if 	G > point:
		for k in range(D)[::-1]:
			if (i>>k)&1==0:
				if (G-point) <= 100*(k+1)*(X[k][0]-1):
					count += -((-(G-point)) // (100*(k+1)))
					break
				else:
					count = 10**5
					break
	if ans == 0 or count < ans:
		ans = count

print(ans)

Measured memory_bytes: 41200
def isPrime(n): 

	if n <= 1: 
		return False

	for i in range(2, n): 
		if n % i == 0: 
			return False; 

	return True

x=int(input())
if isPrime(x): print(x)
while not isPrime(x):
    x+=1
    if isPrime(x): print(x)
    
    

Measured memory_bytes: 2940
#include <algorithm>
#include <cstdio>
#include <tuple>
#include <vector>

#define int long long
#define dotimes(i, n) for (int i : range(n))

using namespace std;

class range {
  class iterator {
    int i, s;
  public:
    iterator(int i, int s): i(i), s(s) {}
    int& operator*() {
      return i;
    }
    void operator++() {
      i += s;
    }
    bool operator!=(iterator const& that) {
      return i < that.i;
    }
  };
  iterator b, e;
public:
  range(int e): b({0, 1}), e({e, 1}) {}
  range(int b, int e): b({b, 1}), e({e, 1}) {}
  range(int b, int e, int s): b({b, s}), e({e, s}) {}
  iterator begin() {
    return b;
  }
  iterator end() {
    return e;
  }
};

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

template<typename T>
inline int size(T container) {
  return static_cast<int>(container.size());
}

template<typename T>
inline bool maxs(T& a, T const& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T>
inline bool mins(T& a, T const& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

struct union_find {
  vector<int> p;
  union_find(int n): p(n) {
    dotimes(x, n)
      p[x] = x;
  }
  int find(int x) {
    while (x != p[x]) {
      int y = p[x];
      p[x] = p[y];
      x = y;
    }
    return x;
  }
  bool eqv(int x, int y) {
    int a = find(x), b = find(y);
    return a == b;
  }
  bool unite(int x, int y) {
    int a = find(x), b = find(y);
    if (a == b)
      return false;
    if (!(a < b))
      swap(a, b);
    p[b] = a;
    return true;
  }
};

signed main() {
  int N = rint();
  pair<int, int> x[N], y[N];
  dotimes(i, N) {
    x[i].first = rint();
    y[i].first = rint();
    x[i].second = i;
    y[i].second = i;
  }
  sort(x, x + N);
  sort(y, y + N);
  tuple<int, int, int> edges[2 * (N - 1)];
  dotimes(i, N - 1) {
    edges[2*i] = make_tuple(x[i+1].first - x[i].first, x[i].second, x[i+1].second);
    edges[2*i+1] = make_tuple(y[i+1].first - y[i].first, y[i].second, y[i+1].second);
  }
  sort(edges, edges + 2 * (N - 1));
  union_find uf(N);
  int r = 0;
  dotimes(i, 2 * (N - 1)) {
    if (uf.unite(get<1>(edges[i]), get<2>(edges[i])))
      r += get<0>(edges[i]);
  }
  wint(r);
  return 0;
}


Measured memory_bytes: 8832
//code by PARTH_4399 for competitive programming
#include<bits/stdc++.h>
using namespace std;
#define l long // -2^31 to +2^31-1 (upper limit ~ 2*(10^9))
#define ul unsigned long // 0 to +2^32-1
#define ll long long // -2^63 to +2^63-1 (upper limit ~ 9*(10^18))
#define ull unsigned long long // 0 to +2^64-1
#define mod(x, m) ((((x)%(m))+(m))%(m))
#define vi vector<int>
#define pi pair<int,int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
//const double pi=acos(-1.0); // cout<<fixed<<setprecision(n)<<pi; - for n decimal digits, use <iomanip.h>
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//code
	ll int n,i,count=0;
	cin>>n;
	ll int a[n],b[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		b[i]=a[i];
	}
	sort(a,a+n);
	for(i=0;i<n;i++)
	{
		if(a[i]!=b[i])
		count++;
		if(count>2)
		break;
	}
	if(count==2 || count==0)
	cout<<"YES";
	else
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int a,b,c,f[15]; 
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(a);printf("%d\n",(1+a)*a/2);
	return 0;
}


Measured memory_bytes: 256
#include "stdio.h"

int main(int argc, char const *argv[]) {
  char S[10];
  for (size_t i = 0; i < 10; i++) {
    scanf("%c", &S[i]);
  }
  int tuki=10*(S[5]-'0')+S[6]-'0';
  int niti=10*(S[8]-'0')+S[9]-'0';
  if (tuki>=5 || (tuki==4 && niti==31)) {
    printf("TBD");
    return 0;
  }
  printf("Heisei");
  return 0;
}


Measured memory_bytes: 128