akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int x, y;
int field[20][20];
int dp[20][20];

int main(){
	while (cin >> x >> y&&x + y){
		REP(i, 16){
			REP(j, 16){
				dp[i][j] = 0;
				field[i][j] = 0;
			}
		}
		REP(i, y)REP(j, x)cin >> field[i][j];
		REP(j, x){
			if (field[0][j] == 0)dp[0][j] = 1;
		}
		REP(i, y - 1){
			REP(j, x){
				if (field[i][j] == 0){
					if (field[i + 1][j] != 1)dp[i + 1][j] += dp[i][j];
					if (j - 1 >= 0 && field[i + 1][j - 1] == 0){
						dp[i + 1][j - 1] += dp[i][j];
					}
					if (j + 1 < x&&field[i + 1][j + 1] == 0){
						dp[i + 1][j + 1] += dp[i][j];
					}
				}
				else if (field[i][j] == 2){
					if (field[i + 2][j] != 1){
						dp[i + 2][j] += dp[i][j];
					}
				}
			}
		}
		int ans = 0;
		//cout << endl;
		//REP(i, y + 1){
		//	REP(j, x){
		//		cout << dp[i][j] << " ";
		//	}
		//	cout << endl;
		//}
		REP(j, x)ans += dp[y - 1][j] + dp[y][j];
		cout << ans << endl;
	}
}

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

int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    int a[10000],count=0,count2=0;
    for(int i=0;i<n;i++){
      cin>>a[i];
      if(a[i]<=1) count++;
      if(a[i]==0) count2++;
    }
    if(count==n) cout<<"NA"<<endl;
    else cout<<n-count2+1<<endl;
  }
  return 0;
}



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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    int maxa = max(a,max(b,c));
    int sm =  maxa*3-a-b-c;
    if(sm%2==0){
        cout << sm/2 << endl;
    }else{
        cout << sm/2+2 << endl;
    }

}

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

int main(){
    std::vector<std::vector<int>> grid(3, std::vector<int>(3));
    int sum = 0;
    for(int i = 0; i < 3; ++i){
        for(int j = 0; j < 3; ++j){
            std::cin >> grid.at(i).at(j);
            sum += grid.at(i).at(j);
        }
    }

    bool flg = true;

    int a, b, c;
    for(int i = 0; i < 2; ++i){
        a = grid.at(0).at(i + 1) - grid.at(0).at(i);
        b = grid.at(1).at(i + 1) - grid.at(1).at(i);
        c = grid.at(2).at(i + 1) - grid.at(2).at(i);
    }

    if(a != b || b != c || c != a){
        flg = false;
    }

    int d, e, f;
    for(int i = 0; i < 2; ++i){
        d = grid.at(i + 1).at(0) - grid.at(i).at(0);
        e = grid.at(i + 1).at(1) - grid.at(i).at(1);
        f = grid.at(i + 1).at(2) - grid.at(i).at(2);
    }

    if(d != e || e != f || f != d){
        flg = false;
    }

    std::string ans = "Yes";
    if(!flg){
        ans = "No";
    }

    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cout << a[i] << " "; cout << "\n"; }
ll dbgt = 1; void err() { cout << "passed " << dbgt++ << "\n"; }
template<class H, class... T> void err(H&& h,T&&... t){ cout<< h << (sizeof...(t)?" ":"\n"); if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll A[200005], dp[200005][4], amax[3];
int main() {
    init();
    ll N;
    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, N + 2) fill(dp[i], dp[i] + 4, -INF);

    ll b = 1 + (N & 1);
    dp[0][0] = 0;
    rep(i,N){
        rep(j,b+1){
            chmax(dp[i + 2][j], dp[i][j] + A[i]);
            chmax(dp[i + 1][j + 1], dp[i][j]);
        }
    }
    rep(j, b) chmax(dp[N + 1][j + 1], dp[N][j]);

    cout << dp[N+1][b] << endl;
}


Measured memory_bytes: 11436
import math
A, B, H, M = map(int, input().split())
 
tyousin = M*360/60
tansin = H*360/12 + M*360/60/12
 
kakudosa = tyousin - tansin

result_root = A**2 + B**2 - 2*A*B*math.cos(math.radians(kakudosa))
 
print(math.sqrt(result_root))

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define inf 1000000000
#define maxs(x,y) (x = max(x , y))
#define mins(x,y) (x = min(x , y))
using namespace std;
typedef long long int ll;

int main(){
  int N,i,j,ans=0,tmp;
  cin >> N;

  string W[N],a,b;
  cin >> W[0];
  for(i=1 ; i<N ; i++){
    cin >> W[i];
    tmp = W[i-1].length()-1;
    if(W[i][0] != W[i-1][tmp]){
      ans = 1;
    }
    for(j=i-1 ; j>=0 ; j--){
      if(W[i] == W[j]){
        ans = 1;
      }
    }
  }

  if(ans == 1){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

}


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

void dfs(vector<vector<pair<int, int64_t>>>& g, int start,
         vector<int64_t>& cost) {
    for (auto & elm : g[start]) {
        if(cost[elm.first] != -1) continue;
        cost[elm.first] = cost[start] + elm.second;
        dfs(g, elm.first, cost);
    }
}

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

    vector<vector<pair<int, int64_t>>> g(n);
    for (auto i = 0; i < n - 1; i++) {
        int u, v, w; cin >> u >> v >> w; u--; v--;
        g[u].emplace_back(v, w); g[v].emplace_back(u, w);
    }

    vector<int64_t> cost(n, -1);
    cost[0] = 0;
    dfs(g, 0, cost);

    vector<int> p;
    for (auto i = 0; i < n; i++) {
//        cout << cost[i] << " ";
        if(cost[i] % 2 == 0) cout << 1 << endl;
        else cout << 0 << endl;
    }

    return 0;
}

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

#define gc getchar
#define t int t; cin>>t; while(t--)
#define rep(i,j,k) for(i=j; i<k; i++)
#define rrep(i,j,k) for(i=j; i>=k; i--)
#define repm(i,j,n,m) for(i=0; i<n; i++) for(j=0; j<m; j++)
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); it++)
#define ZERO(a) memset(a,0,sizeof(a))
#define lowbit(x) (x&(-x))
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end()
#define fin scan_int()
#define fout(x) fast_out(x)
#define pd(x) printf("%d ",x)
#define newl printf("\n")
#define xx first
#define yy second
#define INOUT take_input_and_output_from_file();
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define strtoint(s,n) if (!(istringstream(s) >> n) ) n = 0;
#define mod 1000000007
typedef long long ll;
typedef vector<int > vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<string,int > psi; 
typedef pair<int ,int > pii;

string inttostr(int str){stringstream stream;stream << str;return stream.str();}
ll modexpo(ll a,ll b,ll n){ll d=1;while(b){if(b&1)d=(d*a)%n;b>>=1;a=(a*a)%n;}return d;}
ll expo(ll a,ll b){ll d=1;while(b){if(b&1)d=d*a;b>>=1;a=a*a;}return d;}
inline ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b) {return (a*b)/gcd(a,b);}
ll inv(ll a,ll m){return modexpo(a,m-2,m);}
void parr(int a[],int n){int i;rep(i,0,n)cout<<a[i]<<" ";cout<<endl;}

void take_input_and_output_from_file() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

inline int scan_int() {
    int NR=0,sign=1;
    char c=gc();
    while( c < 48 || c > 57 ) {
        if(c=='-') sign=0;
        c=gc();
    }
    while(c>47 && c< 58) {
        NR = (NR << 3) + (NR << 1) + (c - 48);
        c=gc();
    }
    return (sign?NR:(-NR));
}

////////////////////////////////////////////////////////////////////////////////////////////


int main(){
    //INOUT;
    
    int a=fin, b=fin;
    printf("%d\n", a*b-(a+b-1));


    return 0;
}


Measured memory_bytes: 764
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  long a=sc.nextLong(), b=sc.nextLong(), x=sc.nextLong();
  long count = b/x - a/x;
  if(a%x == 0)count++;
  System.out.println(count);
}}

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

using namespace std;

typedef long long int li;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

vi par,sz,vis,dis;
vector<vi> graph;
vector<vector<pair<li,li>>> wgraph;

void init(li n)
{
    par.resize(n);
    sz.resize(n);
    wgraph.resize(n);
    dis.resize(n);
    vis.resize(n);
    graph.resize(n);

    f(i,0,n-1)
    {
        par[i]=i;
        sz[i]=1;
        dis[i]=INT_MAX;
    }
}

li root(li a)
{
    while(a!=par[a])
    {
        par[a]=par[par[a]];
        a=par[a];
    }

    return a;
}

void unio(li a,li b)
{
    li r_a=root(a);
    li r_b=root(b);

    if(par[r_a]!=r_b)
    { 
        if(sz[r_a]<sz[r_b])
        {
            par[r_a]=par[r_b];
            sz[r_b]+=sz[r_a];
            sz[r_a]=0;
        }
        else
        {
            par[r_b]=par[r_a];
            sz[r_a]+=sz[r_b];
            sz[r_b]=0;
        }
    }
}

void dijkstra(li start)
{
    dis[start]=0;

    multiset<pair<li,li>> s;

    s.insert({0,start});

    while(!s.empty())
    {
        pair<li,li> tp=*s.B;
        s.erase(s.begin());

        li p=tp.S;

        if(!vis[p]) 
        {
            vis[p]=1;

            for(pair<li,li> v:wgraph[p])
            {
                if(dis[p]+v.S<dis[v.F])
                {
                    dis[v.F]=dis[p]+v.S;
                    s.insert({dis[v.F],v.F});
                }
            }
        }
    }
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n,d,a;

    cin>>n>>d>>a;

    vector<pi> v(n+1);

    for(li i=1;i<=n;i++)
    {
        cin>>v[i].F>>v[i].S;
    }

    sort(v.B+1,v.E);

    vi v2(n+2);

    li tp=2*d;

    li cnt=0,temp=0;

    f(i,1,n)
    {
        v[i].S-=temp;

        if(v[i].S>0)
        {
            li tt= (v[i].S+a-1)/a;

            temp+=tt*a;
            cnt+=tt;

            li start=i,end=n+1;

            while(start+1<end)
            {
                li mid=(start+end)/2;

                if(v[i].F+tp>=v[mid].F)
                    start=mid;
                else
                    end=mid;
            }

            v2[start]+=tt*a;
        }

        temp-=v2[i];
    }

    cout<<cnt;

    return 0;
}


Measured memory_bytes: 4992
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	long X, result;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		X = Long.parseLong(in.readLine());
	}

	void calc() {
		for (long i = X;; ++i) {
			if (isPrime(i)) {
				result = i;
				break;
			}
		}
	}

	boolean isPrime(long val) {
		if (val == 2 || val == 3 || val == 5) {
			return true;
		}
		for (long i = 2; i < Math.sqrt((double) val) + 1; ++i) {
			if (val % i == 0) {
				return false;
			}
		}
		return true;
	}

	void showResult() {
		System.out.println(result);
	}
}


Measured memory_bytes: 21204
n=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if L[i]!=L[j]!=L[k]:
        if L[j]+L[i]>L[k]:
         ans+=1

print(ans)

Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <cctype>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map> // pair
#include <set>
#include <string>

#define MAXSIZE 200000
#define PI 3.141592653589
using namespace std;




int main(){
  int a,b;
  while (std::cin >> a>>b) {
    std::cout << a+b << '\n';
  }
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main(){
  int N;
  cin >> N;
  int H[N];

  REP(i, 0, N)
    cin >> H[i];

  ll ans[N];
  for(int i=N-1; i>=0; i--) {
    if ( i == N-1 )
      ans[i] = 0;
    else{
      if ( H[i] >= H[i+1] ){
        ans[i] = ans[i+1] + 1;
      }
      else
        ans[i] = 0;
    }
  }

  ll ma = 0;
  REP(i, 0, N){
    ma = max(ma, ans[i]);
  }

  cout << ma << endl;

  return 0;
}


Measured memory_bytes: 1408
A = [list(map(int,input().split())) for i in range(3)]
n = int(input())
for j in range(n):
  b = int(input())
  for j in range(3):
    for k in range(3): 
    	if b==A[j][k]:
      		A[j][k]=0

for k in range(3):
  if sum(A[k][:])==0:
    print('Yes')
    exit(0)

ri = [[a[k] for a in A]for k in range(3)]

for k in range(3):
  if sum(ri[:][k])==0:
    print('Yes')
    exit(0)
    
if (A[0][0]+A[1][1]+A[2][2]==0)or(A[2][0]+A[1][1]+A[0][2]==0): 
    print('Yes')
    exit(0)
    
print('No')

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i<n;i++){
        cin >> a[i];
    }
    for(int i = n-1;i>=0;i--){
        cout << a[i];
        if (i > 0){
          cout << " ";
        }
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3088
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Map<String, Integer> map = new HashMap<String, Integer>();
        List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(N);
        for (int i = 0; i < N; i++) {
            String str = sc.next();
            // list.add(sc.next());
            map.put(str, map.getOrDefault(str, 0) + 1);
        }
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            list.add(entry);
        }
        Collections.sort(list, Comparator.comparing(Map.Entry<String, Integer>::getValue).reversed());
        int k = list.get(0).getValue();
        List<String> ans = new ArrayList<String>(N);
        for (Map.Entry<String, Integer> entry : list) {
            if(k!=entry.getValue())break;
            ans.add(entry.getKey());
            // System.out.println(entry.getKey());
        }
        Collections.sort(ans,Comparator.naturalOrder());
        for(String str : ans){
            System.out.println(str);
        }
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 89584
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);

        // 初項を変数に格納する
        int s = console.nextInt();

        List<Integer> numbers = new ArrayList<>();

        // リストに初項を追加
        int lastNum = s;
        int currentNum = s;
        int answer = 0;
        numbers.add(currentNum);

        // 数列をリストに追加していく
        for(int i = 2; i <= 10000; i++){
            if(lastNum % 2 == 0 ){
                currentNum = lastNum / 2;
            }else {
                currentNum = 3 * lastNum + 1;
            }

            if(numbers.contains(currentNum)){
                answer = i;
                break;
            }
            numbers.add(currentNum);
            lastNum = currentNum;
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 35676
import heapq
N,M = map(int,input().split())
dic = {}
for i in range(N):
  A,B = map(int,input().split())
  if A <= M:
    if A in dic.keys():
      dic[A].append(B)
    else:
      dic[A] = [B]
      
ans = 0
plan = []
for i in range(1,M+1):
  if i in dic.keys():
    for w in dic[i]:
        heapq.heappush(plan,-w)
  if len(plan) != 0:
    ans += heapq.heappop(plan)

print(-ans)

Measured memory_bytes: 26068
#include<bits/stdc++.h>
#define ll long long
#define rp(a,b,c) for(long long a=b;a<=c;++a)
using namespace std;

ll a[100000+5];
ll pos,neg,z;
ll minn,ans;


int main()
{
	ll n;
	cin>>n;
	rp(i,1,n)
	{
		cin>>a[i];
		if(a[i]>0) pos++;
		if(a[i]==0) z++;
		if(a[i]<0) neg++;
	}
	if((neg&1)&&(!z))
	{
		minn=abs(a[1]);
		rp(i,2,n)
			minn=min(minn,abs(a[i]));
		rp(i,1,n)
			ans+=abs(a[i]);
		ans-=2*minn;
	}
	else
	{
		rp(i,1,n)
			ans+=abs(a[i]);
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import deque

def main():
    H, W = map(int, input().split())
    S = list(list(input()) for _ in range(H))
    visited = [[False] * W for _ in range(H)]
    blacks = []
    ans = 0
    dh = [0,1,0,-1]
    dw = [1,0,-1,0]
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                blacks.append((h,w))

    for h, w in blacks:
        if not visited[h][w]:
            Q = deque([(h,w)])
            white = 0
            black = 1
            visited[h][w] = True
            while Q:
                i, j = Q.popleft()
                now = S[i][j]

                for n in range(4):
                    nh = i + dh[n]
                    nw = j + dw[n]

                    if 0 <= nh < H and 0 <= nw < W:
                        if not visited[nh][nw]:
                            if now != S[nh][nw]:
                                visited[nh][nw] = True
                                Q.append((nh,nw))
                                if S[nh][nw] == '.':
                                    white += 1
                                else:
                                    black += 1
            ans += white * black

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 57644
import Control.Monad

runOperate :: [String] -> String -> IO String
runOperate ["print",   a, b] str = (putStrLn $ take (b' - a' + 1) $ drop a' str) >> (return str)
  where a' = read a; b' = read b
runOperate ["reverse", a, b] str = return $ take a' str ++ (reverse ((take (b' - a' + 1) . drop a') str)) ++ drop (b' + 1) str
  where a' = read a; b' = read b
runOperate ["replace", a, b, sub] str = return $ take a' str ++ sub ++ drop (b' + 1) str
  where a' = read a; b' = read b

main :: IO ()
main = do
  str <- getLine
  n <- readLn
  operates <- fmap (map words) $ replicateM n getLine
  foldl (\x y -> x >>= runOperate y) (return str) operates
  return ()

Measured memory_bytes: 5644
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			int pi = sc.nextInt();
			list.add(pi);
		}
		Collections.sort(list);
		long count = 0;
		for (int i = 0; i < K; i++) {
			count += list.get(i);
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 38748
import itertools
import sys
input = sys.stdin.readline

n = int(input())
l = list(map(int, input().split()))

cnt = 0
for i,j,k in itertools.combinations(list(range(n)), 3):
    if l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
        if 2 * max(l[i],l[j],l[k]) < l[i]+l[j]+l[k]:
            cnt += 1

print(cnt)

Measured memory_bytes: 68260
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int a,b;
   cin>>a>>b;
   
   if(a<=b){
       cout<<a<<endl;
   }
   else{
       cout<<a-1<<endl;
   }
}

Measured memory_bytes: 3584
# -*- coding: utf-8 -*-

N,M,X,Y = map(int, input().split())
xN = list(map(int, input().split()))
yM = list(map(int, input().split()))

for z in range(-101, 101):
    if X < z <= Y and max(xN) < z and min(yM) >= z:
        print('No War')
        exit()
print('War')

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
const double PI = acos(-1);

double a, b, x;

int spill(double ang) {
    ang = ang * PI/ 180;
    double xx = x/a;
    if (b > a*tan(ang)) {
        double vol = 0.5*a*a*tan(ang) + a*(b-a*tan(ang));
        if (xx >= vol) return 1;
    }
    else {
        double vol = 0.5*b*b/tan(ang);
        if (xx >= vol) return 1;
    }
    return 0;
}

signed main(){
    IOS;
    cin >> a >> b >> x;
    double l = 0, r = 90, ans = 0;
    int cnt = 0;
    while (true) {
        cnt++;
        if (cnt >= 1e6) break;
        double mid = (l + r)/2.0;
        if (spill(mid)) {
            r = mid;
        }
        else {
            ans = mid;
            l = mid;
        }
    }
    cout << fixed << setprecision(20) << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, W;
    cin >> n >> W;
 
    ll w0, v0;
    cin >> w0 >> v0;
 
    vl weight(n), value(n);
    vvl x(4);  // x[i][j] : 重さw0+iの品物でj番目に高い価値
    weight[0] = w0, value[0] = v0;
    x[0].pb(v0);
    exrep(i, 1, n-1) {
        cin >> weight[i] >> value[i];
        x[weight[i] - w0].pb(value[i]);
    }
 
    rep(i, 4) {
        sort(rall(x[i]));
    }
 
    vl rui0(x[0].size()+1);  // rui0[i+1] : x[0][0]からx[0][i]までの和
    rep(i, x[0].size()) {
        rui0[i+1] = rui0[i] + x[0][i];
    }
    vl rui1(x[1].size()+1);  // rui1[i+1] : x[1][0]からx[1][i]までの和
    rep(i, x[1].size()) {
        rui1[i+1] = rui1[i] + x[1][i];
    }
    vl rui2(x[2].size()+1);  // rui2[i+1] : x[2][0]からx[2][i]までの和
    rep(i, x[2].size()) {
        rui2[i+1] = rui2[i] + x[2][i];
    }
    vl rui3(x[3].size()+1);  // rui3[i+1] : x[3][0]からx[3][i]までの和
    rep(i, x[3].size()) {
        rui3[i+1] = rui3[i] + x[3][i];
    }
 
    ll ans = 0;
    exrep(a, 0, x[0].size()) {
        exrep(b, 0, x[1].size()) {
            exrep(c, 0, x[2].size()) {
                exrep(d, 0, x[3].size()) {
                    ll sumW = w0*a + (w0+1)*b + (w0+2)*c + (w0+3)*d;
                    if(sumW <= W) {
                        chmax(ans, rui0[a] + rui1[b] + rui2[c] + rui3[d]);
                    }
                }
            }
        }
    }
 
    out(ans);
    re0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;

/*
const int MNUM = 12, leapMNUM = 12;
const int ML[] = {31,28,31,30,31,30,31,31,30,31,30,31};      //day/month in usual year
const int leapML[] = {31,29,31,30,31,30,31,31,30,31,30,31};  //day/month in leap year
const string days[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
*/
const int MNUM = 10, leapMNUM = 10;
const int ML[] = {20,19,20,19,20,19,20,19,20,19};      //day/month in usual year
const int leapML[] = {20,20,20,20,20,20,20,20,20,20};  //day/month in leap year

struct date{
  int y,m,d;

  date(void):y(0),m(1),d(1){}
  date(int a,int b,int c):y(a),m(b),d(c){}
  /*
  bool isLeap(void){
    if(y%400==0)return true;
    if(y%100==0)return false;
    if(y%4==0)return true;
    return false;
  }
  */
  bool isLeap(void){
    if(y%3==0)return true;
    return false;
  }

  date next(void){
    d++;
    if(isLeap()){
      if(leapML[m-1]<d){ d=1; m++; }
      if(leapMNUM<m){ m=1; y++; }
    }else{
      if(ML[m-1]<d){ d=1; m++; }
      if(MNUM<m){ m=1; y++; }
    }
    return *this;
  }

  bool operator==(const date x)const{return (y==x.y && m==x.m && d==x.d);}

  bool operator<(const date x)const{
    if(y!=x.y)return y<x.y;
    if(m!=x.m)return m<x.m;
    return d<x.d;
  }

  bool operator<=(const date x)const{return (*this==x || *this<x); }
  bool operator>(const date x)const{return !(*this<=x);}
  bool operator>=(const date x)const{return !(*this<x);}

  ll dayCount(void)const{
    date tmp;
    for(ll res=0;;res++){
      if(tmp==*this)return res;
      tmp.next();
    }
    return 0;
  }

  ll operator-(const date x)const{
    return dayCount() - x.dayCount();
  }

  //calculate days from Julian Day(-4713/01/01) using Fliegel's formula.
  ll Fliegel(void){
    int a = (14-m)/12, Y = y+4800-a, M = m+12*a-3;
    return (ll)d + (153*M+2)/5 + 365*Y + Y/4 - Y/100 + Y/400 - 32045;
  }

  //calculate day of week using Zeller congruence.
  int Zeller(void){
    int Y = y, M = m;
    if(M<3){ Y--; M+=12; }
    return (Y + Y/4 - Y/100 + Y/400 + (13*M+8)/5 + d)%7;
  }
};

int main(){
  int n;
  int y,m,d;
  cin >> n;
  while(n){
    n--;
    cin >> y >> m >> d;
    cout << date(1000,1,1)-date(y,m,d) << endl;
  }
}

Measured memory_bytes: 1156
#include<iostream>
    using namespace std;
    int main()
    {
      int a,b,c;
      std::cin >> a >> b >>c;

      if (b+c == a || a+c== b ||a+b == c) {
        std::cout << "Yes"<< '\n';
        /* code */
      }
      else {
        std::cout << "No"  << '\n';
      }

        return 0;
      }


Measured memory_bytes: 256
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

using namespace std;

int main() {
  long long L, R;
  cin >> L >> R;

  R = min(R, L+2048);

  long long ret = 2020;
  for (long long i = L; i <= R; ++i) {
    for (long long j = i+1; j <= R; ++j) {
      ret = min(ret, (i*j)%2019);
    }
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
/*
 * @Author: Kaizyn
 * @Date: 2020-05-02 22:12:51
 * @LastEditTime: 2020-05-03 10:17:36
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int N = 1e5+7;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;

int n, m;

inline void solve()
{
    cin >> n >> m;
    /*
    for (int i = 1; i <= m; ++i) {
        if (n&1) cout << i << " " << n-i << endl;
        else cout << i << " " << n-i+1 << endl;
    }
    */
    if (n&1) {
        for (int i = 1; i <= m; ++i) cout << i << " " << n-i << endl;
    } else {
        for (int i = m, j = 1; i > 0; ++j, i -= 2) {
            cout << j << " " << j+i << endl;
        }
        for (int i = m-1, j = n; i > 0; --j, i -= 2) {
            cout << j << " " << j-i << endl;
        }
    }
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int testcase = 1;
    // cin >> testcase;
    for (int i = 1; i <= testcase; ++i) {
        solve();
    }
    return 0;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((a+b)==(c+d)){
    cout << "Balanced" << endl;
  }else{
    cout << ((a+b)>(c+d) ? "Left" : "Right") << endl;
  }
}

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

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
template <class T> using Tree = tree<T, null_type, less<T>, 
	rb_tree_tag, tree_order_statistics_node_update>; 

typedef pair<int, int> pii;
#define mp(a, b) make_pair(a, b)
const int maxn = 200000 + 10;
Tree<pii> t;
int a[maxn];
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d", &a[i]); 
		t.insert(mp(a[i], i));
	}
	for(int i = 1; i <= n; ++i)
	{
		t.erase(mp(a[i], i));
		printf("%d\n", t.find_by_order(n / 2 - 1)->first);
		t.insert(mp(a[i], i));
	}
	return 0;
}
		 

Measured memory_bytes: 15488
N,M = map(int,input().split())
l = [[0]*2 for i in range(M)]
sum = 0
for i in range(M):
    l[i][0],l[i][1] = map(int,input().split())
l.sort(key=lambda l:l[1])
x = 0
for i in range(M):
    if x<=l[i][0]:
        x=l[i][1]
        sum+=1
print(sum)

Measured memory_bytes: 57892
#include<stdio.h>

char exchange(char c) {
  if('A' <= c && c <= 'Z') {
    return c + ('a' - 'A');
  }
  else if('a' <= c && c <= 'z') {
    return c + ('A' - 'a');
  }
  else return c;
}

int main(void){
    int len;
  char s[4096];  /* 1200バイト以上 */
  scanf("%[^\n]", s);// セキュリティ上よろしくないけど仕方がない
  len = strlen(s);   // 文字列の長さをえる
  for(int i = 0; i < len;i++) {
    s[i] = exchange(s[i]);
  }
  printf("%s\n",s);

}



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

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

using namespace std;

namespace mp = boost::multiprecision;

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

int main() {
    // source
    string s, t;
    cin >> s >> t;

    char s_array[s.length()], t_array[t.length()];

    s.copy(s_array, s.length());
    t.copy(t_array, t.length());

    sort(s_array, s_array + s.length());
    sort(t_array, t_array + t.length(), greater<>());

    string a(s_array, s.length());
    string b(t_array, t.length());

    if (a < b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> v(n),s(n+1);
  ll sum = 0;
  rep(i,n){
    cin >>v[i];
    sum += v[i];
  }
  rep(i,n){
    s[i+1] = v[i] + s[i];
  }
  ll ans = abs(2 * v[0] - sum);
  if(n > 2){
    REP(i,1,n){
      if(ans > abs(2 * s[i] - sum)){
        ans = min(ans,abs(2 * s[i] - sum));
      }
    }
    std::cout << ans << std::endl;
  }
  else cout << abs(v[0] - v[1]) << endl;
  return 0;
}


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

void fnInput(vector<int>& rvnNum)
{
  int nNumSiz;
  cin >> nNumSiz;
  rvnNum.resize(nNumSiz);

  for (int& rnNum : rvnNum)
    cin >> rnNum;
}

llong fnSumOfMultpl(const vector<int>& cnrvnNum)
{
  const int cnnMod = 1e9 + 7;
  llong nCumlSum = 0;

  for (int i = 0; i < cnrvnNum.size(); ++i)
    nCumlSum += cnrvnNum[i];

  llong nSumOfMultpl = 0;

  for (int i = 0; i < cnrvnNum.size() - 1; ++i)
  {
    nCumlSum -= cnrvnNum[i];

    nSumOfMultpl += (llong)cnrvnNum[i] * ( nCumlSum % cnnMod );
    nSumOfMultpl %= cnnMod;
  }

  return nSumOfMultpl;
}
  
int main()
{
  vector<int> vnNum;
  
  fnInput(vnNum);
  cout << fnSumOfMultpl(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 4036
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader rd = new BufferedReader(new InputStreamReader(System.in), 1);
	    int n = Integer.parseInt(rd.readLine());
	    //String[] sl = s.split(" ");
		int a[] = new int[123456];
		for(int i = 1; i <= n; i++)
		{
			a[i] = Integer.parseInt(rd.readLine());
		}
		
		int c = 1;
		for(int i = 1; i <= 100001; i++)
		{
			c = a[c];
			if(c == 2)
			{
				System.out.println(i);
				System.exit(0);
			}
		}
		System.out.println(-1);
		
  	}
}

Measured memory_bytes: 51048
x,y = map(str, input().split())
num = ['A','B','C','D','E','F']
for i in num:
    if x == i:
        x = num.index(i)
    if y == i:
        y = num.index(i)
if x == y:
    print('=')
elif x < y:
    print('<')
else:
    print('>')

Measured memory_bytes: 8992
import bisect
from collections import defaultdict
S = input()

s_dic = defaultdict(lambda: [])

for i, s in enumerate(S):
    s_dic[s].append(i)

start_index = -1
repeat_count = 0

T = input()
for t in T:
    if t not in s_dic:
        print(-1)
        exit()
    next_index = bisect.bisect_right(s_dic[t], start_index)
    if next_index == len(s_dic[t]):
        repeat_count += 1
        start_index = s_dic[t][0]
    else:
        start_index = s_dic[t][next_index]

print(repeat_count*len(S) + start_index + 1)


Measured memory_bytes: 46192
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int an = sc.nextInt() + 1;
		int bn = sc.nextInt() + 1;
		int maxmin = sc.nextInt();
		long[] a = new long[an];
		long[] b = new long[bn];
		int j = b.length - 1;
		int res = 0;
		for(int i = 0; i < an; i++){
			if(i == 0){
				a[i] = 0;
			}else{
				a[i] = a[i-1] +sc.nextLong();
			}
		}
		for(int i = 0; i < bn; i++){
			if(i == 0){
				b[i] = 0;
			}else{
				b[i] = b[i-1] + sc.nextLong();
			}
		}
		for(int i = 0; i < a.length; i++){
			for(; j >= 0; j --){
				if(a[i] + b[j] <= maxmin){
					if(res < i + j){
						res = i + j;
					}
					break;
				}
			}
		}
		System.out.println(res);


	}
}

Measured memory_bytes: 62756
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
int a[212345];
vii vec;

int main(){
    std::ios::sync_with_stdio(false);
    int n,i;
    cin>>n;
    rep(i,n){
    	cin>>a[i];
    }
    int ans;
    sort(a,a+n);
    double val=a[n-1]*1.000/2;
    double mini=inf;
    rep(i,n){
    	if(abs(val-a[i])<mini){
    		mini=abs(val-a[i]);
    		ans=a[i];
    	}
    }
    cout<<a[n-1]<<" "<<ans<<endl;
    
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	string s;

	cin >> s;

	vector<int> count(2,0);

	for (int i = 0; i < s.length(); i++) {
		count[s[i] - '0']++;
	}

	sort(count.begin(), count.end());

	cout << count[0] * 2 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    vector<bool> res(n, true);
    for (int &e : h) cin >> e;
    
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (h[a] == h[b]) {
            res[a] = false;
            res[b] = false;
        } else if (h[a] < h[b]) res[a] = false;
        else res[b] = false;
    }
    
    int ans = 0;
    for (bool r : res) if (r) ans++;
    
    cout << ans << '\n';
    
    return 0;
}

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

int main(){
    string s,t;
    cin >> s;
    cin >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if (s < t){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] string = line.split(" ");
		int a = Integer.parseInt(string[0]);
		int b = Integer.parseInt(string[1]);
		int c = Integer.parseInt(string[2]);

		if (a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 26032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=2147483647;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
const int maxn=1e5+5;
ll n,x;
int main(){
	n=read();
	ll ans=1,flag=0;
	for(int i=1;i<=n;i++){
		x=read();
		if(x==0){
			printf("0\n");
			return 0;
		}
		if(flag) continue;
		else if(x>1000000000000000000/ans) flag=1;
		else ans*=x;
	}
	if(flag) printf("-1\n");
	else printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3744
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int [] x = new int[m];
        int[] y = new int[m];
        int[] z = new int[m];
        for (int i = 0 ; i < m ; i++) {
            x[i] = sc.nextInt() - 1;
            y[i] = sc.nextInt() - 1;
            z[i] = sc.nextInt() % 2;
        }

        Unionfind uf = new Unionfind(n);
        for (int i = 0 ; i < m ; i++) {
            uf.union(x[i], y[i]);
        }
        Set<Integer> set = new HashSet<>();
        for (int i = 0 ; i < n ; i++) {
            set.add(uf.findRoot(i));
        }
        System.out.println(set.size());

    }

}


class Unionfind {
    ArrayList<Integer> parent;

    public Unionfind(int n) {
        parent = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            parent.add(-1);
        }
    }

    public boolean union(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y) {
            return false;
        }

        if (size(x) < size(y)) {
            int temp = x;
            x = y;
            y = temp;
        }

        parent.set(x, parent.get(x) + parent.get(y));
        parent.set(y, x);
        return true;
    }

    public int findRoot(int i) {
        if (parent.get(i) < 0) {
            return i;
        } else {
            int root = findRoot(parent.get(i));
            parent.set(i, root);
            return root;
        }
    }

    public int size(int x) {
        return -parent.get(findRoot(x));
    }

    public boolean same(int x, int y) {
        return findRoot(x) == findRoot(y);
    }
}


Measured memory_bytes: 93640
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;

vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
const int N = 1e6 + 5;

int main()
{
	sync;
    ll t, d, s;
    cin >> d >> t >> s;
    if(s * t >= d)
        cout << "Yes";
    else
        cout << "No";   
}

Measured memory_bytes: 3644
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[] c = S.toCharArray();
        int K = sc.nextInt();

        int[][][] dp = new int[105][4][2];
        dp[0][0][0] = 1;
        for (int i=0;i<c.length;i++) {
            for (int j=0;j<4;j++) {
                for (int k=0;k<2;k++) {
                    int nd = (int)c[i]-(int)'0';
                    for (int d=0;d<10;d++) {
                        int ni = i+1;
                        int nj = j;
                        int nk = k;
                        if (d!=0) nj++;
                        if (nj>K) continue;
                        if (k==0) {
                            if (d>nd) continue;
                            if (d<nd) nk = 1;
                        }

                        dp[ni][nj][nk] += dp[i][j][k];
                    }
                }
            }
        }
        System.out.println(dp[c.length][K][0]+dp[c.length][K][1]);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  for(int i = 0;i < 3;i++) {
    if(s.at(i) == s.at(i + 1)) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100];
int main()
{
	int i,n,s=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i+1<n;i++)
	{
		if(a[i]==a[i+1])
		{
			a[i+1]=10000;
			s++;
		}
	}
	printf("%d",s);
	return 0;
}

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

int main(){
    long long cnt=0,k,n,t=0,tt=0;
    cin>>n>>k;
    vector<int> a;
    int aa;
    for(int i =0;i<n;i++){
        cin>>aa;
        a.push_back(aa);
        for(int j=0;j<a.size();j++){
            if(a[j]>aa){
                //cout<<a[j]<<","<<aa<<endl;
                cnt+=k*(k+1)/2;
            }else if(a[j]<aa){
               // cout<<"afafafa"<<a[j]<<","<<aa<<endl;
                cnt+=k*(k-1)/2;
                
            }
            if(cnt>=1000000007){
                long long sa=cnt/1000000007;
                cnt-=1000000007*sa;
            }
        }
    }
   
    
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N;
    cin >> N;
    vector<int> B(N-1);
    REP(i, N-1) cin >> B[i];
    int ans = B[0] + B[N-2];
    REP(i, N-2) {
        ans += min(B[i], B[i+1]);
    }
    cout << ans << endl;
}

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

const int maxn = 1e5+5;
int a[maxn];

int gcd(int a, int b){
    return b ? gcd(b, a % b) : a;
}


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    for(int i = 0; i<n; i++) cin>>a[i];
    
    int ans = gcd(a[0], a[1]);
    for(int i = 2; i< n; i++)ans = gcd(ans, a[i]);
    
    cout<<ans<<endl;


    
    return 0;
}



Measured memory_bytes: 640