akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

void bubbleSort(int array[], int array_size) {
    int i, j, k;

    for (i = 0; i < (array_size - 1); i++) {
        for (j = (array_size - 1); j > i; j--) {
            if (array[j] < array[j - 1]) {
                k = array[j];
                array[j] = array[j - 1];
                array[j - 1] = k;
            }
        }
    }
}

int main()
{
    int N, K;
    int P[1001];
    int sum=0;
    
    cin >> N >> K;

    for (int i = 0; i < N; i++)
    {
        cin >> P[i];
    }
    bubbleSort(P, N);
    for (int i = 0; i < K; i++)
    {
        sum = sum + P[i];
    }
    cout << sum;
}

Measured memory_bytes: 3636
import sys

S = input()
T = input()
alpha_map = {}
talpha_map = {}
for i in range(len(S)):
  s = S[i]
  t = T[i]
  if s in alpha_map.keys():
    if alpha_map[s] != t:
      print("No")
      sys.exit()
  if t in talpha_map.keys():
    if talpha_map[t] != s:
      print("No")
      sys.exit()
  alpha_map[s] = t
  talpha_map[t] = s
print("Yes")

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

int main(void){
    int l;
    int r;
    int d;
    cin >> l >>  r >> d;
    int cnt=0;
    for(int i=l;i<=r;i++){
        if(i%d==0){
            cnt++;
        }
    }
    cout << cnt << endl;
    
    
}

Measured memory_bytes: 3552
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <complex>
#include <functional>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a);)
#define all(v) v.begin(),v.end()
#define trav(x, v) for(auto &x : v)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vi l(2*n);
	trav(x, l) cin >> x;
	sort(all(l));
	int ans = 0;
	rep(i,0,n) ans += l[2*i];
	cout << ans << endl;
}

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


char fie[11][11];
bool used[11][11];
int X,Y;
inline bool check(){
  char c = fie[0][0];
  for(int i=0;i<Y;i++)
    for(int j=0;j<X;j++)
      if( fie[j][i] != c ) return false;
  return true;
}

inline void temp(int (*tmp)[11] ){
  for(int i=0;i<Y;i++)
    for(int j=0;j<X;j++)
      tmp[j][i] = fie[j][i];
}
inline void rev(int (*tmp)[11] ){
  for(int i=0;i<Y;i++)
    for(int j=0;j<X;j++)
      fie[j][i] = tmp[j][i];
}

int dx[]={1,0,0,-1};
int dy[]={0,1,-1,0};

char dc[]="RGB";

inline bool zch(int x,int y){
  return x < 0 || y < 0 || x >= X || y >= Y || used[x][y];
}
inline bool ume(int x,int y,char c){
  if( used[x][y] ) return false;
  used[x][y] = true;
  bool f = false;
  for(int i=0;i<4;i++){
    int nx = x + dx[i], ny = y + dy[i];
    if( zch( nx, ny ) ) continue;
    if( fie[nx][ny] == fie[x][y] )
      f |= ume( nx,ny,c );    
    else if( fie[nx][ny] == c )
      f = true;
  }
  fie[x][y] = c;
  return f;
}

inline void view(){
  cout << "view" << endl;
  for(int i=0;i<Y;i++){
    for(int j=0;j<X;j++)
      cout << fie[j][i];
    cout << endl;
  }
}


int ans;
inline int solve(int res){
  if( ans == res ) return 0;
  if( check() ) {
    ans = res; return 0;
  }
  char c = fie[0][0];
  int tmp[11][11];
  temp(tmp);
  for(int i=0;i<3;i++){
    if( dc[i] == c ) continue;
    memset(used,0,sizeof(used));
    if( ume(0,0,dc[i]) ) 
      solve(res+1);      
    rev(tmp);
  }
  return res;
}

int main(){
  while(cin >> X >> Y&&(X|Y) ){
    for(int i=0;i<Y;i++)
      for(int j=0;j<X;j++)
        cin >> fie[j][i];
    ans = 50;
    solve(0);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    string s;
    cin >> n >> k >> s;

    rep(i, min(k, (int)50)) {
        string t = s;
        reverse(all(t)), s += t;
        string cur = s.substr(n);
        rep(i, n) chmin(cur, s.substr(i, n));
        reverse(all(cur)), s = cur;
    }
    reverse(all(s));
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 384
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  string o,e;
  cin >> o >> e;
  for(int i=0;i<e.size();i++){
    cout << o[i] << e[i];
  }
  if(o.size()>e.size()) cout << o.back();
  cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//最小公倍数を返す関数
int mcd(int n) {
	return 0;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}

int main() {
	int n, a, b;
	ll ans = 0;
	cin >> n >> a >> b;
	for (int i = 1; i <= n; ++i) {
		int temp = i,temp_sum=0;
		while (temp != 0) {
			temp_sum += temp%10;
			temp /= 10;
		}
		if (temp_sum >= a && temp_sum <= b)ans += i;
	}

	cout << ans << endl;
	

	system("pause");
	return 0;
}

Measured memory_bytes: 504
n = int(input())
a_int = list(map(int, input().split()))

height = 0
base = 0
for j in range(0, n - 1):
    if a_int[j] + base > a_int[j + 1] + base:
        base = a_int[j] - a_int[j + 1]
        height += base
        a_int[j + 1] += base
        base = 0
print(height)

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

int main() {
  int a,b,k;
  cin>>a>>b>>k;
  int count=0;
  int c=max(a,b);
  vector<int> x;
  for(int i=1;i<=c;i++){
    if(a%i==0&&b%i==0){
      x.push_back(i);
      count++;
    }
  }
  reverse(x.begin(),x.end());
  cout<<x[k-1]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef vector<int> vi;
typedef long int li;
typedef unsigned long long ull;
 
int main()
{
    int N,z=0;
    vector<int> a(200);
    cin>>N;
    rep(i,N*2) cin>>a[i];
    sort(begin(a),begin(a)+N*2);
    rep(i,N) z+=a[i*2];
    cout<<z<<endl;   
 
    return 0;
}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

struct edge { int u, v, cost; };

bool comp(const edge& e1, const edge& e2) {
		return e1.cost < e2.cost;
}

int N;
vector<P> vx, vy;
vector<edge> es;
int par[100001], rk[100001];
ll res = 0;

void init(int n) {
	rep(i, n) {
		par[i] = i;
		rk[i] = 0;
	}
}

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

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(rk[x] < rk[y]) par[x] = y;
	else par[y] = x;
	if(rk[x] == rk[y]) ++rk[x];
}

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

void kruskal() {
	sort(es.begin(), es.end(), comp);
	init(N);
	rep(i, es.size()) {
		edge e = es[i];
		if(!same(e.u, e.v)) {
			unite(e.u, e.v);
			res += e.cost;
		}
	}
}

int main() {
	scanf("%d", &N);
	rep(i, N) {
		int X, Y;
		scanf("%d %d", &X, &Y);
		vx.push_back(P(X, i)); vy.push_back(P(Y, i));
	}
	sort(vx.begin(), vx.end()); sort(vy.begin(), vy.end());
	FOR(i, 1, vx.size()) {
		es.push_back({vx[i - 1].second, vx[i].second, vx[i].first - vx[i - 1].first});
	}
	FOR(i, 1, vy.size()) {
		es.push_back({vy[i - 1].second, vy[i].second, vy[i].first - vy[i - 1].first});
	}
	kruskal();
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 7144
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a, b;
  for(int i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    if(tmp < 0) {
      b.push_back(tmp);
    } else {
      a.push_back(tmp);
    }
  }
  sort(a.rbegin(), a.rend());
  sort(b.begin(), b.end());
  if(b.size() == n) {
    if(k % 2 != 0) {
      reverse(b.begin(), b.end());
    }
    ll ans = 1;
    for(int i = 0; i < k; i++) {
      ans *= b[i];
      ans %= MOD;
    }
    if(ans < 0) {
      ans += MOD;
    }
    cout << ans << endl;
  } else if(a.size() >= n - 1 && k <= a.size()) {
    ll ans = 1;
    for(int i = 0; i < k; i++) {
      ans *= a[i];
      ans %= MOD;
    }
    if(ans < 0) {
      ans += MOD;
    }
    cout << ans << endl;
  } else {
    ll ans = 1;
    vector<ll> c;
    if(b.size() > 1) {
      for(int i = 0; i < b.size() - 1; i += 2) {
        c.push_back(b[i] * b[i + 1]);
      }
    }
    if(b.size() % 2 != 0) {
      c.push_back(*(b.end() - 1));
    }
    int ac = 0, cc = 0;
    for(int i = 0; i < k; i++) {
      if(a[ac] * a[ac + 1] < c[cc] && i < k - 1) {
        c[cc] %= MOD;
        ans *= c[cc];
        ans %= MOD;
        i++;
        cc++;
      } else if(ac < a.size()) {
        ans *= a[ac];
        ans %= MOD;
        ac++;
      } else {
        c[cc] %= MOD;
        ans *= c[cc];
        ans %= MOD;
        cc++;
        if(cc < c.size() - 1) {
          i++;
        }
      }
    }
    if(ans < 0) {
      ans += MOD;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(void){
    int a, b, c, d, in;
    cin >> in;
    a = in / 1000;
    b = in % 1000 / 100;
    c = in % 1000 % 100 / 10;
    d = in % 1000 % 100 % 10;
    vector<char> op(3);
    if (a + b + c + d == 7) {
        op[0] = '+';
        op[1] = '+';
        op[2] = '+';
    } else if (a + b + c - d == 7) {
        op[0] = '+';
        op[1] = '+';
        op[2] = '-';
    } else if (a + b - c + d == 7) {
        op[0] = '+';
        op[1] = '-';
        op[2] = '+';
    } else if (a - b + c + d == 7) {
        op[0] = '-';
        op[1] = '+';
        op[2] = '+';
    } else if (a + b - c - d == 7) {
        op[0] = '+';
        op[1] = '-';
        op[2] = '-';
    } else if (a - b + c - d == 7) {
        op[0] = '-';
        op[1] = '+';
        op[2] = '-';
    } else if (a - b - c + d == 7) {
        op[0] = '-';
        op[1] = '-';
        op[2] = '+';
    } else if (a - b - c - d == 7) {
        op[0] = '-';
        op[1] = '-';
        op[2] = '-';
    }
    cout << a << op[0] << b << op[1] << c << op[2] << d << "=7\n";    
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,x,y;
  string Odd,Even;
  cin>>a>>b;
    x=a*b;
  y=x%2;
  if(y>0){
    cout<<"Odd"<<endl;
  }
  else{
    cout<<"Even"<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <iomanip>

using namespace std;

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

	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m;) {
		sort(a.begin(), a.end(), std::greater<int>());
		for (int j = 0; j < n && i < m; j++) {
			if (a[0] <= a[j]) {
				a[j] /= 2;
				i++;
			}
			else {
				break;
			}
		}
	}

	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
	}
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 640
/*-----------------------------------------------,
|  __                                       __   |
| |  |--.-----.---.-.----.----.-----.-----.|  |_ |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _||
| |_____|_____|___._|____|____|_____|   __||____||
|                                   |__|         |
`-----------------------------------------------*/
#include<algorithm>
#include<array>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long lint; typedef long double ldouble ;using namespace std;
#define INF 1000000000000
#define MOD 10000007
#define rep(counter, limit) for (long long counter = 0; counter < limit; counter++)
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){cin.tie(0);ios::sync_with_stdio(0); /*cout<<fixed<<setprecision(20);*/};}setupios;
int main() {

  int n;cin>>n;
  vector<int> a(n);
  vector<bool> trs(n,false);
  rep(i,n)cin>>a[i];
  int at=0;
  int sum=0;
  while(true){
    at=a[at]-1;
    sum++;
    if(trs[at]){
      cout<<-1<<endl;
      return 0;
    }else{
      trs[at]=true;
    }
    if(at==1){
      cout<<sum<<endl;
      return 0;
    }
  }

}


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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  unordered_set<int> group1 = {1, 3, 5, 7, 8, 10, 12};
  unordered_set<int> group2 = {4, 6, 9, 11};
  unordered_set<int> group3 = {2};
  if ((group1.count(A) && group1.count(B)) ||
      (group2.count(A) && group2.count(B)) ||
      (group3.count(A) && group3.count(B))) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}


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

int main(){
      int a,b;
      cin>>a>>b;
      int d10=b/10,d1=b%10;
      int count=0;
      for(int i=4;i<=a;i++){
            for(int j=2;j<=d10;j++){
                  for(int k=0;k<=9;k++){
                        if(k<2){
                              continue;
                        }
                        if(d10==j&&k>d1){
                              break;
                        }
                        if(j*k==i){
                              count++;
                              //cout<<i<<" "<<j<<" "<<k<<endl;
                        }
                        
                  }
            }
      }
      cout<<count<<endl;
}

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

int main(){
    int N, K;  cin >> N >> K;
    string S; cin >> S;
    vector<int> a;
    a.push_back(0);
    // a を求める
    for(int i=0; i<N; i++){
        int cnt = 0;
        int j = i;
        while(S[j]==S[i]){
            cnt += (S[i]=='1' ? 1:-1);
            j++;
        }
        a.push_back(cnt);
        i = j-1;
    }
    int n = a.size();

    // a の絶対値の累積和 f を求める
    vector<int> f(n,0); 
    for(int i=0; i<n; i++){
        f[i] = abs(a[i]);
        if(i>0) f[i] += f[i-1];
    }

    int ans = 0;
    for(int l=1; l<n; l++){
        // 区間の右端 r を求める
        int r;
        if(a[l] > 0)
            r = min(n-1, l + 2*K);
        else
            r = min(n-1, l + 1 + 2*(K-1));
        // 区間 [l, r] で a の絶対値の和を求める
        int T_lr = f[r] - f[l-1];
        ans = max(ans, T_lr);
    }
    cout << ans << endl;
}

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

#define Int long long int
#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()

int main(){
    int n;
    cin >> n;
    int a;
    int b[101];
    int table[2][100]={};

    int sum=0;
    REP(i,n){
        cin >> a;
        sum+=a;
        table[0][i]=sum;
    }


    REP(i,n){
        cin >> b[i];
    }
    sum=0;
    for(int i=n-1;i>=0;i--){
        sum+=b[i];
        table[1][i]=sum;
    }
    int res=0;
    REP(i,n){
        res=max(table[0][i]+table[1][i],res);
    }
    cout << res << endl;
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int a, b, x;
    cin >> a >> b >> x;
    
    if(x < a) cout << "NO" << endl;
    else if(a+b < x) cout << "NO" << endl;
    else cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashSet;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();

		Set<Long> x = new HashSet<>();
		
		for(long i = 1; i * i <= N; i++) {
			if(N % i == 0) {
				x.add(i);
				x.add(N / i);
			}
		}
		
		int min = 100;
		
		for(Long i : x) {
			String a = String.valueOf(i);
			String b = String.valueOf(N / i);
			int temp = Math.max(a.length(), b.length());
			min = Math.min(min, temp);
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 998244353;

int main() {
    int n;
    cin >> n;
    VL d(n), cnt(n);
    REP(i,n){
        d[i] = in();
        cnt[d[i]]++;
    }
    if (d[0] != 0 || cnt[0] != 1){
        cout << 0 << endl;
        return 0;
    }
    int ma = *max_element(ALL(d));
    ll ans = 1;
    FOR(i,1,ma){
        REP(j,cnt[i]) ans = (ans * cnt[i - 1]) % mod;
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
    int n;
    string s;
    set<string> wae;
    set<string>::iterator it;
    cin>>n;
    for(int i = 0; i < n; i++)
    {
        cin>>s;
        it = wae.find(s);
        if(it != wae.end())
        {
            wae.erase(s);
        }
        else
        {
            wae.insert(s);

        }

    }
    cout<<wae.size()<<endl;

    return 0;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

string str;

struct rollinghash{
	static const int MD=3;
	static const int MAX=100005;
	const ll base[MD]={1007LL,1009LL,1009LL};
	const ll mods[MD]={999999937LL, 1000000007LL,912941443LL};
	ll hash[MD][MAX+1];
	ll pw[MD][MAX+1];
	void init(){
		for(int i=0;i<MD;i++){
			pw[i][0]=1;
			for(int j=0;j<MAX;j++){
				pw[i][j+1]=pw[i][j]*base[i]%mods[i];
			}
		}
	}
	void construct(const string &str){
		int n=str.size();
		for(int i=0;i<MD;i++){
			hash[i][0]=0;
			for(int j=0;j<n;j++){
				hash[i][j+1]=(hash[i][j]*base[i]%mods[i]+str[j])%mods[i];
			}
		}
	}

	// calc hash value [l,r)
	ll hash_value(int l,int r,int i){
		return ((hash[i][r]-hash[i][l]*pw[i][r-l])%mods[i]+mods[i])%mods[i];
	}

	ll hash_value2(int l,int r,int pos,int v,int i){
		ll val=((hash[i][r]-hash[i][l]*pw[i][r-l])%mods[i]+mods[i])%mods[i];
		if(l<=pos && pos<r){
			ll dif=v-str[pos];
			val+=dif*pw[i][r-pos-1]%mods[i];
			val%=mods[i];
			if(val<0)val+=mods[i];
		}
		return val;
	}

	PP hash_value(int l,int r){
		return PP(hash_value(l,r,0),P(hash_value(l,r,1),hash_value(l,r,2)));
	}



	PP hash_value2(int l,int r,int pos,int v){
		return PP(hash_value2(l,r,pos,v,0),P(hash_value2(l,r,pos,v,1),hash_value2(l,r,pos,v,2)));
	}
};

rollinghash rh; 

bool solve(int l,int r,int t){
	if(rh.hash_value(l,r-t)==rh.hash_value(l+t,r))return true;
	int pl=0,pr=r-l+1;
	while(pl+1<pr){
		int mid=(pl+pr)/2;
		if(rh.hash_value(l,l+mid)==rh.hash_value(l+t,l+t+mid)){
			pl=mid;
		}else{
			pr=mid;
		}
	}
	if(rh.hash_value2(l,r-t,l+pl,str[l+t+pl])==rh.hash_value2(l+t,r,l+pl,str[l+t+pl]))return true;
	if(rh.hash_value2(l,r-t,l+t+pl,str[l+pl])==rh.hash_value2(l+t,r,l+t+pl,str[l+pl]))return true;
	return false;
}

int main(void){
	cin >> str;
	rh.init();
	rh.construct(str);
	int q;
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		int l,r,t;
		scanf("%d%d%d",&l,&r,&t);
		l--;
		printf("%s\n",solve(l,r,t)?"Yes":"No");
		
	}
	
	return 0;
} 


Measured memory_bytes: 8120
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 5100
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    string s; cin >> s;
    sort(all(s));
    ll cnt = 0;
    ll ans = 1;
    char a = 'A';
    ll n = s.size();
    rep(i,n){
        if(a == s[i]){
            ans += cnt;
        }else{
            cnt = i;
            a = s[i];
            ans += cnt;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

void pr1(bool a){
    cout << (a ? "Yes" : "No") << endl;
    exit(0);
}
void pr2(bool a){
    cout << (a ? "YES" : "NO") << endl;
    exit(0);
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a;
    cin >> a;
    string s;
    cin >> s;
    if(a >= 3200){
        cout << s << endl;
    }else{
        cout << "red" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
N, K = map(int, input().split())
MOD = 10**9+7
A = [a % MOD for a in sorted(list(map(int, input().split())))]
MIN, MAX = 0, 0

def div_MOD(a):     # (a^{-1} mod MOD) をフェルマーの小定理より求める
    return pow(a, MOD - 2, MOD)     # a^{-1} = a^{p-2} (mod p)

C = [0]*(K-1) + [1]
for n in range(K, N):
    C.append((C[n-1] * n * div_MOD(n-(K-1))) % MOD)

for i in range(N-K+1):
    MIN = (MIN + (A[i] * C[N-i-1]) % MOD) %MOD
for i in range(N-K+1):
    MAX = (MAX + (A[N-1-i] * C[N-i-1]) % MOD) %MOD

print((MAX - MIN) % MOD)

Measured memory_bytes: 14416
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define EPS 1e-6

int main()
{
    fast;
    lli a,b;
    cin>>a>>b;
    lli n= __gcd(a,b);
    //cout<<n;
    int ans=1;
    const int MAX = 1e6 + 10;
    for (lli i = 2; i*i<=n; ++i) {
        if(n%i==0){
            ans++;
        while (n % i == 0) {
            //cout<<n<<" ";
            n /= i;
        }
        }
    }
    if (n != 1) {
        ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
<?php
list($n) = ints();
for ($i = 1; $i <= intdiv($n, 2); ++$i) {
    if ($n % 2) $g[$i][$n - $i] = false;
    else $g[$i][$n - $i + 1] = false;
}
echo (intdiv($n * ($n - 1), 2) - intdiv($n, 2)) . PHP_EOL;
for ($i = 1; $i <= $n - 1; ++$i) {
    for ($j = $i + 1; $j <= $n; ++$j) {
        if (!isset($g[$i][$j])) echo $i . ' ' . $j . PHP_EOL;
    }
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16232
iN ,iX  = [int(x) for x in input().split()]
aCum = [0]
for x in input().split():
    aCum += [aCum[-1] + int(x)]

def fCeil(iT,iR):
    return -1 * iT // iR * -1

def fCalcCost(iN,iX,aCum,iK):
    iCost = (iN + iK ) * iX + 5 * aCum[iN]
    for i in range(2,fCeil(iN,iK) ):
        iCost += 2 * aCum[iN - i * iK ]
    return iCost


if 1 < iN :

    iULim = fCeil(iN,2)+1
    iLLim = 1
    def fSearchLowCost(iL,iLCost,iU,iUCost,iN,iX,aCum):
        if iU - iL < 2 * iX :
            iTotalCost = min(iLCost,iUCost)
            for iK in range(iL+1,iU) :
                iThisCost = fCalcCost(iN,iX,aCum,iK)
                iTotalCost = min(iThisCost,iTotalCost)
            return iTotalCost
        else:
            iM = (iU + iL) // 2
            iMCost = fCalcCost(iN,iX,aCum,iM)
            if iLCost < iUCost :
                return fSearchLowCost(iL,iLCost,iM,iMCost,iN,iX,aCum)
            else :
                return fSearchLowCost(iM,iMCost,iU,iUCost,iN,iX,aCum)

    print(fSearchLowCost(iLLim,fCalcCost(iN,iX,aCum,iLLim),iULim,fCalcCost(iN,iX,aCum,iULim),iN,iX,aCum))
else:
    print(2*iX + 5*aX[0])


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

int main(){
  int tate,yoko,a,b,m[31];
  char c;
  cin>>tate;
  for(int i=1;i<=tate;i++)
    m[i]=i;
  cin>>yoko;
  for(int i=0;i<yoko;i++){
    cin>>a>>c>>b;
    swap(m[a],m[b]);
  }
  for(int i=1;i<=tate;i++)
    cout<<m[i]<<endl;
  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		String answer = "";

		try {

			String N = sc.next();
			int judge = 0;

			if(N.equals("0")) {
				answer = "Yes";
			}else {

				for(int i = 0; i < N.length(); i++) {
					int num = ((int) N.charAt(i)) - 48;
					judge += num;
					if(judge >= 9) {
						judge %= 9;
					}
					/*
					System.out.println("num " + num );
					System.out.println("judge " + judge);
					*/
				}
				if(judge == 0) {
					answer = "Yes";
				}else {
					answer = "No";
				}
			}

		}finally {
			sc.close();
			System.out.println(answer);
		}
	}

}


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

int main(){
    int n, d;
    cin >> n >> d;
    vector<vector<int>> node(n, vector<int>(d));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < d; j++) cin >> node[i][j];
    }
    long long ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            long long tmp = 0;
            for (int k = 0; k < d; k++){
                tmp += (node[i][k] - node[j][k]) * (node[i][k] - node[j][k]);
            }
            for (int k = 0; k < 150; k++){
                if (k * k == tmp){
                    ans++;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char s[15];
	int i,locat=0;
	gets(s);
	if(s[0]=='A')
	{
		for(i=2;i<strlen(s)-1;i++)
		{
			if(s[i]=='C'){locat=i;break;}
		}
		if(locat==0){printf("WA\n");}
		else
		{
			for(i=1;i<strlen(s);i++)
			{
				if(i==locat)continue;
				if(s[i]>='A'&&s[i]<='Z')
				{
					printf("WA\n");
					break;
				}
				if(i==strlen(s)-1&&s[i]>='a'&&s[i]<='z')
				{
					printf("AC\n");
					break;
				}
			}
		}
	}
	else printf("WA\n");
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
long count[100001];
int main(int argc, char const *argv[]){
	long a,b,i,n,k,c=0;
	scanf("%ld %ld",&n,&k);
	for(i=0;i<n;i++){
		scanf("%ld %ld",&a,&b);
		count[a]+=b;
	}
	for(i=1;i<=100000;i++){
		c+=count[i];
		if(c>=k){
			printf("%ld\n",i);
			break;
		}
	}
	return 0;
}

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

N, Q = map(int, input().split())
C = list(map(int, input().split()))
LR = []
for i in range(Q):
    l, r = map(int, input().split())
    LR.append((l-1, r-1, i))


class FenwickTree(object):
    def __init__(self, n):
        self._bit = [0] * (n+1)
        self.n = n+1
    
    def add(self, i, a):
        i += 1
        while i < self.n:
            self._bit[i] += a
            i += i & -i
    
    def sum(self, i):
        i += 1
        ret = 0
        while i > 0:
            ret += self._bit[i]
            i -= i & -i
        return ret


def solve():
    memo = [-1] * N
    ST = []
    nst = 0
    for i, c in enumerate(C[::-1]):
        if memo[c-1] >= 0:
            ST.append((N-i-1, memo[c-1]))
            nst += 1
        memo[c-1] = N-i-1
    # ST.sort(reverse=True)
    LR.sort(reverse=True, key=lambda x:x[0])
    ans =[0 for _ in range(Q)]
    ft = FenwickTree(N+1)
    j = 0
    for l, r, i in LR:
        while j < nst and ST[j][0] >= l:
            ft.add(ST[j][1], 1)
            j += 1
        ans[i] = r - l + 1 - ft.sum(r)
    return ans

if __name__ == "__main__":
    print('\n'.join(map(str, solve())))


Measured memory_bytes: 237864
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define fr(i,n) for(ll i=0;i<n;i++)
#define pii pair <ll ,ll>
#define ppi pair < pii , int > 
#define x first
#define y second

#include <bits/stdc++.h> 
int main()
{
    ll n;cin>>n;
    ll a[n];fr(i,n)cin>>a[i];
    ll dp1[n][n];
    ll dp2[n][n];
    fr(i,n)dp1[i][i]=a[i];
    fr(i,n)dp2[i][i]=0;
    for(ll l=1;l<n;l++)
    {
        fr(k,n-l)
        {
            ll i = k;
            ll j = k + l;
            // cout<<i<<" "<<j<<endl;
            ll c = a[i] + dp2[i+1][j];
            ll d = a[j] + dp2[i][j-1];
            dp1[i][j] = max(c,d);
            if(c>=d)dp2[i][j]=dp1[i+1][j];
            else dp2[i][j] = dp1[i][j-1];
        }
    }
    cout<<dp1[0][n-1] - dp2[0][n-1]<<endl;
    return 0;
}

Measured memory_bytes: 140032
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;

const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 1e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{   
   	ll n;
   	cin >> n;
   	vector<char> c(n);
   	ll tr = 0;
   	for(int i = 0; i < n; i++)
   	{
   		cin >> c[i];
   		if(c[i] == 'R')
   			tr++;
   	}
   	if(tr == 0 || tr == n)
   	{
   		cout << 0 <<'\n';
   		return;
   	}
   	ll lf = 0, rt = n-1, ans = 0;
   	while(lf < rt)
   	{
   		if(c[lf] == 'W' && c[rt] == 'R')
   		{
   			swap(c[lf], c[rt]);
   			ans++;
   			lf++;
   			rt--;
   		}
   		while(c[lf] == 'R' && lf <= rt)
   			lf++;
   		while(c[rt] == 'W' && lf <= rt)
   			rt--;
   	}
   	cout << ans << '\n';

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef deque<int> di;
typedef pair<int,int> pi;
#define pb push_back
#define mp make_pair
#define mh make_heap
#define s second
#define f first
#define pf push_front
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 1000000000
#define FOR(i,a,b) for(int i=a;i<b;i++)


int main()
{
    //freopen("contest.txt","r",stdin);
    //freopen("contest.txt","w",stdout);
    IOS
    ll n,k;
    cin>>n>>k;
    ll a[n];
    FOR(i,0,n)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    ll sum=0;
    FOR(i,0,k)
    {
        sum+=a[i];
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reve(a) reverse(a.begin(), a.end())
#define PI 3.14159265359
typedef long long ll;
const ll MOD = 1e9+7;

ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b, a%b);
}
/*ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}*/

ll lcm(ll a, ll b){
  ll g = gcd(a, b);
  b /= g;
  a *= b;
  return a;
}

//素数判定 O(√n)
bool is_prime(int64_t n){
  for(int64_t i = 2; i*i<=n; i++){
    if(n%i==0) return false;
  }
  return n!=1;
}

//約数の列挙 O(√n)
vector<int64_t> dividor(int64_t n){
  vector<int64_t> res;
  for(int64_t i=1; i*i<=n; i++){
    if(n%i==0){
      res.push_back(i);
      if(i != n/i) res.push_back(i);
    }
  }
  return res;
}

//素因数分解 O(√n)
map<int64_t, int64_t> prime_factor(int64_t n){
  map<int64_t, int64_t> res;
  for(int64_t i=2; i*i<=n; i++){
    while(n%i==0){
      res[i]++;
      n /= i;
    }
  }
  if(n != 1) res[n] = 1;
  return res;
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int main(){
  /*int n;
  cin >> n; 
  vector<int> A(n);
  rep(i, n) cin >> A[i];*/ 
  string s;
  cin >> s;
  if(s=="ABC") cout << "ARC" << endl;
  else  cout << "ABC" << endl;

}

Measured memory_bytes: 3576
#include <stdio.h>
#include <algorithm>

using namespace std;
using ll = long long;

int n, u[100], v[100], b;
int main() {
	scanf("%d", &n);
	for (int i = 0; i + 1 < n; i++) {
		scanf("%d", &b);
		u[i] = v[i + 1] = b;
	}
	v[0] = u[n - 1] = 1e9;
	int s = 0;
	for (int i = 0; i < n; i++)
		s += min(u[i], v[i]);
	printf("%d\n", s);
}

Measured memory_bytes: 128
/* ITP1_10_A */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String[] str = br.readLine().split(" ");
      double[] p1 = {Double.parseDouble(str[0]), Double.parseDouble(str[1])};
      double[] p2 = {Double.parseDouble(str[2]), Double.parseDouble(str[3])};

      double ans = Math.sqrt(Math.pow((p1[0] - p2[0]), 2) + Math.pow((p1[1] - p2[1]), 2));//?????¢????¨?????????????
      System.out.printf("%.4f\n",ans);
    }catch(Exception e){
      System.out.println(e);
    }
  }
}

Measured memory_bytes: 24812
A,B,C,X,Y = map(int,input().split())
INF = 10**18

res = INF
for AB in range(max(X,Y)*2+1):
    x = AB*C
    a = AB//2
    b = AB//2
    if a < X:
        x += (X-a)*A
    if b < Y:
        x += (Y-b)*B
    if res > x:
        res = x
print(res)

Measured memory_bytes: 40940
#関数リスト
import sys
input = sys.stdin.readline


def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def main():
    num = I()
    result = 0
    for i in range(1,num+1,2):
        temp = len(make_divisors(i))
        if temp == 8:
            result += 1
    print(result)
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 62000
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int[] x = new int[m];
		int[] y = new int[m];
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			x[i] = Integer.parseInt(sa[0]);
			y[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		int[] parent = new int[n + 1];
		for (int i = 1; i < parent.length; i++) {
			parent[i] = i;
		}

		for (int i = 0; i < m; i++) {
			union(parent, x[i], y[i]);
		}

		Set<Integer> set = new HashSet<Integer>();
		for (int i = 1; i < parent.length; i++) {
			set.add(find(parent, i));
		}
		System.out.println(set.size());
	}

	static void union(int[] parent, int x, int y) {
		int px = find(parent, x);
		int py = find(parent, y);
		if (px != py) {
			parent[px] = py;
		}
	}

	static int find(int[] parent, int x) {
		if (parent[x] == x) {
			return x;
		}
		parent[x] = find(parent, parent[x]);
		return parent[x];
	}
}


Measured memory_bytes: 49172
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef  long long ll;
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
    ll N,M;
    int A[100010];
    int B[100010];
    cin>>N>>M;
    for(int i=0;i<M;i++){
        cin>>A[i]>>B[i];
        A[i]--;
        B[i]--;
    }
   UnionFind uf(N);
    long long cur = N * (N-1) / 2;
    vector<long long> res;
    for (int i = 0; i < M; ++i) {
        res.push_back(cur);
            
        int a = A[M-1-i], b = B[M-1-i];
        if (uf.issame(a, b)) continue;
        
        long long sa = uf.size(a), sb = uf.size(b);
        cur -= sa * sb;
        uf.merge(a, b);
    }
        
    reverse(res.begin(), res.end());
    for (int i = 0; i < res.size(); ++i) cout << res[i] <<endl;
}

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define int long
#define rep(a,b) for(int a=0;a<b;++a)
typedef struct{int p,c;}dat;
main(){
  int n,q,k;
  cin>>n;
  vector<vector<dat>> v(n+1);
  rep(i,n-1){
    int a,b,c;
    cin>>a>>b>>c;
    v[a].push_back({b,c});
    v[b].push_back({a,c});
  }
  queue<int> que;
  vector<bool> visited(n+1,false);
  vector<int> cost(n+1,INT_MAX);
  cin>>q>>k;
  que.push(k);
  cost[k]=0;
  while(!que.empty()){
    int p=que.front(); que.pop();
    visited[p]=true;
    for(auto r:v[p])if(!visited[r.p]){cost[r.p]=cost[p]+r.c;que.push(r.p);}
  }
  for(int i=0;i<q;++i){
    int x,y;
    cin>>x>>y;
    cout<<cost[x]+cost[y]<<"\n";
  }
}

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

int n, m, d[30][30], c[500][500], ans = 2e9, w[30][3];

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		for (int j = 0; j < m; j++)
			cin >> d[i][j];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			cin >> c[i][j];
			c[i][j]--;
		}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < m; k++)
				w[k][(i + j) % 3] += d[c[i][j]][k];
	for (int i = 0; i < m; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < m; k++) {
				if (i == j || j == k || k == i)
					continue;
				ans = min(ans, w[i][0] + w[j][1] + w[k][2]);
			}
	cout << ans << endl;
}


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

using namespace std;

map<string, int> wordCount;

int main() {
	string input = "";
	
	cin >> input;
	
	string maxWord = "";
	
	while (input.size() > 0) {
		
		if (wordCount.find(input) == wordCount.end()) {
			wordCount[input] = 1;
		} else {
			wordCount[input] = wordCount[input] + 1;
		}
		
		if (input.size() > maxWord.size()) {
			maxWord = input;
		}
		
		input = "";
		cin >> input;
	}
	
	int freqCount = 0;
	string freqWord;
	
	for (map<string, int>::iterator it = wordCount.begin(); it != wordCount.end(); it++) {
		if ((*it).second > freqCount) {
			freqCount = (*it).second;
			freqWord = (*it).first;
		}
	}
	
	cout << freqWord << " " << maxWord << endl;
	
	return 0;
}

Measured memory_bytes: 1196
n = int(input())

sList = sorted(list(map(int,input().split())),reverse=True)
res = []
acc = False
for i in range(n-1):
  if acc:
    acc = False
  else:
      if sList[i] == sList[i+1]:
        res.append(sList[i])
        acc = True
      if len(res) == 2:
        print(res[0]*res[1])
        exit(0)

print(0)



Measured memory_bytes: 62704
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);

int main() {
	vector<int> a(3);
	rep(i, 3) cin >> a[i];
	sort(a.begin(), a.end());
	if (a[0] == a[2]) cout << "No";
	else if(a[1]!=a[0]&&a[1]!=a[2]) puts("No");
	else puts("Yes");
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
h = na()

c = 1
maxh = h[0]
for i in range(n-1):
    if maxh <= h[i+1]:
        c += 1
        maxh = h[i+1]

print(c)


Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    let mut i = 1;
    input!{
        n: usize,
    }
    loop{
        let mut x = i;
        if x%3 == 0{
            print!(" {}", i);
            if i+1 > n { break; }
        }
        else{
            loop{
                if x%10 == 3{
                    print!(" {}", i);
                    break;
                }
                x /= 10;
                if x == 0 { break; }
            }
        }
        i = i+1;
        if i > n { break; }
    }
    println!{""};
}


Measured memory_bytes: 5032
S = list(input())
K = int(input())
flag = 0
i = 0
while i < K: 
  if int(S[i]) == 1:
    flag = 1
    i = i + 1 
  else:
      print(int(S[i]))
      flag = 0
      break
if flag == 1:
  print(1)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;


int main() {
	ll N;
	string S, T;
	cin >> N >> S >> T;
	string ans = "";
	rep(i, N) {
		ans += S[i];
		ans += T[i];
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using ll = long long int;

int main() {
    // Input
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    // Process
    double m = M * 360 / 60;
    double h = H * 360 / 12 + m / 12;
    double degree = abs(m - h);
    if (degree > 180) degree = 360 - degree;
    double ans = sqrt(A * A + B * B - 2 * A * B * cos(degree * M_PI / 180));

    // Output
    cout << fixed << setprecision(15) << ans << endl;

    return 0;
}


Measured memory_bytes: 4184