akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

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

	sort( L.begin(), L.end() );
	int sum = 0;
	int maxL = L.back();
	for( int i = 0; i < N - 1; ++i )
	{
		sum += L[i];
	}

	if( sum > maxL )
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h> 
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;
long long ni(long long);
long long fact(long long);
int main(){
	long long n;
	cin>>n;
	long long nifact[n+2];
	long long a[n+2];
	long long times[n+2];
	long long answer[n+2];
	long long s1[n+2];
	long long s2[n+2];
	long long i, j, k, u;
	long long x=0, y=0;
	nifact[n+1]=ni(fact(n+1));
	for(i=n;i>=0;i--){
		nifact[i]=((i+1)*nifact[i+1])%1000000007; 
	}
	for(i=0;i<=n+1;i++){
		times[i]=0;
	}
	for(i=1;i<=n+1;i++){
		cin>>a[i];
		times[a[i]]++;
	}
	for(i=1;i<=n;i++){
		if(times[i]==2){
			for(j=1;j<=n+1;j++){
				if(a[j]==i&&x==0) x=j;
				if(a[j]==i&&x!=0) y=j;
			}
		}
	}
	s1[0]=1;
	s2[0]=1;
	for(i=1;i<=n+1;i++){
		s1[i]=(s1[i-1]*(n+2-i))%1000000007;
		s2[i]=(s2[i-1]*(n+1+x-y-i))%1000000007;
	}
	for(k=1;k<=n+1;k++){
		answer[k]=(((s1[k]-s2[k-1]*k)%1000000007*nifact[k])%1000000007+1000000007)%1000000007;
	} 
	for(k=1;k<=n;k++){
		cout<<answer[k];
		cout<<endl;
	} 
	cout<<answer[n+1];
	return 0;
}
long long ni(long long t){
	int m=1000000005;
	long long i, j, s=1, c;
	long long p=1;
	int binary[30]={0};
	for(i=29;i>=0;i--){
		if(m>=pow(2,i)){
			binary[i]=1;
			m-=pow(2,i);
		}
	}
	for(i=0;i<=29;i++){
		if(binary[i]==1){
			p=t;
			for(j=1;j<=i;j++){
				p=(p*p)%1000000007;
			}
			s=(s*p)%1000000007;
			p=t;
		}
	}
	return s;
}
long long fact(long long n){
	int i;
	long long s=1;
	for(i=1;i<=n;i++){
		s=(s*i)%1000000007;
	}
	return s;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    float ans=0;
    for(int i = 0 ; i < n ; i++){
        float x; cin>>x;
        string y; cin>>y;
        if(y=="BTC"){
            x*=380000.0;
            ans+=x;
        }
        else if(y=="JPY"){
            ans+=x;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;

main(void){
  int n,m;
  cin >> n >>m;
  int pi[m];
  string si[m];
  int count =0;
  int Bans[100000] = {0};
  bool flag[100000];
  for(int i=0;i<m;i++){
     flag[i]=false;
  }
  for(int i=0;i<m;i++){
     cin >> pi[i] >> si[i];
     if(si[i] == "AC" && flag[pi[i]] == false){
        flag[pi[i]] = true;
        count++;
     }
     if(flag[pi[i]] == false){
       Bans[pi[i]]++;
     }  
  }
  int bcount=0;
  for(int i=0;i<m;i++){
    if(flag[pi[i]]==true){
      bcount += Bans[pi[i]];
      flag[pi[i]] = false;
    }
  }
  cout << count << " " << bcount; 
  
return 0;
}


Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
const int N = 105;

int n, m, ex, ey;
char s[N][N], a[N][N];
short ans, dp[N][N][N][N], sum[N][N];

int Sum(int U, int L, int D, int R) {
	if (U > D) swap(U, D);
	if (L > R) swap(L, R);
	return sum[D][R] + sum[U - 1][L - 1] - sum[D][L - 1] - sum[U - 1][R];
}

void Upd(short &x, short y) {
	x = max(x, y);
}

int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s[i] + 1);
		for (int j = 1; j <= m; ++j) {
			if (s[i][j] == 'E') {
				ex = i;
				ey = j;
			}
			if (s[i][j] == 'o') sum[i][j] = 1;
			sum[i][j] -= sum[i - 1][j - 1];
			sum[i][j] += sum[i][j - 1] + sum[i - 1][j];
		}
	}
	for (short a = ex; a >= 1; --a) {
		for (short c = ey; c >= 1; --c) {
			for (short b = ex; b <= n; ++b) {
				for (short d = ey; d <= m; ++d) {
					short U = b - ex + 1, D = n - ex + a;
					short L = d - ey + 1, R = m - ey + c;
					short now = dp[a][b][c][d];
					Upd(ans, now);
					if (a > U)
						Upd(dp[a - 1][b][c][d], now + Sum(a - 1, max(L, c), a - 1, min(R, d)));
					if (b < D)
						Upd(dp[a][b + 1][c][d], now + Sum(b + 1, max(L, c), b + 1, min(R, d)));
					if (c > L)
						Upd(dp[a][b][c - 1][d], now + Sum(max(U, a), c - 1, min(D, b), c - 1));
					if (d < R)
						Upd(dp[a][b][c][d + 1], now + Sum(max(U, a), d + 1, min(D, b), d + 1));
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 207104
def sumOfDigits num
  sum = 0
  while num > 0
    sum += num % 10
    num /= 10
  end
  sum
end

inputs = gets.split(' ').map(&:to_i)

n = inputs[0]
a = inputs[1]
b = inputs[2]
sum = 0

for i in 1..n do
  sum += i if sumOfDigits(i) >= a && sumOfDigits(i) <= b
end

p sum

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

typedef long long int ll;
#define loop(i,s,e) for(ll i=s;i<e;i++)
#define test ll x;cin>>x;while(x--)
#define pb push_back
#define vec vector<ll>
#define sortvec(x) sort(x.begin(),x.end())
#define sz(x) x.size()

int main () {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll sum=0;
    ll a[n];
    ll hash[100001]={0};
    loop(i,0,n)
    {
    	cin>>a[i];
    	sum+=a[i];
    	hash[a[i]]++;
    }
    ll m;
    cin>>m;
    while(m--)
    {
    	ll u,v;
    	cin>>u>>v;
    	hash[v]+=hash[u];
    	sum+=v*hash[u]-u*hash[u];
    	hash[u]=0;
    	cout<<sum<<"\n";
	}
}

Measured memory_bytes: 5204
line = gets.split(' ').map(&:to_i)
 
N = line[0]
A = line[1]
B = line[2]
 
interval = A + B
 
num_rep = N / interval
rest = N % interval
 
ans = num_rep * A
if rest > A then
  ans += A
else
  ans += rest
end
puts ans

Measured memory_bytes: 14364
# -*- coding: <encoding name> -*-

s = input()
s_former = s[:(len(s) - 1) // 2]
s_latter = s[(len(s) + 3) // 2 - 1:]
print('Yes' if s == s[::-1] and s_former == s_former[::-1] and s_latter == s_latter[::-1] else 'No')


Measured memory_bytes: 2940
N = int(input())
H = list(map(int, input().split()))

# dp[i] := 足場iにいる時の最低コスト
dp = [float('inf')] * N
dp[0] = 0

for i in range(1, N):
    if i >= 2:
        dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i- 2] + abs(H[i] - H[i - 2]))
    else:
        dp[i] = dp[i - 1] + abs(H[i] - H[i - 1])
        
print(dp[-1])


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

int main(){
	int N, K;
  	cin >> N >> K;
  	vector<char> dislike(K);
  	for (int i=0; i<K ; i++){
    	cin >> dislike.at(i); 
    }
  	string ans=to_string(N);
  	bool solved=false;
  	while(!solved){
      
      bool dame=false;
      for(int i=0; i<ans.size();i++){
        for(int j=0; j<K ; j++){
          if(dislike.at(j) == ans.at(i)){
            dame=true;
            break;
          	}
        }
        if(dame){break;}
      }
      if(!dame){solved=true;}
      else{
      	N++;
        ans = to_string(N);
        dame=false;
      }
      
    }
  	cout << ans << endl;
  	
}


Measured memory_bytes: 256
a,b,c,d,e = map(int, input().split())

ans = 0

if a == 0:
    ans += 1
if b == 0:
    ans += 2
if c == 0:
    ans += 3
if d == 0:
    ans +=4
if e == 0:
    ans += 5

print(ans)

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int sum=0;
  for(int i=0;i<K;i++){
    sum+=a[i];
  }
  cout << sum;
}



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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll n;
ll dp[410][410],brr[410][410];
ll arr[410];

int main(){
	if(fopen("input.txt", "r"))
	freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //ll n;
    cin>>n;
    for(int i=0;i<401;i++){
    	for(int j=0;j<401;j++){
    		dp[i][j]=0;
    	}
    }
    for(int i=0;i<n;i++){
    	cin>>arr[i];
    	dp[i][i] = arr[i];
    	brr[i][i] = arr[i];
    }
    
    for(int k=1;k<=n;k++){
    	for(int i=0;i<n;i++){
    		brr[i][i+k] = brr[i][i+k-1] + arr[i+k];
    	}
    }
    
    // for(int i=0;i<10;i++){
    // 	for(int j=0;j<10;j++){
    // 		cout<<brr[i][j]<<" ";
    // 	}
    // 	cout<<"\n";
    // }

    for(int i=n-2;i>=0;i--){
    	for(int j=i+1;j<n;j++){
    		ll minm=inf;
    		for(int k=i;k<j;k++){
    			minm = min(minm, brr[i][k] + brr[k+1][j] + dp[i][k] + dp[k+1][j]);
    		}
    		dp[i][j] = minm;
    	}
    }
    cout<<dp[0][n-1]-brr[0][n-1];
    return 0;
}


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

ll N, M;
vector<ll> A;

ll sum[101010];

// x以上になる値がいくつあるか

bool ok(ll x) {
    ll ret = 0;
    rep(i, N) {
        ret += N - (lower_bound(A.begin(), A.end(), x-A[i]) - A.begin());
    }
    return ret >= M;
}

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

    A.resize(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    // rep(i, N) {
    //     cout << A[i] << " ";
    // }
    // cout << endl;

    rep(i, N) {
        sum[i+1] += sum[i] + A[i];
    }

    ll l = 0, r = 1e8;
    while (r-l>1) {
        ll m = (r + l) / 2;
        if (ok(m)) {
            l = m;
        }
        else {
            r = m;
        }
    }

    ll x = l;
    ll ans = 0;
    ll num = 0;
    for (int i=N-1; i>=0; --i) {
        if (num >= M) break;
        
        // Xより大きい値だけみる
        int idx = (upper_bound(A.begin(), A.end(), x-A[i]) - A.begin());
        ll tmp = N - idx;
        ans += (sum[N] - sum[idx]) + tmp * A[i];

        num += tmp;
    }
    // 使ってないXの部分だけ足し合わせる
    ans += (M - num) * x;
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N, p = 0, m = 0, z = 0;
	cin >> N;
	vector<int> A(N);
	for (int& i : A) {
		cin >> i;
		if (i > 0) ++p;
		else if (i == 0) ++z;
		else ++m;
	}

	if (z == N) {
		cout << 0 << endl;
		for (int i = 1; i < N; ++i) cout << 0 << ' ' << 0 << endl;
		exit(0);
	}

	sort(A.begin(), A.end(), [](int& a, int& b)->bool{ return abs(a) < abs(b); });
	stack<int> p_s, m_s;

	vector<pair<int, int>> ans;

	if (p == 0) {
		if (z == 0) {
			p_s.push(A.front() - A.back());
			ans.emplace_back(A.front(), A.back());
			for (int i = 1; i < N - 1; ++i) m_s.push(abs(A[i]));
		}
		else {
			for (int i = 0; i < N; ++i) {
				if (A[i] == 0) p_s.push(A[i]);
				else m_s.push(abs(A[i]));
			}
		}
	}
	else if (m == 0) {
		if (z == 0) {
			m_s.push(abs(A.front() - A.back()));
			ans.emplace_back(A.front(), A.back());
			for (int i = 1; i < N - 1; ++i) p_s.push(A[i]);
		}
		else {
			for (int i = 0; i < N; ++i) {
				if (A[i] == 0) m_s.push(A[i]);
				else p_s.push(A[i]);
			}
		}
	}
	else {
		for (int i = 0; i < N; ++i) {
			if (A[i] > 0) p_s.push(A[i]);
			else m_s.push(abs(A[i]));
		}
	}

	while (!p_s.empty() && !m_s.empty()) {
		int tmp = p_s.top() + m_s.top();
		int p_top = p_s.top();
		int m_top = m_s.top();
		p_s.pop();
		m_s.pop();
		if (p_s.empty()) {
			p_s.push(tmp);
			ans.emplace_back(p_top, -m_top);
		}
		else if (m_s.empty()) {
			m_s.push(tmp);
			ans.emplace_back(-m_top, p_top);
		}
		else {
			p_s.push(tmp);
			ans.emplace_back(p_top, -m_top);
		}
	}

	if (p_s.empty()) cout << m_s.top();
	else cout << p_s.top();
	cout << endl;
	for (pair<int, int>& i : ans) cout << i.first << ' ' << i.second << endl;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, P> PP;

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

int n,m;
int ti;

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

	cin>>n>>m;
	ti=1;
	REP(i,m) ti*=2;
	cout<<ll(1900*m+100*(n-m))*ti<<endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG




int main() {
  long double A;
  float B;

  cin >> A >> B;


  int B_tmp = B * 100 + 0.5; 

  ll ans = B_tmp * A /100;
  
  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 3748
// Date: 2020-03-01

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    if(abs(a-b) % 2 == 0) cout << "Alice" << endl;
    else cout << "Borys" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

int main(void){
    string s,t;
    cin >> s >> t;

    int flag = 1;
    for(int i = 0;i < s.size();++i){
        if(s[i] != t[i]){
            flag = 0;
        }
    }

    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#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 = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; string s; cin>>n>>s;
  ll l=0, ans=1;
  rep(i,n*2){
    if(s[i]=='B'){
      if(l%2==0){
        l++;
      }else{
        (ans*=l)%=MOD;
        l--;
      }
    }else{
      if(l%2==0){
        if(l==0){
          cout<<0<<endl;
          return 0;
        }
        (ans*=l)%=MOD;
        l--;
      }else{
        l++;
      }
    }
  }
  if(l!=0){
    cout<<0<<endl;
    return 0;
  }
  reps(i,n) (ans*=i)%=MOD;
  cout<<ans<<endl;
}

Measured memory_bytes: 720
{-# LANGUAGE  ViewPatterns #-}
import Data.List
import qualified Data.Set as S
import Control.Monad

main :: IO ()
main = readLn >>= print . solve 

solve :: Int -> Int 
solve k = walk S.empty $ cons (1, 1) empty
    where
        walk s (pop -> Just ((v, d), xs))
            | v == 0 = d
            | S.member i s && S.member j s = walk t xs
            | S.member i s = walk t $ snoc (j, d + 1) xs
            | S.member j s = walk t $ cons (i, d) xs
            | otherwise = walk t . cons (i, d) $ snoc (j, d + 1) xs
            where
                i = (v * 10) `mod` k 
                j = (v + 1) `mod` k
                t = S.insert v s

data DQ a = DQ [a] [a]
    deriving (Show, Eq)

empty :: DQ a
empty = DQ [] []

cons :: a -> DQ a -> DQ a
cons v (DQ xs ys) = DQ (v : xs) ys

snoc :: a -> DQ a -> DQ a
snoc v (DQ xs ys) = DQ xs $ v : ys

pop :: DQ a -> Maybe (a, DQ a)
pop (DQ (x : xs) ys) = return (x, DQ xs ys)
pop (DQ _ []) = Nothing
pop (DQ _ ys) = pop $ DQ (reverse ys) []




Measured memory_bytes: 31100
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(solve(n));
    }
    
    public static int solve(int n){
        int max = (int)Math.pow(n,0.5)+1;
        int ret = 1;
        for(int i = 2; i < max; i++){
            int pow = 2;
            while(Math.pow(i,pow) <= n){
                ret = Math.max(ret,(int)Math.pow(i,pow));
                pow++;
            }
        }
        return ret;
    }
}


Measured memory_bytes: 23764
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
s=input()
c=False
if s[0]=="A":
    for i in range(1,len(s)):
        if s[i]!="C" and s[i].isupper():
            print("WA")
            break
        elif s[i]=="C" :
            if c==False and 2<=i<=len(s)-2:
                c=True

            else:
                print("WA")
                break
    else:
      if  c:
        print("AC")
      else:
        print("WA")
else:
  print("WA")

Measured memory_bytes: 77336
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
struct UnionFind {
  vector<int> parent, rank;
  UnionFind(int n): parent(n), rank(n){
    rep(i,n) {
      parent[i] = i;
      rank[i] = 0;
    }
  }
  int find(int x) { return parent[x]==x ? x : parent[x] = find(parent[x]); }
  bool same(int x, int y) { return find(x)==find(y); }
  void unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      parent[x] = y;
    } else {
      parent[y] = x;
      rank[x] += 1;//rank[y];
    }   
  }
};

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

  UnionFind t(n);
  rep(i,m){
    int x,y,z;
    cin >> x >> y >> z;
    --x; --y; z%=2;
    t.unite(x,y);
  }
  int ans = 0;
  rep(i,n){
    if(i==t.find(i)) ++ans;
  }
  cout << ans << endl;
}


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

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<pii>
#define pqsmall priority_queue<pair<int,pii>,vector<pair<int,pii> >,greater<pair<int,pii> > >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<string,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

#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

bool check(string s)
{
    int i=0,j=s.size()-1;
    while(i<j)
    {
        if(s[i]!=s[j])
            return false;
        i++,j--;
    }
    return true;
}

int32_t main()
{
    fast;
    string s;cin>>s;
    int n=s.size();
    string tmp="";
    for(int i=0;i<(n-1)/2;i++)
        tmp+=s[i];
    if(check(s) and check(tmp) and check(s.substr((n+3)/2-1)))
        cout<<"Yes";
    else
        cout<<"No";

}

Measured memory_bytes: 384
/*---------vmy okimotiv ---------
前回のABCではE問題を正答することができ、個人的には維持したいレベルの結果になったと感じています。
そして今回ですが、順位表だけをみると酷いものです。しかし、コンテスト1分後ではあるものの、E問題を自力で正答することができました。
さらにE問題は苦手分野です。手ごたえとしては悪くないレベルです。
が、しかしB問題やC問題では解法の誤りや注意力に欠けるミスを連発してしまいペナルティを被ったのはかなり反省に値すると思います。
それに加えて単純に400点問題を正答できていません。
これは由々しき事態です。400点にかけた時間が少なかったのは一つの要因ではありますが、このレベル帯の問題で詰まる、または解けないということ
は、無くさなければなりません。
おそらくB問題やC問題での失敗がここに響いてきたというのも大きな要因の一つでしょう。
できるだけ冷静にいるように心がけてはいましたがまだまだ甘いです。
レートを気にしすぎるあまり本来の実力を発揮できないのは非常にもったいないですし対策を練りたいとも考えています。
何がともあれこのような不甲斐ない結果を取っていることを心から反省し、精進したいと思います。
必ず青になります。まずは気持ちから。。
気持ちを青にもっていくためにも精進を重ねることでその自信を深めたいと思います。
そしてその自信をしっかりと結果に示し、必ずや青になります。
*/
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
V g[ohara];
bool vi[ohara];
map<P,ll> mp;
ll rui[ohara];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>k;
    rep(i,n-1){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }
    /*
    void dfs(ll now,ll de){
    if(vi[now])return;
    vi[now]=true;
    if(de!=0){
        mp[{now,de}]++;
        if(de==1){
            (ans*=(k-mp[{now,de}]))%=MOD;
        }
        else{
            (ans*=(k-1-mp[{now,de}]))%=MOD;
        }
    }
    rep(i,Size(g[now])){
        dfs(g[now][i],de+1);
    }
} */
    queue<P> que;
    que.push({0,0});
    vi[0]=true;
    ans=k;
    while(!que.empty()){
        P moto=que.front();
        que.pop();
        rep(i,Size(g[moto.fi])){
            ll to=g[moto.fi][i];
            if(vi[to])continue;
            vi[to]=true;
            mp[{moto.fi,moto.se}]++;
            //cout<<mp[{moto.fi,moto.se}]<<" "<<moto.fi<<" "<<to<<" "<<"\n";
            if(moto.se==0)(ans*=(k-mp[{moto.fi,moto.se}]+MOD)%MOD)%=MOD;
            else (ans*=(k-1-mp[{moto.fi,moto.se}]+MOD)%MOD)%=MOD;
            que.push({to,moto.se+1});
            //Cout(ans);
        }
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 40448
N = int(input())
 
XYHA = []
 
for i in range(N):
    x,y,h = map(int,input().split())

    if h == 0:
        continue
    XYHA.append([x,y,h])

if len(XYHA) == 1:
    print(XYHA[0][0],XYHA[0][1],XYHA[0][2])
    exit()

for i in range(101):
    for j in range(101):
        HC = max(XYHA[0][2] + abs(XYHA[0][0] - i) + abs(XYHA[0][1] - j), 0)
        for k in range(1, len(XYHA)):

            H = max(XYHA[k][2] + abs(XYHA[k][0] - i) + abs(XYHA[k][1] - j), 0)

            if HC != H:
                break
            elif k == len(XYHA) - 1:
                print(i,j,HC)
                exit()

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

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::string s;
    int n;
    std::cin >> n >> s;
    int result = 0;
    char last = '#';
    for (char c : s)
    {
        if (last != c) ++result;
        last = c;
    }
    std::cout << result;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, A, ans = 0;
	map<int,int> x;
	cin>>N;
	
	
	for(int i = 0; i < N; i++){
		cin>>A;
		int a = A;
		
		for(int j = 2; j * j <= A; j++){
			if(A%j == 0){
				x[j] += a;
				while(A%j == 0){
					A /= j;
				}
			}
		}
		
		if(A != 1){
			x[A] += a;
		}
	}
	
	for(pair<int,int> p : x){
		ans = max(ans, p.second);
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 3204
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;


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

  if(A>=13)  cout << B;
  else if(A>=6 && A<=12)  cout << B/2;
  else cout << 0;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP1(u) for(int i=hd[u],v,c;v=e[i].v,c=e[i].c,i;i=e[i].n)
#define REP2(u) for(int&i=cr[u],v,c;v=e[i].v,c=e[i].c,i;i=e[i].n)
using namespace std;
const int N=200200,M=N<<1,INF=1000010000;
int n,m,S,T,u,fl=1,ans;
int a[N],b[N],c[N],d[N],hd[N],cr[N],dep[N];
queue<int>q;
struct edge{int n,v,c;}e[M];
void add(int u,int v,int c){e[++fl]=(edge){hd[u],v,c};hd[u]=fl;}
void adde(int u,int v,int c){add(u,v,c),add(v,u,0);}
bool bfs(){
	FOR(i,1,T) dep[i]=-1,cr[i]=hd[i];
	dep[S]=0;q.push(S);
	while(q.size()){
		int u=q.front();q.pop();
		REP1(u)if(c && dep[v]<0)
			dep[v]=dep[u]+1,q.push(v);
	}
	return dep[T]>0;
}
int dfs(int u,int E){
	if(u==T) return E;
	int F=0;
	REP2(u)if(c && dep[v]==dep[u]+1){
		int t=dfs(v,min(E,c));
		F+=t,e[i^1].c+=t;
		E-=t,e[i^0].c-=t;
		if(!E) break;
	}
	return F;
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d",&n);
	FOR(i,1,n) scanf("%d",&a[i]),a[i]++;
	FOR(i,1,n) scanf("%d",&b[i]),b[i]++;
	S=m=1;
	FOR(i,1,n)if(!c[i]){
		c[u=i]=++m;
		while(u=a[u],u!=i) c[u]=m;
	}
	FOR(i,1,n)if(!d[i]){
		d[u=i]=++m;
		while(u=b[u],u!=i) d[u]=m;
	}
	T=m+1;
	FOR(i,1,n){
		if(a[i]==b[i]){
			if(a[i]==i) ans++;
			else adde(d[i],c[i],1),adde(c[i],d[i],1);
		}
		else{
				 if(b[i]==i) adde(S,c[i],1);
			else if(a[i]==i) adde(d[i],T,1);
			else adde(d[i],c[i],1);
		}
	}
	while(bfs()) ans+=dfs(S,INF);
	cout<<n-ans<<'\n';
}

Measured memory_bytes: 11264
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	auto n = readln.chomp.to!int;
	auto area = new int[][](n+1, n+1);
	foreach (i; 1..n+1) {
    auto tmp = readln.chomp.split.map!(to!int).array;
    foreach (j; 1..n+1) {
      area[i][j] = tmp[j-1] + area[i-1][j] + area[i][j-1] - area[i-1][j-1];
    }
  }

  auto res = int.min;
  foreach (i; 1..n+1) {
    foreach (j; 1..n+1) {
      foreach (k; 0..i) {
        foreach (l; 0..j) {
          res = max(res, area[i][j] - area[k][j] - area[i][l] + area[k][l]);
        }
      }
    }
  }

  res.writeln;
}

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

int main() {
	// read input
	int n, k;
	cin >> n >> k;
	vector<int> d(k);
	vector<vector<int>> a(k);
	int tmp;
	for(int i = 0; i < k; i++) {
		cin >> d[i];
		for(int j = 0; j < d[i]; j++) {
			cin >> tmp;
			a.at(i).push_back(tmp);
		}
	}

	// count # candies wrt each child
	vector<int> candy_counter(n, 0);
	for(int i=0; i<k; i++) {
		for(int j=0; j<d[i]; j++) {
			candy_counter.at(a[i][j] - 1) += 1;
		}
	}

	// count # kids who don't have any candy
	cout << count(candy_counter.begin(), candy_counter.end(), 0) << endl;

	return 0;
}

Measured memory_bytes: 3640
import qualified Data.Vector         as V
import qualified Data.Vector.Mutable as VM
import Control.Applicative
import Control.Monad
import Data.IORef
import Text.Printf

type Process = (String, Int)

roundRobin :: Int -> [Process] -> IO ()
roundRobin q xs = do
  queue <- V.thaw $ V.fromList (xs ++ [("String", 0)])
  -- front <- newIORef 0
  -- rear  <- newIORef n
  loop 0 queue 0 n
  where
    n = length xs
    loop :: Int -> VM.IOVector (String, Int) -> Int -> Int -> IO ()
    loop t vec front rear = do
      -- f <- readIORef front
      -- r <- readIORef rear
      when (front /= rear) $ do
        -- i <- readIORef front
        -- writeIORef front (if i == n then 0 else i + 1)
        (name, time) <- VM.read vec front
        if time <= q
          then do
          printf "%s %d\n" name (t + time)
          loop (t + time) vec (if front == n then 0 else front + 1) rear
          else do
          -- j <- readIORef rear
          -- writeIORef rear (if j == n then 0 else j + 1)
          VM.write vec rear (name, time - q)
          loop (t + q) vec (if front == n then 0 else front + 1) (if rear == n then 0 else rear + 1)

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine
  xs <- map (toTuple . words) <$> replicateM n getLine
  roundRobin q xs
    where toTuple [n, t]  = (n, read t)



Measured memory_bytes: 38336
#include <stdio.h>

int have[ 50 ];

int main( void ) {
	int i, n, p, r;

	for ( ; scanf( "%d %d", &n, &p ), r = p; printf( "%d\n", i ) )
		for ( i = 0; ; i = ( i + 1 ) % n ) {
			if ( r ) {
				r--;
				have[ i ]++;
			} else {
				r = have[ i ];
				have[ i ] = 0;
			}

			if ( r == p )
				break;
		}

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
void dfs(vector<vector<int>> adjList,vector<int> &cost){
	stack<int> st;
	st.push(1);
	vector<bool> used(adjList.size()+1,false);
	used[1] = true;
	while(!st.empty()){
		int cur = st.top();
		st.pop();
		for(auto u:adjList[cur]){
			if(!used[u]){
				cost[u]+=cost[cur];
				used[u] = true;
				st.push(u);
			}
		}
	}
	// cout<<vertex<<endl;
}
int main(){
	int n,q;
	cin>>n>>q;
	int a,b;
	vector<vector<int>> tree(n+1,vector<int>());
	for(int i=0;i<n-1;i++){
		cin>>a>>b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	vector<int> cost(n+1,0);
	
	for(int i=0;i<q;i++){
		cin>>a>>b;
		cost[a]+=b;
	}
	dfs(tree,cost);
	for(int i=1;i<n+1;i++){
		cout<<cost[i]<<endl;
	}
	return 0;
}


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

using namespace std;

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD = 1000000009;
//const int INF = INT_MAX / 3;

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
	int n, r;
	while (cin >> n >> r, n) {
		vi st(n);
		REP(i, n)
			st[i] = n-i ;

		REP(i, r) {
			vi sw(n);
			REP(i, n)
				sw[i] = st[i];
			int p, c;
			cin >> p >> c;
			REP(j, c)
				sw[j] = st[p-1  + j];
			REP(j, p-1)
				sw[j + c] = st[j];


			REP(i, n)
				st[i] = sw[i];

		}

		cout << st[0] << endl;
	}

	return 0;
}

Measured memory_bytes: 3076
N, K = map(int, input().split())
MOD = 10**9 + 7
memo = {}
def dfs(i, a, b, k):
    key = (i, a, b, k)
    if key in memo:
        return memo[key]
    if i == N:
        if b > 0:
            memo[key] = 0
            return 0
        return k == K
    r = dfs(i+1, a, b, k+a+b) + dfs(i+1, a+1, b+1, k+a+b+2)
    if a > 0:
        r += dfs(i+1, a, b, k+a+b) * a
    if b > 0:
        r += dfs(i+1, a, b, k+a+b) * b
    if a > 0 < b:
        r += dfs(i+1, a-1, b-1, k+a+b-2) * (a * b)
    memo[key] = r = r % MOD
    return r
print(dfs(0, 0, 0, 0))

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

int main() {
  int N;
  cin >> N;
  
  vector<int> motilist(110);

  for (int i = 0; i < N; i++){
   cin >> motilist.at(i);
  }
  
  vector<int> motiorder(110);
   for (int i = 0; i < N; i++){
     int num = motilist.at(i);
     motiorder.at(num) = 1;
   }
  

  
  int count = 0;
  for (int i = 1; i <= 100; i++){
    if (motiorder.at(i) > 0){
      count++;
    }
  }
  
  cout << count << endl;

}

      
  

Measured memory_bytes: 256
import sys
string=sys.stdin.read().lower()
cnt=[0]*26
alphabet = "abcdefghijklmnopqrstuvwxyz"

for i in range(len(string)):
  for j in range(len(alphabet)):
    if string[i]==alphabet[j]:
      cnt[j]+=1
      
for i in range(len(alphabet)):
  print(str(alphabet[i])+" : "+str(cnt[i]))


Measured memory_bytes: 5560
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>//////////////////////////////////////////
#define deb(...)/////////////////////////////////////////////////
#define DBP(...)/////////////////////////////////////////////////
#ifdef LOC///////////////////////////////////////////////////////
#include"debuglib.h"/////////////////////////////////////////////
#endif///////////////////////////////////////////////////////////
#define x first//////////////////////////////////////////////////
#define y second/////////////////////////////////////////////////
#define pb push_back/////////////////////////////////////////////
#define sz(x)int((x).size())/////////////////////////////////////
#define each(a,x)for(auto&a:(x))/////////////////////////////////
#define all(x)(x).begin(),(x).end()//////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)///////////////////////
using namespace std;using ll=long long;using Pii=pair<int,int>;//
using Vi=vector<int>;void run();int main(){cin.sync_with_stdio///
(0);cin.tie(0);cout<<fixed<<setprecision(18);run();return 0;}////
//-------------------------------------------------------------//

void run() {
	int n; cin >> n;
	string s, t; cin >> s >> t;
	int ans = 0;

	rep(common, 0, min(sz(s), sz(t))+1) {
		bool ok = 1;
		rep(i, 0, common) {
			if (t[i] != s[sz(s)-common+i]) {
				ok = 0;
				break;
			}
		}
		if (ok) ans = common;
	}

	cout << sz(s)+sz(t)-ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int a[10],l[10],X,y,z,ans=1e9,n;
inline void dfs(int x)
{
	if(x==n+1)
	{
		int cnt=0,A=0,B=0,C=0,now=n*10-30;
		for(int i=1;i<=n;i++)
		{
			A+=(a[i]==1)*l[i];
			B+=(a[i]==2)*l[i];
			C+=(a[i]==3)*l[i];
			now-=(a[i]==0)*10;
		}
		if(!A||!B||!C) return ;
		ans=min(ans,now+abs(A-X)+abs(B-y)+abs(C-z));
		return ;
	}
	for(int i=0;i<=3;i++)
		a[x]=i,dfs(x+1);
}
int main(int argc, char** argv) {
	cin >> n >> X >> y >> z;
	for(int i=1;i<=n;i++) cin >> l[i];
	dfs(1);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
use std::io::{self, BufRead};

fn readline() -> String {
    let mut line = String::new();
    let stdin = io::stdin();
    stdin.lock().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn id(first: char) -> usize {
    let str = "MARCH";
    for (i, c) in str.chars().enumerate() {
        if c == first {
            return i;
        }
    }
    5
}

fn main() {
    let n: i32 = readline().parse().unwrap();
    let mut count: [i64; 6] = [0, 0, 0, 0, 0, 0];

    for _ in 0..n {
        let str = readline();
        count[id(str.chars().next().unwrap())] += 1;
    }

    let mut ans: i64 = 0;

    for i in 0..5 {
        for j in i+1..5 {
            for k in j+1..5 {
                ans += count[i] * count[j] * count[k];
            }
        }
    }

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

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  deque<char> q;
  int n = s.size();
  int ans = 0;
  rep(i, n) q.push_back(s[i]);
  while(!q.empty()) {
    if(q.size() == 1) q.pop_front();
    else if(q.front() == q.back()) {
      q.pop_front(); q.pop_back();
    } else if(q.front() == 'x') {
      ans++; q.pop_front();
    } else if(q.back() == 'x') {
      ans++; q.pop_back();
    } else {
      cout << -1 << "\n";
      return 0;
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3864
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();
        y /= 1000;
        boolean max = false;
        
        for (int i=0; i<=n; i++) {
            if(max){
                break;
            }
            for(int j=0; j<=n-i; j++){
                if(max) {
                    break;
                }
                int z = n-i-j;
                int sum = i*10+j*5+z;
                if(sum==y && i+j+z==n){
                    System.out.println(i+" "+j+" "+z);
                    max = true;
                    break;
                }
            }
        }

        if(max==false){
            System.out.println(-1+" "+-1+" "+-1);
        }
    }
}


Measured memory_bytes: 23252
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    string inp, str;
    int n;
    while(cin >> inp >> n){
        int ans = 0;
        rep(i,n){
            cin >> str;
            str+=str;
            if(str.find(inp, 0) != string::npos){
                ans++;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1212
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct card{
  char suit;
  int value;
};

struct card L[MAX/2+2],R[MAX/2+2];

void merge(struct card A[],int n,int left,int mid,int right){
  int i,j,k;
  int n1=mid-left;
  int n2=right-mid;

  for(i=0;i<n1;i++)
    L[i]=A[left+i];
  
  for(i=0;i<n2;i++)
    R[i]=A[mid+i];

  L[n1].value=R[n2].value=SENTINEL;

  i=j=0;

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

void mergeS(struct card A[],int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeS(A,n,left,mid);
    mergeS(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct card A[],int n,int p,int r){
  int i,j;

  struct card t,x;
  x=A[r];
  i=p-1;

  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

void quickS(struct card A[],int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickS(A,n,p,q-1);
    quickS(A,n,q+1,r);
  }
}

int main(){
  int n,i,v;
  struct card A[MAX],B[MAX];
  char S[10];
  int stable=1;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].suit=B[i].suit=S[0];
    A[i].value=B[i].value=v;
  }

  mergeS(A,n,0,n);
  quickS(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit!=B[i].suit)
      stable=0;
  }

  if(stable==1)
    printf("Stable\n");
  else
    printf("Not stable\n");

  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}



Measured memory_bytes: 4068
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
    
ll ncr(ll n,ll r){
	if(n < r) return 0;
	if(r > n-r){
		r = n-r;
	}
	ll num = 1, den = 1;
	for(int i=1; i<=r; i++){
		num = (num*(n - i + 1)) % mod;
		den = (den * i) % mod;
	}
	return (num * power(den ,mod - 2, mod))%mod;
}

int run_test(){
	ll n, k;
	cin >> n >> k;
	for(int i=1; i<=k; i++){
		ll ans = (ncr(n - k + 1, i) * ncr(k-1, i -  1)) % mod;
		cout << ans << "\n";
	}
	return 0;
}
    
int main(){
   FAST;
    ll t;
    t = 1;
     
    while(t--){
        run_test();
    }
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
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 int mod=1000000007;
int N;
char C[222];
int dp[210][210];

inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}

signed main(){
    cin>>N;
    rep(i,N)cin>>C[i];

    dp[0][0]=1;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(C[i]=='-'){
                add(dp[i+1][j],dp[i][j]);
            }
            else if(C[i]=='U'){
                add(dp[i+1][j],dp[i][j]*j%mod);
                add(dp[i+1][j+1],dp[i][j]);
            }
            else{
                if(j)add(dp[i+1][j-1],dp[i][j]*j%mod*j%mod);
                add(dp[i+1][j],dp[i][j]*j%mod);
            }
        }
    }

    cout<<dp[N][0]<<endl;
    return 0;
}

Measured memory_bytes: 1488
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, k = f()
    ans = 0
    for b in range(k+1, n+1):
        if k!=0:
            ans += n//b * (b-k) + (n%b - (k-1) if n%b >k-1 else 0)
        else:
            ans += n
    
    print(ans)


solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    string messages = "No";
    for(int i = 0; i < 3; i++) {
        if(S[i] == '7') {
            messages = "Yes";
        }
    }
    cout << messages << endl;
    return 0;
}


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

int main(){
  string S,T;
  int cnt=0;
  cin >> S >> T;
  for (int i=0; i<3; i++){
    if (S.at(i) == T.at(i)){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#define INF 1<<20
using namespace std;
struct data{
	int t,c;
	data(){}
	data(int tt,int cc){
		t=tt;
		c=cc;
	}
};

struct swim{
	int id,t,sp;
	swim(){}
	swim(int ii,int tt,int ss){
		id=ii;
		t=tt;
		sp=ss;
	}
	bool operator<(const swim &s)const{
		if(t==s.t)return sp>s.sp;
		return t>s.t;
	}
};
int n,n_;
data d[51];
int res;

int reach[2][500];

int update(int dat[],int k,int a){
	k+=n_-1;
	dat[k]=a;
	while(k>0){
		k=(k-1)/2;
		dat[k]=max(dat[k*2+1],dat[k*2+2]);
	}
}

int query(int dat[],int a=0,int b=n_,int k=0,int l=0,int r=n_){
	if(a<=l && r<=b)return dat[k];
	if(r<=a || b<=l)return 0;
	int vl=query(dat,a,b,k*2+1,l,(l+r)/2);
	int vr=query(dat,a,b,k*2+2,(l+r)/2,r);
	return max(vl,vr);
}

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		n_=1;
		while(n_<n)n_*=2;
		for(int i=0;i<n;i++){
			scanf("%d%d",&d[i].t,&d[i].c);
		}
		priority_queue<swim> go;
		priority_queue<swim> back;
		for(int i=0;i<n;i++){
			go.push(swim(i,d[i].t,d[i].t));
			update(reach[0],i,d[i].t);
		}
		while(go.size() || back.size()){
			swim g,b;
			g.t=INF;
			b.t=INF;
			if(go.size())g=go.top();
			if(back.size())b=back.top();
			if(g.t<b.t){
				go.pop();
				update(reach[0],g.id,0);
				int best=max(query(reach[1]),g.t+g.sp);
				back.push(swim(g.id,best,g.sp));
				update(reach[1],g.id,best);
			}else{
				back.pop();
				update(reach[1],b.id,0);
				d[b.id].c--;
				if(d[b.id].c==0){
					res=b.t;
					continue;
				}
				int best=max(query(reach[0]),b.t+b.sp);
				go.push(swim(b.id,best,b.sp));
				update(reach[0],b.id,best);
			}
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 1040
#include<bits/stdc++.h>                          
using namespace std;    
long long d,n,x=1;                                          
int main(){	
	cin>>d>>n;
	for(int i=1;i<=d;i++)
	    x*=100;
	if(x==1)
	{
		if(n==100) cout<<101;
		if(n<100) cout<<n;
	} 
	else 
	{
		if(n==100) cout<<(n+1)*x;
		if(n<100) cout<<n*x;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <map>

int main()
{
	int N;
	scanf("%d", &N);

	std::map<int, int, std::greater<int>> map;
	for (int i = 0; i < N; i++) {
		int A;
		scanf("%d", &A);

		auto it = map.upper_bound(A);
		if (it != map.end()) {
			if (it->second == 1) {
				map.erase(it);
			}
			else {
				it->second--;
			}
		}
		auto it2 = map.find(A);
		if (it2 == map.end()) {
			map.emplace(A, 1);
		}
		else {
			it2->second++;
		}
	}

	int ans = 0;
	for (auto &e : map) {
		ans += e.second;
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 4864