akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

ll keta (ll m)
{
  int r = 0;
  for (; m >= 1; m /= 10)
    r++;
  return r;
}

int main()
{
  ll n, ans = INF;
  cin>>n;

  for (ll i = 1; i*i <= n; i++) {
    if (n%i == 0) {
      ans = min(ans, keta(n/i));
      //cout<<i<<" "<<n/i<<" "<<ans<<endl;
      //break;
    }
  }
  cout<<ans<<endl;

  return 0;
}


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

typedef long long ll;

int main() {
	int N;
	std::unordered_map<ll, int> um;

	std::cin >> N;
	for(int i = 0; i < N; ++i) {
		ll a;
		std::cin >> a;
		++um[a];
	}

	int ans = 0;
	for(auto p : um) {
		if(p.second % 2 != 0) ++ans;
	}

	std::cout << ans << std::endl;
}


Measured memory_bytes: 4388
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def make_divisors(n):
    divisors = []
    if n <= 0:
        return []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = []
    balls_in_multiple = [0 for _ in range(N + 1)]
    count = 0
    for i in range(N, 0, -1):
        if balls_in_multiple[i] % 2 != A[i - 1]:
            ans.append(str(i))
            count += 1
            for j in make_divisors(i):
                balls_in_multiple[j] += 1
    print(count)
    if count > 0:
        print(' '.join(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 75516
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
struct E{ll to,co,ti;};
struct P{ll ti,id,re;};
bool operator <(const P &a,const P &b){return a.ti>b.ti;}
ll dp[50][5001],c[50],d[50],ans[50],n,m,s;
vector<E> edge[50];
priority_queue<P> que;

int main(){
  cin>>n>>m>>s;
  while(m--){
    ll u,v,a,b;cin>>u>>v>>a>>b;u--;v--;
    edge[u].push_back({v,a,b});
    edge[v].push_back({u,a,b});
  }
  for(ll i=0;i<n;i++)cin>>c[i]>>d[i];
  que.push({1,0,min(5000LL,s)});
  while(que.size()){
    P p=que.top();que.pop();
    if(dp[p.id][p.re])continue;
    dp[p.id][p.re]=p.ti;
    if(!ans[p.id])ans[p.id]=p.ti;
    for(E q:edge[p.id])
      if(p.re>=q.co&&!dp[q.to][p.re-q.co])
        que.push({p.ti+q.ti,q.to,p.re-q.co});
    if(p.re+c[p.id]<=5000)que.push({p.ti+d[p.id],p.id,p.re+c[p.id]});
  }
  for(ll i=1;i<n;i++)cout<<--ans[i]<<endl;
}


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

int main(){
  int n,m;
  cin>>n>>m;
  int a[110];
  int a_sum=0;
  rep(i,n){
    cin>>a[i];
    a_sum+=a[i];
  }
  
  sort(a,a+n);
  reverse(a,a+n);

  if(a[m-1]>=((double)a_sum/(4*m))){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  } 

  return 0;
}

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

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

  for (int i = 0; i < N; ++i) {
    if (s.substr(i, N - i) == t.substr(0, N - i)) {
      cout << N + i << endl;
      return 0;
    }
  }
  cout << 2 * N << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
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 long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll r;
	cin >> r;
	cout << pow(r,2) << endl;
}



Measured memory_bytes: 256
W,H,N = map(int, input().split())
s = set([])
for h in range(H):
    for w in range(W):
        s.add((w+0.5, h+0.5))
# print(s)

for _  in range(N):
    x,y,a = map(int, input().split())
    rm = set([])
    if a==1:
        for si in s:
            if si[0]<x: rm.add(si)
    if a==2:
        for si in s:
            if si[0]>x: rm.add(si)
    if a==3:
        for si in s:
            if si[1]<y: rm.add(si)
    if a==4:
        for si in s:
            if si[1]>y: rm.add(si)
    s = s - rm
                
print(len(s))

Measured memory_bytes: 5320
# -*- coding: utf-8 -*-
"""
A - Buttons
https://atcoder.jp/contests/abc124/tasks/abc124_a

"""
import sys


def solve(A, B):
    return max(A+B, A+A-1, B+B-1)


def main(args):
    A, B = map(int, input().split())
    ans = solve(A, B)
    print(ans)


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


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rev(a) reverse(all(a)
#define ld long double
const ll mod=1e9+7;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans=0;
    ll r=0,b=0,g=0;
    for(int i=0; i<n; i++){
        if(s[i]=='R') r++;
        if(s[i]=='G') g++;
        if(s[i]=='B') b++;
    }
    ans=r*g*b;
    for(int i=0; i<n; i++){
        ll count=1;
        while((i+2*count)<n){
            set<char> sex;
            sex.insert(s[i]);
            sex.insert(s[i+count]);
            sex.insert(s[i+2*count]);
            if(sex.size()==3) ans--;
            count++;
        }
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
import math
import random
import heapq
from collections import Counter, defaultdict
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def mt(f):
    import time
    import sys

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        print(e - s, 'sec', file=sys.stderr)
        return ret

    return wrap


@mt
def slv(H, W, M):
    def ok(i, j):
        f = False
        if i > 0 and M[i - 1][j] == '#':
            f = True
        if i < H - 1 and M[i + 1][j] == '#':
            f = True

        if j > 0 and M[i][j - 1] == '#':
            f = True

        if j < W - 1 and M[i][j + 1] == '#':
            f = True
        return f

    for i in range(H):
        for j in range(W):
            if M[i][j] == '#' and not ok(i, j):
                return 'No'

    return 'Yes'


def main():
    H, W = read_int_n()
    M = [read_str() for _ in range(H)]
    print(slv(H, W, M))


if __name__ == '__main__':
    main()

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'

#define        MOD 998244353


ll binPow(ll a, ll q)
{
    a %= MOD;
    if (q == 0) return 1;
    return ((q % 2 == 1 ? a : 1) * binPow(a * a, q / 2)) % MOD;
}

ll n;

ll ar[4000];

ll dp[3009][3009];


int main()
{
    ll i,j,k,l,m,s;

    sfl(n);
    sfl(s);

    for(i=0; i<n; i++)sfl(ar[i]);
    // dp[i][j] means upto i porjonto kototar sum j
    // so prottek i theke abar n-i+1 ta option ache
    for(i=1; i<=n; i++)
    {

        for(j=0; j<=s; j++)
        {

            if(ar[i-1] == j)dp[i][j] = i;
            if(j != s)dp[i][j] = (dp[i][j] + dp[i-1][j])%MOD;
            if(ar[i-1] <= j)dp[i][j] = (dp[i][j] + dp[i-1][j-ar[i-1]])%MOD;
        }
    }

    ll fin = 0;

    for(i=1; i<=n; i++)fin = (fin + (dp[i][s]*(n-i+1)))%MOD;

    pfl(fin);
}


Measured memory_bytes: 74268
def main():
    N, A, B, C = (int(_) for _ in input().split())
    L = [int(input()) for _ in range(N)]
    INF = 10 ** 12

    def dfs(i, a, b, c):
        if i == N:
            return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a, b, c) > 0 else INF
        c0 = dfs(i+1, a, b, c)
        c1 = dfs(i+1, a+L[i], b, c) + 10
        c2 = dfs(i+1, a, b+L[i], c) + 10
        c3 = dfs(i+1, a, b, c+L[i]) + 10
        return min(c0, c1, c2, c3)

    print(dfs(0, 0, 0, 0))
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>

int main (){
	int W,H,x,y,r;
	scanf ("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if (W<=x||H<=y||x<=0||y<=0||2*r>W||2*r>H||x+r>W||y+r>H||x-r<0||y-r<0||x>=100||y>=100){
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}
	return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n,q;
vector<int> g[maxn];
int cloc;

int tin[maxn], tout[maxn];

void dfs(int at, int p) {
  tin[at]=cloc++;
  for (int to: g[at]) {
    if (p==to) continue;
    dfs(to,at);
  }
  tout[at]=cloc++;
}

vector<int> v;

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

  cin>>n>>q;
  for (int i=0; i+1<n; i++) {
    int u,v; cin>>u>>v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  dfs(1,0);
  v.resize(cloc);
  while (q--) {
    int u, x; cin>>u>>x;
    v[tin[u]] += x;
    v[tout[u]] -= x;
  }

  for (int i=1; i<cloc; i++) {
    v[i] += v[i-1];
  }


  for (int i=1; i<=n; i++) {
    cout<<v[tin[i]]<<" ";
  }
  cout<<endl;  

  return 0;
}


Measured memory_bytes: 49536
#include<iostream>	// 入出力
#include<stdio.h>	// printf()が使える 小数は%fで
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか

using namespace std;

using ll = long long;

int main()
{
	int H, W, N;

	cin >> H >> W >> N;

	vector<int> a(N, 0);

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


	vector<vector<int>> c(H, vector<int>(W, 0));

	int n = 0;
	int cl = a[0];
	int k = 0;

	for (int i = 0; i < H; ++i)
	{
		if (i % 2 == 0) 
		{

			for (int j = 0; j < W; ++j)
			{
				++n;

				if (cl < n)
				{
					++k;
					cl += a[k];
				}

				c[i][j] = k + 1;
			}

		}

		else
		{

			for (int j = W-1; j >= 0; --j)
			{
				++n;

				if (cl < n)
				{
					++k;
					cl += a[k];
				}

				c[i][j] = k + 1;
			}

		}
	}

	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			cout << c[i][j] << flush;

			if (j != W - 1)
			{
				cout << " " << flush;
			}
			else
			{
				cout << "\n" << flush;
			}
		}
	}
	


	return 0;
}

Measured memory_bytes: 384
// C - Christmas Eve
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()

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

	vector<ll> H(N); rp(i, N)cin>>H[i];
	sort(all(H));

	ll s = 0; rp(i, K-1) s += H[i+1] - H[i];

	ll minH = s;
	for(int pre=0, now=K; now<N; ++now, ++pre){
		s += (H[now] - H[now-1]) - (H[pre+1] - H[pre]);
		minH = min(minH, s);
	}
	cout<< minH <<endl;
}

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

const int inf = 1000000000;

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    for(int i=0; i<n; i++) cin >> x[i];
    int ans = inf;
    for(int i=1; i<=100; i++) {
        int cost = 0;
        for (int j = 0; j < n; j++) cost += (x[j] - i) * (x[j] - i);
        ans = std::min(ans, cost);
    }
    cout << ans << endl;
    return 0;
}

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

int main() 
{
    int A, B, C, X, count=0;
    cin >> A >> B >> C >> X;
    for (int i=0; i<=A; i++)
    {
       for (int j=0; j<=B; j++)
       {
         	for (int k=0; k<=C; k++)
             {
              	if (500*i+100*j+50*k==X) count++;
             }
       }    

    }
    cout << count << endl;
}
  

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
using namespace std;
using ll = long long;
void self_max(int &a,int b){
  a = max(a,b);
}

int main(){
  int n; cin >> n;
  char arr[n] = {};
  rep(i,n){
    cin >> arr[i];
  }
  int count = 0;
  rep(i,n-1){
    if(arr[i] == arr[i+1]) count++;
  }
  
  

  cout << n- count << endl;
  return 0; 
}


Measured memory_bytes: 384
#include <cstdio>
using namespace std;
const int maxn=10001;

int n,s[maxn];
bool dp[maxn];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	    scanf("%d",&s[i]);
	dp[0]=true;
	for(int i=1;i<maxn;i++) dp[i]=false;
	for(int i=1;i<=n;i++)
		for(int j=maxn-1;j>=1;j--)
			if (j>=s[i] && dp[j-s[i]]) dp[j]=true;
	
	
	for(int j=maxn-1;j>=0;j--)
	{
		if ((dp[j] && j%10!=0) || j==0)
		{
			printf("%d\n",j);
			return 0;
		}
	}
}

Measured memory_bytes: 128
def PrimeFactorize(num):
    ret = dict()
    while num % 2 == 0:
        ret.setdefault(2, 0)
        ret[2] = ret[2] + 1
        num //= 2
    prime = 3
    while prime * prime <= num:
        if num % prime == 0:
            ret.setdefault(prime, 0)
            ret[prime] =ret[prime] + 1
            num //= prime
        else:
            prime += 2
    if num != 1:
        ret.setdefault(num, 0)
        ret[num] = ret[num] + 1
    
    return ret

def Main():
    n, p = map(int, input().split())    
    prime_list = PrimeFactorize(p)
    ans = 1
    for key, val in prime_list.items():
        if val >= n:
            ans *= key ** (val // n)
    print(ans)

if __name__ == "__main__":
    Main()

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int N, A, B; cin >> N >> A >> B;
  vector<int> P(N); REP(i, N) cin >> P[i];
  vector<int> ans; ans.resize(3);
  REP(i, N) {
    if(P[i] <= A) ans[0]++;
    else if(A + 1 <= P[i] && P[i] <= B) ans[1]++;
    else if(B + 1 <= P[i]) ans[2]++;
  }
  cout << *min_element(all(ans)) << endl;
}

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

int main() {
	int n, bnum, b[100] = { 0 };
	cin >> n >> bnum;
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int k = 1; k <= bnum; k++) {
		for (int i = 0; i < n-1; i++) {
			if (b[i] % k > b[i + 1] % k) swap(b[i], b[i + 1]);
		}
	}
	for (int j = 0; j < n; j++) {
		cout << b[j] << endl;
	}
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;
  ll a[n + 5];
  for (ll i = 1; i <= n; i++)
    cin >> a[i];

  ll res = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i + 1; j <= n; j++) {
      for (ll k = j + 1; k <= n; k++) {
        if (a[i] == a[j] or a[j] == a[k] or a[k] == a[i])
          continue;

        ll sum1 = a[i] + a[j] + a[k];
        ll max1 = max(a[i], max(a[j], a[k]));

        if (sum1 > 2 * max1)
          res++;
      }
    }
  }

  cout << res << en;
  return 0;
}

Measured memory_bytes: 3644
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;


void main() {
    int n, q;
    scan(n, q);

    auto sd = SqrtDecomp(n);

    foreach (_ ; 0 .. q) {
        auto line = readln.split.to!(int[]);
        if (line[0] == 0) {
            sd.update(line[1], line[2]);
        }
        else {
            writeln(sd.getMin(line[1], line[2] + 1));
        }
    }
}

struct SqrtDecomp {
    private {
        enum sqrtN = 512;
        int N, K;
        int[] bucket;
        int[] data;
    }

    this(int n) {
        N = n;
        K = (N + sqrtN - 1) / sqrtN;
        bucket = new int[](K);
        data = new int[](K * sqrtN);
        bucket[] = int.max;
        data[] = int.max;
    }

    void update(int i, int x) {
        int k = i / sqrtN;
        data[i] = x;
        bucket[k] = int.max;
        foreach (j ; k * sqrtN .. (k + 1) * sqrtN) {
            bucket[k] = min(bucket[k], data[j]);
        }
    }

    int getMin(int l, int r) {
        int res = int.max;

        foreach (k ; 0 .. K) {
            int bl = k * sqrtN, br = (k + 1) * sqrtN;
            if (r <= bl || br <= l) continue;
            if (l <= bl && br <= r) {
                res = min(res, bucket[k]);
            }
            else {
                foreach (i ; max(l, bl) .. min(r, br)) {
                    res = min(res, data[i]);
                }
            }
        }

        return res;
    }
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}



Measured memory_bytes: 3724
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;


int main(void) {
	long long int N,ans;
	cin >> N;
	for (long long int i = 1;; i++) {
		if (i*i <= N)ans = i * i;
		else break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

      int n,k;
      scanf("%d %d",&n,&k);
      int arr[n+5];
      int i;
      for( i=0; i<n; i++)
      {
        scanf("%d",&arr[i]);
      }
       int d = k-1;
      int o=0;
      for(i=d; i<n; i=i+d)
      {
         o++;
         if(i==n-1)
         {
          printf("%d\n",o);
          return 0;
         }
      }
       printf("%d\n",o+1);
      return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.math.*;
import java.util.*;

class Main{
	public static void main(String[] args) throws IOException{
		//BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		Scanner r= new Scanner(System.in);
		char[] c;
		String s;
		int[] huda=new int[10];
		int n;
		int turn;
		int field;
		int i,j;

		while(r.hasNext()){
			turn = 0;
			field= 0;
			s = r.next();
			n = Integer.parseInt(s);
			if(n == 0) break;
			for(i=0;i<n;i++) huda[i]=0;
			s = r.next();
			c = s.toCharArray();
			for(i=0;i<100;i++){
				switch(c[i]){
					case 'M':
						huda[turn]++;
						break;
					case 'S':
						field += huda[turn] + 1;
						huda[turn] = 0;
					 	break;
					case 'L':
						huda[turn] += field + 1;
						field = 0;
						break;
				}
				if(turn+1 == n)
					turn = 0;
				else turn++;
			}
			Arrays.sort(huda,0,n);
			for(i=0;i<n;i++) System.out.print(huda[i]+" ");
			System.out.println(field);
		}
	}
}

Measured memory_bytes: 21848
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll A[100000];
string op[100000];
ll dp[100000][3];
int main() {
	int N;
	cin >> N;
	cin >> A[0];
	for (int i = 0; i + 1 < N; i++) {
		cin >> op[i] >> A[i + 1];
	}
	fill((ll*)dp, (ll*)(dp + N), -INF);
	dp[0][0] = A[0];
	for (int i = 0; i + 1 < N; i++) {
		for (int j = 0; j < 3; j++) {
			if (dp[i][j] == -INF) continue;
			if (op[i] == "+") {
				if (j % 2 == 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + A[i + 1]);
				else dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] - A[i + 1]);
				if (j > 0) {
					if (j % 2 == 0) dp[i + 1][j - 1] = max(dp[i + 1][j - 1], dp[i][j] - A[i + 1]);
					else dp[i + 1][j - 1] = max(dp[i + 1][j - 1], dp[i][j] + A[i + 1]);
				}
			}
			else {
				if (j > 0) {
					if (j % 2 == 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + A[i + 1]);
					else dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] - A[i + 1]);
				}
				if (j < 2) {
					if (j % 2 == 0) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] - A[i + 1]);
					else dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + A[i + 1]);
				}
			}
		}
	}
	ll ans = -INF;
	for (int i = 0; i < 3; i++) {
		ans = max(ans, dp[N - 1][i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 8832
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long double lb;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

ll n, ans;

int main() {
    read(n); ans = n;
    for(register int i = 1; 1ll * i * i <= n; i++) {
        if(n % i == 0) {
            ans = min(ans, i + n / i - 2);
        }
    }
    print(ans, '\n');
    return 0;
}

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

using namespace std;

static const int N = 100000;

string s;

int main () {
  cin >> s;

  char tmp[] = {'0', '0'};

  for (int i = 0; i < s.size(); i++) {
    if (tmp[0] == s[i]) {
      printf("%d %d\n", i - 1, i + 1);
      return 0;
    } else if (tmp[1] == s[i]) {
      printf("%d %d\n", i, i + 1);
      return 0;
    }
    tmp[0] = tmp[1];
    tmp[1] = s[i];
  }
  printf("-1 -1\n");

  return 0;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 15;
const int MAXM = 1000010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, m, a[MAXN][MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,n) FOR(j,1,m) cin >> a[i][j];
    int res = 0;
    FOR(i,1,n)
        FOR(k,i+1,n) {
            int sum = 0;
            FOR(j,1,m) sum += (a[i][j] - a[k][j]) * (a[i][j] - a[k][j]);
            int g = int(sqrt(sum));
            if (sum == g*g) res++;
        }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
// They can't break me, as long as I know who I am...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn = 18, inf = 1e9;

int dp[1<<maxn][maxn];

int a[2][maxn];

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

    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
	cin >> a[0][i];
    for(int i = 0; i < n; i++)
	cin >> a[1][i];
    for(int msk = 1; msk < (1<<n); msk++){
	for(int i = 0; i < n; i++)
	    dp[msk][i] = inf;
    }
    for(int msk = 1; msk < (1<<n); msk++){
	int SZ = __builtin_popcount(msk);
	if(SZ == 1){
	    int id = __builtin_ctz(msk);
	    dp[msk][id] = 0;
	    continue;
	}
	int cnt = 0;
	for(int i = 0; i < n; i++){
	    if(bit(msk, i) == 0)
		continue;
	    for(int j = 0; j < n; j++){
		if(bit(msk, j) && i != j){
		    if(a[(i ^ 1 ^ SZ) &1][i] < a[(j ^ SZ) &1][j])
			continue;
		    dp[msk][i] = min( dp[msk][i], dp[msk ^ (1<<i)][j] + SZ - 1 - cnt );
		}
	    }
	    cnt++;
	}
    }
    int ans = inf;
    for(int i = 0; i < n; i++)
	ans = min(ans, dp[(1<<n)-1][i]);
    return cout << (ans == inf ? -1 : ans) <<endl, 0;
}
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

using namespace std;
int n;
vector<long long>v;
pair<long long,long long>dp[3000][3000][2];
pair<long long,long long> slv(int i=0,int j=n-1,int f=0){
    if(i>j)
        return {0,0};
    if(dp[i][j][f].first!=0ll&&dp[i][j][f].second!=0ll)
        return dp[i][j][f];
    if(f==0){
        pair<long long,long long>chc1=slv(i,j-1,f=1);
        chc1.first+=v[j];
        pair<long long,long long>chc2=slv(i+1,j,f=1);
        chc2.first+=v[i];
        if(chc1.first-chc1.second>=chc2.first-chc2.second)
            return dp[i][j][f]=chc1;
        else
            return dp[i][j][f]=chc2;
    }else{
        pair<long long,long long>chc1=slv(i,j-1,f=0);
        chc1.second+=v[j];
        pair<long long,long long>chc2=slv(i+1,j,f=0);
        chc2.second+=v[i];
        if(chc1.first-chc1.second<=chc2.first-chc2.second)
            return dp[i][j][f]=chc1;
        else
            return dp[i][j][f]=chc2;
    }
}

int main()
{
    cin>>n;
    v=vector<long long>(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<n;j++){
            if(i>j)
            continue;
            for(int f=0;f<2;f++){
                if(f==0){
                    if(i==j)
                        dp[i][j][f]={v[i],0ll};
                    else{
                        pair<long long,long long>chc1=dp[i][j-1][1];
                        ///cout<<dp[i][j-1][1].first<<' '<<dp[i][j-1][1].second<<'\n';
                        chc1.first+=v[j];
                        pair<long long,long long>chc2=dp[i+1][j][1];
                        chc2.first+=v[i];
                        ///cout<<dp[i+1][j][1].first<<' '<<dp[i+1][j][1].second<<'\n';
                        if(chc1.first-chc1.second>=chc2.first-chc2.second)
                            dp[i][j][f]=chc1;
                        else
                            dp[i][j][f]=chc2;
                    }
                }else{
                    if(i==j)
                        dp[i][j][f]={0ll,v[i]};
                    else{
                        pair<long long,long long>chc1=dp[i][j-1][0];
                        ///cout<<dp[i][j-1][0].first<<' '<<dp[i][j-1][0].second<<'\n';
                        chc1.second+=v[j];
                        pair<long long,long long>chc2=dp[i+1][j][0];
                        ///cout<<dp[i+1][j][0].first<<' '<<dp[i+1][j][0].second<<'\n';
                        chc2.second+=v[i];
                        if(chc1.first-chc1.second<=chc2.first-chc2.second)
                            dp[i][j][f]=chc1;
                        else
                            dp[i][j][f]=chc2;
                    }
                }
            }
        }
    }
    pair<long long,long long>ans=slv();
    cout <<(ans.first-ans.second) << endl;
/**
5
0.42 0.01 0.42 0.99 0.42
*/
    return 0;
}


Measured memory_bytes: 156116
s = input()
n = len(s)
ans = [1]*n
for i in range(0, n-2):
    if s[i] == "R" and s[i+1] == "R":
        ans[i+2] += ans[i]
        ans[i] = 0
for i in range(n-1, -1, -1):
    if s[i] == "L" and s[i-1] == "L":
        ans[i-2] += ans[i]
        ans[i] = 0
print(*ans)

Measured memory_bytes: 47684
# coding: utf-8

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

def array2d(row, col, init = None):
    return [[init for _ in range(col)] for _ in range(row)]

N, W = map(int, input().split(" "))
v = []
w = []
for i in range(N):
    vi, wi = map(int, input().split(" "))
    v.append(vi)
    w.append(wi)

dpt = array2d(N + 1, W + 1)

def dp(i, j):
    if dpt[i][j] is not None:
        return dpt[i][j]
    if i == 0:
        dpt[i][j] = 0
        return 0
    if j < w[i-1]:
        dpt[i][j] = dp(i-1, j)
        return dpt[i][j]
    dpt[i][j] = max(dp(i-1, j), dp(i-1, j-w[i-1]) + v[i-1])
    return dpt[i][j]

print(dp(N, W))

Measured memory_bytes: 29176
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int _=1e5+5;
inline int read()
{
	char ch='!';int z=1,num=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')z=-1,ch=getchar();
	while(ch<='9'&&ch>='0')num=(num<<3)+(num<<1)+ch-'0',ch=getchar();
	return z*num;
}
char s[_];
int n,From[_];
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	if(s[n]=='1'||s[1]=='0')return puts("-1"),0;
	for(int i=1;i<n;++i)
		if(s[i]!=s[n-i])return puts("-1"),0;
	int x=1;
	for(int i=2;i<=n;++i){From[i]=x;if(s[i-1]=='1')x=i;}
	for(int i=2;i<=n;++i)printf("%d %d\n",i,From[i]);
	return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    int N, M, A, B, C;
    string s1, s2; 
    cin >> N;
    map<string, int> m;
    rep(i, N){
        string str;
        cin >> str;
        m[str]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

int n;
vector<int>g[maxn];
ll dp[maxn],f[maxn],Fact[maxn],INV[maxn],sz[maxn];

void exgcd(ll a, ll b, ll &x, ll &y)
{
	if(b == 0) {
		x = 1;
		y = 0;
		return;
	}
	exgcd(b,a%b,y,x);
	y = y - (a / b) * x;
}

ll inv(ll a, ll p)
{
	ll x,y;
	exgcd(a,p,x,y);
	return (x % mod + mod) % mod;
}

void init( int n ) {
    Fact[ 0 ] = 1;
    for( int i = 1; i <= n; ++i ) Fact[ i ] = Fact[ i - 1 ] * i % mod;
    INV[ n ] = inv( Fact[ n ], mod );
    for( int i = n - 1; i >= 0; --i ) INV[ i ] = INV[ i + 1 ] * ( i + 1 ) % mod;
    return;
}

void dfs(int u,int fa)
{
	dp[u] = 1;
	sz[u] = 1;
	for(int i = 0; i < (int)g[u].size(); ++i){
		int v = g[u][i];
		if(v == fa) continue;
		dfs(v,u);
		sz[u] += sz[v];
		dp[u] = dp[u] * dp[v] % mod * INV[sz[v]] % mod;
	}
	dp[u] = dp[u] * Fact[sz[u] - 1] % mod;
}

void dfs2(int u, int fa)
{
	f[u] = dp[u];
	for(int i = 0; i < (int)g[u].size(); ++i){
		int v = g[u][i];
		if(v == fa) continue;
		dp[u] = dp[u] * inv(dp[v],mod) % mod * Fact[sz[v]] % mod * INV[sz[u] - 1] % mod;
		dp[v] = dp[v] * INV[sz[v] - 1] % mod;
		sz[u] -= sz[v];
		sz[v] += sz[u];
		dp[u] = dp[u] * Fact[sz[u] - 1] % mod;
		dp[v] = dp[v] * Fact[sz[v] - 1] % mod * dp[u] % mod * INV[sz[u]] % mod;
		//cout << v << " " << u << endl;
		dfs2(v,u);
		dp[v] = dp[v] * inv(dp[u],mod) % mod * Fact[sz[u]] % mod * INV[sz[v] - 1] % mod;
		dp[u] = dp[u] * INV[sz[u] - 1] % mod;
		sz[v] -= sz[u];
		sz[u] += sz[v];
		dp[v] = dp[v] * Fact[sz[v] - 1] % mod;
		dp[u] = dp[u] * dp[v] % mod * INV[sz[v]] % mod * Fact[sz[u] - 1] % mod;
	}
}

int main()
{
	fastIO;
	cin >> n;
	init(n);
	rep(i,0,n - 1) {
		int a,b; cin >> a >> b;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(1,0);
	dfs2(1,0);
	for(int i = 1; i <= n; ++i){
		cout << f[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 21748
n, k = map(int, input().split())
a = list(map(int, input().split()))
l = len(bin(k))-2
if k == 0:
    l = 0
memo = [0 for i in range(l)]

for ai in a:
    for j in range(l):
        if ai & (1<<j):
            memo[j] += 1

x = 0
f = 0

for j in reversed(range(l)):
    if f or k & (1<<j):
        if memo[j] <= n - memo[j]:
            x += 2 ** j
        else:
            f = 1
ans = 0

for ai in a:
    ans += ai ^ x

print(ans)

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

typedef long long lint;
const int MAXN = 200005;

char str[MAXN];
int fail[MAXN];
lint dp[222];
lint cnt[222][26];

vector<lint> solve(lint p, int s, int t){
	memset(dp, 0, sizeof(dp));
	memset(cnt, 0, sizeof(cnt));
	vector<lint> dap(26);
	dp[0] = s;
	dp[1] = s+t;
	vector<int> v;
	for(int i=0; i<s; i++){
		cnt[0][str[i] - 'a']++;
	}
	for(int i=0; i<s+t; i++){
		cnt[1][str[i] - 'a']++;
	}
	for(int i=2; i<100; i++){
		for(int j=0; j<26; j++){
			cnt[i][j] = cnt[i-1][j] + cnt[i-2][j];
		}
		dp[i] = (dp[i-1] + dp[i-2]);
		if(dp[i] >= p){
			for(int j=i; j>=0; j--){
				while(p >= dp[j]){
					p -= dp[j];
					v.push_back(j);
				}
			}
			break;
		}
	}
	for(int i=0; i<p; i++){
		dap[str[i] - 'a']++;
	}
	for(auto &i : v){
		for(int j=0; j<26; j++){
			dap[j] += cnt[i][j];
		}
	}
	return dap;
}

int main(){
	scanf("%s", str);
	int p = 0;
	for(int i=1; str[i]; i++){
		while(p && str[i] != str[p]) p = fail[p];
		if(str[i] == str[p]) p++;
		fail[i + 1] = p;
	}
	int n = strlen(str);
	int s = n / 2 - fail[n / 2];
	int t = fail[n / 2];
	lint l, r; cin >> l >> r;
	auto x = solve(r, s, t);
	auto y = solve(l - 1, s, t);
	for(int i=0; i<26; i++){
		printf("%lld ", x[i] - y[i]);
	}
}


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

long power(long base, long exponent){
    if(exponent % 2){
        return power(base, exponent - 1) * base % long(1e9 + 7);
    }else if(exponent){
        long root_ans = power(base, exponent / 2);
        return root_ans * root_ans % long(1e9 + 7);
    }else{
        return 1;
    }
}

vector<long> factorial_numbers{1};

long combination(long n, long r){
    if(n < r){
        return 0;
    }else{
        return factorial_numbers[n] * power(factorial_numbers[r], 1e9 + 5) % long(1e9 + 7) * power(factorial_numbers[n - r], 1e9 + 5) % long(1e9 + 7);
    }
}

int main(){
    int n;
    cin >> n;
    int nums[n + 1];
    int nums_count[n];
    fill(nums_count, nums_count + n, 0);
    for(int i = 0; i <= n; i++){
        cin >> nums[i];
        nums_count[nums[i] - 1]++;
    }
    int double_number = 0;
    for(int i = 0; i < n; i++){
        if(nums_count[i] == 2){
            double_number = i;
        }
    }
    long space_length = 0;
    for(int i = n; i >= 0; i--){
        if(nums[i] == double_number + 1){
            space_length = i;
            break;
        }
    }
    for(int i = 0; i <= n; i++){
        if(nums[i] == double_number + 1){
            space_length -= i;
            break;
        }
    }
    for(long i = 1; i <= n + 1; i++){
        factorial_numbers.push_back(factorial_numbers.back() * i % long(1e9 + 7));
    }
    for(long i = 1; i <= n + 1; i++){
        cout << (combination(n + 1, i) - combination(n - space_length, i - 1) + long(1e9 + 7)) % long(1e9 + 7) << endl;
    }
    
}





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

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0; i<n; ++i) cin >> s[i];
  int ans = 0;
  for(int i=0; i<n; ++i){
    bool ansis = true;
    for(int j=0; j<n; ++j) for(int k=j+1; k<n; ++k){
      if(s[(j+i)%n][k] != s[(k+i)%n][j]) ansis = false;
    }
    if(ansis) ans += n;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3732
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int n,ans,i,j,dp[31],MAX,day;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=0;i<=30;i++){
			dp[i]=0;
		}
	dp[0]=1;
	MAX=0;
	for(i=0;i<=n;i++){
		for(j=1;j<=3;j++){
			dp[i+j]+=dp[i];
		}
	}
	day=dp[n]/10;
	if(dp[n]%10!=0){
		day++;
	}
	ans=day/365;
	if(day%365!=0){
		ans++;
	}
	printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 2636
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    X = list(map(int, readline().split()))

    print(max(X) - min(X))


if __name__ == '__main__':
    main()


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

using namespace std;

vector<pair<long long, long long> > prime_factorize(long long N){
    vector<pair<long long, long long> > res;
    for(long long a = 2; a*a <= N; ++a){
        if(N % a != 0)continue;
        long long ex = 0; //指数

        // 割れる限り続ける
        while( N%a == 0){
            ++ex;
            N /= a;
        }

        res.push_back( {a, ex} );
    }

    // 最後に残った数について
    if(N != 1) res.push_back({N, 1});
    return res;
}

long long counter(long long N){
    long long counter = 0;
    long long num = 1;

    while(N > 0){
        if( num > N){
            break;
        }
        N -= num;
        num ++;
        counter++;
    }

    return counter;
}


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

    long long ans = 0;
    const auto& res = prime_factorize(N);   
    for(auto p: res){
        ans = ans + counter(p.second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



int main() {
	string str,alpha="abcdefghijklmnopqrstuvwxyz"; cin >> str;

	vector<string> word(str.length());
	vector<string> al(alpha.length());
	vector<string> alone;

	for (int i = 0; i < str.length(); i++) {
		word[i] = str[i];
	}
	for (int i = 0; i < alpha.length(); i++) {
		al[i] = alpha[i];
	}
	

	sort(word.begin(), word.end());
	word.erase(unique(word.begin(), word.end()), word.end());

	for (int i = 0; i < alpha.length(); i++) {
		if (vector_finder(word, al[i]) == 0) alone.push_back(al[i]);
	}
	if (alone.empty()) cout << "None";
	else cout << alone[0];

	return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string str;
  cin>>str;
  int c=0;
  for(int i=0;i<str.size();i++)
    if(str[i]=='7')c++;
  if(c)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 2e5+9;

template <unsigned M> struct modular {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
  static constexpr unsigned mod = M;
  using m = modular;
  unsigned v;
  modular(long long x = 0) : v((x %= mod) < 0 ? x + mod : x) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m b) { if ((int)(v += b.v - mod) < 0) v += mod; return *this; }
  m& operator-=(m b) { if ((int)(v -= b.v) < 0) v += mod; return *this; }
  m& operator*=(m b) { v = (uint64_t)v * b.v % mod; return *this; }
  m& operator/=(m b) { return *this *= power(b, mod - 2); }
  friend m operator+(m a, m b) { return a += b; }
  friend m operator-(m a, m b) { return a -= b; }
  friend m operator*(m a, m b) { return a *= b; }
  friend m operator/(m a, m b) { return a /= b; }
  friend bool operator==(m a, m b) { return a.v == b.v; }
#pragma GCC diagnostic pop
};
using mint = modular<int(1e9+7)>;

ll A[N], B[N];
int main() {
    ios_base::sync_with_stdio(0);
    ll a,b,T,cas=0;
    int n, k;
    cin>>n>>k;
    for(int i=1;i<=n+1;++i) {
        A[i]=A[i-1]+(i-1);
    }
    B[n+1]=n;
    for(int i=n;i>0;--i) {
        B[i]=B[i+1]+(i-1);
    }
    // for(int i=1;i<=n+1;++i)    cerr<<B[i]<<" ";
    mint s=0;
    for(int i=k;i<=n+1;++i) {
    	// cerr<<i<<" "<<A[i]<<" "<<B[n+1-i+1]<<endl;
        s += B[n+1-i+1]-max(0ll, A[i]-1);
        // cerr<<s.v<<endl;
    }
    if(k==1) s+=1; // including 0
    cout<<s.v<<endl;
    return 0;
}

Measured memory_bytes: 6756
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
    string s;
    cin >> s;
    int white = count(s.begin(), s.end(), 'W');
    int pos = 0;
    long long ans = 0;

    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == 'W')
        {
            ans += i - pos;
            pos++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N; cin >> N;
    ll A[N], xA = 0;
    FOR(i,0,N-1){
        cin >> A[i];
        xA ^= A[i];
    }

    FOR(i,0,N-1){
        A[i] &= ~xA;
    }

    ll ans = 0;
    for (int r = 0, c = 60; r < N && c >= 0; --c) if ((xA&(1LL<<c)) == 0) {
        int p = -1;
        FOR(i,r,N-1) if (A[i]&(1LL<<c)) {
            p = i;
            break;
        }
        if (p == -1) continue;
        swap(A[r], A[p]);
        FOR(i,r+1,N-1) if (A[i]&(1LL<<c)) A[i] ^= A[r];

        if ((ans&(1LL<<c)) == 0) ans ^= A[r];
        ++r;
    }

    cout << ((ans<<1) + xA);
}



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

int main() {
  int k,s;
  cin >> k >> s;
  
  ll cnt=0;
  rep(x,k+1){
    rep(y,k+1){
      if(s-x-y >= 0 && s-x-y <= k){
        cnt++;
      }
    }
  }
  
  cout << cnt << endl;
  
  return(0);
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
int dp[105][105][2];

signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
   
 #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
 #endif
 
// -------------------------------------Code starts here---------------------------------------------------------------------     

    fill_n(&dp[0][0][0],105*105*2,1e17);
    int n,m;
    cin>>n>>m;
    string a[105];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]="$"+a[i];
    }
    if(a[1][1]=='#')
    {
        dp[1][1][1]=1;
    }
    else
    {
        dp[1][1][0]=0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]=='#')
            {
                dp[i][j][1]=min({dp[i][j][1],dp[i-1][j][0]+1,dp[i-1][j][1]});
                dp[i][j][1]=min({dp[i][j][1],dp[i][j-1][0]+1,dp[i][j-1][1]});
            }            
            else
            {
                dp[i][j][0]=min({dp[i][j][0],dp[i-1][j][0],dp[i-1][j][1]});
                dp[i][j][0]=min({dp[i][j][0],dp[i][j-1][0],dp[i][j-1][1]});
            }            
        }
    }

    if(a[n][m]=='#')
        cout<<dp[n][m][1];
    else
        cout<<dp[n][m][0];

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;


int main(){
    
    ll N,K,con,ans=0;
    vi a(200010,0);
    cin>>N>>K;
    rep(i,0,N){
        cin>>con;
        a.at(con-1)++;
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    rep(i,0,N-K){
        ans+=a.at(i+K);
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 1024