akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <functional>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())


int main(int argc, char const *argv[])
{
	while(true)
	{
		int n, m;
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0) break;
		vector<pair<int, int> > load;
		REP(i, n)
		{
			int d, p;
			scanf("%d %d", &d, &p);
			load.push_back(make_pair(p, d));
		}
		sort(load.begin(), load.end(), std::greater<pair<int, int> >());
		int ans = 0;
		REP(i, n)
		{
			if (m < load[i].second)
			{
				ans += (load[i].second - m) * load[i].first;
				m = 0;
			}
			else
			{
				m -= load[i].second;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int M = 1005;
const int Mod = 1e9+7;
#define pi acos(-1)
#define INF 1e8
#define INM INT_MIN
#define pb(a)  push_back(a)
#define mk(a,b) make_pair(a,b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx,0,sizeof(axx));
#define metf(axx) memset(axx,-1,sizeof(axx));
#define sd(ax) scanf("%d",&ax)
#define sld(ax) scanf("%lld",&ax)
#define sldd(ax,bx) scanf("%lld %lld",&ax,&bx)
#define sdd(ax,bx) scanf("%d %d",&ax,&bx)
#define sddd(ax,bx,cx) scanf("%d %d %d",&ax,&bx,&cx)
#define sfd(ax) scanf("%lf",&ax)
#define sfdd(ax,bx) scanf("%lf %lf",&ax,&bx)
#define pr(a) printf("%d\n",a)
#define plr(a) printf("%lld\n",a)
int n,m,dis[N],pre[N];
struct Node{int to,dis;};
vector<Node> G[N];
bool djst()
{
    for(int i=1;i<=n;++i) dis[i] = INF;
    dis[1] = 0;
    priority_queue<pii,vector<pii>,greater<pii> > Q;
    Q.push(pii(0,1));
    while(!Q.empty())
    {
        int u = Q.top().second,d = Q.top().first;
        Q.pop();
        if(dis[u] < d) continue;
        for(int i=0;i<G[u].size();++i)
        {
            int v = G[u][i].to,dd = G[u][i].dis;
            if(dis[v] > dis[u]+dd)
            {
                pre[v] = u;
                dis[v] = dis[u]+dd;
                Q.push(pii(dis[v],v));
            }
        }
    }
    for(int i=2;i<=n;++i) if(dis[i] == INF) return false;
    return true;
}
int main()
{
    sdd(n,m);
    while(m--)
    {
        int x,y;sdd(x,y);
        G[x].push_back(Node{y,1});
        G[y].push_back(Node{x,1});
    }
    if(!djst()) printf("No\n");
    else 
    {
        printf("Yes\n");
        for(int i=2;i<=n;++i) pr(pre[i]);
    }
//    system("pause");
	return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

vector<pii> vv;
int d[MAXN];

void solve(){
	int x1, y1, x2, y2, x, y, n;
	scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &n);
	if (x1 > x2) {
		swap(x1, x2);
		swap(y1, y2);
	}
	if (x1 == x2 && y1 > y2) {
		swap(y1, y2);
	}
	int fl = 0;
	REP(i, 0, n) {
		scanf("%d%d", &x, &y);
		if (x1 == x2 && x == x1 && y1 <= y && y <= y2) {
			fl = 1;
		}
		if (y1 == y2 && y == y1 && x1 <= x && x <= x2) {
			fl = 1;
		}
		if (/*x1 != x2 && y1 != y2 &&*/ x1 <= x && x <= x2 && min(y1, y2) <= y && y <= max(y1, y2)) {
			vv.pb(mp(x, y));
		}
	}
	double basic_dis = 100.0 * (abs(x1 - x2) + abs(y1 - y2));
	/*if (fl == 1) {
		printf("%.15lf\n", basic_dis + 10.0 * (PI - 2));
		return;
	}*/
	if (y1 > y2) {
		swap(y1, y2);
		REP(i, 0, SZ(vv)) {
			vv[i]._2 = y1 + y2 - vv[i]._2;
		}
	}
	SORT(vv);
	
	d[0] = -INF;
	REPN(i, 1, SZ(vv))
		d[i] = INF;
	 
	REP(i, 0, SZ(vv)) {
		int j = int (upper_bound (d, d + SZ(vv) + 1, vv[i]._2) - d);
		if (d[j-1] < vv[i]._2 && vv[i]._2 < d[j])
			d[j] = vv[i]._2;
	}
	int tt = 0;
	REPN(i, 1, SZ(vv)) {
		if (d[i] != INF) {
			tt = i;
		}
	}
	//printf("%d\n", tt);
	double offset = 0.0;
	if (min(abs(x1 - x2), abs(y1 - y2)) == tt - 1) {
		tt--;
		offset = 10.0 * (PI - 2);
	}
	
	printf("%.15lf\n", basic_dis - 10.0 * tt * (2 - PI / 2) + offset);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 2672
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

char map[500][500];
int a, b;

int main()
{
	cin >> a >> b;
	for (int i = 0; i < a; i++)
		for (int j = 0; j < b; j++)
			cin >> map[i][j];
	for (int i = 0; i < a; i++)
	{
		for (int j = 0; j < b; j++)
		{
			if (map[i][j] == '#') cout << "#";
			else
			{
				int cnt = 0;
				for (int q = max(i - 1, 0); q <= i + 1; q++)
					for (int p = max(j - 1, 0); p <= j + 1; p++)
						if (map[q][p] == '#')
							cnt++;
				cout << cnt;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
string a, b;
int main() {
	cin>>a;
	for(int i=0; a[i]; i++) {
		if(a[i]!='B') b += a[i];
		else if(!b.empty()) b.pop_back();
	}
	cout<<b;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(ll i = a; i<=b; ++i)
#define NFOR(i,a,b) for(ll i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const ll N = 5e5 + 10;
inline ll add(ll x,ll y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline ll mul(ll x,ll y){
  x = (1LL * x * y) % mod;
  return x;
}

int main()
{   
    ll n,W;
    cin >> n >> W;
    ll w[n+1],v[n+1];
    FOR(i,1,n)cin >> v[i] >> w[i];
    ll dp[n+1][100001] = {0};
    FOR(i,0,1e5)if(i<=w[1])dp[1][i] = v[1]; else dp[1][i] = INF;
    FOR(i,1,n)dp[i][0] = 0;
    FOR(i,2,n){
        FOR(j,1,1e5){
            if(j>=w[i]){
                dp[i][j] = min(v[i]+dp[i-1][j-w[i]], dp[i-1][j]);
            }
            else{
                dp[i][j] = min(v[i],dp[i-1][j]);
            }
        }
    }
    ll ans = 0;
    FOR(i,0,1e5){
        if(dp[n][i]<=W)ans = max(ans,i);
    }
    cout << ans;
    // cout << dp[n][W];

    return 0;
}

Measured memory_bytes: 79104
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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


def resolve():
    n = int(input())

    div = make_divisors(n)
    res = 0
    for i in div:
        if i != 1:
            x, y = divmod(n, i - 1)
            if x == y:
                res += i - 1

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3272
#include<stdio.h>
#include<math.h>
#define N 100000000
#define M 100005
int main()
{
	int n;
	double x[M],y[M];
	char c[M];
	double minS=-1,S1,S2,l=0,r=N;
	double minl1=N,maxr1=-N,maxu1=-N,mind1=N,xx1,yy1,move1=0;
	double minl2=N,maxr2=-N,maxu2=-N,mind2=N,xx2,yy2,move2=N;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%lf%lf %c",&x[i],&y[i],&c[i]);
    for(int k=0;k<=10000&&(move2-move1>0.00000000001);k++)
	{
		minl1=N,maxr1=-N,maxu1=-N,mind1=N;
		minl2=N,maxr2=-N,maxu2=-N,mind2=N;
        move1=(r/3+2*l/3),move2=(2*r/3+l/3);
        for(int i=0;i<n;i++)
		{
	        xx1=xx2=x[i];
			yy1=yy2=y[i];
			if(c[i]=='U')
			{
				yy1+=move1;
				yy2+=move2;
			}
			if(c[i]=='D')
			{
				yy1-=move1;
				yy2-=move2;
			}
			if(c[i]=='L')
			{
				xx1-=move1;
				xx2-=move2;
			}
			if(c[i]=='R')
			{
				xx1+=move1;
				xx2+=move2;
			}
	        if(xx1<minl1)minl1=xx1;
	        if(xx1>maxr1)maxr1=xx1;
	        if(yy1<mind1)mind1=yy1;
	        if(yy1>maxu1)maxu1=yy1;
	        if(xx2<minl2)minl2=xx2;
	        if(xx2>maxr2)maxr2=xx2;
	        if(yy2<mind2)mind2=yy2;
	        if(yy2>maxu2)maxu2=yy2;
	    }
	    S1=(maxr1-minl1)*(maxu1-mind1);
	    S2=(maxr2-minl2)*(maxu2-mind2);
        if(S1<minS||minS==-1)minS=S1;
        if(S2<minS||minS==-1)minS=S2;
        if(S1>S2)l=move1;
        else r=move2;
    }
    printf("%.10f\n",minS);
}

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

#define MAX 2000

using namespace std;

int n,q;
int n_lst[MAX],q_lst[MAX];
static int ans_lst[MAX][MAX];


bool bf(int idx,int x){
    if(x == 0) return true;
    if(idx < n){
        return bf(idx+1,x) || bf(idx+1,x-n_lst[idx]);
    }
    return false;
}

int m_bf(int idx,int x){
    //1:false,2:true

    //定義済み？
    if(ans_lst[idx][x] > 0) return ans_lst[idx][x];


    if(x == 0) ans_lst[idx][x] = 2;
    else if(idx < n){
        if(m_bf(idx+1,x-n_lst[idx]) == 2)
            ans_lst[idx][x] = 2;
        else if(m_bf(idx+1,x) == 2)
            ans_lst[idx][x] = 2;
    }
    else
        ans_lst[idx][x] = 1;

    return ans_lst[idx][x];

}

int main(){
    cin >> n;
    for(int i=0;i<n;i++) cin >> n_lst[i];
    cin >> q;
    for(int i=0;i<q;i++) cin >> q_lst[i];

    for(int i=0;i<q;i++){
        if(m_bf(0,q_lst[i]) == 2)
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
}



Measured memory_bytes: 3192
#include <vector>
#include <functional>
#include <deque>
#include <stdexcept>

template<typename T, typename Container = ::std::vector<T>, typename Compare = ::std::greater<typename Container::value_type>>
class sliding_window {
    using iterator_type = typename Container::const_iterator;
    using value_compare = Compare;
    using value_type = T;
    using const_reference = const value_type &;

    iterator_type right_bound, left_bound, end;
    value_compare comp;
    size_t length;
    ::std::deque<value_type> val;

public:
    void push() {
        if (left_bound == end) {
            throw ::std::runtime_error("already reached to the end");
        }
        const auto &tmp = *left_bound;
        while (!val.empty() && comp(val.back(), tmp))val.pop_back();
        val.push_back(tmp);
        ++left_bound;
        ++length;
    }

    void pop() {
        if (right_bound == left_bound) {
            throw ::std::runtime_error("interval is empty");
        }
        const auto &tmp = *right_bound;
        if (tmp == val.front())val.pop_front();
        ++right_bound;
        --length;
    }

    sliding_window(iterator_type _begin, iterator_type _end, const Compare &_comp = Compare()) : length(0),
                                                                                                 right_bound(_begin),
                                                                                                 left_bound(_begin),
                                                                                                 end(_end), comp(_comp),
                                                                                                 val({}) {}

    const size_t size() const {
        return length;
    }

    const_reference top() const {
        return val.front();
    }

    void resize(size_t n) {
        if (n < length) {
            while (n < length) {
                pop();
            }
        } else {
            while (n > length) {
                push();
            }
        }
    }

    void forward() {
        if (left_bound != end)push();
        pop();
    }

};

#include <iostream>
#include <algorithm>

int main() {
    unsigned long long N, M, K;
    scanf("%llu%llu%llu", &N, &M, &K);

    std::vector<unsigned long long> A(N), dp1(N), dp2(N);
    for (auto &i : A)scanf("%llu", &i);

    std::copy(A.begin(), A.end(), dp1.begin());

    for (unsigned long long i = 1; i < K; ++i) {
        sliding_window<unsigned long long, std::vector<unsigned long long>, std::less<>> slidingWindow(
                dp1.begin() + i - 1, dp1.end());
        std::transform(A.begin() + i, A.end(), dp2.begin() + i, [&i](auto a) { return a * (i + 1); });

        slidingWindow.push();

        for (unsigned long long j = i; j < N; ++j) {
            dp2[j] += slidingWindow.top();
            slidingWindow.push();
            if (slidingWindow.size() > M)slidingWindow.pop();
        }

        std::swap(dp1, dp2);
    }

    std::cout << *std::max_element(dp1.begin(), dp1.end()) << std::endl;

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
// Welcome to my source code!

class Cube {
public:
    int face[6];
    void roll(int i, int j, int k, int l) {
        int t = face[i]; face[i] = face[j]; face[j] = face[k]; face[k] = face[l]; face[l] = t;
    }
    void roll_turn() { roll(1,2,4,3); } // Rotate to the side.
    void roll_S() { roll(1,0,4,5); } // to S
    void roll_E() { roll(2,0,3,5); } // to E
};

bool eq(Cube c1, Cube c2) {
    rep(i,6) {
        if (c1.face[i] != c2.face[i]) return false;
    }
    return true;
}

bool equal(Cube c1, Cube c2) {
    rep(i,6) {
        rep(j,4) {
            if (eq(c1, c2)) return true;
            c1.roll_turn();
        }
        if (i % 2 == 0) c1.roll_E();
        else c1.roll_S();
    }
    return false;
}

Cube c[100];
int n;

bool check() {
    rep(i,n-1) {
        for (int j = i+1; j < n; j++) {
            if (equal(c[i], c[j])) return false;
        }
    }
    return true;
}

int main() {
    cin >> n;
    rep(i,n)
        rep(j,6) cin >> c[i].face[j];
    
    if (check()) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3116
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int array[3];
	for(int i = 0; i < 3; i++) scanf("%d",&array[i]);
	for(int i = 2; i > 0; i--){
		for(int j = 0; j < i; j++){
			if(array[j] > array[j+1])swap(array[j],array[j+1]);
		}
	}
	printf("%d %d %d\n",array[0],array[1],array[2]);
}


Measured memory_bytes: 2660
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
using namespace std;

int main(){
  int N,Q;
  string S;
  cin >> N >> Q >> S;
  vector<pii> LR(Q);
  vi Cumulative_sum(N); //if AC and A is in i-th place then cum_s[i] = 1
  Cumulative_sum[0] = 0;
  for(int i = 0; i < Q; i++){
    cin >> LR[i].first >> LR[i].second;
    LR[i].first--;
    LR[i].second--;
  }
  for(int i = 1; i < N;i++){
      if(S[i - 1] == 'A' && S[i] == 'C'){
        Cumulative_sum[i] = Cumulative_sum[i-1] + 1;
      }
      else{
        Cumulative_sum[i] = Cumulative_sum[i-1];
      }
  }

  rep(i,Q){
    cout << Cumulative_sum[LR[i].second] - Cumulative_sum[LR[i].first] << endl;
  }

}


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

int n;
char s[100005];

int main() {
	scanf(" %s",s+1);
	n = strlen(s+1);
	if(s[1] == '0' || s[n] == '1') return !printf("-1");
	for(int i = 1; i <= n-1; i++) {
		if(s[i] != s[n-i]) return !printf("-1");
	}
	for(int x = 1, y = 1; x <= n; x++) {
		if(s[x] == '1' || x == n) {
			while(y<x) {
				printf("%d %d\n",y,x);
				y++;
			}
		}
	}
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int ans[2], n, t[2], len;
char s[1000005];
int main(){
	scanf("%s", s);
	len = strlen(s);
	for(int i=len-1; i>=0; i--){
		n = s[i]-'0';
		t[0] = min(ans[0],ans[1]+1) + n;
		if(i < len-1) t[1] = min(ans[0]+(10-n), ans[1]+(10-n-1));
		else t[1] = ans[0]+(10-n);
		ans[0] = t[0];
		ans[1] = t[1];
	}
	printf("%d\n", min(ans[0],ans[1]+1));
}

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

using namespace std;
int n;
const int maxn=2e5+5;
int a[maxn];
priority_queue<int> qu;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        qu.push(a[i]);
    }
    int k;
    for(int i=1;i<=n;i++)
    {
        int t=qu.top();
        if(t==a[i])
        {
            qu.pop();
            k=qu.top();
            qu.push(t);
            t=k;
        }
        printf("%d\n",t);
    }
    return 0;
}


Measured memory_bytes: 3316
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
 
def main():
    s = input()
    t = input()

    min_num = 10**5
    max_num = 0
    count = 0
    for i in range(len(s) - len(t)+1):
        for j in range(len(t)):
            if s[i+j] == t[j]:
                count += 1
        if max_num <= count:
            max_num = count
        count = 0

    print(len(t) - max_num)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9552
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, cnt[200000];
vector<int>v[200000];
ll res;

inline ll pw(ll x, int y) {
	ll a = 1;
	while (y) {
		if (y & 1)a = a*x%mod;
		x = x*x%mod;
		y /= 2;
	}
	return a;
}

inline ll modinv(ll x) {
	return pw(x, mod - 2);
}

void dfs(int x, int from) {
	cnt[x] = 1;
	for (int i : v[x]) {
		if (i == from)continue;
		dfs(i, x);
		cnt[x] += cnt[i];
	}
}

int main() {
	cin >> N;
	for (int i = 1; i < N; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(0, 0);
	for (int i = 0; i < N; i++) {
		if (v[i].size() == 1)continue;
		vector<ll>vv;
		if (i) {
			vv.push_back((mod + 1 - modinv(pw(2, N - cnt[i]))) % mod);
		}
		for (int j : v[i]) {
			if (cnt[j] > cnt[i])continue;
			vv.push_back((mod + 1 - modinv(pw(2, cnt[j]))) % mod);
		}
		ll p = 1;
		for (ll l : vv) {
			p *= (mod + 1 - l);
			p %= mod;
		}
		ll t = 1 + mod - p;
		for (ll l : vv) {
			t += mod - p*modinv(mod + 1 - l) % mod*l%mod;
			t %= mod;
		}
		res += t*modinv(2);
		res %= mod;
	}
	cout << res << endl;
}

Measured memory_bytes: 20864
#include <iostream>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	LL X,Y;
	cin>>X>>Y;
	LL aw=1;
	LL x=X;
	while (x<=Y){
		aw++;
		x*=2;
		if (x>Y){
			aw--;
			break;
		}else if (x==Y){
			break;
		}
	}
	cout<<aw<<endl;
	return 0;
}

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

signed main(){
	int n;
	cin>>n;
	
	if(n==1){
		cout<<0<<endl;
		return 0;
	}
	
	int ans=0; 
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			int pos=0;
			while(n%i==0)
				n/=i,pos++;
			
			int now=sqrt(pos*2);
			if(now*(now+1)>pos*2) now--;
			
			ans+=now;
		}
	}
	
	if(n>1) ans++;
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3624
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <sstream>
#include <regex>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int x; cin >> x;
	int k = 1;
	while (k*x % 360 != 0)++k;
	cout << k << endl;
}

Measured memory_bytes: 3604
def gcd(a, b):
    if (b == 0):
        return a
    return gcd(b, a % b);

n, start = [int(a) for a in input().split()]
x = [int(b) for b in input().split()]
x = x + [start]
mi = min(x)

g = abs((x[1] - mi) - (x[0] - mi))
for i, v in enumerate(x):
    if (i > 0):
        d = abs((x[i] - mi) - (x[i - 1] - mi))
        g = gcd(g, d)
        
print (g)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
 using namespace  std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const double pi=3.1415926535897932384626433832;
const long long mod=1e9+7;
//long long primeset[5000000]={};
typedef complex<double> cd;
typedef long long ll;
typedef double ld;
//#define For(i,0,n) for(long long i = 0 ; i<n ;i++) 
cd fast_exp(cd a, long long b)
{
	if (b == 0)
		return 1;
	
	cd res = fast_exp(a, b / 2);
		
	res = res * res;
	
	if (b % 2 == 1)
		res = res * a;
	
	return res;
}

long long fastexpon(long long a,long long b,long long mod)
{
	if(b==0)
		return 1;
	
	long long res=fastexpon(a,b/2,mod);
	
	res=(res*res)%mod;
	if(b%2==1)
		res= (res * a)%mod;

	return res;
}


//TEMPLATE ENDS HERE!!!! ------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------















struct custom
{
	bool operator()(ll a, ll b)
	{
		return a > b;
	}
};

// struct triplet{

// 	ll a;
// 	ll b;
// 	ll c;
// };
int main()
 {
		
		// ios_base::sync_with_stdio(false);
		// cin.tie(NULL);
		// cout.tie(NULL);
 		
 	ll x,y,z,maxk;
 	cin>>x>>y>>z>>maxk;
 	ll a[x+1],b[y+1],c[z+1];
 	map <pair<pair<ll,ll>,ll>,ll> is_there;
 	vector <pair<pair<ll,ll>,ll>> allposs;
 	
 	for(ll i=1 ; i<=x ;i++)
 	cin>>a[i];
 	for(ll i=1 ; i<=y ;i++)
 	cin>>b[i];
 	for(ll i=1 ; i<=z ;i++)
 	cin>>c[i];
 	sort(a+1,a+x+1,greater<>());
 	sort(b+1,b+y+1,greater<>());
 	sort(c+1,c+z+1,greater<>());
 	for(ll i=1 ; i<=x ; i++ )
 		{
 			// if(i>maxk)
 			// 	break;
 			for(ll j=1 ; j<=y ;j++)
 			{
 				// if(i*j > maxk)
 				// 	break;
 				for(ll k=1;k<=z ;k++)
 				{
 					if(i*j*k> maxk)
 						break;
 					else
 					{
 						pair<pair<ll,ll>,ll> trip;
 						trip.ff.ff = i;
 						trip.ff.ss=j;
 						trip.ss=k;

 						if(!is_there[trip])
 						{
 							allposs.pb(trip);
 							is_there[trip]++;
 						}
 					}
 				}
 			}
 		}
 	vector <ll> ans;
 	for(ll i=0 ;i<allposs.size();i++)
 	{
 		ll m1 = allposs[i].ff.ff;
 		ll m2 = allposs[i].ff.ss;
 		ll m3 =allposs[i].ss;
 		ans.pb(a[m1]+b[m2]+c[m3]);
 	}

 	sort(ans.begin(),ans.end(),greater<>());

 	for(ll i=0 ;i<maxk ;i++)
 	cout<<ans[i]<<'\n';			


	//cout<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

Measured memory_bytes: 13488
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;

bool is_ok(int L, int k, V<int> &A) {
    int need = 0;
    for (auto &&a : A) {
        need += (a - 1) / L;
    }
    return need <= k;
}

int binary_searchM(int k, V<int> &A) {
    int ng = 0;
    int ok = 1e9;
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if (is_ok(mid, k, A)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}

void solve() {
    int n, k;
    cin >> n >> k;
    V<int> a(n);
    rep(i, n) cin >> a[i];
    cout << binary_searchM(k, a) << "\n";
}
int main() {
    cin.tie(nullptr);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3952
#include<stdio.h>
#define MAX_LEN 100000
 
typedef struct {
    char name[11];
    int val;
} dic;
 
dic arr[MAX_LEN];
int head, tail;
 
int enqueue(dic x){
    if(tail+1 == head){
        printf("OverFlow\n");
        return 0;
    }
    arr[tail] = x;
    if(tail+1 == MAX_LEN){
        tail=0;
    }else{
        tail++;
    }
    return 0;
}
 
dic dequeue(){
    if(head+1 == MAX_LEN){
        head=0;
        return arr[MAX_LEN-1];
    }else{
        head++;
        return arr[head-1];
    }
}
 
int main(){
    int num, time, i, time_sum=0;
    dic task;
    scanf("%d %d", &num, &time);
    int task_num = num;
    head = 0;
    tail = num;
    for(i=0; i<num; i++){
        scanf("%s %d", arr[i].name, &arr[i].val);
    }
    while(task_num!=0){
        task = dequeue();
        if(task.val <= time){
            printf("%s %d\n", task.name, time_sum+task.val);
            task_num--;
            time_sum += task.val;
        }else{
            task.val -= time;
            enqueue(task);
            time_sum += time;
        }
    }
    return 0;
}

Measured memory_bytes: 3240
#include <stdio.h>

int main(void)
{
	int i,j;
	int h,w;

	while(1){
		scanf("%d %d", &h,&w);
		if(w==0 && h==0)
			break;
		for(i=0; i<h; i++){
			for(j=0; j<w; j++){
				if(i%2==0){
					if(j%2==0){
						printf("#");
					} else {
						printf(".");
					}
				} else {
					if(j%2==0){
						printf(".");
					} else {
						printf("#");
					}
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
import sys
sys.setrecursionlimit(10**7)

# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    a, b = map(int, input().split())
    if a >= 13:
        print(b)
    elif a >= 6:
        print(int(b/2))
    else:
        print(0)

solve()

Measured memory_bytes: 2940
// ITP1_5_B:   Print a Frame
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int H, W;
	int h, w;

	while (1) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0) break;
		
		for (w = 0; w < W; w++) putchar('#');
		putchar('\n');

		for (h = 2; h < H; h++) {
			putchar('#');
			for (w = 2; w < W; w++) putchar('.');
			putchar('#');
			putchar('\n');
		}

		for (w = 0; w < W; w++) putchar('#');
		putchar('\n');

		putchar('\n');
	}
	return 0;
}

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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
using ll = long long;

ll gcd(ll x, ll y) {
    if (x > y) swap(x, y);
    if (x == 0) return y;
    return gcd(y % x, x);
}

struct Rational {
    int p, q;
    Rational(int p, int q) : p(p), q(q) {}
    bool operator==(const Rational &rhs) const { return p * rhs.q == rhs.p * q; }
    bool operator<(const Rational &rhs) const { return p * rhs.q < rhs.p * q; }
    bool operator>(const Rational &rhs) const { return p * rhs.q > rhs.p * q; }
    Rational &operator+=(const Rational &rhs) {
        p = p * rhs.q + rhs.p * q;
        q *= rhs.q;
        int g = gcd(p, q);
        p /= g, q /= g;
        return *this;
    }
    Rational operator+(const Rational &rhs) const {
        Rational tmp(*this);
        return tmp += rhs;
    }
    void show() { cout << p << "/" << q << endl; }
};
int p, q, a, n;
void dfs(int x, int y, int las, int mul, int cnt, int &ans) {
    if (cnt > n) return;
    if (x * q > p * y) return;
    if (x * q == p * y) {
        ans++;
        return;
    }

    for (int k = a / mul; k >= las; k--) {
        dfs(x * k + y, y * k, k, mul * k, cnt + 1, ans);
    }
}

bool solve() {
    cin >> p >> q >> a >> n;
    if (p == 0) return false;
    int ans = 0;
    Rational goal(p, q);
    dfs(0, 1, 1, 1, 0, ans);
    cout << ans << endl;
    return true;
}
signed main() {
    while (solve())
        ;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  vector<int>p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  int num=0;
  sort(p.begin(),p.end());
  for(int i=0;i<k;i++){
    num+=p[i];
  }
  cout<<num<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
vint x;
map<pair<int,int>,bool> seenEdge;
set<int> unSeenVert;
vector<vector<pair<int,int>>> graph;
void dfs(int from,int to,int d)
{
    if(from == -1)
    {
        x[to] = 0;
    }
    else if(unSeenVert.count(to) == 0 and x[to] != x[from] + d)
    {
        cout<<"No"<<endl;
        exit(0);
    }
    else
    x[to] = x[from] + d;

    if(unSeenVert.count(to) == 1)
    unSeenVert.erase(to);
    else
    return;
    seenEdge[{to,d}] = true;
    for (auto &&i : graph[to])
    {
        if(seenEdge[i])
        continue;
        dfs(to,i.first,i.second);
        seenEdge[i] = true;
    }
    
}
int main()
{
    int N,M;
    cin>>N>>M;
    graph.resize(N);
    x.resize(N);
    vint L(M),R=L,D=L;
    for (size_t i = 0; i < M; i++)
    {
        cin>>L[i]>>R[i]>>D[i];
        L[i]--;
        R[i]--;
        graph[L[i]].push_back({R[i],-D[i]}); // x_L[i] = x_R[i] - D[i]
        graph[R[i]].push_back({L[i],D[i]});  // x_R[i] = x_L[i] + D[i]
        unSeenVert.insert(L[i]);
        unSeenVert.insert(R[i]);
    }
    while(!unSeenVert.empty())
    {
        dfs(-1,*unSeenVert.begin(),-1);
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 46252
#!/usr/bin/ruby
n,m=gets.split.map &:to_i
(p (m+1)%(10**9+7);exit)if n==1
r=(0..m+1).bsearch{|i|
	m<(n-1)*i
}
r-=1
p ((m+1)*r*2-(n-1)*r*(r+1)+m+1)%(10**9+7)

Measured memory_bytes: 8732
import sys

input = sys.stdin.readline().strip('\n')
flag = 0
for idx in range(len(input)):
    if input[idx] != 'h' and input[idx] != 'i':
        print('No')
        flag = -1
        break
    elif input[idx] == 'h':
        if idx == len(input)-1:
            print('No')
            flag = -1
            break
        elif input[idx+1] != 'i':
            print('No')
            flag = -1
            break
    else:
        if idx == 0:
            print('No')
            flag = -1
            break
        elif input[idx-1] != 'h':
            print('No')
            flag = -1
            break

if flag == 0:
    print('Yes')


Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
using namespace std;
int n,m,k;
int dp[32][1<<20];
main()
{
	while(cin>>n>>m>>k,n)
	{
		for(int i=0;i<=n;i++)for(int j=0;j<=n*m;j++)dp[i][j]=0;
		dp[0][0]=1;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<=n*m;j++)
			{
				for(int k=0;k<m;k++)dp[i+1][j+k+1]+=dp[i][j];
			}
		}
		double ans=0;
		for(int i=0;i<=n*m;i++)ans+=1L*dp[n][i]*(i>k?i-k:1);
		for(int i=0;i<n;i++)ans=ans/m;
		cout<<fixed<<setprecision(9)<<ans<<endl;
	}
}



Measured memory_bytes: 3368
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
 
using namespace std;
 
int main(){
    int n;
    cin>>n;

    vector<int> even(n/2), odd(n/2);
    int i_even = 0, i_odd = 0;
    for(int i = 0; i < n; i++) {
        if(i%2 == 0) cin>>even[i_even++];
        else cin>>odd[i_odd++];
    }

    sort(even.begin(), even.end());
    sort(odd.begin(), odd.end());

    vector<pair<int, int> > even_count(n/2), odd_count(n/2);

    i_even = 0;
    i_odd = 0;
    int same_even_count = 0, same_odd_count = 0;
    for(int i = 1; i < n/2; i++){
        if(even[i] == even[i-1]) same_even_count++;
        if(even[i] != even[i-1] || i == n/2 - 1){
            even_count[i_even++] = make_pair(same_even_count + 1, even[i-1]);
            same_even_count = 0;
        }

        if(odd[i] == odd[i-1]) same_odd_count++;
        if(odd[i] != odd[i-1] || i == n/2 - 1){
            odd_count[i_odd++] = make_pair(same_odd_count + 1, odd[i-1]);
            same_odd_count = 0;
        }
    }

    sort(even_count.begin(), even_count.end(), greater<pair<int, int> >());
    sort(odd_count.begin(), odd_count.end(), greater<pair<int, int> >());
    int count = 0;
    if(even_count[0].second == odd_count[0].second) count = max(even_count[1].first + odd_count[0].first, even_count[0].first + odd_count[1].first);
    else count = even_count[0].first + odd_count[0].first;

    cout<<n-count<<endl;

  return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int t,p,r;
  int mp[50][13];
  //0 time 1=p problem p+1 solved p+2 num
  while(1){
    cin>>t>>p>>r;
    if(t==0 && p==0 && r==0) break;
    rep(i,t){
      rep(j,p+2){
	mp[i][j]=0;
      }
    }
    rep(i,t) mp[i][p+2]=i+1;
    int tid,pid,time;
    rep(k,r){
      cin>>tid>>pid>>time;
      string s;
      cin>>s;
      if(s=="WRONG"){
	mp[tid-1][pid]++;
      }
      else{
	mp[tid-1][0]+=time+mp[tid-1][pid]*1200;
	mp[tid-1][p+1]++;
      }
    }
    rep(i,t){
      repn(j,i){
	if(j==0) break;
	if(mp[j][p+1]>mp[j-1][p+1]) swap(mp[j],mp[j-1]);
	else if(mp[j][p+1]==mp[j-1][p+1]){
	  if(mp[j][0]<mp[j-1][0]) swap(mp[j],mp[j-1]);
	  else if(mp[j][0]==mp[j-1][0]){
	    if(mp[j][p+2]<mp[j-1][p+2]) swap(mp[j],mp[j-1]);
	    else break;
	  }
	  else break;
	}
	else break;
      }
    }
    
    rep(i,t){
      cout<<mp[i][p+2]<<" "<<mp[i][p+1]<<" "<<mp[i][0]<<endl;
    }
  }

  return 0;
}





Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int MAX = 50;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    ll K;
    cin >> N >> K;

    vector<ll> A(N); for(int i = 0; i < N; i++) cin >> A[i];
    vector<vector<ll> > dp(2, vector<ll>(100, -1));

    dp[1][0] = 0;
    for (int i = 0; i < MAX; i++) {
        ll mask = 1LL<<(MAX - i - 1);
        // A で元々 d 桁目にビットが立っているものの個数
        int num = 0;
        for (int i = 0; i < N; ++i) if (A[i] & mask) ++num;
        // X の d 桁目を 0, 1 にしたときのコスト
        ll cost0 = mask * num;
        ll cost1 = mask * (N - num);
        // smaller -> smaller
        if (dp[0][i] != -1) {
            dp[0][i+1] = max(dp[0][i+1], dp[0][i] + max(cost0, cost1)); // 0 でも 1 でも自在に大きい方
        }
        // exact -> smaller
        if (dp[1][i] != -1) {
            if (K & mask) { // K の d 桁目が 1 だったら、X の d 桁目は 0 にする
                dp[0][i+1] = max(dp[0][i+1], dp[1][i] + cost0);
            }
        }
        // exact -> exact (K にぴったり合わせる)
        if (dp[1][i] != -1) {
            if (K & mask) dp[1][i+1] = max(dp[1][i+1], dp[1][i] + cost1);
            else dp[1][i+1] = max(dp[1][i+1], dp[1][i] + cost0);
        }
    }

    cout << max(dp[0][MAX], dp[1][MAX]) << '\n';
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define INF 5000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

int ans;

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

	int n;
	cin >> n;

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

	for(int i=0; i<=(n-3); i++){
		vector<int> v(3);
		v[0] = p[i];
		v[1] = p[i+1];
		v[2] = p[i+2];
		sort(v.begin(),v.end());

		if(v[1] == p[i+1]){
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
  ll n;
  cin>>n;
  ll ac=0; ll wa=0; ll tle=0; ll re=0;
  rep(i,n){
    string s;
    cin>>s;
  if(s=="AC") ac++;
else if(s=="WA") wa++;
else if(s=="TLE") tle++;
else if(s=="RE") re++;
  }
  cout<<"AC"<<" "<<"x"<<" "<<ac<<endl;
  cout<<"WA"<<" "<<"x"<<" "<<wa<<endl;
  cout<<"TLE"<<" "<<"x"<<" "<<tle<<endl;
  cout<<"RE"<<" "<<"x"<<" "<<re<<endl;
return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF=2e18;
const ll MOD=1000000007;
vector<ll> vs[100010];
ll parent[100010];
vector<ll> children[100010];
ll depth[100010];
ll N,K;
ll ans;
void Make(ll n,ll p){
    parent[n]=p;
    depth[n]=depth[p]+1;
    for(auto v:vs[n]){
        if(v!=p){
            children[n].push_back(v);
            Make(v,n);
        }
    }
}
void Calc(ll n){
    ll k=K-min(2LL,depth[n]+1);
    if(children[n].size()>0){
        ans=(ans*k)%MOD;
        Calc(children[n][0]);
    }
    for(ll i=1;i<children[n].size();i++){
        k--;
        ans=(ans*k)%MOD;
        Calc(children[n][i]);
    }
}
int main(){
    cin>>N>>K;
    for(int i=0;i<N-1;i++){
        ll a,b;
        cin>>a>>b;
        vs[a].push_back(b);
        vs[b].push_back(a);
    }
    children[0].push_back(1);
    depth[0]=-1;
    Make(1,0);
    ans=1;
    Calc(0);
    cout<<ans%MOD<<endl;
    return 0;
}

Measured memory_bytes: 17408
import sys
import math

sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

def devide(n):
	ret = 0
	while n%2 == 0:
		ret += 1
		n //= 2
	return ret

B = [devide(a) for a in A]
# print(B)

print(sum(B))

Measured memory_bytes: 42092
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>
using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    cout << max(max(a+b, a-b),a*b) << endl;
}


Measured memory_bytes: 256
/*
 * atcoder/abc116/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
#include <queue>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * K個のSushiを選ぶ場合の最大値を求めよ.
 *
 * typeを増やしたい場合は、常にまだ選んでいないtypeの中で最高価値をもつものを選ぶのが最善.
 * typeを増やしたくない場合は、各typeのの価値２位以下の集合から最高価値を取っていくのが最善.
 * これによって意図せずtypeが増える可能性があるがその場合価値は常に高くなるので問題なし.
 *
 * これをすべてのtype数について全探索する. O(N)
 * typeが1種類の場合
 * ...
 * typeがN種類の場合
 *
 * 各探索において、各typeの最高価値のSushiの集合を価値降順にmin(type, K)件採る操作は累積和でO(1)
 * 各typeの価値２位以下のSushiの集合からK-min(type, K)件採る操作は累積和でO(1)
 *
 * 合計でO(N)のアルゴリズム.
 *
 * 事前に価値2位以下のSushi集合のソートが必要なのでO(N logN).
 */
int N, K, T = 0;
vector<ll> HIGHEST;
vector<ll> NOT_H;
vector<ll> acc_h, acc_nh;
void solve() {
  cin >> N >> K;
  HIGHEST.assign(N, 0);
  int t; ll d;
  loop(n,0,N) {
    cin >> t >> d;
    t--;
    if (HIGHEST[t] == 0) {
      HIGHEST[t] = d;
      T++;
      continue;
    }

    if (HIGHEST[t] <= d) {
      NOT_H.push_back(HIGHEST[t]);
      HIGHEST[t] = d;
    } else {
      NOT_H.push_back(d);
    }
  }

  sort(HIGHEST.rbegin(), HIGHEST.rend());
  sort(NOT_H.rbegin(), NOT_H.rend());

  acc_h.resize(N+1);
  acc_nh.resize(N+1);
  acc_h[0] = 0; acc_nh[0] = 0;
  loop(n,0,HIGHEST.size()) acc_h[n+1] = acc_h[n] + HIGHEST[n];
  loop(n,0,NOT_H.size()) acc_nh[n+1] = acc_nh[n] + NOT_H[n];

  ll max_ = 0;
  for (ll t=1; t<=min(K,T); t++) {
    // cout << t << " " << K-t << endl;
    ll tt = t*t;
    ll val = acc_h[t] + acc_nh[K-t] + tt;
    chmax(max_, val);
  }
  cout << max_ << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
ll H, W, K;
string field[10];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W >> K;
    for(int h = 0; h < H; h++) {
        cin >> field[h];
    }
    ll ans = 0;
    for(int i = 0; i < (1 << H); i++) {
        for(int j = 0; j < (1 << W); j++) {
            int num = 0;
            for(int h = 0; h < H; h++) {
                for(int w = 0; w < W; w++) {
                    if(i & (1 << h)) continue;
                    if(j & (1 << w)) continue;
                    if(field[h][w] == '#') num++;
                }
            }
            if(num == K) {
                //cerr << i << " " << j << endl;
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	int n=read<int>();

	bool flag=false;

	if(n%10==7) flag=true;
	n/=10;
	if(n%10==7) flag=true;
	n/=10;
	if(n%10==7) flag=true;

	if(flag) puts("Yes");
	else puts("No");

	return 0;

}


Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

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

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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 main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int m, nmax, nmin;
  int P[222];
  while (true) {
    cin >> m >> nmin >> nmax;
    if (m == 0 && nmin == 0 && nmax == 0) break;
    for (int i = 0; i < m; i++) cin >> P[i];
    int ans = 0, dist = 0, mi = 0, cnt = 0;
    for (int i = 0; i < m; i++) {
      
      if (cnt + 1 < nmin) {
        mi = P[i];
        cnt++;
        continue;
      }
      mi = P[i];
      cnt++;
      if (nmax < cnt) break;
      if (dist <= mi - P[i + 1] && i + 1 < m) {
        dist = mi - P[i + 1];
        ans = cnt;
      }
    }
    cout << ans << "\n";
  }

  return 0;
}


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

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

    cout << 0 << endl;
    string s; cin >> s;
    map<string, int> mp;
    if(s=="Male") mp["Male"] = 0, mp["Female"] = 1;
    else if(s=="Female") mp["Male"] = 1, mp["Female"] = 0;
    else return 0;

    int left = -1, right = N;
    while(1<right-left){
        int mid = (left+right) / 2;
        cout << mid << endl;
        cin >> s;
        if(s=="Vacant") return 0;
        else if(mid%2!=mp[s]) right = mid;
        else left = mid;
    }
    cout << N - 1 << endl;
    cin >> s;
    return 0;
}

Measured memory_bytes: 980
#include <iostream>

 using namespace std;

 int main(void){
 int K;
 cin >> K;

 int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2,
1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
 cout << a[K-1] << endl;

 return 0;
}

Measured memory_bytes: 256
'use strict'
const main = (input: string) => {
    // 解説読みました
    const [l, r] = input.trim().split(' ').map(Number)
    const lmod = l % 2019
    const rmod = r % 2019
    if (r - l >= 2018) return console.log(0)
    let result = Infinity
    for (let i = lmod; i < rmod; i++) {
        for (let j = i+1; j <= rmod; j++) {
            result = Math.min(result, (i*j) % 2019)
        }
    }
    console.log(result)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7484