akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int BinSearch(int nA[], int nKey, int n)
{
	int nLeft = 0, nRight = n;
	int nMid = (nLeft + nRight) / 2;
	while (nLeft < nRight)
	{
		if (nA[nMid]<nKey)
		{
			nLeft = nMid + 1;
		}
		else if (nA[nMid]>nKey)
		{
			nRight = nMid;
		}
		else
		{
			return 1;
		}
		nMid = (nLeft + nRight) / 2;
	}
	return 0;
}


int main()
{
	int nA[100000] = { 0 };
	int n = 0, q = 0, nKey = 0, nSum = 0;
	int ni = 0;
	cin >> n;
	while (cin >> nA[ni], ni < (n - 1))
	{
		ni++;
	}
	cin >> q;
	for (ni = 0; ni < q; ni++)
	{
		cin >> nKey;
		if (BinSearch(nA, nKey, n))
		{
			nSum++;
		}
	}
	cout << nSum << endl;
	return 0;
}


Measured memory_bytes: 3492
n = int(input())

s = []
for i in range(n):
  s.append(int(input()))
  
total = sum(s)
if total % 10 != 0:
  print(total)
  exit()
else:
  nums = []
  for i in s:
    if i % 10 != 0:
      nums.append(i)
  if len(nums) == 0:
    print(0)
  else:
    nums.sort()
    print(total-nums[0])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define pa pair<ll,int>
#define mo 1000000007
#define N 100005 
using namespace std;
ll ds[N],dt[N],ways[N],wayt[N];
struct edge{int to,next,v;}e[N*4];
int head[N],vis[N];
int n,m,s,t,tot,ans;
priority_queue<pa > q;
void add(int x,int y,int v){
	e[++tot]=(edge){y,head[x],v};
	head[x]=tot;
}
void dijk_heap(int S,ll *dis,ll *way){
	for (int i=1;i<=n;i++)
		dis[i]=1e18,vis[i]=0,way[i]=0;
	dis[S]=0; way[S]=1;
	while (!q.empty()) q.pop();
	q.push(pa(0,S));
	while (!q.empty()){
		int x=q.top().second; q.pop();
		if (vis[x]) continue; vis[x]=1;
		for (int i=head[x];i;i=e[i].next){
			ll tmp=dis[x]+e[i].v;
			if (dis[e[i].to]>tmp){
				dis[e[i].to]=tmp;
				way[e[i].to]=0;
				q.push(pa(-tmp,e[i].to));
			}
			if (dis[e[i].to]==tmp)
				way[e[i].to]=(way[e[i].to]+way[x])%mo;
		} 
	}
}
int main(){
	scanf("%d%d%d%d",&n,&m,&s,&t);
	for (int i=1;i<=m;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		add(x,y,z);
		add(y,x,z);
	}
	dijk_heap(s,ds,ways);
	ans=1ll*ways[t]*ways[t]%mo;
	dijk_heap(t,dt,wayt);
	for (int i=1;i<=n;i++)
		if (ds[i]*2==ds[t]&&ds[i]+dt[i]==ds[t])
			ans=(ans+mo-1ll*ways[i]*ways[i]%mo*wayt[i]%mo*wayt[i]%mo)%mo;
	for (int x=1;x<=n;x++)
		for (int i=head[x];i;i=e[i].next)
			if (ds[x]+e[i].v+dt[e[i].to]==ds[t])
				if (ds[x]*2<ds[t]&&dt[e[i].to]*2<ds[t])
					ans=(ans+mo-1ll*ways[x]*wayt[e[i].to]%mo*ways[x]%mo*wayt[e[i].to]%mo)%mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 10996
from math import radians,cos
a,b,h,m=map(int,input().split())
x=360-6*m
y = (12*60-h*60-m)
y=(y*360)/(12*60)
angle = abs(x-y)
ans = pow(a*a+b*b-2*a*b*cos(radians(angle)),0.5)
print(ans)


Measured memory_bytes: 62548
#include <iostream>
#include <queue>

int main() {
  int n, q;
  std::cin >> n >> q;
  std::queue<int> s[n];

  for (int i = 0; i < q; ++i) {
    int c, t;
    std::cin >> c >> t;
    switch (c) {
    case 0:
      int x;
      std::cin >> x;
      s[t].push(x);
      break;
    case 1:
      if (s[t].size() > 0)
        std::cout << s[t].front() << std::endl;
      break;
    case 2:
      if (s[t].size() > 0)
        s[t].pop();
      break;
    }
  }
}



Measured memory_bytes: 4256
s = gets.chomp.split('').map(&:to_i)

s.reverse!
ans = 0
[0, 1].repeated_permutation(s.size - 1) do |a|
  tmp = 0
  s.size.times do |i|
    ans += s[i] * (10 ** tmp)
    next if i == s.size - 1
    if a[i] == 0
      tmp += 1
    else
      tmp = 0
    end
  end
end
p ans


Measured memory_bytes: 1788
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    N = int_raw()
    As = ints_raw()
    Ass = sorted(As)
    nc = sum([As[i]!=Ass[i] for i in range(N)])
    if nc <=2:
        return "YES"
    else:
        return "NO"

print(main())


Measured memory_bytes: 38256
#include<iostream>
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
using namespace std;
int main()
{
    fastio;
    long long n,p;
    cin>>n>>p;
    cout<<n-p+1;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;
const int64 INF64 = (int64)2e18;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

const int MAX_N = (int)1e5 + 777;

int n;
int64 x[MAX_N], A, B;

void solve() {
	cin >> n >> A >> B;

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

	int64 answ = 0;

	for(int i = 0; i < n - 1; ++i) {
		answ += std::min((x[i + 1] - x[i]) * A, B);
	}

	cout << answ << '\n';
}

int main() {
	init_IO();
	solve();

	return 0;
}


Measured memory_bytes: 1024
while True:
    N, X = [int(i) for i in input().split()]
    if N == 0 and X == 0:
        exit(0)
    else:
        count = 0
        for i in range(1,N+1):
            for j in range(i+1,N+1):
                for k in range(j+1,N+1):
                    if i + j + k == X:
                        count += 1
        print(count)


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


using namespace std;

int N, L;
string S[100];

int main() {
    cin >> N >> L;
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }
    sort(S, S+N);
    for (int i = 0; i < N; i++) {
        cout << S[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/

#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;


void solve()
{
    ll n,m;
    cin >> n >> m;
    if(n>m)
        cout <<  "No";
    else 
        cout << "Yes";
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

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

int main(void) {
    int64_t remain = 100000;
    
    int n;
    std::cin >> n;
    
    for(int i = 0; i < n; i++) {
        remain *= 1.05;
        if(remain % 1000 > 0)
            remain = (remain - remain % 1000) + 1000;
    }
    
    std::cout << remain << std::endl;
}


Measured memory_bytes: 2972
#include<iostream>
#include<bitset>
#include<string>
#include<cmath>
#include<vector>

using namespace std;
bool iseven(int x){ return x % 2 == 0; }
bool isodd(int x){ return !iseven(x); }
template <typename T>
void show(vector<T> &vec){
    for (auto value : vec) {
        cout << value << " ";
    }
    cout << endl;
}
int ndiv2(int n){
    int count = 0;
    while( (n % 2) == 0){
        n /= 2;
        count += 1;
    }
    return count;
}
//vector<int> parse_line(string input, string separator){
int main(){
    int N;
    string raw_input;
    cin >> N;
    int ans = 0;
    int tmp;
    for(int i = 0; i < N; i++){
        cin >> tmp;
        ans += ndiv2(tmp);
    }
    cout << ans; 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  ll march[5] = {};
  REP(i, n) {
    cin >> s[i];
    if (s[i][0] == 'M') march[0]++;
    else if (s[i][0] == 'A') march[1]++;
    else if (s[i][0] == 'R') march[2]++;
    else if (s[i][0] == 'C') march[3]++;
    else if (s[i][0] == 'H') march[4]++;
  }
  ll sum = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = i+1; j < 4; j++) {
      for (int k = j+1; k < 5; k++) {
	sum += march[i]*march[j]*march[k];
      }
    }
  }
  dump(sum);
  return 0;
}


Measured memory_bytes: 6144
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int step(int s, vector<int> &dp, int n) {
	int cnt = 0;
	if (s == n) return 1;
	for (int i = 1; i <= 3; i++) {
		if (s + i <= n) {
			if (dp[s + i] == -1)
				cnt += step(s + i, dp, n);
			else
				cnt += dp[s + i];
		}
	}
	dp[s] = cnt;
	return cnt;
}

int main(void) {
	int n;
	vector<int> dp;
	vector<int> res;
	dp.resize(31, -1);
	while (cin >> n, n) {
		int cnt = 0;
		for (int i = 1; i <= 3; i++)
			cnt += step(i, dp, n);
		dp.clear();
		dp.resize(31, -1);
		res.push_back(cnt / 10 / 365 + 1);
	}
	for (int i = 0; i < res.size(); i++)
		cout << res[i] << endl;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	
	

	int mod = 1000000007;

	void solve(){

		int tmp;
		FOR(i,0,5){
			ini(tmp1);
			if(tmp1 == 0)tmp = i;
		}
		tmp++;
		out(tmp);
		
		
		
		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;

namespace contest_Csharp
{
    class Program
    {
        static void Main(string[] args)
        {

            var vals = Console.ReadLine().Split(' ')
                .Select(x => int.Parse(x)).ToList();
            var A = vals[0];
            var B = vals[1];
            var C = vals[2];
            var D = vals[3];

            while (true)
            {
                C -= B;
                if (C<=0)
                {
                    Console.WriteLine("Yes");
                    break;
                }
                A -= D;
                if (A <= 0)
                {
                    Console.WriteLine("No");
                    break;
                }
            }


        }
       
       

    }
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< int, int > P;
typedef pair< int, P > PP;

//-------------------------------------------------


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

	int n, m;
	cin >> n >> m;
	int a[m];
	REP(i, m) {
		cin >> a[i]; 
		a[i]--;
	}
	int p[n] = {};
	REP(i, m) {
		int cnt = 0;
		REP(j, n) {
			int t;
		   	cin >> t;
			t--;
            if (t == a[i]) p[j]++;
			else cnt++;
		}
		p[a[i]] += cnt;
	}
	REP(i, n) cout << p[i] << endl;

    return 0;
}





Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define nes ios_base :: sync_with_stdio(0); cin.tie(0);
using namespace std;
ll des=1e18;
int main(){
	nes;
	int n;
	cin>>n;
	vector<ll>v(n);
	ll mul=1;
	for(int i=0;i<n;++i){
		cin>>v[i];
		if(v[i]==0){
			cout<<0;return 0;
		}
	}
	for(int i=0;i<n;++i){
		
		if(mul>des/v[i]+des%v[i]){
			cout<<"-1";return 0;
		}
		mul*=v[i];
	}
	if(mul>des){
		cout<<"-1";return 0;
	}
	cout<<mul;
	return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

const int inf = 1<<29;
int H, W;
vector<vector<int>> dist(10, vector<int>(10, inf));
vector<vector<int>> A(220, vector<int>(220, 0));

void floyd(){
    rep(k, 10){
        rep(i, 10){
            if(dist[i][k] == inf) continue;
            rep(j, 10){
                if(dist[k][j] == inf) continue;
                chmin(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

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

    cin >> H >> W;
    rep(i, 10) rep(j, 10) cin >> dist[i][j];
    rep(i, H) rep(j, W) cin >> A[i][j];

    int ans = 0;
    floyd();
    rep(i, H) rep(j, W) if(A[i][j] != -1) ans += dist[A[i][j]][1];
    cout << ans << endl;
    
    return 0;
}

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

int main()
{
	string s, t;
	cin >> s >> t;

	vector<vector<int>> dp(s.length()+1, vector<int>(t.length()+1));
	int s_size = s.length();
	int t_size = t.length();
	for(int i = 0; i < t_size; ++i)
		dp[0][i] = 0;
	for(int i = 0; i < s_size; ++i)
		dp[i][0] = 0;
	
	for(int i = 1; i <= s_size; ++i)
	{
		for(int j = 1; j <= t_size; ++j)
		{
			if(s[i-1] == t[j-1])
			{
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else
			{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	int i = s_size;
	int j = t_size;
	string res = "";
	while(i > 0 && j > 0)
	{
		if(s[i-1] == t[j-1])
		{
			--i,--j;
			res = s[i] + res;
		}
		else if(dp[i-1][j] > dp[i][j-1])
		{
			--i;
		}
		else
			--j;
	}
	cout << res ;
}

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

#define pb push_back

#define int ll
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

template<typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (const T& x : v)
    o << x << ",";
  return o << "]";
}

const int INF = 2e9;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  string s;
  cin >> s;
  const int d = 2019;
  vi remmult(d, 0);
  int count = 0;
  for (int i=0; i<s.size(); ++i) {
    ++remmult[0];  // the ones that start at this i
    vi newremmult(d, 0);
    for (int r=0; r<remmult.size(); ++r) {
      int newr = (10*r + (s[i]-'0')) % d;
      newremmult[newr] += remmult[r];
    }
    remmult = std::move(newremmult);
    count += remmult[0];
    //cerr << remmult << endl;
  }
  cout << count << endl;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

int main() {
    while (true) {
        Int m, nmin, nmax;
        cin >> m >> nmin >> nmax;
        if (m == 0) break;
        vector<Int> p(m + 1);
        for (Int i = 1; i <= m; i++) {
            cin >> p[i];
        }
        Int ma = -1e9;
        Int index = 1;
        for (Int i = nmin; i <= nmax; i++) {
            if (p[i] - p[i + 1] >= ma) {
                ma = p[i] - p[i + 1];
                index = i;
            }
        }
        dump(index);
    }
    return 0;
}


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vl a(n);
    // vector<pll> cr;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        //        cr.emplace_back(a[i], i+1);
    }
    sort(a.begin(), a.end());
    ll ret = n;
    ll idx = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (a[i] * 2 < a[i + 1])
            ret = n - 1 - i;
        a[i + 1] += a[i];
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 1024
<?php
fscanf(STDIN, '%d', $num);
$ans = 0;
for ($i=1; $i <= $num ; $i++) { 
    for ($j=1; $j <= $num ; $j++) {
        $ij = gmp_gcd($i, $j); 
        for ($k=1; $k <= $num ; $k++) { 
            if ($k === 1) {
                $ans++;
                continue;
            }
            $ans+=gmp_gcd($ij, $k); 
        }
    }
}
echo $ans; 

Measured memory_bytes: 16280
// https://atcoder.jp/contests/abc163/tasks/abc163_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N, M;
  cin >> N >> M;

  ll sum = 0;
  rep(i, M) {
    ll a;
    cin >> a;
    sum += a;
  }

  ll res = N - sum;

  if (res < 0) drop(-1);
  drop(res);
}


Measured memory_bytes: 3688
// !=D
#include <bits/stdc++.h>

using namespace std;

vector<long long> p;
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, x, t;
	cin>> n >> x >> t;
	if(n % x)
		n = n / x + 1;
	else
		n /= x;
	cout<< n * t << endl;
	
	return 0;
}

Measured memory_bytes: 3608
N = int(input())
# =  map(int,input().split())
W =list(map(int,input().split()))
# [list(map(int,input().split())) for i in range(N)]

front = 0
back = 0
dif = []
for i in range(N):
    front = sum(W[:i])
    back = sum(W[i:])
    dif.append(abs(front-back))
    
print(min(dif))


Measured memory_bytes: 38512
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{


    ll n, m, k, i, j, x, y, p=0, s=0, h, f=0;
    cin>>n>>m>>k;
    x=m/k;
    if(n==0){
        cout<<x+1<<endl;
    }
    else{
        y=(n-1)/k;
        cout<<x-y<<endl;
    }


    return 0;
}



Measured memory_bytes: 3600
short , long , hour1 , mini = map(int, input().split())
hour2 = hour1 + mini / 60
import math
shortx = short * math.sin(math.radians( hour2 * 30 ))
shorty = short * math.cos(math.radians( hour2 * 30 ))
longx = long * math.sin(math.radians( mini * 6 ))
longy = long * math.cos(math.radians( mini * 6 ))
c = math.sqrt((shortx - longx) ** 2 + (shorty - longy) ** 2 )
print(c)

Measured memory_bytes: 9360
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M, A_sum=0,lim,count=0;
  string ans = "Yes";
  cin >> N >> M;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    A_sum += A.at(i);
  }
  lim = A_sum / (4 * M);
  if(A_sum % (4 * M)==0){
    for(int i=0;i<N;i++){
      if(A.at(i) >= lim) count++;
    }
    if(count < M) ans = "No";
  }
  else{
    for(int i=0;i<N;i++){
      if(A.at(i) > lim) count++;
    }
    if(count < M) ans = "No";
  }
  cout << ans << endl;
  
    
}

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

using namespace std;

int main()
{
  int p,q,r;
  cin >> p >> q >> r;

  int t1,t2,t3;
  t1 = p+q;
  t2 = q+r;
  t3 = r+p;
  int ret;
  ret = t1;
  if (ret > t2) {
      ret = t2;
  }
  if (ret > t3) {
      ret = t3;
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,a,ans=0;
  map<int,int> mp;
  cin>>n;
  rep(i,n){
     cin>>a;
     mp[a]++; 
  }
  for(auto itr : mp)
      ans+=itr.second%2;
  cout<<ans;
  return 0;
}


Measured memory_bytes: 4864
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
ll dp[105][105];
ll top[105];
ll bottom[105];
ll rec(int a,int b)//[a,b]
{
	if(dp[a][b]!=-1)return dp[a][b];
	if(a==b)return 0;
	ll res=INF;
	for(int i=a;i<b;i++)
	{
		res=min(res,rec(a,i)+rec(i+1,b)+top[a]*bottom[i]*top[i+1]*bottom[b]);
	}
	return dp[a][b]=res;
}
int main()
{
	int n;
	cin >> n;
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++)cin >> top[i] >> bottom[i];
	cout << rec(0,n-1) << endl;
	return 0;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

struct LCA {
    const int n = 0;
    const int log2_n = 0;
    vector<vector<int>> g;
    vector<vector<int>> par;  // par[2^i上][頂点v]
    vector<int> dep;

    void dfs(int v, int p, int d) {
        par[0][v] = p;
        dep[v] = d;
        for(auto to: g[v]) {
            if(to == p) continue;
            dfs(to, v, d+1);
        }
    }

    LCA() {}
    LCA(int n) : n(n), log2_n(log2(n)+1), g(n),
        par(log2_n, vector<int>(n)), dep(n) {}

    void add_edge(int u, int v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }

    void build(ll root=0) {
        dfs(root, -1, 0);
        for(int i=0; i+1 < log2_n; ++i) {
            for(int j = 0; j < n; ++j) {
                if(par[i][j] < 0) par[i+1][j] = -1;
                else par[i+1][j] = par[i][par[i][j]];
            }
        }
    }

    int get(int u, int v) {
        if(dep[u] > dep[v]) swap(u, v);
        REP(i, log2_n) {
            if((dep[v] - dep[u]) >> i & 1) {
                v = par[i][v];
            }
        }
        if(u == v) return u;
        for(int i=log2_n-1; i>=0; --i) {
            if(par[i][u] != par[i][v]) {
                u = par[i][u];
                v = par[i][v];
            }
        }
        return par[0][u];
    }
};

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n-1), b(n-1);
    LCA lca(n);
    REP(i, n-1) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        lca.add_edge(a[i], b[i]);
    }
    lca.build();
    ll m;
    cin >> m;
    vector<ll> u(m), v(m);
    REP(i, m) cin >> u[i] >> v[i], u[i]--, v[i]--;

    vector<ll> x(n-1);
    auto dist = [&](ll p, ll q) {
        ll l = lca.get(p, q);
        return lca.dep[p] + lca.dep[q] - 2*lca.dep[l];
    };
    REP(i, n-1) {
        dump(i);
        REP(j, m) {
            if(dist(u[j], v[j]) == dist(u[j], a[i]) + dist(a[i], v[j]) && dist(u[j], v[j]) == dist(u[j], b[i]) + dist(b[i], v[j])) {
                x[i] |= 1LL<<j;
            }
        }
    }

    vector<vector<ll>> dp(n, vector<ll>(1LL<<m));
    dp[0][0] = 1;
    REP(i, n-1) REP(j, 1LL<<m) {
        dp[i+1][j|x[i]] += dp[i][j];
        dp[i+1][j] += dp[i][j];
    }
    cout << dp[n-1][(1LL<<m)-1] << endl;

    return 0;
}

Measured memory_bytes: 418304
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int x, y;
  scanf("%d %d", &x, &y);

  int ans = 600000;
  if (x == 1 && y == 1) ans += 400000;
  ans -= min(x - 1, 3) * 100000 + min(y - 1, 3) * 100000;
  printf("%d\n", ans);
  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  vector<int> b(n,0), c(n,0);
  rep(i,n)
  {
    b[i] += (i+1)*20202;
    c[i] += (n-i)*20202;
    b[a[i]-1] += i;
    c[a[i]-1] += i;
  }
  
  rep(i,n) cout << b[i] << ((i == n-1)? "\n" : " ");
  rep(i,n) cout << c[i] << ((i == n-1)? "\n" : " ");
  //rep(i,n) cout << b[i] + c[i] << " "; cout << endl;
  
  return 0;
}
  

Measured memory_bytes: 896
N, D = list(map(int, input().split()))
X = []
for i in range(N):
  X.append(list(map(int, input().split())))
  
def dis(l, m):
  out = 0
  for i in range(len(l)):
    out += (l[i] - m[i])**2
  return out ** 0.5

count = 0


for x in range(N-1):
  for y in range(x+1,N):
    if dis(X[x], X[y]) == int(dis(X[x], X[y])):
      count += 1
                              
print(count)

Measured memory_bytes: 3188
#include<iostream>
#include<iomanip>
#include<vector>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<unordered_set>
using namespace std;
const int MAX = 200;
const int INF = 100000000;

int graph[MAX][MAX] = { 0 };
int town[MAX];
bool check[MAX] = { false };
int N, M, R;

int solve(int t, int cost,int d) {
	if (d >= R)return cost;
	check[t] = true;
	int res = INF;
	for (int i = 0; i < R; i++) {
		if(check[i] == false){
			res = min(solve(i, graph[town[t]][town[i]],d + 1) + cost, res);
		}
	}
	check[t] = false;
	return res;
}

int main() {
	int ans = INF;

	cin >> N >> M >> R;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			graph[i][j] = INF;
		}
	}
	for (int i = 0; i < R; i++) {
		cin >> town[i];
		town[i]--;
	}
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		graph[a][b] = c;
		graph[b][a] = c;
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				if (j == k)continue;
				graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]);
			}
		}
	}

	for (int i = 0; i < R; i++) {
		ans = min(solve(i, 0, 1), ans);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll n, a[500000], b[500000], d1[500000], d2[500000], sum[500000];
P p[500000];

int main() {
  scanf("%lld", &n);
  for (ll i = 0; i < n; i++) scanf("%lld%lld", &a[i], &b[i]), p[i] = P(a[i], b[i]);
  sort(p, p+n);
  for (ll i = 0; i < n; i++) a[i] = p[i].first, b[i] = p[i].second;
  sum[0] = b[0];
  for (ll i = 1; i < n; i++) sum[i] = b[i] + sum[i-1];

  for (ll i = 0; i < n; i++) d1[i] = sum[i] - a[i];
  d2[0] = -a[0];
  for (ll i = 1; i < n; i++) d2[i] = sum[i-1] - a[i];

  ll ans = 0, mx = -1000000000000000000LL;
  for (ll i = n-1; i >= 0; i--) mx = max(mx, d1[i]), ans = max(ans, mx - d2[i]);
  printf("%lld\n", ans);
}



Measured memory_bytes: 30076
if __name__ == '__main__':
    
    a = int(raw_input())
    b = int(raw_input())
    c = int(raw_input())
    x = int(raw_input())
    
    count = 0
    na = x / 500
    for i in range(na+1):
        nb  =   (x-i*500)/100
        for j in range(nb+1):
            nc = (x-i*500-j*100)/50
            if (i <= a) & (j <= b) & (nc <= c):
                count += 1
                
    print count

Measured memory_bytes: 2568
def decomp(m):
    p2=0
    p5=0
    while m%2==0:
        m//=2
        p2+=1
    while m%5==0:
        m//=5
        p5+=1
    return p2,p5

n=int(input())
table=[[0]*50 for _ in range(50)]
ans=0
for i in range(n):
    a=input().split('.')
    if len(a)==1:
        ax=int(a[0]+'0'*9)
    else:
        ax=int(a[0]+a[1]+'0'*(9-len(a[1])))
    p2,p5=decomp(ax)
    if i!=0:
        for j in range(18-p2,50):
            ans+=sum(table[j][18-p5:])
    table[p2][p5]+=1

print(ans)

Measured memory_bytes: 80372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	string s, t;
	cin >> s >> t;
	ll n = s.size();
	ll m = t.size();
	ll dp[n+1][m+1], tb[n+1][m+1];
	memset(dp, 0, sizeof(dp));
	
	rep(i, 1, n+1){
		rep(j, 1, m+1){
			if(s[i-1] == t[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
				tb[i][j] = 0;
			}
			if(dp[i-1][j] >= dp[i][j]){
				dp[i][j] = dp[i-1][j];
				tb[i][j] = 1;
			}
			if(dp[i][j-1] >= dp[i][j]){
				dp[i][j] = dp[i][j-1];
				tb[i][j] = 2;
			}
		}
	}
	string ans = "";
	ll itri = n;
	ll itrj = m;
	while(itri > 0 && itrj > 0){
		if(tb[itri][itrj] == 0){
			ans = s[itri-1] + ans;
			itri--;
			itrj--;
		}
		else{
			if(tb[itri][itrj] == 1){
				itri--;
			}
			else{
				itrj--;
			}
		}
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 140928
using System;

namespace _100C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long[] A = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            int count = 0;
            int i = 0;
            while(i < N ){
                if(A[i] != 0 && A[i] % 2 ==0){
                    A[i] /= 2;
                    count++;
                    continue;
                }else{
                    A[i] *= 3;
                    i ++;
                }
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 13920
import math
a,b,h,m = map(int,input().split())
a_rad = (2*math.pi/12*(h+m/60))%(2*math.pi)
b_rad = 2*math.pi/60*m
rad = abs(a_rad-b_rad)
double_c = a**2+b**2-2*a*b*math.cos(rad)
c = math.sqrt(double_c)
print(c)


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

int main(){
  int H,W,a[50][50]={{0}};
  cin>>H>>W;
  for(int i=0;i<H;i++){
      string s;
      cin>>s;
      for(int j=0;j<W;j++){
      if(s[j]=='#'){
        
        for(int k=-1;k<2;k++)
          for(int l=-1;l<2;l++)
            if(i+k>=0&&j+l>=0&&i+k<H&&j+l<W)
            a[i+k][j+l]++;
        
        a[i][j]=100;
        
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++)
      if(a[i][j]>10)
        cout<<"#";
    else
      cout<<a[i][j];
    
    cout<<endl;
  }
}

  

Measured memory_bytes: 256
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   998244353
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//

int32_t main()
{
    io;
    int n;
    cin>>n;
    vi inp(n);
    for(auto& x: inp) cin>>x;
    int dp[n+1];
    dp[n-1] = 0;
    dp[n-2] = abs(inp[n-1] - inp[n-2]);
    for(int i = n-3; i>= 0;i--)
        dp[i] = min(abs(inp[i] - inp[i+1]) + dp[i+1], abs(inp[i] - inp[i+2]) + dp[i+2]);
    cout<<dp[0];
    return 0;
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int> > vec(n, vector<int>(d));
  for(int i=0; i<n; i++) {
    for(int j=0; j<d; j++) {
      cin >> vec.at(i).at(j);
    }
  }
  int cnt = 0;
  for(int i=0; i<n; i++) {
    for(int j=1; i+j<n; j++) {
      int sum = 0;
      for(int k=0; k<d; k++) {
        
        sum += (vec.at(i).at(k) - vec.at(i+j).at(k)) * (vec.at(i).at(k) - vec.at(i+j).at(k));
      }
    
      for(int l=0; l<=sum; l++) {
        if(sum == l*l) {
          cnt++;
        }
      }
    }
  }  
  cout << cnt << endl;
  
  
}

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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

int main()
{
  ll N, k;
  cin >> N >> k;
  ll id = 0; N--;
  while(N--) {
    id += id/(k-1) + 1;
  }
  cout << id << endl;
  return 0;
}

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

int main(){
  vector<int> v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >>K;
  cout<<v.at(K-1)<<endl;
}

Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N = int(sys.stdin.readline())

a = (N - 1) * N // 2
print(a)


Measured memory_bytes: 22196
#include <cstdio>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define min(a,b)    (((a) < (b)) ? (a) : (b))
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define abs(x)    ((x) < 0 ? -(x) : (x))
#define INF 0x3f3f3f3f
#define delta 0.85
#define eps 1e-3
#define PI 3.14159265358979323846
#define MAX_R 10
#define MAX_C 10000
using namespace std;
int R, C;
int mp[MAX_R][MAX_C];

int main(){
	while(~scanf("%d%d", &R, &C) && R){
		for(int i = 0; i < R; i++){
			for(int j = 0; j < C; j++){
				scanf("%d", &mp[i][j]);
			}
		}
		int res = 0;
		for(int i = 0; i < 1 << R; i++){
			int flip[MAX_R];
			for(int j = 0; j < R; j++){
				flip[j] = (1 & (i >> j)) ? 1 : 0;
			}
			int sum = 0;
			for(int j = 0; j < C; j++){
				int tmp = 0;
				for(int k = 0; k < R; k++){
					tmp += mp[k][j] ^ flip[k];
				}
				sum += max(tmp, R - tmp);
			}
			res = max(res, sum);
		}
		printf("%d\n", res);
	}
	return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K,X,Y;
int a,b,c,d;
string S,T;
vector<int> A,B;
int H,W;
//=============================
void input()
{
    cin>>H>>W;
}
//=============================
void func(){}
/*
 - 樹形図をかく
*/
//=============================
void solve()
{
    // 3つの長方形に分割する．

    // greedy
    // 1tume
    int h=H,w=W;
    int s1 = H*W/3;
    int s2,s3,s4;
    //4通り?
    int ans = INF;
    rep(i,0,1){
        int subans=INF;
        rep(j,0,1){
        h=H,w=W;
        int h2,w2;
            if (j){
                h = (H+1)/3;
                w2=W;
                h2=H-h;
            }
            else {
                w = (W+1)/3;
                h2=H;
                w2=W-w;

            }
            s1 = h*w;
        
            if (i){
                h2 /= 2;
            }
            else {
                w2 /= 2;
            }
            s2 = h2*w2;
            s3 = (H*W - s1 - s2);

            // debug(s1);
            // debug(s2);
            // debug(s3);

            subans = max({s1,s2,s3}) - min({s1,s2,s3});
   //         debug(subans);
            ans = min(ans, subans);
        }
    }
    cout<<ans<<endl;



}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
diff=b-a
#b to n
#a to a+b-n
if(diff%2==0):
    print(diff//2)
else:

    ans1=n-b
    dist=n-(a+n-b)
    if(dist%2==0):
        ans1+=dist//2
    else:
        ans1+=1+(dist-1)//2
    #print(dist)
    ans2=a-1
    dist=(b-(a-1))-1
    if(dist%2==0):
        ans2+=dist//2
    else:
        ans2+=1+(dist-1)//2
    #print(ans1,ans2)
    print(min(ans1,ans2))


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define fin(x) cout << x << endl;

using namespace std;
using ll = long long;

int main(void) {
  int a, b;
  cin >> a >> b;
  for (double ans = 1; ans <= 2500; ans++) {
    if ((int)(ans * 0.08) == a && (int)(ans * 0.1) == b) {
      fin((int)(ans));
      return 0;
    }
  }
  fin(-1);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 10000

int main(void){
  int i,num;
  int w,fee[N];
  for(i=0;;i++){
    scanf("%d",&w);
    if(w==-1)
      break;
    fee[i]=1150;
    if(w-10<=0)
      continue;
    w-=10;
    if(w-10<=0){
      fee[i]+=w*125;
      continue;
    }
    fee[i]+=1250;
    w-=10;
    if(w-10<=0){
      fee[i]+=w*140;
      continue;
    }
    fee[i]+=1400;
    w-=10;
    fee[i]+=w*160;
  }
  num=i;
  for(i=0;i<num;i++){
    printf("%d\n",4280-fee[i]);
  }
  return 0;
}

Measured memory_bytes: 0
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.sum(A)-np.cumsum(np.append(0, A[:len(A)-1]))
v=0
k=0
for i in range(N+1):
  if i==0:
    if N==0 and A[0]==1:
      k=1
    elif A[0]==0:
      k=1
    else:
      print(-1)
      break
  elif i==N:
    if B[i]<=2*(k-A[i-1]):
      k=B[i]
    else:
      k=0
      print(-1)
      break
  else:
    k=min(2*(k-A[i-1]),B[i])
    if k<=0:
      print(-1)
      break
  v+=k
if k>0:
  print(v)

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

int n;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    map<string,int> mp;
    for (int i = 0; i < n; i++) {
        string si; cin >> si;
        mp[si]++;
    }
    map<int,vector<string>> v;
    for (auto p: mp) {
        v[p.second].push_back(p.first);
    }
    vector<string> u = v.rbegin()->second;
    sort(u.begin(),u.end());
    for (auto s: u) {
        cout << s << '\n';
    }
}



Measured memory_bytes: 27120
function main(_stdin){
    const stdin = _stdin.split('\n');
    const len = parseInt(stdin.shift(), 10);

    const data = stdin.filter((e, i) => i < len).map(e => e.split(' ').map(e => parseInt(e, 10)));

    const dists = [null, 0];

    bfs(data[0], dists, data);

    for(const node of data){
        if(dists[node[0]] === undefined) dists[node[0]] = -1;
    }
    dists.shift();
    dists.forEach((e, i) => {
        console.log(i + 1,  e);
    });
}

function bfs(node, dists, data){
    const key = node[0];
    const next = dists[key] + 1;
    const children = node.slice(2);

    for(const child of children){
        if(dists[child] === undefined || dists[child] > next){
            const nextNode = data.find(e => e[0] === child);
            dists[child] = next;
            bfs(nextNode, dists, data);
        }
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));




Measured memory_bytes: 17560
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=707,OO=1e9;
int a[N][N];
vector<int>g[N];
int c[N];
void no(){
    cout<<"-1\n";
    exit(0);
}
int c1,c2;
void dfs(int v,int co=1){
    c[v]=co;
    if(co==1)c1++;
    else c2++;
    for(int to:g[v]){
        if(!c[to])dfs(to,3-co);
        if(c[to]!=3-co)no();
    }
}
int dp[N][N];
int32_t main(){
    int n,m;
    cin>>n>>m;
    forn(i,m){
        int x,y;
        cin>>x>>y;
        a[x][y]=a[y][x]=1;
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<i;++j){
            if(!a[i][j]){
                g[i].pb(j);
                g[j].pb(i);
            }
        }
    }
    vector<pii> v;
    for(int i=1;i<=n;++i){
        if(!c[i]){
            c1=c2=0;
            dfs(i);
            v.pb(c1,c2);
        }
    }
    dp[0][0]=1;
    int s=0;
    for(pii p:v){
        int l=p.f,r=p.s;
        for(int i=0;i<=s;++i){
            int j=s-i;
            dp[i+l][j+r]|=dp[i][j];
            dp[i+r][j+l]|=dp[i][j];
        }
        s+=l+r;
    }
    int ans=OO;
    forn(i,n+1){
        int j=n-i;
        if(dp[i][j])upn(ans,i*(i-1)/2+j*(j-1)/2);
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 11284