akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	int circleLeft = x - r;
	int circleRight = x + r;
	int circleBottom = y - r;
	int circleTop = y + r;

	if ((circleLeft >= 0) && (circleRight <= W) && (circleBottom >= 0) && (circleTop <= H))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}




Measured memory_bytes: 3132
n=int(input())
a=sorted(map(int,input().split()),reverse=True)
i=1;l=0;r=0
while(i<n):
  if a[i-1]==a[i]:
    if l==0:l=a[i];i+=1
    else:r=a[i];i=n
  i+=1
print(l*r)

Measured memory_bytes: 14252
//include
//------------------------------------------
#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>

using namespace std;


#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


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



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

	int r = n % 7;
	int p = n / 7;

	while (true) {
		if (r%4 == 0) {
			ANS("Yes");
			break;
		}
		if (p <= 0) {
			ANS("No");
			break;
		}
		p--;
		r += 7;
	}



	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#define ll long long
#define N 100000
int n,k,a[N];
int chex(ll b){
  int i = 0,j,c;
    for(j = 0; j < k; j++){
        c = 0;
        while(c+a[i] <= b){
            c += a[i];
            i++;
            if(i == n)return n;
        }
    }
    return i;
}
int main(){
  int i,b;
  ll mid,min = 0,max = 100000*10000;
  scanf("%d %d",&n,&k);
  for(i = 0; i < n; i++) scanf("%d",&a[i]);

  while(min + 1 < max){
    mid = (max + min) / 2;
    b = chex(mid);
    if( b < n) min = mid;
    else max = mid;
  }
  
  printf("%d\n",max);
  
  return 0;
}




Measured memory_bytes: 2244
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;


int main()
{
    Go_
    int a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    
    cin>>n;
    bl=true;
    for(i=0;i<n;i++) {
        cin>>x;
        if(x%2==0){
            if((x % 3 != 0) && (x % 5 != 0)) bl=false;
            //if() bl=false;
        }
    }
    if(bl) cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
    
}

Measured memory_bytes: 256
a = input()
l =list(map(int, input().split()))
t = 0
for i,j in zip(l,l[1:]):
    if i-j==1:t+=1
    elif i-j>1:t+=2
    elif j-i>0:t=0
    if t>1:
        print("No")
        exit(0)
print("Yes")

Measured memory_bytes: 14396
N = int(input())
s = input()

mod = 10**9+7
dp = [[0]*N for _ in range(N)]
t = [1]*N
if s[0] == "<":
    t[0] = 0
else:
    t[N-1] = 0
dp[0] = t

S = [0]*(N+1)
for i in range(N):
    S[i+1] = S[i] + dp[0][i]
     
for i in range(N-1):
    if s[i] == "<":
        for j in range(N-1):
            dp[i+1][j] = S[N] - S[j+1]
    else:
        for j in range(N):
            if i+j+1 < N:
                dp[i+1][j] = S[j+1]
                
    S = [0]*(N+1)
    for j in range(N):
        dp[i+1][j] %= mod
        S[j+1] = S[j] + dp[i+1][j]
        S[j+1] %= mod
        
print(dp[N-1][0])

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    string s;
    cin >> s;
    int a = (s[0]-'0') * 10 + (s[1]-'0');
    int b = (s[2]-'0') * 10 + (s[3]-'0');
    bool MMYY = (a>=1&&a<=12), YYMM = (b>=1&&b<=12);
    if (MMYY) {
        if (YYMM) puts("AMBIGUOUS");
        else puts("MMYY");
    }
    else {
        if (YYMM) puts("YYMM");
        else puts("NA");
    }
    return 0;
}


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

const int maxn = 1e5+10;
int n,x;
multiset<int>a;
multiset<int>::iterator it;

int main()
{
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&x);
        if(a.empty())
            a.insert(x);
        else
        {
            it = a.lower_bound(x);
            if(it==a.begin())
                a.insert(x);
            else
            {
                it--;
                a.erase(a.find(*it));
                a.insert(x);
            }
        }
    }
    int ans = a.size();
    printf("%d\n",ans);
    return 0;
}


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

int battle(uint64_t &monster, uint64_t &yu_sya)
{
    int win = min(monster, yu_sya);
    
    monster -= win;
    yu_sya -= win;
    
    return win;
}

int main(int argc, const char * argv[])
{
    uint64_t N;
    cin >> N;
    
    vector<uint64_t> A;
    for (uint64_t i = 0; i < N+1; i++) {
        uint64_t tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    
    vector<uint64_t> B;
    for (uint64_t i = 0; i < N; i++) {
        uint64_t tmp;
        cin >> tmp;
        B.push_back(tmp);
    }
    
    uint64_t win = 0;
    uint64_t nokori_yu_sya = 0;
    for (uint64_t i = 0; i < N + 1; i++) {
        uint64_t monster = A[i];
        uint64_t yu_sya;
        if (i == N) {
            yu_sya = 0;
        }else {
            yu_sya = B[i];
        }
        
        if (nokori_yu_sya > 0) {
            win += battle(monster, nokori_yu_sya);
        }
        win += battle(monster, yu_sya);
        
        nokori_yu_sya = yu_sya;
    }
    
    cout << win << endl;
    
    return 0;
}


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

using namespace std;
int n,k;
int ar[100005];
long long mem[100005];

long long solve(int ind){
    if(ind==n-1){
        return 0;
    }
    if(ind>n-1){
        return 1e11;
    }
    if(mem[ind]!=-1){
        return mem[ind];
    }
    long long mn=1e18;
    for(int i=1;i<=k;i++){
        mn=min(mn,solve(ind+i)+abs(ar[ind+i]-ar[ind]));
    }
    return mem[ind]=mn;
}

int main() {
    //freopen("input.in", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(mem,-1,sizeof mem);
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    cout<<solve(0)<<endl;
    return 0;
}

Measured memory_bytes: 6144
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int n;
int f[370];
int p[370];
int ft[370];
int pt[370];
int ans[370];
int main(){
	cin>>n;
	for(int i = 0;i < n;i++){
		int sum1 = 0;
		int sum2 = 0;
		int suma = 0;
		int sumb = 0;
		int sumc = 0;
		cin>>f[i]>>p[i]>>ft[i]>>pt[i];
		sum1 = f[i]*ft[i]+p[i]*pt[i];
		if(ft[i]>=5&&pt[i]>=2){
			sum2 =(f[i]*ft[i]+p[i]*pt[i])*0.8;
			ans[i] =min(sum1,sum2);
			continue;
		}
		if(ft[i]<5&&pt[i]<2){
			suma =(5*(f[i])+2*(p[i]))*0.8;
			ans[i] = min(sum1,suma);
			continue;
		}
		if(ft[i]>=5&&pt[i]<2){
			sumb = (f[i]*ft[i]+p[i]*2)*0.8;
			ans[i] =min(sum1,sumb);
			continue;
		}
		if(ft[i]<5&&pt[i]>=2){
			sumc = (f[i]*5+p[i]*pt[i])*0.8;
			ans[i] =min(sum1,sumc);
			continue;
		}
	}
	rep(i,n){
		cout <<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1172
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *XYH = map(int, read().split())

    for x, y, h in zip(*[iter(XYH)] * 3):
        if h != 0:
            x0, y0, h0 = x, y, h

    for cx in range(101):
        for cy in range(101):
            H = h0 + abs(x0 - cx) + abs(y0 - cy)
            ok = True
            for x, y, h in zip(*[iter(XYH)] * 3):
                if max(H - abs(x - cx) - abs(y - cy), 0) != h:
                    ok = False
                    break
            if ok:
                print(cx, cy, H)
                return

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 73652
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

void dfs(ll curr, vector<pair<ll,ll>> v[], set<ll> &st)
{
    for(auto it = v[curr].begin();it!=v[curr].end();it++)
    {
        if(st.find(it->ff) != st.end())
            continue;
        st.insert(it->ff);
        dfs(it->ff,v,st);
    }
}

int main()
{
   FAST/**/
   
   ll n,m,p;
   cin>>n>>m>>p;
   
   vector<pair<ll,ll>> v[n];
   vector<pair<pair<ll,ll>,ll>> ed;
   set<ll> reach;
   reach.insert(n-1);
   set<ll> r1;
   vector<pair<ll,ll>> v1[n];
   r1.insert(0);
   //bool reach[n][n];
   //memset(reach,0,sizeof(reach));
   for(ll i=0;i<m;i++)
   {
       ll a,b,c;
       cin>>a>>b>>c;
       a--,b--;
      // reach[a][b] = 1;
       //v[a].pb(mp(b,c));
       v[b].pb(mp(a,c));
       v1[a].pb(mp(b,c));
       ed.pb(mp(mp(a,b),c));
   }
   
   dfs(n-1,v,reach);
   dfs(0,v1,r1);
   if(reach.find(0) == reach.end())
   {
       cout<<-1;
       return 0;
   }
   
   ll dis[n];
   for(ll i=0;i<n;i++)
        dis[i] = -inf;
   dis[0] = 0;        
   
   for(ll i=0;i<n-1;i++)
   {
       for(ll j=0;j<m;j++)
       {
           ll u = ed[j].ff.ff;
           ll v = ed[j].ff.ss;
           ll cst = ed[j].ss;
           dis[v] = max(dis[v], dis[u] + cst - p);
       }
   }
   
   bool pos = 1;
   //ll temp = dis[n-1];
   //temp = max(temp, (ll)0);
   for(ll j=0;j<m;j++)
   {
       ll u = ed[j].ff.ff;
       ll v = ed[j].ff.ss;
       ll cst = ed[j].ss;
       if(dis[v]<dis[u] + cst - p)
       {
           if(reach.find(v)!=reach.end() && r1.find(v)!=r1.end())
           {
               pos = 0;
               break;
           }
           else
                dis[v]=dis[u] + cst - p;
       }
   }
   
   if(pos == 0)
   {
       cout<<-1;
       return 0;
   }
       
   
   cout<<max(dis[n-1],(ll)0);
   
   return 0;        
}  
   

Measured memory_bytes: 1024
#pragma GCC optimize(2)
#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;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    map<int, int> tb;
    bitset<3> bingo[3];
    FOR(i, 0, 3) { bingo[i].reset(); }
    int n;
    int x;
    FOR(i, 0, 9)
    {
        cin >> x;
        tb.insert({x, i});
    }
    cin >> n;
    FOR(i, 0, n)
    {
        cin >> x;
        if (tb.find(x) == tb.end())
        {
            continue;
        }
        int res = tb[x];
        int a = res / 3, b = res % 3;
        bingo[a][b] = true;
    }
    bool ok = false;
    if(bingo[0][0] && bingo[1][1] && bingo[2][2])
    {
        ok = true;
    }
    if(bingo[0][2] && bingo[1][1] && bingo[2][0])
    {
        ok = true;
    }
    FOR(i, 0, 3)
    {
        if(bingo[0][i] && bingo[1][i] && bingo[2][i])
        {
            ok = true;
        }
        if(bingo[i][0] && bingo[i][1] && bingo[i][2])
        {
            ok = true;
        }
    }
    cout << (ok ? "Yes\n" : "No\n");
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

upper = lower = float(stdin.readline())
for line in stdin:
    h = float(line)
    if h > upper:
        upper = h
    elif h < lower:
        lower = h
print(upper - lower)

Measured memory_bytes: 4244
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll N,K;
    cin>>N>>K;
    cout<<min(N%K,K-(N%K));
    return 0;
}

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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1000000000;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong n;
    cin >> n;

    string ans = "";
    while (n) {
        n -= 1LL;
        ans += 'a' + (n % 26);
        n /= 26;
    }

    reverse(all(ans));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3648
a, b, c = map(str, input().split())
a_arr = list(a)
a_tail = a_arr[-1]

b_arr = list(b)
b_head = b_arr[0]
b_tail = b_arr[-1]

c_arr = list(c)
c_head = c_arr[0]

if a_tail == b_head:
   if b_tail == c_head:
      print("YES")
   else:
      print("NO")
else:
   print("NO")

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

int main(){
  int N,T,c,t,minI,minC;
  vector<int> cs,ts;
  cin >>N>>T;
  for(int i=0;i<N;i++){
    cin >>c>>t;
    if(t<=T){
      cs.push_back(c);
      ts.push_back(t);
    }
  }
  if(ts.size()==0){
    cout<<"TLE";
  }
  else{
  	minI=0;
  	minC=cs[minI];
  	for(int i=0;i<cs.size();i++){
    	if(minC>cs[i]){
      	minI=i;
      	minC=cs[minI];
    	}
  	}
    cout <<minC;
  }
}

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

long long calc(int i, int j, vector<vector<long long>>& memo){
    if(i < 0 || j < 0)return 0;
    if(memo[i][j] >= 0)return memo[i][j];
    return memo[i][j] = calc(i - 1, j, memo) + calc(i, j - 1, memo);
}

int main(){
    long long a, b, n, x, y;
    while(cin >> a >> b){
        if(a == 0 && b == 0)break;
        
        vector<vector<long long>> dp(a, vector<long long>(b, -1));
        dp[0][0] = 1;
        
        cin >> n;
        for(int i = 0; i < n; ++i){
            cin >> x >> y;
            dp[x - 1][y - 1] = 0;
        }
        
        cout << calc(a - 1, b - 1, dp) << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if(n == 1) {
        cout << "Hello World" << endl;
    } else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

struct st{
	string a;
	int b,c;
};
int main(){
	int n;cin>>n;
	vector<st>v;
	rep(i,n){
		st a;
		cin>>a.a>>a.b;
		a.c=i+1;
		v.push_back(a);
	}
	sort(v.begin(),v.end(),[](st a,st b){
		if(a.a==b.a)return a.b>b.b;
		return a.a<b.a;
	});
	for(auto s:v){
		cout<<s.c<<endl;
	}
}

Measured memory_bytes: 256
/*
*  author: mkbaloch
*  time:   2019-12-31 14:24:20
*/

#include<bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for(int i=a; i<=b; i++)
#define repn(i, n) for(int i=0; i<(int)n; i++)

using namespace std;

int main()
{
 string a, b;
 cin >> a >> b;
 cout << b + a << endl;
 return 0;
}


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

int main(){
	int N;
	cin >> N;
	
	int cnt=0;
	int pre=0;
	int ans=1;   //入力が１の時は１が正解
	for(int i=1; i<=N; i++){
		int n=i;
		
		//割れる回数を計算
		int cnt=0;
		while(n%2==0){
			cnt++;
			n/=2;
		}
	
		//割れる回数がそれまでを上回ったら上書き
		if(cnt>pre){
			pre=cnt;
			ans=i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

int n;
int t[20][20];
int dp[20][1 << 20];
bool vis[20][1 << 20];

int solve(int x, int y)
{
    if (vis[x][y])
        return dp[x][y];
    vis[x][y] = true;
    int res = t[x][0];
    rep(i, n) if (y & (1 << i))
        res = min(res, t[x][i + 1]);
    y += (1 << x);
    int nxt = INF;
    rep(i, n)
    {
        if (y & (1 << i))
            continue;
        nxt = min(nxt, solve(i, y));
    }
    if (nxt == INF)
        nxt = 0;
    return dp[x][y - (1 << x)] = res + nxt;
}

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

    while (1)
    {
        cin >> n;
        if (n == 0)
            break;
        rep(i, n) rep(j, n + 1) cin >> t[i][j];
        rep(i, n) rep(j, 1 << n) vis[i][j] = false;
        int ans = INF;
        rep(i, n) ans = min(ans, solve(i, 0));
        cout << ans << endl;
    }
}


Measured memory_bytes: 11156
#include<iostream>
#include<algorithm>
#include<string>
 
using namespace std;
 
int dp[1001][1001];
 
int main(){
 
  string s1,s2;
  cin>>s1>>s2;
  for(int i=0;i<=s1.length();i++){
    dp[i][0] = i;
  }
  for(int j=0;j<=s2.length();j++){
    dp[0][j] = j;
  }
 
  for(int i=1;i<=s1.length();i++){
    for(int j=1;j<=s2.length();j++){
      int k=0;
      if(s1[i-1]==s2[j-1]){
	k=0;
      }else{
	k=1;
      }
      dp[i][j]=min(dp[i-1][j]+1,min(dp[i][j-1]+1,dp[i-1][j-1]+k));
    }
  }
  cout<<dp[s1.length()][s2.length()]<<endl;
  return 0;
}



Measured memory_bytes: 7132
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void run() {
		PrintWriter pw = new PrintWriter(System.out);
		Scanner sc = new Scanner();
		int N = sc.nextInt();
		if (N == 3) {
			System.out.println(2 + " " + 5 + " " + 63);
			return;
		}
		N -= 4;
		System.out.print(2 + " " + 4 + " " + 3 + " " + 9 + (N == 0 ? "\n" : " "));
		int MAX = 30000;
		for (int i = 8; i <= MAX && N >= 2; i += 6) {
			System.out.print(i + " " + (i + 2));
			N -= 2;
			System.out.print(N == 0 ? "\n" : " ");
		}
		for (int i = 15; i <= MAX && N >= 2; i += 12) {
			System.out.print(i + " " + (i + 6));
			N -= 2;
			System.out.print(N == 0 ? "\n" : " ");
		}
		for (int i = 6; i <= MAX && N >= 1; i += 6) {
			System.out.print(i);
			N -= 1;
			System.out.print(N == 0 ? "\n" : " ");
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

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

}


Measured memory_bytes: 27492
N, M = map(int, input().split())
A = []
B = []
for i in range(N):
  A.append(input())
for i in range(M):
  B.append(input())
f = 0
for i in range(N - M + 1):
  for j in range(N - M + 1):
    g = 0
    for k in range(M):
      for l in range(M):
        if A[i+k][j+l] != B[k][l]:
          g = 1
          break
      if g == 1:
        break
    if g == 0:
      print("Yes")
      f = 1
      break
  if f == 1:
    break
if f == 0:
  print("No")

Measured memory_bytes: 63640
n, k = [int(i) for i in input().split()]
stock = []
for i in range(n):
	stock.append(int(input()))
stock = sorted(stock)
ret = 1000000000
for i in range(n - k + 1):
	length = stock[i+k-1] - stock[i]
	ret = min(ret, length)
print (ret)


Measured memory_bytes: 8280
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
const int NEGA=-INF; 
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair
#define INT int_64

ll ans = 0;
int a;
int main() 
{
    int n;
    cin>>n;
    int cl[9]={0};
    rep(i,n){
     cin>>a;
     if(a/400<8) cl[a/400]=1;
     else cl[8]++;
    }
    int kind=0;
    rep(i,8) kind+=cl[i];
    if(kind==0) {
        kind++;
        cl[8]--;
    }
    cout<<kind<<" "<<kind+cl[8]<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
int d=365;
vector<int> ans(d);
vector<int> ans1(d);
vector<int> c(26);
vector<vector<int> > s(d);
int score=-1000000000;
int keisan(){
  int cost=0,i,j,k=0;
  vector<int> x(26,-1);
  for(i=0;i<d;i++){
    cost+=s[i][ans1[i]];
    x[ans1[i]]=i;
    for(j=0;j<26;j++){
      cost=cost-c[j]*(i-x[j]);
    }
  }
  return cost;
}
void solve(){
  int i;
  if(score<=keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
    score=keisan();
    int v=randxor()%d;
    int w=randxor()%d;
    swap(ans1[v],ans1[w]);
  }
  else{
    for(i=0;i<d;i++){
      ans1[i]=ans[i];
    }
  }
}
void solve1(){
  int i;
  if(score<=keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
    score=keisan();
    ans1[randxor()%d]=randxor()%26;
  }
  else{
    for(i=0;i<d;i++){
      ans1[i]=ans[i];
    }
  }
}
int main(){
  int i,j;
  int ti=clock();
  cin >> d;
  for(i=0;i<26;i++){
    scanf("%d",&c[i]);
  }
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      int a;
      scanf("%d",&a);
      s[i].push_back(a);
    }
  }
  for(i=0;i<d;i++){
    ans1[i]=i%26;
    ans[i]=ans1[i];
  }
  while(clock()-ti<198.2*CLOCKS_PER_SEC/100){
    solve();
    solve1();
    solve();
  }
  for(i=0;i<d;i++){
    printf("%d\n",ans[i]+1);
  }
  return 0;
}

Measured memory_bytes: 3888
// thanks to https://codeforces.com/blog/entry/23554
#include <cstdio>
#include <cmath>
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.8lf", sqrt(d));
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sort(v) sort(all(v))
#define ff first
#define ss second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define MODE 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    IOS
    vector<int> a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(a);
    cout<<a[0]+a[1];
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int count = 0;
		for (int i = a;i <= b; i++) {
			if(c % i ==00) {
				count++;

			}
			if (i == b);


		}
		System.out.println(count);



	}
}


Measured memory_bytes: 26364
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;  //10000  5000  1000
int main()
{
	int a,ans=0;
	long long n;
	cin>>n;
	for(int i=sqrt(n);i>=1;i--)
	{
		if(n%i==0)
		{
			a=n/i;
			break;
		}		
	}
	for(;a>=1;)
	{
		a=a/10;
		ans++;
	}
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
N,*D = `dd`.split.map &:to_i
if D[0] != 0
  p 0
  exit
end
D.sort!
Mod = 998244353
ans = 1
cs = {}
D.each{ |d|
  if d == 0
    if cs[d]
      ans = 0
      break
    end
  else
    ans = ans * (cs[d-1] || 0) % Mod
  end
  cs[d] = (cs[d] || 0) + 1
}
p ans

Measured memory_bytes: 15472
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int w,n;

  cin >> w >> n;

  vector<int> line(w);
  for(int i = 0; i < w; i++) {
    line[i]=i;
  }
  int t = 0;
  while(t < n) {
    int a,b;
    char c;
    cin >> a >> c  >> b;
    line[a-1] ^= line[b-1];
    line[b-1] ^= line[a-1];
    line[a-1] ^= line[b-1];
    
    t++;
  }

  for(auto l : line)
    cout << l+1 << endl;
  
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  vector<int64_t> B(N);
  //数字iの個数がB.at(i-1)に格納される
  
  for(int i=0; i<N; i++){
    cin >> A.at(i);
    B.at(A.at(i)-1)++;
  }
  
  int64_t max=0;
  for(int i=0; i<N; i++){
    int64_t b = B.at(i);
    max += (b)*(b-1)/2;
  }
  
  vector<int64_t> C(N);
  //k=iの時の答えをC.at(i-1)に格納
  
  for(int i=0; i<N; i++){
    int64_t tmp=max;
    int64_t a = A.at(i);
    int64_t b = B.at(a-1);
    tmp -= b*(b-1)/2;
    tmp += (b-1)*(b-2)/2;
    cout << tmp << endl;
  }
  
}


// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));
 
  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
   // }
  //}


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

#define chmin(x,y) x=min(x,y)

const int N=55;
const long long INF=10000000000000000ll;
int n,tmn,d,ans;
int p[N],sz[N];
long long mn[N];
long long dp[N][N*N*N];
int lim[N],lft[N];
vector<int> son[N];
int ord[N];

void dfs(int x){
	sz[x]=1;
	for(int i=0;i<son[x].size();i++){
		int to=son[x][i];
		dfs(to);
		sz[x]+=sz[to];
		mn[x]+=mn[to];
	}
}

bool cmp(int x,int y){
	return mn[y]*sz[x]>mn[x]*sz[y];
}

int main(){
	scanf("%d%d%d",&n,&tmn,&d);
	scanf("%lld",mn+1);
	for(int i=2;i<=n;i++){
		scanf("%lld%d",mn+i,p+i);
		son[p[i]].push_back(i);
	}
	dfs(1);
//	for(int i=1;i<=n;i++) printf("%d %lld\n",sz[i],mn[i]);
	for(int i=1;i<=n;i++) ord[i]=i;
	sort(ord+1,ord+1+n,cmp);
//	for(int i=1;i<=n;i++) printf("%d ",ord[i]);puts("");
	lim[1]=50;
	lft[1]=INT_MAX/2;
	for(int i=2;i<=n;i++){
		lim[i]=min(50,d);
		lft[i]=d-lim[i];
	}
//	for(int i=1;i<=n;i++) printf("%d ",lft[i]);puts("");
	for(int i=0;i<N;i++) for(int j=0;j<N*N*N;j++) dp[i][j]=INF;
	dp[0][0]=0ll;
	for(int i=1;i<=n;i++) for(int j=0;j<N*N*N;j++) if(dp[i-1][j]!=INF){
		long long res=dp[i-1][j];
		for(int k=0;k<=lim[i];k++) chmin(dp[i][j+k*sz[i]],res+mn[i]*k);
	}
	for(int i=0;i<N*N*N;i++) if(dp[n][i]<=1ll*tmn){
//		printf("%d %d %d\n",n,i,dp[n][i]);
		int res=i;
		int ml=1ll*tmn-dp[n][i];
		for(int j=1;j<=n;j++){
			int x=ord[j];
			int ch=int(min(1ll*ml/mn[x],1ll*lft[x]));
			res+=ch*sz[x];
			ml-=ch*mn[x];
		}
		ans=max(ans,res);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 75308
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
#include <bitset>
#include<math.h>
#include<list>
#include<map>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979323846  

int main() {
	int a, b, ans;
	cin >> a >> b;
	for (int i = 1; i <= 3; i++) {
		if (i != a && i != b) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
}

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

ll dp[1005][9000];
ll keys[1005], cost[1005];
ll boxes,m;
ll ans, total;

ll F(ll cur, ll in){
	if(in == m){
		if(cur == total)return 0;
		else return 1e15;
	}
	if(dp[in][cur] != -1)return dp[in][cur];
   	ll a = F(cur,in + 1);	
	ll b = F(cur | keys[in], in + 1) + cost[in];
	return dp[in][cur] = min(a,b);
}

void doit(){
	cin >> boxes;
	ll i;
	rep(i,0,boxes)total |= 1LL << i;
	cin >> m;
	rep(i,0,m){
		ll x, C;
		cin >> cost[i] >> x;
		ll j, cur = 0;
		rep(j,0,x){
			cin >> C;
			cur |= (1LL << (C - 1));
		}
		keys[i] = cur;
	}
	memset(dp, -1, sizeof(dp));
	ans = 1e15;
	ans = F(0,0);
	if(ans == 1e15)cout << -1 << nl;
	else cout << ans << nl;
}
int main() {
#ifndef ONLINE_JUDGE
//    freopen("input1.txt","r",stdin);
//    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 74348
//In the name of ALLAH
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define MP make_pair
const bool DEBUG = false;
#define cerr if(DEBUG)cerr
using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long long maxn = 2e5 + 5;
const long long INF = 1e18 + 1;
const long long inf = 1e9 + 5;
const long long M = 1e9 + 7;
const int lg = 21;

ll ans = INF, n, a[maxn], A[maxn];

ll sum(ll l, ll r){
	if(l > r) return 0;		
	if(l == 0) return A[r];
	return A[r] - A[l - 1];
}

pair<pll, pll> f(ll l, ll r){	
	int low = l, high = r, mid = 0;
	while(high - low > 1){
		mid = high + low >> 1;
		if(sum(l, mid) <= sum(mid + 1, r))
			low = mid;
		else
			high = mid;		
	}
	if(low == r - 1)
		return MP(MP(sum(l, low), sum(low + 1, r)), MP(0, INF));
	return MP(MP(sum(l, low), sum(low + 1, r)), MP(sum(l, low + 1), sum(low + 2, r)));
}

ll CHECK(pll a, pll b){
	return max({a.X,a.Y,b.X,b.Y})-min({a.X,a.Y,b.X,b.Y});
}

ll check(ll mid){
	pair<pll, pll> a = f(0, mid - 1);
	pair<pll, pll> b = f(mid, n - 1);
	return min({CHECK(a.X, b.X), CHECK(a.X, b.Y), CHECK(a.Y, b.X), CHECK(a.Y, b.Y)});
}

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	A[0] = a[0];
	for(int i = 1; i < n; i++)
		A[i] = A[i - 1] + a[i];
	for(int i = 2; i <= n - 2; i++){
		ans = min(ans, check(i));
	}	
	cout << ans << endl;
	return 0;
}


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

int main(){
	string n;
	cin >> n;

	int ans = 0;
	for (int i = 0;i < n.size();i++) {
		if (n[i] != '0') {
			int sum = 0;
			for (int j = 0;j < n.size();j++) {
				if (j < i) {
					sum += n[j] - '0';
				}
				else if (j == i) {
					sum += n[j] - '0' - 1;
				}
				else {
					sum += 9;
				}
			}
			ans = max(ans, sum);

		}
	}
	int sum = 0;
	for (int j = 0;j < n.size();j++) {
		sum += n[j] - '0';
	}
	ans = max(ans, sum);
	cout << ans << endl;




	return 0;
}

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

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

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

  int H, W; cin >> H >> W;
  vector<string> a(H);
  rep(i, H) cin >> a[i];

  int cnt = 0;
  rep(i, H) rep(j, W) {
    if(a[i][j] == '#') cnt++;
  }

  cout << (cnt == H+W-1 ? "Possible" : "Impossible") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = long long;
// using ll = boost::multiprecision::int128_t;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;


map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}


int invtr(ll x) {
  ll z = 0;
  while (z*(z+1)/2 <= x) ++z;
  return z-1;
}

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

  ll ans = 0;
  for(auto p : prime_factor(N)) {
    ans += invtr(p.second);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3660
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 300010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, q;
ll p[MAXN], P[10][MAXN];
ll t[MAXN*8], lazy[MAXN*8];

ll MOD = 998244353;

ll add(ll a, ll b) {
    return (a + b) % MOD;
}

ll sub(ll a, ll b) {
    return (a - b + MOD) % MOD;
}

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

void build(int k, int l, int r) {
    if (l > r) return;
    if (l == r) {
        t[k] = 1;
        return;
    }
    int m = (l + r) >> 1;
    build(k*2, l, m);
    build(k*2+1, m+1, r);
    t[k] = add(mul(t[k*2], p[r - m]), t[k*2+1]);
}

void lazyUpdate(int k, int l, int r) {
    if (l > r) return;
    if (lazy[k] == 0) return;
    t[k] = P[lazy[k]][r-l+1];
    if (l < r) {
        lazy[k*2] = lazy[k];
        lazy[k*2+1] = lazy[k];
    }
    lazy[k] = 0;
}

void update(int k, int l, int r, int u, int v, int val) {
    lazyUpdate(k, l, r);
    if (l > r || r < u || v < l) return;
    if (u <= l && r <= v) {
        lazy[k] = val;
        lazyUpdate(k, l, r);
        return;
    }
    int m = (l + r) >> 1;
    update(k*2, l, m, u, v, val);
    update(k*2+1, m+1, r, u, v, val);
    t[k] = add(mul(t[k*2], p[r - m]), t[k*2+1]);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    p[0] = 1;
    FOR(i,1,300000) p[i] = p[i-1] * 10 % MOD;
    FOR(i,1,9) {
        P[i][0] = 0;
        FOR(j,1,300000) P[i][j] = add(mul(P[i][j-1], 10), i);
    }
    cin >> n >> q;
    build(1,1,n);
    while (q--) {
        int l, r, x;
        cin >> l >> r >> x;
        update(1,1,n,l,r,x);
        cout << t[1] << "\n";
    }
    return 0;
}


Measured memory_bytes: 35300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    string S;
    cin >> S;
    bool ret = true;
    if(S.size() % 2 != 0) {
        ret = false;
    }
    for(int i = 0;i < S.size() - 1;i += 2) {
        if(!(S.at(i) == 'h' && S.at(i + 1) == 'i')) {
            ret = false;
        }
    }
    if(ret == true) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

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 U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};



int main(void){
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int a,b;
    cin >> a >> b;
    print(max(0, a - 2 * b));
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,t,T[30],dp[101][30],a[101];
main()
{
	while(cin>>t,t)
	{
		for(int i=0;i<t;i++)cin>>T[i];
		for(int i=0;i<=100;i++)
		{
			a[i]=23;
			for(int j=0;j<t;j++)dp[i][j]=1e9;
		}
		cin>>n;
		for(;n--;)
		{
			int d,m;cin>>d>>m;
			a[d-1]=min(a[d-1],m);
		}
		dp[0][0]=0;
		for(int i=0;i<100;i++)
		{
			for(int j=0;j<t;j++)
			{
				if(a[i+1]>=T[(j+1)%t])dp[i+1][(j+1)%t]=min(dp[i+1][(j+1)%t],dp[i][j]);
				dp[i+1][0]=min(dp[i+1][0],dp[i][j]+1);
			}
		}
		int ans=1e9;
		for(int i=0;i<t;i++)ans=min(ans,dp[100][i]);
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3016
import Data.List
import Control.Monad
g a b = compare (head a) (head b)
f a m r = if m==0 then r else if m-((last.head) a)<0 then r+((head.head)a*m) else f (tail a) (m-(last.head)a) (r+(product.head) a)
main=do
 [n,m]<-map read.words<$>getLine
 a<-sortBy g.map (map read.words)<$>replicateM n getLine
 print$f a m 0

Measured memory_bytes: 155004
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int L = s.length();
		String[] Num = s.split("");
		int[] num = new int[L];
		int min = 999;
		for(int i = 0; i < L; i++) {
			num[i] = Integer.parseInt(Num[i]);
		}
		for(int i = 0; i <= L-3; i++) {
			int sft = num[i]*100 + num[i+1]*10 + num[i+2];
			int dif = Math.abs(sft-753);
			min = Math.min(min, dif);
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
typedef long long int ll;
 
using namespace std;
// {{{ Modint
// using mint = modint<1000000007>;
// mint x = 2;
// std::cout << x.a << std::endl;
template <std::int64_t M>
class modint {
public:
  int64_t a;
 
  explicit constexpr modint(const int64_t x = 0) noexcept :
    a((x % M + M) % M) {}
  constexpr int64_t &value() noexcept { return a; }
  constexpr const int64_t &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= M) {
      a -= M;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += M;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % M;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    int64_t exp = M - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  constexpr modint pow(ll t) const {
    if (!t) return modint(1);
    modint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};
// }}}
using mint = modint<1000000007>;
 
ll N, K;
mint dp[61][64][64];
 
int main() {
  cin >> N >> K;
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      ll x;
      cin >> x;
      dp[0][i][j] = mint(x);
    }
  }
  for (int k=1; k<61; k++) {
    for (int i=0; i<N; i++) {
      for (int j=0; j<N; j++) {
        for (int u=0; u<N; u++) {
          dp[k][i][j] += dp[k-1][i][u] * dp[k-1][u][j];
          //if (dp[k][i][j].value() > 0) {
          //  printf("dp[%d][%d][%d]=%d\n",k,i,j,dp[k][i][j]);
          //}
        }
      }
    }
  }
  vector<mint> c(N, mint(1));
  for (int k=0; k<61; k++) {
    if (((((ll)1)<<k) & K)) {
      vector<mint> nc(N, mint(0));
      for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
          nc[j] += c[i] * dp[k][i][j];
        }
      }
      c = nc;
    }
  }
  mint ans;
  for (int i=0; i<N; i++) {
    ans += c[i];
  }
  cout << ans.value() << endl;
  return 0;
}

Measured memory_bytes: 1920