akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

const int MAX_N = 14;

int n;
unsigned int subcnt[MAX_N][MAX_N];
int memo[1 << MAX_N][MAX_N];

unsigned int solve(int S, int v)
{
  if (S == (1 << n)-1)
    return 0;

  if (memo[S][v] != -1)
    return memo[S][v];

  unsigned int ret = 1 << 30;
  for (int i = 0; i < n; ++i) {
    if (!(S & (1 << i)))
      ret = min(ret, solve(S | (1 << i), i)+subcnt[v][i]);
  }
  return memo[S][v] = ret;
}

int main()
{
  while (cin >> n) {
    if (n == 0)
      break;

    vector<string> name(n);
    for (int i = 0; i < n; ++i)
      cin >> name[i];

    for (int i = 0; i < (1 << MAX_N); ++i) {
      for (int j = 0; j < MAX_N; ++j)
	memo[i][j] = -1;
    }

    int S = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
	if (i == j)
	  continue;
	subcnt[i][j] = name[j].size();
	if (name[i].find(name[j]) != string::npos) {
	  if (!(S & (1 << i)))
	    S |= 1 << j;
	} else {
	  for (unsigned int k = 0; k < name[i].size(); ++k) {
	    string substr = name[i].substr(k);
	    if (name[j].find(substr) == 0) {
	      subcnt[i][j] = name[j].size() - substr.size();
	      break;
	    }
	  }
	}
      }
    }

    unsigned int ans = 1 << 30;
    for (int i = 0; i < n; ++i) {
      if (!(S & (1 << i)))
	  ans = min(ans, name[i].size()+solve(S | (1 << i), i));
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1824
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
using ll = long long;

int main() {
    ll K;cin>>K;
    ll N = K / 50;
    K = K % 50;
    // init
    vector<ll> ans(50);
    REP(i,50) ans[i] = i + N;
    //
    
    cout << 50 << '\n';
    REP(i,50){
        if(i==K) break;
        ans[i] += 50;
        REP(j,50){
            if(i==j) continue;
            --ans[j];
        }
    }
    REP(i,50)
        cout << ans[i] << (i==49 ? '\n':' ');
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int n,cnt=0;
    cin>>s;
    cin>>n;
    for(int i=0;i<s.size();i++){
        if(s[i]-'0'==1){
            cnt++;
            if(cnt==n){
                cout<<1<<endl;
                return 0;
            }
        }else{
            cout<<s[i]<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
N = int(input())
MOD = 10**9 + 7

a = N + 100
fact = [0] * (a)
fact[0] = 1
for i in range(1, a):
    fact[i] = fact[i-1] * i % MOD

inv_fact = [0] * a
inv_fact[a-1] = pow(fact[a-1], MOD-2, MOD)
for i in range(a-1, 0, -1):
    inv_fact[i-1] = inv_fact[i] * i % MOD

def nCk(n, k):
    return (fact[n] * inv_fact[k] * inv_fact[n-k]) % MOD

ans = 0
for i in range(2, N+1):
    ans += nCk(N, i) * (pow(2, i, MOD)-2) * pow(8, N-i, MOD) % MOD
    ans %= MOD
print(ans)

Measured memory_bytes: 99080
#!/usr/bin/env python3

import numpy as np

def main():
    n = int(input())
    l = list(map(int,input().split()))
    arr = np.array(l)

    suml = []
    for i in range(1, 101):
        gokei = sum((arr-i)**2)
        suml.append(int(gokei))
    
    print(min(suml))


if __name__ == '__main__':
    main()

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

bool ok(ll d, ll x, ll y) {
    return abs(x-y) <= d;
}

int main() {
    ios::sync_with_stdio(false);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (ok(d, a, c) || (ok(d, a, b) && ok(d, b, c))) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}



Measured memory_bytes: 764
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> Q;
const int INF = 1000000000;
struct edge { int to, cost; };

int n, m, x, a, b, di, t[100000];

vector<edge> G[100000];
int d[100000][401];

int dijkstra() {
  const int maxX = x * 2 + 1;
  const int maxPlus = x; // 1 ~ maxPlus => hot / maxPlus + 1 ~ maxX - 1 => cold
  for (int i = 0; i < n; i++) for (int j = 0; j < maxX; j++) d[i][j] = INF;
  int num = x + 1;
  d[0][num] = 0;
  priority_queue<Q, vector<Q>, greater<Q> > que;
  que.push(Q(0, P(0, num)));
  while (!que.empty()) {
    Q q = que.top(); que.pop();
    int cost = q.first, from = q.second.first;
    num = q.second.second;
    if (d[from][num] < cost) continue;
    if (d[from][0] < cost) continue;
    for (int i = 0; i < G[from].size(); i++) {
      edge e = G[from][i];
      int to = e.to, newcost = cost + e.cost, newnum = num;
      if (d[to][0] <= newcost) continue;
      if (newnum > 0 && newnum <= maxPlus) newnum = max(0, newnum - e.cost);
      if (maxPlus < newnum) {
        newnum = newnum + e.cost;
        if (newnum >= maxX) newnum = 0;
      }
      if (newnum != 0) {
        if (t[to] == 1 && newnum > maxPlus) continue;
        if (t[to] == -1 && newnum <= maxPlus) continue;
      }
      if (t[to] == 1) newnum = x;
      if (t[to] == -1) newnum = x + 1;
      if (d[to][newnum] <= newcost) continue;
      d[to][newnum] = newcost;
      que.push(Q(newcost, P(to, newnum)));
    }
  }
  int ans = INF;
  for (int i = 0; i < maxX; i++) ans = min(ans, d[n - 1][i]);
  return ans;
}

int main() {
  scanf("%d%d%d", &n, &m, &x);
  for (int i = 0; i < n; i++) scanf("%d", &t[i]), t[i]--;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &di);
    a--; b--;
    edge e1, e2;
    e1.to = b, e2.to = a;
    e1.cost = e2.cost = di;
    G[a].push_back(e1);
    G[b].push_back(e2);
  }
  printf("%d\n", dijkstra());
}



Measured memory_bytes: 21496
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=20,M=1010;
char s[N][M];
int ans,n,m,k,cut[N],c[M],p[N],sum[M];
int check()
{
	int res=0;
	for(int i=1;i<n;i++)if(cut[i])p[++res]=i;
	for(int i=1;i<=m;i++)c[i]=0,sum[i]=0;
	p[0]=0;int Q;p[Q=++res]=n;
	for(int K=1;K<=m;K++)
	{
		for(int i=1;i<=Q;i++)
		{
			int l=p[i-1]+1,r=p[i],tmp=0;
			if(c[K-1])sum[i]=0;
			for(int j=l;j<=r;j++)tmp+=s[j][K]=='1';
			if(tmp>k)return n+m+1;
			sum[i]+=tmp;
			if(sum[i]>k)
			{
				c[K-1]=1,sum[i]=tmp,res++;
			}
		}
		if(c[K-1])
		{
			for(int i=1;i<=Q;i++)
			{
				int l=p[i-1]+1,r=p[i],tmp=0;
				for(int j=l;j<=r;j++)tmp+=s[j][K]=='1';
				sum[i]=tmp;
			}
		}
	}
	return res-1;
}
void dfs(int now)
{
	if(now>=n)
	{
		ans=min(ans,check());
		return;
	}
	cut[now]=0;dfs(now+1);
	cut[now]=1;dfs(now+1);cut[now]=0;
}
int main()
{
	n=gi();m=gi();k=gi();ans=n+m+1;
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	dfs(1);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
a,b,c,d=gsmi
ar=(a..b).to_a
ar2=(c..d).to_a
ans=ar&ar2
putsend 0 if ans.size==0
puts ans.size-1

Measured memory_bytes: 1788
#include <stdio.h>
typedef long long ll;

ll abs(ll a) {
  return a > 0 ? a : -a;
}

int main(void) {
  ll x, y, ans = 0;
  scanf("%lld%lld", &x, &y);
  if(x <= y) {
    if(x * y < 0) x = -x, ans = 1;
  } else {
    if(x * y > 0) ans = 2;
    else ans = 1, x = -x;
  }
  printf("%lld", abs(y - x) + ans);
  return 0;
}

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

using namespace std ;

int x, y, z, n ; 

typedef long long LL ; 

const int MAXN = 100010 ; 

int a[MAXN], b[MAXN], c[MAXN], d[MAXN], p[MAXN] ; 

LL L[MAXN], R[MAXN] ; 

priority_queue<int, vector<int>, greater<int> > pq ; 

bool cmp(int x, int y) { 
		return d[x] < d[y] ; 
}
int main() { 

		scanf("%d%d%d", &x, &y, &z) ; 
		n = x + y + z ; 
		for (int i = 1; i <= n; i ++) scanf("%d%d%d", &a[i], &b[i], &c[i]), d[i] = c[i] - b[i], p[i] = i ; 
	    sort(p + 1, p + n + 1, cmp) ; 
		LL now = 0, change = 0 ; 

		for (int i = 1; i <= y; i ++) pq.push(b[p[i]] - a[p[i]]), now += a[p[i]], change += b[p[i]] - a[p[i]] ;  

		for (int i = y; i < n - z + 1; i ++) { 
				L[i] = now + change ; 
				int tmp = b[p[i + 1]] - a[p[i + 1]] ; 
				if (tmp > pq.top()) { 
						change -= pq.top() ; 
						pq.pop() ; 
						pq.push(tmp) ; 
						change += tmp; 
				}
				now += a[p[i + 1]] ; 
		}
		while (pq.size()) pq.pop() ; 
		now = 0, change = 0 ;
		for (int i = n; i >= n - z + 1; i --) { pq.push(c[p[i]] - a[p[i]]), now += a[p[i]], change += c[p[i]] - a[p[i]]; }
		for (int i = n - z + 1; i > y; i --) { 
				R[i] = now + change ; 
				int tmp = c[p[i - 1]] - a[p[i - 1]] ; 
				if (tmp > pq.top()) { 
						change -= pq.top() ; 
						pq.pop() ; 
						change += tmp; 
						pq.push(tmp);
				}
				now += a[p[i - 1]] ; 
		}

		LL ans = 0 ; 
		for (int i = y; i < n - z + 1; i ++) {
			   ans = max(ans, L[i] + R[i + 1]) ; 
		}	   

		cout << ans << endl ; 
}



		


Measured memory_bytes: 3712
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (a, b, h, m) = {
        let abhm = get_line().split_whitespace()
            .map(|e| e.parse().unwrap())
            .collect::<Vec<f64>>();
        (abhm[0], abhm[1], abhm[2], abhm[3])
    };

    let m_ratio = m / 60.0;
    let h_ratio = (60.0 * h + m) / (12.0 * 60.0);

    let diff_rad = 2.0 * std::f64::consts::PI * (m_ratio - h_ratio).abs();

    let result = a.powi(2) + b.powi(2) - 2.0 * a * b * diff_rad.cos();
    println!("{}", result.sqrt());
}


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

using namespace std;

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

    while(n>0){
        if(n%10==7){
            cout << "Yes" << endl;
            return 0;
        }
        n/=10;
    }

    cout << "No" << endl;
}

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	int n, m; cin >> n >> m;
	vector<int> num;
	map<int, int> mp;
	rep(i, 0, n) {
		int p; cin >> p;
		num.push_back(p);
		mp[p]++;
	}
	rep(i, 0, m) {
		int p1, p2; cin >> p1 >> p2;
		num.push_back(p2);
		mp[p2] += p1;
	}
	sort(num.begin(), num.end());
	num.erase(unique(num.begin(), num.end()), num.end());
	reverse(num.begin(), num.end());
	ll ans = 0;
	rep(i, 0, num.size()) {
		ans += 1LL*min(n,mp[num[i]]) * num[i];
		n -= mp[num[i]];
		if (n <= 0) break;
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 10356
#include<bits/stdc++.h>
#define inf ((int)0x3f3f3f3f)
#define neinf ((int)0xc1c1c1c1)
#define llinf ((ll)0x3f3f3f3f3f3f3f3f)
#define nellinf ((ll)0xc1c1c1c1c1c1c1c1)
#define ull unsigned long long
#define uint usigned int
#define lson root<<1
#define rson root<<1|1
#define Mid int mid=(l+r)>>1;
#define FREI freopen("in.txt","r",stdin)
#define FREO freopen("out.txt","w",stdout)
#define Mem(a,b) memset(a,b,sizeof(a))
#define Memv(a,b) for(int i=0;i<=b;i++) a[i].clear()
#define ll long long
#define eps 1e-6
#define PB push_back
#define PI acos(-1)
#define lmove(n) (1<<(n))
#define FI first
#define SE second
#define Ceil(x,y) ((x+y-1)/(y))
using namespace std;
char st[200];
int a,b,all[30];
int main()
{
    scanf("%d%d",&a,&b);getchar();
    for (int i=1;i<=a;i++)
    {
        scanf("%s",st);
        //printf("%s\n",st+1);
        for (int j=0;j<b;j++)
            all[st[j]-'a']++;
    }

    if (a>b) {int temp=b;b=a;a=temp;}
    int temp1=a/2,temp2=b/2;
    int temp=temp1*temp2;
    int chu4=0;
    for (int i=0;i<='z'-'a';i++)
    {
        if (all[i]>=4 && temp>0)
            chu4+=all[i]/4;
    }
    if (chu4<temp) {printf("No");return 0;}
    int odd=0;
    for (int i=0;i<='z'-'a';i++)
    {
        if (all[i]%2==1) odd++;
    }
    if (a*b%2==1 && odd>1) {printf("No");return 0;}
    if (a*b%2==0 && odd>0) {printf("No");return 0;}
    printf("Yes");

}


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

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  int ti, tj;
  cin >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si,sj);
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    rep(v,4) {
      int ni = i+di[v], nj = j+dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    for (int ei = -2; ei <= 2; ++ei) {
      for (int ej = -2; ej <= 2; ++ej) {
        int ni = i+ei, nj = j+ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9544
#include <bits/stdc++.h>
#include <time.h>
//#include <random>
//#ifndef _LOCAL
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#endif
#define sz(x) int(x.size())
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define N 100500
#define oo ll(1e16)
#define pii pair <int, int>
#define pll pair <ll, ll>
#define ft first
#define sd second
#define pb push_back
#define ppb pop_back
#define el '\n'
#define elf endl
#define base ll(1e9 + 7)
#define re return
#define nins 4294967295
using namespace std;
typedef long long ll;
typedef long double ld;

//mt19937 rnd(0);

void solve() {
    int m, n;

    cin >> m >> n;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        m -= x;
    }

    cout << max(-1, m);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef _LOCAL
//        in("input.txt");

        int t = 1;
//        cin >> t;
        for (int i = 1; i <= t; i++) {
            cout << "Test #" << i << elf;

            clock_t start_time = clock();

            solve();

            cerr.precision(4); cerr << fixed;
            cerr << elf;
            cerr << "Time :: " << ld(clock() - start_time) / CLOCKS_PER_SEC << elf;

            cout << elf;
        }
    #else
        int t = 1;
//        cin >> t;

        while (t--) {
            solve();
            cout << el;
        }
    #endif
}


Measured memory_bytes: 3648
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define ll long long

using namespace std;

const ll FFF=2000+5;

ll n,a;
ll now;

bitset<FFF*FFF> bs;

int main()
{
	//if(fopen(".in", "r"))
	//{
	//	freopen(".in", "r", stdin);
	//	freopen(".out", "w", stdout);
	//}
	ios::sync_with_stdio(false);
	cin>>n;
	bs[0]=1;
	for(int i=1;i<=n;++i)
	{
		cin>>a;
		bs|=bs<<a;
		now+=a;
	}
	for(int i=(now+1)/2;i<=now;++i)
	{
		if(bs[i]!=0)
		{
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    vector<int> v(100002,0);
    cin>>n;
    for(;n--;){
        int p;
        cin>>p;
        v[p]++;
        v[p+1]++;
        v[p+2]++;
    }
    cout<<v[max_element(v.begin(),v.end())-v.begin()];
    
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
# ifdef DEB
# define debug(...) fprintf(stderr, __VA_ARGS__)
# else
# define debug(...)
#endif
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LL long long
#define LD long double
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define pb pop_back
#define VI vector<int> 
#define VPI vector<PII> 
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define ALL(x) (x).begin(), (x).end()
#define siz(V) ((int)V.size())
const LL mod = 1e9 + 7;
const int M = 1e6 + 5;

int n;
LL dp[M], P[M];

int main()
{
  //ios_base::sync_with_stdio(0);
  scanf("%d", &n);
  dp[0] = 1;
  P[0] = 1;
  dp[1] = n;
  P[1] = n + 1;
  for (int i = 2; i <= n; i++)
  {
    dp[i] = P[i - 1];
    dp[i] -= dp[i - 2];
    dp[i] += ((LL)(n - 1) * (n - 1)) % mod;
    dp[i] += (n - i + 1);
    
    
    while (dp[i] < 0)
    {
      dp[i] += mod;
    }
    while (dp[i] >= mod)
    {
      dp[i] -= mod;
    }
    
    P[i] = P[i - 1] + dp[i];
    while (P[i] >= mod)
    {
      P[i] -= mod;
    }
    //debug("%d: %lld %lld\n", i, dp[i], P[i]);
  }
  printf("%lld\n", dp[n]);
  return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define Mx 200001
#define inf 1e15
const int MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


typedef long long  L;
//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,q,q1,q2,q3,q4,r,s,t,
u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,id4,lim;

//double rat;
L A[Mx+5],B[Mx+5];

char str[Mx];

// vector<L>V,V1;
// set<L>S;
// map<L,L>Mp;
// priority_queue<L>Pq;

//struct node{L nid,nv;node(L nid_,L nv_){nid=nid_;nv=nv_;}};
//vector<node>V;
void solve(){
    L size = 0, k = 1;
    while(k<=n){
        k *= m;
        size += 1;
    }
    printf("%lld\n",size);
}
int main()
{
    scanf("%lld%lld",&n,&m);
    solve();
    return 0;
}
/// lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int retu[8][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}};

int main(){
    int N;
    string S;
    cin >> N >> S;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < S.size(); j++){
            if(S[j] == 'Z'){
                S[j] = 'A';
            }else{
                S[j]++;
            }
        }
    }
    cout << S << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  sort(a.begin(), a.end(), greater<int>());
  vector<ll> e;
  rep(i, n - 1) {
    if (a[i] == a[i + 1]) {
      e.push_back(a[i]);
      i++;
      if (e.size() == 2) {
        cout << e[0] * e[1] << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;



  
  return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define all(x) (x).begin(),(x).end()

const int mod = 1e9 + 7;

signed main() {
#ifdef _DEBUG
  // freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n, k;
  cin >> n >> k;
  int ans = 0;
  for (int i = k; i <= n + 1; i++) {
    (ans += (n - i + 1) * i + 1) %= mod;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
	
	string s; cin>>s;
	int cnt1{},cnt2{};
	for(int i=0; i<s.size(); i++){
		if(s.at(i)=='0'+i%2) cnt1++;
		if(s.at(i)=='1'-i%2) cnt2++;
	}
	cout << min(cnt1,cnt2)<<endl;
	
	
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;

ll st[812345], n;

const int inf = 1e9;
ll query(int l, int r, int L=0, int R=n-1, int id=1) {
  if (L > r or R < l) return -inf;
  if (L >= l and R <= r) {
    return st[id];
  } else {
    int M = (L+R)/2;
    return max(query(l, r, L, M, id*2), query(l, r, M+1, R, id*2+1));
  }
}

void update(int i, ll x, int L=0, int R=n-1, int id=1) {
  if (i > R or i < L) return;
  if (L==R) {
    st[id] = x;
    return;
  }
  int M = (L+R)/2;
  update(i, x, L, M, id*2);
  update(i, x, M+1, R, id*2+1);
  st[id] = max(st[id*2], st[id*2+1]);
}

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  memset(st, 0, sizeof st);
  cin >> n;

  vector<pii> a;
  rep(i,0,n) {
    int x, d;
    cin >> x >> d;
    a.emplace_back(x, d);
  }
  sort(all(a));

  vi r(n);
  rep(i,0,n) {
    auto it = lower_bound(all(a), make_pair(a[i].fst+a[i].snd, 0LL));
    --it;
    r[i] = it-a.begin();
 //   cerr << i << ' ' << r[i] << endl;
  }

  for (int i = n-1; i >= 0; --i) {
  //  cerr << i << ' ' << r[i] << endl;
    ckmax(r[i], query(i, r[i]));
    update(i, r[i]);
//    cerr << i << ' ' << r[i] << endl;
  }

  const ll mod = 998244353;
  vi dp(n+1);
  dp[n] = 1;
  for (int i = n-1; i >= 0; --i) {
    dp[i] = dp[i+1] + dp[r[i]+1];
    dp[i] %= mod;
  }

  cout << dp[0] << endl;
}

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    string s;
    cin1(s);
    if (s <= "2019/04/30")
        cout << "Heisei" << endl;
    else
        cout << "TBD" << endl;
    //s.erase(7,1);
    //s.erase(4,1);
    //lli x = atoi(s.c_str());
    //if (x <= 20190430)
    //    cout << "Heisei" << endl;
    //else
    //    cout << "TBD" << endl;


}


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

int main()
{
    char c;
    cin >> c;
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') cout << "vowel" << endl;
    else cout << "consonant" << endl;
    return 0;
}


Measured memory_bytes: 3588
import math
a,b,x = map(int,input().split())

if x == a*a*b/2:
    print(math.degrees(math.atan2(b,a)))
elif x > a*a*b/2:
    c = 2*(a*a*b-x)/(a**2)
    print(math.degrees(math.atan2(c,a)))
elif x < a*a*b/2:
    c = (2*x)/(a*b)
    print(math.degrees(math.atan2(b,c))) 

Measured memory_bytes: 3064
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        l: usize,
        r: usize,
    }
    let y = 2019;
    let r = if r - l > y {
        y * (l / y) + y + r % y
    } else {
        r
    };
    let mut min = y;
    for j in l..r + 1 {
        for i in l..j {
            let a = (i * j) % y;
            if a < min {
                min = a;
            }
        }
    }
    println!("{}", min);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define mod 998244353
#define ll long long
using namespace std;
int n,a,b,q[300005],x[300005],ans;
ll k;
int pow(int c,int p){
	int tot=1;
	while(p){
		if(p&1) tot=1ll*c*tot%mod;
		c=1ll*c*c%mod;
		p>>=1;
	}
	return tot;
}
int C(int A,int B){
	if(A==0) return 1; if(A>B||B-A>n) return 0; if(A==B) return 1;
	return 1ll*q[B]*x[A]%mod*x[B-A]%mod;
}
int main(){
	scanf("%d%d%d%lld",&n,&a,&b,&k);
	q[1]=1;for(int i=2;i<=n;++i) q[i]=1ll*q[i-1]*i%mod;
	x[n]=pow(q[n],mod-2);
	for(int i=n-1;i>=0;--i) x[i]=x[i+1]*1ll*(i+1)%mod;
	if(k==0){puts("1");return 0;}
	for(int i=1;i<=n;++i){
		ll j=k-1ll*i*a;
		if(j%b) continue;
		j/=b;
		ans=(ans+1ll*C(i,n)*C(j,n)%mod)%mod;
	}
	printf("%d",ans);
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;
bool comp(pli& a,pli& b){
  return a.first>b.first;
}//降順ソート
 
int main() {
 int n,m;
  cin >> n >> m;
  vector<long long> a(n);
  vector<pair<long long,int> > pairs(m);
  for(int i=0;i<n;i++){
  cin >> a[i];
  }
  for(int i=0;i<m;i++){
  cin >> pairs[i].second >> pairs[i].first;
  }
  sort(a.begin(),a.end());
  sort(pairs.begin(),pairs.end(),comp);//Ciで降順ソート
 
 
 
 ll k=0,sum=0;
  for(int i=0;i<m;i++){
    ll b=pairs[i].second,c=pairs[i].first;
    for(int j=0;j<b;j++){
      if(c>=a[k]){
        a[k]=c;k++;
      }
      else{
 
        for(int g=0;g<n;g++){
        sum+=a[g];
        }
        cout << sum << endl;
        return 0;
      }
    }
  }
  for(int g=0;g<n;g++){
  sum+=a[g];
  }
  cout << sum << endl;
 
}

Measured memory_bytes: 2560
A, B = map(int, input().split())
import math

price_A = math.ceil(A/0.08)
price_A_max = math.floor(price_A+12.5)
cnt = 0
for i in range(price_A, price_A_max):
	if math.floor(i*0.1)==B:
		cnt = 1
		print(i)
		break
if cnt == 0:
	print(-1)

Measured memory_bytes: 38384
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    d = collections.defaultdict(int)
    for i in range(1, n + 1):
        s = str(i)
        d[s[0], s[-1]] += 1
    cnt = 0
    for i in range(1, n + 1):
        s = str(i)
        cnt += d[s[-1], s[0]]
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 40300
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr ll mod998=998244353;

int N,a[100],c;

int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>a[i];
		if(i%2==0&&a[i]%2==1)c++;
	}
	cout<<c<<endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    int A,B;
    cin >> A >> B;
    if(A % 3 == 0 || B % 3 == 0 || (A+B)%3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int64_t long long
constexpr int64_t MOD=1e9+7;

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(0,(c-(a-b)))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int s;
	cin>>s;
	int a=s/100;
	int b=s%100;

	if(a>0 && a<13)
	{
		if(b==0 || b>12)
			cout<<"MMYY"<<endl;
		else
			cout<<"AMBIGUOUS"<<endl;
	}
	else
	{
		if(b>0 && b<13)
			cout<<"YYMM"<<endl;
		else
			cout<<"NA"<<endl;
	}

}			

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

const int maxN = 100;

bool isAlphaUsed[26];
int counts[maxN];


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

	fill(counts, counts + maxN, 0);

	for (int i = 1; i < N; i++) {
		fill(isAlphaUsed, isAlphaUsed + 26, false);
		
		for (int j = 0; j < i; j++) {
			int idx = (int)(str[j] - 'a');
			isAlphaUsed[idx] = true;
		}

		for (int j = i; j < N; j++) {
			int idx = (int)(str[j] - 'a');
			if (isAlphaUsed[idx]) {
				isAlphaUsed[idx] = false;
				counts[i]++;
			}
		}
	}

	cout << *max_element(counts, counts + maxN) << endl;

	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 n=sc.nextInt();
        int[] num=new int[n];
        for(int i=0;i<n;i++){
            num[i]=sc.nextInt();
        }
        double ans=0.0;
        for(int i=0;i<n;i++){
            ans+=(double)1/num[i];
        }
        System.out.println(1/ans);
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<memory.h>
#include<vector>
#include<functional>
using namespace std;

int main()
{
	int dp[2001];
	int n, k, a, b;
	vector<int> c[11], g[11];
	memset(dp, 0, sizeof(dp));
	cin >> n >> k;
	for (int i = 0; i<n; i++){
		cin >> a >> b; b--;
		g[b].push_back(a);
	}

	for (int i = 0; i<10; i++){
		sort(g[i].begin(), g[i].end(), greater<int>());
	}

	for (int i = 0; i<10; i++){
		if (!g[i].empty()){
			c[i].push_back(g[i].front());
		}
		else{
			c[i].push_back(0);
		}
		for (int i2 = 1; i2<g[i].size(); i2++){
			c[i].push_back(c[i][i2 - 1] + g[i][i2] + ((i2 + 1) - 1) * 2);
		}
	}
	for (int j = 0; j<10; j++){
		for (int i = k; i >= 0; i--){
			for (int i2 = 0; (i2<c[j].size()) && (i - i2 - 1 >= 0); i2++){
				dp[i] = max(dp[i], dp[i - i2 - 1] + c[j][i2]);
			}
		}
	}
	cout << dp[k] << endl;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

int main() {
    int n;
    cin >> n;
    vi a(n);
    map<int, int> m;
    rep(i, n) {
        cin >> a[i];
        m[a[i]]++;
    }
    int cnt = 0;
    for (auto x : m) {
        if (x.first > x.second) {
            cnt += x.second;
        } else {
            cnt += x.second - x.first;
        }
    }
    cout << cnt << endl;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<long long> T(N);
  for (int i = 0; i < N; i++) cin >> T[i];
  long long ans = 1;
  for (int i = 0; i < N; i++) {
    ans = ans / __gcd(ans, T[i]) * T[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <set>
#include <numeric>
using namespace std;
using ll = long long;

#define no "no"
#define No "No"
#define NO "NO"
#define yes "yes"
#define Yes "Yes"
#define YES "YES"
#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define view(_list) foreach(e, _list){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e)
#define INF 1e+9
#define PI acos(-1)
#define TAU PI * 2
#define EPS 0.00000001
const ll MOD = 1000000007;

int main(){
    FAST;

    ll k, a, b;
    cin >> k >> a >> b;
    
    FOR(i, a, b + 1){
        if(i % k == 0){
            println("OK");
            stop;
        }
    }
    println("NG");
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return (a.second < b.second);}
ll gcd(ll a, ll b){if(a==0)return b;return gcd(b % a, a);}
int main()
{
	chutiyaap;
	ll a,b;cin>>a>>b;
	ll gcdd=__gcd(a,b);
	ll res=1;
	for(ll i=2;i*i<=gcdd;i++)
	{
		if(gcdd%i==0)
		{
			res++;
			while(gcdd%i==0)gcdd/=i;
		}
	}
	if(gcdd>1)res++;
	cout<<res<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, m, a[100010], b[100010];
P jobs[100010];
prique<int> que;
signed main() {
	cin >> n >> m;
	rep(i, n) {
		cin >> a[i] >> b[i];
		a[i] = m - a[i];
		jobs[i] = make_pair(a[i], b[i]);
	}
	sort(jobs, jobs + n, greater<P>());
	int now = 0, ans = 0;
	for (int i = m; i >= 0; i--) {
		while (now < n && jobs[now].first >= i) {
			que.push(jobs[now].second);
			now++;
		}
		if (!que.empty()) {
			ans += que.top();
			que.pop();
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4472
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cctype>
#include <stack>
#include <map>
#include <cstring>
#include <sstream>
#include <set>
#include <list>
#include <fstream>
#include <iomanip>
#include <assert.h>

#define ll long long
#define ull unsigned long long
#define pii std::pair<int, int>
#define op                            \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);

const int INF = 0x3f3f3f3f;
const int maxn = (100000 + 5);
const int mod = (1000000007);

int main()
{
    ll n,a,b;
    ll ans=0;
    scanf("%lld %lld %lld",&n,&a,&b);
    ll x=n/(a+b);
    ll y=n-(a+b)*x;
    ans+=x*a+std::min(y,a);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
package main

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

//FOR I/O : STARTS
var Reader *bufio.Reader = bufio.NewReader(os.Stdin)
var Writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func Printf (f string, a ...interface{}) { fmt.Fprintf(Writer, f, a...) }
func Scanf (f string, a ...interface{}) { fmt.Fscanf(Reader, f, a...) }
func Println (a ...interface{}) { fmt.Fprintln(Writer, a...)}
func Scanln (a ...interface{}) { fmt.Fscanln(Reader, a...)}
//I/O ENDS HERE

func Abs(x int) int {
    if x < 0 {
        return -x
    }
    return x
}

func Min(x, y int) int {
    if x < y {
        return x
    } else {
        return y
    }
}

func Max(x, y int) int {
    if x >= y {
        return x
    } else {
        return y
    }
}

func Ceil(x, y int64) int64 {
    //returns x/y
    if x%y == 0 {
        return x/y
    } else {
        return int64(x/y)+1
    }
}

func main() {
    defer Writer.Flush()

    var n int
    Scanf("%d\n", &n)

    arr := make([]int, n+1)

    m := make(map[int]int)
    cnt := 0

    for i := 1; i <= n; i += 1 {
        Scanf("%d ", &arr[i])
        temp := i-arr[i]
        cnt += m[temp]
        m[arr[i]+i] += 1;
        // Println(i, temp, arr[i], i, cnt, m)
    }

    Println(cnt)

}


Measured memory_bytes: 14616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    vector<int> c(n-1),s(n-1),f(n-1),cd(n,0);
    for(int i=0;i<n-1;i++)cin>>c.at(i)>>s.at(i)>>f.at(i);
    for(int i=0;i<n-1;i++){
        ll ans=0;
        ans+=s.at(i);
        ans+=c.at(i);
        for(int j=i+1;j<n-1;j++){
              if(ans>=s.at(j)){
                 if(ans%f.at(j)!=0) ans+=f.at(j)-ans%f.at(j);
              }
              else ans=s.at(j);
              ans+=c.at(j);
        }
        cout<<ans<<endl;
    }
    cout<<0<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n+2];
  for(int i=1;i<n+1;i++){
    cin >> a[i];
  }
  a[0]=0;
  a[n+1]=0;
  int y=0;
  for(int i=1;i<2+n;i++){
    y=y+abs(a[i]-a[i-1]);
  }
  int u;
  for(int i=1;i<n+1;i++){
    u=y+abs(a[i+1]-a[i-1])-abs(a[i]-a[i-1])-abs(a[i]-a[i+1]);
    cout << u << endl;
  }
}


Measured memory_bytes: 1664
#include <stdio.h>

int main(){
    char c[2][4];
    char o[2][4];
    int x,y;
    int flug=0;
    scanf("%s",c[0]);
    scanf("%s",c[1]);
    o[0][0]=c[1][2];
    o[0][1]=c[1][1];
    o[0][2]=c[1][0];
    o[1][0]=c[0][2];
    o[1][1]=c[0][1];
    o[1][2]=c[0][0];
    for(x=0;x<3;x++)for(y=0;y<2;y++)if(c[y][x]!=o[y][x])flug=1;
    printf("%s\n",(flug==1)?"NO":"YES");
    return 0;
}


Measured memory_bytes: 128
N, Q = map(int, input().split())
s = list(input())
t = [input().split() for _ in range(Q)]


def func(n):
    pos = n
    for x in t:
        if x[0] == s[pos]:
            if x[1] == 'L':
                pos -= 1
                if pos < 0:
                    return 'L'
            else:
                pos += 1
                if pos == N:
                    return 'R'
    return 'T'


def calcl(pl, pr):
    if pl == pr:
        return pl
    else:
        p = (pr + pl) // 2
        a = func(p)
        if a == 'T':
            return calcl(pl, p)
        else:
            return calcl(p+1, pr)


def calcr(pl, pr):
    if pl == pr:
        return pl
    else:
        p = (pr + pl + 1) // 2
        a = func(p)
        if a == 'T':
            return calcr(p, pr)
        else:
            return calcr(pl, p - 1)


pl = 0
pr = N - 1
p = (pl + pr) // 2
a = func(p)
ans = 0
if a == 'T':
    p1 = calcl(pl, p)
    p2 = calcr(p, pr)
    ans = p2 - p1 + 1
elif a == 'L':
    while True:
        pl = p + 1
        if pl == N:
            break
        p = (pl + pr) // 2
        a = func(p)
        if a == 'T':
            p1 = calcl(pl, p)
            p2 = calcl(p, pr)
            ans = p2 - p1 + 1
            break
elif a == 'R':
    while True:
        pr = p - 1
        if pr == -1:
            break
        p = (pl + pr) // 2
        a = func(p)
        if a == 'T':
            p1 = calcl(pl, p)
            p2 = calcl(p, pr)
            ans = p2 - p1 + 1
            break
print(ans)

Measured memory_bytes: 42868
#include <stdio.h>

#define SIZE 2000000

int main() {
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp, n;
  char com[21], buf[20];
  buf[19]='\0';
  char *p;
  do {
    fgets(com, 20, stdin);
    if (com[0] == 'i') {
      n = 0;
      p = com+7;
      while (*p!='\n') {
        n = n*10+*p-'0';
        p++;
      }
      A[++H] = n;
      for (i=H; i>1 && A[i/2]<A[i];i>>=1) {
        tmp = A[i/2];
        A[i/2] = A[i];
        A[i] = tmp;
      }

    } else if (com[1]=='x') { // extract
      n = A[1];
      for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
      puts(buf+i+1);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i<<1;
        largest = i;
        if (l < H && A[l] > A[i])        largest = l;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (com[2]!='d');
  return 0;
}


Measured memory_bytes: 5448
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*

 */
int n,m,c,a[20][20],b[20];

int main(){
  cin>>n>>m>>c;
  REP(j,m){
    cin>>b[j];
  }

  REP(i,n){
    REP(j,m){
      cin>>a[i][j];
    }
  }

  int ans=0;
  REP(i,n){
    int lhs=c;
    REP(j,m){
      lhs += a[i][j] * b[j];
    }
    if(lhs > 0)
      ans++;    
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] n = new int[10];
    for (int i = 0; i < 4; i++) {
      int tmp = sc.nextInt();
      n[tmp]++;
    }
    if (n[1] == 1 && n[9] == 1 && n[7] == 1 && n[4] == 1) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 22996