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

int main() {

	string S;
	cin >> S;
  	int price = 700;
  
  	if(S[0] == 'o')price += 100;
    if(S[1] == 'o')price += 100;
  	if(S[2] == 'o')price += 100;

    cout << price << endl;

}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define in(x, data) (data).find(x) != (data).end()

typedef long long ll;
typedef pair<int, int> PRii;

class Node {
public:
    int dist, number;
    Node(int d, int n) {
        dist = d;
        number = n;
    }
};

bool operator < (const Node &l, const Node &r) {
    return l.dist < r.dist
    || (!(r.dist < l.dist) && l.number < r.number);
};

bool operator > (const Node &l, const Node &r) {
    return r < l;
};

class Edge {
public:
    int to, cost;
    Edge(int t, int c) {
        to = t;
        cost = c;
    }
};

int node_n;
vector<vector<Edge>> edge;
vector<int> d;

void cost_initializer(int n) {
    edge = vector<vector<Edge>>(n, vector<Edge>());
}

void dijkstra(int start_p) {
    d = vector<int>(node_n, INT_MAX); d[start_p] = 0;
    vector<int> prev = vector<int>(node_n);

    priority_queue<Node,vector<Node>,greater<Node>> Q;

    for(int i=0; i<node_n; i++) {
        Q.push(Node(d[i],i));
    }

    while(!Q.empty()) {
        Node u = Q.top(); Q.pop();
        if(u.dist > d[u.number]) continue;
        for(int i=0; i<edge[u.number].size(); i++) {
            int alt = d[u.number] + edge[u.number][i].cost;
            int v = edge[u.number][i].to;
            if(d[v] > alt) {
                d[v] = alt;
                prev[v] = u.number;
                Q.push(Node(d[v],v));
            }
        }
    }
}

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

    int n; cin >> n;
    node_n = n;
    cost_initializer(node_n);

    rep(i,n) {
        int u, k; cin >> u >> k;
        rep(j,k) {
            int v, c; cin >> v >> c;
            edge[u].push_back(Edge(v,c));
        }
    }

    dijkstra(0);
    rep(i,n) cout << i << " " << d[i] << endl;
    return 0;
}



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

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

	int N, K; cin>>N>>K;
	vector<int> P(N), C(N);
	rep(i, N) cin>>P[i], P[i]--;
	rep(i, N) cin>>C[i];

	ll score = -1e18;
	rep(st, N){
		ll lap_sc = 0;
		int lap_cn = 0;
		int nx = st;
		while(true){
			lap_cn++;
			lap_sc += C[nx];
			if(st == (nx = P[nx])) break;
		}
		lap_sc = max(0LL, lap_sc);

		ll sum_sc = 0;
		rep(k_cn, K){
			sum_sc += C[nx];
			score = max(score, sum_sc + lap_sc * ((K - (k_cn + 1)) / lap_cn));
			if(st == (nx = P[nx])) break;
		}
	}
	cout<< score <<endl;
}


Measured memory_bytes: 3680
import sys
K = int(input()) #iを取得し、intに値を入れる

kumi = list(range(0,K+1))
l_even = [i for i in kumi if i % 2 == 0 and i != 0]
l_kisu = [i for i in kumi if i % 2 != 0]

answer = len(l_even) * len(l_kisu)

print(answer)

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

int main(){
    int n,m;
    
    cin >> n;
    string A[n];
    for(int i=0;i<n;i++)
        cin >> A[i];
    
    cin >> m;
    string B[m];
    for(int i=0;i<m;i++)
        cin >> B[i];

    int c=0;

    for(int i=0;i<n;i++){
        string tmp=A[i];
        int num=0;
        for(int j=0;j<n;j++){
            if(tmp==A[j])   num++;
        }
        for(int k=0;k<m;k++){
            if(tmp==B[k])   num--;
        }
        if(c<num)
            c=num;
    }

    cout << c << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

char arr[] = { 'S','W' };
char func(char ch, char a, char b) {
	int tmp = 0;
	if (a == 'S') {
		if (b == 'W')tmp = -1;
	}
	else {
		if (b == 'S')tmp = -1;
	}
	return arr[(ch == 'o' ? abs(tmp) : abs(~tmp))];
}

int main() {
	init();

	int N; cin >> N;
	string s;cin >> s;
	rep(bit, 0, 4) {
	vector<char>ans(N, '-1');
		ans[0] = (bit & 1 ? 'S' : 'W');
		ans[1] = (bit & (1 << 1) ? 'S' : 'W');
		rep(i, 1, N - 1) {
			ans[i + 1] = func(s[i], ans[i], ans[i - 1]);
		}
		bool ok = true;
		rep(i, 0, N) {
			int a = i - 1, b = i + 1;
			if (i == 0)a = N - 1;
			if (i == N - 1)b = 0;
			if (func(s[i], ans[i], ans[a]) != ans[b])ok = false;
		}
		if (ok) {
			rep(i, 0, N) {
				cout << ans[i];
				if (i == N - 1)cout << "\n";
			}
			return 0;
		}
	}
	cout << -1 << "\n";

	return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  string op;
  int result;

  cin >> A >> op >> B;
  
  if ( op == "+" ) {
    result = A + B;
  } else if ( op == "-" ) {
    result = A - B;
  } else {
    // Error
  }
  cout << result << endl;
}


Measured memory_bytes: 256
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs
    S.sort()
    total = reduce(lambda acc, x: acc+x, S, 0)
    if total % 10 == 0:
        for s in S:
            if s % 10 != 0:
                total -= s
                break
    return 0 if total % 10 == 0 else total


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(int_inputs(N))
    print(ret)


Measured memory_bytes: 3940
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

#define eb emplace_back
#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define ll long long

const int N = 2e6;
const int INF = 1e9;

int d[N], b[N], a[N];

void solve() {
	int n, h;
	cin >> h >> n;
	for (int i = 1; i <= n; ++ i)
		cin >> a[i] >> b[i];
	for (int i = 1; i <= h; ++ i)
		d[i] = INF;
	for (int i = 1; i <= h; ++ i) {
		for (int j = 1; j <= n; ++ j)
			d[i] = min(d[i], d[max(i - a[j], 0)] + b[j]);
	}
	cout << d[h];
}

int main () {
	cerr << "Ready\n";
	solve();
	return 0;
}

Measured memory_bytes: 4352
import numpy as np
N = int(input())
A = sorted(list(map(int, input().split())))
B = np.array(A)
tmp = set(B)

if len(tmp) > 1:
    t = sum(np.abs(B))
    if A[0] > 0:
        print(t-A[0]*2)
    elif A[-1] < 0:
        print(t+A[-1]*2)
    else:
        print(t)
else:
    print((N - 2) * abs(A[0]))

for i in range(N-2):
    x = A.pop(0)
    y = A.pop(-1)
    if x > y:
        tmp = x
        x = y
        y = tmp
    if A[0] > 0:
        print(x, y)
        A.append(x-y)
    else:
        print(y, x)
        A.append(y-x)
x = A[0]
y = A[1]
if x > y:
    print(x, y)
else:
    print(y, x)


Measured memory_bytes: 23412
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String passS = scan.nextLine();
        String passT = scan.nextLine();
        int moji = passS.length();
        String passTa = passT.substring(0,moji);
        if (passS.equals(passTa)) {
          System.out.println("Yes");
        } else {
          System.out.println("No");
        }
    }
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  string s,z = "AKIHABARA";
  cin >> s;
  int j = 0;
  R(i,SZ(z)){
    if(z[i] == s[j])
      j++;
    else if(z[i] != 'A'){
      cout << "NO\n";
      return 0;
    }
  }
  if(j != SZ(s)){
    cout << "NO\n";
  }else
    cout << "YES\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int c[5][5],x,y,z,h,n,m,o,p,r;
int main(){
    for(register int i=1;i<=3;i++)
    	for(register int j=1;j<=3;j++)
    		cin>>c[i][j];
    for(register int a1=0;a1<=100;a1++){
        x=c[1][1]-a1;
        h=c[1][2]-a1;
        o=c[1][3]-a1;
        for(register int a2=0;a2<=100;a2++){
            y=c[2][1]-a2;
            n=c[2][2]-a2;
            p=c[2][3]-a2;
            if(x!=y || h!=n || o!=p)
            	continue;
            for(register int a3=0;a3<=100;a3++){
            	z=c[3][1]-a3;
            	m=c[3][2]-a3;
            	r=c[3][3]-a3;
            	if(x==z && h==m && o==r){
            		cout<<"Yes"<<endl;
            		return 0;
            	}
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

int main(){
        int H, W;
        char a[100][100];
        int i, j, f;
        scanf("%d %d", &H, &W);
        for(i = 0; i < H; i++){
                scanf("%s", a[i]);
        }

        for(i = 0; i < H; i++){
                for(j = 0; j < W; j++){
                        if(a[i][j] == '#') break;
                }
                if(j == W){
                        for(j = 0; j < W; j++){
                                a[i][j] = ' ';
                        }
                }
        }

        for(i = 0; i < W; i++){
                for(j = 0; j < H; j++){
                        if(a[j][i] == '#') break;
                }
                if(j == H){
                        for(j = 0; j < H; j++){
                                a[j][i] = ' ';
                        }
                }
        }
        f = 0;
        for(i = 0; i < H; i++){
                for(j = 0; j < W; j++){
                        if(a[i][j] == ' ') continue;
                        printf("%c", a[i][j]);
                        f = 1;
                }
                if(f){
                        f = 0;
                        putchar('\n');
                }
        }
        return 0;
}

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

using namespace std;

int main() {
   int n,k;
   cin>>n>>k;
   
   int A[n],tot=0;
   for(int i=0;i<n;++i)
   {
       cin>>A[i];
   }
   sort(A,A+n);
   for(int i=0;i<k;++i)
   {
       tot+=A[i];
   }
   cout<<tot<<endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
 
ll mizu(vector<ll>& h,ll l,ll r,ll n){
  //cout<<l<<"-"<<r<<endl;
  if(l==r)return h[l]-n;
  ll mizuyari;
  ll min=*min_element(h.begin()+l,h.begin()+r+1);
  mizuyari=min-n;
  ll beg=-1;
  while(1){
    if(l>r)break;
    if(h[l]!=min){
      if(beg==-1)beg=l;
    }else{
      if(beg!=-1){
        mizuyari+=mizu(h,beg,l-1,min);
        beg=-1;
      }
    }
    l++;
  }
  if(beg!=-1)mizuyari+=mizu(h,beg,r,min);
  return mizuyari;
}
int main(){
  ll N;
  cin>>N;
  vector<ll> h;
  for(int i=0;i<N;++i){
    ll tmp;
    cin>>tmp;
    h.push_back(tmp);
  }
  cout<<mizu(h,0,h.size()-1,0)<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
n = int(input())
h = list(map(int,input().split()))
cnt = 0
state = 1
for i in range(n):
    for j in range(i+1):
        if h[i]<h[j]:
            state = 0
            break
        else:
            state = 1
    if state == 1:
        cnt+=1
print(cnt)

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

using namespace std;

class Rectangle{
public:
  int h;
  int w;
  Rectangle(int _h,int _w) : h(_h), w(_w) {}
};

int main(){
  int h, w;
  vector<Rectangle> data;
  while(!cin.eof()){
    cin >> h >> w;
    if(h == 0 && w == 0) break;
    data.push_back(Rectangle(h, w));
  }

  for (vector<Rectangle>::size_type i = 0; i < data.size(); i++)
  {
    for(int j = 0; j < data[i].h; j++){
      for(int k = 0; k < data[i].w; k++){
        if(j != 0 && j != data[i].h - 1 && k != 0 && k != data[i].w - 1){
          cout << ".";
        }else{
          cout << "#";
        }

      }
      cout << endl;
    }
    cout << endl;
  }
  


  return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    vector<string> w={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    int ans=0;
    for (int i=0;i<7;i++) {
        if (s==w[i]) ans=7-i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int k,l;
    int mod,ans;
    scanf("%d",&k);

    if (k%7==0)
    {
        l=9*k/7;
    } else
    {
        l=9*k;
    }

    if (l%2==0 || l%5==0)
    {
        printf("-1\n");
        return 0;
    }

    mod=1;
    ans=0;
    for (int i=0; i<l; i++)
    {
        mod*=10;
        mod=mod%l;
        if (mod==1)
        {
            ans=i+1;
            break;
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

const int MAX_N = 2006;
int N, L[MAX_N];

void solve()
{
	sort(L, L+N);
	ll ans = 0;
	for(int i=0;i<N;++i)for(int j=i+1;j<N;++j){
		const int a = L[i], b = L[j];
		// c < a+b, but c > a and c > b
		int n = lower_bound(L, L+N, a+b)-L; // how many elements in L is smaller than a + b
		// j+1 ... n-1
		if(n-1 >= j+1) ans += n-j-1;
	}
	cout << ans << "\n";
}

int main()
{
	cin >> N;
	for(int i=0;i<N;++i){
		cin >> L[i];
	}
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    const int N = 1000000;

    static bool P[N];
    for (int i=2; i<N; i++)
        P[i] = true;
    for (int i=2; i<N; i++)
        if (P[i])
            for (int j=i+i; j<N; j+=i)
                P[j] = false;

    static int A[N];
    for (int i=1; i<N; i++)
        A[i] = A[i-1] + int(P[i]);

    int n;
    while (cin>>n)
        cout<<A[n]<<endl;
}

Measured memory_bytes: 7808
# jsc2019-qualA - Takahashi Calendar
def main():
    M, D = tuple(map(int, input().split()))
    ans = 0
    for d in range(22, D + 1):
        d1, d10 = d % 10, d // 10
        ans += 1 if d1 >= 2 and d1 * d10 <= M else 0
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

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

  vector <int> car(N), train(N);
  for (int i = 0; i < N; i++){
    car[i] = i; train[i] = i;
  }
  
  for (int i = 0; i < K; i++){
    int P, Q; cin >> P >> Q;
    P--; Q--;
    int GP = car[P];
    while (GP != car[GP]){
      GP = car[GP];
    }
    int GQ = car[Q];
    while (GQ != car[GQ]){
      GQ = car[GQ];
    }
    
    car[max(GP, GQ)] = min(GP, GQ);
  }

  for (int i = 0; i < N; i++){
    int Gi = car[i];
    while (Gi != car[Gi]){
      Gi = car[Gi];
    }
    car[i] = Gi;
  }
  
  for (int i = 0; i < L; i++){
    int R, S; cin >> R >> S;
    R--; S--;
    int GR = train[R];
    while (GR != train[GR]){
      GR = train[GR];
    }
    int GS = train[S];
    while (GS != train[GS]){
      GS = train[GS];
    }
    train[max(GR, GS)] = min(GR, GS);
  }

  for (int i = 0; i < N; i++){
    int Gi = train[i];
    while (Gi != train[Gi]){
      Gi = train[Gi];
    }
    train[i] = Gi;
  }
  

  vector < pair< pair<int, int>, int> > P(N);

  for (int i = 0; i < N; i++){
    P[i].first = make_pair(car[i], train[i]);
    P[i].second = i;
  }
  sort(P.begin(), P.end());
  
  vector <int> ans(N);
  queue <int> que; int cnt = 1;

  for (int i = 0; i < N - 1; i++){
    que.push(P[i].second);
    if (P[i].first == P[i + 1].first){
      cnt++;
    }else{
      while (!que.empty()){
        int Q = que.front(); que.pop();
        ans[Q] += cnt;
      }
      cnt = 1;
    }
  }
  que.push(P[N - 1].second);
  while (!que.empty()){
    int Q = que.front(); que.pop();
    ans[Q] += cnt;
  }
  

  for (int i = 0; i < N; i++){
    cout << ans[i];
    if (i == N - 1) cout << endl;
    else cout << " ";
  }
  
  return 0;
}


Measured memory_bytes: 5504
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[a[i][j]], y[-a[i][j]-1]}:
                break
            if x[j] == y[a[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

a = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
n = int(input())
x = [input().split() for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

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

int main(){

  int n,a[200]={},b=0,c=0;
  cin>>n;

  for(int i=1;i<100;i++){
    b=2*i-1;
    for(int j=1;j<200;j++){
      if(j%b==0) a[j]++;
    }
  }
  for(int i=0;i<=n;i++){
    if(a[i]==8) c++;
  }
  
  cout<<c<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<lint, int> pli;
typedef struct edge{
    int to; lint cost;
    edge(int t, lint c){
        to = t; cost = c;
    }
}edge;

void dijkstra(vector<lint> &d, vector<vector<edge>> G, int s){
    priority_queue<pli, vector<pli>, greater<pli>> que;
    d[s] = 0;
    que.push(pli(0, s));
    while(!que.empty()){
        pli p = que.top(); que.pop();
        int v = p.se;
        if(d[v] < p.fi) continue;
        rep(i, G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(pli(d[e.to], e.to));
            }
        }
    }
}

int main(){
    int n, m, s, t; cin >> n >> m >> s >> t;
    s--; t--;
    vector<vector<edge>> Ga = vector<vector<edge>>(n);
    vector<vector<edge>> Gb = vector<vector<edge>>(n);
    rep(i, m){
        int u, v; lint a, b; cin >> u >> v >> a >> b;
        u--; v--;
        Ga[u].push_back(edge(v, a));
        Ga[v].push_back(edge(u, a));
        Gb[u].push_back(edge(v, b));
        Gb[v].push_back(edge(u, b));
    }
    vector<lint> ds(n, 1e17), dt(n, 1e17);
    dijkstra(ds, Ga, s);
    dijkstra(dt, Gb, t);
    lint c[n+1];
    c[n] = 1e17;
    rrep(i, n) c[i] = min(c[i+1], ds[i] + dt[i]);
    rep(i, n) cout << 1000000000000000 - c[i] << endl;
}

Measured memory_bytes: 25148
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;

int main()
{
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	char a,b,c;
	a=toupper(s1[0]);
	b=toupper(s2[0]);
	c=toupper(s3[0]);
	cout<<a<<b<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000000000000000
#define MOD 1000000007

ll power(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b>0)
    {
        if (b%2==1)
            ans=((ans%mod)*(a%mod))%mod;;
        a=((a%mod)*(a%mod))%mod;
        b=b/2;
    }
    return ans;
}

void func()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll cnt=0;
    loop(i,0,n){
        if(s[i]=='1') cnt++;
    }
    ll b[3]={0};
    while(1){
        revloop(i,n-1,0){
            if(cnt-1<=0) break;
            if(s[i]=='1'){
                b[0]+=power(2,n-1-i,cnt-1);
                b[0]=b[0]%(cnt-1);
            }
        }
        revloop(i,n-1,0){
            if(s[i]=='1'){
                b[2]+=power(2,n-1-i,cnt+1);
                b[2]%=(cnt+1);
            }
        }
        break;
    }
    //cout<<b[2]<<"\n";
    loop(i,0,n){
        if(s[i]=='0'){
            ll y=b[2];
            y+=power(2,n-1-i,cnt+1);
            y%=(cnt+1);
            if(i==n-1){
                //cout<<y<<" "<<"yo"<<"\n";
            }
        ll t=y;
        ll ans=1;
        while(t>0){
            ll r=t;
            ll cnt1=0;
            while(r>0){
                cnt1+=(r%2);
                r=r/2;
            }
            t=t%cnt1;
            ans++;
        }
        if(i==n-1){
            //cout<<ans<<" "<<"y"<<"\n";
        }
        cout<<ans<<"\n";
    }
    else{
        ll y=b[0];
        if((cnt-1)==0){
            cout<<0<<"\n";
            continue;
        }
        y=(y-power(2,n-1-i,cnt-1)+ (cnt-1)) %(cnt-1);
        ll t=y;
        ll ans=1;
        while(t>0){
            ll r=t;
            ll cnt1=0;
            while(r>0){
                cnt1+=(r%2);
                r=r/2;
            }
            t=t%cnt1;
            ans++;
        }
        cout<<ans<<"\n";
    }
    }
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;

stack<int> hist;
vector<bool> seen, finished;
int pos = -1;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    hist.push(v);
    for(auto nv : G[v]) {
        if(finished[nv])
            continue;
        if(seen[nv] && !finished[nv]) {
            pos = nv;
            return;
        }
        dfs(G, nv);
        if(pos != -1)
            return;
    }
    finished[v] = true;
    hist.pop();
}

int main() {
    int N, M;
    cin >> N >> M;
    seen.assign(N, false), finished.assign(N, false);
    Graph G(N);
    for(int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }

    for(int i = 0; i < N; ++i) {
        pos = -1;
        dfs(G, i);
        if(pos != -1)
            break;
    }

    if(pos == -1) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> cycle;
    vector<int> next(N);
    vector<bool> isincluded(N);
    while(!hist.empty()) {
        int tmp = hist.top();
        cycle.push_back(tmp);
        isincluded[tmp] = true;
        hist.pop();
        if(tmp == pos)
            break;
    }
    reverse(cycle.begin(), cycle.end());

    int csize = cycle.size();
    for(int i = 0; i < csize; ++i)
        next[cycle[i]] = cycle[(i + 1) % csize];

    int anssize = csize;
    for(int v = 0; v < csize; ++v) {
        int inc = 0;
        for(auto nv : G[cycle[v]]) {
            if(!isincluded[nv])
                continue;
            int vtmp = cycle[v];
            if(nv == next[vtmp])
                continue;
            while(next[vtmp] != nv) {
                isincluded[next[vtmp]] = false;
                inc++;
                anssize--;
                vtmp = next[vtmp];
            }
            next[cycle[v]] = nv;
        }
        v += inc;
    }

    cout << anssize << endl;
    for(int i = 0; i < csize; ++i)
        if(isincluded[cycle[i]])
            cout << cycle[i] + 1 << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const string MINUSINF = "-";

void chmax(string &a, string b) {
    if (a == MINUSINF) a = b;
    else if (a.size() < b.size()) a = b;
    else if (a.size() == b.size()) {
        if (a < b) a = b;
    }
}

ll match[10] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[11000];



int main()
{
    ll N, M; cin >> N >> M;
    vll A(M);
    rep(i, M) cin >>  A[i];

    rep(i, 11000) dp[i] = MINUSINF;

    dp[0] = "";
    for (int i = 0; i <= N; i++) {
        if (dp[i] == MINUSINF) continue;
        for (auto a : A) chmax(dp[i + match[a - 1]], dp[i] + (char)('0' + a));
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 43648
n=int(input())
data=[[]]
for i in range(n):
    a=int(input())
    xy=[list(map(int,input().split())) for i in range(a)]
    data.append(xy)
ans=0
for i in range(2**n):
    lst=[0]
    for j in range(n):
        if (i>>j)&1==1:
            lst.append(1)
        else:
            lst.append(0)
    for j in range(1,n+1):
        if lst[j]==1:
            for k,l in data[j]:
                if lst[k]==l:
                    continue
                else:
                    break
            else:
                continue
            break
    else:
        ans=max(ans,sum(lst))
print(ans)

Measured memory_bytes: 44524
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <time.h>
#include <vector>

using namespace std;
typedef long long ll;
template <class T = ll>
T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T>
void print(T x) {
    cout << x << "\n";
}
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define reps(x, c) for (auto x : c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a)
#define mp(a, b) make_pair((a), (b))
#define pl pair<ll, ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cerr << #x "=" << (x) << "\n"
#define dbgv(x) \
    cerr << #x << "\n"; \
    reps(y, x) { cerr << y << " "; } \
    cerr << "\n"

int main() {
    int a, b;
    cin >> a >> b;
    cout << max(max(a + a - 1, a + b), b + b - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
const ll inf = 1000000007;
int main() {
  ll a,b,c,d,k; cin >>a>>b>>c>>d>>k;
  ll ans = (c-a)*60;
  if(b<=d){
    ans+=d-b-k;
  }else{
    ans+=-b+d-k;
  }
  cout <<ans<<endl;
}



Measured memory_bytes: 3676
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    HashSet<Integer> set = new HashSet<Integer>();
    for(int i = 0; i < n; i++) {
      set.add(sc.nextInt());
    }
    String ans = "NO";
    if(set.size() == n) ans = "YES";
    System.out.println(ans);
  }
}

Measured memory_bytes: 70232
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
     int n;cin >> n;
     vector<int>a(n),b(n),c(n);
     for(int i = 0;i<n;i++)
        cin >> a[i] >> b[i] >> c[i];
     int dp[n+1][3];
     memset(dp,0,sizeof(dp));
     for(int i = 0;i<n;i++){
        dp[i+1][0] = max(dp[i][1]+a[i],dp[i][2]+a[i]);
        dp[i+1][1] = max(dp[i][0]+b[i],dp[i][2]+b[i]);
        dp[i+1][2] = max(dp[i][0]+c[i],dp[i][1]+c[i]);
     }
     cout << max(dp[n][0],max(dp[n][1],dp[n][2]));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 5580
fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn reads<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().split(' ').map(|x| x.parse().unwrap()).collect()
}

fn readln<T>() -> T
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().parse().unwrap()
}

fn main() {
    let q = readln();
    let mut lrs: Vec<(usize, usize)> = vec![];

    for _ in 0..q {
        let lr = reads();

        lrs.push((lr[0], lr[1]));
    }

    let m = 100000;
    let mut primes = vec![true; m + 1];
    primes[0] = false;
    primes[1] = false;

    sieve(&mut primes);

    let mut ps = vec![];
    count(&mut ps, &primes);

    for (l, r) in lrs {/*
        println!("l: {}, c: {}", l, ps[l / 2]);
        println!("r: {}, c: {}", r, ps[r / 2]);*/
        println!("{}", ps[r / 2] - ps[l / 2] +
        if 3 > l || ps[l / 2] == ps[l / 2 - 1] {
            0
        }
        else {
            1
        });
    }
}

fn sieve(primes: &mut Vec<bool>) {
    let n = (primes.len() as f64).sqrt().trunc() as usize;
    for i in 2..n {
        for j in (i + 1)..primes.len() {
            if primes[j] && j % i == 0 {
                primes[j] = false;
            }
        }
    }
}

fn count(ps: &mut Vec<u64>, primes: &Vec<bool>) {
    ps.push(0);
    let mut c = 0;
    for i in 3..primes.len() {
        if i % 2 == 0 {
            continue;
        }

        if primes[i] && primes[(i + 1) / 2] {
            c += 1;
        }
        ps.push(c);
    }
}

Measured memory_bytes: 6780
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

result = 0

for i in range(N):
    result += B[A[i]-1]
    if i == 0:
        pass
    elif A[i] - 1 == A[i-1]:
        result += C[A[i-1]-1]

print(result)

Measured memory_bytes: 3064
from math import acos, tan, hypot

def getRad1(s12, s13, s23):
    return acos((s12*s12 + s13*s13 - s23*s23) / (2*s12*s13))

def getMaxR(s12, rad1, rad2):
    tan1 = tan(rad1 / 2)
    tan2 = tan(rad2 / 2)
    h = s12 * (tan1*tan2) / (tan1+tan2)
    return h * (tan1+tan2) / (2*tan1*tan2 + tan1 + tan2)

x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())

s12 = hypot(x1-x2, y1-y2)
s23 = hypot(x2-x3, y2-y3)
s31 = hypot(x3-x1, y3-y1)

rad1 = getRad1(s12, s31, s23)
rad2 = getRad1(s23, s12, s31)
rad3 = getRad1(s31, s23, s12)

maxRs = [
    getMaxR(s12, rad1, rad2), 
    getMaxR(s23, rad2, rad3),
    getMaxR(s31, rad3, rad1)
]
print(max(maxRs))


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,M=MAP()
broken=[False]*(N+1)
for i in range(M):
    a=INT()
    broken[a]=True

dp=[0]*(N+1)
dp[0]=1
for i in range(N):
    if not broken[i+1]:
        dp[i+1]+=dp[i]
        dp[i+1]%=MOD
    if i!=N-1:
        if not broken[i+2]:
            dp[i+2]+=dp[i]
            dp[i+2]%=MOD
print(dp[N])


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

typedef long long ll;
typedef pair<ll,ll> p;

int max_value(std::map<int, int> m) {
  int max = 0;
  for (std::map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
    if (max < it->second) max = it->second;
  }
  return max;
}

int main()
{
  int n;
  cin >> n;
  vector<int> v(n, 0);

  map<int, int> mp1;
  map<int, int> mp2;

  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
    if(i % 2 == 0) mp1[v[i]]++;
    else mp2[v[i]]++;
  }

  int max1 = max_value(mp1);
  int max2 = max_value(mp2);

  int maxk1;
  int maxk2;

  for(auto a : mp1)
  {
    // cout << a.first << " : " << a.second << endl;
    if(a.second == max1) maxk1 = a.first;
    // cout << maxk1 << endl;
  }

  for(auto a : mp2)
  {
    // cout << a.first << " : " << a.second << endl;
    if(a.second == max2) maxk2 = a.first;
    // cout << maxk2 << endl;
  }

  // cout << maxk1 << endl;
  // cout << maxk2 << endl;

  // for(auto a : mp1)
  // {
  //   cout << a.first << " : " << a.second << endl;
  // }

  mp1.erase(maxk1);
  mp2.erase(maxk2);

  // for(auto a : mp1)
  // {
  //   cout << a.first << " : " << a.second << endl;
  // }
  // cout << mp1.size() << endl;

  int res = n - max1 - max2;
  if(maxk1 == maxk2)
  {
    int tmp1 = n - max_value(mp1) - max2;
    int tmp2 = n - max1 - max_value(mp2);
    res = min(tmp1, tmp2);
    // if(max1 < max2)
    //   max1 = max_value(mp1);
    // else
    //   max2 = max_value(mp2);
  }
  // cout << max1 << endl;
  // cout << max2 << endl;

  cout << res << endl;

}


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

#define CIN1(a) long long a;cin >> a;
#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int main(){
    CIN3(r,d,x)
    long long ans = x;
    rep(i,10){
        ans = r*ans-d;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
loop{
   r=gets.chop.split(' ').map{|e|e.to_i}.first
   break if r==0
   m=Array.new()
   r.times do
      m.push(gets.chop.split(''))
   end

   x,y=0,0
   loop{
      case m[y][x]
         when '^'
            m[y][x]=nil
            y-=1
         when 'v'
            m[y][x]=nil
            y+=1
         when '>'
            m[y][x]=nil
            x+=1
         when '<'
            m[y][x]=nil
            x-=1
         when '.'
            break
         else
            x=nil
            break
      end
   }
   if x.nil?
      puts 'LOOP'
   else
      puts '%d %d' % [x,y]
   end
}

Measured memory_bytes: 6780
#include <iostream>
#include <string>
int ice[10];
int main(){
	int n;
	while(std::cin>>n,n){
		for(int i=0;i<10;++i)ice[i]=0;
		for(int i=0;i<n;++i){
			int a;
			std::cin>>a;
			ice[a]++;
		}
		for(int i=0;i<10;i++){
			if(ice[i]==0)std::cout<<'-'<<std::endl;
			else {
				std::string s(ice[i],'*');
				std::cout<<s<<std::endl;
			}
		}
	}
}

Measured memory_bytes: 1196
#include<iostream>
#include<algorithm>

using namespace std;

struct Yoko{
	int h,p,q;
};

int main(){
	char dummy[10];
	int n,m,a;
	struct Yoko yBou[1001];;
	
	while(cin>>n>>m>>a){
		if(n==0 && m==0 && a==0){
			break;
		}
		
		//初期化
		int tate[1001]={0};
		for(int i=0;i<1001;i++){
			yBou[i].h=yBou[i].p=yBou[i].q=0;
			tate[i]=i;
		}
		
		
		for(int i=1;i<=m;i++){
			/*if(i==m+1){
				cin>>dummy;
			}
			else{*/
				cin>>yBou[i].h>>yBou[i].p>>yBou[i].q;
			//}
		}
		
		
		for(int i=1;i<=m;i++){
		 	for(int j=m;j>i;j--){
		 		if(yBou[j-1].h>yBou[j].h){
		 			swap(yBou[j-1],yBou[j]);
		 		}
		 	}
		}
		
		
		for(int i=1;i<=m;i++){
			swap(tate[yBou[i].p],tate[yBou[i].q]);
		}
		
		
		cout<<tate[a]<<endl;
	}
}

Measured memory_bytes: 1172
#include <iostream>
#define MAX_2N 200

using namespace std;

void fill( int cards[], int len ){
  for( int i = 0; i < len; i++ ){
    cards[ i ] = i + 1;
  }
}

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

void print( int a[], int len ){
  for( int i = 0; i < len; i++ ){
    cout << a[ i ] << endl;
  }
}

void r_shuffle( int cards[], int n ){
  int n_cards[ MAX_2N ];
  for( int i = 0; i < n; i++ ){
    n_cards[ 2 * i ] = cards[ i ];
    n_cards[ 2 * i + 1 ] = cards[ n + i ];
  }
  copy( cards, n_cards, 2 * n );
}

int cut( int cards[], int k, int n ){
  int n_cards[ MAX_2N ];
  for( int i = 0; i < 2 * n; i++ ){
    if( i < 2 * n - k  ){
      n_cards[ i ] = cards[ k + i ];
    }else{
      n_cards[ i ] = cards[ i - ( 2 * n - k ) ];
    }
  }
  copy( cards, n_cards, 2 * n );
}

int main(){
  int cards[ MAX_2N ];
  int n, m, k;
  cin >> n >> m;
  fill( cards, 2 * n );
  for( int i = 0; i < m; i++ ){
    cin >> k;
    if( !k ){
      r_shuffle( cards, n );
    }else{
      cut( cards, k, n );
    }
  }
  print( cards, 2 * n );
  return 0;
}

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

int main(){
  char a, b;
  cin >> a;
  if(a == 'A'){
    b = 'T';
  } else if(a == 'C'){
    b = 'G';
  } else if(a == 'G'){
    b = 'C';
  } else {
    b = 'A';
  }
  
  cout << b << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <set>
#include <map>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define LIMIT3 1000010
#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
template<class T,class C> T max(T a,C b){ return ((a)>(T)(b) ? (a) : (T)(b)); }
template<class T,class C> T min(T a,C b){ return ((a)<(T)(b) ? (a) : (T)(b)); }
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
struct UnionFind {
  vector<int> par;
  UnionFind(int n) : par(n,-1) {}
  void init(int n) { par.assign(n,-1); }
  //木の根であれば連結する頂点数×(-1),そうでなければ親ノードのID
  int root(int x){
    if(par[x]<0) return x;
    else return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x==y) return;//既に連結
    
    if(par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return;
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
  int size(int x){
    return -par[root(x)];
  }
};

void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int x,y,z;
  string s;
  
  cin >> n >> m;
  UnionFind uf(n+1);
  uf.init(n+1);
  result = n;
  rep(i,m){
    cin >> x >> y >> z;
    x--,y--;
    if(!uf.same(x,y)) result--;
    uf.unite(x,y);
  }
  
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3768
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>

const double pi = atan(1.) * 4;

struct Point;
using Vector = Point;
using Polygon = std::vector<Point>;

struct Point {
    int x,y,id;

    Point() {}

    Point(int _x,int _y, int id = -1) : x(_x),y(_y),id(id) {}

    Point operator + (const Point &rhs) const {
        return Point(x + rhs.x,y + rhs.y);
    }

    Point operator - (const Point &rhs) const {
        return Point(x - rhs.x,y - rhs.y);
    }

    bool operator == (const Point &rhs) const {
        return x == rhs.x && y == rhs.y;
    }

    bool operator < (const Point &rhs) const {
        if (x != rhs.x) return x < rhs.x;
        return y < rhs.y;
    }
};

using LL = long long;

LL det(const Point &a,const Point &b) {
    return a.x * 1LL * b.y - a.y * 1LL * b.x;
}

LL det(const Point &a, const Point &b, const Point &c) {
    return det(b - a, c - a);
}

LL dot(const Point &a,const Point &b) {
    return a.x * 1LL * b.x + a.y * 1LL * b.y;
}

const int kN = 100 + 5;
int n;
Point pts[kN];
double result[kN];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i) {
        scanf("%d%d", &pts[i].x, &pts[i].y);
        pts[i].id = i;
    }
    std::sort(pts, pts + n);
    std::vector<Point> stack;
    for (int i = 0; i < n; ++ i) {
        while (stack.size() > 1 && det(stack[stack.size() - 2], stack.back(), pts[i]) >= 0) stack.pop_back();
        stack.push_back(pts[i]);
    }
    int m = stack.size();
    for (int i = n - 2; i >= 0; -- i) {
        while (stack.size() > m && stack.size() > 1 && det(stack[stack.size() - 2], stack.back(), pts[i]) >= 0) stack.pop_back();
        stack.push_back(pts[i]);
    }
    stack.pop_back();

    if (stack.size() == 2) {
        result[stack.back().id] = .5;
        result[stack[0].id] = .5;
    }
    else {
        for (int i = 0; i < stack.size(); ++ i) {
            const Point &cur = stack[i];
            Point left = stack[(i + stack.size() - 1) % stack.size()] - cur;
            Point right = stack[(i + 1) % stack.size()] - cur;
            // printf("%f\n", sqrt(1. * dot(left, right) / dot(left, left) / dot(right, right)));
            result[cur.id] = (pi - acos(1. * dot(left, right) / sqrt(dot(left, left)) / sqrt(dot(right, right)))) / (2 * pi);
        }
    }
    for (int i = 0; i < n; ++ i)
        printf("%.10f\n", result[i]);
}


Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll a,b,i,j,plugs = 1,ans = 0;
    cin >> a >> b;
    while(plugs < b)
    {
        plugs--;
        plugs += a;
        ans++;
    }
    cout << ans << endl;


    return 0;
}





Measured memory_bytes: 3592
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll fib[100];
typedef pair<ll, ll>pii;
vector<pii>dat[100];
ll mod = 1000000007;
void calc(ll a, ll b, ll k)
{
	if (b > 1000000000000000000LL)return;
	if (a > fib[k + 2] || b > fib[k + 2])return;
	dat[k].push_back(make_pair(a, b));
	dat[k].push_back(make_pair(b, a));
	calc(b, a + b, k + 1);
	calc(a + b + b, a + b + b + b, k + 2);
}
int main()
{
	/*for (int i = 1; i <= 34; i++)
	{
		for (int j = 1; j <= 34; j++)
		{
			int t = 1;
			int x = i, y = j;
			for (;;)
			{
				if (x < y)swap(x, y);
				x %= y;
				if (x == 0)break;
				t++;
			}
			printf("%d ", t);
		}
		printf("\n");
	}*/
	fib[1] = 1;
	for (int i = 2; i <= 90; i++)fib[i] = fib[i - 1] + fib[i - 2];
	calc(1, 1, 1);
	int query;
	scanf("%d", &query);
	for (int p = 0; p < query; p++)
	{
		ll za, zb;
		scanf("%lld%lld", &za, &zb);
		if (za > zb)swap(za, zb);
		if (za == 1)
		{
			printf("1 %lld\n", zb % mod);
			continue;
		}
		if (za == 2 && zb == 2)
		{
			printf("1 4\n");
			continue;
		}
		int ans = 0;
		for (int t = 0;; t++)
		{
			if (za >= fib[t] && zb >= fib[t + 1])ans = t;
			else break;
		}
		ll cnt = 0;
		for (int i = 0; i < dat[ans].size(); i++)
		{
			if (dat[ans][i].first <= za)cnt += max(0LL, (zb - dat[ans][i].second + dat[ans][i].first) / dat[ans][i].first);
			cnt %= mod;
		}
		printf("%d %lld\n", ans - 1, cnt);
	}
}

Measured memory_bytes: 4224
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

template<typename has_less>
using ordered_set =
tree<has_less,
	null_type,
	less<has_less>,
	rb_tree_tag,
	tree_order_statistics_node_update>;

#define pb push_back
#define F first
#define S second
#define ALL(v) v.begin(),v.end()
#define fast_cin() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

bool bit(int n, int i) { return (n >> i) & 1; }

int faltu;

const int mod = 1e9+7;
const ll inf = 5e18;
const int N = 2e5 + 100;

int n, m, q;

vector <int> remove(vector <int> b, int i) {
	vector <int> tmp;
	for(int j = 0; j < b.size(); j++) {
		if(j != i) {
			tmp.pb(b[j]);
		}
	}
	return tmp;
}

int main()
{
	fast_cin();
	srand(time(0));

	cin >> n;
	vector <int> b;
	for(int i = 0; i < n; i++) {
		int x; cin >> x;
		b.pb(x);
	}
	deque <int> a;
	for(int i = 0; i < n; i++) {
		int pos = -1;
		for(int j = 0; j < b.size(); j++) {
			if(b[j] == j + 1) {
				pos = j;
			}
		}
		if(pos == -1) {
			cout << -1 << endl;
			return 0;
		}
		a.push_front(b[pos]);
		b = remove(b, pos);
	}
	for(int i: a) {
		cout << i << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
  int qq, n, i, u;
  
  scanf("%d", &n);
  
  for(i = 1;i <= 9;i++) {
    for(u = 1;u <= 9;u++) {
      qq = i * u;
      if(qq == n) {
        puts("Yes"); return 0;
      }
    }
  }
  
  puts("No");
  
  return 0;
}
    

Measured memory_bytes: 128