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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef map<int, int> mint;
typedef vector<int> vint;
typedef vector<char> vch;
typedef vector<long long> vll;
typedef vector<string> vstr;


int mod(int a, int b){return (a%b+b)%b;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b){ll ans=1; rep(i, b){ans=ans*a%MOD;} return ans;}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}

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




template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}


vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}



int f(ll a, ll b){
    if(to_string(a).size() > to_string(b).size())
        return to_string(a).size();
    else
        return to_string(b).size();
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n;
    cin >> n;

    int ans = INF;

    for(int a=1; a<=sqrt(n); a++){
        if(n%a == 0){
            int b = n/a;
            ans = min(ans, f(a,b));
            dpp(a);
            dpp(b);
            dpp(ans);
        }


    }


    ppp(ans);

    return 0;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;

    priority_queue<int> q;
    for(int i=0; i<n; i++){
        int temp;
        cin >> temp;
        q.push(temp);
    }

    while(m--){
        int temp = q.top(); q.pop();
        temp = temp>>1;
        q.push(temp);
    }

    long long int ans = 0;
    while(n--){
        ans += q.top(); q.pop();
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define EPS (1e-10)

int used[20];
int cx[20],cy[20];
int dx,dy;
int n;
int tmp;

void dragon(int c,double sum,int hx,int hy)
{
	int i;
	double r;
	
	if(tmp)return;

	if(c==n){
		tmp = 1;
		return;
	}
	
	for(i=0;i<n;i++){
		if(used[i]==0){
		  r = sum + sqrt((hx-cx[i])*(hx-cx[i])+(hy-cy[i])*(hy-cy[i]));
			if(r + EPS > sqrt((dx-cx[i])*(dx-cx[i])+(dy-cy[i])*(dy-cy[i])) )return;
		}
	}
	
	for(i=0;i<n;i++){
		if(used[i]==0){
			used[i]=1;
			r = sum + sqrt((hx-cx[i])*(hx-cx[i])+(hy-cy[i])*(hy-cy[i]));
			dragon(c+1,r,cx[i],cy[i]);
			used[i]=0;
		}
	}
}

int main(void)
{
	int i,j,c;
	int hx,hy;

	while(1)
	{
		scanf("%d %d %d %d %d",&n,&hx,&hy,&dx,&dy);
		if(n==0 && hx==0 && hy==0 && dx==0 && dy==0)break;
		
		for(i=0;i<n;i++){
			scanf("%d %d",&cx[i],&cy[i]);
		}
	  
		for(i=0;i<n;i++){
			used[i]=0;
		}
    
    tmp = 0;
    dragon(0,0.0,hx,hy);
		if(tmp){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
		
	}
	return 0;
	
}	


		

Measured memory_bytes: 380
#include<stdio.h>
#include<string.h>

#define N 1000

int LCS(char X[],char Y[]);

  
int main(void){
  int i,n;
  char s1[N],s2[N];
  
  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%s %s",s1,s2);
    printf("%d\n",LCS(s1,s2));
  }

  return 0;
}



int LCS(char X[],char Y[]){
  int i,j;
  int c[N+1][N+1];
  int n = strlen(X) + 1;
  int m = strlen(Y) + 1;
  int maxl = 0;
    
  for(i = 1;i < n;i++){ 
    for(j = 1;j < m;j++){
      if(X[i-1] == Y[j-1]){ 
	c[i][j] = c[i-1][j-1] + 1;
      } else {
	if(c[i][j-1] < c[i-1][j]){
	  c[i][j] = c[i-1][j];
	} else {
	  c[i][j] = c[i][j-1];
	}
      }
	    
      if(c[i][j] > maxl){
	maxl = c[i][j];
      }
	  
    }
  }
  
  return maxl;
}



Measured memory_bytes: 5684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

struct que {
    int a;
    int b;
    int c;
    ll d;
};

int N, M, Q;

vector<que> q;
ll ans;

ll check(vector<int> x, vector<que> q)
{
    ll tmp = 0;

    rep(i, Q)
    {
        if (x[q[i].b] - x[q[i].a] == q[i].c) {
            tmp += q[i].d;
        }
    }

    return tmp;
}


void dfs(vector<int> x, int j)
{
    chmax(ans, check(x, q));
    bool flag = true;
    rep(i, N)
    {
        if (x[i] < M) {
            flag = false;
        }
    }
    if (flag) {
        return;
    }


    if (j >= 0) {
        if (j < N - 1) {
            for (int i = 2; i <= x[j + 1]; i++) {
                x[j] = i;
                dfs(x, j - 1);
            }
        } else {
            for (int i = 2; i <= M; i++) {
                x[N - 1] = i;
                dfs(x, N - 2);
            }
        }
    }
}


int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M >> Q;

    vector<int> pos(N, 1);

    ans = 0;

    q.resize(Q);
    rep(i, Q)
    {
        cin >> q[i].a >> q[i].b >> q[i].c >> q[i].d;
        --q[i].a;
        --q[i].b;
    }


    dfs(pos, N - 1);

    cout << ans << endl;
}


Measured memory_bytes: 3620
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = NextInt()
        Dim M As Integer = CInt(Int(Math.Sqrt(N)))
        WriteLine(Math.Pow(M, 2))
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define N 100002
char s[N],t[N];
vector<int>p[30];
int main()
{
	scanf("%s%s",s+1,t+1);
	int ls=strlen(s+1),lt=strlen(t+1);
	for(int i=1;i<=ls;i++)
		p[s[i]-'a'].push_back(i);
	ll las=0,ans=0;
	for(int i=1;i<=lt;i++)
	{
		int a=t[i]-'a',siz=p[a].size();
		if(siz==0)
		{
			printf("-1");
			return 0;
		}
		if(p[a][siz-1]<=las)las=0,ans+=ls;
		las=*upper_bound(p[a].begin(),p[a].end(),las);
	}
	printf("%lld",ans+las);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int dp[45];
int main()
{
    int n;
    cin>>n;
    dp[0]=dp[1]=1;
    for(int i=2;i<=n;i++)
    {
        dp[i]=dp[i-1]+dp[i-2];
    }
    cout<<dp[n]<<"\n";
    return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include <iomanip>

using namespace std;
int main()
{
  double s;

  for(;cin>>s;)
    {
  double sum=s;
  for(int i=2;i<=10;i++)
    {
      if(i%2==0)
	s*=2;
      else
	s/=3;
      sum+=s;
    }
   cout<< fixed << setprecision(8)<<sum<<endl;
    }
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N, 0);
    REP(i, N)
    {
        cin >> A[i];
    }

    sort(A.begin(), A.end());
    int num = A[0];
    int count = 1;
    priority_queue<int, vector<int>, greater<int> > q;
    for (int i = 1; i < N; ++i)
    {
        if (A[i] == num)
        {
            count++;
        }
        else
        {
            q.push(count);
            num = A[i];
            count = 1;
        }
    }
    q.push(count);
    
    int ans = 0;
    while(q.size() > K)
    {
        ans += q.top();
        q.pop();
    }

    cout << ans << endl;
}


Measured memory_bytes: 2168
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	answer := minSnack(a, b)
	fmt.Println(answer)
}

func minSnack(a, b int) int {
	if a == 1 {
		return b
	} else if b == 1 {
		return a
	}
	aDivisors := findDivisors(a)
	bDivisors := findDivisors(b)
	var divisors []int
	finA := false
	finB := false

	for a, b := 0, 0; ; {
		if !finA && !finB && aDivisors[a] == bDivisors[b] {
			divisors = append(divisors, aDivisors[a])
			a++
			b++
		} else if finB || !finA && aDivisors[a] <= bDivisors[b] {
			divisors = append(divisors, aDivisors[a])
			a++
		} else if finA || !finB && aDivisors[a] >= bDivisors[b] {
			divisors = append(divisors, bDivisors[b])
			b++
		}
		if len(aDivisors) <= a {
			finA = true
		}
		if len(bDivisors) <= b {
			finB = true
		}
		if finA && finB {
			break
		}
	}
	minS := 1
	for _, v := range divisors {
		minS *= v
	}
	return minS
}

func findDivisors(x int) []int {
	var divisors []int
	for i := 2; i <= x; i++ {
		if x%i == 0 {
			x /= i
			divisors = append(divisors, i)
			i--
		}
	}
	return divisors
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
using namespace std;
int main(void){
  int n;
  cin>>n;
  int t=n;
  int s(0);
  while(t>0){
    s+=t%10;
    t/=10;
  }
  if(n%s==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
li = [list(map(int, input().split())) for i in range(n)]
li.sort(key=lambda x: x[1])
time = 0
for i in range(n):
    time += li[i][0]
    if time > li[i][1]:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 54212
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define MOD 1000000009
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >>n;
  vector<int > L(n);
  REP(i,n){
    cin >> L[i] ;
  }
  std::sort(L.begin(), L.end());
//  REP(i,n){
//    cout << L[i] << endl;
//  }
  long long num = 0;
  int b;
  int x;
  int ind_c;
  for (int i = 0; i < n - 2;i ++ ){
	int a = L[i];
	for (int j = i + 1; j < n - 1; j ++){
		b = L[j];
      	auto itr_l = L.begin() + j;
      	x = a + b ;
      	auto itr_c = lower_bound(itr_l, L.end(),x);
		ind_c = itr_c  - L.begin() -1;
//		cout << i <<" " << j << " " << a << " " << b << " " << ind_c << " "<< L[ind_c] << endl;	
	    if(ind_c > j){
			num += ind_c - j; 
		}
	}
}	
	cout << num << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0031
public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while (sc.hasNextInt()) {
			String s = Integer.toString(sc.nextInt(), 2);
			for (int i = s.length() - 1; i >= 0; i--) {
				if (s.charAt(i) == '1') {
					System.out.print((int)pow(2, s.length() - i - 1));
					if (i != 0) 
						System.out.print(" ");
				} else {
					
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
#![allow(non_snake_case)]
use std::io::*;
use std::str::FromStr;


fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
    token.parse().ok().expect("failed to parse token")
}

/*
6 1000000000
695 343 933 872 827 350
*/
fn main() {
    let n: usize = read();
    let k: i64 = read();
    let a: Vec<usize> = (0..n).map(|_| read()).collect();
    let max = *a.iter().max().unwrap();
    let mut left = 0;
    let mut right = max;

    while left < right -1 {
        let findLength = (left + right) / 2;
        let mut cut = 0;
        for &i in a.iter() {
            cut += ((i as f64) / (findLength as f64)).ceil() as i64 - 1;
        }
        if cut > k {
            left = findLength;
        } else {
            right = findLength;
        }
    }
    print!("{}", right);
}


Measured memory_bytes: 3860
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <set>
#include <map>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)

using namespace std;
typedef long long ll;

int N;

struct Permutation{
    vector<int> x;
    int sz;
    
    Permutation(){
        ;
    }
    
    Permutation(int a):sz(a){
        x.resize(sz);
        for(int i = 0;i < sz;i++){
            x[i]=i;
        }
    }
    
    int &operator[](int a){
        return x[a];
    }
    
    Permutation &operator=(const Permutation &a){
        sz = a.sz;
        x.resize(sz);
        for(int i = 0;i < sz;i++){
            x[i]=a.x[i];
        }
        return (*this);
    }
    
    void show(){
        for(int i =0 ;i<sz-1;i++){
            cout<<x[i]+1<<" ";
        }
        cout<<x[sz-1]+1<<endl;
    }
    


    Permutation operator *(const Permutation &B){
        Permutation ret(sz);
        for(int i = 0;i < sz;i++){
            ret.x[i]=x[B.x[i]];
        }
        return ret;
    }

    
    Permutation operator *(ll X){
        Permutation ret(sz);
        Permutation A = *this;
        while(X>0){
            if(X%2==1)ret = ret*A;
            A=A*A;
            X>>=1;
        }
        return ret;
    }
};

Permutation inv(const Permutation &A){
    Permutation ret(A.sz);
    for(int i = 0;i < A.sz;i++){
        ret[A.x[i]]=i;
    }
    return ret;
}

Permutation id;

void init(){
    id.sz=N;
    id.x.reserve(N);
    for(int i = 0;i < N;i++){
        id.x.push_back(i);
    }
}

int main(){
    ll K;
    cin>>N>>K;
    K--;
    init();
    Permutation P(N),Q(N),Pi,Qi;
    vector<Permutation> A(6);
    vector<Permutation> B(6);
    Permutation T;
    for(int i = 0;i< N;i++){
        cin>>P[i];
        P[i]--;
    }
    for(int i = 0;i< N;i++){
        cin>>Q[i];
        Q[i]--;
    }
    Pi=inv(P);
    Qi=inv(Q);
    B[0]=P;
    B[1]=Q;
    B[2]=Q*Pi;
    B[3]=Pi;
    B[4]=Qi;
    B[5]=Qi*P;
    A[0]=id;
    A[1]=id;
    A[2]=id;
    A[3]=Q;
    A[4]=Q*Pi;
    A[5]=Q*Pi;
//    cout<<"B:"<<endl;
//    for(int i = 0;i < 6;i++){B[i].show();};
//    cout<<"A:"<<endl;
//    for(int i = 0;i < 6;i++){A[i].show();};
    T= Q*Pi*Qi*P;
    T = (T*(K/6));
    T = (T*A[K%6]);
    Permutation ans = T*B[K%6]*inv(T);
    ans.show();
}


Measured memory_bytes: 9080
#include <iostream>

using namespace std;

int main()
{
	int N, L;
	cin >> N >> L;

	const int T = N * L + N * (N - 1) / 2;
	int x = 1;
	int ans = T - (L + x - 1);

	for (int i = 1; i <= N; ++i) {
		int Ax = L + x - 1;
		int Ai = L + i - 1;
		int Px = T - Ax;
		int Pi = T - Ai;
		if (abs(T - Pi) < abs(T - Px)) {
			x = i;
			ans = Pi;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;

#define TSIZE 1000000

int a2i(char *str){
  int r=0,i=0;
  while (str[i]!='\0'){
    r *= 5;
    if (str[i]=='A'){
      r += 1;
    }else if (str[i]=='C'){
      r += 2;
    }else if (str[i]=='G'){
      r += 3;
    }else if (str[i]=='T'){
      r += 4;
    }
    i++;
  }
  return r;
}

int hash(int k,int i){
  return (k + i*( (k-1)%(TSIZE-1) ) )%TSIZE;
}

int main(){
  int n,k,j;
  char cmd[10],str[15];
  int table[TSIZE];

  for (int i=0;i<TSIZE;i++)table[i]=-1;
  
  cin >> n;

  for (int i=0;i<n;i++){
    cin >> cmd >> str;
    if (cmd[0]=='i'){
      k=a2i(str);
      j=0;
      while (table[hash(k,j)]!=-1&&table[hash(k,j)]!=k) j++;
      table[hash(k,j)]=k;
    }else{
      k=a2i(str);
      j=0;
      while (table[hash(k,j)]!=-1&&table[hash(k,j)]!=k)j++;
      if (table[hash(k,j)]==k) cout << "yes" << endl;
      else cout << "no" << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 7008
#include <stdio.h>

using namespace std;

int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((x >= r && x <= W-r) && (y >= r && y <= H-r))
		printf("Yes\n");
	else{
		printf("No\n");
	}
}



Measured memory_bytes: 2608
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int c[] = new int[26];
		for(int i=0; i<c.length;i++){
			c[i] = 0;
		}
		for(int i=0;i<S.length();i++){
			c[(int)S.charAt(i)-97]++;
		}
		for(int i=0; i<c.length; i++){
			if(c[i]==0) {
				System.out.println((char)(i+97));
				return;
			}
		}
		System.out.println("None");


	}
}




Measured memory_bytes: 23764
#include <iostream>
#include <stdio.h>
#include<algorithm>
#include <math.h>
#include <string.h>
#define eps 1e-9
typedef long long int ll;
using namespace std;
char a[200];
int main()
{
    cin>>a;
    int n=strlen(a);
    for(int i=0;i<n;i++)
    {
        cout<<"x";
    }
    return 0;
}


Measured memory_bytes: 256
let rec is_prime p n =
  if n < p * p
  then true
  else 0 < n mod p && is_prime (p + 1) n
let is_prime = is_prime 2

let rec solve n =
  if is_prime n then n else solve (n + 1)

let () = Printf.printf "%d" @@ Scanf.scanf "%d\n" @@ solve


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

int pre[1005];

int main(){
	pre[0] = 0;
	for (int i = 1; i <= 1000; ++i){
		pre[i] = pre[i-1] + i;
	}
	int a,b; scanf("%d%d",&a,&b);
	printf("%d\n",pre[b-a] - b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
#define ll long long int
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define rep(i,l,r) for(i=l;i<r;i++)
#define bep(i,l,r) for(i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
int main()
{
    io;
    int n;
    cin>>n;
    vector<pii>a(n);
    int i;
    rep(i,0,n)
    {
    cin>>a[i].ff;
    a[i].ss=i;
    }
    sort(a.begin(),a.end());
    int pos=a[n-1].ss;
    rep(i,0,n)
    {
        if(i==pos)
            cout<<a[n-2].ff<<"\n";
        else
            cout<<a[n-1].ff<<"\n";
    }
    return 0;
}


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

using namespace std;

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

struct UnionFind {
    vector<int> par; 

    UnionFind(int N) : par(N) { 
        rep(i,N) par[i] = i;
    }

    int root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        x = root(x); 
        y = root(y); 
        if (x == y) return; 
        par[x] = y; 
    }

    bool same(int x, int y) { 
      return root(x)== root(y);
    }

};

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

  rep(i,m){
   int x,y,z;
    cin >> x >> y >> z;
    x--;
    y--;
    u.unite(x,y);
  }
  
  int res=0;
  set<int> s;
  rep(i,n) s.insert(u.root(i));
  
  cout << s.size() << endl;
  
}

Measured memory_bytes: 5376
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
const string FILENAME = "input";



int h, w;
string s[1400];
int dist[1400][1400];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	queue<pair<int, int> > q;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') {
				dist[i][j] = 0;
				q.push({i, j});
			} else {
				dist[i][j] = 1e9;
			}
		}
	}
	int ans = 0;
	while (!q.empty()) {
		auto a = q.front();
		q.pop();
		chkmax(ans, dist[a.first][a.second]);
		for (int k = 0; k < 4; k++) {
			int i = a.first + dx[k];
			int j = a.second + dy[k];
			if (i < 0 || i >= h || j < 0 || j >= w) {
				continue;
			}
			if (dist[i][j] > dist[a.first][a.second] + 1) {
				dist[i][j] = dist[a.first][a.second] + 1;
				q.push({i, j});
			}
		}
	}
	cout << ans << '\n';
	return 0; 	
}

Measured memory_bytes: 15632
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};
bool tate[32][32], yoko[32][32], v[32][32][900];
int cy[32][32][32][32], ct[32][32][32][32];
int h, w;

void calc(int c[32][32]){
	queue<int> q;
	c[h - 1][w - 1] = 0;
	q.push(h * w - 1);
	while(!q.empty()){
		int y = q.front() / w, x = q.front() % w;
		q.pop();
		rep(d, 4){
			int ny = y + dy[d], nx = x + dx[d];
			if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
			if(d % 2 && tate[ny][max(nx, x)] || d % 2 == 0 && yoko[max(ny, y)][nx]) continue;
			if(c[ny][nx] <= c[y][x] + 1) continue;
			c[ny][nx] = c[y][x] + 1;
			q.push(ny * w + nx);
		}
	}
}

int main(){
	while(cin >> h >> w, h){
		memset(tate, 1, sizeof(tate));
		memset(yoko, 1, sizeof(yoko));
		memset(v, 0, sizeof(v));
		
		rep(i, h){
			rep(j, w - 1) cin >> tate[i][j + 1];
			if(i < h - 1) rep(j, w) cin >> yoko[i + 1][j];
		}
		rep(i, h) rep(j, w){
			rep(k, h) rep(l, w) ct[i][j][k][l] = cy[i][j][k][l] = inf;
			if(!tate[i][j]){
				tate[i][j] = 1;
				calc(ct[i][j]);
				tate[i][j] = 0;
			}
			if(!yoko[i][j]){
				yoko[i][j] = 1;
				calc(cy[i][j]);
				yoko[i][j] = 0;
			}
		}
		
		priority_queue<pair<pi, int> > q;
		q.push(mp(mp(0, 0), 0));
		int ans = inf;
		while(!q.empty()){
			int cost = -q.top().first.first, step = -q.top().first.second;
			int y = q.top().second / w, x = q.top().second % w;
			q.pop();
			
			if(v[y][x][step]) continue;
			v[y][x][step] = 1;
			if(y == h - 1 && x == w - 1){
				cout << cost << endl;
				goto END;
			}
			rep(d, 4){
				int ny = y + dy[d], nx = x + dx[d];
				if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
				
				int goal = d % 2 ? ct[ny][max(x, nx)][y][x] : cy[max(ny, y)][nx][y][x];
				if(goal >= inf) continue;
				
				int nc = max(step + 1, max(cost, step + goal));
				if(!v[ny][nx][step + 1] && nc < inf) q.push(mp(mp(-nc, -step - 1), ny * w + nx));
			}
		}
		cout << -1 << endl;
		END:;
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> t(N+1), x(N+1), y(N+1);
  t.at(0) = 0;
  x.at(0) = 0;
  y.at(0) = 0;
  for (int i = 1; i < N+1; i++) {
    cin >> t.at(i) >> x.at(i) >> y.at(i);
  }
  
  bool flag = true;
  for (int i = 1; i < N+1; i++) {
    int dt = t.at(i) - t.at(i-1);
    int dx = x.at(i) - x.at(i-1);
    int dy = y.at(i) - y.at(i-1); 
    int dl = (abs(dx) + abs(dy));
    
    if(dt/dl == 0 || dt%dl != 0) {
      flag = false;
      break;
    }
  }
  
  if(flag) 
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 1408
from Queue import Queue
mv=((1,0),(-1,0),(0,1),(0,-1))
while True:
    w,h=map(int,raw_input().split())
    if w==h==0:break
    INF=1e3
    dist=[[INF]*w for i in range(h)]
    L=[raw_input() for i in range(2*h-1)]
    Q=Queue()
    Q.put((0,0,1))
    dist[0][0]=1
    while not Q.empty():
        x,y,d=Q.get()
        for dx,dy in mv:
            mx=x+dx
            my=y+dy
            if mx<0 or w<=mx or my<0 or h<=my:
                continue
            if dist[my][mx]>d+1 and L[y*2+dy][x*2+dx]=="0":
                dist[my][mx]=d+1
                Q.put((mx,my,d+1))
    print dist[h-1][w-1] if dist[h-1][w-1]!=INF else 0

Measured memory_bytes: 4896
import java.util.Scanner;

public class Main {
	private int[] a;
	private String[] ori;
	private String[] se;
	
	private Scanner sc;

	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		int lim = Integer.parseInt(sc.nextLine());
		
		a = new int[lim];
		ori = new String[lim];
		se = new String[lim];
		for (int i = 0; i < lim; i++) {
			ori[i] = sc.nextLine();
			se[i] = ori[i];
			a[i] = Integer.parseInt(se[i].split(" ")[1]);
		}
		quickSort(0, (lim - 1));
		
		boolean flag = false;
		int scope = a[0];
		for (int i = 0; i < lim; i++) {
			flag = false;
			for (int j = 0; j < lim; j++) {
				if (se[i].equals(ori[j])) {
					if (i == (lim - 1) || (scope != a[i + 1])) {
						flag = true;
						break;
					} else {
						i++;
					}
				}
			}
			
			if (flag == false) break;
			if (i != (lim - 1)) scope = a[i + 1];
			
		}
		if (flag) System.out.println("Stable");
		else System.out.println("Not stable");
		
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < lim; i++) {
			sb.append(se[i] + "\n");	
		}
		System.out.print(sb);
	}
	
	private void quickSort(int p, int r) {
		if (p < r) {
			int q = partition(p, r);
			quickSort(p, (q - 1));
			quickSort((q + 1), r);
		}
		
	}
	
	private int partition(int p, int r) {
		int x = a[r];
		int i = p - 1;
		
		int tmp;
		String stmp;
		
		for (int j = p; j < r; j++) {
			if (a[j] <= x) {
				i = i + 1;
				
				tmp = a[i];
				stmp = se[i];
				
				a[i] = a[j];
				se[i] = se[j];
				
				a[j] = tmp;
				se[j] = stmp;
			}
		}
		
		tmp = a[i + 1];
		stmp = se[i + 1];
		
		a[i + 1] = a[r];
		se[i + 1] = se[r];
		
		a[r] = tmp;
		se[r] = stmp;
		return (i + 1);
	}
}

Measured memory_bytes: 167020
n=int(input())
s=input()
d={}
for i in range(n):
    if s[i] in d.keys():
        d[s[i]]+=1
    else:
        d[s[i]]=1
w=1
for i in d.values():
    w*=(i+1)
    w=w%(1e9+7)
    #1e9+7より大きかったら引くだけでは次にオーバーフローする可能性あり
    #かといって1e8+7とかにしてもダメ、
    #しかもこれだと最終解を出す時に正になるまで足し続けないといけなくて、オーバーフロー
    #毎回余りを出せば良い
if w==0:
    print(1e9+6)
else:
    print(int(w-1))


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <climits>
#include <unordered_map>
#include <numeric>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<int,int> pii;
inline int getint() {
	register char ch;
	while(!isdigit(ch=getchar()));
	register int x=ch^'0';
	while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
	return x;
}
ll vec[3000];
int main(){
    int n = getint();
    int sz = 0;
    while(n--){
        vec[sz++] = (ll)getint();
        while(sz >= 3 and vec[sz-1] <= vec[sz-2] and vec[sz-3] <= vec[sz-2]){
            vec[sz-3] = vec[sz-1] + vec[sz-3] - vec[sz-2];
            sz-=2;
        }
    }
    ll ans = 0;
    int i = 0, j = sz-1;
    int k = 1;
    while(i<=j){
        if(vec[i] > vec[j]){
            ans += vec[i]*k;
            i++;
        }else{
            ans += vec[j]*k;
            j--;
        }
        k *= -1;
    }
    printf("%lld", ans);
}

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

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

    long long ans = -9999999999;
    long long minv = 9999999;
    vector<pair<int,int> > r(n);
    for(int i = 0; i < n; i++){
        long long tmp;
        cin >> tmp;
        if(i == 0){
            minv = tmp;
        }
        else
        {
            ans = max(ans, tmp - minv);
            minv = min(minv, tmp);
        }
        

    }

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


Measured memory_bytes: 4384
a,b,c = map(int,input().split())
ans = 0
for i in range(10 ** 5):
         if (a % 2 == 1) or (b % 2 == 1) or (c % 2 == 1):
                  print(ans)
                  exit()
         tmpa = a
         tmpb = b
         tmpc = c
         a = (tmpb // 2) + (tmpc // 2)
         b = (tmpc // 2) + (tmpa // 2)
         c = (tmpa // 2) + (tmpb // 2)
         ans += 1
print(-1)


Measured memory_bytes: 9096
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int n; cin>>n;
  int a=0,b=0,x=0,y=0;
  rep(i,0,n){
    string s; cin>>s;
    if(s=="AC") a++;
    else if(s=="WA") b++;
    else if(s=="TLE") x++;
    else y++;
  }
  co("AC x "<<a);
  co("WA x "<<b);
  co("TLE x "<<x);
  co("RE x "<<y);
    
  return 0;
}

Measured memory_bytes: 3628
fun main(args: Array<String>) {
    val (a, v) = readLine()?.split(" ")?.map(String::toLong)?: return
    val (b, w) = readLine()?.split(" ")?.map(String::toLong)?: return
    val t = readLine()?.toLong()?: return
    if (Math.abs(a-b)  <= (v - w) * t) {
        println("YES")
    } else {
        println("NO")
    }
}


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

int main() {
  string s; cin >> s;
  int n = s.size();
  vll a(n+1);
  for (int i = 0; i <= n; i++)
    if (s[i] == '<') a[i+1] = max(a[i+1], a[i] + 1);
  for (int i = n; i >= 0; i--)
    if (s[i] == '>') a[i] = max(a[i], a[i+1] + 1);
  ll ans = 0;
  rep(i, n+1) ans += a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4740
#include<stdio.h>
#include<math.h>
#define dis(a,b) (a)*(a)+(b)*(b)
int main(){
  double x0,x1,xp,y0,y1,yp,a,d;
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x0,&y0,&x1,&y1,&xp,&yp)!=-1){
    a=atan2(y1-y0,x1-x0)*2-atan2(yp-y0,xp-x0);
    d=sqrt(dis(xp-x0,yp-y0));
    printf("%lf %lf\n", x0+cos(a)*d,y0+sin(a)*d);
  }
  return 0;
}

Measured memory_bytes: 0
// Problem : E - Max-Min Sums
// Contest : AtCoder Beginner Contest 151
// URL : https://atcoder.jp/contests/abc151/tasks/abc151_e
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vp vector<pair<int,int>>
#define f first
#define se second
using namespace std;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
double pi=acos(-1.0);
int md=1000000007;
int abst(int a)
{return a<0?-a:a;}
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};
int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%md;n=(n*n)%md;x=x>>1;}
 return ans;}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int fact[100001],inv[100001];
void solve()
{
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,k;
fact[0]=1;
for(int i=1;i<=100000;i++)
fact[i]=(fact[i-1]*i)%md;
inv[0]=inv[1]=1;
for(int i=2;i<=100000;i++)
inv[i]=Pow(fact[i],md-2);
cin>>n>>k;
vi v(n);cin>>v;
sort(v.begin(),v.end());
int total1=0;
for(int i=1;i<=n;i++)
{
 if(n-i<k-1)
	break;
	total1=(total1+(((fact[n-i]*inv[k-1])%md)*((inv[n-i-k+1]*v[i-1])%md)%md))%md;
}
int total2=0;
for(int i=1;i<=n;i++)
{
	if(i<k)
	continue;
	total2=(total2+(((fact[i-1]*inv[k-1])%md)*((inv[i-k]*v[i-1])%md)))%md;
	}
	cout<<(total2-total1+md)%md;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t;
//cin>>t;
t=1;
while(t--)
{
    solve();
}
}


Measured memory_bytes: 2560
//Coded by tzc_wk
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int n=read();
vector<int> g[200005];
int col[200005];
int cnt[2],a[200005];
inline void dfs(int x,int fa){
	col[x]=col[fa]^1;
	cnt[col[x]]++;
	foreach(it,g[x]){
		int y=*it;
		if(y==fa)	continue;
		dfs(y,x);
	}
}
signed main(){
	fz(i,1,n-1){
		int x=read(),y=read();
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1,0);
	set<int> st;
	fz(i,1,n)	st.insert(i);
	if(cnt[0]<=n/3){
		int cnt1=0;
		fz(i,1,n)	if(col[i]==0)	cnt1++,a[i]=cnt1*3,st.erase(st.find(a[i]));
		fz(i,1,n){
			if(!a[i])	a[i]=*st.begin(),st.erase(st.begin());
		}
	}
	else if(cnt[1]<=n/3){
		int cnt1=0;
		fz(i,1,n)	if(col[i]==1)	cnt1++,a[i]=cnt1*3,st.erase(st.find(a[i]));
		fz(i,1,n){
			if(!a[i])	a[i]=*st.begin(),st.erase(st.begin());
		}
	}
	else{
		int cnt1=0,cnt2=0;
		fz(i,1,n){
//			cout<<col[i]<<endl;
			if(col[i]==0&&cnt1*3+1<=n)	a[i]=cnt1*3+1,cnt1++,st.erase(st.find(a[i]));
			if(col[i]==1&&cnt2*3+2<=n)	a[i]=cnt2*3+2,cnt2++,st.erase(st.find(a[i]));
			}
		fz(i,1,n){
			if(!a[i])	a[i]=*st.begin(),st.erase(st.begin());
		}
	}
	fz(i,1,n)	cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 23924
import java.util.*;

public class Main {
	
  	public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
      	String input = sc.nextLine();
      	String[] inputs = input.split(" ");
      	int a = Integer.valueOf(inputs[0]);
      	int b = Integer.valueOf(inputs[1]);
      	int c = Integer.valueOf(inputs[2]);
      	int d = Integer.valueOf(inputs[3]);
      	int start = 0; 
      	int stop = 0;
     	if(a>=c) {
          start = a;
        }
      	else {
          start = c;
        }
      
      if(b<=d) {
        stop = b;
      }
      else {
        stop = d;
      }
      
      if(start>=stop) {
        System.out.println("0");
      }
      else {
      	System.out.println(stop-start);
      }
      
      
      
      
      
    }

}

Measured memory_bytes: 21204
n = int(input())
s = input()

ans = 0

for i in range(n):
    cnt = 0
    x = s[:i]
    y = s[i:]
    for j in range(i):
        if x[j] in y and x[j] not in x[:j]:
            cnt += 1
    if cnt >= ans:
        ans = cnt

print(ans)

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> v(n);
    vector<double> x(n), y(n);
    rep(i, 0, n) cin >> x[i] >> y[i];

    double ans = 0;
    iota(v.begin(), v.end(), 1);
    do {
        rep(i, 1, n) ans += sqrt(pow(x[v[i] - 1] - x[v[i - 1] - 1], 2.0) +
                                 pow(y[v[i] - 1] - y[v[i - 1] - 1], 2.0));
    } while (next_permutation(v.begin(), v.end()));
    rep(i, 1, n + 1) ans /= (double)i;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = 3.14159265358;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin >> N;
    vector<ll> num(N);
    rep(i,N)cin >> num[i];
    cin >> M;
    vector<ll> q(M);
    rep(i,M)cin >> q[i];
    map<ll,bool> ok;
    for(ll i = 0;i < (1 << N);i++){
        ll cnt = 0;
        rep(j,N){
            if(i >> j&1)cnt += num[j];
        }
        ok[cnt] = true;
    }
    rep(i,M){
        if(ok[q[i]])cout << "yes" << "\n";
        else cout << "no" << "\n";
    }
    /*for(auto x : ok){
        cout << x.first << ":" << x.second << "\n";
    }*/
}


Measured memory_bytes: 3248
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		//int[] a = new int[n];
		for(int i = 0 ; i < n ; i++){
			int a = sc.nextInt();
			System.out.println("Case " + (i+1) +":");
			for(int k = 0 ; k < 10 ; k++){
				a = a * a;
				String buf = Integer.toString(a);
				if(buf.length() <= 8){
					for(int x = 0 ; x < 8 ; x++){
						buf = "0" + buf;
					}
				}
				buf = buf.substring(buf.length() -6,buf.length() -2);
				a = Integer.parseInt(buf);
				System.out.println(a);
			}
		}
		sc.close();
	}

}

Measured memory_bytes: 17512
void main() {
    dchar[] s = readln.chomp.to!(dchar[]);
    long a = s.countUntil('A');
    reverse(s);
    long z = s.countUntil('Z');
    writeln(s.length - z - a);
}

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

Measured memory_bytes: 3000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
typedef vector<int> vi;
int main()
{
    int s,w;
    cin>>s>>w;

    if(w>=s)
        cout<<"unsafe\n";
    else
        cout<<"safe\n";
    return 0;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int a[3][3];
	bool ok[3][3]={};
	for(int i=0; i<3; i++) for(int j=0; j<3; j++) cin>>a[i][j];
	int n; cin>>n;
	for(int i=0; i<n; i++){
		int b; cin>>b;
		for(int j=0; j<3; j++) for(int k=0; k<3; k++) if(a[j][k]==b) ok[j][k]=1;
	}
	for(int i=0; i<3; i++){
		bool nuo=1;
		for(int j=0; j<3; j++) if(!ok[i][j]) nuo=0;
		if(nuo){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	for(int i=0; i<3; i++){
		bool nuo=1;
		for(int j=0; j<3; j++) if(!ok[j][i]) nuo=0;
		if(nuo){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	if(ok[0][0] && ok[1][1] && ok[2][2]){
		cout<<"Yes"<<endl;
		return 0;
	}
	if(ok[2][0] && ok[1][1] && ok[0][2]){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
import numpy as np

def resolve():
    N, M, Q = map(int, input().split())
    S = np.zeros(((N + 1), (N + 1)))
    for _ in range(M):
        l, r = map(int, input().split())
        # L,Rの区間にある本数
        S[l, r] += 1

    # ゼータ変換（横縦累積和） axis=1:横, axis=0:縦
    S = np.cumsum(S, axis=1).cumsum(axis=0)

    for _ in range(Q):
        ans = 0
        l, r = map(int, input().split())
        l -= 1
        ans = S[r, r] - S[l, r] - S[r, l] + S[l, l]
        print(int(ans))


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 18236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 998244353;
// const ll INF = 1000000000000000000LL;

int main(){
 int n,id;
 cin >> n >> id;
 vector<double> x(n);
 vector<double> y(n);
 rep(i,n) {
    cin >> x[i];
    cin >> y[i];
 }
 vector<double> d(n);
 rep(i,n){
    d[i] = sqrt(x[i]*x[i]+y[i]*y[i]);
 }
 int cnt=0;
 rep(i,n){
    if(id>=d[i]) cnt++;
 }
 cout << cnt << endl;
 return 0;
}

Measured memory_bytes: 8132
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 10005;
vector<int> trans;


int cost(int val){
	if(val == 1)return 2;
	if(val == 2)return 5;
	if(val == 3)return 5;
	if(val == 4)return 4;
	if(val == 5)return 5;
	if(val == 6)return 6;
	if(val == 7)return 3;
	if(val == 8)return 7;
	if(val == 9)return 6;
	return MOD;
}

int main(){
	fast_io();
	int n,m;
	cin >> n >> m;
	cu(i,0,m){
		int x;
		cin >> x;
		trans.pb(x);
	}
	vector<pii> dp(n + 1, {0,0});
	dp[0].F = 0;
	dp[0].S = 0;
	fu(i,0,n){
		if(i == 0 || dp[i].F != 0){
			for(int jmp:trans){
				int cst = cost(jmp);
				if(dp[i].F + 1 > dp[i + cst].F || (dp[i].F + 1 == dp[i + cst].F && jmp > dp[i + cst].S)){
					dp[i + cst].F = dp[i].F + 1;
					dp[i + cst].S = jmp;
				}
			}
		}
	}
	int ind = n;
	while(dp[ind].F){
		cout << dp[ind].S;	
		ind -= cost(dp[ind].S);
	}cout << '\n';
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
using namespace std;
 
	
 
int32_t main(){IOS;
	int test = 1; //cin >> test;
	while(test--){
		int n , a ; cin >> n >> a ; 
		int ans = 0;
		if(n%a==0) ans = -1;
		ans += n/a+1;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256