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

using namespace std;

char red[500][500], blue[500][500];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (i % 2 == 0) {
				if (j == W - 1) {
					red[i][j] = '.';
					blue[i][j] = '#';
				} else {
					red[i][j] = '#';
					blue[i][j] = '.';
				}
			} else {
				if (j != 0) {
					red[i][j] = '.';
					blue[i][j] = '#';
				} else {
					red[i][j] = '#';
					blue[i][j] = '.';
				}				
			}
		}
	}

	for (int i = 0; i < H; i++) {
		string a;
		cin >> a;
		for (int j = 0; j < W; j++) {
			if (a[j] == '#') {
				red[i][j] = '#';
				blue[i][j] = '#';
			}
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << red[i][j];
		}
		cout << endl;
	}
	cout << endl;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << blue[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
using ll = long long;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = max({a * c, a * d, b * c, b * d});
  if (a * b <= 0 || c * d <= 0) {
    ans = max(ans, 0ll);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define sutu (ll)1e18+10
#define ll long long
using namespace std;
#define  pi  3.141592653
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t,n,c=0,temp;
  cin>>n>>t;
  while(t--){
    cin>>temp;
    c+=temp;
  }
  if(n>=c)
  cout<<n-c<<endl;
  else cout<<-1<<endl;
}


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

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

    vector<vector<bool>> dp(N + 1, vector<bool>(1 << 24, false));
    dp[0][1] = true;

    int D;
    for (int i = 1; i <= N; i++)
    {
        cin >> D;
        if (D == 0)
        {
            continue;
        }
        for (int j = 0; j < (1 << 24); j++)
        {
            if (dp[i - 1][j])
            {
                if ((j >> D) ^ 1)
                {
                    dp[i][(j | (1 << D))] = true;
                }
                if ((j >> (24 - D)) ^ 1)
                {
                    dp[i][(j | (1 << (24 - D)))] = true;
                }
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < (1 << 24); i++)
    {
        if (dp[N][i])
        {
            int s = INT_MAX;
            bitset<24> b(i);
            for (int j = 0; j < 24; j++)
            {
                for (int k = 0; k < j; k++)
                {
                    if (b[j] && b[k])
                    {
                        s = min(s, min((j - k), 24 - (j - k)));
                    }
                }
            }
            // assert(b.count() == N + 1);
            if (s != INT_MAX && b.count() == N + 1)
            {
                ans = max(ans, s);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 107008
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main(){
	int A[3];
	scanf("%d %d %d", &A[0], &A[1], &A[2]);

	int m = A[0], M = A[0];
	REP(i, 3){
		if (A[i] < m){
			m = A[i];
		}
		if (A[i]>M){
			M = A[i];
		}
	}
	printf("%d\n", M - m);


	return 0;
}

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

int main()
{
    long long n, k;
    scanf("%lld%lld", &n,&k);
    
    int flag = 1;
    
    if (k < n){
        if ((n-k)%k == 0) {
            printf("0\n");
            return 0;
        }
        else n -= ((n-k)/k + 1)*k;
    }
        
    if (llabs(k-n) < n){
        n = llabs(k-n);
    }
    printf("%lld\n",n);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <string>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int>L(N);
	for (int i = 0; i < N; i++) {
		cin >> L.at(i);
	}
	sort(L.begin(), L.end(), greater<int>());
	int ans = 0;
	for (int i = 0; i < N - 2; i++) {
		for (int j = i + 1; j < N - 1; j++) {
			for (int k = j + 1; k < N; k++) {
				if (L.at(i) < L.at(j) + L.at(k)) ans++;
			}
		}
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

using Graph = vector<vector<int>>;
typedef pair<int, int> P;

int N,M;

bool check(Graph G, vector<int> v){
    rep(i,N-1){
        if(!G[v[i]][v[i+1]]){
            return false;
        }
    }
    return true;
}

int main(){
    cin >> N >> M;
    Graph G(N,(vector<int>(N,0)));
    rep(i,M) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        G[a][b] = G[b][a] = 1;
    }
    vector<int> v(N);
    rep(i,N) v[i] = i;
    long long ans = 0;
    do{
        if(v[0]==0 && check(G, v)) ans++;
    }while(next_permutation(v.begin(), v.end()));
    cout << ans << endl;
}



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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    LL k, s;
    cin >> k >> s;

    LL ans = 0;
    for(LL i = 0; i <= k; i++){
        for(LL j = 0; j <= k; j++){
            if(i + j <= s && s - i - j <= k)
                ans++;
        }
    }


    cout << ans << '\n';
    return 0;
}



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

#define M_PI 3.141592653589793


int main(void) {

	int i = 0, j, k;
	int sum;
	int alpha[26] = { 0 };
	char temp[27] = "abcdefghijklmnopqrstuvwxyz";

	char str[1200];

	scanf("%[\x01-\xff]", str);
	

	for (i = 0; i < strlen(str); i++) {
		if (str[i] >= 'a' && str[i] <= 'z') {
			alpha[str[i] - 'a']++;
		}
		else if (str[i] >= 'A' && str[i] <= 'Z') {
			alpha[(int)str[i] - 'A']++;
		}
	}
	for (i = 0; i < 26; i++) {
		printf("%c : %d\n", temp[i], alpha[i]);
	}

	return 0;

}

Measured memory_bytes: 2728
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int dx[4] = {1, 0 , -1, 0}, dy[4] = {0, 1, 0, -1};
typedef pair<int, int> pi;

int main() {
  int h,w;
  cin >> h >> w;

  char field[h][w];
  int d[h][w], bc = 0;
  rep(i,h)rep(j,w) {
    cin >> field[i][j];
    if (field[i][j] == '#') bc++;
    d[i][j] = 1000000;
  }

  queue<pi> que;
  que.push(make_pair(0,0));
  d[0][0] = 0;

  while (que.size() > 0) {
    pi p = que.front(); que.pop();
    if (p.first == h-1 and p.second == w-1) {
      break;
    }

    for (int i = 0; i < 4; ++i) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx and nx < h and ny < w and ny >= 0 and field[nx][ny] != '#' and d[nx][ny] == 1000000) {
        que.push(make_pair(nx,ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }

  if (d[h-1][w-1] == 1000000) {cout << -1 << endl; return 0;}
  int ans = h*w - bc - 1 - d[h-1][w-1];

  cout << ans << endl;
}


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

int gcd(int a, int b) {
  if (a < b) {
    int c = a;
    a = b;
    b = c;
  }

  if (b == 0) {
    return a;
  }

  return gcd(b, (a % b));
}

int main() {
  int N, X;
  std::cin >> N >> X;

  std::vector<int> x(N);
  for (int i = 0; i < N; i++) {
    std::cin >> x.at(i);
    x.at(i) = std::abs(x.at(i) - X);
  }

  int D;
  if (N == 1) {
    D = x.at(0);
  } else {
    D = gcd(x.at(0), x.at(1));
    for (int i = 2; i < N; i++) {
      D = gcd(D, x.at(i));
    }
  }

  std::cout << D << std::endl;
  return 0;
}

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

#define M 1046257
#define L 14

char H[M][L];

/* 文字から数値に変換 */
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

/* 文字列から数値へ変換して key を生成する */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i=0, h;
  key = getKey(str);
  while(1) {
    h = (h1(key) + i*h2(key)) % M;
    i++;
    if(!strcmp(H[h],str)) return 1;
    else if ( !strlen(H[h]) ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i=0, h;
  key = getKey(str); /* 文字列を数値に変換 */
  while(1) {
    h = (h1(key) + i * h2(key)) %M;
    i++;
    if(!strcmp(H[h],str)) return 1;
    else if(!strlen(H[h])) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str);
    if(!strcmp(com,"insert")) {
      insert(str);
    } else if(!strcmp(com,"find")) {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    } else {
      printf("command error\n");
    }
  }
  return 0;
}



Measured memory_bytes: 16044
#include<iostream>
#include<stdio.h>

int main(){
int n, ma = -1000000, mi = 1000000, a;
long long sum = 0;
std::cin >> n;
for(int i=0;i<n; i++){
    std::cin >> a;
    ma = std::max(a,ma);
    mi = std::min(a,mi);
    sum += a;
}
std::cout << mi << " " << ma << " " << sum << std::endl;
return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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; }

int main () {
  int n;
  ll x;
  cin >> n >> x;
  vll a(n);
  rep(i,n) cin >> a[i];
  
  vll a_original = a;
  if (a[0] > x) a[0] = x;
  rep(i,n-1) {
    ll sum2 = a[i] + a[i+1];
    if (sum2 <= x) continue;
    a[i+1] -= sum2 - x;
  }

  ll ans = 0;
  rep(i,n) {
    ans += a_original[i] - a[i];
  }
  cout << ans << endl;
  return 0;
}

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

const ll INF=LONG_LONG_MAX;

int main(){
    int a,b,q;
    cin>>a>>b>>q;
    vector<ll>s(a),t(b);
    rep(i,a)cin>>s[i];
    rep(i,b)cin>>t[i];
    rep(i,q){
        ll x;
        scanf("%lld", &x);
        ll ans=INF;
        ll d1=-1,d2=-1,d3=-1,d4=-1;
        d2=lower_bound(s.begin(),s.end(),x)-s.begin(),d1=d2-1;
        d4=lower_bound(t.begin(),t.end(),x)-t.begin(),d3=d4-1;
        if((0<=d1&&d1<a)&&(0<=d3&&d3<b)){
            ll cnt=max(abs(x-s[d1]),abs(x-t[d3]));
            ans=min(ans,cnt);
        }
        if((0<=d2&&d2<a)&&(0<=d4&&d4<b)){
            ll cnt=max(abs(x-s[d2]),abs(x-t[d4]));
            ans=min(ans,cnt);
        }
        if((0<=d2&&d2<a)&&(0<=d3&&d3<b)){
            ll cnt=min(abs(x-s[d2])*2+abs(x-t[d3]),abs(x-s[d2])+abs(x-t[d3])*2);
            ans=min(ans,cnt);
        }
        if((0<=d1&&d1<a)&&(0<=d4&&d4<b)){
            ll cnt=min(abs(x-s[d1])*2+abs(x-t[d4]),abs(x-s[d1])+abs(x-t[d4])*2);
            ans=min(ans,cnt);
        }
        printf("%lld\n",ans);
    }
}

Measured memory_bytes: 4848
#include<stdio.h>
int main(){
	int n,i,j,k,l,count;
	while(scanf("%d",&n)!=EOF){
		count=0;
		for(i=0;i<10;i++){
			for(j=0;j<10;j++){
				for(k=0;k<10;k++){
					for(l=0;l<10;l++){
						if(i+j+k+l==n){
							count++;
						}
					}
				}
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b;
	for(int i=0;i<2;i++){
		if(a>=b){
			c=c+a;
			a--;
		}else{
			c=c+b;
			b--;
		}
	}
	cout << c << "\n";
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

//XOR系はbitごとに独立して考える
//２進数の足し算をしっかりイメージする 1 + 2 + 4 + 8....
ll fast_pow(ll a, ll n, ll mod = MOD){
    if(n == 0) return 1;
    //べき数nが奇数, aを前にだして, a^n-1の気持ちに
    if(n % 2 == 1){
        return a * fast_pow(a, n - 1) % mod;
    }else{
        //べき数nが偶数のとき，べき数を半分にして, aをまとめる. べき数を半分にする
        return fast_pow(a * a % mod, n / 2) % mod;
    }
}

int main() {

    ll N; cin >> N;
    vector<ll > A(N, 0);

    for(ll i = 0; i < N; i++){
        cin >> A[i];
    }

    ll sum = 0;

    vector<vector<ll > > memo(60, vector<ll >(2, 0));
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j < 60; j++){
            if((A[i] >> j) & 1 == 1){
                memo[j][1]++;
            }else{
                memo[j][0]++;
            }
        }
    }

    //算出
    for(ll j = 0; j < 60; j++){
        sum += fast_pow(2, j) * (memo[j][0] * memo[j][1] % MOD) % MOD;
        sum %= MOD;
    }
    cout << sum << endl;

}

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

int main() {
	int n;
	cin >> n;
	int e[n];
	for (int i = 0; i < n; i++) {
		cin >> e[i];
	}
	sort(e, e + n);
	int sum = 0;
	for (int i = 0; i < n - 1; i++) {
		sum += e[i];
	}
	if (e[n - 1] < sum) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
const int N=1e5+10,P=1e9+7;
int n,m;
int w[N];
struct Mt {
  int M[3][3];
}A,B;
Mt operator *(Mt a,Mt b) {
  Mt c;
  for(int i=0;i<3;++i) {
    for(int j=0;j<3;++j) {
      c.M[i][j]=0;
      for(int k=0;k<3;++k) {
        (c.M[i][j]+=1ll*a.M[i][k]*b.M[k][j]%P)%=P;
      }
    }
  }
  return c;
}
Mt Pow(Mt a,int k) {
  Mt res;
  for(int i=0;i<3;++i) {
    for(int j=0;j<3;++j) {
      res.M[i][j]=i==j;
    }
  }
  for(;k;k>>=1) {
    if(k&1) res=res*a;
    a=a*a;
  }
  return res;
}
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n,m);
  for(int i=1;i<=m;++i) read(w[i]);
  A.M[0][0]=1;
  int now=0;
  for(int i=1;i<=m;++i) {
    B.M[0][0]=1; B.M[0][1]=1; B.M[0][2]=1;
    B.M[1][0]=0; B.M[1][1]=1; B.M[1][2]=2;
    B.M[2][0]=1; B.M[2][1]=1; B.M[2][2]=2;
    B=Pow(B,w[i]-now);
    A=A*B;
    int a=A.M[0][0],b=(A.M[0][0]+A.M[0][1])%P,c=((A.M[0][0]+A.M[0][1]*2%P)%P+A.M[0][2])%P;
    A.M[0][0]=a; A.M[0][1]=b; A.M[0][2]=c;
    now=w[i]+1;
  }
  if(now!=n) {
    B.M[0][0]=1; B.M[0][1]=1; B.M[0][2]=1;
    B.M[1][0]=0; B.M[1][1]=1; B.M[1][2]=2;
    B.M[2][0]=1; B.M[2][1]=1; B.M[2][2]=2;
    B=Pow(B,n-now);
    A=A*B;
  }
  printf("%d\n",A.M[0][2]);
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
    int n=0, q=0, C=0;
    int S[100000]={0}, T[100000]={0};
    int i=0, j=0;
    int key;
    
    scanf("%d", &n);
    for (i=0; i<n; i++){
        scanf("%d", &S[i]);
    }
    scanf("%d", &q);
    for (j=0; j<q; j++){
        scanf("%d", &T[j]);
    }
    
    for (j=0; j<q; j++){
        i = 0;
        key = T[j];
        S[n] = key;
        while (S[i] != key){
            i++;
        }
        if(i!=n) C++;
    }
    
    printf("%d\n",C);
    return 0;
}


Measured memory_bytes: 2620
#include <iostream>

using namespace std;

int main() {
    string line; cin >> line;

    char last = line[0];
    for(int i = 0; i < 3; ++i) {
        if(last != line[i]) {
            cout << "Yes" << endl;
            return 0;
        }
        last = line[i];
    }

    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int a[202];
int main()
{
    ft
    int i,n,m,l=INT_MAX,x,y;
    cin>>m>>n;
    for(int r,i=0; i<n; i++)
    {
        cin>>r;
        a[r]=1;
    }
    for(i=0; i<201; i++)
    {
        if(a[i]==0)
        {
            x=abs(m-i);
            if(x<l)
            {
                y=i;
                l=x;
            }
        }
    }
    cout<<y<<"\n";
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1L << 30
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int N;
vector<long> x(1000);

vector<long> dp(1000, INF);



int main(){
	cin >> N;
	rep(i, N) cin >> x.at(i);
	int max = *max_element(x.begin(), x.end());
	//cout << "max: " << max << endl;
	int ans = INF;
	for (int p=1; p<max+1; p++){
		int sum = 0;
		rep(i, N){
			sum += pow(abs(x[i]- p), 2);
		}
		chmin(ans, sum);
	}
	cout << ans << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll N, S, ans=0, tmp=0;
vector<ll> A;
vector<vector<ll>> G;

vector<ll> enum_divisors(ll N) {
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

signed main(){
    cin >> N >> S;
    if(N<S) {
        cout << -1 << endl;
        return 0;
    }
    if(N==S) {
        cout << N+1 << endl;
        return 0;
    }
    for(int i=2;i<=sqrt(N);i++) {
        tmp = N;
        ans = 0;
        while(tmp>0) {
            ll dt = tmp%i;
            if(dt<0) dt += i;
            ans += dt;
            tmp /= i;
        }
        if(ans==S) {
            cout << i << endl;
            return 0;
        }
    }
    const auto &res = enum_divisors(N-S);
    for (auto p : res) {
        if(p+1>sqrt(N)) {
            if(N/(p+1)+N%(p+1)==S) {
                cout << p+1 << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3668
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextStr()

	if s[0] != 'A' {
		fmt.Println("WA")
		return
	}
	if strings.Count(s, "C") != 1 {
		fmt.Println("WA")
		return
	}
	cidx := strings.Index(s, "C")
	if cidx == 1 || cidx == len(s)-1 {
		fmt.Println("WA")
		return
	}

	for i := 1; i < len(s); i++ {
		if s[i] != 'C' {
			if isKomoji(s[i]) == false {
				fmt.Println("WA")
				return
			}
		}
	}

	fmt.Println("AC")

}
func isKomoji(a byte) bool {
	return ((a >= 'a') && (a <= 'z'))
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
ll a,b,c,d;
map<ll,ll>memo;
ll dfs(ll v){
  if(v==0) return 0;
  if(v==1) return d;
  if(memo.count(v)) return memo[v];
  ll l2=(v/2)*2;
  ll r2=((v+1)/2)*2;
  ll l3=(v/3)*3;
  ll r3=((v+2)/3)*3;
  ll l5=(v/5)*5;
  ll r5=((v+4)/5)*5;
  ll MIN=1e18;
  if(v<MIN/d) MIN=v*d;
  MIN=min(MIN,dfs(l2/2)+(v-l2)*d+a);
  MIN=min(MIN,dfs(r2/2)+(r2-v)*d+a);
  MIN=min(MIN,dfs(l3/3)+(v-l3)*d+b);
  MIN=min(MIN,dfs(r3/3)+(r3-v)*d+b);
  MIN=min(MIN,dfs(l5/5)+(v-l5)*d+c);
  MIN=min(MIN,dfs(r5/5)+(r5-v)*d+c);
  memo[v]=MIN;
  return MIN;
}

int main(){
  ll t;
  cin >> t;
  for(int i=0; i<t; i++){
    memo.clear();
    ll n;
    cin >> n;
    cin >> a >> b >> c >> d;
    cout << dfs(n) << endl;
  }
}
  
  
  


Measured memory_bytes: 4388
import sys
n=int(input())
s=input()
num = 0
if n%2 ==1:
  num=1
  print("No")
  sys.exit()
else:
  for i in range(int(n/2)):
    if s[i] != s[int(i+n/2)]:
      print("No")
      num=1
      break
if num ==0:
  print("Yes")

Measured memory_bytes: 3060
import collections
def slove(n, a):
    b = collections.deque()

    for i, x in enumerate(a):
        if i % 2 == 0:
            b.append(x)
        else:
            b.appendleft(x)
    if n % 2 == 0:
        return " ".join(b)
    else:
        return " ".join(reversed(b))

if __name__ == "__main__":
    n = int(input())
    a_list = [i for i in input().split()]
    print(slove(n, a_list))


Measured memory_bytes: 26556
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i,n) for(int i=n-1;i>=0;i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef pair<int,int> P;
//typedef long long int ll;

int ans;

signed main(){

	int n;
	cin>>n;
  	if(n==1){
      	cout<<0<<endl;
      	return 0;
    }
	for(int i=1;i*i<=n;i++){
		if(n%i==0 && n/(n/i-1)==n%(n/i-1)){
			ans+=n/i-1;
		}
	}
	cout<<ans<<endl;
}


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

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

    int n;
    cin >> n;
    vector<vector<int>> adj(n);
    vector<pair<int, int>> es;
    map<pair<int, int>, int> col;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
        es.emplace_back(minmax(a, b));
    }
    int maxdeg = 0;
    for (int i = 0; i < n; i++) {
        maxdeg = max(maxdeg, (int)adj[i].size());
    }
    auto dfs = [&](auto dfs, int v, int p) -> void {
        int cnt = 0;
        for (auto &s : adj[v]) {
            if (s != p) {
                cnt++;
                dfs(dfs, s, v);
            }
        }
        maxdeg = max(maxdeg, cnt);
    };

    dfs(dfs, 0, -1);
    auto kek = [&](auto kek, int v, int p, int c) -> void {
        col[minmax(v, p)] = c;
        int cur = 1;
        for (auto &s : adj[v]) {
            if (s != p) {
                if (cur == c) cur++;
                kek(kek, s, v, cur++);
            }
        }
    };
    kek(kek, 0, -1, 0);
    cout << maxdeg << endl;
    for (int i = 0; i < n - 1; i++) {
        cout << col[es[i]] << '\n';
    }
}


Measured memory_bytes: 13048
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        a: i32, b: i32,
    }
    let mut c = if a <= 3 { 100000 * (4 - a) } else { 0 };
    c += if b <= 3 { 100000 * (4 - b) } else { 0 };
    if a == 1 && b == 1 {
        c += 400000;
    }
    puts!("{}\n", c);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
 
#A
def A():
    n = II()
    print((n-2)*180)
    return
 
#B
def B():
    b = S()
    kati = b.count("o")
    kati += 15 - len(b)
    if kati >= 8:
        print("YES")
    else:
        print("NO")
    return
 
#C
def C():
    return
 
#D
def D():
    n = II()
    ab = LIR_(n-1)
    C = LI()
    C.sort()
    c = deque(C)
    edg = [[] for i in range(n)]
    for a, b in ab:
        edg[a].append(b)
        edg[b].append(a)
    for num,e in enumerate(edg):
        if len(e) == 1:
            start = num
            break
    q = deque()
    ans = [0 for i in range(n)]
    q.append(start)
    ans[start] = c.pop()
#    print(start)
    while q:
        p = q.pop()
        for e in edg[p]:
            if not ans[e]:
                ans[e] = c.pop()
                q.append(e)
    anssum = 0
    for a, b in ab:
        anssum += min(ans[a], ans[b])
    print(anssum)
    ans = list(map(str, ans))
    print(" ".join(ans))
 
 
    return
 
#E
def E():
    return
 
#F
def F():
    return
 
#G
def G():
    return
 
#H
def H():
    return
 
#Solve
if __name__ == '__main__':
    D()

Measured memory_bytes: 49116
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long
#define endl '\n'

int32_t main()
{
    IOS;
    int n;
    cin>>n; 
    int arr[n];
    int val=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        val^=arr[i];
    }
    for(int i=0;i<n;i++)
        cout<<(val^arr[i])<<" "; 
}


Measured memory_bytes: 5148
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;
const double PI=3.14159265359;
 
 

 
int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin>>s;
    
    
    int k,n=s.size();
    cin>>k;
    
    vector<string> vs;
    for(int i=0; i<n; i++){
        for(int j=i; j<min(n, i+5); j++){
            vs.push_back(s.substr(i,j-i+1));
        }
    }
    sort(vs.begin(), vs.end());
    unique(vs.begin(), vs.end());
    cout<<vs[k-1];
    
    
    return 0;
    
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;
int main(){
  int N,K;
  cin>>N>>K;
  vector<int>count(N);
  for(int i=0;i<N;i++){
    int A;
    cin>>A;
    count[A-1]++;
  }
  sort(count.begin(),count.end());
  int ans=0;
  for(int i=0;i<N-K;i++){
  ans+=count.at(i);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		ArrayList<Integer>[] g = new ArrayList[n];
		for(int i = 0; i < n; i++){
			g[i] = new ArrayList<>();
		}
		for(int i = 0; i < n-1; i++){
			st = new StringTokenizer(br.readLine());
			int a = Integer.parseInt(st.nextToken())-1;
			int b = Integer.parseInt(st.nextToken())-1;
			g[a].add(b);
		}
		long[] vals = new long[n];
		for(int i = 0; i < Q; i++){
			st = new StringTokenizer(br.readLine());
			int p = Integer.parseInt(st.nextToken())-1;
			long x = Integer.parseInt(st.nextToken());
			vals[p] += x;
		}
		LinkedList<Integer> q = new LinkedList<>();
		q.add(0);
		while(!q.isEmpty()){
			int u = q.removeFirst();
			for(int v: g[u]){
				vals[v] += vals[u];
				q.add(v);
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < n; i++){
			sb.append(vals[i]+" ");
		}
		bw.write(sb.toString().trim());
		bw.write("\n");
		bw.flush();
	}

}


Measured memory_bytes: 120628
#include<stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1
#define false 0
#define true 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1],x[N][N];

void initialize();
void printBoard();
void recursive(int );

int main(){

  int i,j;
  int k,r,c;
  
  initialize();

  for(i=0;i<N;i++){
    for(j=0;j<N;j++)x[i][j]=false;
  }

  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    x[r][c]=true;
  }

  recursive(0);

  return 0;
}

void initialize(){
  int i;
  
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
  }
  for(i=0;i<2*N-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
}

void printBoard(){
  int i,j;
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(x[i][j]){
	if(row[i]!=j)return ;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;
  
  if(i==N){
    printBoard();
    return;
  }

  for(j=0;j<N;j++){
    if(NOT_FREE==col[j] || NOT_FREE==dpos[i+j] || NOT_FREE==dneg[i-j+N-1])continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    
    recursive(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}











Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
//Credits: errichto
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N=3003;
ll dp[2][N];

void solve(){
	dp[1][1]=1;
	int n;
	cin>>n;
	string s;
	cin>>s;
	int t=0;
	fr(i,2,n+1){
		fr(j,0,i+1)
			dp[t][j]=0;
		fr(j,1,i+1){
			if(s[i-2]=='<')
				dp[t][j]=(dp[t][j]+ (dp[t^1][j-1]) +MOD)%MOD;
			else
				dp[t][j]=(dp[t][j]+ (dp[t^1][i-1]-dp[t^1][j-1]) + MOD)%MOD;
		}
		fr(j,1,i+1)
			dp[t][j]=(dp[t][j]+dp[t][j-1])%MOD;
		t^=1;
	}
	cout<<dp[t^1][n]<<endl;
	return;
}

int main()
{
	boost();
	
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}

Measured memory_bytes: 3708
//                          VIVEK UPADHYAY
//                         MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
//                        $$ JAB-TAK TODEGA NHI,
//                           TAB -TAK CHODEGA NHI :D
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<endl ;
#define ok cout<<"ok\n" ;
typedef long long ll;
const int MAXN = 1e5 + 10 ;
const int MAX = 1e6 ;
double pi = 3.1415926535897932384626433832795;
const ll inf=1e18 ;
ll mod = 1e9 + 7 ;
int main(){
    string s ;
    cin >> s ;
    if(s.length()==2) cout<<s<<endl;
    else {
        reverse(s.begin(),s.end());
        cout<<s<<endl;
    }
}


Measured memory_bytes: 256
using System;


namespace aoj8c_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            int[] counter = new int[26];

            while((line = Console.ReadLine()) != null)
            {
                char[] ch = line.ToCharArray();
                for( int i = 0; i < ch.Length; i++)
                {                   
                    if (char.IsUpper(ch[i]))
                    {
                        ch[i] = char.ToLower(ch[i]);
                    }

                    if (char.IsLower(ch[i]))
                    {
                        counter[ch[i] - 'a']++;
                    }
                }
                
            }
            for (int i = 0; i < 26; i++)
            {
                Console.WriteLine(Convert.ToChar(i + 'a') + " : " + counter[i]);
            }
        }
    }
}

Measured memory_bytes: 9180
import sys
from collections import deque
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())

    g = [ [] for i in range(n) ]

    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1

        g[a].append(b)
        g[b].append(a)

    q = deque([0])
    f = [ -1 ] * n

    while q:
        u = q.popleft()

        for v in g[u]:
            if f[v] == -1:
                f[v] = u
                q.append(v)

    ans = [ f[x] + 1 for x in range(1, n) ]
    print('Yes')
    print("\n".join(map(str, ans)))

main()


Measured memory_bytes: 104052
n=int(input())
a=[0]*(n+1)
for i in range(2,n+1):
    x=i
    for j in range(2,n+1):
        while x%j==0:
           a[j]+=1
           x//=j
def num(s):
    return len(list(filter(lambda x:x>=s-1,a))) 
ans=0
ans+=num(75)
ans+=num(15)*(num(5)-1)
ans+=num(25)*(num(3)-1)
ans+=num(5)*(num(5)-1)*(num(3)-2)//2
print(ans)

Measured memory_bytes: 38512
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.8.2)

import math
import statistics
import numpy as np
import queue
import itertools
import functools 

def ddist(x, y):
	return x**2 + y**2

ans = 0
n, d = map(int, input().split())
for _ in range(n):
  x, y = map(int, input().split())
  if(ddist(x, y) <= d**2):
    ans += 1
print(ans)


Measured memory_bytes: 27376
#include <iostream>
#include <vector>
#include <deque>
using i64 = long long;

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<std::vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        std::cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int ret = 0;
    std::vector<int> done(n);
    for (int i = 0; i < n; i++) if (!done[i]) {
        ret++;
        std::deque<int> q { i };
        done[i] = 1;
        while (!q.empty()) {
            const int v = q.front();
            q.pop_front();
            for (const int to : g[v]) if (!done[to]) {
                done[to] = 1;
                q.push_back(to);
            }
        }
    }

    std::cout << ret - 1 << std::endl;

    return 0;
}


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


int main(){
  ll n;
  cin >> n;
  
  ll ans = n-1;
  for(ll i=1; i<=sqrt(n); i++){
    ll j = (ll)(n/i);
    if(i*j == n){
      if(i+j-2 < ans){
        ans = i+j-2;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n, k;
  int x[110];
  cin >> n >> k;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    ans += min(2 * abs(x[i]), 2 * abs(x[i] - k));
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	//for(int i=0;i<N;i++) {}
	public static void main(String[] args) {
		//String S=sc.next();
		
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		long X=sc.nextLong();
		long n=100;
		int ans=0;
		while(n<X) {
			n*=1.01;
		//	p(ans+" "+n);
			ans++;
			
			
		}
		
		p(ans);
		
		
		
		
		
		
		
		
		
		
		
		
		
	}
	
	
	
	
	
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 35840
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF (LL)1e15
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n;
vector<LL> a, ruiseki1, ruiseki2;

/**********************************************/

int main(){
    cin >> n;
    a.resize(n+5);
    ruiseki1.resize(n+5);
    ruiseki2.resize(n+5);

    REP(i, n) cin >> a[i];
    
    ruiseki1[0] = 0;
    ruiseki2[0] = 0;
    LL cnt1 = 0, cnt2 = 0, sum1 = 0, sum2 = 0;
    REP(i, n){
        ruiseki1[i+1] = ruiseki1[i] + a[i];
        ruiseki2[i+1] = ruiseki2[i] + a[i];
        
        if(i % 2 == 0){
            if(ruiseki1[i+1] >= 0){
                cnt1 += abs(ruiseki1[i+1]) + 1;
                sum1 -= abs(ruiseki1[i+1]) + 1;
                ruiseki1[i+1] = -1;
            }
            if(ruiseki2[i+1] <= 0){
                cnt2 += abs(ruiseki2[i+1]) + 1;
                sum2 += abs(ruiseki2[i+1]) + 1;
                ruiseki2[i+1] = 1;
            }
        }else{
            if(ruiseki1[i+1] <= 0){
                cnt1 += abs(ruiseki1[i+1]) + 1;
                sum1 += abs(ruiseki1[i+1]) + 1;
                ruiseki1[i+1] = 1;
            }
            if(ruiseki2[i+1] >= 0){
                cnt2 += abs(ruiseki2[i+1]) + 1;
                sum2 -= abs(ruiseki2[i+1]) + 1;
                ruiseki2[i+1] = -1;
            }
        }
    }
    cout << min(cnt1, cnt2) << endl;

}


Measured memory_bytes: 2688
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n, t, e;
    cin >> n >> t >> e;

    for(int i=1; i<=n; ++i){
        int x;
        cin >> x;

        int t2 = t / x * x;
        if(t-e <= t2 && t2 <= t+e || t-e <= t2+x && t2+x <= t+e){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}

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

/* */
int gcd(int m, int n) {
  if (n == 0)
    return m;
  else
    return gcd(n, m % n);
}
 

int main(){
    // 入力スタンダード
    int k;
    cin >> k;

    ll sum=0;
    for(int a=1; a<k+1; a++){
        for(int b=1; b<k+1; b++){
            for(int c=1; c<k+1; c++){
                sum += gcd(a,gcd(b,c));

            }
        }
    }

    cout << sum <<endl;


    return 0;
}

Measured memory_bytes: 3632
m, d = map(int, input().split())
ans = 0
if d <= 21:
  ans = 0
else:
  for i in range(m):
    i += 1
    for j in range(21, d):
      j += 1
      d1 = int(str(j)[0])
      d2 = int(str(j)[1])
      if d1 * d2 == i and d1 >= 2 and d2 >= 2:
        ans += 1
print(ans)

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

const int64 mod = 1e9+7;

using Row = vector<int64>;
using Mat = vector<Row>;

int main(void){
	int32 N;
	cin >> N;
	vector<int64> h(N), dp(N+1, INF_LL);
	REP(i, N) cin >> h[i];
	dp[0] = 0;
	REP(i, N){
		if(i+1 < N)
			chmin(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
		if(i+2 < N)
			chmin(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
	}
	cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
bool check(int x ,int y ,int z)
{

    if(x!=y && y!=z && z!=x)
    {
        if(z <x + y)
        {
            return true ;
        }
        else 
        {
            return false; 
        }
    }
    else 
    {
        return false;
    }

}
int main()
{
    int  n; 

    cin>> n; 



    vector<long long int> a;
    set<long long> s ; 

    for(int i =0 ; i<n;i++ )
    {
        int x;
        cin>> x; 

        a.push_back(x);
    }
    

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

    long long int sum= 0  ; 

    for(int i=0 ; i<n -1;i++ )
    {
        for(int j = i + 1 ; j<n;j++ )
        {
            for(int k= j+1; k<n ; k++ )
            {
                if(check(a[i], a[j],a[k]))
                {
                    sum++ ; 
                }
                
            }
        }
    }
    cout<<sum<<endl; 


}

Measured memory_bytes: 3612