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

int main() {
    int n;
    vector<int> l;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        l.push_back(a);
    };

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

}

Measured memory_bytes: 256
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> P;
  vector<ll> C;

  int p;
  for (int i = 0; i < N; ++i) {
    cin >> p;

    P.push_back(p - 1);
  }

  ll c;
  for (int i = 0; i < N; ++i) {
    cin >> c;

    C.push_back(c);
  }

  ll ans = LLONG_MIN;

  for (int i = 0; i < N; ++i) {
    int cur = i;
    ll point = 0;

    ll loopSize = 1;
    int idx = P[i];
    ll loopSum = C[idx];

    while (idx != i) {
      idx = P[idx];
      loopSum += C[idx];
      loopSize += 1;
    }

    if (loopSum < 0) {
      loopSum = 0;
    }

    for (ll k = 1; k <= min((ll) K, loopSize); ++k) {
      cur = P[cur];
      point += C[cur];

      ll loopCnt = (K - k) / loopSize;
      ll score = point + loopCnt * loopSum;

      /*
      fprintf(stderr, "[%d, k: %lld, cur: %d, point: %lld, loopSize: %lld, loopCnt: %lld, score: %lld]\n",
          i, k, cur, point, loopSize, loopCnt, score);
          */
      ans = max(ans, score);
    }
  }

  cout << ans << endl;

  return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  vll l(n+1), r(n+1);
  rep(i,n){
    l[i+1]=gcd(a[i],l[i]);
  }
  rrep(i,n){
    r[i]=gcd(a[i],r[i+1]);
  }
  ll ans=0;
  rep(i,n){
    chmax(ans,gcd(l[i],r[i+1]));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
from collections import defaultdict
from sys import setrecursionlimit
setrecursionlimit(10**6)
n,m=map(int,input().split())
d=defaultdict(list)
for i in range(m):
    a,b=map(int,input().split())
    d[a].append(b)
    d[b].append(a)
def dfs(node):
    vis.add(node)
    for i in d[node]:
        if i not in vis:
            dfs(i)
vis=set()
ans=0
for i in range(1,n+1):
    if i not in vis:
        dfs(i)
        ans+=1
print(ans-1)

Measured memory_bytes: 899520
import numpy as np
N = int(input())
X = np.array(input().split(), dtype=np.int64)
argsort = X.argsort()
argsort_argsort = argsort.argsort()
X_sorted = X[argsort]
m1, m2 = N // 2 - 1, N // 2
for idx in argsort_argsort:
    if idx <= m1:
        print(X_sorted[m2])
    else:
        print(X_sorted[m1])


Measured memory_bytes: 35708
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

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

  if(n >= 1000) cout << "ABD";
  else cout << "ABC";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

// [l, r)
int calc(vi& sum, int l, int r){
    return sum[r] - sum[l];
}

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

    string S, T; cin >> S >> T;
    int ns = S.size(), nt = T.size();
    vi sums(ns + 1), sumt(nt + 1);
    rep(i, ns){
        sums[i + 1] = sums[i] + (S[i] == 'B' ? 1:2);
    }
    rep(i, nt){
        sumt[i + 1] = sumt[i] + (T[i] == 'B' ? 1:2);
    }

    int Q; cin >> Q;
    rep(loop, Q){
        int a, b, c, d; cin >> a >> b >> c >> d;
        int vs = calc(sums, a - 1, b) % 3;
        int vt = calc(sumt, c - 1, d) % 3;
        cout << (vs == vt ? "YES":"NO") << endl;
    }

    return 0;
}


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

int main(){
  int N,K,x = 1;
  cin >> N >> K;
  
  for(int i = 0; i < N; i++){
  	if(x < K){
      x *= 2;
      }else{
         x += K;
      }
  }
  cout << x;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
	int N, M;
	scanf("%d", &N);
	M = N;
	
	int sum = 0, mod;
	while(M >= 10)
	{
		mod = M % 10;
		sum += mod;
		M = (M - mod) / 10;
	}
	
	sum += M;
	N % sum == 0 ? printf("Yes") : printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
/********
*	????????????
*********/

/*********??¢?????´?????????
*	(1)???????????\??????????????????????????´?????\??????????????§?????????????????????
*	(2)
*********/

int main(void)
{
	int  n, m,l ;		//??¨????????°??¨?????°
	int  gyouretsu_A[101][101]={{0}} ;	//??????
	int  gyouretsu_B[101][101]={{0}} ;	//??????
	long gyouretsu_C[101][101]={{0}} ;	//??????
	int  i, j, k;		//???????????¨
	int  a, b  ;		//??????A,B???????´?
//	long c = 0 ;		//??????C???????´?
	
	scanf("%d %d %d\n", &n, &m, &l);	//?????°??¨?????°?????\???
	
	for(i = 1 ; i <= n  ; i++ ){		//??????A?????\???
		for( j= 1 ; j <= m ; j++ ){
			
			scanf("%d", &a);
			gyouretsu_A[i][j] = a;
		}
		scanf("\n");
	}
	for(i = 1 ; i <= m  ; i++ ){		//??????B?????\???
		for( j= 1 ; j <= l ; j++ ){
			
			scanf("%d", &b);
			gyouretsu_B[i][j] = b;
		}
		scanf("\n");
	}
//-------------------------------------------------	??????C?????????
	
	for(i = 1 ; i <= n  ; i++ ){		//??????C????¨????
		for( j= 1 ; j <= l ; j++ ){
			for( k= 1 ; k <= m ; k++ ){
			
				gyouretsu_C[i][j] += gyouretsu_A[i][k] * gyouretsu_B[k][j] ;
			
			}
		}
		scanf("\n");
	}
	
	
//-------------------------------------------------	??????C?????????
	for( i = 1 ; i <= n ; i++ ){
		for( j= 1 ; j <= l ; j++ ){
			printf("%ld", gyouretsu_C[i][j]);
			if(j < l){
				printf(" ");	//1???????????¨?????????
			} else if(j == l){
				printf("\n");	//?????????????????§??????
			}else {
				//??????????????\??????
			}
		}
	}
    return 0;
	
}

Measured memory_bytes: 1204
#include<stdio.h>

#define N 500000
#define I 1000000000

void mergesort(int *,int,int);
void merge(int *,int,int,int);

int count=0;

void mergesort(int *S,int left,int right)
{
  int mid;
  
  if(left+1 < right) {
    mid = (left + right) / 2;
    mergesort(S,left,mid);
    mergesort(S,mid,right);
    merge(S,left,mid,right);
  }
  
}
  

void merge(int *S,int left,int mid,int right)
{
  int i,j,k,a,b;
  int L[N],R[N];

  a = mid - left;
  b = right - mid;

  for(i=0;i<a;i++) {
    L[i] = S[left+i];
  }
  
  for(i=0;i<b;i++) {
    R[i] = S[mid+i];
  }
  
  L[a] = I;
  R[b] = I;

  i=0;
  j=0;

  for(k=left;k<right;k++){
    count++;
    if(L[i] <= R[j]){
      S[k] = L[i];
      i++;
    }else{
      S[k] = R[j];
      j++;
    }
  }
}
  

int main()
{
  int n,i;
  int S[N];

  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%d",&S[i]);
  }
  
  mergesort(S,0,n);

  for(i=0;i<n;i++) {
    if(i)
      printf(" ");
    printf("%d",S[i]);
  }
  
  printf("\n");
  printf("%d\n",count);
  

  return 0;
}



Measured memory_bytes: 5644
<?php

fscanf(STDIN, "%d %d", $x, $y);

$a = 2*$x - 0.5*$y;

if ($y%2 === 0 && 2*$x >= 0.5*$y && 0.5*$y >= $x) {
    fprintf(STDOUT, "Yes\n");
} else {
    fprintf(STDOUT, "No\n");
}

Measured memory_bytes: 16160
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;


long long int n;
char ch[1004];
map<string,int>mp;


int main() {
	string s,t;
	cout << fixed << setprecision(18);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		for(int j=1;j<s.length();j++){
			string s1=s.substr(0,j),s2=s.substr(j,s.length()-j);
			reverse(s1.begin(),s1.end());reverse(s2.begin(),s2.end());
			string s3=s1,s4=s2;
			s1=s.substr(0,j),s2=s.substr(j,s.length()-j);
			mp[s1+s2]=1;
			mp[s2+s1]=1;
			mp[s3+s2]=1;
			mp[s2+s3]=1;
			mp[s1+s4]=1;
			mp[s4+s1]=1;
			mp[s3+s4]=1;
			mp[s4+s3]=1;
		}
		cout<<mp.size()<<endl;
		mp.clear();
	}

} 


Measured memory_bytes: 3152
import sys
def input(): return sys.stdin.readline().strip()

def main():
    S = input()
    d = set()
    for c in S: d.add(c)
    for i in range(26):
        if chr(i + 97) not in d:
            print(chr(i + 97))
            return
    print("None")
    
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 66872
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//modint 2^61-1
class RHint {
private:
	const ull MASK30 = (1UL << 30) - 1;
	const ull MASK31 = (1UL << 31) - 1;
	const ull RMOD = (1UL << 61) - 1;
	inline ull Mul(ull a, ull b) {
		ull au = a >> 31;
		ull ad = a & MASK31;
		ull bu = b >> 31;
		ull bd = b & MASK31;
		ull mid = ad * bu + au * bd;
		ull midu = mid >> 30;
		ull midd = mid & MASK30;
		return (au * bu * 2 + midu + (midd << 31) + ad * bd);
	}
	//mod 2^61-1を計算する関数
	inline ull CalcMod(ull a) {
		a = (a & RMOD) + (a >> 61);
		if (a > RMOD) a -= RMOD;
		return a;
	}
public:
	ull val;

	RHint() { val = 0; };
	RHint(ull a) {
		val = CalcMod(a);
	}

	inline RHint operator+(const RHint& r) {
		return RHint(CalcMod(this->val + r.val));
	}
	inline RHint operator*(const RHint& r) {
		return RHint(Mul(this->val, r.val));
	}
	inline RHint& operator=(const RHint& r) {
		val = r.val;
		return *this;
	}
	inline RHint& operator+=(const RHint& r) {
		*this = *this + r;
		return *this;
	}
	inline RHint& operator*=(const RHint& r) {
		*this = *this * r;
		return *this;
	}
};
inline bool operator==(const RHint& l,const RHint& r) {
	return l.val == r.val;
}
inline bool operator!=(const RHint& l, const RHint& r) {
	return l.val != r.val;
}
class RollingHash {
private:
	const ull RMOD = (1UL << 61) - 1;
	const ull PV = RMOD * 3;
	RHint base;
public:
	vector<RHint> hash, pow;
	RollingHash(string s,ull b) {
		int l = s.size();
		base = RHint(b);
		hash = vector<RHint>(l + 1, 0);
		pow = vector<RHint>(l + 1, 1);
		for (int i = 0; i < l; i++) {
			hash[i + 1] = (hash[i] + RHint(s[i])) * base;
			pow[i + 1] = pow[i] * base;
		}
	}
	RHint get(int l, int r) {
		return RHint(hash[r].val + PV - (hash[l] * pow[r - l]).val);
	}
	RHint connect(RHint h1, RHint h2, int h2l) {
		return  (h1 * pow[h2l] + h2);
	}
	int lcp(RollingHash& b, int l1, int r1, int l2, int r2) {
		int len = min(r1 - l1, r2 - l2);
		int low = -1, high = len + 1;
		while (high - low > 1) {
			int mid = (low + high) / 2;
			if (get(l1, l1 + mid) == b.get(l2, l2 + mid))low = mid;
			else high = mid;
		}
		return low;
	}
};


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

	int N;
	cin >> N;
	string s;
	cin >> s;
	RollingHash S(s, 10007);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			while (ans < j - i && j + ans < N && S.get(i, i + ans + 1) == S.get(j, j + ans + 1))ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
 
int main(void)
{
	int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    
    if(A==B&&A==C&&B==C)
    	printf("No\n");
    else if(A!=B&&A!=C&&B!=C)
      	printf("No\n");
  	else
      	printf("Yes\n");
 
        
    return 0;
}

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

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

int main() {
	char s[200001]; cin >> s;

	int min_a = 200001;
	int max_z = 0;

	rep(i, 0, 200001) {
		if (s[i] == '\0') {
			break;
		}
		if (s[i] == 'A') {
			if (min_a > i) {
				min_a = i;
			}
		}
	}

	rep(i, 0, 200001) {
		if (s[i] == '\0') {
			break;
		}
		if (s[i] == 'Z') {
			if (max_z < i) {
				max_z = i;
			}
		}
	}

	cout << (max_z - min_a + 1) << endl;

	return 0;
}

Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	r, d, x := nextInt(), nextInt(), nextInt()
	res := x

	for i := 0; i < 10; i++ {
		res = res * r - d
		fmt.Println(res)
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 998244353;

ll dp[3010][6010];

int main() {
	int N, S, A;
	cin >> N >> S;
	dp[0][0] = 1;
	for (int i = 0;i < N;i++) {
		cin >> A;
		for (int j = 0;j <= S;j++) {
			dp[i + 1][j] += dp[i][j] * 2;
			dp[i + 1][j] %= MOD;

			dp[i + 1][j + A] += dp[i][j];
			dp[i + 1][j + A] %= MOD;
		}
	}
	cout << dp[N][S] << endl;
}

Measured memory_bytes: 97772
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define p push_back
#define endl "\n"
#define l long long int
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    l n,k,c=0,ans=1,ml=1,j=0;
    cin>>n>>k;
    vector<l>a;
    for(l i=0;i<n;i++){
        l s;
        cin>>s;
        a.p(s);
    }
    for(l i=k;i<n;i++){
        if(a[i]>a[i-k]){
            cout<<"Yes \n";
        }
        else cout<<"No \n";
    }
    return 0;
}


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

#define MAX 1000005
int dp[MAX];

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < MAX; i++) {
        dp[i] = 0;
    }
    for (int x : A) {
        if (dp[x] != 0) {
            dp[x] = 2;
            continue;
        }
        for (int j = x; j < MAX; j += x) {
            dp[j]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (dp[A[i]] == 1) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8248
#include <bits/stdc++.h>
#define rep(i, s, n) for(int i = s; i < n; i++)
#define rrep(i, s, n) for(int i = s; i > (s)-(n); i--)
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;



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


  int n;
  cin >> n;

  pr(n/3);


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
 
    int size(int x) {
        return -r[root(x)];
    }
};
 
 
int main() {
    int N, M;
    cin >> N >> M;
 
    //友達集合を作る
    UnionFind UF(N);
    for (int i = 0; i < M; i++)
    {
        int A, B;
        cin >> A >> B;
        A -= 1; B -= 1;
        UF.unite(A, B);
    }
 
    //最大の友達集合を求める
    int ans = -1;
    int p[N+1];
    
    for (int i = 0; i <= N; i++)
    {
         p[i]=0;
    }
    for (int i = 0; i < N; i++)
    {
         p[UF.size(i)]++;
    }
    for (int i = 1; i <= N; i++)
    {
      if(p[i]>0){ans+=p[i]/i;}
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 4052
open System
open System.Collections.Generic
open System.Linq
open System

// Following contents are my library. The Main processes are on the bottom of this code.

let puts = Console.WriteLine : 'a -> unit
let put = Console.Write : 'a -> unit
let read() = Console.ReadLine()
let reads () = Console.ReadLine().Split()
let read2 () = reads() |> (fun x -> x.[0], x.[1])
let read3 () = reads() |> (fun x -> x.[0], x.[1], x.[2])
let read4 () = reads() |> (fun x -> x.[0], x.[1], x.[2], x.[3])
let tmap2 f1 f2 (t1, t2) = (f1 t1, f2 t2)
let tmap3 f1 f2 f3 (t1, t2, t3) = (f1 t1, f2 t2, f3 t3)
let tmap4 f1 f2 f3 f4 (t1, t2, t3, t4) = (f1 t1, f2 t2, f3 t3, f4 t4)
let readAs f = read() |> f
let readAs2 f1 f2 = read2 () |> tmap2 f1 f2
let readAs3 f1 f2  f3 = read3 () |> tmap3 f1 f2 f3
let readAs4 f1 f2 f3 f4 = read4 () |> tmap4 f1 f2 f3 f4
let readInt () = readAs int
let readInt2 () = readAs2 int int
let readInt3 () = readAs3 int int int
let readInt4 () = readAs4 int int int int
let ensmallen l = l % 1000000007L
let manhattan x y = abs (fst x - fst y) + abs (snd x - snd y)
let sayYESNO b = if b then puts "YES" else puts "NO"
let sayYesNo b = if b then puts "Yes" else puts "No"

let toIntArray (s:string) = s.ToCharArray() |> Array.map (fun c -> int c - int '0')


// The main contents of this submission are below this line.
let n = read() |> (fun x -> x.ToCharArray()) |> Array.filter (fun x -> x = '2') |> Array.length |> puts


Measured memory_bytes: 13268
#include <stdio.h>
int w,h;
int tai;
int ans,ans_x,ans_y;

int tai2(int x,int y){
	return x*x+y*y;
}

int check(int y,int x){
	if(x<=y)return 0;
	if(x==w&&h==y)return 0;
	if(tai>tai2(x,y))return 0;
	if(ans<tai2(x,y))return 0;
	if(tai==tai2(x,y)&&y<=h)return 0;
	if(ans==tai2(x,y)&&y>=ans_x)return 0;
	//printf("x:%d y:%d w:%d h:%d ans:%d tai2(x,y):%d ans_y:%d\n",x,y,w,h,ans,tai2(x,y),ans_y);
	return 1;
}

int main(){
	int i,j;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0&&w==0)break;
		tai=tai2(w,h);
		ans=tai2(150,150);
		ans_x=150;
		ans_y=150;
		for(i=1; i<=150; i++){
			for(j=1; j<=150; j++){
				if(check(i,j)){
					ans=tai2(i,j);
					ans_x=i;
					ans_y=j;
				}
			}
		}
		printf("%d %d\n", ans_x,ans_y);
	}

	return 0;
}

Measured memory_bytes: 600
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    n=int(input())
    s=list(input())
    k=int(input())
    val=s[k-1]
    for i in range(n):
        if s[i]!=val:
            s[i]='*'
    print(''.join(s))


resolve()

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

using namespace std;

const int INF = 0x0fffffff;

int N;
int K;

typedef pair<int, int> ii;

vector< vector<int> > M;
vector<bool> V; // visited

vector<ii> R; // range

const ii inf = make_pair(-INF, INF);
const ii fail = make_pair(INF, -INF);

ii dfs(int i) {
    //if (V[i]) {
    //    return inf;
    //}

    V[i] = true;

    for (size_t j = 0; j < M[i].size(); ++j) {
        int ni = M[i][j]; // next i

        if (V[ni]) {
            continue;
        }

        ii rv = dfs(ni);

        //if (rv == make_pair(-INF-1, INF+1)) {
        //    rv = inf;
        //}

        if (rv == fail) {
            return fail;
        //} else if (R[i] == inf){
        //    R[i] = rv;
        //} else if (rv == inf) {
        //    continue;
        } else if (R[i] != inf && rv != inf && R[i].first % 2 != rv.first % 2) {
            return fail;
        //} else if (R[i].second < rv.first) {
        //    return fail;
        //} else if (rv.second < R[i].first) {
        //    return fail;
        } else {
            R[i].second = min(R[i].second, rv.second);
            R[i].first  = max(R[i].first, rv.first);
        }
    }

    if (R[i].second < R[i].first) {
        return fail;
    }

    if (R[i] == inf) {
        return inf;
    } else {
        return make_pair(R[i].first-1, R[i].second+1);
    }
}

void dfs2(int i) {
    if (V[i]) {
        return;
    } 

    V[i] = true;

    R[i] = make_pair(R[i].first, R[i].first);
    
    for (size_t j = 0; j < M[i].size(); ++j) {
        int ni = M[i][j]; // next i
        
        if (V[ni]) {
            continue;
        }

        R[ni] = make_pair(max(R[ni].first, R[i].first-1), min(R[ni].second, R[i].second+1));

        dfs2(ni);
    }
}

int main(int argc, char* argv[]) {
    // for cin
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;

    M.resize(N);

    for (int i = 0; i < N; ++i) {
        M[i].clear();
    }

    for (int i = 0; i < N-1; ++i) {
        int a;
        int b;

        cin >> a >> b;
        a--;
        b--;

        M[a].push_back(b);
        M[b].push_back(a);
    }

    V.resize(N);
    fill(V.begin(), V.end(), false);

    R.resize(N);
    fill(R.begin(), R.end(), inf);

    cin >> K;

    for (int i = 0; i < K; ++i) {
        int v;
        int p;

        cin >> v >> p;
        v--;

        R[v] = make_pair(p, p);
    }

    ii rv = dfs(0);

    if (rv == fail) {
        printf("No\n");
        return 0;
    }

    printf("Yes\n");
    fill(V.begin(), V.end(), false);

    dfs2(0);

    for (int i = 0; i < N; ++i) {
        printf("%d\n", R[i].first);
    }

    return 0;
}


Measured memory_bytes: 11904
n=int(input())
a = [int(i) for i in input().split()]
b = [0] * n


for i in range(n, 0, - 1):
    k=0
    for j in range(2*i-1, n, i):
        k ^= b[j] & 1
    b[i - 1] = k ^ a[i - 1]
print(sum(b))
for i, j in enumerate(b):
    if j == 1:
        print(i+1)
        

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

using namespace std;

const int N = 2010;

vector <int> adj[N];
int dist[N];
int ans[N];



int main() {
	int n, x, y;
	cin >> n >> x >> y;
	for (int i = 1; i < n; ++i) {
		adj[i].push_back(i+1);
		adj[i+1].push_back(i);
	}

	adj[x].push_back(y);
	adj[y].push_back(x);


	for (int i = 1; i <= n; ++i) {
		memset(dist, 0x3f3f3f3f, sizeof dist);
		dist[i] = 0;
		queue<int> q;
		q.push(i);

		while(!q.empty()) {
			int f = q.front();
			q.pop();
			for (int at: adj[f]) {
				if(dist[at] == 0x3f3f3f3f) {
					dist[at] = dist[f] + 1;
					q.push(at);
				}
			}
		}
		for (int j = i+1; j <= n; ++j) {
			ans[dist[j]]++;
		}
	}
	for (int i = 1; i < n; ++i) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 384
#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>;
using vv = vector<vector<ll>>;
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;}

const int INF = 2147483647;
const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int n;cin >> n;
    ll ans = 1;
    bool ok = false;
    rep(i,n){
	ll a;cin >> a;
	if(a==0){
	    cout << 0 << endl;
	    return 0;
	}
	if(a  <= 1000000000000000000/ans){
	   ans *= a; 
	}else{
	    ok = true;
	}
    }
    if(ok) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
    long long int a,b,c,k,d=0;
    cin>>a>>b>>c>>k;
    for(long long int i=1;i<=min(a,k);i++){
        d++;
    }
    for(long long int i=a+b+1;i<=min(a+b+c,k);i++){
        d--;
    }
    cout<<d;
    return 0;
}




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

int main(){
    string s;   cin>>s;
    bool flag=true;
    int a=0;
    if(s[0]=='m'){
        ++a;

        for(int i=1;i<s.length();i++){
            if(s[i]=='m')a++;
            if(s[i]=='e')a+=2;
            if(s[i]=='w')a-=3;

            if(i<s.length()-1 && a<=0){
                flag=false;
                break;
            }
        }
    }else flag=false;

    flag? cout<<"Cat"<<endl :   cout<<"Rabbit"<<endl;



    return 0;
}



Measured memory_bytes: 3232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <stack>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

void solve() {
	int n; cin >> n;
	vector<int> v(2, 0);
	map<ll, int> m;
	while (n--) {
		ll a; cin >> a;
		m[a]++;
	}
	for (auto it : m) {
		if (it.second >= 2) {
			it.second -= 2;
			v[0] = it.first;
			sort(v.begin(), v.end());
		}
		if (it.second >= 2) {
			it.second -= 2;
			v[0] = it.first;
			sort(v.begin(), v.end());
		}
	}
	cout << 1ll * v[0]*v[1] << endl;

}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 9820
N = int(input())
arr = [0]*(N+2)
 
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            n = x**2 + y**2 + z**2 + x*y + x*z + y*z
            if n <= N :
                arr[n] += 1
 
for i in range(1,N+1):
    print(arr[i])

Measured memory_bytes: 8944
N=int(input())
a=list(map(int,input().split()))
a=sorted([a[i]-i for i in range(N)])
if N%2==1:
    print(sum([abs(b-a[N//2]) for b in a]))
else:
    print(sum([abs(b-(a[N//2]+a[N//2-1])//2) for b in a]))

Measured memory_bytes: 25200
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i=0; i<(int)(n); i++)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
typedef long long ll;

int main() {
    ll x;
    cin >> x;
    ll sum = 1;
    ll cnt = 0;
    while(x > 1){
        x /= 2;
        cnt++;
        sum += pow(2, cnt);
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 30005;
int N;
string S;

signed main()
{
  cin >> N;
  cin >> S;

  int ans = 0;
  REP(i,10) {
    REP(j,10) {
      REP(k,10) {
        int cnt = 0;
        REP(n,N) {
          if(cnt == 0) {
            if(S[n]-'0' == i) {
              cnt++;
            }
          } else if(cnt == 1) {
            if(S[n]-'0' == j) {
              cnt++;
            }
          } else if(cnt == 2) {
            if(S[n]-'0' == k) {
              cnt++;
            }
          }
          if(cnt == 3) break;
        }
        if(cnt == 3) ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
data = n.times.map {gets.split.map(&:to_i)}.map {|x, l| [x - l, x + l]}

result = 0
current = -Float::INFINITY

data.sort {|a, b| a[1] <=> b[1]}.each do |arm|
  next if current > arm[0]
  result += 1
  current = arm[1]
end

puts result

Measured memory_bytes: 15352
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios::sync_with_stdio(0),cin.tie(0);

int main()
{
	int n,res=0;
	cin >> n;
	for (int i = 1; i <= n; i+=2)
	{
		int cnt = 0;
		for (int j = 1; j*j<=i; j++)
		{
			if (i%j == 0)cnt += 2;
		}
		if (cnt == 8)res++;
	}
	cout << res;
	return 0;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

typedef tuple<int,int,int> tiii;

int main()
{
	for(int n,w,h;cin>>n>>w>>h && n|w|h;){
		int p=2*(w+h);
		vector<pii> rs;
		rep(i,n){
			int x,y; string d; cin>>x>>y>>d;
			if(d=="N"){
				int l=x-(h-y),r=x+(h-y);
				rs.emplace_back(l,r);
			}
			if(d=="E"){
				int b=y-(w-x),t=y+(w-x);
				rs.emplace_back(w+(h-t),w+(h-b));
			}
			if(d=="S"){
				int l=x-y,r=x+y;
				rs.emplace_back(w+h+(w-r),w+h+(w-l));
			}
			if(d=="W"){
				int b=y-x,t=y+x;
				rs.emplace_back(w+h+w+b,w+h+w+t);
			}
		}
		rep(i,n) if(rs[i].first<0){
			rs[i].first+=p;
			rs[i].second+=p;
		}
		
		int res=INF;
		rep(i,n){
			priority_queue<tiii,vector<tiii>,greater<tiii>> pq;
			rep(j,n){
				if(rs[j].first>=rs[i].first){
					pq.emplace(rs[j].first,0,j);
					pq.emplace(rs[j].second,1,j);
				}
				else{
					pq.emplace(rs[j].first+p,0,j);
					pq.emplace(rs[j].second+p,1,j);
				}
			}
			set<int> require;
			int cnt=0;
			while(pq.size()){
				int l,s,j; tie(l,s,j)=pq.top(); pq.pop();
				if(s==0){ // open
					require.insert(j);
				}
				else{ // close
					if(require.count(j)){
						cnt++;
						require.clear();
					}
				}
			}
			res=min(res,cnt);
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 3228
#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>;

int main(){
    int n;
    cin >> n;
    ll ans = 1;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        if(a[i]==0){
            ans = 0;
            cout << ans << endl;
            return 0;
        }
    }
    rep(i,n){
        if(!a[i] || ans > LLONG_MAX/a[i]){
            ans = -1;
            break;
        }
        ans *= a[i];
        if(ans>1000000000000000000){
            ans = -1;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4000
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

minSum = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    nowsum = a[x - 1] + b[y - 1] - c
    if nowsum < minSum:
        minSum = nowsum
print(minSum)


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

int main(){
    int n, q, a, b, c;
    cin >> n >> q;

    vector<queue<int>> v(n);

    for(int i = 0; i < q; i++){
        cin >> a;

        if(a == 0){
            cin >> b >> c;
            v[b].push(c);
        }else if(a == 1){
            cin >> b;
            if(!v[b].empty())   cout << v[b].front() << endl;
        }else if(a == 2){
            cin >> b;
            if(!v[b].empty())   v[b].pop();
        }
    }

    return 0;
}


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

int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a>0){
		cout<<(b-a)*e<<endl;
	}
	else{
		cout<<b*e+d-a*c<<endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <vector>

int main() {
    std::string L;
    std::cin >> L;

    int length = L.size();
    std::vector<long long> dp_less(length + 1);
    std::vector<long long> dp_equal(length + 1);
    dp_less[1] = 1;
    dp_equal[1] = 2;
    for (int i = 2; i <= length; ++i) {
        if (L[i - 1] == '0') {
            dp_less[i] = 3 * dp_less[i - 1];
            dp_equal[i] = dp_equal[i - 1];
        } else {
            dp_less[i] = 3 * dp_less[i - 1] + dp_equal[i - 1];
            dp_equal[i] = 2 * dp_equal[i - 1];
        }
        dp_less[i] %= (long long)1e9 + 7;
        dp_equal[i] %= (long long)1e9 + 7;
    }
    long long ans = dp_less[length] + dp_equal[length];
    ans %= (long long)1e9 + 7;

    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2048
# ABC136 C-Build Stairs
N = int(input())
H = list(map(int,input().split()))
L = []

ans = 'Yes'
for i in range(N-1):
    if H[i+1]-H[i] == -1:
        H[i+1] = H[i]
    elif H[i+1] >= H[i]:
        continue
    else:
        ans = 'No'
        print(ans)
        exit()
print(ans)


Measured memory_bytes: 14252
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int W, H;
  while(cin>>W>>H && W){
    char grid[20][20];
    REP(y, H)REP(x, W) cin>>grid[y][x];
    int sx, sy;
    REP(y, H)REP(x, W) if(grid[y][x] == 'P'){
      sx = x; sy = y;
      grid[y][x] = '.';
      break;
    }
    int N;
    cin>>N;
    int G[8], D[8], S[8], E[8];
    REP(i, N) cin >> G[i] >> D[i] >> S[i] >> E[i];
    static bool used[20][20][1<<8][102] = {};
    memset(used, 0, sizeof(used));
    queue<int> qx, qy, qs, qt;
    qx.push(sx);
    qy.push(sy);
    qs.push(0);
    qt.push(0);
    set<int> ans;
    ans.insert(0);
    while(!qx.empty()){
      int x = qx.front(); qx.pop();
      int y = qy.front(); qy.pop();
      int s = qs.front(); qs.pop();
      int t = qt.front(); qt.pop();
      if(t >= 101) continue;
      REP(r, 4) {
        int nx = x + dx[r];
        int ny = y + dy[r];
        if(valid(nx, ny, W, H)){
          if(grid[ny][nx] == '.'){
            if(!used[ny][nx][s][t + 1]){
              used[ny][nx][s][t + 1] = true;
              qx.push(nx);
              qy.push(ny);
              qs.push(s);
              qt.push(t + 1);
            }
          }else{
            REP(i, N)if(0 == (s >> i & 1)){
              if(G[i] == grid[ny][nx] - '0' && S[i] <= t && t < E[i]){
                int ns = s | (1 << i);
                if(!used[y][x][ns][t]){
                  used[y][x][ns][t] = true;
                  qx.push(x);
                  qy.push(y);
                  qs.push(ns);
                  qt.push(t);
                  ans.insert(ns);
                }
              }
            }
          }
        }
      }
    }
    vector<int> v;
    int out = 0;
    FORIT(it, ans){
      bool ok = true;
      int s = *it;
      REP(i, N) REP(j, N) if(i != j && s >> i & 1 && s >> j & 1 && G[i] == G[j]) ok = false;
      if(!ok) continue;
      int tmp = 0;
      REP(i, N)if(s >> i & 1){
        tmp += D[i];
      }
      out = max(out, tmp);
    }
    cout << out << endl;
  }
  return 0;
}

Measured memory_bytes: 11916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=105+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int t[N],ans[N];
int main(){
	int n,s=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>t[i],s+=t[i];
	int m;cin>>m;
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		ans[i]=s+y-t[x];
	}
	for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 3764
use std::*;

fn read<T: str::FromStr>() -> T {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

fn read_vec<T: str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|a| a.parse().ok().unwrap())
        .collect()
}

fn read_vec2d<T: str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn digit(n: u32) -> u32 {
    if n < 10 {
        1
    } else {
        digit(n / 10) + 1
    }
}

fn has_8_div(n: u32) -> bool {
    let mut div = 2;
    for i in 2..(n / 2 + 1) {
        if n % i == 0 {
            div += 1;
        }
        if div > 8 {
            break;
        }
    }

    return div == 8;
}

fn main() {
    let n: u32 = read();
    let mut count = 0;
    let mut i = 105;

    while i <= n {
        if has_8_div(i) {
            count += 1;
        }
        i += 2;
    }

    println!("{}", count);
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here

        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long p = sc.nextLong();

        if (n == 1) {
            System.out.println(p);
            return;
        }

        long ans = 1;

        for (long i = 2; i <= Math.sqrt(p); i++) {
            if (p % i == 0) { // 最小の因数を求める
                int contain = 0;
                while (p % i == 0) {
                    p /= i; // 最小の因数で割った数を代入する
                    contain++;
                }
                if (contain >= n) {
                    ans *= Math.pow(i, contain / n);
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <limits.h>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



int main()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;

    cout << Z << " " << X << " " << Y << endl;
}

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;
using P = pair<int, int>;

int main()
{
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define em emplace_back
#define M 1000000007

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	double d, t, s;
	cin >> d >> t >> s;
	double x = d / s;
	(x <= t) ? cout << "Yes" : cout << "No";
}

Measured memory_bytes: 3724
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<double,double>P;

int main()
{
    ll n;
    cin>>n;
    vector<ll> x(n),y(n);
    rep(i,n)
    {
        cin>>x[i];
        y[i]=x[i];
    }
    sort(x.begin(),x.end());
    ll medless=x[n/2-1];
    ll medmore=x[n/2];
    rep(i,n)
    {
        if(y[i]<=medless)
        {
            cout<<medmore<<endl;
        }
        else
        {
            cout<<medless<<endl;
        }
        
    }
}

Measured memory_bytes: 5376
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	Node root = new Node();
	readonly List<long> l = new List<long>();
	long L;
	public K()
	{
		var I = GL();
		var N = I[0];
		L = I[1];
		for (var i = 0; i < N; i++)
		{
			var s = Console.ReadLine();
			var n = root;
			for (var j = 0; j < s.Length; j++)
			{
				var x = s[j] - '0';
				n = n[x] = n[x] ?? new Node(n);
			}
		}
		DFS(root);
		var g = 0L;
		foreach (var x in l) g ^= F(x);
		Console.WriteLine(g != 0 ? "Alice" : "Bob");
	}
	long F(long n)
	{
		var c = 1L;
		while (n % 2 == 0) { c <<= 1; n >>= 1; }
		return c;
	}
	void DFS(Node n)
	{
		if (n == null) return;
		if (n.Count == 1) l.Add(L - n.Depth);
		DFS(n.Left);
		DFS(n.Right);
	}
}
class Node
{
	public Node Left, Right;
	public readonly int Depth;
	public Node this[int i] { get { return i == 0 ? Left : Right; } set { if (i == 0) Left = value; else Right = value; } }
	public int Count { get { return (Left == null ? 0 : 1) + (Right == null ? 0 : 1); } }
	public Node() { }
	public Node(Node p) { Depth = p.Depth + 1; }
}


Measured memory_bytes: 18912
#include<bits/stdc++.h>
#define REP(i,n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define ll long long
#define  p push_back
#define rep(i,j,n) for(ll i=j;i<n;i++)
#define MOD 1000000009
#define babo ios_base::sync_with_stdio(false);cin.tie(NULL);
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;

using namespace std;

vector<int> ar[100001];
int vis[100001];

void dfs(int node)
{
	vis[node] = 1;
	
	for(int child : ar[node])
	if(!vis[child])
	dfs(child);
	
}


int main()
{
	int n , m , a , b;
	cin>>n>>m;
	
	for(int i=1;i<=m;i++)
	cin>>a>>b , ar[a].push_back(b) , ar[b].push_back(a);
	
	int cc = 0;
	
	for(int i=1;i<=n;i++)
	if(!vis[i])
	dfs(i) , cc++;
	
	cout<<cc-1<<"\n";
}


Measured memory_bytes: 9940
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c=0;
	cin>>a>>b;
	if(a<=b)
	{
		for(int i=0;i<a;i++)
		{
			c++;
		}
	}
	if(a>b)
	{
		for(int i=0;i<a-1;i++)
		{
			c++;
		}
	}
	cout<<c;
	return 0;
}

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

int main(){
  int64_t Tx0,Tv,Rx0,Rv,time;
  cin >> Tx0 >> Tv >> Rx0 >> Rv >> time;

  int64_t dist= (Rv > Tv) ? 0LL
                          : time*(Tv- Rv);

  string ans= (abs(Rx0- Tx0) <= dist) ? "YES"
                                      : "NO";
  
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>

main()
{
	char buf[2000];
	int i = 0;
	
	
	scanf("%[^\n]",buf);
	
	while(buf[i] != '\0'){
		if('A' <= buf[i] && buf[i] <= 'Z'){
			printf("%c",buf[i] + ('a'-'A'));
		} else if('a'<=buf[i] && buf[i] <= 'z'){
			printf("%c",buf[i]-('a'-'A'));
		} else {
			printf("%c",buf[i]);
		}
		i++;
	}
	printf("\n");
	return 0;
}
	

Measured memory_bytes: 524
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

long long int cnt;

void insertion_sort(int *data, int n, int g)
{
	for(int i = g; i < n; i++)
	{
		int v = data[i];
		int j = i - g;
		while(j >= 0 && data[j] > v) {
			data[j+g] = data[j];
			j = j-g;
			cnt++;
		}
		data[j+g] = v;
	}
}

void shell_sort(int *data, int n, vector<int> g)
{
	int h = 1;
	while(h <= n) {
		g.push_back(h);
		h = 3*h + 1;
	}

	fprintf(stdout, "%lu\n", g.size());
	for(int i = g.size()-1; i >= 0; i--) {
		fprintf(stdout, "%d", g[i]);
		if(i) printf(" ");
		if(i == 0) printf("\n");
	}

	for(int i = g.size()-1; i >= 0; i--) {
		insertion_sort(data, n, g[i]);		
	}
}

int main(void)
{
	int *data;
	int n;

	cin >> n;
	data = new int[n];

	for(int i = 0; i < n; i++) {
		scanf("%d", &data[i]);
	}

	vector<int> g;	
	
	shell_sort(data, n, g);
	
	fprintf(stdout, "%lld\n", cnt);
	for(int i = 0; i < n; i++) {
		fprintf(stdout, "%d\n", data[i]);
	}

	delete data;
	return 0;
}


Measured memory_bytes: 6768