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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

vector<int64_t> fact, fact_inv;

void create_mod_tables(int num){
    fact.assign(num+1, 1);
    fact_inv.assign(num+1, 1);
    for(int i=1; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
    fact_inv[num] = inv_mod(fact[num]);
    for(int i=num; i>0; i--) fact_inv[i-1] = fact_inv[i] * i % MOD;
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int main(){
    string str;
    cin >> str;
    int N = str.size();
    vector<int> S(N);
    for(int i=0; i<N; i++) S[i] = str[i] - '0';
    int K;
    cin >> K;
    int O = accumulate(S.begin(), S.end(), 0);
    int Z = N-O;
    K = min(K, O);
    
    vector<int> nxt, all;
    int len = 0, len_all = 0;
    for(int i=N-1; i>=0; i--){
        if(S[i]){
            len++;
            len_all++;
        }else{
            nxt.push_back(len);
            all.push_back(len_all);
            len = 0;
        }
    }
    nxt.push_back(len);
    all.push_back(len_all);
    reverse(nxt.begin(), nxt.end());
    reverse(all.begin(), all.end());

    static int64_t dp[310][310][310][2];
    dp[0][0][0][0] = 1;
    for(int i=0; i<=Z; i++){
        for(int j=0; j<=K; j++){
            int64_t s = 0;
            for(int k=0; k<=O; k++){
                add(s, dp[i][j][k][0]);
                if(k > nxt[i]) add(s, MOD - dp[i][j][k-nxt[i]-1][0]);
                int r = O-k;
                //cerr << r << " " << s << " " << all[i]-nxt[i] << endl;
                if(r <= all[i]-nxt[i]) add(dp[i+1][j][k][0], s);
                r -= nxt[i];
                if(r <= all[i]-nxt[i]) add(dp[i][j][k+nxt[i]][1], dp[i][j][k][0]);
                //cerr << i<<j<<k << " " << dp[i][j][k][0] << " " << dp[i][j][k][1] << endl;
            }
        }
        for(int j=0; j<=K; j++) for(int k=0; k<=O; k++){
            int r = O-k-1;
            if(r <= all[i]-nxt[i]){
                add(dp[i][j+1][k+1][1], dp[i][j][k][1]);
                add(dp[i+1][j+1][k+1][0], dp[i][j][k][1]);
            }
        }
    }

    int64_t ans = 0;
    int b = nxt.back();
    for(int j=0; j<=K; j++) add(ans, dp[Z+1][j][O][0]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 110380
from collections import defaultdict
MOD = 10 ** 9 + 7

H, W, K = map(int, input().split())

fib = {-2: 0, -1: 1, 0: 1}
for i in range(1, W):
    fib[i] = fib[i - 1] + fib[i - 2]

dp = defaultdict(int)

dp[(0, 1)] = 1
for i in range(1, H + 1):
    for j in range(1, W + 1):
        dp[(i, j)] \
            = fib[j - 3] * fib[W - j - 1] * dp[(i - 1, j - 1)] \
            + fib[j - 2] * fib[W - j - 1] * dp[(i - 1, j)] \
            + fib[j - 2] * fib[W - j - 2] * dp[(i - 1, j + 1)]
        dp[(i, j)] %= MOD

print(dp[(H, K)])


Measured memory_bytes: 3444
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramE
    {
        static void Main()
        {
            var s = Line;
            var t = Line;
            var counts = Enumerable.Range(0, 26).Select(_ => new List<int>()).ToArray();

            for (int i = 0; i < s.Length; i++)
            {
                counts[s[i] - 'a'].Add(i);
            }

            long result = 0;
            int value = -1;
            for (int i = 0; i < t.Length; i++)
            {
                var list = counts[t[i] - 'a'];
                if (!list.Any())
                {
                    System.Console.WriteLine(-1);
                    return;
                }

                int left = -1, right = list.Count();
                while (right - left > 1)
                {
                    int mid = (left + right) / 2;

                    if (list[mid] > value) right = mid;
                    else left = mid;
                }

                if (right == list.Count())
                {
                    result += s.Length - (value - list.First());
                    value = list.First();
                }
                else
                {
                    result += list[right] - value;
                    value = list[right];
                }

                // System.Console.WriteLine($"left:{left}, right:{right}, value:{value}, result:{result}");
            }

            System.Console.WriteLine(result);
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 19296
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int money = 0;
		money = scan.nextInt();
		int y500 = money / 500;
		int y5 = money%500 / 5;
		System.out.println(1000*y500 + y5*5);
	}
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;   
int main()  
{ 
int n;
cin>>n;
int ans=0;
int s[105]={0};
int sum=0;
for(int i=0;i<n;i++){
    int asd=0;
    cin>>asd;
    s[asd]++;}
for(int i=0;i<104;i++){
    if(s[i]!=0)ans++;}
cout<<ans<<endl;
return 0;
}


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

using namespace std;
vector<int> data;

int n, q;
const int INF = (1 << 31) - 1;

void update(int x, int val)
{
    x += n - 1;
    data[x] = val;
    while (x > 0)
    {
        x = (x - 1) / 2;
        data[x] = min(data[x * 2 + 1], data[x * 2 + 2]);
    }
}

int find(int a, int b, int x, int l, int r)
{
    if (r <= a or b <= l)
        return INF;
    else if (a <= l and r <= b)
    {
        return data[x];
    }
    else
    {
        int vl, vr, nx;
        nx = x * 2;
        int m = (l + r) / 2;
        vl = find(a, b, nx + 1, l, m);
        vr = find(a, b, nx + 2, m, r);
        return min(vl, vr);
    }
}

int main()
{
    cin >> n >> q;
    int _n = 1;
    while (_n < n)
        _n *= 2;
    n = _n;

    for (int i = 0; i < 2 * n - 1; i++)
        data.push_back(INF);
    for (int i = 0; i < q; i++)
    {
        int com, x, y;
        cin >> com >> x >> y;

        if (com == 0)
            update(x, y);
        else
            cout << find(x, y + 1, 0, 0, n) << endl;
    }

    return 0;
}


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


int main() {
    int n;
    string s;
    cin>>n>>s;
    long long ans=0;
    if(n<4) {
        cout << 0 <<endl;
        return 0;
    }
    int r[n],g[n],b[n];
    int numr,numg,numb;
    rep(i,n) {
        if(s[i]=='R')numr++;
        if(s[i]=='G')numg++;
        if(s[i]=='B')numb++;
        r[i]=numr;
        g[i]=numg;
        b[i]=numb;
        for(int j = i+1;j<n;j++){
            ans+=n-j-1;
        }
    }

    rep(i,n)for(int j=i+1;j<n;j++) {
        if(s[i]==s[j]) {
            ans-=n-j-1;
        }else if(s[i]=='R') {
            if(s[j]=='G') {
                ans-=numr-r[j]+numg-g[j];
                if(2*j-i<n and s[2*j-i]=='B')ans--;
            }else if(s[j]=='B'){
                ans-=numr-r[j]+numb-b[j];
                if(2*j-i<n and s[2*j-i]=='G')ans--;
            }
        }else if(s[i]=='G') {
            if(s[j]=='B') {
                ans-=numg-g[j]+numb-b[j];
                if(2*j-i<n and s[2*j-i]=='R')ans--;
            }else if(s[j]=='R'){
                ans-=numg-g[j]+numr-r[j];
                if(2*j-i<n and s[2*j-i]=='B')ans--;
            }
        }else if(s[i]=='B') {
            if(s[j]=='R') {
                ans-=numb-b[j]+numr-r[j];
                if(2*j-i<n and s[2*j-i]=='G')ans--;
            }else if(s[j]=='G'){
                ans-=numb-b[j]+numg-g[j];
                if(2*j-i<n and s[2*j-i]=='R')ans--;
            }
        }
    }
    cout << ans <<endl;
}

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

using namespace std;

int main()
{
	int l,r;
	cin>>l>>r;
	if(l/2019!=r/2019)
	{
		cout<<0;
		return 0;
	}
	else if(l%2019==0||r%2019==0)
	{
		cout<<0;
		return 0;
	}
	else
	{
		long long min=2019;
		for(long long i=l;i<r;i++)
		{
			for(long long j=i+1;j<=r;j++)
			{
				if((i*j)%2019<min)
				min=(i*j)%2019;
			}
		}
		cout<<min;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int main (){
	long long a, b, x;
	scanf("%lld %lld %lld", &a, &b, &x);
	a = ((a + x - 1) / x) * x;
	b = b / x * x;
	printf("%lld\n", (b - a) / x + 1);
	return 0;
}

Measured memory_bytes: 128
def e_one_or_two(N, M, Info):
    class UnionFind(object):
        def __init__(self, n):
            self.p = list(range(n))  # i番の頂点の親(parent)はi番とする
            self.rank = [0] * n  # 全頂点はランク0(繋がりなし)とする
            self.size = [1] * n  # 全頂点の連結成分の大きさ1とする

        def union(self, x, y):  # x, yを同じ連結成分に属させる
            u, v = self.find(x), self.find(y)
            if u == v:  # x, yは既に同じ連結成分に属していた
                return
            if self.rank[u] < self.rank[v]:
                self.p[u] = v  # ランクの大きな方につなげる
                self.size[v] += self.size[u]  # つながっている要素数だけ足す
                self.size[u] = 0  # ランクが小さかった連結成分は「解散」
            else:  # 上と同様にやる
                self.p[v] = u
                self.size[u] += self.size[v]
                self.size[v] = 0
                if self.rank[u] == self.rank[v]:
                    self.rank[u] += 1  # 根の分だけ1個「ずれる」
            # 経路圧縮を行い、連結成分の代表を更新
            self.find(x)
            self.find(y)
            return None

        def find(self, x):  # 頂点xが属する連結成分の代表(根の番号)を求める
            if self.p[x] != x:  # 頂点xの代表は他の頂点だった
                self.p[x] = self.find(self.p[x])  # 経路圧縮(xを代表につなぐ)
            return self.p[x]

        def is_same(self, x, y):  # 頂点x,yは同じ連結成分に属するか？
            return self.find(x) == self.find(y)

    uf = UnionFind(N)
    for x, y, z in Info:
        if not uf.is_same(x - 1, y - 1):
            uf.union(x - 1, y - 1)
    return sum([1 for i in range(N) if i == uf.find(i)])

N, M = [int(i) for i in input().split()]
Info = [[int(i) for i in input().split()] for j in range(M)]
print(e_one_or_two(N, M, Info))

Measured memory_bytes: 27512
class SegTree:
    def __init__(self, init_val, ide_ele, segfunc):
        self.n = len(init_val)
        self.num =2**(self.n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg = [self.ide_ele]*2*self.num
        self.segfunc = segfunc
        
        #set_val
        for i in range(self.n):
            self.seg[i+self.num-1] = init_val[i]    
        #built
        for i in range(self.num-2,-1,-1) :
            self.seg[i] = segfunc(self.seg[2*i+1], self.seg[2*i+2]) 
    
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2])
    
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res = self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res
    
### 使い方 ##

import sys
input = sys.stdin.readline
N = int(input())


GOTO = [i for i in range(1,N+1)]
INF = 10**15
ide_ele = -1
SEG = SegTree(GOTO,ide_ele,max)


LIST = []
XX = []
mod = 998244353

for i in range(N):
    X,D = map(int,input().split())
    LIST.append([X,D])

LIST.sort(key=lambda x: x[0])
for i in range(N):
    XX.append(LIST[i][0])

#print(LIST)
import bisect
for i in range(N-1):
    j = N-2-i
    Xj = LIST[j][0]
    Dj = LIST[j][1]
    Nj = bisect.bisect_right(XX, Xj+Dj-1)
    #print(Xj,Dj,j+1,Nj)
    NEXT = SEG.query(j+1,Nj)
    if NEXT != -1:
        GOTO[j] = NEXT
        SEG.update(j,NEXT)
    
S = [-1]*(N+1)
S[N] = 1

#print(LIST)
#print(GOTO)
for i in range(N):
    j = N-1-i
    S[j] = S[j+1] + S[GOTO[j]]
    S[j] %= mod

print(S[0])

Measured memory_bytes: 114484
using System; 
class Program
    {
        static void Main(string[] args)
        {

            string line = Console.ReadLine();
            var data = line.Split(new char[] { ' ' });
            bool isPoor = false;

            if ((data[0] == data[1] && data[0] != data[2]) ||
            (data[1] == data[2] && data[1] != data[0]) ||
            (data[2] == data[0] && data[2] != data[1]))
            {
                isPoor = true;
            }

            if (isPoor)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }

Measured memory_bytes: 11092
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
using namespace std;

int main()
{   
    int n, a, b, sum=0, total=0;
    string s;
    cin >> n >> a >> b;
    for(int i=1; i<=n; i++, sum=0){
        for(int j=0; j<int(floor(log10(i)))+1; j++) {
            sum += int(float(i)/pow(10,j))%10;
        }
        if((sum >= a) & (sum <= b)) {
            total += i;
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main()
{
  ll n;
  cin >> n;
  string str ="";
  if(n == 0){
    str = "0";
    cout<<str<<endl;
    return 0;    
  }

  ll base = 1;
  while(n!=0){  
    if(n%(base*2) == 0) str += '0';
    else
    {
      str+='1';
      n-=base;
    }
    base*=-2; 
  }
  reverse(str.begin(),str.end());
  cout<<str<<endl;
}

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    int N; cin >> N;
    int M; cin >> M;
    vector<vi> graph(3*N);
    F0R(i, M) {
        int A, B; cin >> A >> B; A--; B--;
        graph[A].pb(B+N); graph[A+N].pb(B+2*N); graph[A+2*N].pb(B);
    }

    int S, T; cin >> S >> T; S--; T--;

    queue<int> Q;
    int dist[3*N]; F0R(i, 3*N) dist[i] = -1;

    dist[S] = 0;
    Q.push(S);
    while (!Q.empty()) {
        int cur = Q.front(); Q.pop();
        F0R(i, sz(graph[cur])) {
            int nxt = graph[cur][i];
            if (dist[nxt] == -1) {
                dist[nxt] = dist[cur] + 1;
                Q.push(nxt);
            }
        }
    }

    if (dist[T] == -1) {
        cout << -1 << endl;
        return 0;
    }

    cout << dist[T] / 3 << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

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

struct node {
	int n,mn,mt,cn[21],t[21];
};
node d[21];

int search(int fr,int to,int a) {
	int i,k,m=0,mn=0,mt=0;
	for (i=0;i<d[to].n;i++) {
		if (d[to].cn[i]==fr || d[d[to].cn[i]].n==1) continue;
		k=search(to,d[to].cn[i],d[to].t[i]);
		if (k>=m) { mn=d[to].cn[i]; mt=d[to].t[i]; m=k;}
	}
    d[to].mn=mn; d[to].mt=mt;
    return m+a;
}

int main() {
     int i,n,a,b,t,g,s;
     while(cin >> n && n>0) {
	   g=0;
	   for (i=1;i<=n;i++)  d[i].n=d[i].mn=0;	 
	   for (i=0;i<n-1;i++) {
		   cin >> a >> b >> t; g=g+t*2;
		   d[a].t[d[a].n]=d[b].t[d[b].n]=t; d[a].cn[d[a].n++]=b; d[b].cn[d[b].n++]=a; 
	       }
	   for (i=2;i<=n;i++) if (d[i].n==1) g-=d[i].t[0]*2;
	   search(1,1,0);
	   s=1;
	   while(d[s].mn>0) {  g-=d[s].mt; s=d[s].mn; }
	   cout << g << endl;
	   }
   return 0;
 }

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define mod 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

using namespace std;

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

int main(){
    int p,q,r;
    cin>>p>>q>>r;
    int mina=1000000;
    mina=min(mina,p+q);
    mina=min(mina,q+r);
    mina=min(mina,r+p);

    cout<<mina;
    return 0;
}

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

const int MAX_VAL = 1e4;
int main() {
    int H, N; cin >> H >> N;
    vector<int> A(N), B(N);
    rep(i, N) {
        cin >> A[i] >> B[i];
    }

    vector<int> dp(H + 1, 1e9);
    dp[0] = 0;
    
    rep(i, N) {
        rep(j, H+1) {
            dp[min(j+A[i], H)] = min(dp[min(j+A[i], H)], dp[j] + B[i]);
        }
    }

    cout << dp[H] << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int w, h, x, y, r;
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
	
	if (0 <= x - r && x + r <= w && 0 <= y - r && y + r <= h) puts("Yes");
	else puts("No");
	
	return 0;
}

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

int main(){
  long long int n,a,b;
  cin>>n>>a>>b;
  if(n%(a+b)<=a){
    cout<<n/(a+b)*a+n%(a+b)<<endl;
  }
  else{
    cout<<n/(a+b)*a+a<<endl;
  }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,f,n) for(int i=f; i<(n); i++)
int main()
{
  ll n, ans = 0;
  cin >> n;
  vector<ll> a, b, c;
  REP(i,0,n){
    int inter;
    cin >> inter;
    a.push_back(inter);
  }
  REP(i,0,n){
    int inter;
    cin >> inter;
    b.push_back(inter);
  }
  REP(i,0,n){
    int inter;
    cin >> inter;
    c.push_back(inter);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  
  
  REP(i,0,n){
    ll sita = upper_bound(c.begin(),c.end(),b[i]) - c.begin();
    ll ue = lower_bound(a.begin(),a.end(),b[i]) - a.begin();
    ans += (n - sita)*ue;
  }
  cout << ans << endl;

  //--debug : end_stoper
  //string end_stoper; cin >> end_stoper;

  return 0;
}

Measured memory_bytes: 6400
#include <stdio.h>


int main(){
  int i, n, fib[45];

  fib[0]=fib[1]=1;
  for(i=2; i<45; i++){
    fib[i]=fib[i-1]+fib[i-2];
  }

  scanf("%d",&n);

  printf("%d\n",fib[n]);

  return 0;
}



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

int main() {
    int height, weight, i;

    cin >> height >> weight;
    vector<string> str(100);

    for (i = 0; i < height; i++)
        cin >> str.at(i);

    for (i = 0; i < weight + 2; i++)
        cout << "#";
    cout << endl;
    
    for (int i = 0; i < height; i++) {
        cout << "#";
        cout << str.at(i) + "#" << endl;
    }

    for (i = 0; i < weight + 2; i++)
        cout << "#";
    cout << endl;

    return 0;
}


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

unsigned foo(unsigned n, unsigned k, unsigned s, unsigned temp,int m){
	unsigned ans = 0;//cout<<n<<" "<<k<<" "<<s<<" "<<temp<<" "<<m<<endl;
	if(k==0){
		if(temp == s) return 1;
		else return 0;
	}
	for(int i = m; i <= n; i++){
		ans += foo(n,k-1,s,temp+i,i+1);
	}
	return ans;
}

int main(){
	unsigned n, k, s;
	
	while(1){
		cin>>n>>k>>s;
		if(!n&&!k&&!s)break;
		cout<<foo(n,k,s,0,1)<<endl;
	}
	return 0;
}


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

#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl

using namespace std;

const int maxn = 3e5+5;
const int intinf = 1<<29;
const ll inf = 1ll<<60;


void GG(){cout<<"No\n"; exit(0);}

bool p[maxn];
int nb[maxn];

int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   	int n, m; cin>>n>>m;
   	REP(i,n) nb[i]=1;
   	p[0]=1;
   	REP(i,m){
   		int x, y; cin>>x>>y; x--; y--;
   		nb[x]--; nb[y]++;
   		if (p[x]) p[y]=1;
   		if (nb[x]==0) p[x]=0;
   	}
   	int re = 0;
   	REP(i,n) re+=p[i];
   	cout<<re<<endl;
}

Measured memory_bytes: 768
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((s)),(s).begin(),TL<char>)
# define UPPER(s)    transform(ALL((s)),(s).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int Par[1010101];
int Rank[1010101];

void init(int n) {
	for (int i = 0; i < n; i++) {
		Par[i] = i;
		Rank[i] = 0;
	}
}

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

void unite(int  x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (Rank[x] < Rank[y]) {
		Par[x] = y;
	}
	else {
		Par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}

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

int n;
string a[101010];

int x[101010];
int m;
int main() {
	map<string, int> mp;
	cin >> n;
	init(n + 1);
	REP(i, n) {
		cin >> a[i] >> x[i];
		mp[a[i]] = i;
	}
	cin >> m;
	REP(i, m) {
		string s, t;
		cin >> s >> t;
		int ss = mp[s], tt = mp[t];
		unite(ss, tt);
	}
	REP(i, n) {
		x[find(i)] = min(x[find(i)], x[i]);
	}
	LL ans = 0;
	REP(i, n)ans += x[find(i)];
	cout << ans << endl;
}


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

using namespace std;
#define ll long long int

ll dp[123456];
ll arr[123456];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }


    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        dp[i] = dp[i-1] + abs(arr[i-1]- arr[i]);
        if (i >= 2) {
            dp[i] = min(dp[i], dp[i-2] + abs(arr[i-2] -  arr[i]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
ans = 0

for i in range(1, len(S)):
	if S[i] != S[i-1]:
		ans += 1

print(ans)

Measured memory_bytes: 5464
#include <bits/stdc++.h>
#include <random>
//-------------------------------------------------------------------------
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define prv(v) for (auto i : v) { cout << i << " ";}
#define prmat(v) for (auto i : v) { prv(i); cout << "\n";}
#define cout(x) cout << fixed << setprecision(x)
#define read(v) for (int i_ = 0; i_ < v.size(); i_++) { cin >> v[i_];}
#define fast_io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define all(v) (v.begin()), (v.end())
#define rall(v) (v.rbegin()), (v.rend())
#define pii pair<ll, ll>
//------------------------------------------------------------------------
int main(){
    fast_io;
#ifdef LOCALKA
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    vector<ll> v(n);
    read(v);
    sort(v.rbegin(), v.rend());
    map<ll, ll> mp;
    for(auto i : v){
        mp[i]++;
    }
    ll ans = 0;
    for(auto x : v){
        ll cur_two = 1;
        while(cur_two <= x){
            cur_two *= 2;
        }
        ll need = cur_two - x;
        if(need == x){
            if(mp[need] > 1){
                mp[need]-= 2;
                ans++;
            }
        }
        else if(mp[need] > 0 && mp[x] > 0){
            ans++;
            mp[need]--;
            mp[x]--;
        }
    }
    cout << ans;
    
    
}


Measured memory_bytes: 26880
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1000][1000];
vector<ll> va,vb,vc;


int main(){
    cin>>c>>a>>b;
    if(a<b)C min(max(ll(0),b-(a+c)),max(ll(0),(b+c)-a)) E;
    else C min(max(ll(0),(a+c)-b),max(ll(0),a-(b+c))) E;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    
    int r,d,x;
    cin >> r >> d >> x;

    rep(i,0,10){
	P(r*x - d);
	x = r*x-d;
    }
    return  0;
}


Measured memory_bytes: 256
#pragma region Header
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n, k;
    cin >> n >> k;
    vector<int> p_s(n);
    rep(i, n)
    {
        cin >> p_s[i];
    }
    i64 cur_sum = 0;
    rep(i, k)
    {
        cur_sum += p_s[i];
    }
    i64 sum = cur_sum;
    for (int l = 1; l + k <= n; ++l)
    {
        int r = l + k;
        cur_sum += p_s[r - 1] - p_s[l - 1];
        sum = max(sum, cur_sum);
    }
    sum += k;
    cout << (double)sum / 2 << endl;

    return 0;
}


Measured memory_bytes: 4000
#include <stdio.h>

int main()
{
    int x[5];

    for (int s = 0; s < 5; s++)
    {
        scanf("%d", &x[s]);
    }

    for (int i = 0; i < 5; i++)
    {
        if (x[i]==0)
        {
            printf("%d", i+1);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1724
#include <iostream>
#include<map>
using namespace std;
typedef long long ll;
ll n,s[26],d[365][26],t[365],ans,u[26],q,a,b,c,MAX=-10000000,L,A[365],M,MM;
int main(void){
    cin>>n;
    for(int i=0;i<26;i++){
        cin>>s[i];
    }
    for(int i=0;i<n;i++){
        M=0;
        for(int j=0;j<26;j++){
            cin>>d[i][j];
            if(M<d[i][j])MM=j;
        }
        t[i]=MM+1;
    }
    
    
    //for(int i=0;i<n;i++){
    //        t[i]=rand()%26+1;
    ///    }
        
        
    q=20000;
    while(q--){
        a=rand()%n;
        b=rand()%26;
        ans=0;
        for(int i=0;i<26;i++)u[i]=0;
        
        c=t[a];
        t[a]=b+1;
        
        for(int i=0;i<n;i++){
            ans+=d[i][t[i]-1];
            u[t[i]-1]=i+1;
            for(int j=0;j<26;j++){
                ans-=s[j]*(i+1-u[j]);
            }
        }
        if(MAX<ans){
            MAX=ans;
        }
        else t[a]=c;
    }
    
    for(int i=0;i<n;i++){
        cout<<t[i]<<endl;
    }
    //cout<<MAX<<endl;
}


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

int main() {
  long long int N,res,sum=0,sumx=0;
  cin>>N;
  vector<long long int> as(N);
  for(int i=0;i<N;i++){cin>>as.at(i);sum+=as.at(i);}
  sumx+=as.at(0);
  res=abs(sum-2*sumx);
  for(int i=1;i<N-1;i++){
    sumx+=as.at(i);
    res=min(res,abs(sum-2*sumx));
  }
  cout<<res<<endl;
}

Measured memory_bytes: 1792
def solve():
    A, B, K = map(int, input().split())

    lst = []
    for i in range(1, max(A,B)+1):
        if A % i == 0 and B % i == 0:
            lst.append(i)
    
    print(lst[-K])

if __name__ == '__main__':
    solve()

Measured memory_bytes: 38256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int m,d;
    cin >> m >> d;
    int sum=0;
    for(int i=22;i<=d;i++){
    	int k=i/10,t=i%10;
    	if(k>1&&t>1&&k*t<=m&&k*t!=0){
//    		cout << k*t << " ";
    		sum+=1;
	}	
}
cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

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

	vector<int> arr(n);

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

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

	int ni = arr.back();
	int ki = arr[0];
	int nowd = arr.back();

	for (int i = 0; i < n - 1; i++)
	{
		int dx = abs((ni + 1) / 2 - arr[i]);

		if (ni % 2 == 0)
			dx = min(dx, abs(ni / 2 + 1 - arr[i]));
		
		if (dx < nowd)
		{
			nowd = dx;
			ki = arr[i];
		}
	}

	printf("%d %d\n", ni, ki);

	return 0;
}

Measured memory_bytes: 640
import sys


def solve(x, k, d):
    x = abs(x)
    if d * k <= x:
        return x - d * k
    p, q = divmod(x, d)
    if (k - p) % 2 == 0:
        return q
    else:
        return d - q


def main():
    input = sys.stdin.buffer.readline
    x, k, d = map(int, input().split())
    print(solve(x, k, d))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9236
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;

signed main(){
    int a,p;
    cin >> a >> p;
    p+=a*3;
    cout << p/2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;

int main() {
    int h, w; cin >> h >> w;
    vector<string> grid(h);
    for (int i=0; i<h; ++i) cin >> grid[i];
    vector<vector<long long>> paths(h+1, vector<long long>(w+1, 0));
    paths[1][1] = 1;
    for (int i=1; i<=h; ++i) {
        for (int j=1; j<=w; ++j) {
            if (i == 1 && j == 1) continue;
            if (grid[i-1][j-1] == '#') continue;
            paths[i][j] = paths[i-1][j]%mod + paths[i][j-1]%mod;
            paths[i][j] %= mod;
        }
    }
    cout << paths[h][w] << endl;
}

Measured memory_bytes: 9216
x,y;
main(){
    char c;
    for(;scanf("%d %c %d",&x,&c,&y),c!='?';){
        switch(c){
            case '+':x+=y;break;
            case '-':x-=y;break;
            case '*':x*=y;break;
            case '/':x/=y;break;
        }
        printf("%d\n",x);
    }
}

Measured memory_bytes: 1716
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	string s;
	cin >> s;
	if(s.size() == 3) reverse(s.begin(), s.end());
	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; scanf("%d", &n);
    string s[300];
    for (int i = 0; i < n; i++) {
        string str; cin >> str;
        s[i] = str;
    }
    int res = 0;
    for (int k = 0; k < n; k++) {
        bool flag = true;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (s[i][(j+k)%n] != s[j][(i+k)%n]) {
                    flag = false;
                    break;
                }
            }
            if (!flag) break;
        }
        if (flag) res++;
    }
    cout << res * n << endl;
}



Measured memory_bytes: 512
N = int(input())
def factorization(n): # => {prime:count,...}
    fac = {}
    count = 0
    while n % 2 == 0:
        n //= 2
        count += 1
    if count > 0:
        fac[2] = count
    for i in range(3, int(n ** .5) + 1, 2):
        count = 0
        while n % i == 0:
            n //= i
            count += 1
        if count > 0:
            fac[i] = count
    if n > 1:
        fac[n] = 1
    return fac
ans = 0
for key, cnt in factorization(N).items():
    n = 1
    while cnt >= 0:
        cnt -= n
        n += 1
        ans += 1
    ans -= 1
print(ans)

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define print(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n;
    map<string,int> a;
    rep(i,n){
        cin >> s;
        a[s]++;
    }
    int max = 0;
    for(auto i:a){
        chmax(max,i.second);
    }
    for(auto i:a){
        if (i.second == max) print(i.first);
    }
}


Measured memory_bytes: 23808
class Bit:
    def __init__(self, n):
        """
        :param n: 最大の要素数
        """
        self.n = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length() - 1

    def sum(self, i):
        """ 区間[0,i) の総和を求める """
        s = 0
        i -= 1
        while i >= 0:
            s += self.tree[i]
            i = (i & (i + 1) )- 1
        return s

    def built(self, array):
        """ array を初期値とするBITを構築 """
        for i, a in enumerate(array):
            self.add(i, a)

    def add(self, i, x):
        """ i 番目の要素に x を足す """
        while i < self.n:
            self.tree[i] += x
            i |= i + 1

    def get(self, i, j):
        """ 部分区間和 [i, j) """
        if i == 0:
            return self.sum(j)
        return self.sum(j) - self.sum(i)

    def lower_bound(self, x, equal=False):
        """
        (a0+a1+...+ai < x となる最大の i (存在しない時は -1 ) , その時の a0+a1+...+ai )
        a0+a1+...+ai <= x としたい場合は equal = True
        二分探索であるため、ai>=0 を満たす必要がある
        """
        sum_ = 0
        pos = -1    # 1-indexed の時は pos = 0
        if not equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] < x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        if equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] <= x: # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        return pos, sum_

    def __getitem__(self, i):
        """ [a0, a1, a2, ...] """
        return self.get(i, i+1)

    def __iter__(self):
        """ [a0, a1, a2, ...] """
        for i in range(self.n):
            yield self.get(i, i+1)

    def __str__(self):
        text1 = " ".join(["element:            "] + list(map(str, self)))
        text2 = " ".join(["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1)))
        return "\n".join((text1, text2))

n,q = map(int,input().split())
a = list(map(int,input().split()))
B = Bit(n)
B.built(a)

for _ in range(q):
    a,b,c = map(int,input().split())
    if a == 0:
        B.add(b, c)
    else:
        print(B.get(b, c))


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

int main() {
  ll N; cin >> N;
  int ans = 1000010;
  for(int i = 1; i <= sqrt(N); ++i) {
    ll tmp = N / i;
    if(tmp * i == N) {
      int A = to_string(tmp).size();
      int B = to_string(i).size();
      int tmp = max(A, B);
      if(ans > tmp) ans = tmp;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=111;
int n,x[maxn],cnt,ans,iro=-1;
int main(){
    scanf("%d",&n);
    for(register int i=1;i<=n;i++){
        scanf("%d",&x[i]);
        if(x[i]==x[i-1]) cnt++;
        else{
            ans+=cnt/2;
            cnt=1;
        }
    }
    ans+=cnt/2;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256