akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
// #include <fstream>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) lower_bound(ALL(c),x)
#define UB(c,x) upper_bound(ALL(c),x)
#define COUNT(c,x) (int)(UB(c,x)-LB(c,x))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}


signed main()
{
  // string filename; cin >> filename;
  // ifstream in(filename);
  // cin.rdbuf(in.rdbuf());

  int N; cin >> N;
  vector<int> p(N);
  rep(i, 0, N) {
    cin >> p[i];
  }

  int ans = 0;
  rep(i, 0, N-1) {
    if (i+1 == p[i]) {
      ans++;
      swap(p[i], p[i+1]);
    }
  }
  if (N == p[N-1]) {
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
/**
 *   author: sahushivam
 *   created: 26 January 2020 (Sunday)  17:36:27
**/
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define int long long

void solve(){
	int n,k;
	cin>>n>>k;
	std::vector<int> v(n);
	for(int i=0;i<n;i++) cin>>v[i];
	sort(v.begin(),v.end());
	int s=0;
	for(int i=0;i<n-k;i++)
	{
		s+=v[i];
	}
	cout<<s;
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int t=1; while(t--) solve();
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

int main() {
	ll a,b,c,d,n;
	scanf("%lld%lld%lld%lld%lld", &a, &b, &c, &d, &n);
	if (b > 2*a) b=2*a;
	if (c > 2*b) c=2*b;
	if (d > 2*c) d=2*c;
	printf("%lld\n", n/2*d + n%2*c);
	return 0;
}


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

int main() {
  
  int N;
  cin >> N;
  if(N>=100){
    N=N%100;
  }
  if(N>=10){
    N=N%10;
  }
  if(N==3){
    cout << "bon" << endl;
  }
  else if(N==0 || N==1 || N==6 || N==8){
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3624
n, m = gets.split.map(&:to_i)
graph = Array.new(n+1){Array.new(n+1, false)}
edge = []
m.times do |i|
  edge[i] = gets.split.map(&:to_i)
  graph[edge[i][0]-1][edge[i][1]-1] = graph[edge[i][1]-1][edge[i][0]-1] = true
end
dp = Array.new(1<<n) {Array.new(n,0)}
dp[1][0] = 1
(1<<n).times do |s|
  n.times do |v|
    next if (1 << v) & s > 0
    n.times do |u|
      if ((1<<u) & s) > 0 && graph[u][v]
        dp[s|(1<<v)][v] += dp[s][u]
      end
    end
  end
end

puts dp[(1<<n)-1].inject(:+)


Measured memory_bytes: 1788
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    As = list(map(int, input().split()))

    s = 0
    max_n = As[0]
    for i in range(len(As)):
        if i == 0: continue
        if max_n > As[i]:
            s += max_n - As[i]
        elif max_n < As[i]:
            max_n = As[i]
    print(s)

if __name__ == '__main__':
    main()

Measured memory_bytes: 32292
/*  -*- coding: utf-8 -*-
 *
 * 1616.cc: Taro's Shopping
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  for (int n, m; scanf("%d%d", &n, &m) == 2 && n > 0;) {
    for (int i = 0; i < n; i++) scanf("%d", as + i);

    int maxsum = -1;
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) {
	int sum = as[i] + as[j];
	if (sum <= m && maxsum < sum) maxsum = sum;
      }

    if (maxsum < 0) puts("NONE");
    else printf("%d\n", maxsum);
  }
  return 0;
}



Measured memory_bytes: 3216
import java.util.*;
  
class Main{
   public static void main(String[] args){
     Scanner stdId = new Scanner(System.in);
     int a = stdId.nextInt(); 
		 int b = stdId.nextInt();
		 int c = stdId.nextInt();
     if(a<b && b<c) System.out.println("Yes");
     else System.out.println("No");
  }
}

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

int L[11];

int main() {
    int N, max_L = 0, idx = -1;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> L[i];
        if (L[i] > max_L) {
            max_L = max(max_L, L[i]);
            idx = i;
        }
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
        if (i == idx) continue;
        sum += L[i];
    }
    if (sum > max_L) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

N, M = map(int,input().split())
UFT = UnionFind(N + M)
for i in range(N):
    K, *L = map(int,input().split())
    for l in L:
        UFT.union(i, N+l-1)

if len(set([UFT.find(i) for i in range(N)])) == 1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 15580
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int maxn = 200006;
int n, x;
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n >> x;
    for(int i = 1; i <= 1000; i ++){
        if(abs(n - x) == abs(i - 1)){
            return 0 * printf("%d\n", i);
        }
    }
    return 0;
}


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

ll dfs(vector<ll> A,vector<ll> P,ll N,ll X){
	ll res=0;
	if(N==1){
		if(X==2) res+=1;
		if(X==3) res+=2;
		if(X==4) res+=3;
		if(X==5) res+=3;
		return res;
	}
	if(X==1){
		res+=0;
	}else if(2<=X && X<=A[N-1]+1){
		res+=dfs(A,P,N-1,X-1);
	}else if(X==A[N-1]+2){
		res+=1+P[N-1];
	}else if(3+A[N-1]<=X && X<=2*A[N-1]+2){
		res+=P[N-1]+1+dfs(A,P,N-1,X-(2+A[N-1]));
	}else{
		res+=P[N];
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	ll N,X;
	cin>>N>>X;
	vector<ll> A(N+1);
	vector<ll> P(N+1);
	for(int i=1;i<=N;i++){
		if(i==1){
			A[i]=5;
			P[i]=3;
		}else{
			A[i]=A[i-1]*2+3;
			P[i]=P[i-1]*2+1;
		}
	}
	cout<<dfs(A,P,N,X)<<endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=[]
for i in range(0,N):
    A.append(int(input()))
A.sort()
def histogram_sorted(data):
    result=[]
    item = data[0]
    c=1
    for i in range(1,len(data)):
        if item==data[i]:
            c=c+1
        else:
            result.append([item,c])
            c=1
            item=data[i]
    result.append([item,c])
    return result
a=histogram_sorted(A)
kosu=0
for i in range(len(a)):
        if a[i][1]%2==1:
             kosu=kosu+1
print(kosu)

Measured memory_bytes: 17228
S = input()

flg = True

end = len(S)-1
for i in range(len(S) // 2):
    if S[i] != S[end-i]:
        flg = False

half_end = (len(S) // 2) - 1
for i in range(len(S) // 4):
    if S[i] != S[half_end-i]:
        flg = False

hajime = ((len(S)-1+3) // 2)
for i in range(hajime, len(S)):
    if S[i] != S[end-i]:
        flg = False

if flg:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<stdio.h>
int max(int x,int y,int z){
if(x>=y&&x>=z)return x;
if(y>=x&&y>=z)return y;
  if(z>=x&&z>=y)return z;
}
int main(void){
int p,q,r;
  scanf("%d%d%d",&p,&q,&r);
  int sum=p+q+r;
  printf("%d",sum-max(p,q,r));
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<LL,LL> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

vector<P> v1;

int main(){
	LL n,m;
	int i,j,k;
	LL a,b,c;
	LL p[5];
	LL x,y,z;
	cin>>x>>y;
	z=x+y;
	for(i=0;i<3;i++){
		cin>>p[i];
	}
	for(i=0;i<3;i++){
		for(j=0;j<p[i];j++){
			cin>>a;
			v1.push_back(make_pair(a,i));
		}
	}
	sort(v1.rbegin(),v1.rend());
	a=0;
	for(auto node:v1){
		if(z==0)continue;
		if(node.second==0 && x==0)continue;
		if(node.second==1 && y==0)continue;
		z--;
		if(node.second==0)x--;
		if(node.second==1)y--;
		a+=node.first;
	}
	cout<<a<<endl;
}

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

int main(){
	char c;
	cin >> c;
	if(c >= 'A'&& c <= 'Z') cout << "A" << endl;
	else cout << "a" << endl;
	

}













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

int main() {
    ll n,m; cin >> n >> m;
    ll out;
    if(n==1 && m == 1)out = 1;
    else if(n==1)out = m-2;
    else if(m==1)out = n-2;
    else out = (n-2)*(m-2);
    cout << out << endl;
}   



Measured memory_bytes: 256
//{{{ #include <bits/stdc++.h>
#ifndef __clang__
#include <bits/stdc++.h>
#endif
using namespace std; //}}}
const long long MOD = static_cast<int>(1e9) + 7;
//{{{TEMPLATE_BEGIN
#include <unistd.h>
using namespace std::rel_ops;
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef vector<int> vint;
#define rep(i, n)                                                              \
    for (int i = 0, i##_len = static_cast<int>(n); i < i##_len; i++)
#define all(c) begin(c), end(c)
#define perm(c)                                                                \
    sort(all(c));                                                              \
for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))
#define uniquenize(v) (v).erase(unique(all(v)), end(v))
#define cauto const auto &
#define memset(x, y) memset(x, y, sizeof(x))
#define popcount __builtin_popcount
#define gcd __gcd
inline lint bit(int x) {
    return 1LL << x;
}
template <class T>
inline int size(const T &a) {
    return (int)a.size();
}
template <class T>
inline bool chmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}
template <class T>
inline int clamp(T v, T lo, T hi) {
    return (v > hi) - (v < lo);
}
template <class T>
inline bool chmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T> &v, const char &c) {
    return make_pair(v, c);
}
template <class T>
inline istream &operator>>(istream &is, vector<T> &v) {
#ifdef ZEROKUGI
    if (v.empty()) {
        cerr << "Error L" << __LINE__ << ": vector size is zero." << endl;
        exit(EXIT_FAILURE);
    }
#endif
    for (auto &x : v)
        is >> x;
    return is;
}
template <class T>
inline ostream &operator<<(ostream &os, const pair<vector<T>, char> &v) {
    bool t = 0;
    for (const T &x : v.first) {
        if (t)
            os << v.second;
        os << x;
        t = 1;
    }
    return os;
}
template <class T>
inline ostream &operator<<(ostream &os, vector<T> &v) {
    return os << v * ' ';
}
struct before_main {
    before_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} __before_main;
//}}}TEMPLATE_END

int main() {
    vector<int> a(3);
    cin >> a;
    sort(all(a));
    cout << (a[0] * a[1]) / 2 << endl;
}



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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

string s, t;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] != t[i])
            ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3784
#include<iostream>
using namespace std;
const int MAX = 50;
int main()
{
	while (true)
	{
		int n, p;
		cin >> n >> p;
		if (!n && !p)
			break;
		int pOfCan[MAX] = { 0 };
		int pOfBowl = p;
		int winIdx = -1;
		int idx = 0;
		bool flag = false;
		while (true)
		{
			for (int i = 0; i < n; i++)
				if (pOfCan[i] == p)
				{
					winIdx = i;
					flag = true;
					break;
				}
			if (flag)
				break;
			if (idx > n - 1)
				idx = 0;
			if (pOfBowl > 0)
			{
				pOfCan[idx]++;
				pOfBowl--;
			}
			else if (pOfBowl == 0)
			{
				pOfBowl = pOfCan[idx];
				pOfCan[idx] = 0;
			}
			idx++;
		}
		cout << winIdx << endl;
	}
}


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

long long n;

long long solve();

int main() {
  cin >> n;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j * i <= n; ++j) res += i * j;
  }
  return res;
}

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

int main()
{
    int H, W;
    scanf("%d %d", &H, &W);
    char mp[H][W+10];
    for(int i = 0; i < H; ++i) scanf("%s", mp[i]);

    for(int i = 0; i < W + 2; ++i) printf("#");
    printf("\n");
    for(int i = 0; i < H; ++i) {
        printf("#"); printf("%s", mp[i]); printf("#\n");
    }
    for(int i = 0; i < W + 2; ++i) printf("#");
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, Q;
    cin >> N >> Q;
    vector<vector<int>> v(N);
    while (Q--) {
        int q; cin >> q;
        if (q == 0) {
            int t, x; cin >> t >> x;
            v[t].push_back(x);
        } else if (q == 1) {
            int t; cin >> t;
            bool f = false;
            for (auto& x : v[t]) {
                if (f) cout << " ";
                cout << x;
                f = true;
            }
            cout << endl;
        } else {
            int t; cin >> t;
            v[t].clear();
        }
    }
}


Measured memory_bytes: 5768
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define pll pair<long long,long long>
using namespace std;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    cout<<a*b;
    return 0;
}

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

#define modulo 1000000007

using namespace std;

int main(){
	int N, M;
	int tmp;
	cin >> N >> M;
	vector<int> a(N + 1, 0);
	vector<long> f(N + 1, 0);
	for(int i = 0; i < M; i++){
		cin >> tmp;
		a[tmp] = 1;
	}
	
	int pt;
	f[0] = 1;

	if(!a[1])
		f[1] = 1;
	for(int i = 2; i < N+1; i++){
		if(a[i])
			continue;
		f[i] = (f[i-1] + f[i-2]) % modulo;
	}

	cout << f[N] << endl;

}

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

int main(){
  int S,n;
  cin >>S;
  n=S;
  int a=0;
  while(S>0){
    a+=S%10;
    S=S/10;
  }
  if(n%a==0){
    cout << "Yes" <<endl;
  }
  else{
    cout <<"No" <<endl;
  }
}


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

#define fst first
#define snd second
#define INF 0x3FFFFFFF
#define PI (2*acos(0))

using namespace std;

typedef long long ll;
typedef complex<double> pt;

int v[100];
int t[100];
int speed[20001];
int limit[20001];
int sum;

void fix(int idx) {
  if (idx > 0 && speed[idx] + 1 < speed[idx - 1]) {
    speed[idx - 1] = speed[idx] + 1;
    fix(idx - 1);
  }
  if (idx < sum && speed[idx] + 1 < speed[idx + 1]) {
    speed[idx + 1] = speed[idx] + 1;
    fix(idx + 1);
  }
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &t[i]);
    sum += t[i];
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
  }
  
  limit[0] = 1000;
  int idx = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= t[i]; j++) {
      if (j == 0) {
        limit[idx] = v[i];
        speed[idx] = min(v[i], speed[idx]);
      } else {
        limit[idx] = v[i];
        speed[idx] = v[i];
      }
      idx++;
    }
    idx--;
  }
  speed[0] = 0;
  speed[sum] = 0;
  for (int i = 0; i <= sum; i++) {
    fix(i);
  }

  // for (int i = 0; i <= sum; i++) {
  //   cout << i << ":" << speed[i] << ":" << limit[i] << " ";
  // }
  // cout << endl;

  double res = 0;
  for (int i = 0; i < sum; i++) {
    res += speed[i];
    if (speed[i] < speed[i + 1] && limit[i] > speed[i]) res += 0.5;
    if (speed[i] == speed[i + 1] && limit[i] > speed[i]) res += 0.25;
    if (speed[i] > speed[i + 1]) res -= 0.5;
    // cout << res << endl;
  }
  printf("%.10lf\n", res);
  return 0;
}


Measured memory_bytes: 384
import math
def sieve (n):
	prime = [0,0]
	prime += [1 for i in range(n-1)]
	ub = math.sqrt(n) + 1
	d = 2
	while d <= ub:
		if prime[d] == 0:
			d += 1
			continue
		prod = 2
		while d * prod <= n:
			prime[d*prod] = 0
			prod += 1
		d += 1
	return prime
prime = sieve(1299709)
while 1:
	k = int(raw_input())
	if k == 0:
		break
	l = r = k
	while prime[l] == 0:
		l -= 1
	while prime[r] == 0:
		r += 1
	print (r-1) - (l+1) + 2

Measured memory_bytes: 56192
#include <stdio.h>
#include <math.h>

long n;
int c[1000];
int k = 0, i, res = 0;

void factorize(long n){
    int count = 0;
    while (!(n % 2)) {
        n/= 2;
        count++;
    }
    if (count)
    {
        c[k] = count;
        ++ k;
    }
    for (long i = 3; i <= sqrt(n); i += 2)
    {
        count = 0;
        while (n % i == 0)
        {
            count++;
            n = n / i;
        }
        if (count)
        {
            c[k] = count;
            ++ k;
        }
    }
    if (n > 2)
    {
        c[k] = 1;
        ++ k;
    }
}
 
int main() 
{       
    scanf("%ld", &n);
    
    if (n == pow(10, 9) + 7)
    {
        printf("1");
        return 0;
    }

    factorize(n);
    
    for (i = 0; i < k; ++ i)
    {
        for (int j = 1; j <= c[i]; ++ j)
            if (j <= c[i])
            {
                ++ res;
                c[i] -= j;
            }
    }
 
    printf("%d", res);
 
    return 0;
}

Measured memory_bytes: 3236
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1001

ll nCm[NUM][NUM];
ll fact[NUM];
ll memo[NUM];
ll POW[NUM];

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

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

ll mod_fact(ll n,ll p,ll &e){
	e = 0;
	if(n == 0)return 1;

	int res = mod_fact(n/p,p,e);
	e += n/p;

	if(n/p%2 != 0)return res*(p-fact[n%p])%p;
	return res*fact[n%p]%p;
}

int main(){

	ll N,K;
	scanf("%lld %lld",&N,&K);

	fact[0] = 1;
	for(ll i = 1; i <= K; i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}

	POW[0] = 1;
	ll tmp;
	for(ll i = 1; i <= K; i++){
		tmp = 1;
		for(int loop = 0; loop < N; loop++){
			tmp *= i;
			tmp %= MOD;
		}
		POW[i] = tmp;
	}

	nCm[0][0] = 1;
	for(int n = 1; n <= K; n++){
		for(int m = 0; m <= K; m++){

			if(n == 0){

				nCm[n][m] = 1;

			}else{

				nCm[n][m] = nCm[n-1][m]+nCm[n-1][m-1];

			}
			nCm[n][m] %= MOD;
		}
	}

	memo[1] = 1;
	ll ans = 0;

	for(ll num = 1; num <= min(N,K); num++){

		memo[num] = POW[num];

		for(int i = 1; i <= num-1; i++){
			memo[num] -= nCm[num][i]*memo[i];
			memo[num] %= MOD;
			if(memo[num] < 0)memo[num] += MOD;
		}

		tmp = memo[num]*mod_inverse(fact[num],MOD);
		tmp %= MOD;
		if(tmp < 0)tmp += MOD;
		ans += tmp;
		ans %= MOD;
		if(ans < 0)ans += MOD;
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 11068
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  map<char, int> cnt;
  int g1, g2, g4;
  if (H % 2 && W % 2) {g1 = 1; g2 = (H+W-1)/2; g4 = (H*W-(g1+2*g2))/4;}
  else if (H % 2 == 0 && W % 2 == 0) {g1 = 0; g2 = 0; g4 = (H*W)/4;}
  else if (H % 2 && W % 2 == 0) {g1 = 0; g2 = W/2; g4 = (H*W-2*g2)/4;}
  else if (H % 2 == 0 && W % 2) {g1 = 0; g2 = H/2; g4 = (H*W-2*g2)/4;}
  VC alp;
  REP(i, H) REP(j, W)
  {
    char a;
    cin >> a;
    cnt[a]++;
    alp.push_back(a);
  }
  UNIQUE(alp);

  priority_queue<int> que;
  REPx(x, alp) que.push(cnt.at(x));

  while(que.size())
  {
    int x = que.top(); que.pop();
    if (g4 > 0 && x >= 4)
    {
      x -= 4;
      g4--;
    }
    else if (g2 > 0 && x >= 2)
    {
      x -= 2;
      g2--;
    }
    else if (g1 > 0 && x >= 1)
    {
      x--;
      g1--;
    }
    else
    {
      que.push(x);
      break;
    }
    if (x != 0) que.push(x);
  }

  if (que.size()) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


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

int main() {
  int n, x;
  int a[101];
  
  for (int i = 0; i <= 101; i++) {
    a[i] = i;
  }
  
  while  (1) {
    cin >> n >> x;
    if (n==0 && x==0) break;
    
    int count = 0;
    for (int i = 1; i <= n-2; i++) {
      for (int j = i+1; j <= n-1; j++) {
        for (int k = j+1; k <= n; k++) {
          if (a[i] + a[j] + a[k] == x) count++;
        }
      }
    }
    cout << count << endl;
  
  }
}



Measured memory_bytes: 3092
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;
int t[105]={};
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    t[a]+=1;
    t[b]+=-1;
    t[c]+=1;
    t[d]+=-1;
    for(int i=0;i<101;i++){
        t[i+1]+=t[i];
    }
    int cnt=0;
    for(int i=0;i<=100;i++){
        if(t[i]>=2)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

void f(int a, int b, int c, int d, bool w) {
  if(w) {
    rep(i,abs(b-d)) cout << (d>=b?'U':'D');
    rep(i,abs(c-a)) cout << (c>=a?'R':'L');
  }
  else {
    rep(i,abs(c-a)) cout << (c>=a?'R':'L');
    rep(i,abs(b-d)) cout << (d>=b?'U':'D');
  }
}

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << 'U'; f(a, b+1, c-1, d, true); cout << 'R';
  cout << 'R'; f(c+1, d, a, b-1, true); cout << 'U';
  cout << 'R'; f(a+1, b, c, d-1, false); cout << 'U';
  cout << 'U'; f(c, d+1, a-1, b, false); cout << 'R';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

int N, W;
ll w[110], v[110];
ll dp[110][100010] = {0};

int main() {
    cin >> N >> W;
    rep(i, N) cin >> w[i] >> v[i];

    for (int i = 0; i < N; i++) {
        for (int sum_w = 0; sum_w <= W; sum_w++) {
            // i番目の品物を選ぶとき
            if (sum_w - w[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i]);
            }

            // i番目の品物を選ばないとき
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    ll ans = 0;
    for (int sum_w = 0; sum_w <= W; sum_w++) {
        ll tmp = dp[N][sum_w];
        if (tmp > ans) ans = tmp;
    }
    cout << ans << endl;
}


Measured memory_bytes: 79360
# Your code here!
a,b=gets.split
a=a.to_i
b=b.to_i

arr=Array.new(a,0)

arr2=gets.split.map{|i| i.to_i}
i=0
a.times{
    arr[arr2[i]-1]+=1
    i+=1
}
    
arr=arr.sort.reverse

ans=arr[0..b-1].inject(:+)
p a-ans

Measured memory_bytes: 19968
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    vi a(n);
    int x;
    rep(i, n){
        cin >> a[i];
        if(i==0)x=a[i];
        else x^=a[i];
    }
    rep(i, n) {
        cout << (x^a[i]) << ' ';
    }
    return 0;
}

Measured memory_bytes: 4764
S = input()
N = len(S)
for i in range(1, N):
    T = S[:-i]
    if len(T) % 2 != 0:
        continue
    M = len(T)
    T1 = T[:M//2]
    T2 = T[M//2:]
    if T1 == T2:
        print(M)
        break

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class DGatheringChildren {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        string s;
        cin >> s;
        int n = s.size();
        vector<int> L(n + 1), R(n + 1);
        REP(i, n) {
            R[i + 1] = R[i];
            if (s[i] == 'R') {
                R[i + 1]++;
            } else {
                R[i + 1] = 0;
            }
        }
        REV(i, n, 1) {
            L[i - 1] = L[i];
            if (s[i] == 'L') {
                L[i - 1]++;
            } else {
                L[i - 1] = 0;
            }
        }

        vector<int> res(n);
        REP(i, n - 1) {
            if (s[i] == 'R' && s[i + 1] == 'L') {
                int r = R[i];
                int l = L[i + 1];
                int k = (r + l + 2) / 2;
                if (r == l || (r % 2 == l % 2)) {
                    res[i] = k;
                    res[i + 1] = k;
                } else if (r % 2 == 1) {
                    res[i] = k;
                    res[i + 1] = k + 1;
                } else {
                    res[i] = k + 1;
                    res[i + 1] = k;
                }
                i++;
            }
        }
        REP(i, n) {
            cout << res[i] << " ";
        }
        cout << endl;

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DGatheringChildren solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3024
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

const string YES = "Yes";
const string NO = "No";

void Main();
void solve(long long X, long long Y);

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
}

void solve(long long X, long long Y){
    if(Y % 2){
        cout << NO << el;return;
    }
    if(X*2 <= Y && Y <= X*4){
        cout << YES << el;
    }else{
        cout << NO << el;
    }
}



Measured memory_bytes: 3672
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <cctype>
using namespace std;

int p;
string expr;

int parseInt()
{
	int ret=0;
	while(isdigit(expr[p]))
	{
		ret*=10;
		ret+=expr[p]-'0';
		p++;
	}
	
	return ret;
}

char parseChr()
{
	char ret=expr[p];
	p++;
	
	return ret;
}

int calc(stack<int>& num, stack<char>& sta)
{
	int r=num.top(); num.pop();
	int l=num.top(); num.pop();
	char e=sta.top(); sta.pop();
	
	if(e=='+') return l+r;
	if(e=='-') return l-r;
	if(e=='*') return l*r;
	
	return l/r;
}

int main()
{
	int N;
	
	map<char, int> tab;
	tab.insert(make_pair('+',1));
	tab.insert(make_pair('-',1));
	tab.insert(make_pair('*',2));
	tab.insert(make_pair('/',2));
	tab.insert(make_pair('(',3));
	tab.insert(make_pair(')',-3));
	
	cin >> N;
	while(N--)
	{	
		p=0;
		cin >> expr;
		
		int nc=0;
		stack<char> sta;
		stack<int> cnt;
		stack<int> num;
		while(expr[p]!='=')
		{
			if(isdigit(expr[p]))
			{
				num.push(parseInt());
			}
			else
			{
				char c=parseChr();
				if(c=='('||c==')') nc+=tab[c];
				else
				{
					while(!sta.empty())
					{
						if(cnt.top()+tab[sta.top()] >= nc+tab[c])
						{
							int ret=calc(num,sta);
							num.push(ret);
							cnt.pop();
						}
						else break;
					}
					
					sta.push(c);
					cnt.push(nc);
				}
			}
		}
		
		while(!sta.empty())
		{
			int ret=calc(num,sta);
			num.push(ret);
		}
		
		cout << num.top() << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e6+9, M = (1<<31), OO = 0x3f3f3f3f;
int main()
{
  int n,m;
  priority_queue<LL> pq;
  scanf("%d%d",&n,&m);
  for(int i=0;i<n;++i)
  {
    LL x;
    scanf("%lld",&x);
    pq.push(x);
  }
  while(m--)
  {
    LL x=pq.top();
    pq.pop();
    x/=2;
    pq.push(x);
  }
  LL x=0;
  while(!pq.empty())
  {
    x+=pq.top();
    pq.pop();
  }
  printf("%lld\n",x);

  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll unsigned long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
#define maxval 10003000
ll power(ll x,ll n)
{//ll x1=0;
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x);
       //  if(result>=1000000001) return 0;
        x=(x*x);
      //   if(x>=1000000001) return 0;
        n=n/2;
    }
    return result;
}
int vowel(char x){
    if(x=='a') return 1;
    if(x=='e') return 1;
    if(x=='i') return 1;
    if(x=='o') return 1;
    if(x=='u') return 1;
    return 0;
}
ll numb(ll x){ll z=sqrt(x);
if(z*z==x) return 1;
    return 0;
}
int main(){
   IOS;
ll t;t=1;//cin>>t;

while(t--){
ll  n;
cin>>n;
ll ans=0;ll v=0;
for(ll i=1;i<n;i++){
  //  if(numb(i)) v++;
  ans=ans+(n-1)/i;  
}
cout<<ans-v<<"\n";

} 
    
    

    
return 0;    
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
namespace my_std{
	using namespace std;
	#define reg register
	#define Rint register int
	#define FOR(i,a,b) for(register int i=(a);i<=(b);++i)
	#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
	#define FORit(templ,arr,i,a,b) for(register templ *i=(arr)+(a);i!=(arr)+(b)+1;++i)
	#define ROFit(templ,arr,i,a,b) for(register templ *i=(arr)+(a);i!=(arr)+(b)-1;--i)
	#define GO(x,p,e,i,v) for(register int i=p[x].head,v;i;i=e[i].link)
	#define MEM(x,v) memset(x,v,sizeof(x))
	#define fir first
	#define sec second
	#define pq priority_queue
	#define PII pair<int,int>
	#define MP make_pair
	typedef long long LL;
	typedef double DB;
	inline int read(){
		int ans=0,f=1;char c=getchar();
		while(!isdigit(c)){ f^=(c=='-'); c=getchar(); }
		for(;isdigit(c);c=getchar()) ans=(ans<<1)+(ans<<3)+(c^48); return f?ans:-ans;
	}
	const int mod = 998244353 , N = 200010;
	inline void inc(int &x,const int &y){ x+=y; if(x>=mod) x-=mod; }
	inline int ksm(int x,LL y){ int res=1; for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) res=1ll*res*x%mod; return res;}
	inline int gcd(int x,int y){ if(x<y) swap(x,y); return y?gcd(y,x%y):x; }
	#define FILE(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
}
using namespace my_std;

char s[N];
int n,t[30];
LL ans;

int main(){
	scanf("%s",s + 1);
	n = strlen(s + 1);
	FOR(i,1,n) t[s[i] - 'a' + 1]++;
	ans = 1ll * n * (n + 1) / 2 + 1;
	FOR(i,1,26) ans -= 1ll * t[i] * (t[i] - 1) / 2 + t[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

int main() {
	int n;
	cin >> n;
	int a[100];
	rep(i, n) {
		cin >> a[i];

	}
	rep(i, n) {
		if (a[i] % 2 == 0) {
			if (a[i] % 3 != 0) {
				if (a[i] % 5 != 0) {
					cout << "DENIED";
					return 0;
				}
			}
		}
	}
	cout << "APPROVED";
	return 0;
}

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

int main(){
    ll N;  cin >> N;
    ll ans = 1e18;
    for(ll i = 1; i*i<=N; i++){
        if(N%i == 0){
            ans = min(i - 1 + N/i - 1 , ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;


void printStage(char stage[20][20],int W,int H,int i,int n){
	for(int y=0;y<H;y++){
		for(int x=0;x<W;x++){
			printf("%c",stage[y][x]);
		}
		printf("\n");
	}
	if(i != n-1) printf("\n");
}
int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			int W,H;
			char stage[20][20];

			scanf("%d %d",&H,&W);

			int px,py;
			for(int y=0;y<H;y++){
				char buf[32];
				scanf("%s",buf);
				for(int x=0;x<W;x++){
					stage[y][x] = buf[x];
					if(buf[x]=='>'
						|| buf[x]=='<'
						|| buf[x]=='^'
						|| buf[x]=='v'){
							px = x;
							py = y;
					}
				}
			}

			int com;
			char buf[128];
			scanf("%d",&com);
			scanf("%s",buf);
			for(int j=0;j<com;j++){
				switch(buf[j]){
				case 'U':
					stage[py][px] = '^';
					if(py -1 >= 0 && stage[py-1][px] == '.'){
						stage[py][px] = '.';
						stage[py-1][px] = '^';
						py--;
					}
					break;
				case 'D':
					stage[py][px] = 'v';
					if(py +1 < H && stage[py+1][px] == '.'){
						stage[py][px] = '.';
						stage[py+1][px] = 'v';
						py++;
					}
					break;
				case 'L':
					stage[py][px] = '<';
					if(px -1 >= 0 && stage[py][px-1] == '.'){
						stage[py][px] = '.';
						stage[py][px-1] = '<';
						px--;
					}
					break;
				case 'R':
					stage[py][px] = '>';
					if(px +1 < W && stage[py][px+1] == '.'){
						stage[py][px] = '.';
						stage[py][px+1] = '>';
						px++;
					}
					break;

				case 'S':
					switch(stage[py][px]){
					case '^':
						for(int y=py;y>=0;y--){
							if(stage[y][px] == '#'){
								break;
							}
							if(stage[y][px] == '*'){
								stage[y][px] = '.';
								break;
							}
						}
						break;
					case 'v':
						for(int y=py;y<H;y++){
							if(stage[y][px] == '#'){
								break;
							}
							if(stage[y][px] == '*'){
								stage[y][px] = '.';
								break;
							}
						}
						break;
					case '<':
						for(int x=px;x>=0;x--){
							if(stage[py][x] == '#'){
								break;
							}
							if(stage[py][x] == '*'){
								stage[py][x] = '.';
								break;
							}
						}
						break;
					case '>':
						for(int x=px;x<W;x++){
							if(stage[py][x] == '#'){
								break;
							}
							if(stage[py][x] == '*'){
								stage[py][x] = '.';
								break;
							}
						}
						break;
					default:
						break;
					}

				default:
					break;
				}
			}

			printStage(stage,W,H,i,n);
		}
	}
}

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

using namespace std;

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	vector<int> p{1};
	while(p.size() < n) p.insert(p.begin(), p[0] * 10);

	map<int, int> s;
	int ans = 0;
	while(m--) {
		int a, b;
		scanf("%d %d", &a, &b);
		if(s.count(a)) {
			if(s[a] != b) return printf("-1\n"), 0;
		}
		else {
			s[a] = b;
			ans += b * p[a - 1];
			if(a == 1 and b == 0 and n > 1) return printf("-1\n"), 0;
		}
	}
	if(n > 1 and !s.count(1)) {
		ans += p[0];
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<stdio.h>
   
#define AMAX 20
#define MMAX 2000
  
int n, q;
int isExist[ MMAX+1 ] = {0};
 
int main( void ) 
{
    int i, j;
    int num;
 
    scanf( "%d", &n );
    for( i=0; i<n; i++ ) {
        scanf( "%d", &num );
        for( j=MMAX-num; 0<j; j-- ) {
            if( isExist[ j ] ) {
                isExist[ j+num ] = 1;
            }
        }
        isExist[ num ] = 1;        
    }
    scanf( "%d", &q );
    for( i=0; i<q; i++ ) {
        scanf( "%d", &num );
        if( isExist[ num ] ) {
            printf( "yes\n" );      
        } else {
            printf( "no\n" );
        }
    }
    return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    string w;
    cin >> w;
    int size = w.size();
    vector<int> alphabet(26,0);
    for(int i=0;i<size;i++){
        int num = (int)(w[i]-'a');
        alphabet[num]++;
    }
    for(int i=0;i<26;i++){
        if(alphabet[i]%2==1){
            cout << "No" << endl;
            break;
        }
        else if(i==25){
            cout << "Yes" << endl;
        }
    }
}

Measured memory_bytes: 3632
# 入力
N = int(input())
s = [input() for _ in range(N)]

# 先頭がBである／ではない、末尾がAである／ではない文字列の個数を数え上げる
a = sum(t[0] != 'B' and t[-1] == 'A' for t in s)
b = sum(t[0] == 'B' and t[-1] != 'A' for t in s)
ba = sum(t[0] == 'B' and t[-1] == 'A' for t in s)

# 最初に、先頭文字がBではない、かつ、末尾文字がAの文字列を先頭におく（そのような文字列が存在すれば）
# 次に、先頭文字がB、かつ、末尾文字がAの文字列を可能な限り連結する
# 次に、（先頭文字がB、かつ、末尾文字がAでない文字列）と（先頭文字がBではない、かつ、末尾文字がAの文字列）を交互に連結する
# 最後に、余っている文字列を適当に連結する
ans = (
    sum(t.count('AB') for t in s) +
    (
        ba if a > 0 else
        max(0, ba - 1)
    ) +
    (
        min(1, b) if a == 0 and ba > 0 else
        min(a, b)
    )
)

# 出力
print(ans)


Measured memory_bytes: 3700