akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n, m;
long long ans;
vector<int> G[maxn];
int fa[maxn], dep[maxn];
long long d[maxn];
map<pair<int, int>, int> mp;
void dfs(int u, int f) {
	fa[u] = f;
	for(auto v : G[u]) {
		if(v != f) {
			dep[v] = dep[u] + 1;
			dfs(v, u);
		}
	}
}
int main() {
	scanf("%d", &n);
	for(int i = 1; i < n; ++i) {
		int u, v; scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
		mp[minmax(u, v)] = i - 1;
	}
	dfs(1, 0);
	scanf("%d", &m);
	for(int i = 0; i < m; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		while(u != v) {
			if(dep[u] < dep[v]) {
				swap(u, v);
			}
			d[i] |= 1LL << mp[minmax(u, fa[u])];
			u = fa[u];
		}
	}
	for(int S = 0; S < 1 << m; ++S) {
		long long e = 0;
		for(int i = 0; i < m; ++i) {
			if(S >> i & 1) {
				e |= d[i];
			}
		}
		int c = 0;
		for(int i = 0; i < n - 1; ++i) {
			if(e & (1LL << i)) {
				++c;
			}
		}
		if(__builtin_popcount(S) & 1) {
			ans -= 1LL << (n - c - 1);
		} else {
			ans += 1LL << (n - c - 1);
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

typedef long long ll;

int A[3];

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

    if (accumulate(A, A + 3, 0) <= 21) {
        printf("win\n");
    } else {
        printf("bust\n");
    }
}

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

using namespace std;

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

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

    int count = 0;
    int sum = 0;

    while(sum == 0){
        for(int i = 0; i < N; i++)
        {
            sum = sum + (A[i] % 2);
        }
        if (sum > 0){
            break;
        }
        for(int i = 0; i < N; i++)
        {
            A[i] = A[i] / 2;
            }
        count = count + 1;    
    }
    
    cout << count << endl;

    return 0;
}

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

bool visited_from1[200010];
bool visited_fromN[200010];

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

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;

        if (a > b) swap(a, b);
        if (a == 1) visited_from1[b] = true;
        if (b == N) visited_fromN[a] = true;
    }

    for (int v = 1; v <= N; v++) {
        if (visited_from1[v] and visited_fromN[v]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}

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

using namespace std;
using ll = long long int;

template <typename T>
struct SegmentTree {
    using F = function<T(T, T)>;

    const T e;
    const F f;
    size_t sz;
    vector<T> tree;

    SegmentTree(size_t n, const F &f, const T &e = 0) : f(f), e(e) {
        sz = 1;
        while(sz < n) sz <<= 1;
        tree.assign(2*sz, e);
    }

    void set(typename vector<T>::iterator begin, typename vector<T>::iterator end) {
        copy(begin, end, tree.begin() + sz);
        for(size_t k=sz-1; k>0; k--)
            tree[k] = f(tree[2*k+0], tree[2*k+1]);
    }

    void update(size_t k, const T &x) {
        k += sz;
        tree[k] = x;
        while(k >>= 1)
            tree[k] = f(tree[2*k+0], tree[2*k+1]);
    }

    T query(size_t a, size_t b) const {
        b = min(b, sz);
        a = max((size_t)0, a);
        T l = e, r = e;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) l = f(l, tree[a++]);
            if(b & 1) r = f(tree[--b], r);
        }
        return f(l, r);
    }

    T operator[](const size_t k) const {
        return tree[sz + k];
    }
};

int main(void) {
    // constexpr ll MOD = 1e9 + 7;
    constexpr ll MOD = 998244353;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n;
    cin >> n;
    vector<pair<ll,ll>> xd(n);
    for(auto &t: xd) cin >> t.first >> t.second;
    sort(xd.begin(), xd.end());

    SegmentTree<ll> st(n+1, [&](ll a, ll b){return max(a, b);}, 0);

    vector<vector<ll>> dp(n+1, vector<ll>(2));
    dp[n][0] = 1;
    dp[n-1][0] = 1;
    dp[n-1][1] = 1;
    st.update(n-1, n);
    for(ll i=n-2; i>=0; i--) {
        ll j = lower_bound(xd.begin(), xd.end(), make_pair(xd[i].first + xd[i].second, (ll)-1e9)) - xd.begin();
        ll k = max(st.query(i, j), j);
        st.update(i, k);

        dp[i][1] = (dp[k][1] + dp[k][0]) % MOD;
        dp[i][0] = (dp[i+1][1] + dp[i+1][0]) % MOD;
    }

    cout << (dp[0][0] + dp[0][1]) % MOD << endl;
}


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

using LL = long long;
using LD = long double;
 
LL mod = 1e9+7;

int main()
{
	LL a, b, c, d;
	cin >> a >> b >> c >> d;

	LL mx = max(a, b);
	LL tt = c/b + (c%b ? 1 : 0);
	LL ta = a/d + (a%d ? 1 : 0);

	if (tt <= ta) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}



Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;
const ll MOD = 998244353;


int main() {
    int n; cin >> n;
    vector<ll> d(n);
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
        if(d[0] != 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    sort(d.begin(), d.end());
    vector<ll> e;
    ll now = 1, cnt=0ll;
    for (int i = 1; i < n; i++)
    {
        if(d[i] == 0) {
            cout << 0 << endl;
            return 0;
        }

        if(d[i] == now) {
            cnt++;
        } else {
            if (d[i] == now+1) {
                e.push_back(cnt);
                cnt = 1;
                now=d[i];
            } else {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    e.push_back(cnt);

    ll ans = 1;
    for (int i = 1; i < (int)e.size(); i++)
    {
        for(int j = 0; j < e[i]; j++) {
            ans = (ans*e[i-1])%MOD;
        }
    }
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 2168
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    DMenagerie solver = new DMenagerie();
    solver.solve(1, in, out);
    out.close();
  }

  static class DMenagerie {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      String det = in.next();
      char[] ss = new char[n];
      char[] sw = new char[n];
      char[] ws = new char[n];
      char[] ww = new char[n];
      ss[0] = 'S';
      ss[1] = 'S';
      sw[0] = 'S';
      sw[1] = 'W';
      ws[0] = 'W';
      ws[1] = 'S';
      ww[0] = 'W';
      ww[1] = 'W';
      for (int i = 2; i < n; i++) {
        ss[i] = (det.charAt(i - 1) == 'o' ^ ss[i - 1] == 'S' ^ ss[i - 2] == 'S') ? 'S' : 'W';
        sw[i] = (det.charAt(i - 1) == 'o' ^ sw[i - 1] == 'S' ^ sw[i - 2] == 'S') ? 'S' : 'W';
        ws[i] = (det.charAt(i - 1) == 'o' ^ ws[i - 1] == 'S' ^ ws[i - 2] == 'S') ? 'S' : 'W';
        ww[i] = (det.charAt(i - 1) == 'o' ^ ww[i - 1] == 'S' ^ ww[i - 2] == 'S') ? 'S' : 'W';
      }

    /*
    out.println(ss);
    out.println(sw);
    out.println(ws);
    out.println(ww);

     */

      if (!(ss[0] == 'S' ^ ss[1] == 'S' ^ ss[n - 1] == 'S' ^ det.charAt(0) == 'o') &&
          !(ss[0] == 'S' ^ ss[n - 2] == 'S' ^ ss[n - 1] == 'S' ^ det.charAt(n - 1) == 'o')) {
        for (int i = 0; i < n; i++) {
          out.print(ss[i]);
        }
        out.println();
        return;
      }
      if (!(sw[0] == 'S' ^ sw[1] == 'S' ^ sw[n - 1] == 'S' ^ det.charAt(0) == 'o') &&
          !(sw[0] == 'S' ^ sw[n - 2] == 'S' ^ sw[n - 1] == 'S' ^ det.charAt(n - 1) == 'o')) {
        for (int i = 0; i < n; i++) {
          out.print(sw[i]);
        }
        out.println();
        return;
      }
      if (!(ws[0] == 'S' ^ ws[1] == 'S' ^ ws[n - 1] == 'S' ^ det.charAt(0) == 'o') &&
          !(ws[0] == 'S' ^ ws[n - 2] == 'S' ^ ws[n - 1] == 'S' ^ det.charAt(n - 1) == 'o')) {
        for (int i = 0; i < n; i++) {
          out.print(ws[i]);
        }
        out.println();
        return;
      }
      if (!(ww[0] == 'S' ^ ww[1] == 'S' ^ ww[n - 1] == 'S' ^ det.charAt(0) == 'o') &&
          !(ww[0] == 'S' ^ ww[n - 2] == 'S' ^ ww[n - 1] == 'S' ^ det.charAt(n - 1) == 'o')) {
        for (int i = 0; i < n; i++) {
          out.print(ww[i]);
        }
        out.println();
        return;
      }
      out.println("-1");
    }

  }
}



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


int main(void){
  int n,k,i,j,a[103],dp[100005]={};
  
  cin >> n >> k;
  for (i=0;i<n;i++) cin >> a[i];
  
  dp[0]=0;
  for (i=1;i<=k;i++){
    bool u[105]={false};
    j=0;
    while (j<n && a[j]<=i){
      u[dp[i-a[j]]]=true;
      j++;
    }
    j=0;
    while (u[j]) j++;
    dp[i]=j;
  }
  
  if (dp[k]>0) cout << "First" << endl;
  else cout << "Second" << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int a,b;
	cin>>a>>b;
	for(int i=9;i<=16;i++){
		if(a==i||b==i){
			cout<<":("<<endl;
			return 0;
		}
	}
	cout<<"Yay!"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int main() {
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	string str;
	cin >> str;
	int ans = 0;
	for (int i = 0; i < 6; i++) if (str[i] == '1') ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  char a, b;

  unused = scanf("%c %c", &a, &b);
  if(a=='H' && b=='H') printf("H");
  else if(a=='D' && b=='H') printf("D");
  else if(a=='H' && b=='D') printf("D");
  else if(a=='D' && b=='D') printf("H");

  return 0;
}

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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 3e5 + 10;
const int M = (int) 2018 * 2018;
const int K = (int) 15;
const int INF = (int) 1e9 + 7;
const int mod = (int) 998244353;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e18;

int n;
int a[N];
int b[N];
multiset<int> A, B;
map<int, vec> v;
map<int, int> u;
vec o;

void dfs(int x, int b) {
	u[x] = 1;
	for (auto it : v[x]) {
		if (!u[it]) dfs(it, b);
	}
	if (b) {
		o.pb(x);
	}
}

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[n + 1] ^= a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
		b[n + 1] ^= b[i];
	}
	for (int i = 1; i <= n + 1; i++) {
		A.insert(a[i]);
		B.insert(b[i]);
	}
	if (A != B) {
		cout << -1;
		return 0;
	}
	/*
	for (int i = 1; i <= n + 1; i++) {
		cout << a[i] << " \n"[i == n + 1];
	}
	for (int i = 1; i <= n + 1; i++) {
		cout << b[i] << " \n"[i == n + 1];
	}
	*/
	int e = 0, c = 0;
	set<int> pt;
	pt.insert(a[n + 1]);
	pt.insert(b[n + 1]);
	for (int i = 1; i <= n; i++) {
		if (a[i] != b[i]) {
			pt.insert(a[i]);
			pt.insert(b[i]);
			e++;
			v[a[i]].pb(b[i]);
		}		
	}
	for (auto it : pt) {
		if (!u[it]) {
			dfs(it, 1);
		}
	}
	u.clear();
	reverse(all(o));
	for (auto it : o) {
		if (!u[it]) {
			dfs(it, 0);
			c++;
		}
	}
	
	//cout << e <<' ' << c << endl;
	cout << e + c - 1;
	return 0;	
}

Measured memory_bytes: 40700
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int main(void){
    int m,n;
    while(1){
        cin>>m>>n;
        int t=0,h=0;
        if(m==0&&n==0)break;
        int taro[m],hana[n];
        for(int i=0;i<m;i++){
            cin>>taro[i];
            t+=taro[i];
        }
        for(int s=0;s<n;s++){
            cin>>hana[s];
            h+=hana[s];
        }
        sort(taro,taro+m);
        sort(hana,hana+n);
        
        bool frg=0;
        for(int i=0;i<m;i++){
            for(int s=0;s<n;s++){
                int t2=t-taro[i]+hana[s];
                int h2=h-hana[s]+taro[i];
                if(t2-h2==0&&frg==0){
                    frg=1;
                    cout<<taro[i]<<" "<<hana[s]<<endl;
                    break;
                }
            }
            if(frg==1)break;
        }
        if(frg==0)cout<<"-1"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<map>
#include<string>
using namespace std;

map<string,int> M;
int main(){
	int N=0,L=0;
	string word,fre,lon;
	while(cin>>word){
		M[word]+=1;
		if(M[word]>N){
			N=M[word];
			fre=word;
		}
		if(word.size()>L){
			L=word.size();
			lon=word;
		}
	}
	cout<<fre<<" "<<lon<<endl;
}

Measured memory_bytes: 1196
package main

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

var (
	BufferSize = 10 * 10 * 10 * 10 * 10 * 10 * 10
)

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}

	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}

	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	a := scanInt(sc)
	b := scanInt(sc)
	c := 0
	min := 0

	if a > b {
		c = a - b
		min = b
	} else {
		c = b - a
		min = a
	}

	if c%2 != 0 {
		fmt.Printf("IMPOSSIBLE\n")
		return
	}

	fmt.Printf("%d\n", c/2+min)
}


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

using namespace std;

int main(){

	int N,K,hi,menor;
	vector <int> H;
	cin>>N>>K;
	for(int i=0; i<N; i++){
		cin>>hi;
		H.push_back(hi);	
	}
	sort(H.begin(),H.end());
	for(int i=0;i<N-K+1;i++){
		if(i==0) menor = H[i+K-1]-H[i];
		else if(H[i+K-1]-H[i]<menor) menor = H[i+K-1]-H[i];	
	}
	cout<<menor;
return 0;
}

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

ll n;
vector<vector<ll> > adj(50, vector<ll>(50, -1ll));
vector<vector<ll> > paths(50, vector<ll>(50, 0ll));

ll pop_count(ll b) {
	ll cnt = 0;
	for (ll i = 0; i < 50; ++i) if ((b>>i)&1ll) cnt++;
	return cnt;
}

void dfs(ll x, ll p, ll bit) {
	for (ll v = 0; v < 50; ++v)
	{
		ll j = adj[x][v];
		if (j < 0) continue;
		if (v == p || paths[p][v] != 0) continue;
		paths[p][v] = bit + (1ll<<j);
		dfs(v, p, bit + (1ll<<j));
	}
	return;
}

int main() {
	cin >> n;
	for (ll i = 0; i < n-1; ++i)
	{
		ll a, b; cin >> a >> b;
		adj[a-1][b-1] = i;
		adj[b-1][a-1] = i;
	}
	for (ll i = 0; i < n; ++i) dfs(i, i, 0ll);

	ll m; cin >> m;
	vector<ll> cons(m);
	for (ll i = 0; i < m; ++i)
	{
		ll u, v;
		cin >> u >> v;
		cons[i] = paths[u-1][v-1]; 
	}
	vector<ll> uses(1ll<<m, 0);

	ll ans = (1ll<<(n-1ll));
	for (ll b = 1; b < (1ll<<m); ++b)
	{
		bool pop = pop_count(b)%2;
		ll cur = 0ll;
		while (((1ll<<cur) & b) == 0) cur++;
		ll use = uses[b - (1ll<<cur)] | cons[cur];
		uses[b] = use;
		if (pop) ans -= 1ll << (n - 1ll - pop_count(use));
		else ans += 1ll << (n - 1ll - pop_count(use));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8448
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

int main() {
  char buf[32];
  scanf("%s", buf);
  std::string S=buf;

  if (S.length() == 26) {
    if (S == "zyxwvutsrqponmlkjihgfedcba")
      return !printf("-1\n");

    std::set<char> seen;
    for (size_t i=26; i--;) {
      for (char ch: seen) {
        if (S[i] < ch) {
          return !printf("%s%c\n", S.substr(0, i).c_str(), ch);
        }
      }
      seen.insert(S[i]);
    }
  }

  int alpha[26]={};
  for (size_t i=0; i<S.length(); ++i) {
    ++alpha[S[i]-'a'];
  }

  printf("%s", buf);
  for (size_t i=0; i<26; ++i)
    if (alpha[i] == 0)
      return !printf("%c\n", 'a'+i);
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scanf("%d", &n)
	fmt.Scanf("%d", &k)

	p := make([]int, n)
	for i := 0; i < len(p); i++ {
		fmt.Scanf("%d", &p[i])
	}
	sort.Ints(p)

	var ans int
	for i := 0; i < k; i++ {
		ans = ans + p[i]
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1888
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int A,B,C,D;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	if((A+B)>(C+D)) printf("Left\n");
	else if((A+B)==(C+D)) printf("Balanced\n");
	else printf("Right\n");
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const ll Inf = 1e18;
const double EPS = 1e-9;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, c;
    cin >> n >> c;
    vector<vector<int> > d(c, vector<int>(c)), cnt(3, vector<int>(c));
    rep (i, c) rep (j, c) cin >> d[i][j];
    rep (i, n) {
        rep (j, n) {
            int x;
            cin >> x;
            --x;
            ++cnt[(i + j) % 3][x];
        }
    }
    ll res = Inf;  
    rep (i, c) {
        rep (j, c) {
            if (i == j) continue;
            rep (k, c) {
                if (i == k || j == k) continue;
                ll tmp = 0;
                rep (l, c) {
                    tmp += cnt[0][l] * d[l][i];
                    tmp += cnt[1][l] * d[l][j];
                    tmp += cnt[2][l] * d[l][k];
                }
                res = min(res, tmp);
            }
        }
    }
    cout << res << endl;
    
    return 0;
}



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

int main() {
  vector<long> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(),a.end());
  if((a[0]==5&&a[1]==5)&&a[2]==7) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int len[10],pos[10],a[10],f[305][305][64],n,fac=1,c;
void upd(int&x,int y){x=x+y;}
int ksm(int x,int k){return k?x*ksm(x,k-1):1;}
int main(){
    double sum=0;
    cin>>n>>c;
    for(int i=1;i<=n;i++)
        cin>>len[i];
    for(int i=1;i<n;i++)
        a[i]=i,fac=fac*i;
    sort(len+1,len+n+1);
    do{
        memset(f,0,sizeof(f));
        for(int i=1;i<n;i++)pos[a[i]]=i;
        f[0][len[n]*n-1][1<<(n-1)]=1;
        for(int i=1;i<=n*c;i++){
            for(int j=i;j<=n*c;j++){
                for(int k=1<<(n-1);k<1<<n;k=(k+1)|(1<<(n-1))){
                    if(!f[i-1][j][k])continue;
                    int l=pos[i%n];
                    upd(f[i][j][k],f[i-1][j][k]);
                    if(!l||k>>(l-1)&1)continue;
                    upd(f[i][min(n*c,max(j,i+len[l]*n-1))][k|(1<<(l-1))],f[i-1][j][k]);
                }
            }
        }
        int ans=f[n*c][n*c][(1<<n)-1],all=ksm(c,n-1);
        sum+=1.0*ans/all/fac;
    }while(next_permutation(a+1,a+n));
    cout<<fixed<<setprecision(12)<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int gcd(int x, int y){
    return y>0 ? gcd(y, x%y) : x;
}
int lcm(int x, int y){
    return x / gcd(x,y) * y;
}

int main(){
    int K;
    cin >> K;
    int i=0;
    ll n;
    queue<ll> q;

    rep(x,9){
        q.push(x+1);
    }
    while(true){
        i++;
        n=q.front();
        if (i==K){
            cout << n << endl;
            break;
        }
        q.pop();
        if (n%10 != 0){
            q.push(n*10 + n%10 - 1);
        }
        q.push(n*10+ n%10);
        if (n % 10 != 9){
            q.push(n*10 + n%10 + 1);
        }
    }
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var a = cin.nextInt();
            var b = cin.nextInt();
            var h = cin.nextInt();
            Console.WriteLine(((a+b)*h)/2);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


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

int main(){

  char ans;
  char b;

  cin >> b;

  if(b=='A'){
    ans = 'T';
  }
  if(b=='T'){
    ans = 'A';
  }
  if(b=='C'){
    ans = 'G';
  }
  if(b=='G'){
    ans = 'C';
  }

  cout << ans << endl;
  return 0;
}

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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s;
    cin>>s;
    cout<<s[0]<<s[1]<<s[2];
    return 0;
}


Measured memory_bytes: 3600
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    ll X, Y, Z, tmp;

    cin >> X >> Y >> Z;

    tmp = X;
    X = Y;
    Y = tmp;

    tmp = X;
    X = Z;
    Z = tmp;

    cout << X << " " << Y << " " <<Z;

}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
vector<int> out[100100];
int main()
{
	int n,m,t=1;
	cin>>n;
	m=(int)(sqrt(2.0*n));
	if(m*(m+1)/2!=n){
		cout<<"No"<<endl;return 0;
	}
	rep(i,m+1) REP(j,i+1,m+1){
		out[i].pb(t);out[j].pb(t);t++;
	}
	cout<<"Yes"<<endl;
	cout<<m+1<<endl;
	rep(i,m+1){
		cout<<m;
		rep(j,m) cout<<' '<<out[i][j];
		cout<<endl;
	}
}


Measured memory_bytes: 4736
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int n;
long long tmp;
bool kk[32];
bool aa[100005][32];
long long b[100005];

long long solve(int t){
	if(kk[t] == false) return 0;
	long long tt=0;
	for(int i=0;i<n;i++){
		bool add = true;
		for(int j=31;j>t;j--){
			if(!kk[j] && aa[i][j]){
				add = false;
				break;
			}
		}
		if(aa[i][t]) add = false;
		if(add) tt += b[i];
	}
	return tt;
}

int main(){
	cin>>n>>tmp;
	for(int i=0;i<32;i++){
		if(tmp%2) kk[i] = true;
		else kk[i] = false;
		tmp/=2;
	}

	for(int i=0;i<n;i++){
		cin>>tmp>>b[i];
		for(int j=0;j<32;j++){
			if(tmp%2) aa[i][j] = true;
			else aa[i][j] = false;
			tmp/=2;
		}
	}
	long long ans = 0;
	for(int i=31;i>=0;i--){
		ans = max(ans, solve(i));
	}

	long long tt=0;
	for(int i=0;i<n;i++){
		bool add = true;
		for(int j=31;j>=0;j--){
			if(!kk[j] && aa[i][j]){
				add = false;
				break;
			}
		}
		if(add) tt += b[i];
	}
	ans = max(ans,tt);
	cout<<ans<<endl;
	return 0;

}


Measured memory_bytes: 4224
def main():
    d, g = map(int, input().split())
    probs = []
    ans = 0
    for i in range(d):
        p, c = map(int, input().split())
        probs.append(((i + 1) * 100, p, c))
        ans += p

    for mask in range(1 << d):
        solved = 0
        my_score = 0
        for i in range(d):
            score, occ, bonus = probs[i]
            if (mask & (1 << i)) > 0:
                solved += occ
                my_score += score * occ + bonus

        for x in range(d - 1, -1, -1):
            if my_score >= g:
                break
            if (mask & (1 << x)) > 0:
                continue
            score, occ, bonus = probs[x]
            for _ in range(occ):
                solved += 1
                my_score += score
                if my_score >= g:
                    break
        if my_score >= g:
            ans = min(ans, solved)

    print(ans)

main()


Measured memory_bytes: 3064
import java.util.*; 
import java.io.*;

//brute force
public class Main  {
    static StringTokenizer st;
    static BufferedReader br;  
    static PrintWriter out;
 
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        
        int N = nextInt();
        
        int[] List = new int[N+1];
        for (int i=1; i<=N; i++) {
            List[i] = nextInt(); 
        }

        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++) {
                    count += GetCount(List[i],List[j],List[k]);
                }
            }   
        }

        System.out.println(count);
    }
    
    public static int GetCount(int i, int j, int k)  {
        if(i==j || j==k || k==i){
            return 0;
        }

        if(i+j<=k || j+k<=i || k+i<=j){
            return 0;
        }

        return 1;
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}


Measured memory_bytes: 33132
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>

using namespace std;
int a,b;
stack<int> s;

bool que(int fr,int tar){
	if(fr==tar) return 1;
	cout<<"? "<<fr<<" "<<tar<<endl;
	string x; cin>>x;
	return x[0]=='y'||x[0]=='Y';
}

int main(){
	cin>>a>>b;
	if(a<=b) return puts("Impossible"),0;
	for(int t=0;t<a+b;++t)
		if(s.empty()) s.push(t);
		else 
			if(que(s.top(),t)) s.push(t);
			else s.pop();
	string x="! ";
	for(int t=0;t<a+b;++t)
		x=x+(que(s.top(),t)?"1":"0");
	cout<<x<<endl;
	return 0;//asddasadsdas
}



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

int main()
{
    int r;
    cin >> r;
    if(r<1200){
        cout << "ABC" << "\n";
    }else if(r<2800){
        cout << "ARC" << "\n";
    }else{
        cout << "AGC" << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
arr = [[] for _ in range (n+1)]
for i in range(m):
    a,b = map(int,input().split())
    arr[a].append(b)
    arr[b].append(a)

memo = {1:[0,None]}
for room in arr[1]:
    memo[room] = [1,1]

possible = True 
if len(memo.keys())<2:
    possible = False

visit = arr[1]
while len(visit) > 0:
    index = visit.pop(0)
    for item in arr[index]:
        if item not in memo.keys():
            distance = memo[index][0]
            memo[item] = [distance+1,index]
            visit.append(item)

if possible and len(memo.keys())==n:
    print("Yes")
    memo.pop(1)
    for item in sorted(memo.keys()):
        print(memo[item][1])

Measured memory_bytes: 47448
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for(int i = 1; i <= N; ++i) {
			if(i % 3 == 0) {
				System.out.print(" " + i);
			}
			else {
				boolean ok = false;
				int x = i;
				while(x > 0) {
					if(x % 10 == 3) {
						ok = true;
					}
					x /= 10;
				}
				if(ok) {
					System.out.print(" " + i);
				}
			}
		}
		System.out.println();
	}
}


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

using namespace std;

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

    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << ' ' << b << ' ' << c << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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 T>
using pq=priority_queue<T,vector<T>,greater<T>>;

string S;
ll w;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> S;
    cin >> w;
    solve();
}

// string S, ll w
void solve(){
    rep(i,S.size()){
        if(i%w==0)cout<<S[i];
    }
    cout<<endl;
}


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

#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,l;
	while(cin >> n >> l){
		int r = l+n-1;
		int mi = 1e9;
		int sum = 0;
		for(int i = l ; i <= r ; i++){
			if(abs(i)<abs(mi)){
				mi = i;
			}
			sum += i;
		}
		cout << sum - mi << endl;
	}
}

Measured memory_bytes: 256
// attack survival
#include <stdio.h>
#define MAX_LEN 100000
using namespace std;

int main() {
    int N; // #participants
    int K; // max points
    int Q; // #correct answers
    int ncorrect[MAX_LEN] = {0};
    int min_points;

    scanf("%d %d %d", &N, &K, &Q);
    min_points = K - Q;

    for (int i=0; i < Q; i++) {
        int cor;
        scanf("%d", &cor);
        ncorrect[cor-1]++;
    }   

    for (int i = 0; i < N; i++) {
        if (min_points + ncorrect[i] <= 0) {
            printf("No\n");
        } else {
            printf("Yes\n");
        }
    }   
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin >> n >> k;
	int m,min=100000;
	for(int i=0;i<n;++i){
		cin >> m;
		k-=m;
		if(m<min)min=m;
	}
	cout << n+k/min << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

S=[]
for si in input().split():
    S.append(si[0])
for i in range(3):
    S[i]=S[i].upper()
print(*S,sep="")

Measured memory_bytes: 38256
from collections import deque
# from fractions import gcd # >=Python3.5
# from math import gcd # <Python3.5

n  = int(input())
li = [list(map(int,input().split())) for i in range(n-1)]

road = [[] for i in range(n)]
cost = [[] for i in range(n)]

for i in li:
  i[0]-=1
  i[1]-=1
  road[i[0]].append(i[1])
  road[i[1]].append(i[0])
  cost[i[0]].append(i[2]%2)
  cost[i[1]].append(i[2]%2)

dist = [-1]*n
que  = deque()
dist[0] = 0
que.append(0)

while(len(que)!=0):
  # BFS/DFS
  v = que.popleft()
  for i,r in enumerate(road[v]):
    if dist[r]!=-1:
      continue
    dist[r] = (dist[v]+cost[v][i])%2
    que.append(r)

print(*dist,sep='\n')

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

int main()
{
	int a[4];
	int b[4];
	while (cin >> a[0])
	{
		int hit = 0;
		int blow = 0;
		for (int i = 1; i < 4; i++)cin >> a[i];
		for (int i = 0; i < 4; i++)cin >> b[i];
		for (int i = 0; i < 4; i++)
		{
			for (int j = 0; j < 4; j++)
			{
				if (i == j && a[i] == b[j])hit++;
				else if (a[i] == b[j])blow++;
			}
		}
		cout << hit << " " << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n, m; cin >> n >> m;
    int a[200001]; INITA(a, 0, 200000, 0);
    int b[200001]; INITA(b, 0, 200000, 0);
    set<int> st;
    REP(i, m) {
        cin >> a[i] >> b[i];
        if (a[i] == 1) {
            st.insert(b[i]);
        }
        if (b[i] == 1) {
            st.insert(a[i]);
        }
    }
    REP(i, m) {
        if ((st.find(a[i]) != st.end()) && (b[i] == n)) {
            cout << "POSSIBLE" << endl;
            return 0;
        } else if ((st.find(b[i]) != st.end()) && (a[i] == n)) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 9812
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
int modpow(int X,int Y){
  int sum=X,cnt=1;
  vi A;
  while(cnt<=Y){
    A.pb(sum);
    sum*=sum;
    sum%=MOD;
    cnt*=2;
  }
  int M=A.size();
  int ret=1;
  REP(i,1,M){
    if(Y>=(1ll<<M-i)){
      Y-=(1ll<<M-i);
      ret*=A[M-i];
      ret%=MOD;
    }
  }
  return ret;
}
int fac[500000],finv[500000];
void COMinit(){
  fac[0]=fac[1]=finv[1]=finv[0]=1;
  rep(i,2,500000){
    fac[i]=fac[i-1]*i%MOD;
    finv[i]=finv[i-1]*modpow(i,MOD-2)%MOD;
  }
}
int COM(int n,int k){
  if(n<k||n<0||k<0) return 0;
  return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}
signed main(){
  COMinit();
  int N,M,K; cin>>N>>M>>K;
  int ans=0;
  rep(i,1,N){
    ans+=i*(N-i)%MOD*M%MOD*M%MOD*COM(N*M-2,K-2)%MOD;
    ans%=MOD;
  }
  rep(i,1,M){
    ans+=i*(M-i)%MOD*N%MOD*N%MOD*COM(N*M-2,K-2)%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

//素因数分解O(root n)
vector<PII> prime_factor(ll n){
  vector<PII> v;
  for(int i=2; i<=sqrt(n); i++){
    int num=0;
    while(n%i==0){
      num++;
      n/=i;
    }
    if(num!=0) v.push_back(PII(i,num));
  }
  if(n!=1) v.push_back(PII(n,1));
  return v;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll N;cin >> N;
  vector<PII> prime = prime_factor(N);
  int num = 0;
  for(PII p : prime){
    int n = 0;
    while(++n){
      if(n > p.second) break;
      ++num;
      p.second -= n;
    }
  }
  cout << num << endl;
  return 0;
}


Measured memory_bytes: 3672
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define pii pair<int,int>
#define fr(i, a, b) for(int i = a; i < b; i++)
#define frb(i, a, b) for(int i = a; i > b; i--)
#define sz(s) (int)s.size()
#define all(v) (v).begin(), (v).end()
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
#define iset tree < int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define oset tree < pair<int, int> ,  null_type ,  less<pair<int, int> > ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define ll long long
using namespace std; 
using namespace __gnu_pbds; 


int  prg()
{
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    fr(i,0,n)
    cin>>a[i]>>b[i];
    srt(a);
    srt(b);
    if(n%2==1)
    cout<<b[n/2]-a[n/2]+1;
    else
    {
        cout<<b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1;
    }
    return 0;    
}
void multi()
{
    int t;
    cin>>t;
    for(int i=0;i<t;++i)
    {
       prg();
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    prg();
    return 0;
}

Measured memory_bytes: 4768
// Vicfred
// https://atcoder.jp/contests/abc177/tasks/abc177_c
// math
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    const long mod = 10^^9+7;
    long n = readln.chomp.to!long;
    long[] a = readln.split.map!(to!long).array;

    long sum = 0;
    for(long i = 0; i < n; i++) {
        sum += a[i];
        sum %= mod;
    }


    long ans = 0;
    for(int i = 0; i < n; i++) {
        sum -= a[i];
        if(sum < 0) sum += mod;

        ans += a[i] * sum;
        ans %= mod;
    }

    ans.writeln;
}



Measured memory_bytes: 11700
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define EPS 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f3f3f3f3f
#define MEM(a, b) memset(a, b, sizeof(a))
#define PPER(i, n, m) for (int i = n; i >= m; i--)
#define REPP(i, n, m) for (int i = n; i <= m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define PER(i, n, m) for (int i = n; i > m; i--)
#define SA(n) scanf("%d", &(n))
#define SLLA(n) scanf("%lld", &(n))
#define MP make_pair
#define FF first
#define SS second
#define PB push_back
#define DE(val) cout << #val << ": " << val << endl;

const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 1, 0,-1};
const int dy4[6] = {-1, 0, 1,0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};
void update(ll& x,ll v){
    if(x==-1)x=v;
    else if(x>v)x=v;
}

ll po(ll a, ll b, ll mod)
{
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}
void extgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
    if (!b)
    {
        d = a;
        x = 1;
    }
    else
    {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
ll inverse(ll a, ll n)
{
    ll d, x, y;
    extgcd(a, n, d, x, y);
    return d == 1 ? (x + n) % n : -1;
}
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const int maxn = 3e3 + 5;
const double PI = acos(-1.0);
const ll mod = 1000000007;
/*************************************************************************/

ll n,a,b;
void solve() {
    cin>>n>>a>>b;
    ll ans = n/(a+b)*a;
    ans += min(n%(a+b),a);
    cout<<ans<<endl;
}

int main()
{

  solve();
  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 pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }

int n;

void dfs(string s, char mx){
  if(sz(s)==n){
    cout << s << endl;
    return;
  }
  for(char c='a'; c<=mx+1; c++){
    string t=s;
    t+=c;
    dfs(t,max(mx,c));
  }
}

int main(int argc, char const *argv[]) {
  cin >> n;
  dfs("",'a'-1);
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

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;
}

ll max3(ll a, ll b, ll c){
    if(a > b){
        if(b > c) return a;
        else{
            if(a > c) return a;
            else return c;
        }
    }else{
        if(b > c) return b;
        else return c;
    }
}

int main(){
    string s,t; cin >> s >> t;
    ll S = s.size();
    ll T = t.size();
    vvl dp(S+1, vl(T+1,0));
    string ans = "";
    ll tmp = 0;
    rep(i,S){
        rep(j,T){
            tmp = 0;
            if(s[i] == t[j]) tmp = 1;
            dp[i+1][j+1] = max3(dp[i][j]+tmp, dp[i+1][j], dp[i][j+1]);
        }
    }
    //cout << dp[S][T] << endl;
    
    ll i = S; ll j = T;
    while(i > 0 && j > 0){
        if(dp[i][j] == dp[i-1][j]){
            i--;
        }else if(dp[i][j] == dp[i][j-1]){
            j--;
        }else{
            ans = ans + s[i-1];
            i--; j--;
        }
    }
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 70784
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static int n;
    static int[,] A;

    static void Main()
    {
        n = int.Parse(Console.ReadLine());
        A = new int[n, n];
        for (int i = 0; i < n; i++)
        {
            string[] inputs = Console.ReadLine().Trim().Split(' ');
            for (int j = 0; j < n; j++)
            {
                A[i, j] = inputs[j] == "-1" ? int.MaxValue : int.Parse(inputs[j]);
            }
        }

        Prim();
        Console.WriteLine(TotalWeight());
    }

    static int[] parent;
    static void Prim()
    {
        int[] weight = Enumerable.Repeat(int.MaxValue, n).ToArray();
        weight[0] = 0;
        bool[] isFinal = new bool[n];
        parent = Enumerable.Repeat(-1, n).ToArray();
        while (true)
        {
            int u = -1;
            int minv = int.MaxValue;
            for (int i = 0; i < n; i++)
            {
                if(minv > weight[i] && !isFinal[i])
                {
                    u = i;
                    minv = weight[i];
                }
            }
            if(u == -1) break;
            isFinal[u] = true;
            for (int i = 0; i < n; i++)
            {
                if(!isFinal[i] && weight[i] > A[u, i])
                {
                    weight[i] = A[u, i];
                    parent[i] = u;
                }
            }
        }
    }
    static int TotalWeight()
    {
        int sum = 0;
        for (int i = 0; i < n; i++)
        {
            if(parent[i] != -1) sum += A[parent[i], i];
        }
        return sum;
    }
}

Measured memory_bytes: 9616