akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int>>> prefecture(n + 1, vector<pair<int, int>>(0));
    vector<pair<int, int>> res(m + 1);
    int p, y;
    rep(i, m) {
        cin >> p >> y;
        prefecture[p].push_back(make_pair(y, i + 1));
    }
    repk(i, 1, n + 1) sort(prefecture[i].begin(), prefecture[i].end());
    repk(i, 1, n + 1) {
        for (int j = 0; j < prefecture[i].size(); j++) {
            res[prefecture[i][j].second] = make_pair(i, j + 1);
        }
    }
    repk(i, 1, m + 1) {
        cout << setfill('0') << right << setw(6) << res[i].first;
        cout << setfill('0') << right << setw(6) << res[i].second << endl;
    }
}

Measured memory_bytes: 9488
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a, b, c; cin >> a >> b >> c;
	if (c == 1) {
		cout << "Open" << endl;
	}
	else if (a == 1 && b == 1) {
		cout << "Open" << endl;
	}
	else {
		cout << "Close" << endl;
	}
	cin >> n;
}


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

#define pb push_back
#define PQ priority_queue
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

typedef long long ll;
typedef long double ld;

//__builtin_popcount(x)

using namespace std;

const int mod = 1e9 + 7;

ll add(ll a, ll b) {
    ll res = a + b;
    if (res >= mod) res -= mod;
    return res;
}

ll sub(ll a, ll b) {
    ll res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
}

ll mul(ll a, ll b) {
    return (((a % mod) * (b % mod)) % mod);
}

/* Z-FUNCTION
ll l = 0, r = 0, n = (int)s.size();
vector<int> z(n, 0);
for (int i = 1; i < n; i++) {
    if (r >= i) {
        z[i] = min(1ll*z[i-l], r-i+1);
    }
    while (z[i] + i < n && s[z[i]] == s[z[i] + i]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
}
*/

/*vector<int> find_dividers(int x) {
    vector<int> dividers;

    for (int i = 1; i <= sqrt(x); i++) {
        if (x % i == 0) {
           dividers.push_back(i);
            if (i * i != x) {
                dividers.push_back(x / i);
            }
        }
    }

    return dividers;
}*/

/*int nok(int a, int b) {
    return a / __gcd(a, b) * b;
}*/

int n, m;
vector<vector<int>> g;
vector<int> dp;

int dfs(int u) {
    if (dp[u] != -1) return dp[u];
    int len = 0;
    for (int i = 0; i < (int)g[u].size(); i++) {
        int to = g[u][i];
        len = max(len, dfs(to));
    }

    dp[u] = 1+len;
    return dp[u];
}

void solve() {
    cin >> n >> m;
    g.resize(n+1);
    dp.resize(n+1, -1);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
    }

    int ans = -1;
    for (int i = 1; i <= n; i++) {
        int x = dfs(i);
        ans = max(ans, x);
    }

    /*for (int i = 1; i <= n; i++) {
        cout << dp[i] << ' ';
    }
    cout << endl;*/

    cout << ans-1 << endl;
}

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

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 11092
from operator import mul
from functools import reduce

def ncr(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

a = int(input())
A = list(map(int, input().split()))  
d = {}
for k in A:
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
 
res = 0
for k in d:
    if d[k] >= 2:
      res += ncr(d[k], 2)

for k in A:
  temp = res
  m = d[k]
  d[k] -= 1
  if m >= 2:
    temp -= ncr(m, 2)

  if d[k] >= 2:
    temp += ncr(d[k], 2)
  print(temp)
  d[k] += 1


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

int gcd(int a, int b){
  if (a%b == 0) return b;
  return gcd(b, a%b);
}

int main() {
  int k; cin >> k;
  ll ans = 0;
  for (int a=1; a<k+1; a++) {
    for (int b=1; b<k+1; b++) {
      int ab = gcd(a, b);
      for (int c=1; c<k+1; c++) {
        ans += gcd(ab, c);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int n,k;
    cin>>n>>k;
    int arr[n+1];
    for(int i=1;i<=n;i++) cin>>arr[i];
    int dp[n+1];
    for(int i=0;i<=n;i++) dp[i] = INT_MAX;
    dp[1] = 0, dp[2] = abs(arr[2] - arr[1]);
    
    for(int i=3;i<=n;i++){
        for(int j=1;i-j>=1 && j<=k;j++){
            dp[i] = min(dp[i],dp[i-j] + abs(arr[i] - arr[i-j]));
        }
    }
    
    cout<<dp[n];
}

Measured memory_bytes: 1024
#include<stdio.h>

int n;
int a[1000010];
int ans[100],len;
int cnt;

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	ans[len++]=1;
	while(ans[len-1]*3+1<n)ans[len]=ans[len-1]*3+1,len++;
	for(int k=len-1;k>=0;k--){
		for(int i=0;i<n;i++){
			int t=a[i];
			int j=i;
			while(j-ans[k]>=0&&a[j-ans[k]]>t){
				a[j]=a[j-ans[k]];
				j-=ans[k];
				cnt++;
			}
			a[j]=t;
		}
	}
	printf("%d\n",len);
	for(int i=len-1;i>=0;i--)printf("%d%c",ans[i],i?32:10);
	printf("%d\n",cnt);
	for(int i=0;i<n;i++)printf("%d\n",a[i]);
}



Measured memory_bytes: 5604
#pragma optimization_level 3
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, Q;
string S[100000];
int C[100000];
int R[100000][26][26];
int p[256];

class Trie {
public:
  Trie *a[26];
  int ctr;
  bool leaf;

  Trie() {
    for (int i=0; i<26; i++) a[i] = NULL;
    leaf = false;
    ctr = 0;
  }
  void insert(const char *s) {
    if (*s == '\0') {
      leaf = true;
      ctr++;
      return;
    }
    int k = *s - 'a';
    if (a[k] == NULL) {
      a[k] = new Trie();
    }
    a[k]->insert(s+1);
    ctr++;
  }

  int find(const char *s, int x) {
    if (*s == '\0') return leaf;
    int c = leaf;
    int k = *s - 'a';
    for (int i=0; i<26; i++) {
      if (a[i] != NULL) {
        R[x][i][k] += a[i]->ctr;
      }
    }
    if (a[k] == NULL) return c;
    c += a[k]->find(s+1, x);
    return c;
  }
};


signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> S[i];
  cin >> Q;

  Trie trie;
  rep(i, N) trie.insert(S[i].c_str());
  rep(i, N) {
    C[i] = trie.find(S[i].c_str(), i);
  }
  rep(i, Q) {
    int k; cin >> k;
    k--;
    rep(i, 26) {
      char c;
      cin >> c;
      p[c - 'a'] = i;
    }
    int s = C[k];
    rep(i, 26) {
      rep(j, 26) {
        if (p[i] < p[j]) s += R[k][i][j];
      }
    }
    cout << s << "\n";
  }
  return 0;
}


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

int main(){
  int N, M;
  scanf("%d%d", &N, &M);
  long H[N];
  int i;
  for(i=0; i<N; i++){
    scanf("%ld", &H[i]);
  }
  vector< set<int> > is_roadLtoR(N);
  
  int A, B;
  for(i=0; i<M; i++){
    scanf("%d%d", &A, &B);
    A--;B--;
    is_roadLtoR.at(A).insert(B);//AからBへ
    is_roadLtoR.at(B).insert(A);//BからAへ
  }
  int isgood;
  int count = 0;
  for(i=0; i<N; i++){
    //iから見て
    isgood=1;
    for(auto to:is_roadLtoR.at(i)){
      if(H[i]<=H[to])isgood=0;
    }
    if(isgood)count++;
    //printf("\n");
  }
  //*/
  printf("%d\n", count);
}

Measured memory_bytes: 18072
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        List<String> a = new ArrayList<>();
        for (int i = 0; i < h; i++) {
            a.add(sc.next());
        }
        List<Boolean> row = new ArrayList<>();
        for (int i = 0; i < h; i++) {
            row.add(false);
        }
        List<Boolean> col = new ArrayList<>();
        for (int i = 0; i < w; i++) {
            col.add(false);
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (a.get(i).charAt(j) == '#') {
                    row.set(i, true);
                    col.set(j, true);
                    continue;
                }
            }
        }
        for (int i = 0; i < h; i++) {
            if (!row.get(i)) {
                continue;
            }
            for (int j = 0; j < w; j++) {
                if (!col.get(j)) {
                    continue;
                }
                System.out.print(a.get(i).charAt(j));
            }
            System.out.println();
        }
    }
}


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

int main() {
    string s;
    string li[] = {"maerd", "remaerd", "esare", "resare"};
    cin >> s;
    string t = "";
    for(int i = s.size()-1; i >= 0; --i) {
        t += s[i];
        for(int j = 0; j < 4; ++j) {
          if(t == li[j]) t = "";
        }
    }
    if(t == "") cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int ,int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int x, a,b ;
	cin >> x >> a >> b;
	if (abs(x-a) < abs(x-b))
		cout << "A\n";
	else
		cout << "B\n";
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

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

void solve(string S) {
    vector<bool> v;
    string::const_iterator itr = S.begin();
    while (itr != S.end()) {
        if (*itr == 'n') {
            v.EB(false);
            itr += 5;
        } else if (*itr == 'w') {
            v.EB(true);
            itr += 4;
        }
    }
    REVERSE(v);
    int cd = 0, mom = 1;
    REP(i, v.size()) {
        if (i == 0) cd += 90 * v[i];
        else {
            int p = pow(2, i);
            if (v[i]) cd = cd * (p / mom) + 90;
            else cd = cd * (p / mom) - 90;
            mom = 1;
            while (cd % 2 == 0 && p) {
                cd >>= 1;
                p >>= 1;
            }
            if (p) mom *= p;
        }
    }
    if (cd != 0 && mom > 1) {
        cout << cd << "/" << mom << endl;
    } else {
        cout << cd << endl;
    }
    return;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> s, s != "#") {
        solve(s);
        //return 0;
    }
}

Measured memory_bytes: 3264
#include <cstdio>
#include <climits>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
using namespace std;
typedef pair<int, int> P;
struct edge { int to, cost; };
vector<edge> G[3000];
int mind[3000];
int d[3000];
int n, m, k;
void dijkstra(int s) {
    fill(d, d+n, INT_MAX);
    d[s]=0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0,s));
    while (!que.empty()) {
        P p=que.top(); que.pop();
        int v=p.second;
        if (d[v]<p.first) continue;
        for (int i=0; i<G[v].size(); i++) {
            edge e=G[v][i];
            if (d[e.to]>d[v]+e.cost) {
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
    for (int i=0; i<n; i++) mind[i]=min(mind[i],d[i]);
}
int main() {
    scanf("%d%d%d",&n,&m,&k);
    fill(mind, mind+n, INT_MAX);
    for (int i=0; i<m; i++) {
        int a, b, l; scanf("%d%d%d",&a,&b,&l);
        G[a-1].push_back((edge){b-1,l});
        G[b-1].push_back((edge){a-1,l});
    }
    for (int i=0; i<k; i++) {
        int s; scanf("%d",&s);
        dijkstra(s-1);
    }
    int res=0;
    for (int i=0; i<n; i++) {
        for (int j=0; j<G[i].size(); j++) {
            edge e=G[i][j];
            res=max(res,(mind[i]+mind[e.to]+e.cost+1)/2);
        }
    }
    printf("%d\n",res);
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;

vector<vector<int>> A, B;
int dfs(int y, int x) {
    if(B[y][x] != 0)
        return B[y][x];
    if(x == 0 && y == 0)
        return A[y][x];
    int tmp1, tmp2;
    tmp1 = (x - 1 < 0 ? 0 : dfs(y, x - 1));
    tmp2 = (y - 1 < 0 ? 0 : dfs(y - 1, x));
    return B[y][x] = max(tmp1, tmp2) + A[y][x];
}

int main() {
    int N;
    cin >> N;
    A.resize(2, vector<int>(N)), B.resize(2, vector<int>(N));
    for(int i = 0; i < 2; ++i)
        for(int j = 0; j < N; ++j)
            cin >> A[i][j];
    cout << dfs(1, N - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n = in();
  int ma = 0;
  int sum = 0;
  rep(i,n) {
    int l;
    cin >> l;
    ma = max(ma, l);
    sum += l;
  }
  if (ma < sum - ma) yn;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
typedef long long ll;
const int maxn = 2e5 + 10;
int n;
int a[maxn];
ll ans;
int main()
{
	scanf("%d", &n); 
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1, greater<int>());
	for(int i = 2; i <= n; ++i)
		ans += a[(i + 1) / 2];
	printf("%lld\n", ans);
	return 0;
}
	
	 

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main(){

    string s,t;
    cin >> s >> t;
    vector<vector<ll>> c(26);
    rep(i,s.size()){
        ll id = s[i] - 'a';
        c[id].push_back(i);
    }
    
    ll ans = 0;
    ll p = -1; // sの何文字目か
    rep(i,t.size()){
        ll id = t[i] - 'a';

        if(c[id].size()==0){
            cout << -1 << endl;
            return 0;
        }

        auto it = upper_bound(c[id].begin(), c[id].end(), p);
        if(it != c[id].end()){
            p = *it;
        }else{
            p = c[id][0];
            ans++;
        }
        // cout << p << endl;

    }

    cout << ans*s.size() + p+1 << endl;


    return 0;
}

Measured memory_bytes: 1724
<?php
fscanf(STDIN,"%d",$n);

function sosu_juge($n) {
  $tmp_n = $n;
  for($i=2;$i*$i<$n;$i++){
    while($tmp_n%$i==0){
      $result[$i]++;
      $tmp_n /= $i;
    } 
  }
  if($tmp_n>1){
	  $result[$tmp_n]++;
  }
  return $result;
}


//print_r(sosu_juge(24));
$soinsu = sosu_juge($n);
$res = 0;
foreach($soinsu as $count){
  $i = 1;
  while($count>=$i){
    $count = $count-$i;
    $i++;
    $res++;
  }
}
    
echo $res;


Measured memory_bytes: 16272
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
 
public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
        int rowCount = inpt[0];

        StringBuilder ans = new StringBuilder();
        for(int i=0; i<rowCount; i++) {
            string text = Reader.ReadLine();
            ans.AppendLine(text);
            ans.AppendLine(text);
        }
        Console.Write(ans.ToString());

    }

    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"

2 2
*.
.*


";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 2904
N,M = map(int, input().split())
import heapq
A = list(map(int, input().split()))
A = [(-x,x) for x in A]
heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)[1]
    heapq.heappush(A, (-int(a/2), int(a/2)))
B = [a[1] for a in A]
print(sum(B))

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

typedef long long ll;

void dfs(ll sum, ll prev, ll node, vector<vector<ll>> &T, vector<ll> &cnt) {
    sum += cnt[node];
    cnt[node] = sum;
    for(ll i = 0; i < T[node].size(); i++) {
        if(T[node][i] != prev) 
            dfs(sum, node, T[node][i], T, cnt);
    }
}

int main() {
    ll N, Q;
    cin >> N >> Q;
    vector<vector<ll>> T(N, vector<ll>());
    vector<ll> cnt(N, 0);
    for(ll i = 0; i < N - 1; i++) {
        ll a, b; cin >> a >> b; a--; b--;
        T[a].push_back(b);
        T[b].push_back(a);
    }

    for(ll i = 0; i < Q; i++) {
        ll p, x; cin >> p >> x; p--;
        cnt[p] += x;
    }

    dfs(0, 0, 0, T, cnt);
    for(ll i = 0; i < cnt.size(); i++) {
        cout << cnt[i] << endl;
    }

    return 0;
}

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

using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    int x = n / 105;
    int y = n / 100;
    if (105 * y >= n && 100 * y <= n || 105 * x >= n && 100 * x <= n) {
        cout << 1 << EOL;
    } else {
        cout << 0 << EOL;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define All(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main() {
  Cin(int, n);
  Cins(int, n, a);

  vector<double> inv(n);
  for (int i = 0; i < n; ++i) inv[i] = 1. / a[i];

  double bunbo = 0;
  for (auto e : inv) bunbo += e;

  cout << 1. / bunbo << endl;
}

int main() {
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>
#include <list>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
//#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
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 main(void)
{
    int K; cin >> K;
    int A, B; cin >> A >> B;
    bool flag = false; 
    rep(i, 1, B / K + 1) {
        if (A <= K * i && K * i <= B) {
            flag = true;
            break;
        }
    }
   
    cout << (flag ? "OK" : "NG") << endl;


    return 0;
}

Measured memory_bytes: 3652
n = int(input())
a = input()
b = input()
c = input()

num_op = 0
for i in range(n):
    if a[i] == b[i] == c[i]:
        continue
    if a[i] != b[i] and a[i] != c[i] and b[i] != c[i]:
        num_op += 2
    elif a[i] == b[i] or a[i] == c[i] or b[i] == c[i]:
        num_op += 1
print(num_op)


Measured memory_bytes: 3064
import Data.List

solve :: Int -> Int -> Int
solve d1 d2
  | even d1 && even d2 = d1 `div` 2 + d2 `div` 2
  | even d1 && odd  d2 = d1 `div` 2 + d2 `div` 2 + 2
  | odd  d1 && even d2 = d1 `div` 2 + d2 `div` 2 + 2
  | odd  d1 && odd  d2 = d1 `div` 2 + d2 `div` 2 + 1

main :: IO ()
main = do
    list <- (map read) . words <$> getLine :: IO [Int]
    let [a, b, c] = reverse $ sort list
    let delta1 = a - b
    let delta2 = a - c
    print $ solve delta1 delta2


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

using namespace std;
int main() {
  vector<int> v;
  int s;
  cin >> s;
  v.push_back(s);
  int i = 0;
  int cnt = 0;
  while (true) {
    int a1 = v.at(i);
    if (a1 == 1) cnt++;
    if (cnt > 2) break;
    int a = 0;
    if (a1 % 2 == 0) {
      a = a1 / 2;
    } else {
      a = 3 * a1 + 1;
    }
    v.push_back(a);
    i++;
  }
  int result = 0;
  bool isBreak = false;
  for (int i = 0; i < v.size(); i++) {
    for (int j = i + 1; j < v.size(); j++) {
      if (v.at(i) == v.at(j)) {
        result = j;
        isBreak = true;
        break;
      }
    }
    if (isBreak) break;
  }
  cout << result + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
import bisect
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
q=[-1 for _ in range(n)]
for i in range(n):
    x=a[i]
    idx = bisect.bisect_left(q,x)
    q[idx-1]=x
print(n-bisect.bisect_right(q,-1))

Measured memory_bytes: 56280
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>
#include <string>
#include <complex>
using namespace std;

#define INT_max 2147483647


typedef long long ll;
typedef long double ld;


int main(){
  int N;
  cin>>N;
  vector<int> num(N,0);
  for(int i = 0;i < N-1;i++){
  	int t;
  	cin>>t;
  	num[t-1]++;
  }
  for(int i = 0;i < N;i++){
  	cout<<num[i]<<endl;
  }
  return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<string, int> mp;
  while (n--) {
    string s;
    cin >> s;
    ++mp[s];
  }
  int mx = 0;
  for (auto e : mp) {
    mx = max(mx, e.second);
  }
  for (auto e : mp) {
    if (e.second == mx) {
      cout << e.first << '\n';
    }
  }
}


Measured memory_bytes: 23808
def main():
    from heapq import heappush, heappop
    import sys
    sys.setrecursionlimit(10 ** 7)
    
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines

    n,q=map(int,readline().split())
    stx = [[int(x) for x in readline().split()] for _ in range(n)]
    event=[]
    stop=set()
    for s,t,x in stx:
        event.append([s-x,1,x])
        event.append([t-x,-1,x])
    for i in range(q):
        event.append([int(input()),2,i])
    event.sort()
    
    ans=[0]*q
    
    stop=set()
    hq=[]
    for t,op,x in event:
        if op==1:
            heappush(hq,x)
            stop.add(x)
        elif op==-1:
            stop.remove(x)
    
        else:
            while hq and hq[0] not in stop:
                heappop(hq) 
            ans[x]=hq[0] if hq else -1
        
    for x in ans:
        print(x)

if __name__ == "__main__":
    main()

Measured memory_bytes: 147932
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
どっかでとる順番が入れ替わるだけかな
累積和
1個とばしの累積和
lower_boundかな
O(NQは無理
xの上に最大何個あるか
そこまで加算
それまで個別判断？
少なくとも/2まではとれるとか

幅をとってから交互
交互ゾーン   青木ゾーン 高橋ゾーン
[1,2,3,4,5],[6,7,8,9],[a,b,c,d]

Xの値でどれを取るか判断するとか

3 5 7 11 13

T 13
X>=10 11
9>=X>=7 7
65 57
X<=5 35

Xでもう解答まで
2分探索かな
その幅にある個数で判断？

*/
int main(){
  ll N,Q; cin>>N>>Q;
  vector<ll> A(N,0), S(N,0), ES(N,0);
  for(ll i=0; i<N; i++) cin>>A[i];
  S=ES=A;
  for(ll i=1; i<N; i++) S[i]+=S[i-1];  
  for(ll i=2; i<N; i+=2) ES[i]+=ES[i-2];//024
  for(ll i=3; i<N; i+=2) ES[i]+=ES[i-2];//135
  while(Q--){
    ll X,low=1, high=(N+1)/2, mid=(low+high)/2, ans=0;//青木ゾーン数
    cin>>X;
    while(low<high){
      ll T=N-1-mid;
      ll t=T-mid;
      if(abs(X-A[t])<=abs(X-A[T])) low=mid+1;
      else high=mid;
      mid=(low+high)/2;
    }
//cout<<"X:"<<X<<" low:"<<low<<endl;    
    ans+=S[N-1]-S[N-1-low];
    ll z=N-low*2-1;
    if(z>=0) ans+=ES[z];
    cout<<ans<<endl;
  }
}

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

int main(){
  int n,r;
  cin >> n;
  string s;
  cin >> s;
  for(int i;i<n;i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
      r++;
    }
  }
  cout << r;
  return 0;
}
     


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
signed main(){
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    sort(a,a+n);
    sort(b,b+n);
    int p=0,q,x=0,y=0,ans=1;
    while(x<n&&y<n){
        if(a[x]<b[y]){
            q=p+1;
            x++;
        }else {
            q=p-1;
            y++;
        }
        if(abs(p)>abs(q))ans=(ans*abs(p))%MOD;
        p=q;
    }
    while(x<n){
        ans=(ans*abs(p))%MOD;
        p++;
        x++;
        
    }
     while(y<n){
         ans=(ans*abs(p))%MOD;
        p--;
        y++;
        
    }
    cout<<ans;



    return 0;
}


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

#define mp make_pair
#define X first
#define Y second
#define FOE(x, a) for(auto x : a)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)

using namespace std;

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

const int N = 2e5 + 10;
const ll INF = 1e18;

struct segmentTree{
    ll d[N * 4], lazy[N * 4];
    void doLazy(int id, int l, int r){
        d[id] += lazy[id];
        if (l < r){
            lazy[id << 1] += lazy[id];
            lazy[id << 1 | 1] += lazy[id];
        }
        lazy[id] = 0;
    }
    void update(int id, int l, int r, int u, int v, ll val){
        doLazy(id, l, r);
        if (v < l || r < u)
            return;
        if (u <= l && r <= v){
            lazy[id] += val;
            doLazy(id, l, r);
            return;
        }
        int mid = (l + r) >> 1;
        update(id << 1, l, mid, u, v, val);
        update(id << 1 | 1, mid + 1, r, u, v, val);
        d[id] = min(d[id << 1], d[id << 1 | 1]);
    }
    ll getMin(int id, int l, int r, int u, int v){
        doLazy(id, l, r);
        if (v < l || r < u)
            return INF;
        if (u <= l && r <= v)
            return d[id];
        int mid = (l + r) >> 1;
        return min(getMin(id << 1, l, mid, u, v), getMin(id << 1 | 1, mid + 1, r, u, v));
    }
} ST[2];

int n, q, a, b;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q >> a >> b;

    FOR(i, 1, n){
        ST[0].update(1, 1, n, i, i, abs(b - i) - i);
        ST[1].update(1, 1, n, i, i, abs(b - i) + i);
    }

    while (q--){
        int x;
        cin >> x;

        ll cur = ST[0].getMin(1, 1, n, a, a) + a;
        ll minVal = min(ST[0].getMin(1, 1, n, 1, x) + x, ST[1].getMin(1, 1, n, x, n) - x);
        minVal = min(minVal, cur + abs(x - a));

        ST[0].update(1, 1, n, a, a, minVal - cur);
        ST[1].update(1, 1, n, a, a, minVal - cur);

        if (a > 1){
            ST[0].update(1, 1, n, 1, a - 1, abs(x - a));
            ST[1].update(1, 1, n, 1, a - 1, abs(x - a));
        }

        if (a < n){
            ST[0].update(1, 1, n, a + 1, n, abs(x - a));
            ST[1].update(1, 1, n, a + 1, n, abs(x - a));
        }
        a = x;
    }

    ll ans = INF;
    FOR(i, 1, n)
        ans = min(ans, ST[0].getMin(1, 1, n, i, i) + i);

    cout << ans;

    return 0;
}


Measured memory_bytes: 20068
#include <stdio.h>

#define freopen(x) freopen(x".in", "r", stdin);freopen(x".out", "w", stdout)
#define abs(a) ((a) < 0 ? -(a) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define isdigit(a) ((a) >= '0' && (a) <= '9' ? true : false)

const int INF = 0x3f3f3f3f;

long long read();

int main() {
	int n = read(), l = read();
	int sum = 0, x = INF;
	for (int i = 1; i <= n; ++i) sum += i + l - 1;
	for (int i = 1; i <= n; ++i) {
		int t = i + l - 1;
		if (abs(t) < abs(x)) x = t;
	}
	printf("%d\n", sum - x);
  return 0;
}

long long read() {
  long long a = 0, c = getchar(), s = 0;
  while (!isdigit(c)) s |= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}


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

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, n);
    CINS(int, p, n);

    int ans = 0;
    for (int i = 0; i < n - 2; i++) {
        if ( p[i+0] < p[i+1] && p[i+1] < p[i+2] ) {
            ans++;
        } else if ( p[i+2] < p[i+1] && p[i+1] < p[i+0] ) {
            ans++;
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 10e9
#define INFL 10e18;
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modinv(ll a){
	return powm(a,mod-2)%mod;
}
//cout<< fixed << setprecision(10)

int main(){

    fast;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        ll n,i,x;
        cin>>n;
        x=n%10;
        if(x==3)
        {
        	cout<<"bon";
		}
		else
		{
			if(x==0||x==1||x==6||x==8)
			{
				cout<<"pon";
			}
			else
			{
				cout<<"hon";
			}
		}
        
        
	}

}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}


void solve_TLE(long long N, std::vector<long long> P){
    ll cnt=0;
    for (ll i = 0; i < N; i++) {
        sort(P.begin(), P.begin()+i);
        auto itr = lower_bound(P.begin(), P.begin()+i, P[i]);
        ll e = itr - P.begin();
        // debg(*itr);
        // debg(e);
        if(e == 0) cnt++;
    }
    cout << cnt << "\n";
}

void solve(long long N, std::vector<long long> P){
    ll cnt=0;
    // priority_queue<ll> q;
    std::priority_queue<
      int,
      std::vector<int>,
      std::greater<int>
    > q;
    for (ll i = 0; i < N; i++) {
        q.push(P[i]);
        // if(q.top()>=P[i]) cnt++;
        if(q.top()>=P[i]) cnt++;
        // debg(q[0]);
        // debg(q.top());
        // cout << q.front() << "\n";
        // debg(P[i]);
    }
    cout << cnt << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    solve(N, std::move(P));
    return 0;
}


Measured memory_bytes: 2936
//#pragma GCC optimize(2)
#pragma comment(linker, "/STACK:102400000,102400000")

#include <bits/stdc++.h>
using namespace std;
#define rep(i, beg, end) for (int i = beg; i < end; i++)
#define rrep(i, beg, end) for (int i = beg; i >= end; i--)
typedef long long ll;
typedef pair<ll, ll> P;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const int N = 6000;
ull p_hash(ull x, ull y) { return (x + y) * (x + y + 1) / 2 + y; } //NxN->N

ll p[N];
ll c[N];
ll n, k;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> k;
    rep(i, 1, n + 1)
    {
        cin >> p[i];
    }

    rep(i, 1, n + 1)
    {
        cin >> c[i];
    }

    ll ans = -1e18;
    rep(i, 1, n + 1)
    {
        int x = i;
        ll tot = 0;
        vector<int> sc;
        while (true)
        {
            x = p[x];
            tot += c[x];
            sc.push_back(c[x]);
            if (x == i)
                break;
        }

        int l = sc.size();
        ll t = 0;
        rep(j, 0, l)
        {
            t += sc[j];
            if (j + 1 > k)
                break;
            ll now = t;
            if (tot > 0)
            {
                ll e = (k - j - 1) / l;
                now += tot * e;
            }
            ans = max(ans, now);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K,S;
  cin>>K>>S;
int count=0;
  for(int i=0;i<=K;i++){
	for(int j=0;j<=K;j++){
    	int k=S-i-j;
        	if(0<=k and k<=K){
            	count++;
            }
        
    }
}  
cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
const int maxm=1e6+5;
int a[maxm];
int b[maxm];
int n,k;
int check(int x){
    vector<int>temp;
    for(int i=1;i<=n;i++){
        int t=a[i]%x;
        if(t)temp.push_back(t);
    }
    sort(temp.begin(),temp.end());
    int l=0,r=(int)temp.size()-1;
    int ans=0;
    while(l<r){
        int t=min(temp[l],x-temp[r]);
        ans+=t;
        temp[l]-=t;
        temp[r]+=t;
        if(temp[l]==0)l++;
        if(temp[r]==x)r--;
    }
    return ans<=k;
}
signed main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    int sum=0;
    for(int i=1;i<=n;i++)sum+=a[i];
    int ans=0;
    for(int i=1;i*i<=sum;i++){
        if(sum%i==0){
            if(check(i)){
                ans=max(ans,i);
            }
            if(check(sum/i)){
                ans=max(ans,sum/i);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
/*
因为操作不改变序列的总和sum,
因此满足条件的x,一定是sum的因子,
O(sq)枚举sum的因子,然后O(n)check即可.

如何check:
计算出所有a[i]对x的余数t[i]
每个数要么减掉t[i],要么加上x-t[i],
现在要使操作次数最少,且满足加的和减的一样.
*/


Measured memory_bytes: 3592
h, w = STDIN.gets.split(" ").map(&:to_i)
map = []
h.times do
  map << STDIN.gets.strip.split("")
end

for i in 0...h do
  if map[i].all? { |v| v == '.' }
    for j in 0...w do
      map[i][j] = nil
    end
  end
end

for j in 0...w do
  white = true
  for i in 0...h do
    unless map[i][j] == '.' || map[i][j] == nil
      white = false
    end
  end

  if white
    for i in 0...h do
      map[i][j] = nil
    end
  end
end

for i in 0...h do
  row = map[i].compact
  puts row.join('') if row.size > 0
end


Measured memory_bytes: 2684
#include <stdio.h>
int main(void){
    int i;
    char s[4096];
    while(1){
        int ans=0;
        scanf("%s",s);
        if(s[0]=='0')break;
        for(i=0;s[i]!='\0';i++){
            ans+=s[i]-'0';
        }
        printf("%d\n",ans);
    }
    
    return 0;
}



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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

bool check(int idx);

LL N, M, V, P;
vector<int> v;

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

    cin >> N >> M >> V >> P;
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        v.pb(a);
    }
    sort(all(v), greater<>());

    int l = 0;
    int r = N;
    while(r - l > 1) {
        int mid = (r + l) / 2;
        if(check(mid)) l = mid;
        else r = mid;
    }
    cout << r << endl;

    return 0;
}

bool check(int idx) {
    int t = v[idx] + M;

    LL vot = M * V - M;

    vector<int> r;
    int res = N;
    for(int i = 0; i < N; ++i) {
        if(i == idx) continue;
        if(t < v[i]) {
            vot -= M;
        } else {
            r.pb(v[i]);
            --res;
        }
    }

    if(res > P) {
        return false;
    }

    sort(all(r), greater<>());
    for(int i = 0; i < r.size(); ++i) {
        if(t - r[i] < M && res < P) {
            vot -= M;
            ++res;
        } else {
            vot -= min((int)M, t - r[i]);
        }
    }

    return vot <= 0;
}



Measured memory_bytes: 4400
#include "bits/stdc++.h"
using namespace std;
static const int N=100;

int main(){
	int M[N][N]; //0?????????????????????
	int n,u,k,v;
	cin>>n;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) M[i][j]=0;
	}
		for (int i = 0; i < n; ++i) {
			cin>>u>>k;
			u--;
			for (int j = 0; j < k; ++j) {
				cin>>v;
				v--;
				M[u][v]=1;//u??¨v?????????????????????
			}
		}
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if(j)cout<<" ";
				cout<<M[i][j];
			}
			cout<<endl;
		}
	return 0;
}

Measured memory_bytes: 3108
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      s: Bytes
   }
   let n = s.len();
   for i in 0..n-1 {
      if s[i] == s[i+1] {
         println!("{} {}", i+1, i+2);
         return;
      }
      if i != n-2 && s[i] == s[i+2] {
         println!("{} {}", i+1, i+3);
         return;
      }
   }
   println!("-1 -1");
}



Measured memory_bytes: 2332
#include<bits/stdc++.h>
using namespace std;
#define forn for(int i=0;i<n;i++)
#define pb push_back
#define pr pair<int,int>
#define mp make_pair
#define ll long long int
const int mod=1e9+7;
int isPalindrome(string str) 
{ 
    int l=0;
    int h = str.size() - 1; 
    while (h > l) 
    { if (str[l++] != str[h--]) 
        { 
            return 0;
        } 
    } 
    return 1;
} 
int main()
{ ll t=1;
   while(t--){
   	string s;
   cin>>s;
   ll n=s.size();
   if(isPalindrome(s)==1){
       string t=s.substr(0,(n-1)/2);
       if(isPalindrome(t)==1){
           string u=s.substr((n+3)/2-1,(n-3)/2+1);
           if(isPalindrome(u)==1)cout<<"Yes"<<endl;
           else cout<<"No"<<endl;
       }else cout<<"No"<<endl;
   }else cout<<"No"<<endl;
}
}

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

#define INT__(N) ((int)(N) - (int)'a')

string S;
bool w[30];

int main()
{
	for(int a = 0; a<=INT__('z');a++)
	{
		w[a] = true;
	}

	cin >> S;
	for(int i = 0;i < S.size();i++)
	{
		w[INT__(S[i])] = false;
	}

	for(int i = 0; i <= INT__('z');i++)
	{
		if(w[i])
		{
			cout << (char)('a' + i) << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}


Measured memory_bytes: 512