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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long double ld;
typedef long long ll;
const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;


int main() {
    ll n, k, s; cin >> n >> k >> s;

    ll s2 = s;
    if(s == 1e9) s2--;
    else s2++;

    for(int i = 0; i < n; i++){
        if(0 < k){
            cout << s << endl;
            k--;
        }else{
            cout << s2 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main() {
	int i,n;
	int count=0;
	int p[20] = { 0 };
	scanf("%d\n", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}
	for (i = 1; i < n - 1; i++) {
		if ((p[i] > p[i - 1] && p[i] < p[i + 1])||(p[i] < p[i - 1] && p[i] > p[i + 1])) {
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(100000)
N, M = [int(_) for _ in input().split()]
XYZ = [[int(_) for _ in input().split()] for _ in range(M)]

UF = list(range(N + 1))


def find(x):
    if UF[x] != x:
        UF[x] = find(UF[x])
    return UF[x]


def unite(x, y):
    UF[find(x)] = find(y)


def same(x, y):
    return find(x) == find(y)


for x, y, z in XYZ:
    unite(x, y)
s = set()
for i in range(1, N + 1):
    s.add(find(i))
print(len(set(s)))


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

int main() {
  int N;
  int alice=0,bob=0;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++)
    cin >> a.at(i);
  
  int max=0;
  for(int i=0;i<N;i++){
    for(int k=0;k<N;k++)
      if(max<a.at(k))
        max=a.at(k);
    for(int k=0;k<N;k++)
      if(max==a.at(k)){
        a.at(k)=0;
        break;
      }
    if(i%2==0)
      alice+=max;
    else
      bob+=max;
    max=0;
    }
  cout << alice-bob;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,m,q,i,j,vt[100005],d[100005],c[100005],dp[100005],col[100005];
vector <int> g[100005];
void dfs(int v,int d,int c)
{
	if (!col[v]) col[v]=c;
	if (dp[v]>=d || d==0) return;
	dp[v]=d;for (int i=0;i<g[v].size();++i)
		dfs(g[v][i],d-1,c);
}
int main()
{
	cin>>n>>m;
	for (i=0;i<m;++i)
	{
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	cin>>q;
	for (i=0;i<q;++i) cin>>vt[i]>>d[i]>>c[i];
	for (i=q-1;i>=0;--i) dfs(vt[i],d[i],c[i]);
	for (i=1;i<=n;++i) cout<<col[i]<<endl;
}

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

int main() {
    string s,t,ans;
    cin >> s >> t;
    int ss=s.size();
    int tt=t.size();
    if(ss<tt){
        ans="UNRESTORABLE";
        cout << ans << endl;
        return 0;
    }
    int count;
    for(int i=ss-tt;i>=0;i--){
        count=0;
        for(int j=0;j<tt;j++){
            if(s[i+j]==t[j]) count++;
            else if(s[i+j]=='?') count++;
        }
        if(count==tt){
            for(int j=0;j<tt;j++){
                s[i+j]=t[j];
            }
            break;
        }
        if(i==0){
            ans="UNRESTORABLE";
            cout << ans << endl;
            return 0;
        }
    }
    for(int i=0;i<ss;i++){
        if(s[i]=='?') s[i]='a';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
/*
  AOJ 1519
  Title:Room of Time and Spirit
  @kankichi573
  2016/06/16 WA 6/44
*/
#include <stdio.h>
#include <limits.h>

int N,Q;
int offset[100001];
int base[100001];

void training(int a,int b,int c)
{
  int i,d,oldbase,newbase;
  
  if(base[a]==0 && base[b]==0)
    {
      offset[a]=c;
      offset[b]=c*2;
      base[a]  = base[b]  =a;
    }
  else if(base[a]==0 && base[b]!=0)
    {
      offset[a]= offset[b];
      base[a]  = base[b];
      offset[b] += c;
    }
  else if(base[a]!=0 && base[b]==0)
    {
	offset[a] += c;
	offset[b] = offset[a]+c;
	base[b]=base[a];
    }
  else if(base[a]!=base[b])
	  {
	    oldbase=base[b];
	    newbase=base[a];
	    d = offset[a]-offset[b]+c;

	    offset[a] += c;
	    offset[b] = offset[a]+c;
	    base[b]=newbase;


	    for(i=1;i<=N;i++)
	      if(base[i]==oldbase)
		{
		  offset[i] += d;
		  base[i]=newbase;
		}
	  }
  else
    {
      offset[a] += c;
      offset[b] += c;
    }
}

void query(int a,int b)
{
  if(base[a]!=base[b] || base[a]==0)
    printf("WARNING\n");
  else
    printf("%d\n",offset[b]-offset[a]);
}

void dump()
{
  int i;
  for(i=1;i<=N;i++)
    printf("%2d [%2d]|",offset[i],base[i]);
  printf("\n");
}

main()
{
  int i,a,b,c;
  char order[8];
  
  scanf("%d %d",&N,&Q);
  for(i=0;i<Q;i++)
    {
      scanf("%s %d %d",order,&a,&b);
      if(0==strcmp("IN",order))
	{
	  scanf("%d",&c);
	  training(a,b,c);
#ifdef DEBUG
	  dump();
#endif
	}
      else
	query(a,b);
    }
  return(0);
}

Measured memory_bytes: 1388
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

void enqueue(P);
P dequeue(void);
int min(int,int);

P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  if(tail + 1 == LEN) tail = 0;
  else tail = tail + 1;
}

P dequeue(){
  P x;
  x = Q[head];
  if(head + 1 == LEN) head = 0;
  else head = head + 1;
  return x;
}

int min(int a,int b){
  if(a < b) return a;
  else return b;
    }

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d%d",&n,&q);

  for (i = 1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }

  head = 1;
    tail = n+1;
  
  while(head != tail){
    u = dequeue();
    c = min(q,u.t);
    u.t -= c;
    elaps +=c;

    if(u.t > 0){
      enqueue(u);
    }

    else printf("%s %d\n",u.name,elaps);
  }
  
  return 0;
}

Measured memory_bytes: 10752
#include <stdio.h>

int main(int argc, char** argv)
{
  char a[20 + 1];

  fscanf(stdin, "%s", a);

  char* p;

  for (p = a; *p != '\0'; p ++)
    ;

  for (int i = p - a; i > 0; i --)
    fputc(a[i - 1], stdout);
  
  fputc('\n', stdout);
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
//#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N; cin >> N;
    ll A[N]; rep(i, N) cin >> A[i];
    ll ans = 0;
    bool ok = true;
    rep(i, N - 1) {
        if(1 < A[i + 1] - A[i]) {
            ok = false;
            break;
        }else if(A[i] < A[i + 1]) {
            ++ans;
        }else if(A[i] >= A[i + 1]) {
            ans += A[i + 1];
        }
    }
    if(A[0] != 0) ok = false;
    if(ok) cout << ans << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 1792
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0500

#include <iostream>
using namespace std;

int main() {
  int n;
  while (cin >> n && n) {
    int A = 0;
    int B = 0;
    for (auto i=0; i<n; i++) {
      int a, b;
      cin >> a >> b;
      if (a > b) {
	A = A+a+b;
      } else if (a < b) {
	B = B+a+b;
      } else {
	A += a;
	B += b;
      }
    }
    cout << A << " " << B << endl;
  }
}

Measured memory_bytes: 1156
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
  int a,b;
  char op;
  while(true){
    cin>>a>>op>>b;
    switch (op) {
      case '+':
        cout << a + b<<endl;
        break;
      case '-':
        cout << a-b <<endl;
        break;
      case '*':
        cout << a*b <<endl;
        break;
      case '/':
        cout << a/b <<endl;
        break;
      case '?':
        goto LABEL;
    }
  }
  LABEL:

  return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define pii pair <int,int>
#define vpii vector< pair<int,int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	ll n, m, x, ans;
	cin >> n >> m;
	x = __gcd(n, m);
	ans = (n * m) / x;
	cout << ans;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main(){
    int n, m, card[200], temp[200];
    scanf("%d", &n);
    for(int i = 0; i < n * 2; i++) card[i] = i + 1;

    scanf("%d", &m);
    for(int j = 0; j < m; j++){
        for(int i = 0; i < n * 2; i++) temp[i] = card[i];
        int k;
        scanf("%d", &k);
        switch(k){
            case 0:
                for(int i = 0; i < n; i++){
                    card[i * 2] = temp[i];
                    card[i * 2 + 1] = temp[i + n];
                }
                break;
            default:
                for(int i = 0; i < n * 2 - k; i++) card[i] = temp[i + k];
                for(int i = 0; i < k; i++) card[i + n * 2 - k] = temp[i];
        }
    }
    for(int i = 0; i < n * 2; i++) printf("%d\n", card[i]);

    return 0;
}



Measured memory_bytes: 2688
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,k,a[100010];

int main(){
	while(cin>>n>>k&&n){
		rep(i,k)cin>>a[i];
		a[k]=INF;
		sort(a,a+k+1);
		int b=0,pre=-INF,c=0;
		vc<pi> v;
		rep(i,k+1)if(a[i]!=0){
			if(a[i]==pre+1)pre++,c++;
			else v.pb(pi(pre-c+1,pre)),pre=a[i],c=1;
		}
		rep(i,v.sz){
			b=max(b,v[i].sec-v[i].fir+1+(a[0]==0));
			if(a[0]==0&&i>0&&v[i-1].sec+2==v[i].fir)b=max(b,v[i].sec-v[i-1].fir+1);
		}
		cout<<b<<endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;
int main() {


	vector<int> vec(3);
	for (int i = 0; i < 3; i++)
	{
		cin >> vec[i];
	}


	int k;
	cin >> k;
	
	sort(ALLG(vec));

	for (int i = 0; i < k; i++)
	{
		vec[0] *= 2;
	}

	cout << vec[1] + vec[2] + vec[0];


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int judge(string s) {
  int r = s.size()/2;
  for(int i=0; i<r; i++) {
    if(s.at(i) != s.at(s.length()-1-i)) {
      return false;
    }
  }
  return true;
}
int main() {
  string s;
  cin >> s;
  if(!judge(s)) {
    cout << "No" << endl;
    return 0;
  }
  int p = (s.size()-1)/2;
  string t = s.substr(0,p);
  if(!judge(t)) {
    cout << "No" << endl;
    return 0;
  }
  p = (s.size()+3)/2;
  p -= 1;
  string u = s.substr(p,s.back());
  if(!judge(u)) {
    cout << "Nou" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3644
c = [list(map(int, input().split())) for i in range(3)]

mx = 0
for i in range(3): mx = max(mx, max(c[i]))

flag = True
for i in range(mx+1):
    d1 = [c[0][0]-i, c[0][1]-i, c[0][2]-i]
    for j in range(mx+1):
        d2 = [c[1][0]-j, c[1][1]-j, c[1][2]-j]
        for k in range(mx+1):
            d3 = [c[2][0]-k, c[2][1]-k, c[2][2]-k]
            if d1==d2==d3: flag = False
print("YNeos"[flag::2])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n;
    cin>>n;
    n = n % 10;
    if(n == 2 || n== 4|| n == 5 || n == 7 || n == 9){
        cout<<"hon"<<endl;
    }else if (n == 3){
        cout<<"bon"<<endl;
    }else cout<<"pon"<<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int a, b;
  cin >> a >> b;
  if(a == 1) a = 14;
  if(b == 1) b = 14;
  if(a>b) cout << "Alice" << endl;
  else if(a == b) cout << "Draw" << endl;
  else cout << "Bob" << endl;
  return 0;
}


Measured memory_bytes: 3564
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> A(N);
	for (auto & e : A) cin >> e;
	A.push_back(0);//番兵
	vector<int> removable;
	vector<int> tmp;
	int ans = 1000*1000*1000 + 1;

	for (const auto& x : A) {
		if (x == 0) continue;//breakでも同じだが。
		for (const auto & e : A) {
			if (e >= x) {
				tmp.push_back(e);
				continue;
			}
			if (tmp.size() >= K) {
				sort(tmp.begin(), tmp.end());
				for (int i = 0; i < tmp.size() - K + 1; ++i) {
					removable.push_back(tmp[i]);
				}
			}
			tmp.clear();
		}
		if (removable.size() >= Q) {
			sort(removable.begin(), removable.end());
			ans = min(ans, removable[Q - 1] - removable[0]);
		}
		removable.clear();
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var lines = [];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
    // ここで入力を処理する
    lines.push(line);
});
var sub_fn = (ary)=>{
  
}
reader.on('close', () => {
 // var x = 1*lines[0].split(' ')[0]
 // var l = lines[0].split(' ')[1]
  var l = lines[lines.length -1]
 // console.log(l)
  var c_flg = false;
  var t = 0;
  for(var i=1; i<(lines.length -1);i++){
    var d = lines[i].split(' ')[0];
    var e = lines[i].split(' ')[1];
    if(c_flg){
    t += (1*e)
    }
    //console.log(d)
    if(d == l){
      c_flg = true
    }
  }
    console.log(t)


});


Measured memory_bytes: 7628
# ABC157e


#print(bin(toBitSet([1, 2, 3, 2])))

# for i in range(97, 123):
#    print(chr(i))


def main():
    import sys
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    class SegmentTree:
        #####単位元######
        ide_ele = 0

        # num:n以上の最小の2のべき乗

        def segfunc(self, x, y):
            return x | y  # 例としてmin関数を設定

        def __init__(self, n):
            super().__init__()
            self.num = 2**(n-1).bit_length()  # nは元々の配列の長さ
            self.seg = [self.ide_ele]*(2*self.num+1)

        def init(self, init_val):  # セグ木にしたい配列を渡す
            # set_val
            for i in range(len(init_val)):
                self.seg[i+self.num-1] = init_val[i]
            # built
            for i in range(self.num-2, -1, -1):
                self.seg[i] = self.segfunc(self.seg[2*i+1], self.seg[2*i+2])

        def update(self, k, x):
            k += self.num-1
            self.seg[k] = x
            while k:
                k = (k-1)//2
                self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2])

        def query(self, p, q):
            if q <= p:
                return ide_ele
            p += self.num-1
            q += self.num-2
            res = self.ide_ele
            while q-p > 1:
                if p & 1 == 0:
                    res = self.segfunc(res, self.seg[p])
                if q & 1 == 1:
                    res = self.segfunc(res, self.seg[q])
                    q -= 1
                p = p//2
                q = (q-1)//2
            if p == q:
                res = self.segfunc(res, self.seg[p])
            else:
                res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
            return res

    n = int(input())
    s = list(input())
    q = int(input())

    def toBitSet(numberSet):
        theSet = 0
        for i in numberSet:
            theSet = theSet | 1 << i
        return theSet

    def alphabetToZeroIndexed(alphabet):
        return ord(alphabet) - 97

    tree = SegmentTree(n)

    for i in range(n):
        tree.update(i+1, toBitSet([alphabetToZeroIndexed(s[i])]))

    for _ in range(q):
        a, b, c = input().split()
        b = int(b)
        if int(a) == 1:
            tree.update(b, toBitSet([alphabetToZeroIndexed(c)]))
        else:
            c = int(c)
            print(bin(tree.query(b, c+1)).count('1'))


if __name__ == '__main__':
    main()


Measured memory_bytes: 103848
#include<bits/stdc++.h>
 
using namespace std;
 
void aa(int x)
{
	if(x==1) cout<<'+';
	else if(x==2)cout<<'-'; 
}
 
int dd(int a,int b){
	if(a==1)
	{
		return b;
	}
	else return -b;
}
 
int sum;
 
int main(){
	char e[100];	
	int a,b,c,d;
	cin>>e;
	a=e[0]-'0';
	b=e[1]-'0';
	c=e[2]-'0';
	d=e[3]-'0';
	sum=a;
	for(int i=1;i<=2;i++)
	 for(int j=1;j<=2;j++)
	  for(int k=1;k<=2;k++)
	  {
	  	sum+=dd(i,b);
	  	sum+=dd(j,c);
	  	sum+=dd(k,d);
	  	if(sum==7)
	  	{
	  		cout<<a;
			aa(i);
			cout<<b;
			aa(j);
			cout<<c;
			aa(k);
			cout<<d<<"=7";
			return 0;	
		}
	  	sum=a;
	}	 
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = 0;
    for (int i = 1; i <= (int)to_string(N).size(); i += 2) {
        int l = pow(10, i-1) - 1, r = pow(10, i) - 1;
        if (N < r) ans += N - l;
        else ans += r - l;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>

int main() {

    int n, x;
    int flag = 1; 

    scanf("%d", &n); 
    for (int i = 1; i <= n; i ++) {
        scanf("%d", &x); 
        if (x % 2) continue ;
        if ((x % 3) && (x % 5)) flag = 0; 
    }

    printf("%s", flag ? "APPROVED" : "DENIED");

    return 0; 
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
D - Various Sushi
https://atcoder.jp/contests/abc116/tasks/abc116_d
AC
"""
import sys

from collections import Counter

def solve(N, K, sushi):
    sushi.sort(key=lambda x: x[1], reverse=True)
    pick = sushi[:K]            #  おいしさポイントの高い方からK個の寿司を選択
    pick_type = set([t for t, d in pick]) # 選択済の種類

    cnt = Counter()             #  各種類の寿司が何個ずつあるか覚えておく
    for t, d in pick:
        cnt[t] += 1

    rem = dict()                #  未選択の種類の寿司のうち、一番おいしさポイントが高い物
    for t, d in sushi:
        if t not in pick_type:
            rem[t] = max(rem.get(t, 0), d)
    res = sorted([[k, v] for k, v in rem.items()], key=lambda x: x[1]) # おいしさで昇順にソート(一番おいしい物が末尾)

    manzoku = sum([d for t, d in pick])
    ans = [manzoku + len(pick_type)**2] #  現在の選択でのスコア、ここから種類を1つずつ増加させていきスコアを計算する
    while len(pick_type) < K and pick and res:
        t, d = res.pop()
        pick_type.add(t)
        tt, dd = pick.pop()
        while cnt[tt] == 1 and pick:
            tt, dd = pick.pop()
        if cnt[tt] > 1:
            cnt[tt] -= 1
            manzoku = manzoku - dd + d
            ans.append(manzoku+ len(pick_type)**2)
    return max(ans)


def main(args):
    N, K = map(int, input().split())
    sushi = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, K, sushi)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

#define ll long long

using namespace std;

int main() {
  ll N;
  cin >> N;
  vector<ll> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }

  ll ans = 0, mn = 0;
  mn = v[0];
  for (int i = 1; i < N; i++) {
    if (mn > v[i]) {
      ans++;
      mn = v[i];
    }
  }

  cout << ans + 1 << endl;
}

Measured memory_bytes: 1792
/*
R         R R R R        R        R R R      R      R    R    R      R    R R R R                                                     
R         R             R R       R    RR    R R    R    R    R R    R    R              
R         R            R   R      R R R      R  R   R    R    R  R   R    R   R R                 
R         R R R       R R R R     R R        R   R  R    R    R   R  R    R     R                       
R         R          R       R    R   RR     R    R R    R    R    R R    R     R           
R R R R   R R R R   R         R   R     RR   R      R    R    R      R    R R R R               

*/


#include<bits/stdc++.h>
using namespace std;
#define  bf            ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll            long long
#define  pb            push_back
#define  pr            10
#define  mx            100000 // 10^6
#define  md            1000000007
#define  result(a)     cout<<a<<endl;
#define  forr(a,x)     for(int i=a;i<=x;i++)
#define  input(n,a)    int a[n];for(int i=0;i<n;i++)cin>>a[i];
#define  print(a)      for(auto it:a)cout<<it<<' '; //0-based 
#define  printt(n,a)   for(i=0;i<n;i++)cout<<a[i]<<' '; //1-based 
#define  sz(a)         cout<<a.size()<<endl; 
#define  prefx(n,a)    for(i=1;i<n;i++)a[i]=a[i-1]+a[i]; //0-based
#define  sortt(v)      sort(v.begin(),v.end());
#define  srt(n,a)      sort(a,a+n);
#define  rev(n,a)      reverse(a,a+n);
#define  revr(a)       reverse(a.begin(),a.end());
#define  yes           cout<<"yes\n";
#define  no            cout<<"no\n";

int main()
{
  ll n,i;
  cin>>n;
  input(n,a);
  sort(a,a+n);
  cout<<(a[n-1]-a[0])<<endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define n 500000
#define mem(arr) memset(arr, 0, sizeof(arr))
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
void solve();
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int times = 1;
//	cin >> times;
	for(int i=0; i<times; i++)
	{
		solve();
		cout << '\n';
	}
	return 0;
}

lli a, b, c, d, e, f, g, h;
lli arr[n + 50], arr1[n + 50], arr2[n + 50];

//type here

void solve()
{
	cin >> a >> b;
	for(int i=0; i<a; i++)
		cin >> arr[i];
	lli ans = 0;
	for(int i=1; i<a; i++)
	{
		if(arr[i - 1] + arr[i] > b)
		{
			lli tmp = min(arr[i] + arr[i - 1] - b, arr[i]);
			arr[i] -= tmp;
			ans += tmp;
		}
		if(arr[i - 1] + arr[i] > b)
		{
			lli tmp = min(arr[i] + arr[i - 1] - b, arr[i - 1]);
			arr[i - 1] -= tmp;
			ans += tmp;
		}
	}
	cout << ans << '\n';
}

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

#define MAX_V 100005

using namespace std;

struct Edge {
  int dst, cost;
  Edge() {}
  Edge(int b, int c) : dst(b), cost(c) {}
};

vector<Edge> tree[MAX_V];
int ans[MAX_V];

void dfs(int cur_v, int par_v, int color) {
  ans[cur_v] = color;
  for (int i = 0; i < tree[cur_v].size(); i++) {
    Edge e = tree[cur_v][i];
    if ( e.dst == par_v ) { continue; }
    dfs(e.dst, cur_v, (color+e.cost)%2);
  }
}

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

  for (int i = 0; i < n-1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    tree[u].push_back( Edge(v, w) );
    tree[v].push_back( Edge(u, w) );
  }
  
  dfs(0, -1, 0);

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 9088
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    val x = readLine()!!.toInt()
    val y = readLine()!!.toInt()

    println(x * Math.min(n, k) + y * Math.max(0, n-k))
}


Measured memory_bytes: 31564
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from math import atan2, degrees
a, b, x = mapint()
if x<=a*a*b/2:
    leng = x/b/a*2
    s = atan2(b, leng)
    print(degrees(s))
else:
    x = a*a*b-x
    leng = x/a/a*2
    s = atan2(a, leng)
    print(90-degrees(s))

Measured memory_bytes: 62464
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(){
  int a,b;cin>>a>>b;
  int tmp, res=3;
  if(a>b){
    tmp=a;a=b;b=tmp;
  }
  if(a==2){
    res=1;
  }else if(b==3){
    res=2;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 256
s = input()
ans = "NO"
if s[:7] == "keyence" or s[-7:] == "keyence": ans = "YES"
else:
  w = "keyence"
  for i in range(len(s)):
    if w[i] == s[i]: continue
    else: break
  if w[i:] == s[-len(w[i:]):]: ans = "YES"
print(ans)

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

int32_t main(){
	int n; cin>>n;
	float ans = 0.0;
	while(n--){
		float x; string u; cin>>x>>u;
		if(u == "JPY"){
			ans += 1.0 * x;
		}
		else{
			ans += 380000.0 * x;
		}
	}
	cout<<fixed<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 256
import math

N = int(input())

divisor_N1=set()
for i in range(1, math.floor(math.sqrt(N-1)) + 1):
    if (N - 1) % i == 0:
        divisor_N1.add(i)
        divisor_N1.add((N-1) // i)
#print(divisor_N1)

divisor_N=set()
for i in range(1, math.floor(math.sqrt(N) + 1)):
    if N % i == 0:
        divisor_N.add(i)
        divisor_N.add(N // i)
#print(divisor_N)
divisor_N.remove(1)
divisor_N1.remove(1)
#print(divisor_N)
#print(divisor_N1)

cnt = len(divisor_N1)
for num in divisor_N:
    temp = N
    while temp % num == 0:
        temp //= num
    if temp % num == 1:
        cnt += 1
        #print(num)
print(cnt)

Measured memory_bytes: 40044
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;

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

  if(N%500 <= A)   cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
using pp=pair<int,pair<int,int>>;
#define MAX 200003
#define MOD 1000000007
#define INF 1000000000000000000

int D;
vector<ll> c(26);
vector<vector<ll>> s;

ll score(vector<int> t){
  vector<ll> last(26,0);
  ll ans=0;
  for(ll i=0;i<D;i++){
    ans+=s.at(i).at(t.at(i));
    last.at(t.at(i))=i+1;
    for(ll j=0;j<26;j++){
      ans-=c.at(j)*((i+1)-last.at(j));
    }
  }
  return ans;
}


int main(){
  clock_t start,end;
  start=clock();
  cin>>D;
  for(int i=0;i<26;i++){
    cin>>c.at(i);
  }
  s.resize(D);
  for(int i=0;i<D;i++){
    s.at(i).resize(26);
    for(int j=0;j<26;j++){
      cin>>s.at(i).at(j);
    }
  }
/*
  vector<ll> last(26,0);
  vector<int> t(D);
  for(ll i=0;i<D;i++){
    int k=0;
    for(int j=0;j<26;j++){
      if(pow(c.at(j)*((i+1)-last.at(j)),2.5)-s.at(i).at(j)>pow(c.at(k)*((i+1)-last.at(k)),2.5)-s.at(i).at(k)){
        k=j;
      }
    }
    t.at(i)=k;
    last.at(k)=i+1;
  }
  ll ans=score(t);

  vector<int> nt=t;
  for(int i=0;i<D;i++){
    int k=0;
    for(int j=0;j<26;j++){
      if(s.at(i).at(k)<s.at(i).at(j)){
        k=j;
      }
    }
    nt.at(i)=k;
    ll sub=score(nt);
    if(sub>ans){
      t=nt;
    }
    end=clock();
  }*/
/*
  for(int i=0;i<D;i++){
    cout<<t.at(i)+1<<endl;
  }
*/

  vector<int> t(D);
  for(int i=0;i<D;i++){
    t.at(i)=rand()%26;
  }
  ll ans=score(t);
  vector<int> nt(D);
  end=clock();
  while(end-start<=1800000){
    for(int i=0;i<D;i++){
      nt.at(i)=rand()%26;
      ll ans2=score(nt);
      if(ans2>ans){
        t=nt;
      }
      end=clock();
    }
  }

  for(int i=0;i<D;i++){
    cout<<t.at(i)+1<<endl;
  }

}


Measured memory_bytes: 3756
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long po=sc.nextLong();
        String s[]=sc.next().replace(".","A").split("A",0);
        long a;
        if(s.length==1){
            a=100*Long.parseLong(s[0]);
        }else{
            a=100*Long.parseLong(s[0]);
            a+=Long.parseLong(s[1]);
        }
        long sum=0;
        sum=(po/100)*a;
        long aa=(po%100)*a;
        System.out.println(sum+aa/100);
    }
}


Measured memory_bytes: 35620
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
	ll a,b;scanf("%lld%lld",&a,&b);
	if(b >= a * 2){
		printf("%lld",a + (b - a * 2) / 4);
	}
	else{
		printf("%lld\n",b / 2);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  scanf("%d",&N);
  
  int l[200];
  int i;
  for(i=0;i<2*N;i++){
    scanf("%d",&l[i]);
  }
  sort(l,l+2*N);
  int ans=0;
  for(i=0;i<2*N;i+=2){
    ans += l[i];
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())

HW = H * W
HW2 = HW // 2

if H == 1 or W == 1:
    ans = 1
else:
    if HW % 2 == 0:
        ans = HW2
    else:
        ans = HW2 + 1

print(ans)

Measured memory_bytes: 38256
import sys

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())


def main():
    N = ii()
    txy = [list(mi()) for i in range(N)]
    t, x, y = [list(i) for i in zip(*txy)]
    if t[0]-x[0]-y[0] < 0 or (t[0]-x[0]-y[0])%2:
        print('No')
        return
    for i in range(N-1):
        k = t[i+1]-t[i]-abs(x[i+1]-x[i])-abs(y[i+1]-y[i])
        if k < 0 or k%2:
            print('No')
            return
    print('Yes')
    


if __name__ == '__main__':
    main()


Measured memory_bytes: 97712
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int h,w,n;
	cin>>h>>w>>n;
	vi arr(n);
	for(int &i:arr)cin>>i;
	int idx=0;
	bool right = true;
	vector<vector<int>> ans(h, vi(w));
	REP(i,0,h-1) {
		if(right) {
			REP(j,0,w-1) {
				ans[i][j]=idx+1;
				arr[idx]--;
				if(arr[idx]==0)idx++;
			}
		} else {
			for(int j=w-1;j>=0;j--) {
				ans[i][j]=idx+1;
				arr[idx]--;
				if(arr[idx]==0)idx++;
			}
		}
		right=!right;
	}
	for(auto &i:ans) {
		for(auto &j:i)cout<<j<<" ";
		cout<<"\n";
	}
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3660
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    string s;
    int q;
    cin >> s >> q;
    deque<char> sd;
    for (char c : s) {
        sd.push_back(c);
    }
    bool reversed = false; // 
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            reversed = !reversed;
        } else if (t == 2) {
            int f;
            char c;
            cin >> f >> c;
            if ((f == 1 && !reversed) || (f == 2 && reversed)) {
                sd.push_front(c);
            } else {
                sd.push_back(c);
            }
        }
    }
    if (reversed) {
        reverse(sd.begin(), sd.end());
    }
    for (char c : sd) {
        cout << c;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 896
line = input()

strL = line.split()
X = abs(int(strL[0]))
K = int(strL[1])
D = int(strL[2])

mod = X % D
div = int(X / D)

if div > K:
    ans = X - K * D
elif (K - div) % 2 != 0:
    ans = mod - D
else:
    ans = mod

print(abs(int(ans)))

Measured memory_bytes: 9108
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

int n,m,cost,a,b,c;
vector <int>num[1010],dn,dm;
int f[1010][1010],h[1010][1010];
bool vis[1010][1010];

int main()
{
    while(scanf("%d%d%d",&n,&m,&cost) && n!=0 && m!=0 && cost!=0)
    {
      for(int i=0;i<=n;i++)num[i].clear();
      memset(vis,0,sizeof(vis));memset(f,0,sizeof(f));
      for(int i=0;i<m;i++)
      {
        scanf("%d%d%d",&a,&b,&c);
        num[a].push_back(b);
        f[a][b]=c;
      }
      dn.clear();dm.clear();vis[1][0]=1;
      for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)h[i][j]=2000000000;h[1][0]=0;
      dn.push_back(1);dm.push_back(0);
      for(int i=0;i<dn.size();i++)
      {
        a=dn[i];b=dm[i];
        for(int j=0;j<num[a].size();j++)
        {
          if(h[num[a][j]][b]>h[a][b]+f[a][num[a][j]])
          {
            h[num[a][j]][b]=h[a][b]+f[a][num[a][j]];
            if(!vis[num[a][j]][b])
            {
              vis[num[a][j]][b]=1;
              dn.push_back(num[a][j]);
              dm.push_back(b);
            }
          }
          if(h[num[a][j]][b+1]>h[a][b])
          {

            h[num[a][j]][b+1]=h[a][b];
            if(!vis[num[a][j]][b+1])
            {
              vis[num[a][j]][b+1]=1;
              dn.push_back(num[a][j]);
              dm.push_back(b+1);
            }
          }
        }
        vis[a][b]=0;
      }
      for(int i=0;i<=n;i++)
        if(h[n][i]<=cost)
        {
          printf("%d\n",i);
          break;
        }
    }
    return 0;
}

Measured memory_bytes: 8484
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn solve(n: i32, l: i32) -> i32 {
    if (l * (l + n - 1)) < 0 {
        return (l + (l + n - 1)) * n / 2;
    }

    if l < 0 {
        return (l + (l + n - 2)) * (n - 1) / 2;
    }

    ((l + 1) + (l + n - 1)) * (n - 1) / 2
}

fn main() {
    let (n, l) = parse_line!(i32, i32);
    println!("{}", solve(n, l));
}

#[test]
fn solve_test() {
    assert_eq!(solve(5, 2), 18);
    assert_eq!(solve(3, -1), 0);
    assert_eq!(solve(30, -50), -1044);
    assert_eq!(solve(10, -10), -54);
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

typedef pair<int,int> P;
vector<int> dp(200010,inf);

int main(){
  int x[2],y[2],n; int f[2]={1,1};
  scanf("%d%d%d%d%d",&x[0],&y[0],&x[1],&y[1],&n);
  if(x[0]>x[1])swap(x[0],x[1]),f[0]=-1;
  if(y[0]>y[1])swap(y[0],y[1]),f[1]=-1;
  vector<P> a;
  rep(i,0,n){
    int px,py; scanf("%d%d",&px,&py);
    if(x[0]<=px&&px<=x[1]&&y[0]<=py&&py<=y[1])a.push_back({px*f[0],py*f[1]});
  }
  sort(ALL(a)); for(auto p:a){int val=p.second; *lower_bound(ALL(dp),val)=val;}
  int val=lower_bound(ALL(dp),inf)-dp.begin();
  double ans=100.0*(x[1]-x[0]+y[1]-y[0])-(20-5*M_PI)*val;
  if(val==min(x[1]-x[0],y[1]-y[0])+1)ans+=5*M_PI;
  printf("%.15f\n",ans);
  return 0;
}

Measured memory_bytes: 3188
program ABC133C
    implicit none
    integer(8)::L,R,ans,i,j
    read*,L,R

    if(R/2019-(L-1)/2019>=1)then
        print'(i0)',0
    else
        ans=2019
        do i=L,R-1
            do j=i+1,R
                ans=min(ans,mod(i*j,2019))
            end do
        end do
        print'(i0)',ans
    end if
end program ABC133C

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

int main(){
    int N,M,s,c;
    cin >> N >> M;
    vector<int> V(N,-1);
    for(int i=0;i<M;i++){
        cin >> s >> c;
        s--;
        if(V[s]==-1 || V[s]==c){
            V[s]=c;
        }
        else{
            cout << -1<<endl ;
            return 0;
       }
    }

    if(N==1 && (V[0]==-1 || V[0]==0)){
        cout << 0<<endl;
        return 0;
    }
    
    if(V[0]==-1){
        V[0]=1;
    }
    if(V[0]==0){
        cout<<-1<<endl;
        return 0;
    }

    for(int i=0;i<V.size();i++){
        if(V[i]==-1){
            cout<<0;
        }
        else{
            cout<<V[i];
        }
    }
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
const int INF=1e+9;
const ll INFLL=1e+17;
int N,M;
int X[100010],Y[100010],Z[100010];
class uft{
public:
  int par[100010];//親
  int rank[100010];//木の深さ
  int size[100010];//木の大きさ
  uft(int n);//コンストラクタ
  int find(int x);
  void unite(int x,int y);
  bool same(int x,int y);
  int usize(int x);
  bool check(int x);
};
uft::uft(int n){//コンストラクタ
  for(int i=0;i<n;i++){
    par[i]=i;
    rank[i]=0;
    size[i]=1;
  }
}
int uft::find(int x){//xの根を返す
  if(par[x]==x) return x;//根の親は自分自身
  else return par[x]=find(par[x]);//再起で親を辿る
}
void uft::unite(int x,int y){//x,yを併合
  x=find(x);
  y=find(y);
  if(x==y) return ;//根が同じなら併合する必要なし

  if(rank[x]<rank[y]){//木の深い方に浅い方をつける
    par[x]=y;
    size[y]+=size[x];
  }
  else{
    par[y]=x;
    size[x]+=size[y];
    if(rank[x]==rank[y]) rank[x]++;//同じ深さなら深さを増やす
  }
}
bool uft::same(int x,int y){//x,yが同じグループにいるかどうかを返す
  return find(x)==find(y);//根が同じかどうかを判断する
}
int uft::usize(int x){
  return size[find(x)];
}
bool uft::check(int x){
  return x==find(x);
}
int solve(){
  int res=0;
  uft uf(N);
  rep(i,M) uf.unite(X[i],Y[i]);
  rep(i,N) if(uf.check(i)) res++;
  return res;
}
int main(){
  cin>>N>>M;
  rep(i,M){
    cin>>X[i]>>Y[i]>>Z[i];
    X[i]--;Y[i]--;
  }
  prin(solve());
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
bool prost(int x){
     for(int i=2;i<=x/2;++i){
        if(x%i==0)
            return true;
     }
     return false;
}

int main()
{
    int x;
    cin>>x;
    bool t=true;
    while(t){
        if(!prost(x)){
            cout<<x;
            t=false;
        }
        else
            x++;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>


using namespace std;


template <class ...Args>
void Input(Args &...args)
{
	(cin >> ... >> args);
}

template <class T>
void InputArray(std::size_t size, T &t)
{
	t.resize(size);
	for (auto &e : t) {
		cin >> e;
	}
}

template <class ...Args>
void InputArray(std::size_t size, Args &...args)
{
	(InputArray(size, args), ...);
}

template <class ...Args>
void InputVerticalArray(std::size_t size, Args &...args)
{
	(args.resize(size), ...);
	for (int i = 0; i < size; i++) {
		((cin >> args[i]), ...);
	}
}

template <class ...Args>
void Output(const Args &...args)
{
	((cout << args << ' '), ...) << endl;
}

template <class ...Args>
void OutputVertical(const Args &...args)
{
	((cout << args << endl), ...);
}

template <class T>
void OutputArray(const T &t)
{
	for (const auto &e : t) {
		cout << e << ' ';
	}
	cout << endl;
}

template <class ...Args>
void OutputArray(const Args &...args)
{
	(OutputArray(args), ...);
}

template <class ...Args>
void OutputVerticalArray(const Args &...args)
{
	for (int i = 0; i < min({ args.size()... }); i++) {
		((cout << args[i] << ' '), ...) << endl;
	}
}


#define inp(type, ...) \
	type __VA_ARGS__; \
	Input(__VA_ARGS__)

#define inpa(type, size, ...) \
	type __VA_ARGS__; \
	InputArray((size), __VA_ARGS__)

#define inpva(type, size, ...) \
	type __VA_ARGS__; \
	InputVerticalArray((size), __VA_ARGS__)

#define otp(...) \
	Output(__VA_ARGS__)

#define otpv(...) \
	OutputVertical(__VA_ARGS__)

#define otpa(...) \
	OutputArray(__VA_ARGS__)

#define otpva(...) \
	OutputVerticalArray(__VA_ARGS__)

#define rep(counter, range) \
	for (int (counter) = 0; (counter) < (range); (counter)++)

#define repi(range) \
	rep(i, range)

#define rrep(counter, range) \
	for (int (counter) = (range) - 1; (counter) >= 0; (counter)--)

#define rrepi(range) \
	rrep(i, range)

#define repc(element, container) \
	for (auto &(element) : (container))

#define repe(container) \
	repc(e, container)

#define all(container) \
	(container).begin(), (container).end()

#ifdef __CCR__
#	define dlog(x) clog << #x " = " << x << endl
#else
#	define dlog(x)
#endif



int main()
{
	inp(int, d, t, s);
	
	otp(t * s >= d ? "Yes" : "No");
	
	return 0;
}


Measured memory_bytes: 3128
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
//'A' = 65, 'a' = 97

int main()
{
    int d, g;
    cin >> d >> g;
    int p[d], c[d];
    for (int i = 0; i < d; i++) {
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for (int i = 0; i < (1 << d); i++) {

        int solved = 0;
        int score = 0;
        bool comp[d];
        for (int j = 0; j < d; j++) {
            if (i & (1 << j)) {
                solved += p[j];
                score += p[j] * 100 * (j + 1) + c[j];
                comp[j] = true;
            } else {
                comp[j] = false;
            }
        }
        
        if (g <= score) {
            ans = min(ans, solved);
        } else {
            int unsolved = 0;
            for (int i = d - 1; i >= 0; i--) {
                if (!comp[i]) {
                    unsolved = i;
                    break;
                }
            }
            for (int i = 0; i < p[unsolved]; i++) {
                solved ++;
                score += 100 * (unsolved + 1);
                if (g <= score) {
                    ans = min(ans, solved);
                    break;
                }
            }
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int N, M;
map<pair<int,int>,int> edges;
vector<int> G[55];

vector<int> cst[55];
ll dp[55][(1<<20)+5];

vector<int> getPath(int x, int y){
  vector<int> dist(55, -1);
  queue<pair<int,int>> que;
  que.push(make_pair(x,0));
  while(!que.empty()){
    pair<int,int> p = que.front(); que.pop();
    dist[p.first] = p.second;
    rep(i,G[p.first].size()){
      int nxt = G[p.first][i];
      if(dist[nxt] != -1) continue;
      que.push(make_pair(nxt,p.second+1));
    }
  }

  vector<int> ret;
  int now = y;
  while(now != x){
    int nxt = -1;
    rep(i,G[now].size()){
      if(dist[now]>dist[G[now][i]]){
        nxt = G[now][i];
      }
    }
    ret.push_back(edges[make_pair(now,nxt)]);
    now = nxt;
  }
  return ret;
}

int main(){
  cin >> N;
  rep(i,N-1){
    int a, b;
    cin >> a >> b;    
    edges[make_pair(a,b)] = i;
    edges[make_pair(b,a)] = i;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  cin >> M;
  rep(i,M){
    int u, v;
    cin >> u >> v;
    vector<int> res = getPath(u, v);
    rep(j,res.size()){
      cst[res[j]].push_back(i);
    }
  }

  dp[0][0] = 1;
  rep(i,N-1){
    int mask = 0;
    rep(j,cst[i].size()){
      mask |= (1 << cst[i][j]);
    }
    rep(j,(1<<20)+5){
      dp[i+1][j] += dp[i][j];
      dp[i+1][j | mask] += dp[i][j];
    }
  }

  cout << dp[N-1][(1<<M)-1] << endl;
  
  return 0;
}



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

int main(){
    ll N,K;cin>>N>>K;
    vector<ll> x(101000,0);
    rep(i,N){
        cin>>x[i];
    }
    ll y=M;
    rep(i,N-K+1){
        ll a=min(abs(x[i]),abs(x[i+K-1]))+abs(x[i+K-1]-x[i]);
        y=min(a,y);
    }
    cout<<y<<endl;        
}

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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long N) {
    if (N == 2) {
        cout << 1 << endl;
        return;
    }
    int ans = 1; // K = N - 1
    for (int i = 2; i <= sqrt(N); i++) {
        if ((N - 1) % i == 0) {
            ans += 2;
            if ((N - 1) == i * i) ans--;
        }
    }
    // debug(ans);

    for (int k = 2; k <= sqrt(N); k++) {
        int x = k;
        rep(i, 50) if (N % x == 0) {
            if ((N / x - 1) % k == 0) ans++;
            x *= k;
        }
        else {
            break;
        }
    }
    cout << ans + 1 << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int,int> pii;
const int mod = (int) 1000000007;
const int inf = (int) 2e18;
 
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> v(2*n-1);
    for(int i=0; i<n; i++) cin >> v[i];
    sort(all(v), greater<int>());
    for(int i=1; i<n; i++) v.push_back(v[i]);
    sort(all(v), greater<int>());
    int res = v[0];
    for(int i=1; i<=n-2; i++) res += v[i];
    cout << res << "\n";
}

Measured memory_bytes: 9536